:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --text: #1c1e24;
  --muted: #6b7280;
  --line: #e3e5ea;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --user-bubble: #dbe7ff;
  --danger: #dc2626;
  --code-bg: #f0f1f4;
  --chip: #eef0f4;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111318;
    --panel: #1a1d24;
    --text: #e6e8ee;
    --muted: #8b93a3;
    --line: #2a2e38;
    --accent: #4f8cff;
    --accent-text: #ffffff;
    --user-bubble: #22355e;
    --danger: #f87171;
    --code-bg: #0e1015;
    --chip: #232733;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Noto Sans CJK SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
button { font: inherit; cursor: pointer; border: 0; border-radius: 10px; background: var(--chip); color: var(--text); padding: 8px 12px; }
button.primary { background: var(--accent); color: var(--accent-text); }
button.danger { background: var(--danger); color: #fff; }
button.ghost { background: transparent; color: var(--muted); }
button.icon { width: 40px; height: 40px; padding: 0; font-size: 18px; background: transparent; }
button.small-btn { padding: 6px 10px; font-size: 13px; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%;
}
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); min-height: 1.2em; margin: 6px 0 0; }
.row { display: flex; gap: 8px; align-items: center; }
.row > * { min-width: 0; }

.view { height: 100%; }

/* login */
#login { display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px 24px; display: grid; gap: 12px; }
.login-card p { margin: 0; }
.login-logo { display: flex; justify-content: center; margin: 4px 0 8px; }
.login-logo img { width: 240px; height: auto; }
.center { text-align: center; }
.empty-logo { width: 230px; max-width: 70vw; height: auto; margin-bottom: 8px; opacity: .95; }

/* app frame */
#app { display: grid; grid-template-rows: auto auto 1fr auto; height: 100%; }

/* usage strip */
.usage-strip { display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: center; width: 100%; padding: 5px 12px; border-radius: 0; background: var(--panel); border-bottom: 1px solid var(--line); font-size: 11.5px; color: var(--muted); text-align: left; }
.usage-cell { display: inline-flex; align-items: center; gap: 6px; }
.usage-label { white-space: nowrap; }
.usage-bar { width: 64px; height: 6px; border-radius: 3px; background: var(--chip); overflow: hidden; }
.usage-fill { display: block; height: 100%; width: 0; background: var(--accent); transition: width .4s; }
.usage-fill.warn { background: #f59e0b; }
.usage-fill.full { background: var(--danger); }
.usage-num { min-width: 48px; font-variant-numeric: tabular-nums; color: var(--text); }
.usage-note { flex: 1; min-width: 120px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar { display: flex; align-items: center; gap: 6px; padding: 8px 8px; padding-top: calc(8px + env(safe-area-inset-top)); background: var(--panel); border-bottom: 1px solid var(--line); }
.topbar-title { flex: 1; min-width: 0; text-align: center; }
#thread-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.messages { overflow-y: auto; padding: 12px 12px 8px; display: flex; flex-direction: column; gap: 12px; scroll-behavior: smooth; }
.empty { margin: auto; text-align: center; padding: 40px 16px; }
.empty p { margin: 4px 0; }

.msg { max-width: 92%; }
.msg.user { align-self: flex-end; background: var(--user-bubble); border-radius: 16px 16px 4px 16px; padding: 10px 14px; white-space: pre-wrap; word-break: break-word; }
.msg.assistant { align-self: stretch; max-width: 100%; display: grid; gap: 8px; }

.item { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; word-break: break-word; }
.item.agent p { margin: 0 0 8px; white-space: pre-wrap; }
.item.agent p:last-child { margin-bottom: 0; }
.item pre { margin: 8px 0 0; padding: 10px; background: var(--code-bg); border-radius: 8px; overflow-x: auto; font: 12.5px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre; }
.item.step { padding: 8px 12px; }
.item.step summary { cursor: pointer; list-style: none; display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 13px; }
.item.step summary::-webkit-details-marker { display: none; }
.item.step .label { color: var(--text); font-weight: 500; }
.item.step .cmd { font-family: ui-monospace, Menlo, monospace; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.item.step .badge { font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--chip); }
.item.step .badge.ok { color: #16a34a; }
.item.step .badge.bad { color: var(--danger); }
.item.step .badge.run { color: var(--accent); }
.item.reasoning { color: var(--muted); font-size: 13px; white-space: pre-wrap; }
.item.err { border-color: var(--danger); color: var(--danger); }
.status { font-size: 12px; color: var(--muted); padding: 0 4px; }
.status.running::before { content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 6px; border-radius: 50%; background: var(--accent); animation: pulse 1s infinite; }
@keyframes pulse { 0%, 100% { opacity: .3; } 50% { opacity: 1; } }

.composer { display: flex; gap: 8px; align-items: flex-end; padding: 8px 10px; padding-bottom: calc(8px + env(safe-area-inset-bottom)); background: var(--panel); border-top: 1px solid var(--line); }
.composer textarea { flex: 1; resize: none; max-height: 40vh; line-height: 1.4; }
.composer button { height: 42px; white-space: nowrap; }

/* drawer */
.drawer { position: fixed; inset: 0 auto 0 0; width: min(86vw, 340px); background: var(--panel); border-right: 1px solid var(--line); z-index: 20; display: grid; grid-template-rows: auto auto auto 1fr auto; padding-top: env(safe-area-inset-top); }
select.effort { flex: 0 0 110px; }
.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 10; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 8px 16px; font-weight: 600; border-bottom: 1px solid var(--line); }
.drawer-section { padding: 12px 12px 8px; display: grid; gap: 8px; border-bottom: 1px solid var(--line); }
.drawer-foot { padding: 8px 12px; padding-bottom: calc(8px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.thread-list { list-style: none; margin: 0; padding: 6px 0; overflow-y: auto; }
.thread-list li { display: flex; align-items: center; gap: 6px; padding: 10px 8px 10px 16px; border-bottom: 1px solid var(--line); }
.thread-list li.active { background: var(--chip); }
.thread-list .t-main { flex: 1; min-width: 0; cursor: pointer; }
.thread-list .t-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-list .t-sub { font-size: 12px; color: var(--muted); }
.thread-list .t-del { color: var(--muted); background: transparent; padding: 6px 8px; }

@media (min-width: 900px) {
  #app { max-width: 860px; margin: 0 auto; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}
