:root {
  --bg: #f6f7f9; --panel: #ffffff; --text: #16181d; --muted: #5d6573; --line: #e2e5ea;
  --accent: #dc244c; --accent-text: #ffffff; --ok: #1a7f4b; --warn: #a15c00; --bad: #c62828;
  --user: #e9eefc; --code: #f1f3f6; --chip: #eef0f3;
  --radius: 12px; --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115; --panel: #171a21; --text: #e7e9ee; --muted: #9aa3b2; --line: #2a2f3a;
    --accent: #ff4d6d; --accent-text: #16181d; --ok: #4cc38a; --warn: #f0b429; --bad: #ff6b6b;
    --user: #1e2638; --code: #11141a; --chip: #232835;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1115; --panel: #171a21; --text: #e7e9ee; --muted: #9aa3b2; --line: #2a2f3a;
  --accent: #ff4d6d; --accent-text: #16181d; --ok: #4cc38a; --warn: #f0b429; --bad: #ff6b6b;
  --user: #1e2638; --code: #11141a; --chip: #232835;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%; }
a { color: var(--accent); }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 8px 14px; min-height: 40px; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.danger { color: var(--bad); }
button:disabled { opacity: .5; cursor: default; }
input, textarea { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%; font-size: 16px; }
.wrap { max-width: 760px; margin: 0 auto; padding: 0 16px; }
header.bar { position: sticky; top: 0; z-index: 5; background: var(--bg); border-bottom: 1px solid var(--line);
  padding: calc(env(safe-area-inset-top) + 8px) 0 8px; }
header.bar .wrap { display: flex; align-items: center; gap: 10px; }
header.bar h1 { font-size: 17px; margin: 0; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
header.bar .who { color: var(--muted); font-size: 13px; }
.icon { min-width: 40px; padding: 8px 10px; }
.login { max-width: 380px; margin: 12vh auto 0; padding: 0 16px; display: grid; gap: 12px; }
.login h1 { margin: 0 0 8px; font-size: 24px; }
.login .or { text-align: center; color: var(--muted); font-size: 14px; }
.err { color: var(--bad); font-size: 14px; }
.note { color: var(--muted); font-size: 14px; }
section h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 22px 0 8px; }
.card { display: block; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px;
  margin-bottom: 10px; text-decoration: none; color: inherit; }
.card .top { display: flex; gap: 8px; align-items: baseline; font-size: 13px; color: var(--muted); }
.card .title { font-weight: 600; margin: 2px 0; overflow-wrap: anywhere; }
.card .prop { font-size: 14px; color: var(--muted); overflow-wrap: anywhere; }
.badge { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 99px; background: var(--chip); color: var(--muted); }
.badge.ready { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.badge.active { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }
.badge.failed { color: var(--bad); }
.spin { display: inline-block; width: 10px; height: 10px; border: 2px solid var(--muted); border-right-color: transparent; border-radius: 50%;
  animation: spin 1s linear infinite; vertical-align: -1px; }
@keyframes spin { to { transform: rotate(360deg); } }
.row { display: flex; gap: 8px; }
.banner { background: color-mix(in srgb, var(--warn) 15%, var(--panel)); border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent);
  border-radius: var(--radius); padding: 10px 12px; font-size: 14px; margin-top: 14px; overflow-wrap: anywhere; }

/* chat */
.chat { display: flex; flex-direction: column; height: 100dvh; }
.log { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 12px 0 20px; }
.msg { margin: 10px 0; overflow-wrap: anywhere; }
.msg .who { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.msg.user { display: flex; flex-direction: column; align-items: flex-end; }
.msg.user .body { background: var(--user); border-radius: 14px 14px 4px 14px; padding: 8px 12px; max-width: 88%; white-space: pre-wrap; }
.msg.assistant .body { background: var(--panel); border: 1px solid var(--line); border-radius: 4px 14px 14px 14px; padding: 4px 14px; }
.md p { margin: 8px 0; } .md ul, .md ol { padding-left: 20px; margin: 8px 0; }
.md blockquote { margin: 8px 0; padding: 4px 12px; border-left: 3px solid var(--accent); background: var(--code); border-radius: 0 8px 8px 0; }
.md pre { background: var(--code); padding: 10px; border-radius: 8px; overflow-x: auto; font-size: 13px; }
.md code { font-family: var(--mono); font-size: 13px; background: var(--code); padding: 1px 4px; border-radius: 4px; }
.md pre code { padding: 0; background: none; }
.md table { border-collapse: collapse; display: block; overflow-x: auto; font-size: 14px; margin: 8px 0; }
.md td, .md th { border: 1px solid var(--line); padding: 4px 8px; vertical-align: top; text-align: left; }
.md h1, .md h2, .md h3 { font-size: 16px; margin: 12px 0 6px; }
details.tool { margin: 4px 0; font-size: 13px; }
details.tool summary { color: var(--muted); font-family: var(--mono); cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  list-style: none; padding: 2px 0; }
details.tool summary::before { content: "▸ "; }
details.tool[open] summary::before { content: "▾ "; }
details.tool.err summary { color: var(--bad); }
details.tool pre { background: var(--code); padding: 8px; border-radius: 8px; overflow-x: auto; max-height: 50vh; white-space: pre-wrap;
  font-size: 12px; margin: 4px 0; }
.perm { background: var(--panel); border: 2px solid var(--warn); border-radius: var(--radius); padding: 10px 12px; margin: 10px 0; }
.perm pre { font-family: var(--mono); font-size: 13px; white-space: pre-wrap; background: var(--code); padding: 8px; border-radius: 8px; margin: 6px 0; max-height: 40vh; overflow: auto; }
.perm .row { flex-wrap: wrap; }
.perm.decided { border-color: var(--line); }
.sys { font-size: 13px; color: var(--muted); text-align: center; margin: 8px 0; }
.sys.bad { color: var(--bad); text-align: left; white-space: pre-wrap; font-family: var(--mono); font-size: 12px; }
.live { white-space: pre-wrap; }
footer.compose { border-top: 1px solid var(--line); background: var(--bg); padding: 8px 0 calc(env(safe-area-inset-bottom) + 8px); }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; scrollbar-width: none; }
.chips button { background: var(--chip); border: 0; border-radius: 99px; padding: 4px 12px; min-height: 32px; font-size: 14px; white-space: nowrap; }
.compose .row textarea { resize: none; max-height: 40vh; min-height: 44px; line-height: 22px; }
.md td:first-child { white-space: nowrap; color: var(--muted); }
.compose .row button { flex: none; }
.status { font-size: 13px; color: var(--muted); min-height: 20px; }

/* audit */
.audit { font-size: 13px; }
.audit .e { border-bottom: 1px solid var(--line); padding: 8px 0; overflow-wrap: anywhere; }
.audit .e b { font-weight: 600; }
.audit .d { font-family: var(--mono); color: var(--muted); white-space: pre-wrap; font-size: 12px; }
