:root {
  --brand: #0b4f9c;
  --brand-dark: #083a73;
  --accent: #12b3a8;
  --bg: #eef3fa;
  --panel: #ffffff;
  --text: #152238;
  --muted: #64748b;
  --line: #dbe4f0;
  --user: #0b4f9c;
  --radius: 18px;
  --shadow: 0 10px 30px rgba(11, 79, 156, 0.12);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: radial-gradient(1200px 600px at 50% -10%, #dbe9fb 0%, var(--bg) 55%, #e8eef8 100%);
  color: var(--text);
  font: 16px/1.55 "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 22px;
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-dark) 70%);
  color: #fff;
  box-shadow: 0 6px 20px rgba(8, 58, 115, 0.25);
}

.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }

.logo {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.35);
  font-size: 22px;
  font-weight: 700;
}

.brand-text { min-width: 0; }

.brand-text h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-text p {
  margin: 2px 0 0;
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.75);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions { display: flex; align-items: center; gap: 12px; }

.status {
  font-size: 0.75rem;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.28);
  white-space: nowrap;
}

.status.warn { background: rgba(255, 196, 0, 0.2); border-color: rgba(255, 214, 102, 0.6); }

.ghost {
  background: transparent;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.5);
  padding: 8px 14px;
  border-radius: 12px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s ease;
}

.ghost:hover { background: rgba(255, 255, 255, 0.14); }

.chat-wrap {
  flex: 1;
  width: min(920px, 100%);
  margin: 0 auto;
  padding: 22px 18px 8px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 6px 4px 12px;
  scroll-behavior: smooth;
}

.msg {
  display: flex;
  gap: 10px;
  max-width: 88%;
  animation: rise 0.18s ease;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg.bot { align-self: flex-start; }

.avatar {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 0.85rem;
  font-weight: 700;
  background: var(--brand);
  color: #fff;
  box-shadow: 0 4px 12px rgba(11, 79, 156, 0.28);
}

.msg.user .avatar { background: var(--accent); box-shadow: 0 4px 12px rgba(18, 179, 168, 0.3); }

.bubble {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  border-top-left-radius: 6px;
  padding: 12px 15px;
  box-shadow: var(--shadow);
  overflow-wrap: anywhere;
}

.msg.user .bubble {
  background: var(--user);
  border-color: var(--user);
  border-radius: var(--radius);
  border-top-right-radius: 6px;
  color: #fff;
  box-shadow: 0 8px 20px rgba(11, 79, 156, 0.28);
}

.bubble p { margin: 0 0 8px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul { margin: 6px 0; padding-left: 20px; }
.bubble li { margin: 3px 0; }
.bubble strong { font-weight: 650; }
.bubble a { color: var(--brand); }
.msg.user .bubble a { color: #d6f4f1; }

.cite {
  display: inline-block;
  margin: 0 1px;
  padding: 0 5px;
  border-radius: 6px;
  background: #e6f4f3;
  color: #0a7b74;
  font-size: 0.72em;
  font-weight: 600;
  vertical-align: super;
  line-height: 1.4;
}

.sources { margin-top: 10px; border-top: 1px dashed var(--line); padding-top: 8px; }
.sources summary {
  cursor: pointer;
  list-style: none;
  font-size: 0.78rem;
  color: var(--muted);
  user-select: none;
}
.sources summary::-webkit-details-marker { display: none; }
.sources summary::before { content: "▸ "; }
.sources[open] summary::before { content: "▾ "; }
.sources ol { margin: 8px 0 0; padding-left: 18px; font-size: 0.78rem; color: var(--muted); }
.sources li { margin: 4px 0; }
.sources code {
  font-size: 0.75rem;
  background: #f1f5fb;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1px 5px;
}

.feedback { display: flex; gap: 6px; margin-top: 8px; }

.feedback button {
  border: 1px solid var(--line);
  background: #f8fafd;
  border-radius: 10px;
  padding: 4px 9px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease;
}

.feedback button:hover { background: #eef4fc; transform: translateY(-1px); }
.feedback button.active { background: #e6f4f3; border-color: #9fdcd7; }
.feedback button:disabled { opacity: 0.55; cursor: default; transform: none; }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 4px 12px;
}

.chip {
  border: 1px solid #b9d2ee;
  background: rgba(255, 255, 255, 0.85);
  color: var(--brand);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 0.84rem;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.12s ease;
}

.chip:hover { background: #eaf3ff; transform: translateY(-1px); }

.dots { display: inline-flex; gap: 4px; align-items: center; height: 18px; }
.dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #9db4d2;
  animation: blink 1.2s infinite ease-in-out;
}
.dots span:nth-child(2) { animation-delay: 0.15s; }
.dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes blink {
  0%, 80%, 100% { opacity: 0.35; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

.error-text { color: #b3261e; }

.composer-wrap {
  width: min(920px, 100%);
  margin: 0 auto;
  padding: 0 18px 18px;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 10px 10px 10px 16px;
  box-shadow: var(--shadow);
}

.composer textarea {
  flex: 1;
  border: 0;
  resize: none;
  outline: none;
  font: inherit;
  color: var(--text);
  background: transparent;
  max-height: 160px;
  min-height: 28px;
  padding: 4px 0;
}

.composer textarea::placeholder { color: #93a3b8; }

.composer button {
  border: 0;
  background: var(--brand);
  color: #fff;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 10px 20px;
  border-radius: 13px;
  cursor: pointer;
  transition: background 0.15s ease, opacity 0.15s ease;
}

.composer button:hover { background: var(--brand-dark); }
.composer button:disabled { opacity: 0.55; cursor: default; }

.disclaimer {
  margin: 10px 4px 0;
  font-size: 0.72rem;
  line-height: 1.45;
  color: var(--muted);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  background: #152238;
  color: #fff;
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 0.82rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  max-width: min(92vw, 480px);
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 640px) {
  .topbar { padding: 12px 14px; }
  .brand-text p { display: none; }
  .status { display: none; }
  .chat-wrap { padding: 14px 10px 4px; }
  .msg { max-width: 94%; }
  .composer-wrap { padding: 0 10px 12px; }
  .composer { padding: 8px 8px 8px 12px; }
  .composer button { padding: 10px 14px; }
}

