:root {
  color-scheme: light;
  --bg: #f4f3f0; --surface: #fcfcfb; --surface-2: #f0efec; --line: #dcdad4;
  --text: #0b0b0b; --text-2: #52514e; --muted: #7a7974; --accent: #2a78d6;
  --good: #0ca30c; --warning: #fab219; --critical: #d03b3b; --pending: #9a9890;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --line: #383835;
    --text: #f0efec; --text-2: #c3c2b7; --muted: #8f8e86; --accent: #3987e5;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --line: #383835;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #8f8e86; --accent: #3987e5;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 13px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; display: flex; flex-direction: column; }
header { display: flex; align-items: center; gap: 16px; padding: 8px 16px; background: var(--surface); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { display: flex; flex-direction: column; }
.brand .sub { color: var(--text-2); font-size: 11px; }
.counters { display: flex; gap: 14px; color: var(--text-2); font-variant-numeric: tabular-nums; margin-left: auto; }
.counters b { color: var(--text); font-weight: 600; }
.provider { display: flex; gap: 6px; align-items: center; }
select, input, textarea, button { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; }
button { cursor: pointer; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
main { flex: 1; display: grid; grid-template-columns: 330px minmax(0, 1fr) 400px; gap: 10px; padding: 10px; min-height: 0; }
section { display: flex; flex-direction: column; gap: 10px; min-height: 0; overflow: auto; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.panel.grow { flex: 1; display: flex; flex-direction: column; min-height: 0; }
h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-2); margin: 0 0 8px; }
.row { display: flex; align-items: center; gap: 10px; }
.row h2 { margin: 0; }
.note { color: var(--text-2); font-size: 12px; }
.badge { padding: 3px 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); font-weight: 600; }
.st { display: inline-flex; align-items: center; gap: 4px; }
.st::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--pending); flex: none; }
.st.pass::before { background: var(--good); } .st.warn::before { background: var(--warning); }
.st.fail::before { background: var(--critical); } .st.pending::before { background: var(--pending); }
#deliveries { margin: 0 0 8px; padding-left: 18px; }
#deliveries li { margin: 3px 0; color: var(--text-2); }
#deliveries li.done { color: var(--text); }
#deliveries li.next { font-weight: 600; }
#deliveries li small { display: block; color: var(--muted); }
#chain table { border-collapse: collapse; width: 100%; font-size: 12px; }
#chain th, #chain td { padding: 3px 4px; text-align: left; border-bottom: 1px solid var(--line); }
#chain td.cell { cursor: pointer; white-space: nowrap; }
#chain .gatehead { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 8px; }
#chain .gatehead span { padding: 2px 6px; border-radius: 4px; background: var(--surface-2); font-size: 11px; }
#view { flex: 1; min-height: 300px; border-radius: 8px; background: var(--surface-2); position: relative; overflow: hidden; }
#legend { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 6px; font-size: 12px; color: var(--text-2); }
#legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
.seg { display: flex; } .seg button { border-radius: 0; } .seg button:first-child { border-radius: 6px 0 0 6px; } .seg button:last-child { border-radius: 0 6px 6px 0; }
.seg button.on { background: var(--surface-2); border-color: var(--accent); }
.busy { color: var(--accent); font-size: 12px; margin-left: auto; }
#graph { width: 100%; height: 240px; }
#graph text { font-size: 10px; fill: var(--text-2); }
#graph .n { cursor: pointer; }
#graph .edge { stroke: var(--line); fill: none; }
#graph .edge.hi { stroke: var(--accent); stroke-width: 2; }
.chatpanel { min-height: 0; }
#chat { flex: 1; overflow: auto; display: flex; flex-direction: column; gap: 8px; padding-right: 4px; }
.msg { padding: 8px 10px; border-radius: 8px; white-space: pre-wrap; }
.msg.agent { white-space: normal; }
.msg.agent p { margin: 0 0 6px; } .msg.agent ul { margin: 0 0 6px; padding-left: 18px; }
.msg.agent code { font-size: 11px; background: var(--surface-2); padding: 0 3px; border-radius: 3px; }
table.mdt { border-collapse: collapse; font-size: 12px; margin: 4px 0 8px; } table.mdt th, table.mdt td { border-bottom: 1px solid var(--line); padding: 2px 8px 2px 0; text-align: left; }
.msg.user { background: var(--surface-2); align-self: flex-end; max-width: 90%; }
.msg.agent { border: 1px solid var(--line); }
.msg.tool { color: var(--muted); font-size: 11px; padding: 2px 6px; font-family: ui-monospace, Menlo, monospace; }
.card { border: 1px solid var(--accent); border-radius: 8px; padding: 8px 10px; }
.card h3 { margin: 0 0 4px; font-size: 13px; }
.card .why { color: var(--text-2); margin: 4px 0; }
.card .src { color: var(--muted); font-size: 11px; }
.card .act { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.card.approved { border-color: var(--good); } .card.rejected { border-color: var(--critical); }
.card .res { margin-top: 6px; font-size: 12px; }
#ask { display: flex; gap: 6px; margin-top: 8px; }
#ask textarea { flex: 1; resize: vertical; }
.log { max-height: 190px; }
#log { overflow: auto; max-height: 150px; font-size: 11px; color: var(--text-2); font-family: ui-monospace, Menlo, monospace; }
#log .error { color: var(--critical); }
.bar { display: grid; grid-template-columns: 52px 1fr 44px; gap: 6px; align-items: center; font-size: 11px; margin: 3px 0; }
.bar .track { height: 10px; background: var(--surface-2); border-radius: 4px; position: relative; }
.bar .fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 0 4px 4px 0; background: var(--s1); }
.bar .fill.over { background: var(--critical); }
.bar .v { text-align: right; font-variant-numeric: tabular-nums; color: var(--text); }
@media (max-width: 1100px) { main { grid-template-columns: 1fr; } }

pre.code { margin: 6px 0 0; font: 11px/1.4 ui-monospace, Menlo, monospace; white-space: pre-wrap; max-height: 260px; overflow: auto; color: var(--text-2); }
.msg.shot img { width: 100%; border-radius: 6px; display: block; background: var(--surface-2); }
