:root {
  color-scheme: light dark;
  --fg: #16181a; --bg: #f6f6f4; --dim: #6b6f73; --line: #dcdcd8; --panel: #ecece8;
  --you: #e3e9ef; --accent: #c2304a; --accent-fg: #fff; --ok: #1f8a4c; --bad: #c2304a; --warn: #b07a12;
  --code: #e8e8e3;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fg: #e6e7e8; --bg: #0d0f10; --dim: #8a8f94; --line: #23272a; --panel: #131618;
    --you: #1a2128; --accent: #ff8093; --accent-fg: #1a0a0d; --ok: #5fd38d; --bad: #ff8093; --warn: #e2b35a;
    --code: #171a1c;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 15px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; }
button, select, textarea, input { font: inherit; color: inherit; }
/* Author display rules (.request is a grid, its labels too) beat the UA's [hidden] style,
   so hidden elements stayed on screen. Make hidden mean hidden everywhere. */
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.shell { display: grid; grid-template-columns: 260px 1fr; height: 100dvh; }

/* sidebar */
.sidebar { display: flex; flex-direction: column; background: var(--panel); border-right: 1px solid var(--line); min-height: 0; }
.side-top { padding: 14px; display: grid; gap: 12px; padding-top: calc(14px + env(safe-area-inset-top, 0px)); }
.crumb { color: var(--dim); text-decoration: none; font-size: 13px; }
.crumb:hover { color: var(--fg); }
.chats { flex: 1; overflow-y: auto; padding: 0 8px; }
.chat-item { display: flex; align-items: center; gap: 4px; border-radius: 6px; }
.chat-item a { flex: 1; min-width: 0; padding: 7px 8px; color: var(--fg); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; }
.chat-item:hover, .chat-item.active { background: var(--bg); }
.chat-item .del { opacity: 0; border: 0; background: none; color: var(--dim); cursor: pointer; padding: 4px 8px; }
.chat-item:hover .del, .chat-item.active .del, .chat-item .del:focus-visible { opacity: 1; }
.chat-item .del.armed { color: var(--bad); }
.side-foot { padding: 12px 14px; border-top: 1px solid var(--line); display: grid; gap: 4px; font-size: 12px; color: var(--dim); padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }
.status { display: inline-flex; align-items: center; gap: 8px; }
.status i { width: 8px; height: 8px; border-radius: 50%; background: var(--dim); }
.status[data-state="online"] i { background: var(--ok); }
.status[data-state="offline"] i, .status[data-state="error"] i { background: var(--bad); }
.status[data-state="checking"] i, .status[data-state="partial"] i { background: var(--warn); }
.who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* main */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.bar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; padding-top: calc(10px + env(safe-area-inset-top, 0px)); }
.bar h1 { font-size: 16px; margin: 0; margin-right: auto; }
.model { min-width: 0; }
.model select { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; max-width: 60vw; text-overflow: ellipsis; }
.think { font-size: 13px; color: var(--dim); display: inline-flex; gap: 6px; align-items: center; }

.btn { border: 1px solid var(--line); background: var(--bg); border-radius: 6px; padding: 7px 14px; cursor: pointer; }
.btn:hover { border-color: var(--dim); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.btn.icon { display: none; padding: 4px 10px; }

.log { flex: 1; overflow-y: auto; padding: 24px 16px; }
.log > * { max-width: 760px; margin-left: auto; margin-right: auto; }
.empty { color: var(--dim); margin-top: 12vh; }
.empty .big { color: var(--fg); font-size: 1.4rem; margin: 0 0 8px; }

.msg { margin-bottom: 22px; }
.msg .role { font-size: 12px; color: var(--dim); margin-bottom: 4px; display: flex; gap: 8px; }
.msg.user .body { background: var(--you); border-radius: 8px; padding: 10px 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.assistant .body { overflow-wrap: anywhere; }
.msg .body p { margin: 0 0 .8em; }
.msg .body p:last-child { margin-bottom: 0; }
.msg .body ul, .msg .body ol { margin: 0 0 .8em; padding-left: 1.5em; }
.msg .body h2, .msg .body h3, .msg .body h4 { font-size: 1em; margin: 1em 0 .4em; }
.msg .body code { background: var(--code); border-radius: 4px; padding: 1px 5px; font-size: .92em; }
.msg .body pre { background: var(--code); border: 1px solid var(--line); border-radius: 8px; padding: 12px; overflow-x: auto; margin: 0 0 .8em; position: relative; }
.msg .body pre code { background: none; padding: 0; }
.msg .body pre .copy { position: absolute; top: 6px; right: 6px; font-size: 11px; padding: 2px 8px; }
.msg .body a { color: var(--accent); }
.msg .error { color: var(--bad); }
.msg .meta { font-size: 11px; color: var(--dim); margin-top: 6px; }
.cursor::after { content: "▍"; animation: blink 1s steps(2) infinite; color: var(--dim); }
@keyframes blink { 50% { opacity: 0; } }

details.thinking { border-left: 2px solid var(--line); padding-left: 12px; margin-bottom: 10px; color: var(--dim); font-size: 13px; }
details.thinking summary { cursor: pointer; user-select: none; }
details.thinking .t { white-space: pre-wrap; margin-top: 6px; }

.notice { max-width: 760px; margin: 0 auto 8px; width: calc(100% - 32px); padding: 10px 14px; border: 1px solid var(--bad); border-radius: 8px; font-size: 13px; }
.notice a { color: var(--accent); }

.quota { max-width: 760px; margin: 0 auto; width: calc(100% - 32px); font-size: 12px; color: var(--dim); text-align: right; }
.quota[data-low] { color: var(--warn); }
.dim { color: var(--dim); }
.request { max-width: 760px; margin: 0 auto 8px; width: calc(100% - 32px); padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); display: grid; gap: 8px; font-size: 13px; }
.request p { margin: 0; }
.request label { display: grid; gap: 4px; }
.request input, .request textarea { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 7px 10px; resize: vertical; }
.request-actions { display: flex; gap: 10px; align-items: center; }
.composer { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; padding: 12px 16px; border-top: 1px solid var(--line); padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }
.composer textarea { flex: 1; min-width: 0; resize: none; max-height: 40vh; min-height: 44px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; line-height: 1.45; }
.composer .btn { min-height: 44px; }
.composer .keys { flex-basis: 100%; margin: 0; font-size: 11px; color: var(--dim); }
.composer textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 25% 0 0; z-index: 10; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.4); }
  .btn.icon { display: inline-block; }
  .bar h1 { margin-right: 0; }
  .model { margin-left: auto; }
}
/* Touch: no Shift+Enter, so Enter is a newline and Send sends; 16px inputs stop iOS zooming on focus. */
@media (pointer: coarse) {
  .composer .keys { display: none; }
  .composer textarea, .request input, .request textarea, .model select { font-size: 16px; }
}
@media (prefers-reduced-motion: reduce) { .sidebar { transition: none; } .cursor::after { animation: none; } }
