:root {
  --bg: #0f1115; --panel: #161920; --panel2: #1d212a; --line: #2a2f3a; --fg: #e7e9ee; --dim: #9aa1ad;
  --accent: #d97757; --user: #2b3445; --ok: #3fb68b; --err: #e5534b; --warn: #d4a72c;
  --add: rgba(63, 182, 139, .16); --del: rgba(229, 83, 75, .16); --code: #0b0d11;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) { :root:not([data-theme=dark]) {
  --bg: #f7f7f8; --panel: #ffffff; --panel2: #f0f1f3; --line: #e1e3e8; --fg: #1b1d22; --dim: #6b7280;
  --user: #e9edf5; --add: rgba(26, 127, 55, .12); --del: rgba(207, 34, 46, .1); --code: #f3f4f6; color-scheme: light;
} }
:root[data-theme=light] {
  --bg: #f7f7f8; --panel: #ffffff; --panel2: #f0f1f3; --line: #e1e3e8; --fg: #1b1d22; --dim: #6b7280;
  --user: #e9edf5; --add: rgba(26, 127, 55, .12); --del: rgba(207, 34, 46, .1); --code: #f3f4f6; color-scheme: light;
}
[hidden] { display: none !important; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Rubik, Heebo, Arial, sans-serif; }
code, pre, .mono { font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
#app { display: flex; height: 100dvh; }
.bar { display: flex; align-items: center; gap: 8px; padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line); background: var(--panel); min-height: 56px; }
.icon { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 18px; flex: none; }
.icon:active { background: var(--panel2); }
.brand { font-weight: 700; font-size: 18px; flex: 1; }
.conn { width: 10px; height: 10px; border-radius: 50%; background: var(--warn); }
.conn.on { background: var(--ok); } .conn.off { background: var(--err); }

/* worker list */
#list { width: 100%; display: flex; flex-direction: column; background: var(--panel); }
#workers { flex: 1; overflow: auto; }
.wk { display: flex; gap: 12px; align-items: center; padding: 14px 14px; border-bottom: 1px solid var(--line); width: 100%; text-align: start; }
.wk:active, .wk.sel { background: var(--panel2); }
.av { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; font-size: 22px; flex: none; position: relative; }
.av .dot { position: absolute; bottom: 0; inset-inline-end: 0; width: 13px; height: 13px; border-radius: 50%; border: 2px solid var(--panel); background: var(--dim); }
.av .dot.idle { background: var(--ok); } .av .dot.busy { background: var(--accent); animation: pulse 1.2s infinite; } .av .dot.off { background: #555; }
@keyframes pulse { 50% { opacity: .35; } }
.wk .txt { flex: 1; min-width: 0; }
.wk .nm { font-weight: 650; display: flex; gap: 6px; align-items: baseline; }
.wk .tt { color: var(--dim); font-size: 13px; font-weight: 400; }
.wk .pv { color: var(--dim); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wk .badge { background: var(--accent); color: #fff; border-radius: 10px; font-size: 12px; padding: 0 7px; }
.hint { color: var(--dim); font-size: 12px; padding: 12px 14px calc(12px + env(safe-area-inset-bottom)); }

/* chat */
#chat { display: none; flex-direction: column; width: 100%; min-width: 0; position: relative; }
body.in-chat #list { display: none; } body.in-chat #chat { display: flex; }
@media (min-width: 860px) {
  #list { width: 320px; border-inline-end: 1px solid var(--line); display: flex !important; }
  #chat { display: flex; } .back { display: none; }
}
.who { flex: 1; display: flex; gap: 10px; align-items: center; min-width: 0; }
.who .av { width: 38px; height: 38px; font-size: 19px; }
.who .nm { font-weight: 650; line-height: 1.2; }
.who .st { font-size: 12.5px; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu { position: absolute; top: 60px; inset-inline-end: 10px; z-index: 5; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 6px; box-shadow: 0 10px 30px rgba(0,0,0,.3); min-width: 240px; }
.menu button { display: block; width: 100%; text-align: start; padding: 11px 12px; border-radius: 10px; }
.menu button:active { background: var(--panel2); }
.menu .meta { font-size: 11.5px; color: var(--dim); padding: 6px 12px; direction: ltr; text-align: left; word-break: break-all; }
#scroller { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 12px 12px 4px; }
#msgs { max-width: 820px; margin: 0 auto; display: flex; flex-direction: column; gap: 10px; }
.u { align-self: flex-start; max-width: 86%; background: var(--user); padding: 8px 13px; border-radius: 18px; border-start-start-radius: 6px; white-space: pre-wrap; overflow-wrap: anywhere; }
.u .meta { font-size: 11px; color: var(--dim); margin-top: 2px; }
.u img { max-width: 160px; border-radius: 10px; display: block; margin-bottom: 4px; }
.a { overflow-wrap: anywhere; }
.a > :first-child { margin-top: 0 } .a > :last-child { margin-bottom: 0 }
.a p { margin: .45em 0; } .a ul, .a ol { margin: .4em 0; padding-inline-start: 1.4em; } .a li { margin: .15em 0; }
.a h1, .a h2, .a h3, .a h4 { margin: .8em 0 .3em; line-height: 1.3; font-size: 1.08em; }
.a h1 { font-size: 1.2em; }
.a blockquote { margin: .5em 0; padding-inline-start: 10px; border-inline-start: 3px solid var(--line); color: var(--dim); }
.a code { background: var(--panel2); padding: 1px 5px; border-radius: 5px; font-size: .88em; unicode-bidi: isolate; }
.a pre { background: var(--code); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; overflow-x: auto; font-size: 13px; line-height: 1.45; direction: ltr; text-align: left; }
.a pre code { background: none; padding: 0; font-size: inherit; }
.a table { border-collapse: collapse; display: block; overflow-x: auto; font-size: 14px; margin: .5em 0; }
.a th, .a td { border: 1px solid var(--line); padding: 4px 8px; text-align: start; }
.a a { color: var(--accent); }
.a.streaming > :last-child::after { content: "▍"; color: var(--accent); animation: pulse 1s infinite; }
.note { align-self: center; font-size: 12.5px; color: var(--dim); background: var(--panel2); padding: 3px 12px; border-radius: 12px; text-align: center; }
.note.warn { color: var(--warn); } .note.shift { color: var(--accent); background: none; border-top: 1px solid var(--line); border-radius: 0; width: 100%; padding-top: 8px; }
.res { font-size: 11.5px; color: var(--dim); align-self: flex-end; margin-top: -6px; }
.res.err { color: var(--err); }

/* tool groups */
.tg { border: 1px solid var(--line); border-radius: 12px; background: var(--panel); overflow: hidden; }
.tg > .hd { display: flex; gap: 8px; align-items: center; padding: 8px 12px; width: 100%; text-align: start; font-size: 14px; color: var(--dim); }
.tg > .hd .s { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tg > .hd .chev { transition: transform .15s; } .tg.open > .hd .chev { transform: rotate(-90deg); }
.ic { width: 18px; text-align: center; flex: none; }
.ic.ok { color: var(--ok); } .ic.err { color: var(--err); } .ic.run { color: var(--accent); animation: pulse 1s infinite; }
.tg .body { display: none; border-top: 1px solid var(--line); }
.tg.open .body { display: block; }
.tl { border-bottom: 1px solid var(--line); } .tl:last-child { border-bottom: 0; }
.tl > .hd { display: flex; gap: 8px; align-items: center; padding: 7px 12px; width: 100%; text-align: start; font-size: 13.5px; }
.tl > .hd .s { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.tl .det { display: none; padding: 0 10px 10px; }
.tl.open .det, .tl.diff .det { display: block; }
.det pre, .diff-v { margin: 0; background: var(--code); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 12.5px; line-height: 1.45;
  direction: ltr; text-align: left; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 360px; overflow: auto; }
.det .lbl { font-size: 11.5px; color: var(--dim); margin: 6px 2px 3px; }
.diff-v { padding: 0; font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace; } .diff-v div { padding: 0 10px; white-space: pre-wrap; }
.diff-v .ad { background: var(--add); } .diff-v .dl { background: var(--del); } .diff-v .hh { color: var(--dim); background: var(--panel2); font-size: 11.5px; }
.diff-v .fname { color: var(--dim); background: var(--panel2); padding: 4px 10px; font-size: 11.5px; position: sticky; top: 0; }

/* prompts */
.pr { border: 1px solid var(--accent); border-radius: 14px; padding: 12px; background: var(--panel); }
.pr .q { font-weight: 600; margin-bottom: 4px; }
.pr .hdr { font-size: 12px; color: var(--accent); }
.pr .opts { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.pr .opt { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; text-align: start; background: var(--panel2); }
.pr .opt .d { font-size: 13px; color: var(--dim); }
.pr .opt.on { border-color: var(--accent); }
.pr .opt:active { transform: scale(.99); }
.pr .row2 { display: flex; gap: 8px; margin-top: 10px; }
.pr .btn { flex: 1; padding: 10px; border-radius: 12px; background: var(--accent); color: #fff; font-weight: 600; }
.pr .btn.ghost { background: var(--panel2); color: var(--fg); border: 1px solid var(--line); }
.pr input { width: 100%; margin-top: 8px; padding: 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--fg); font: inherit; }
.pr.done { border-color: var(--line); opacity: .75; } .pr.done .opts, .pr.done .row2, .pr.done input { display: none; }
.pr .ans { font-size: 13px; color: var(--dim); margin-top: 6px; }
.pr pre { margin: 6px 0 0; }

#typing { display: flex; gap: 4px; padding: 10px 4px; max-width: 820px; margin: 0 auto; }
#typing[hidden] { display: none; }
#typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--dim); animation: pulse 1s infinite; }
#typing span:nth-child(2) { animation-delay: .2s } #typing span:nth-child(3) { animation-delay: .4s }
#toBottom { position: absolute; bottom: 86px; left: 50%; transform: translateX(-50%); background: var(--accent); color: #fff; border-radius: 16px; padding: 4px 14px; font-size: 13px; z-index: 3; }

/* composer */
#composer { border-top: 1px solid var(--line); background: var(--panel); padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); }
#composer .row { display: flex; align-items: flex-end; gap: 6px; max-width: 820px; margin: 0 auto; }
#input { flex: 1; resize: none; max-height: 160px; min-height: 42px; padding: 9px 14px; border-radius: 21px; border: 1px solid var(--line);
  background: var(--bg); color: var(--fg); font: inherit; line-height: 1.4; outline: none; }
#input:focus { border-color: var(--accent); }
.send { background: var(--accent); color: #fff; border-radius: 50%; font-weight: 700; }
.stop { background: var(--panel2); color: var(--err); border-radius: 50%; }
.now { background: var(--panel2); border-radius: 50%; }
.cam { cursor: pointer; }
#thumbs { display: flex; gap: 6px; max-width: 820px; margin: 0 auto; }
#thumbs:not(:empty) { padding-bottom: 6px; }
#thumbs .th { position: relative; } #thumbs img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; }
#thumbs .x { position: absolute; top: -6px; inset-inline-end: -6px; background: var(--err); color: #fff; border-radius: 50%; width: 20px; height: 20px; font-size: 12px; }
.empty { color: var(--dim); text-align: center; margin-top: 30vh; }
