:root {
  --bg: #f6f7f9; --panel: #ffffff; --text: #1d2330; --muted: #667085; --line: #e3e6ec;
  --accent: #4f46e5; --accent-fg: #ffffff; --user: #eef2ff; --bot: #ffffff; --danger: #d92d20; --code: #f1f3f7;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1218; --panel: #171b24; --text: #e8ebf2; --muted: #9aa4b5; --line: #2a3140; --accent: #7c83ff; --accent-fg: #0f1218; --user: #1e2540; --bot: #171b24; --danger: #ff6b5e; --code: #202636; }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.6 -apple-system, "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", sans-serif; display: flex; flex-direction: column; }
button, select, textarea, input { font: inherit; color: inherit; }
.top { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; }
.logo { color: var(--accent); font-size: 20px; }
.status { color: var(--muted); font-size: 13px; margin-left: 6px; }
.tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.field { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 14px; }
select, input[type=number], input[type=password], textarea { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
select { max-width: 52vw; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 8px 14px; }
button:focus-visible, select:focus-visible, textarea:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.ghost:hover { background: var(--code); }
button.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); font-weight: 600; }
button.danger { background: var(--danger); color: #fff; border-color: var(--danger); font-weight: 600; }
button:disabled { opacity: .5; cursor: not-allowed; }
.sys { padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.sys label { font-size: 13px; color: var(--muted); }
.sys textarea { width: 100%; margin: 6px 0; resize: vertical; }
.row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.row.end { justify-content: space-between; margin-top: 12px; }
.inline { display: inline-flex; gap: 6px; align-items: center; font-size: 14px; color: var(--muted); }
.inline input[type=number] { width: 90px; padding: 4px 8px; }
.log { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; scroll-behavior: smooth; }
.empty { margin: auto; text-align: center; max-width: 560px; color: var(--muted); }
.empty h1 { color: var(--text); font-size: 26px; margin: 0 0 8px; }
.msg { max-width: min(860px, 100%); width: fit-content; padding: 10px 14px; border: 1px solid var(--line); border-radius: 14px; white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--user); }
.msg.bot { align-self: flex-start; background: var(--bot); }
.msg.err { align-self: center; color: var(--danger); background: transparent; border-color: var(--danger); }
.msg .meta { display: block; margin-top: 6px; font-size: 12px; color: var(--muted); }
.msg pre { margin: 8px 0; padding: 10px 12px; background: var(--code); border-radius: 10px; overflow-x: auto; white-space: pre; font: 13.5px/1.5 ui-monospace, "Cascadia Mono", Consolas, monospace; }
.msg code.inline-code { background: var(--code); padding: 1px 5px; border-radius: 6px; font: 0.92em ui-monospace, Consolas, monospace; }
.msg details { margin: 4px 0 8px; color: var(--muted); font-size: 14px; }
.cursor::after { content: "▍"; animation: blink 1s steps(2) infinite; color: var(--accent); }
@keyframes blink { 50% { opacity: 0; } }
.composer { display: flex; gap: 8px; align-items: flex-end; padding: 10px 16px; padding-bottom: max(10px, env(safe-area-inset-bottom)); background: var(--panel); border-top: 1px solid var(--line); }
.composer textarea { flex: 1; resize: none; max-height: 40vh; min-height: 44px; line-height: 1.5; }
.composer button { min-height: 44px; }
dialog { border: 1px solid var(--line); border-radius: 16px; background: var(--panel); color: var(--text); padding: 20px; width: min(420px, 92vw); }
dialog::backdrop { background: rgba(0,0,0,.5); }
dialog h2 { margin: 0 0 6px; font-size: 18px; }
dialog p { margin: 4px 0 10px; color: var(--muted); font-size: 14px; }
dialog input[type=password] { width: 100%; }
.err { color: var(--danger) !important; }
@media (max-width: 560px) { .top { padding: 8px 12px; } .log { padding: 12px; } .composer { padding: 8px 12px; } .field span { display: none; } }
@media (prefers-reduced-motion: reduce) { .log { scroll-behavior: auto; } .cursor::after { animation: none; } }
