:root {
  --bg: #f6f3ec; --panel: #fffdf8; --ink: #1d1b16; --muted: #6f6a5d; --line: #e1dccf;
  --accent: #c8501e; --accent-ink: #fff; --ok: #2f7d4f; --warn: #a8710f; --bad: #b3341f;
  --code: #efeadd; --radius: 10px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #14130f; --panel: #1c1a15; --ink: #ece7da; --muted: #9a9484; --line: #2d2a22; --accent: #e8703a; --accent-ink: #1a0e07; --ok: #5fc08a; --warn: #e0b04a; --bad: #ef7a63; --code: #25221b; }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; display: grid; grid-template-columns: 360px 1fr; overflow: hidden; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; }
h3 { font-size: 11px; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 6px 12px; }
button:hover:not(:disabled) { border-color: var(--muted); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.ghost { background: transparent; }
button.link { border: 0; background: none; padding: 0; color: var(--accent); text-decoration: underline; }
button.icon { display: none; font-size: 18px; padding: 4px 10px; }
input, select, textarea { width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
textarea { resize: none; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Sidebar */
#side { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 18px; padding: 16px; overflow-y: auto; min-height: 0; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 18px; flex: 1; }
.badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: -8px; }
.pill { font-size: 11px; padding: 2px 8px; border: 1px solid var(--line); border-radius: 99px; color: var(--muted); }
.pill.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.pill.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.pill.bad { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
.inrow { display: flex; gap: 6px; }
.inrow input { flex: 1; min-width: 0; }
#preset { margin-top: 8px; color: var(--muted); }
#check { margin-top: 10px; padding: 10px; border: 1px dashed var(--line); border-radius: var(--radius); display: grid; gap: 8px; }
#check label { font-size: 12px; color: var(--muted); display: block; }
#check label.sub { margin-top: -4px; }
#check .rel { margin: 0; padding-left: 18px; }
.grow { flex: 1; }
.meta { font-size: 12px; color: var(--muted); word-break: break-word; }
.err { color: var(--bad); margin: 0; font-size: 13px; }
.empty { color: var(--muted); font-size: 13px; margin: 0; }
#models { display: grid; gap: 10px; }
.card { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; display: grid; gap: 4px; background: var(--bg); }
.card.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.card h4 { font-size: 14px; word-break: break-word; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.actions button { padding: 5px 10px; font-size: 13px; }
.bar { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; margin: 4px 0; }
.bar i { display: block; height: 100%; background: var(--accent); transition: width .2s; }
#storage .row { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--muted); }

/* Main */
main { display: grid; grid-template-rows: auto 1fr auto; min-width: 0; min-height: 0; height: 100%; }
.top { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.top .spacer { flex: 1; }
#active { display: grid; line-height: 1.25; min-width: 0; }
#active strong { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#active span { font-size: 12px; color: var(--muted); }
#messages { overflow-y: auto; padding: 20px 16px; display: flex; flex-direction: column; gap: 18px; scroll-behavior: smooth; }
.hero { margin: auto; max-width: 520px; text-align: center; color: var(--muted); }
.hero h2 { color: var(--ink); font-size: 22px; margin-bottom: 8px; }
.hero ol { text-align: left; display: inline-block; }
.msg { max-width: 780px; width: 100%; margin: 0 auto; }
.msg .who { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-bottom: 2px; }
.msg.user .body { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px; }
.msg .body p { margin: .4em 0; }
.msg .body > :first-child { margin-top: 0; }
.msg .stat { font-size: 11px; color: var(--muted); margin-top: 4px; }
.msg pre { background: var(--code); border-radius: 8px; padding: 10px 12px; overflow-x: auto; font-size: 13px; position: relative; }
.msg code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92em; background: var(--code); padding: 1px 5px; border-radius: 4px; }
.msg pre code { background: none; padding: 0; }
.msg pre[data-lang]:not([data-lang=""])::before { content: attr(data-lang); position: absolute; top: 4px; right: 8px; font-size: 10px; color: var(--muted); }
.think { border-left: 2px solid var(--line); padding-left: 10px; margin: 6px 0; color: var(--muted); font-size: 14px; }
.think summary { cursor: pointer; font-size: 12px; }
.dots i { display: inline-block; width: 6px; height: 6px; margin-right: 4px; border-radius: 50%; background: var(--muted); animation: b 1s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: .15s; } .dots i:nth-child(3) { animation-delay: .3s; }
@keyframes b { 0%, 80%, 100% { opacity: .2; } 40% { opacity: 1; } }
.composer { display: flex; gap: 8px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); align-items: flex-end; max-width: 100%; }
.composer textarea { flex: 1; max-height: 200px; }
.composer button { height: 38px; }

dialog { border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--ink); width: min(520px, 94vw); padding: 20px; }
dialog::backdrop { background: rgba(0, 0, 0, .5); }
dialog h2 { margin-bottom: 12px; }
dialog h3 { margin: 16px 0 8px; }
dialog label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
dialog label.check { display: flex; align-items: center; gap: 8px; }
dialog label.check input { width: auto; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; max-width: min(90vw, 560px); font-size: 14px; z-index: 50; box-shadow: 0 6px 24px rgba(0,0,0,.3); }
#scrim { display: none; }

@media (max-width: 860px) {
  body { grid-template-columns: 1fr; }
  button.icon { display: inline-block; }
  #side { position: fixed; inset: 0 auto 0 0; width: min(92vw, 380px); z-index: 20; transform: translateX(-102%); transition: transform .2s; }
  body.side-open #side { transform: none; }
  body.side-open #scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 10; }
  .top .ghost { padding: 5px 8px; font-size: 13px; }
}

button.wide { width: 100%; margin-top: 8px; }
#local { margin-top: 10px; padding: 10px; border: 1px dashed var(--line); border-radius: var(--radius); display: grid; gap: 8px; }
label.radio { display: flex !important; gap: 8px; align-items: flex-start; font-size: 12px; color: var(--muted); }
label.radio input { width: auto; margin-top: 3px; }
#side.drop { outline: 2px dashed var(--accent); outline-offset: -8px; }
#update { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 60; display: flex; gap: 10px; align-items: center; background: var(--panel); border: 1px solid var(--accent); border-radius: 12px; padding: 8px 12px; box-shadow: 0 6px 24px rgba(0,0,0,.25); font-size: 14px; }
#update[hidden] { display: none; }



