:root {
  --bg: #f6f6f4; --panel: #ffffff; --text: #1d1d1b; --muted: #6b6b66; --line: #e2e2dd;
  --accent: #1f6feb; --accent-text: #ffffff; --user: #e6efff; --tool: #f0f0ec;
  --warn-bg: #fff4d6; --warn-line: #e0b84a; --danger: #c0362c; --ok: #1f8a4c;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161615; --panel: #20201e; --text: #ecece8; --muted: #a0a09a; --line: #33332f;
    --accent: #5b9bff; --accent-text: #0d1520; --user: #1e2c44; --tool: #292926;
    --warn-bg: #3a2f10; --warn-line: #8f7426; --danger: #ff7b6e; --ok: #55c98a;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
#app { max-width: 760px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }
button, select, textarea, input { font: inherit; color: inherit; }
button { min-height: 44px; padding: 0 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); cursor: pointer; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.danger { color: var(--danger); }
button:disabled { opacity: .55; cursor: default; }
button:focus-visible, select:focus-visible, textarea:focus-visible, input:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
select, input, textarea { width: 100%; min-height: 44px; padding: 10px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
a { color: var(--accent); }

.bar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px; padding: 8px 16px; background: var(--bg); border-bottom: 1px solid var(--line); }
.bar h1 { flex: 1; min-width: 0; margin: 0; font-size: 16px; font-weight: 600; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.bar > button { flex: none; max-width: 38%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 14px; }
.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.tabs button { flex: 1 0 auto; border: 0; background: transparent; color: var(--muted); padding: 0 10px; }
.tabs button[aria-current="page"] { color: var(--text); font-weight: 600; box-shadow: inset 0 -2px 0 var(--accent); border-radius: 0; }

.pad { padding: 12px 16px; display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 8px; align-items: center; }
.row > .grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); font-size: 14px; }
.list { list-style: none; margin: 0; padding: 0 16px 24px; display: flex; flex-direction: column; gap: 8px; }
.chat-item { width: 100%; display: block; text-align: left; padding: 10px 12px; height: auto; }
.chat-item strong { display: block; font-weight: 500; overflow-wrap: anywhere; }

.messages { flex: 1; padding: 12px 16px; display: flex; flex-direction: column; gap: 10px; }
.msg { padding: 10px 12px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user { background: var(--user); border-color: transparent; align-self: flex-end; max-width: 92%; }
.msg.tool { background: var(--tool); border-color: transparent; font-size: 14px; padding: 6px 10px; }
.msg.tool summary { cursor: pointer; min-height: 32px; display: list-item; overflow-wrap: anywhere; }
.msg pre { margin: 6px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; font: 13px/1.4 ui-monospace, Consolas, monospace; }
.status-failed { color: var(--danger); }

.dock { position: sticky; bottom: 0; background: var(--bg); border-top: 1px solid var(--line); padding: 8px 16px calc(8px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 8px; }
.dock textarea { min-height: 48px; max-height: 40vh; resize: vertical; }
.notice { padding: 10px 12px; border-radius: 10px; background: var(--warn-bg); border: 1px solid var(--warn-line); }
.notice pre { margin: 6px 0 8px; white-space: pre-wrap; overflow-wrap: anywhere; font: 13px/1.4 ui-monospace, Consolas, monospace; }
.running { color: var(--ok); font-size: 14px; }

.sheet { position: fixed; inset: 0; z-index: 10; background: rgba(0, 0, 0, .45); display: flex; align-items: flex-end; justify-content: center; }
.sheet > div { width: 100%; max-width: 760px; max-height: 80vh; overflow-y: auto; background: var(--bg); border-radius: 14px 14px 0 0; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.sheet h2 { margin: 0 0 4px; font-size: 16px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.card h2 { margin: 0; font-size: 16px; }
.meter { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--accent); }
.kv { display: flex; justify-content: space-between; gap: 12px; font-variant-numeric: tabular-nums; }
.kv span:first-child { color: var(--muted); overflow-wrap: anywhere; }

#toast { position: fixed; left: 16px; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 20; max-width: 728px; margin: 0 auto; padding: 12px 14px; border-radius: 10px; background: var(--text); color: var(--bg); }
.login { margin: auto; width: 100%; max-width: 360px; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.login h1 { margin: 0; font-size: 20px; }
input.check { width: 22px; min-height: 22px; flex: none; }
[hidden] { display: none !important; }
