* { box-sizing: border-box; }
:root {
  color-scheme: light;
  --page: #f9f9fc; --surface: #fff; --nav: #f0f0f6; --ink: #1d1c2c;
  --muted: #57566d; --line: #deddea; --accent: #5338a6; --soft: #eae3ff;
  font-family: "Segoe UI", system-ui, sans-serif; color: var(--ink); background: var(--page);
}
[hidden] { display: none !important; }
body { margin: 0; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; color: inherit; }
button:disabled { opacity: .55; cursor: default; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
button, input, textarea, select { border-radius: 10px; }
h1, h2, p { margin-top: 0; }
a { color: var(--accent); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.auth { display: grid; min-height: 100dvh; place-items: center; padding: 20px; background: radial-gradient(ellipse at 50% 0, #e8e0fb, transparent 58%); }
.auth-card { width: min(100%, 430px); padding: clamp(24px, 6vw, 44px); border: 1px solid var(--line); border-radius: 24px; background: var(--surface); box-shadow: 0 16px 80px #25144b0c; }
.wordmark { display: flex; align-items: center; gap: 10px; font-size: 1.15rem; font-weight: 750; letter-spacing: -.025em; }
.mark { display: grid; width: 33px; height: 33px; place-items: center; border-radius: 12px; background: var(--soft); color: var(--accent); font-size: 1.38rem; line-height: 1; flex: none; }
.auth h1 { margin: 30px 0 8px; font-size: clamp(1.65rem, 7vw, 2rem); letter-spacing: -.045em; line-height: 1.12; }
.auth p, dialog p { color: var(--muted); line-height: 1.5; }
.auth form, #router-form { display: grid; gap: 15px; }
.auth label, dialog label { display: grid; gap: 7px; font-size: .92rem; font-weight: 600; }
input { width: 100%; padding: 11px 12px; border: 1px solid var(--line); color: var(--ink); background: var(--surface); font-size: 1rem; }
.primary { min-height: 42px; border: none; background: var(--accent); color: #fff; font-weight: 650; padding: 9px 14px; }
.primary:hover, .send:hover { background: #412782; }
.text-button { margin-top: 14px; border: 0; padding: 6px 0; background: none; color: var(--accent); text-align: left; font-size: .94rem; }
.text-button:hover { text-decoration: underline; }
cap-widget { width: 100%; --cap-border-color: var(--line); --cap-background: var(--page); --cap-color: var(--ink); }
.workspace { height: 100dvh; display: grid; grid-template-columns: 258px minmax(0, 1fr); overflow: hidden; }
.sidebar { background: var(--nav); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 20px 14px 12px; min-height: 0; }
.sidebar .wordmark { margin: 0 6px 29px; }
.new-chat { display: flex; align-items: center; gap: 8px; min-height: 42px; padding: 8px 11px; border: 1px solid #d7cafa; background: var(--soft); color: #402879; font-weight: 650; text-align: left; }
.new-chat span { font-size: 1.15rem; }
.new-chat:hover { background: #e1d6ff; }
.history { margin-top: 25px; overflow: auto; flex: 1; }
.history h2 { color: var(--muted); font-size: .9rem; font-weight: 650; margin: 0 10px 8px; }
.history button, .history p { display: block; width: 100%; padding: 9px 10px; text-align: left; font-size: .92rem; }
.history button { border: 0; background: transparent; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history button:hover, .history button[aria-current] { background: #e3e1ef; }
.history p { color: var(--muted); }
.account { display: flex; align-items: center; gap: 7px; border-top: 1px solid var(--line); padding: 12px 0 0; }
.account #account-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; font-weight: 650; font-size: .92rem; }
.avatar { flex: none; border-radius: 50%; width: 33px; height: 33px; display: grid; place-items: center; background: #e3dcfa; color: #42247d; font-weight: 700; }
.icon { display: grid; place-items: center; width: 38px; height: 38px; flex: none; border: 0; background: transparent; font-size: 1.2rem; }
.icon:hover:not(:disabled) { background: #eae6f7; }
.chat { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; min-height: 0; }
.topbar { min-height: 60px; display: flex; align-items: center; gap: 9px; padding: 8px 24px; border-bottom: 1px solid #edecf3; }
.topbar span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 650; }
.delete { border: 0; color: var(--muted); background: transparent; padding: 8px; font-size: .88rem; }
.delete:hover { background: #eee9f7; color: var(--ink); }
.mobile { display: none; }
.scroll { display: flex; flex-direction: column; overflow: auto; }
.empty { width: min(100%, 760px); margin: auto; text-align: center; padding: 26px 16px; }
.hero-mark { width: 59px; height: 59px; margin: 0 auto 20px; border-radius: 20px; font-size: 2.45rem; }
.empty h1 { font-size: clamp(2.05rem, 5vw, 3.65rem); line-height: 1.06; font-weight: 700; letter-spacing: -.065em; margin-bottom: 10px; }
.empty p { color: var(--muted); margin: 0; }
.thread { width: min(100%, 790px); margin: 0 auto; padding: 0 24px; }
.thread:not(:empty) { padding-top: 24px; padding-bottom: 12px; }
.message { margin-bottom: 24px; overflow-wrap: anywhere; }
.message-user { margin-left: auto; width: fit-content; max-width: min(90%, 610px); padding: 11px 15px; border-radius: 16px 16px 4px 16px; background: var(--soft); white-space: pre-wrap; line-height: 1.52; }
.message-assistant { padding-left: 13px; border-left: 2px solid #d8ccf8; line-height: 1.65; }
.message-label { display: block; color: var(--muted); font-size: .87rem; font-weight: 650; margin-bottom: 6px; }
.message-body.plain { white-space: pre-wrap; }
.message-body > :first-child { margin-top: 0; }
.message-body > :last-child { margin-bottom: 0; }
.message-body img { max-width: 100%; }
.message-body pre { overflow: auto; padding: 12px; background: #eeedf5; border-radius: 8px; }
.message-body :not(pre) > code { background: #eeedf5; padding: 2px 4px; border-radius: 4px; }
.composer-wrap { width: min(100%, 790px); margin: 0 auto; padding: 12px 24px max(24px, env(safe-area-inset-bottom)); }
.composer { display: grid; padding: 10px 12px; border: 1px solid #d7d4e6; background: var(--surface); border-radius: 19px; box-shadow: 0 8px 22px #2919550a; }
.composer:focus-within { border-color: #9b8bd0; }
textarea { width: 100%; max-height: 24vh; min-height: 48px; padding: 7px; resize: vertical; border: none; background: transparent; color: var(--ink); }
textarea:focus-visible { outline-offset: 0; }
.composer-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.model-label { min-width: 0; }
select { max-width: 100%; min-height: 38px; border: 1px solid var(--line); background: var(--page); color: var(--ink); padding: 5px 9px; font-size: .88rem; }
.send { background: var(--accent); color: #fff; border-radius: 12px; }
.icon.send:hover:not(:disabled) { background: #412782; }
.status { color: var(--muted); font-size: .9rem; margin: 0 0 8px; }
.error, .status.error { color: #952843; font-size: .9rem; margin: 0; }
.composer-wrap .error { margin-bottom: 8px; }
dialog { width: min(calc(100% - 28px), 445px); max-height: 90dvh; border: 1px solid var(--line); border-radius: 20px; padding: 23px; color: var(--ink); background: var(--surface); }
dialog::backdrop { background: #20182b66; }
.dialog-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.dialog-title h2 { margin: 0; }
dialog h3 { margin-bottom: 5px; }
dialog ul { margin: 8px 0; padding-left: 19px; color: var(--muted); }
@media (max-width: 700px) {
  .workspace { display: block; }
  .chat { height: 100%; }
  .sidebar { position: fixed; z-index: 2; inset: 0 auto 0 0; width: min(83vw, 278px); }
  .sidebar:not(.open) { display: none; }
  .scrim { position: fixed; z-index: 1; inset: 0; width: 100%; border: 0; border-radius: 0; background: #291d4760; }
  .mobile { display: grid; }
  .topbar { padding: 5px 12px; min-height: 52px; }
  .composer-wrap, .thread { padding-left: 12px; padding-right: 12px; }
}
@media (prefers-color-scheme: dark) {
  :root { color-scheme: dark; --page: #191824; --surface: #232130; --nav: #201e2c; --ink: #f4efff; --muted: #bfb6d5; --line: #423b54; --accent: #bba6ff; --soft: #36294f; }
  .auth { background: radial-gradient(ellipse at 50% 0, #342746, transparent 58%); }
  .primary, .send { color: #1e1034; }
  .primary:hover, .icon.send:hover:not(:disabled) { background: #cfbbff; }
  .new-chat, .avatar { border-color: var(--line); color: var(--ink); background: var(--soft); }
  .new-chat:hover, .history button:hover, .history button[aria-current], .icon:hover:not(:disabled), .delete:hover, .message-body pre, .message-body :not(pre) > code { background: #3a304d; }
  .topbar, .composer { border-color: var(--line); }
  .error, .status.error { color: #ffadbd; }
}
