:root {
  color-scheme: light;
  --bg: #f7f8f6;
  --panel: #ffffff;
  --sidebar: #111816;
  --sidebar-hover: #1d2925;
  --sidebar-text: #f1f5f3;
  --sidebar-muted: #9eaaa5;
  --text: #16201d;
  --muted: #66726e;
  --subtle: #8b9692;
  --border: #dfe5e2;
  --border-strong: #ccd5d1;
  --accent: #18795e;
  --accent-hover: #11664e;
  --accent-soft: #e4f2ed;
  --user: #e9eeeb;
  --source: #f8faf9;
  --warning: #a45b10;
  --warning-bg: #fff3df;
  --danger: #a33e3e;
  --shadow: 0 1px 2px rgba(17, 24, 22, .06), 0 8px 28px rgba(17, 24, 22, .07);
  --composer-shadow: 0 6px 30px rgba(25, 39, 34, .12);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #202624;
  --panel: #252c29;
  --sidebar: #101513;
  --sidebar-hover: #202a26;
  --sidebar-text: #edf2ef;
  --sidebar-muted: #98a39e;
  --text: #eef3f0;
  --muted: #aab5b0;
  --subtle: #87938e;
  --border: #3a4541;
  --border-strong: #4b5752;
  --accent: #57b99a;
  --accent-hover: #6dc8ab;
  --accent-soft: #293e37;
  --user: #343d39;
  --source: #29302d;
  --warning: #f2bd76;
  --warning-bg: #49391f;
  --danger: #f08d8d;
  --shadow: 0 1px 2px rgba(0, 0, 0, .18), 0 10px 30px rgba(0, 0, 0, .2);
  --composer-shadow: 0 8px 32px rgba(0, 0, 0, .25);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, textarea { font: inherit; }
button { color: inherit; }
button:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-shell { display: flex; width: 100%; height: 100%; }

.sidebar {
  position: relative;
  z-index: 20;
  display: flex;
  flex: 0 0 272px;
  flex-direction: column;
  min-width: 0;
  padding: 18px 14px;
  background: var(--sidebar);
  color: var(--sidebar-text);
}

.brand { display: flex; align-items: center; gap: 11px; padding: 0 8px 19px; }
.brand-mark, .welcome-mark, .assistant-avatar {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  background: linear-gradient(145deg, #269a77, #14634d);
  color: #fff;
  font-family: Georgia, serif;
  font-weight: 700;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .17);
}
.brand-mark { width: 32px; height: 32px; border-radius: 9px; font-size: 17px; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 14px; line-height: 1.35; }
.brand small { color: var(--sidebar-muted); font-size: 11px; }

.new-chat {
  display: flex;
  align-items: center;
  width: 100%;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid #35413d;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: background .15s ease, border-color .15s ease;
}
.new-chat:hover { background: var(--sidebar-hover); border-color: #4d5b56; }
.new-chat svg, .icon-button svg, .send-button svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.sidebar-section { margin-top: 28px; }
.section-label {
  margin: 0 10px 8px;
  color: var(--sidebar-muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
}
.conversation-item { display: flex; gap: 10px; padding: 10px; border-radius: 10px; }
.conversation-item.active { background: var(--sidebar-hover); }
.conversation-icon {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: #32423c;
  color: #c9ded6;
  font-family: Georgia, serif;
  font-size: 13px;
  font-weight: 700;
}
.conversation-item strong, .conversation-item small { display: block; }
.conversation-item strong { font-size: 12px; }
.conversation-item small { margin-top: 1px; color: var(--sidebar-muted); font-size: 10px; }

.sidebar-note {
  display: flex;
  gap: 9px;
  margin-top: auto;
  padding: 12px;
  border: 1px solid #34413c;
  border-radius: 11px;
  background: rgba(255, 255, 255, .025);
}
.note-icon {
  display: grid;
  place-items: center;
  flex: 0 0 19px;
  width: 19px;
  height: 19px;
  margin-top: 1px;
  border: 1px solid #63716b;
  border-radius: 50%;
  color: #c0cbc6;
  font-family: Georgia, serif;
  font-size: 12px;
  font-weight: 700;
}
.sidebar-note p { margin: 0; color: var(--sidebar-muted); font-size: 10.5px; line-height: 1.5; }
.sidebar-note strong { color: #dce4e0; }

.sidebar-footer { padding: 15px 8px 0; }
.connection-row { display: flex; align-items: center; gap: 7px; color: #c1cbc7; font-size: 11px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #5cc99f; box-shadow: 0 0 0 3px rgba(92, 201, 159, .11); }
.status-dot.checking { background: #d5a75c; box-shadow: none; }
.status-dot.offline { background: #e47777; box-shadow: none; }
.sidebar-footer > p { margin: 5px 0 0 14px; color: #65716c; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 9px; }

.main-panel { position: relative; display: flex; flex: 1; min-width: 0; flex-direction: column; background: var(--panel); }
.topbar {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  min-height: 66px;
  padding: 10px 21px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  backdrop-filter: blur(16px);
}
.title-block { min-width: 0; }
.title-line { display: flex; align-items: center; gap: 9px; }
.title-block h1 { overflow: hidden; margin: 0; font-size: 15px; line-height: 1.4; text-overflow: ellipsis; white-space: nowrap; }
.title-block p { margin: 1px 0 0; color: var(--muted); font-size: 11px; }
.experiment-badge { padding: 2px 7px; border: 1px solid color-mix(in srgb, var(--accent) 33%, var(--border)); border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 9px; font-weight: 750; letter-spacing: .03em; text-transform: uppercase; }
.icon-button { display: grid; place-items: center; width: 36px; height: 36px; margin-left: auto; border: 0; border-radius: 9px; background: transparent; color: var(--muted); cursor: pointer; }
.icon-button:hover { background: var(--bg); color: var(--text); }
.menu-button { display: none; margin: 0 11px 0 0; }
.moon-icon { display: none; }
[data-theme="dark"] .sun-icon { display: none; }
[data-theme="dark"] .moon-icon { display: block; }

.chat-scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scroll-behavior: smooth; }
.chat-thread { width: min(100%, 850px); min-height: 100%; margin: 0 auto; padding: 34px 28px 190px; }
.welcome { display: flex; flex-direction: column; align-items: center; max-width: 720px; margin: clamp(42px, 10vh, 108px) auto 0; text-align: center; animation: enter .35s ease both; }
.welcome-mark { width: 54px; height: 54px; border-radius: 16px; font-size: 26px; box-shadow: var(--shadow); }
.welcome h2 { margin: 19px 0 7px; font-size: clamp(23px, 3vw, 30px); letter-spacing: -.025em; }
.welcome > p { max-width: 580px; margin: 0; color: var(--muted); font-size: 14px; }
.prompt-grid { display: grid; width: 100%; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 32px; }
.prompt-card { min-height: 82px; padding: 14px 16px; border: 1px solid var(--border); border-radius: 13px; background: var(--panel); text-align: left; cursor: pointer; transition: border-color .15s ease, background .15s ease, transform .15s ease; }
.prompt-card:hover { border-color: var(--border-strong); background: var(--bg); transform: translateY(-1px); }
.prompt-card strong, .prompt-card span { display: block; }
.prompt-card strong { margin-bottom: 3px; font-size: 13px; }
.prompt-card span { color: var(--muted); font-size: 12px; }

.message { display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 14px; margin: 25px 0; animation: enter .22s ease both; }
.message.user { grid-template-columns: minmax(0, 1fr); justify-items: end; margin: 30px 0; }
.user-bubble { max-width: min(82%, 660px); padding: 11px 16px; border-radius: 19px 19px 5px 19px; background: var(--user); white-space: pre-wrap; overflow-wrap: anywhere; }
.assistant-avatar { width: 31px; height: 31px; margin-top: 1px; border-radius: 9px; font-size: 14px; }
.assistant-content { min-width: 0; padding-top: 2px; }
.assistant-heading { display: flex; align-items: center; gap: 8px; min-height: 22px; margin-bottom: 7px; }
.assistant-heading strong { font-size: 13px; }
.route-badge { padding: 2px 7px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 9px; font-weight: 700; letter-spacing: .035em; text-transform: uppercase; }
.route-badge.abstain { background: var(--warning-bg); color: var(--warning); }
.route-badge.refuse { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.answer-copy { max-width: 760px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px; line-height: 1.68; }
.answer-copy.error { color: var(--danger); }
.answer-tools { display: flex; gap: 4px; margin-top: 11px; }
.text-button { padding: 4px 8px; border: 0; border-radius: 7px; background: transparent; color: var(--subtle); cursor: pointer; font-size: 10px; }
.text-button:hover { background: var(--bg); color: var(--text); }

.sources { max-width: 760px; margin-top: 18px; }
.sources-label { margin: 0 0 7px; color: var(--muted); font-size: 10px; font-weight: 750; letter-spacing: .08em; text-transform: uppercase; }
.source-card { margin: 7px 0; border: 1px solid var(--border); border-radius: 11px; background: var(--source); overflow: hidden; }
.source-card summary { display: flex; align-items: center; gap: 9px; padding: 10px 12px; list-style: none; cursor: pointer; }
.source-card summary::-webkit-details-marker { display: none; }
.source-number { display: grid; place-items: center; flex: 0 0 24px; width: 24px; height: 24px; border-radius: 7px; background: var(--accent-soft); color: var(--accent); font-size: 10px; font-weight: 750; }
.source-title { min-width: 0; flex: 1; overflow: hidden; font-size: 11px; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.source-id { color: var(--subtle); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 9px; }
.chevron { width: 7px; height: 7px; border-right: 1.5px solid var(--subtle); border-bottom: 1.5px solid var(--subtle); transform: rotate(45deg); transition: transform .15s ease; }
.source-card[open] .chevron { transform: translateY(2px) rotate(225deg); }
.source-detail { padding: 0 12px 12px 45px; }
.source-detail p { margin: 0 0 9px; color: var(--muted); font-size: 11px; line-height: 1.55; }
.source-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.source-meta span { padding: 2px 6px; border: 1px solid var(--border); border-radius: 999px; color: var(--subtle); font-size: 9px; }
.source-meta a { margin-left: auto; color: var(--accent); font-size: 10px; font-weight: 650; text-decoration: none; }
.source-meta a:hover { text-decoration: underline; }

.loading-copy { display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: 13px; }
.loading-dots { display: flex; gap: 3px; }
.loading-dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); animation: pulse 1.1s infinite ease-in-out; }
.loading-dots i:nth-child(2) { animation-delay: .13s; }
.loading-dots i:nth-child(3) { animation-delay: .26s; }

.composer-area { position: absolute; z-index: 4; right: 0; bottom: 0; left: 0; padding: 34px 24px 15px; background: linear-gradient(to bottom, transparent, var(--panel) 31%, var(--panel)); }
.composer { position: relative; display: flex; align-items: flex-end; width: min(100%, 790px); margin: 0 auto; padding: 9px 9px 9px 17px; border: 1px solid var(--border-strong); border-radius: 19px; background: var(--panel); box-shadow: var(--composer-shadow); }
.composer:focus-within { border-color: color-mix(in srgb, var(--accent) 55%, var(--border)); }
.composer textarea { flex: 1; max-height: 160px; min-height: 24px; padding: 5px 8px 4px 0; resize: none; overflow-y: auto; border: 0; outline: 0; background: transparent; color: var(--text); line-height: 1.45; }
.composer textarea::placeholder { color: var(--subtle); }
.send-button { display: grid; place-items: center; flex: 0 0 34px; width: 34px; height: 34px; border: 0; border-radius: 10px; background: var(--accent); color: #fff; cursor: pointer; transition: background .15s ease, opacity .15s ease; }
.send-button:hover:not(:disabled) { background: var(--accent-hover); }
.send-button:disabled { opacity: .3; cursor: default; }
.composer-disclosure { max-width: 790px; margin: 8px auto 0; color: var(--subtle); font-size: 9.5px; text-align: center; }
.composer-disclosure span { color: var(--muted); font-weight: 650; }
.sidebar-scrim { display: none; }

@keyframes enter { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pulse { 0%, 65%, 100% { opacity: .25; transform: translateY(0); } 35% { opacity: 1; transform: translateY(-2px); } }

@media (max-width: 760px) {
  .sidebar { position: fixed; top: 0; bottom: 0; left: 0; width: min(86vw, 292px); transform: translateX(-102%); transition: transform .2s ease; box-shadow: 16px 0 40px rgba(0, 0, 0, .24); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-scrim { position: fixed; z-index: 15; inset: 0; display: block; background: rgba(8, 12, 10, .52); opacity: 0; pointer-events: none; transition: opacity .2s ease; }
  .sidebar-scrim.open { opacity: 1; pointer-events: auto; }
  .menu-button { display: grid; }
  .topbar { min-height: 61px; padding: 8px 12px; }
  .title-block p { display: none; }
  .experiment-badge { display: none; }
  .chat-thread { padding: 24px 16px 178px; }
  .welcome { margin-top: 48px; }
  .prompt-grid { grid-template-columns: 1fr; margin-top: 25px; }
  .prompt-card { min-height: 65px; }
  .message { grid-template-columns: 29px minmax(0, 1fr); gap: 10px; }
  .assistant-avatar { width: 28px; height: 28px; }
  .user-bubble { max-width: 90%; }
  .source-detail { padding-left: 12px; }
  .source-id { display: none; }
  .composer-area { padding: 30px 10px 9px; }
  .composer { border-radius: 17px; }
  .composer-disclosure { padding: 0 8px; font-size: 9px; }
}

@media (max-width: 430px) {
  .welcome h2 { font-size: 22px; }
  .welcome > p { font-size: 13px; }
  .prompt-grid .prompt-card:nth-child(n+4) { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
