:root {
  --bg: #f7f7f8; --panel: #ffffff; --text: #1d1d22; --muted: #6b6b76;
  --border: #e3e3e8; --accent: #4f46e5; --accent-text: #ffffff; --user: #eef0ff; --code: #f1f1f4;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131316; --panel: #1c1c21; --text: #ececf1; --muted: #9a9aa6;
    --border: #2c2c33; --accent: #818cf8; --accent-text: #111; --user: #262a45; --code: #26262d;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.55 system-ui, -apple-system, Segoe UI, sans-serif; background: var(--bg); color: var(--text);
  display: flex; flex-direction: column; height: 100dvh; }
header { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--panel); }
.brand { font-weight: 700; font-size: 18px; }
.brand span { font-weight: 400; color: var(--muted); font-size: 14px; margin-left: 6px; }
.controls { display: flex; gap: 10px; align-items: center; font-size: 13px; color: var(--muted); }
select { margin-left: 6px; padding: 4px 6px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg); color: var(--text); }
.pill { padding: 3px 10px; border-radius: 999px; border: 1px solid var(--border); }
.pill.demo { color: #b45309; border-color: #f59e0b; }
.pill.live { color: #047857; border-color: #10b981; }
main { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; max-width: 860px; width: 100%; margin: 0 auto; }
.empty { margin: auto; text-align: center; color: var(--muted); max-width: 560px; }
.empty h1 { color: var(--text); font-size: 24px; }
.msg { padding: 12px 14px; border-radius: 12px; background: var(--panel); border: 1px solid var(--border); overflow-wrap: anywhere; }
.msg.user { background: var(--user); align-self: flex-end; max-width: 85%; white-space: pre-wrap; }
.msg.error { border-color: #ef4444; color: #ef4444; }
.msg pre { background: var(--code); padding: 10px; border-radius: 8px; overflow-x: auto; }
.msg code { background: var(--code); padding: 1px 4px; border-radius: 4px; font-size: 13px; }
.msg pre code { background: none; padding: 0; }
.live-status { color: var(--muted); font-size: 13px; font-style: italic; }
details.trace { margin-top: 10px; font-size: 13px; color: var(--muted); }
details.trace summary { cursor: pointer; }
.step { border-left: 3px solid var(--accent); padding: 4px 10px; margin: 8px 0; }
.step .who { font-weight: 600; color: var(--text); }
.step .out { white-space: pre-wrap; max-height: 180px; overflow-y: auto; margin-top: 4px; }
form { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); background: var(--panel);
  max-width: 860px; width: 100%; margin: 0 auto; }
textarea { flex: 1; resize: none; padding: 10px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font: inherit; }
button { padding: 0 18px; border: 0; border-radius: 10px; background: var(--accent); color: var(--accent-text); font-weight: 600; cursor: pointer; }
button:disabled { opacity: .5; cursor: wait; }
.sources { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 10px; }
.source { display: flex; gap: 6px; align-items: baseline; max-width: 260px; padding: 6px 10px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--bg); color: var(--text); text-decoration: none; font-size: 12px; }
.source:hover { border-color: var(--accent); }
.source b { color: var(--accent); }
.source span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source small { color: var(--muted); display: block; }
a.cite { font-size: 11px; vertical-align: super; text-decoration: none; color: var(--accent); font-weight: 600; padding: 0 1px; }
button.small { padding: 5px 14px; font-size: 13px; }
button.link { background: none; color: var(--accent); padding: 0; font-weight: 500; }
#account { display: inline-flex; gap: 8px; align-items: center; }
#account[hidden] { display: none; }
#user-email { color: var(--text); max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
dialog#signin { width: min(380px, calc(100vw - 32px)); border: 1px solid var(--border); border-radius: 14px;
  background: var(--panel); color: var(--text); padding: 20px 22px; }
dialog#signin::backdrop { background: rgb(0 0 0 / .45); }
dialog#signin h2 { font-size: 18px; margin: 0 0 14px; }
dialog#signin form { display: flex; flex-direction: column; gap: 10px; padding: 0; border: 0; max-width: none; margin: 0; background: none; }
dialog#signin .close-row { flex-direction: row; justify-content: flex-end; margin: -8px -8px 0 0; }
dialog#signin label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
dialog#signin input { padding: 9px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font: inherit; }
dialog#signin button[type=submit], button.oauth { padding: 10px; }
#oauth-buttons { display: flex; flex-direction: column; gap: 8px; }
button.oauth { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
button.oauth:hover { border-color: var(--accent); }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; margin: 14px 0; }
.divider[hidden] { display: none; }
.divider::before, .divider::after { content: ''; flex: 1; border-top: 1px solid var(--border); }
.auth-msg { font-size: 13px; min-height: 1em; margin: 10px 0 0; color: var(--muted); }
.auth-msg.error { color: #ef4444; }
.auth-links { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-size: 13px; margin: 6px 0 0; }
.auth-links .soon { color: var(--muted); opacity: .55; cursor: not-allowed; user-select: none; }
form.locked textarea { cursor: pointer; }
/* Chat list sidebar */
#layout { flex: 1; display: flex; min-height: 0; }
#pane { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#sidebar { width: 260px; flex-shrink: 0; display: flex; flex-direction: column; gap: 10px; padding: 12px;
  border-right: 1px solid var(--border); background: var(--panel); overflow-y: auto; }
#sidebar[hidden] { display: none; }
button.new-chat { padding: 9px 12px; text-align: left; }
#chat-list { display: flex; flex-direction: column; gap: 2px; }
.side-note { color: var(--muted); font-size: 13px; margin: 6px 4px; }
.chat-item { display: flex; align-items: center; border-radius: 8px; }
.chat-item:hover, .chat-item.active { background: var(--bg); }
.chat-item.active .open { font-weight: 600; }
.chat-item .open { flex: 1; min-width: 0; text-align: left; background: none; color: var(--text); font-weight: 400;
  padding: 8px 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.chat-item .mini { background: none; color: var(--muted); padding: 4px 6px; font-size: 14px; visibility: hidden; }
.chat-item:hover .mini, .chat-item.active .mini, .chat-item .mini:focus-visible { visibility: visible; }
.chat-item .mini:hover { color: var(--text); }
.icon-btn { display: none; background: none; color: var(--text); padding: 2px 8px; font-size: 20px; }
@media (max-width: 760px) {
  .icon-btn:not([hidden]) { display: inline-block; }
  #sidebar { position: fixed; top: 0; bottom: 0; left: 0; z-index: 20; width: min(280px, 85vw);
    transform: translateX(-100%); transition: transform .2s ease; }
  body.side-open #sidebar { transform: none; box-shadow: 0 0 24px rgb(0 0 0 / .25); }
  .brand span, #status { display: none; }
  header { flex-wrap: nowrap; }
  .controls { gap: 8px; }
  .controls label { font-size: 0; }
  .controls select { max-width: 110px; margin-left: 0; font-size: 13px; }
  .brand { font-size: 16px; white-space: nowrap; }
  #user-email { display: none; }
  .chat-item .mini { visibility: visible; }
}
