:root {
  --bg: #f6f7f9; --panel: #ffffff; --fg: #15171c; --muted: #6b7280; --line: #e3e5ea;
  --accent: #2f6df6; --accent-fg: #fff; --user: #eaf0ff; --code: #f1f3f6; --danger: #d23b3b; --ok: #1f9d55; --warn: #e5484d;
  --radius: 12px; --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111317; --panel: #1a1d23; --fg: #e8eaee; --muted: #9aa1ad; --line: #2a2e36;
    --accent: #5b8cff; --user: #1f2a44; --code: #0d0f13;
  }
}
:root[data-theme="dark"] {
  --bg: #111317; --panel: #1a1d23; --fg: #e8eaee; --muted: #9aa1ad; --line: #2a2e36;
  --accent: #5b8cff; --user: #1f2a44; --code: #0d0f13;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); font: 15px/1.45 var(--font); -webkit-text-size-adjust: 100%; }
#app { display: flex; flex-direction: column; height: 100dvh; max-width: 900px; margin: 0 auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
button { font: inherit; color: inherit; }
.bar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--panel); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; min-width: 0; }
.brand span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ready { background: var(--ok); } .dot.loading { background: #e7a614; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.spacer { flex: 1; }
.icon { background: none; border: 0; font-size: 18px; width: 36px; height: 36px; border-radius: 10px; cursor: pointer; flex: none; }
.icon:hover, .icon:focus-visible { background: var(--code); }
.pill { border-radius: 999px; padding: 3px 10px; font-size: 12px; border: 0; }
.pill.screen { background: var(--warn); color: #fff; font-weight: 600; cursor: pointer; white-space: nowrap; }
.pill.offline { background: var(--code); color: var(--muted); }

#log { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; overscroll-behavior: contain; }
.msg { max-width: 100%; padding: 9px 12px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line); overflow-wrap: anywhere; }
.msg.user { background: var(--user); border-color: transparent; align-self: flex-end; max-width: 88%; white-space: pre-wrap; }
.msg.tool { font-family: var(--mono); font-size: 13px; white-space: pre-wrap; }
.msg.tool.fail { border-color: var(--danger); }
.msg.err { border-color: var(--danger); color: var(--danger); }
.msg .meta { font-size: 11px; color: var(--muted); margin-top: 6px; font-family: var(--font); }
.msg p { margin: 0 0 8px; } .msg p:last-child { margin-bottom: 0; }
.msg code { font-family: var(--mono); font-size: 13px; background: var(--code); padding: 1px 4px; border-radius: 4px; }
.codeblock { position: relative; margin: 8px 0; }
.codeblock pre { white-space: pre; overflow-wrap: normal; margin: 0; background: var(--code); padding: 10px; border-radius: 8px; overflow-x: auto; font: 13px/1.4 var(--mono); }
.codeblock .tools { display: flex; gap: 6px; justify-content: flex-end; margin-top: 4px; }
.codeblock .tools button { font-size: 12px; padding: 3px 8px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; }
.empty { margin: auto; text-align: center; color: var(--muted); max-width: 420px; font-size: 14px; }
.empty kbd, .muted kbd { font-family: var(--mono); font-size: 12px; border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }

.status { padding: 4px 14px; font-size: 12px; color: var(--muted); }
#composer { display: flex; align-items: flex-end; gap: 6px; padding: 8px 10px 10px; border-top: 1px solid var(--line); background: var(--panel); }
#input { flex: 1; resize: none; border: 1px solid var(--line); border-radius: 18px; padding: 8px 14px; font: 16px/1.35 var(--font);
  background: var(--bg); color: var(--fg); max-height: 40vh; outline: none; }
#input:focus { border-color: var(--accent); }
.send { width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-fg); font-size: 18px; cursor: pointer; flex: none; }
.send.stop { background: var(--danger); }

dialog { border: 1px solid var(--line); border-radius: 16px; background: var(--panel); color: var(--fg); padding: 16px; width: min(560px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.35); }
#settingsDlg { max-height: calc(100dvh - 32px); padding: 0; }
.sheet { padding: 16px; }
.sheet section { border-top: 1px solid var(--line); padding: 12px 0; }
h2 { margin: 0; font-size: 18px; } h3 { margin: 0 0 8px; font-size: 15px; }
.row { display: flex; align-items: center; gap: 8px; margin: 6px 0; } .row.end { justify-content: flex-end; } .row.wrap { flex-wrap: wrap; }
label.row { justify-content: space-between; }
.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 6px 12px; cursor: pointer; }
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }
select, input:not([type]), input[type=text], .sheet textarea { font: 16px var(--font); background: var(--bg); color: var(--fg); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }
.sheet textarea, #modelSelect { width: 100%; }
pre { white-space: pre-wrap; overflow-wrap: anywhere; font-family: var(--mono); }
#confirmBody { max-height: 45vh; overflow: auto; background: var(--code); padding: 10px; border-radius: 8px; font-size: 13px; }
.muted { color: var(--muted); } .small { font-size: 12px; }
.progress { height: 6px; background: var(--code); border-radius: 3px; overflow: hidden; margin-top: 8px; }
.progress div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.toolrow { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; align-items: center; padding: 4px 0; border-bottom: 1px dashed var(--line); }
.toolrow .d { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }
.note { padding: 4px 0; border-bottom: 1px dashed var(--line); display: flex; gap: 8px; }
.note div { flex: 1; min-width: 0; }
@media (max-width: 420px) { .bar { padding: 6px 8px; } #log { padding: 8px; } }
