:root {
  --bg: #f7f7f5;
  --panel: #ffffff;
  --side: #efefec;
  --ink: #1b1b1a;
  --muted: #6b6b66;
  --line: #deded9;
  --accent: #2f4f6f;
  --accent-ink: #ffffff;
  --user: #e8ecf0;
  --code: #f0f0ec;
  --danger: #a33a2c;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161616;
    --panel: #1d1d1c;
    --side: #121212;
    --ink: #e8e8e4;
    --muted: #96968f;
    --line: #2e2e2c;
    --accent: #8fb0cf;
    --accent-ink: #10151a;
    --user: #24292e;
    --code: #262624;
    --danger: #e0806f;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #161616; --panel: #1d1d1c; --side: #121212; --ink: #e8e8e4; --muted: #96968f;
  --line: #2e2e2c; --accent: #8fb0cf; --accent-ink: #10151a; --user: #24292e; --code: #262624;
  --danger: #e0806f; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 28px; display: grid; gap: 14px;
}
.login-card h1 { margin: 0 0 4px; font-size: 20px; font-weight: 600; letter-spacing: .2px; }
label { display: grid; gap: 5px; font-size: 13px; color: var(--muted); }
input, select, textarea {
  border: 1px solid var(--line); background: var(--panel); border-radius: 7px; padding: 9px 11px;
  font-size: 15px; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
.msg { margin: 0; min-height: 1.2em; font-size: 13px; color: var(--danger); }

.btn-primary {
  background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 7px;
  padding: 9px 14px; font-weight: 500; cursor: pointer;
}
.login-card button[type=submit] { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 7px; padding: 10px; font-weight: 500; cursor: pointer; }
.link { background: none; border: 0; padding: 4px 0; color: var(--muted); cursor: pointer; font-size: 13px; }
.link:hover { color: var(--ink); }
.danger { color: var(--danger); }
.icon-btn {
  background: none; border: 0; width: 36px; height: 36px; display: grid; place-items: center;
  border-radius: 7px; cursor: pointer; color: var(--muted); flex: none;
}
.icon-btn:hover { background: var(--line); color: var(--ink); }

/* layout */
.app { display: flex; height: 100dvh; }
.side {
  width: 272px; flex: none; background: var(--side); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 12px; gap: 10px;
}
.side-head { display: flex; gap: 6px; }
.side-head .btn-primary { flex: 1; }
.proj-row { display: flex; gap: 4px; }
.proj-row select { flex: 1; min-width: 0; padding: 7px 9px; font-size: 14px; }
.chat-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 1px; margin: 0 -4px; }
.chat-item {
  display: flex; align-items: center; gap: 4px; padding: 7px 8px; border-radius: 6px;
  cursor: pointer; font-size: 14px; color: var(--ink);
}
.chat-item:hover { background: var(--line); }
.chat-item.on { background: var(--panel); box-shadow: inset 0 0 0 1px var(--line); }
.chat-item span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item button { opacity: 0; width: 26px; height: 26px; }
.chat-item:hover button, .chat-item.on button { opacity: 1; }
.chat-item svg { width: 15px; height: 15px; }
.side-foot { border-top: 1px solid var(--line); padding-top: 10px; font-size: 13px; color: var(--muted); }
.who { color: var(--ink); font-weight: 500; }
.srv { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.foot-btns { display: flex; justify-content: space-between; margin-top: 6px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.top {
  height: 52px; flex: none; display: flex; align-items: center; gap: 10px; padding: 0 16px;
  border-bottom: 1px solid var(--line); background: var(--panel);
}
.title { flex: 1; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status { font-size: 12px; color: var(--muted); white-space: nowrap; }
.status.off { color: var(--danger); }

.thread { flex: 1; overflow-y: auto; padding: 24px 16px 8px; }
.turn { max-width: 780px; margin: 0 auto 22px; }
.turn.user { display: flex; flex-direction: column; align-items: flex-end; }
.bubble { background: var(--user); border-radius: 12px; padding: 10px 14px; max-width: 85%; white-space: pre-wrap; word-wrap: break-word; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; justify-content: flex-end; }
.chip { font-size: 12px; border: 1px solid var(--line); border-radius: 6px; padding: 2px 8px; color: var(--muted); background: var(--panel); }
.chip img { display: block; max-height: 90px; max-width: 160px; border-radius: 4px; margin: 2px -4px; }
.chip.gone { font-style: italic; }

.answer { word-wrap: break-word; }
.answer p { margin: 0 0 .7em; }
.answer pre { background: var(--code); border: 1px solid var(--line); border-radius: 7px; padding: 10px 12px; overflow-x: auto; font-size: 13px; }
.answer code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .92em; }
.answer :not(pre) > code { background: var(--code); padding: 1px 5px; border-radius: 4px; }
.answer table { border-collapse: collapse; display: block; overflow-x: auto; margin: .5em 0; }
.answer th, .answer td { border: 1px solid var(--line); padding: 5px 9px; text-align: left; }
.answer a { color: var(--accent); }
.answer img { max-width: 100%; }
details.think { margin-bottom: 10px; border-left: 2px solid var(--line); padding-left: 10px; color: var(--muted); font-size: 14px; }
details.think summary { cursor: pointer; font-size: 13px; list-style: none; }
details.think summary::-webkit-details-marker { display: none; }
details.think .tbody { white-space: pre-wrap; margin-top: 6px; max-height: 340px; overflow-y: auto; }
.tools { display: flex; flex-direction: column; gap: 3px; margin-bottom: 8px; font-size: 13px; color: var(--muted); }
.tools div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meta { font-size: 12px; color: var(--muted); margin-top: 4px; display: flex; gap: 12px; }
.meta button { padding: 0; font-size: 12px; }
.err { color: var(--danger); font-size: 14px; }
.cursor::after { content: "▍"; animation: blink 1s steps(2) infinite; color: var(--muted); }
@keyframes blink { 50% { opacity: 0; } }
.empty { max-width: 780px; margin: 18vh auto 0; text-align: center; color: var(--muted); }
.empty h2 { color: var(--ink); font-weight: 500; font-size: 22px; margin: 0 0 6px; }

.composer-wrap { padding: 8px 16px calc(12px + env(safe-area-inset-bottom)); }
.atts { max-width: 780px; margin: 0 auto 6px; display: flex; flex-wrap: wrap; gap: 6px; }
.att { display: flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel); border-radius: 7px; padding: 4px 4px 4px 8px; font-size: 13px; max-width: 260px; }
.att img { height: 34px; width: 34px; object-fit: cover; border-radius: 4px; }
.att span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att .x { width: 24px; height: 24px; }
.att .x svg { width: 14px; height: 14px; }
.composer {
  max-width: 780px; margin: 0 auto; display: flex; align-items: flex-end; gap: 6px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 6px;
}
.composer:focus-within { border-color: var(--accent); }
.composer textarea { flex: 1; border: 0; resize: none; max-height: 220px; padding: 8px 4px; background: transparent; }
.send { background: var(--accent); color: var(--accent-ink); border: 0; width: 36px; height: 36px; border-radius: 8px; display: grid; place-items: center; cursor: pointer; flex: none; }
.send.stop svg { stroke-width: 0; fill: currentColor; }
.toggles { max-width: 780px; margin: 8px auto 0; display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; font-size: 13px; color: var(--muted); }
.toggles label { display: flex; align-items: center; gap: 5px; cursor: pointer; font-size: 13px; }
.toggles input { margin: 0; accent-color: var(--accent); }
.hint { margin-left: auto; font-size: 12px; }
.drop { outline: 2px dashed var(--accent); outline-offset: -8px; }

.dlg { border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--ink); padding: 0; width: min(480px, calc(100vw - 32px)); }
.dlg::backdrop { background: rgba(0,0,0,.35); }
.dlg-body { padding: 22px; display: grid; gap: 12px; }
.dlg-body h2 { margin: 0; font-size: 17px; font-weight: 600; }
.dlg-btns { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.sp { flex: 1; }

.info { margin: 0; font-size: 13px; color: var(--muted); }
.row { display: flex; gap: 6px; align-items: center; }
.row input { flex: 1; min-width: 0; }
.row select { padding: 8px 9px; font-size: 14px; }
.sec { border-top: 1px solid var(--line); padding-top: 12px; display: grid; gap: 8px; }
.sec-h { font-size: 13px; font-weight: 600; }
.list { display: grid; gap: 4px; max-height: 200px; overflow-y: auto; }
.list-item { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 4px 0; }
.list-item span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .tag { color: var(--muted); flex: none; }

.info code { font-size: 12px; background: var(--code); padding: 1px 5px; border-radius: 4px; }
.keyshow { font-size: 12px; background: var(--code); border: 1px solid var(--line); border-radius: 7px; padding: 8px 10px; word-break: break-all; display: grid; gap: 6px; }
.keyshow b { font-weight: 600; color: var(--danger); }

.sec.first { border-top: 0; padding-top: 0; }
.dlg-body { max-height: calc(100dvh - 48px); overflow-y: auto; }
.guest-note { max-width: 780px; margin: 6px auto 0; font-size: 12px; color: var(--muted); }

.only-mobile { display: none; }
@media (max-width: 760px) {
  .only-mobile { display: grid; }
  .side { position: fixed; inset: 0 auto 0 0; z-index: 10; transform: translateX(-100%); transition: transform .2s; width: 84vw; max-width: 320px; box-shadow: 0 0 40px rgba(0,0,0,.25); }
  .side.open { transform: none; }
  .top { padding: 0 8px; }
  .thread { padding: 16px 16px 8px; }
  .composer-wrap { padding-left: 10px; padding-right: 10px; }
  .hint { display: none; }
  .bubble { max-width: 92%; }
}

.note { font-size: 14px; color: var(--muted); border-left: 2px solid var(--accent); padding-left: 10px; margin-bottom: 8px; }

.main { position: relative; }
.warm { position: absolute; inset: 52px 0 auto 0; bottom: 120px; display: grid; place-items: center; background: color-mix(in srgb, var(--bg) 88%, transparent); z-index: 5; padding: 16px; }
.warm-card { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 26px 24px; text-align: center; display: grid; gap: 10px; justify-items: center; }
.spin { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.warm-t { font-weight: 600; font-size: 16px; }
.warm-s { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.warm-h { font-size: 12px; color: var(--muted); }
.bar { width: 100%; height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .8s ease; }
.warm.err .spin { animation: none; border-top-color: var(--danger); }

.tools { gap: 6px; }
.step { font-size: 13px; color: var(--muted); }
.step-h { display: flex; align-items: center; gap: 8px; min-width: 0; }
.step-l { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.step.done .step-l { color: var(--ink); }
.step-n { flex: none; font-size: 12px; color: var(--muted); }
.step-spin { flex: none; width: 13px; height: 13px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
.step-ok { flex: none; width: 13px; height: 13px; border-radius: 50%; background: var(--accent); position: relative; }
.step-ok::after { content: ""; position: absolute; left: 4px; top: 2px; width: 3px; height: 6px; border: solid var(--accent-ink); border-width: 0 1.6px 1.6px 0; transform: rotate(45deg); }
.step-src { display: flex; flex-wrap: wrap; gap: 4px; margin: 5px 0 2px 21px; }
.step-src a { font-size: 12px; color: var(--muted); text-decoration: none; border: 1px solid var(--line); border-radius: 5px; padding: 1px 7px; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.step-src a:hover { color: var(--accent); border-color: var(--accent); }

.phase { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--accent); margin-bottom: 8px; font-variant-numeric: tabular-nums; }
