:root {
  --bg: #0e1015; --panel: #161921; --panel-2: #1d212b; --line: #2a2f3b; --text: #e7e9ee; --muted: #9aa1b2;
  --accent: #d97757; --accent-2: #f0a37f; --ok: #4fbf8a; --err: #ef6b6b; --radius: 12px;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root { --bg: #f6f5f1; --panel: #ffffff; --panel-2: #f1efe9; --line: #e1ddd3; --text: #1f1e1c; --muted: #6b675f; color-scheme: light; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; height: 100vh; display: flex; flex-direction: column; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.error { color: var(--err); min-height: 1.2em; }

/* Top bar */
.topbar { display: flex; align-items: center; gap: 16px; padding: 10px 18px; border-bottom: 1px solid var(--line); background: var(--panel); }
.brand { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.logo { color: var(--accent); }
.spend { display: flex; gap: 6px; align-items: center; margin-left: auto; flex-wrap: wrap; }
.pill { background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; font-variant-numeric: tabular-nums; }
.pill b { color: var(--muted); font-weight: 500; margin-right: 4px; }
.pill.flash { border-color: var(--accent); }

/* Buttons */
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel-2); border-radius: 8px; padding: 7px 12px; }
button:hover { border-color: var(--muted); }
button:disabled { opacity: .5; cursor: not-allowed; }
.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.ghost { background: transparent; }
.small { padding: 2px 8px; font-size: 12px; }
.icon { background: transparent; border: none; padding: 4px 6px; font-size: 16px; }
.help { width: 20px; height: 20px; padding: 0; border-radius: 50%; border: 1px solid var(--muted); color: var(--muted); font-size: 12px; line-height: 18px; text-align: center; flex: none; background: transparent; }
.help:hover { color: var(--accent); border-color: var(--accent); }

/* Layout */
.layout { flex: 1; display: grid; grid-template-columns: 330px 1fr; min-height: 0; }
.sidebar { border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 12px; border-bottom: 1px solid var(--line); }
.tabs button.active { border-color: var(--accent); color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.settings { padding: 12px 14px 24px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field .lbl { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.field .lbl .val { text-transform: none; color: var(--text); font-variant-numeric: tabular-nums; margin-left: auto; }
.field select, .field input[type=text], .field input[type=number], .field textarea { width: 100%; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; }
.field textarea { resize: vertical; min-height: 60px; }
.field input[type=range] { width: 100%; accent-color: var(--accent); }
.field .hint { font-size: 12px; color: var(--muted); }
.check { display: flex; align-items: center; gap: 8px; text-transform: none !important; font-size: 13px !important; color: var(--text) !important; }
.price-tag { font-size: 12px; color: var(--muted); background: var(--panel-2); border: 1px dashed var(--line); border-radius: 8px; padding: 8px 10px; }
.price-tag b { color: var(--text); }
.drop { border: 1px dashed var(--line); border-radius: 8px; padding: 10px; text-align: center; color: var(--muted); cursor: pointer; }
.drop img { max-width: 100%; max-height: 140px; border-radius: 6px; display: block; margin: 0 auto 6px; }

/* Main */
.main { display: flex; flex-direction: column; min-height: 0; }
.feed { flex: 1; overflow-y: auto; padding: 22px 28px; display: flex; flex-direction: column; gap: 16px; }
.empty { margin: auto; text-align: center; color: var(--muted); max-width: 460px; line-height: 1.6; }
.empty h2 { color: var(--text); margin-bottom: 6px; }
.msg { max-width: 920px; width: 100%; margin: 0 auto; }
.msg.user .bubble { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; margin-left: auto; width: fit-content; max-width: 80%; white-space: pre-wrap; }
.msg.user .meta { text-align: right; }
.msg.ai .bubble { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; line-height: 1.6; overflow-wrap: anywhere; }
.meta { font-size: 12px; color: var(--muted); margin: 4px 2px; }
.cost { display: inline-flex; gap: 10px; align-items: center; margin-top: 10px; padding: 6px 10px; border-radius: 8px; background: color-mix(in srgb, var(--ok) 12%, transparent); border: 1px solid color-mix(in srgb, var(--ok) 35%, transparent); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.cost b { color: var(--ok); font-size: 14px; }
.err-box { color: var(--err); border: 1px solid color-mix(in srgb, var(--err) 40%, transparent); background: color-mix(in srgb, var(--err) 8%, transparent); border-radius: 8px; padding: 8px 10px; }
.bubble pre { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px; overflow-x: auto; }
.bubble code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
.bubble p:first-child { margin-top: 0; } .bubble p:last-child { margin-bottom: 0; }
details.thinking { margin-bottom: 10px; color: var(--muted); font-size: 13px; }
details.thinking pre { white-space: pre-wrap; background: transparent; border: none; padding: 4px 0 0; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.gallery figure { margin: 0; background: repeating-conic-gradient(#8882 0 25%, transparent 0 50%) 50% / 16px 16px; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); }
.gallery img, .gallery video { width: 100%; display: block; }
.gallery figcaption { display: flex; justify-content: space-between; padding: 6px 8px; font-size: 12px; background: var(--panel); color: var(--muted); }
.gallery a { color: var(--accent); }
iframe.anim { width: 100%; aspect-ratio: 16/9; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: -2px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Composer */
.composer { border-top: 1px solid var(--line); background: var(--panel); padding: 12px 28px 10px; }
.composer-row { display: flex; gap: 10px; align-items: flex-end; max-width: 920px; margin: 0 auto; }
.composer textarea { flex: 1; resize: none; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; max-height: 200px; }
.composer textarea:focus, .field :is(input, select, textarea):focus { outline: 2px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 0; }
.attach { cursor: pointer; align-self: center; }
.attach-row { max-width: 920px; margin: 0 auto 6px; font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.estimate { max-width: 920px; margin: 6px auto 0; font-size: 12px; color: var(--muted); min-height: 1em; }

/* Dialogs */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 14px; padding: 20px 22px; max-width: 560px; width: 92vw; }
dialog::backdrop { background: #0008; }
dialog h3 { margin: 0 0 10px; }
dialog .dlg-actions { display: flex; justify-content: flex-end; margin-top: 16px; }
dialog table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
dialog td, dialog th { padding: 5px 6px; border-bottom: 1px solid var(--line); text-align: left; }
dialog td.num, dialog th.num { text-align: right; font-variant-numeric: tabular-nums; }
.help-price { margin-top: 10px; padding: 8px 10px; border-radius: 8px; background: color-mix(in srgb, var(--accent) 10%, transparent); border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent); }
#help-body { line-height: 1.55; max-height: 60vh; overflow-y: auto; }

/* Login */
.login-body { align-items: center; justify-content: center; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px; width: min(380px, 92vw); display: flex; flex-direction: column; gap: 10px; }
.login-card input { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; }
.login-card label { font-size: 12px; color: var(--muted); }

@media (max-width: 800px) { .layout { grid-template-columns: 1fr; } .sidebar { max-height: 45vh; } .spend .pill:nth-child(3), .spend .pill:nth-child(4) { display: none; } }
.tab-feed { display: contents; }
.tab-feed[hidden] { display: none; }
[hidden] { display: none !important; }
