/* Layout: one-screen app. Top bar, then a workspace: the page (robot beside its controls) with the log docked as a column on the right (below it on narrow screens). */
:root {
    --bg: #f4f5f8;
    --panel: #ffffff;
    --panel-hi: #eef0f5;
    --line: #e0e3ea;
    --line-strong: #c6cad6;
    --track: #dcdfe8;
    --fg: #171922;
    --fg-dim: #5d6172;
    --accent: #2f66d6;
    --accent-fg: #ffffff;
    --accent-soft: #e4ecfb;
    --ok: #1d8743;
    --ok-soft: #e1f3e7;
    --err: #c8372d;
    --err-soft: #fbe7e5;
    --on-err: #ffffff;
    --warn: #a35a0b;
    --warn-soft: #fbefdf;
    --shadow: rgba(23, 27, 45, 0.12);
    --scrim: rgba(20, 22, 32, 0.32);
    /* The robot drawing: blue shell, white parts, dark screen (as on the real RSC) */
    --rsc-body: #2d67c0;
    --rsc-body-line: #1f4f98;
    --rsc-shell: #f7f8fb;
    --rsc-shell-line: #a9b2c4;
    --rsc-screen: #141a26;
    --rsc-face: #f1f4fa;
    --led-on: #f2b632;
    --ring-blue: #2f6bff;
    --ring-purple: #9a45d6;
    --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    --r: 10px;
    --r-sm: 7px;
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0e0e12; --panel: #1a1a22; --panel-hi: #24242e; --line: #2a2a35; --line-strong: #3b3b4a; --track: #30303d;
        --fg: #e6e6ea; --fg-dim: #8f8fa0; --accent: #6a9dff; --accent-fg: #0b1020; --accent-soft: #1c2640;
        --ok: #7ed491; --ok-soft: #17291d; --err: #ff8080; --err-soft: #361b1f; --on-err: #1a0b0b; --warn: #ffb266; --warn-soft: #33250f;
        --shadow: rgba(0, 0, 0, 0.5); --scrim: rgba(0, 0, 0, 0.6);
        --rsc-body: #2a5ca8; --rsc-body-line: #4a7fd0; --rsc-shell: #d9dde7; --rsc-shell-line: #7d8699; --rsc-screen: #090c12; --rsc-face: #eef1f7;
        --led-on: #ffd36b; --ring-blue: #5a8dff; --ring-purple: #bf74f2;
        color-scheme: dark;
    }
}
:root[data-theme="dark"] {
    --bg: #0e0e12; --panel: #1a1a22; --panel-hi: #24242e; --line: #2a2a35; --line-strong: #3b3b4a; --track: #30303d;
    --fg: #e6e6ea; --fg-dim: #8f8fa0; --accent: #6a9dff; --accent-fg: #0b1020; --accent-soft: #1c2640;
    --ok: #7ed491; --ok-soft: #17291d; --err: #ff8080; --err-soft: #361b1f; --on-err: #1a0b0b; --warn: #ffb266; --warn-soft: #33250f;
    --shadow: rgba(0, 0, 0, 0.5); --scrim: rgba(0, 0, 0, 0.6);
    --rsc-body: #2a5ca8; --rsc-body-line: #4a7fd0; --rsc-shell: #d9dde7; --rsc-shell-line: #7d8699; --rsc-screen: #090c12; --rsc-face: #eef1f7;
    --led-on: #ffd36b; --ring-blue: #5a8dff; --ring-purple: #bf74f2;
    color-scheme: dark;
}

* { box-sizing: border-box; scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border: 3px solid transparent; border-radius: 10px; background-clip: content-box; }
::-webkit-scrollbar-button { display: none; }
[hidden] { display: none !important; }
html, body { height: 100%; overflow: hidden; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 14px/1.45 var(--sans); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { text-wrap: balance; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
code { font-family: var(--mono); font-size: 12px; }
.ic { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.dim { color: var(--fg-dim); }

.frame { height: 100%; display: flex; flex-direction: column; min-height: 0; }

/* ---- App frame ---- */
.app { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.shell { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.workspace { flex: 1; min-height: 0; position: relative; display: grid; grid-template-columns: minmax(0, 1fr) var(--log-w, 380px); grid-template-rows: minmax(0, 1fr); grid-template-areas: "main log"; }
body[data-log="closed"] .workspace { grid-template-columns: minmax(0, 1fr); grid-template-areas: "main"; }
body[data-view="settings"] .workspace { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); grid-template-areas: "main"; }
/* The scrollbar's space is always reserved, so switching panels never shifts the layout sideways */
.page { grid-area: main; min-height: 0; min-width: 0; overflow: auto; scrollbar-gutter: stable; padding: 20px 16px 32px; }

/* ---- Buttons and inputs ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 36px; padding: 0 14px; border-radius: var(--r-sm); border: 1px solid var(--line-strong); background: var(--panel); cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn:hover { background: var(--panel-hi); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { background: var(--err); border-color: var(--err); color: var(--on-err); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--fg-dim); }
.btn.ghost:hover { color: var(--fg); background: var(--panel-hi); }
.btn.danger-t, .btn.danger-t:hover { color: var(--err); }
.btn.sm { min-height: 32px; padding: 0 11px; font-size: 13px; }
.btn.sm .ic { width: 16px; height: 16px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; filter: none; }
.icon-btn { width: 36px; height: 36px; display: inline-grid; place-items: center; border-radius: var(--r-sm); border: 1px solid transparent; background: transparent; cursor: pointer; color: var(--fg-dim); flex: none; }
.icon-btn:hover { background: var(--panel-hi); color: var(--fg); }
.icon-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.icon-btn.sm { width: 30px; height: 30px; }
.icon-btn.sm .ic { width: 16px; height: 16px; }
.input, select, textarea { width: 100%; border: 1px solid var(--line-strong); background: var(--bg); border-radius: var(--r-sm); padding: 8px 10px; }
textarea { resize: vertical; font-family: var(--mono); font-size: 12.5px; }
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; line-height: 16px; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--fg-dim); white-space: nowrap; }
.chip.ok { color: var(--ok); background: var(--ok-soft); border-color: transparent; }
.chip.sim { color: var(--accent); background: var(--accent-soft); border-color: transparent; }
.chip.warn { color: var(--warn); background: var(--warn-soft); border-color: transparent; }
.form-err { margin: 0; color: var(--err); font-size: 13px; }

/* ---- Connect (landing) ---- */
.connect { flex: 1; overflow: auto; padding: 48px 16px; }
.connect-inner { max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; gap: 28px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--fg-dim); font-weight: 600; font-size: 13px; letter-spacing: 0.02em; }
.brand img { height: 36px; width: auto; }
.connect h1 { margin: 0; font-size: 26px; font-weight: 650; letter-spacing: -0.01em; }
.connect-note { margin: -16px 0 0; padding: 10px 12px; border-radius: var(--r-sm); background: var(--panel-hi); color: var(--fg-dim); font-size: 13px; }
.eyebrow { margin: 0 0 10px; font-size: 11px; font-weight: 650; letter-spacing: 0.08em; text-transform: uppercase; color: var(--fg-dim); }
.recent ul, .scan-list { list-style: none; margin: 0; padding: 0; }
.recent ul { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); }
.robot-row { display: flex; align-items: center; gap: 12px; padding: 12px 10px 12px 14px; }
.robot-row + .robot-row { border-top: 1px solid var(--line); }
.rr-ic { width: 34px; height: 34px; border-radius: 8px; background: var(--panel-hi); display: grid; place-items: center; color: var(--fg-dim); flex: none; }
.rr-ic svg { width: 22px; height: 22px; }
.rr-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.rr-name { font-family: var(--mono); font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rr-meta { font-size: 12px; color: var(--fg-dim); }
.connect-form { display: flex; flex-direction: column; gap: 12px; }
.cf-grid { display: grid; grid-template-columns: minmax(0, 1fr) 96px; gap: 10px; }
.cf-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.cf-grid .full { grid-column: 1 / -1; }
.cf-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.scan-list { display: flex; flex-direction: column; gap: 6px; }
.scan-list li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px dashed var(--line-strong); border-radius: var(--r-sm); }
.scan-list .rr-name { flex: 1; }

/* ---- Top bar: menu button left, then title and robot on one baseline ---- */
.topbar { position: relative; display: flex; align-items: center; gap: 8px; padding: 8px 16px 8px 8px; border-bottom: 1px solid var(--line); background: var(--panel); min-height: 56px; }
#burger { position: relative; z-index: 46; }
#burger[aria-expanded="true"] { background: var(--panel-hi); color: var(--fg); }
.tb-id { display: flex; align-items: baseline; gap: 12px; min-width: 0; }
.tb-title { margin: 0; font-size: 16px; line-height: 24px; font-weight: 650; }
.tb-robot { display: flex; align-items: baseline; gap: 8px; font-size: 13px; line-height: 24px; color: var(--fg-dim); min-width: 0; }
.tb-robot .dot { align-self: center; }
.tb-name { font-family: var(--mono); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }
.tb-spacer { flex: 1; }
.tb-logo { position: absolute; left: 50%; top: 50%; height: 32px; width: auto; transform: translate(-50%, -50%); pointer-events: none; }
@media (max-width: 420px) { .tb-logo { display: none; } }
.btn.stop { background: var(--err-soft); border-color: var(--err); color: var(--err); font-weight: 600; }
.btn.stop:hover { background: var(--err); color: var(--on-err); }
.btn.stop .ic { width: 14px; height: 14px; }
.spin { width: 14px; height: 14px; flex: none; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (max-width: 520px) {
    .tb-name, .tb-robot .chip { display: none; }
    .btn.stop span { display: none; }
    .btn.stop { padding: 0 11px; }
}

/* ---- Menu: side sheet from the left, below the top bar so the menu button stays reachable ---- */
.menu-backdrop { position: fixed; inset: var(--menu-top, 0px) 0 0 0; z-index: 44; background: var(--scrim); }
.menu { position: fixed; z-index: 45; top: var(--menu-top, 0px); left: 0; bottom: 0; width: min(300px, 86vw); display: flex; flex-direction: column; gap: 2px; padding: 12px 10px calc(16px + env(safe-area-inset-bottom, 0px)); overflow-y: auto; background: var(--panel); border-right: 1px solid var(--line); box-shadow: 12px 0 32px var(--shadow); }
.menu-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: 0; border-radius: var(--r-sm); background: transparent; cursor: pointer; text-align: left; }
.menu-item:hover { background: var(--panel-hi); }
.menu-item[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 550; }
.menu-item:disabled { opacity: 0.55; cursor: default; background: transparent; }
.menu-item .chip { margin-left: auto; }
.menu-sep { height: 1px; flex: none; background: var(--line); margin: 6px 4px; }
.menu-foot { display: flex; flex-direction: column; gap: 2px; margin-top: auto; }
.menu-item.danger-t { color: var(--err); }
.menu-chats { display: none; flex-direction: column; gap: 2px; }
@media (max-width: 760px) {
    body[data-view="chat"] .menu-chats { display: flex; }
}

/* ---- Controls ---- */
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; }
.sub { margin: 6px 0 -4px; font-size: 11px; font-weight: 650; letter-spacing: 0.08em; text-transform: uppercase; color: var(--fg-dim); }
.hint { margin: -6px 0 0; font-size: 12px; line-height: 1.5; color: var(--fg-dim); }
/* A box groups related controls on a tinted ground, like the test meters */
.box { display: flex; flex-direction: column; gap: 14px; padding: 12px 14px; background: var(--panel-hi); border-radius: var(--r-sm); --track: var(--line-strong); }
.box .seg { background: var(--bg); }
.field { display: flex; flex-direction: column; gap: 3px; }
.field-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.field label, .field-label { font-size: 13px; }
.field.is-off, .switch-row.is-off { opacity: 0.45; }
.num { display: inline-flex; align-items: baseline; gap: 3px; }
.num input { width: 70px; text-align: right; font-family: var(--mono); font-size: 13px; font-variant-numeric: tabular-nums; border: 1px solid transparent; background: transparent; border-radius: 5px; padding: 2px 4px; }
.num input:hover:not(:disabled), .num input:focus { border-color: var(--line-strong); background: var(--bg); }
.unit { color: var(--fg-dim); font-size: 12px; }
.ticks { display: flex; justify-content: space-between; font-size: 11px; color: var(--fg-dim); font-variant-numeric: tabular-nums; }
.range { -webkit-appearance: none; appearance: none; width: 100%; height: 26px; margin: 0; background: transparent; cursor: pointer; --a: 0%; --b: 50%; }
.range:disabled { cursor: not-allowed; }
.range::-webkit-slider-runnable-track { height: 6px; border-radius: 3px; background: linear-gradient(to right, var(--track) 0 var(--a), var(--accent) var(--a) var(--b), var(--track) var(--b) 100%); }
.range::-moz-range-track { height: 6px; border-radius: 3px; background: linear-gradient(to right, var(--track) 0 var(--a), var(--accent) var(--a) var(--b), var(--track) var(--b) 100%); }
.range.bipolar::-webkit-slider-runnable-track { background: linear-gradient(to right, transparent calc(50% - 1px), var(--fg-dim) calc(50% - 1px) calc(50% + 1px), transparent calc(50% + 1px)), linear-gradient(to right, var(--track) 0 var(--a), var(--accent) var(--a) var(--b), var(--track) var(--b) 100%); }
.range.bipolar::-moz-range-track { background: linear-gradient(to right, transparent calc(50% - 1px), var(--fg-dim) calc(50% - 1px) calc(50% + 1px), transparent calc(50% + 1px)), linear-gradient(to right, var(--track) 0 var(--a), var(--accent) var(--a) var(--b), var(--track) var(--b) 100%); }
.range::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; margin-top: -6px; border-radius: 50%; background: var(--panel); border: 2px solid var(--accent); box-shadow: 0 1px 3px var(--shadow); }
.range::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--panel); border: 2px solid var(--accent); box-shadow: 0 1px 3px var(--shadow); }
.range:focus-visible { outline: none; }
.range:focus-visible::-webkit-slider-thumb { outline: 2px solid var(--accent); outline-offset: 2px; }
.range:focus-visible::-moz-range-thumb { outline: 2px solid var(--accent); outline-offset: 2px; }
.seg { display: flex; flex-wrap: wrap; gap: 2px; padding: 3px; background: var(--panel-hi); border-radius: var(--r-sm); }
.seg-opt { flex: 1 1 auto; position: relative; }
.seg-opt input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.seg-opt input:disabled { cursor: not-allowed; }
.seg-opt span { display: block; padding: 6px 10px; border-radius: 5px; text-align: center; font-size: 13px; color: var(--fg-dim); }
.seg-opt input:checked + span { background: var(--panel); color: var(--fg); font-weight: 550; box-shadow: 0 1px 2px var(--shadow); }
.seg-opt input:focus-visible + span { outline: 2px solid var(--accent); }
.switch-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 28px; font-size: 13px; cursor: pointer; }
.switch-row input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch { position: relative; width: 36px; height: 20px; border-radius: 10px; background: var(--track); flex: none; transition: background 0.15s; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--panel); box-shadow: 0 1px 2px var(--shadow); transition: transform 0.15s; }
.switch-row input:checked + .switch { background: var(--accent); }
.switch-row input:checked + .switch::after { transform: translateX(16px); }
.switch-row input:focus-visible + .switch { outline: 2px solid var(--accent); outline-offset: 2px; }
.expr { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.expr button { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 6px 10px; border: 1px solid transparent; border-radius: var(--r-sm); background: var(--panel-hi); cursor: pointer; font-size: 12.5px; }
.expr button:hover { border-color: var(--line-strong); }
.expr button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.glyph { width: 30px; height: 30px; stroke: currentColor; fill: none; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.glyph .f { fill: currentColor; stroke: none; }
.device { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--fg-dim); min-width: 0; }
.device code { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.readout { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 13px; color: var(--fg-dim); }
.readout code { background: var(--panel); color: var(--fg); padding: 2px 7px; border-radius: 5px; }
.readout .hold { width: 100%; color: var(--warn); font-weight: 600; }
.meters { display: flex; flex-direction: column; gap: 6px; padding: 10px 12px; background: var(--panel-hi); border-radius: var(--r-sm); }
.meters .cap { font-size: 12px; color: var(--fg-dim); }
.meter { display: grid; grid-template-columns: 40px minmax(0, 1fr) 92px; align-items: center; gap: 10px; font-size: 12.5px; }
.meter code { text-align: right; font-variant-numeric: tabular-nums; }
.bar { height: 8px; border-radius: 4px; background: var(--line-strong); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--ok); border-radius: 4px; }
.meter.scale { font-size: 10.5px; color: var(--fg-dim); }
.meter.scale span:nth-child(2) { display: flex; justify-content: space-between; }
.working { margin: 0; font-size: 13px; color: var(--warn); }

/* Advanced controls sit folded at the bottom of each panel */
.adv { border-top: 1px solid var(--line); }
.adv > summary { display: flex; align-items: center; gap: 6px; padding: 12px 0 2px; cursor: pointer; list-style: none; font-size: 13px; font-weight: 600; color: var(--fg-dim); }
.adv > summary::-webkit-details-marker { display: none; }
.adv > summary:hover { color: var(--fg); }
.adv > summary .ic { width: 16px; height: 16px; transition: transform 0.15s; }
.adv[open] > summary .ic { transform: rotate(180deg); }
.adv-body { display: flex; flex-direction: column; gap: 14px; padding-top: 12px; }
.checks { display: flex; flex-direction: column; background: var(--panel-hi); border-radius: var(--r-sm); }
.check { display: flex; align-items: center; gap: 12px; padding: 9px 10px 9px 14px; }
.check + .check { border-top: 1px solid var(--panel); }
.check > div { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.check strong { font-size: 13px; font-weight: 600; }
.check span { font-size: 12px; color: var(--fg-dim); }

/* ---- Console: robot beside the selected part ---- */
#pageConsole { container-type: inline-size; }
.robotwrap { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 440px); gap: 20px; max-width: 1160px; margin: 0 auto; align-items: start; }
@container (max-width: 780px) {
    .robotwrap { grid-template-columns: minmax(0, 1fr); }
    .robot-stage svg { max-width: 340px; }
}
@media (min-height: 760px) {
    @container (min-width: 781px) { .robot-stage { position: sticky; top: 0; } }
}
.robot-stage { display: flex; flex-direction: column; gap: 14px; padding: 16px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); }
.robot-stage svg { width: 100%; max-width: 400px; height: auto; display: block; margin: 0 auto; }
.part-chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.part-chips button { padding: 5px 11px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); cursor: pointer; font-size: 12.5px; }
.part-chips button:hover { border-color: var(--line-strong); }
.part-chips button[aria-current="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.stage-tools { display: flex; flex-direction: column; gap: 10px; padding-top: 14px; border-top: 1px solid var(--line); }
.tools-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.tools-row .push { margin-left: auto; }
.tools-quick { display: contents; }
.qa { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: 999px; background: var(--panel); cursor: pointer; font-size: 13px; }
.qa:hover { background: var(--panel-hi); }
.qa .ic { width: 16px; height: 16px; }
.qa[aria-pressed="true"] { border-color: var(--err); background: var(--err-soft); color: var(--err); }
.pop-wrap { position: relative; }
.pop-wrap .btn .chev { width: 14px; height: 14px; transition: transform 0.15s; }
.pop-wrap .btn[aria-expanded="true"] .chev { transform: rotate(180deg); }
.pop { position: absolute; left: 0; bottom: calc(100% + 6px); z-index: 25; width: 270px; max-width: calc(100vw - 48px); display: flex; flex-direction: column; gap: 2px; padding: 6px; background: var(--panel); border: 1px solid var(--line-strong); border-radius: var(--r); box-shadow: 0 14px 36px var(--shadow); }
.pop-item { display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 10px; border: 0; border-radius: var(--r-sm); background: transparent; cursor: pointer; text-align: left; font-size: 13.5px; }
.pop-item:hover { background: var(--panel-hi); }
.pop-item .ic { width: 16px; height: 16px; color: var(--fg-dim); }
.rb-body { fill: var(--rsc-body); stroke: var(--rsc-body-line); stroke-width: 1.5; }
.rb-edge { fill: none; stroke-width: 3; }
.rb-shell { fill: var(--rsc-shell); stroke: var(--rsc-shell-line); stroke-width: 1.5; }
.rb-axle { fill: var(--rsc-shell-line); }
.rb-pivot { fill: var(--rsc-shell-line); }
.rb-screen { fill: var(--rsc-screen); }
.rb-face { fill: var(--rsc-face); }
.rb-mouth { fill: none; stroke: var(--rsc-face); stroke-width: 4; stroke-linecap: round; }
.rb-led { fill: var(--led-on); }
.rb-grille { fill: var(--rsc-body-line); }
.rb-grille-lit { fill: var(--rsc-shell); transition: opacity 0.15s; }
.rb-mic { fill: var(--rsc-screen); }
.rb-mic-off { stroke: var(--err); stroke-width: 2; stroke-linecap: round; }
.part { cursor: pointer; outline: none; }
.part .hl { fill: transparent; stroke: transparent; stroke-width: 1.5; stroke-dasharray: 4 3; }
.part:hover .hl, .part:focus-visible .hl { stroke: var(--fg-dim); }
.part.is-sel .hl { stroke: var(--accent); stroke-width: 2; stroke-dasharray: none; }
.card { padding: 20px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); display: flex; flex-direction: column; gap: 14px; }
.card-head { display: flex; align-items: center; gap: 10px; }
.card-head h2 { margin: 0 auto 0 0; font-size: 17px; font-weight: 650; }
@media (max-width: 820px) { .card { padding: 16px; } }

/* ---- Settings page ---- */
.settings { max-width: 640px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.settings .card h2 { margin: 0; font-size: 15px; font-weight: 650; }
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 8px 20px; margin: 0; font-size: 13px; }
.kv dt { color: var(--fg-dim); }
.kv dd { margin: 0; font-family: var(--mono); font-size: 12.5px; overflow-wrap: anywhere; }

/* ---- Chat: list of chats on the left, conversation on the right ---- */
.page-chat { display: grid; grid-template-columns: 260px minmax(0, 1fr); padding: 0; overflow: hidden; }
.chat-side { display: flex; flex-direction: column; gap: 2px; min-height: 0; overflow-y: auto; padding: 12px 10px; background: var(--panel); border-right: 1px solid var(--line); }
.chat-side .btn { justify-content: flex-start; margin-top: auto; }
#chatSideList { padding-bottom: 12px; }
.side-label { margin: 10px 0 2px; padding: 0 10px; font-size: 11px; font-weight: 650; letter-spacing: 0.06em; text-transform: uppercase; color: var(--fg-dim); }
.chat-item { display: block; width: 100%; padding: 7px 10px; border: 0; border-radius: var(--r-sm); background: transparent; cursor: pointer; text-align: left; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item:hover { background: var(--panel-hi); }
.chat-item[aria-current="page"] { background: var(--panel-hi); font-weight: 600; }
.chat-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chat-head { display: flex; align-items: center; gap: 6px; min-height: 48px; padding: 6px 12px 6px 20px; border-bottom: 1px solid var(--line); }
.chat-head h2 { flex: 1; min-width: 0; margin: 0; font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-head .icon-btn { display: none; }
.chat-scroll { flex: 1; min-height: 0; overflow: auto; padding: 20px 16px; }
.chat-msgs { max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: 85%; padding: 10px 14px; border-radius: 12px; line-height: 1.55; min-width: 0; overflow-wrap: anywhere; }
.msg.ai { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); }
.msg.user { align-self: flex-end; background: var(--accent-soft); }
.msg p { margin: 0 0 6px; }
.msg p:last-child { margin-bottom: 0; }
.msg ol, .msg ul { margin: 4px 0 8px; padding-left: 20px; }
.msg .via { display: flex; align-items: center; gap: 5px; margin-bottom: 4px; font-size: 11.5px; color: var(--fg-dim); }
.msg .via .ic { width: 13px; height: 13px; }
.msg .att { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.sugg { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.sugg button { padding: 5px 10px; border: 1px solid var(--line-strong); border-radius: var(--r-sm); background: var(--bg); cursor: pointer; font-size: 13px; }
.sugg button:hover { border-color: var(--accent); color: var(--accent); }
.cursor { display: inline-block; width: 7px; height: 14px; margin-left: 2px; vertical-align: -2px; background: var(--fg-dim); animation: blink 1s steps(1) infinite; }
.dots { display: inline-flex; gap: 4px; padding: 4px 0; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--fg-dim); animation: bounce 1.1s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: 0.15s; }
.dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes blink { 50% { opacity: 0; } }
@keyframes bounce { 0%, 80%, 100% { opacity: 0.3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }
.composer { display: flex; flex-direction: column; gap: 8px; width: calc(100% - 32px); max-width: 760px; margin: 0 auto 16px; padding: 8px; background: var(--panel); border: 1px solid var(--line-strong); border-radius: 12px; }
.composer:focus-within { border-color: var(--accent); }
.composer-row { display: flex; align-items: flex-end; gap: 4px; }
.composer textarea { flex: 1; min-width: 0; max-height: 140px; padding: 7px 6px; border: 0; background: transparent; resize: none; outline: none; font-family: var(--sans); font-size: 14px; }
.files { display: flex; flex-wrap: wrap; gap: 6px; }
.file-chip { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; min-height: 28px; padding: 2px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel-hi); font-size: 12.5px; }
.file-chip .ic { width: 14px; height: 14px; color: var(--fg-dim); }
.file-chip .fn { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip small { color: var(--fg-dim); }
.files .file-chip { padding-right: 2px; }
.icon-btn.rec { background: var(--err); color: var(--on-err); }
.listening { flex: 1; display: flex; align-items: center; gap: 10px; min-height: 36px; padding: 0 6px; color: var(--err); font-size: 14px; }
.wave { display: inline-flex; align-items: center; gap: 3px; height: 18px; }
.wave i { width: 3px; height: 6px; border-radius: 2px; background: currentColor; animation: wave 0.9s infinite ease-in-out; }
.wave i:nth-child(2) { animation-delay: 0.12s; }
.wave i:nth-child(3) { animation-delay: 0.24s; }
.wave i:nth-child(4) { animation-delay: 0.36s; }
.wave i:nth-child(5) { animation-delay: 0.48s; }
@keyframes wave { 0%, 100% { height: 5px; } 50% { height: 18px; } }
@media (max-width: 760px) {
    .page-chat { grid-template-columns: minmax(0, 1fr); }
    .chat-side { display: none; }
    .chat-head { padding-left: 16px; }
    .chat-head .icon-btn { display: inline-grid; }
}
@media (max-width: 480px) {
    #chatSend span { display: none; }
    #chatSend { padding: 0 11px; }
}

/* ---- Log: a column on the right, below the page on narrower screens, a bar at the bottom on phones ---- */
.log { grid-area: log; position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--panel); border-left: 1px solid var(--line); }
body[data-log="closed"] .log, body[data-view="settings"] .log { display: none; }
.log-toggle { margin-right: 12px; }
.log-toggle[aria-pressed="true"] { background: var(--panel-hi); }
.log-grip { position: absolute; z-index: 2; left: -4px; top: 0; bottom: 0; width: 8px; cursor: ew-resize; touch-action: none; }
.log-grip:hover, .log-grip:focus-visible { outline: none; background: linear-gradient(to right, transparent 3px, var(--accent) 3px 5px, transparent 5px); }
.log-head { display: flex; align-items: center; gap: 2px; padding: 8px 8px 6px 14px; }
.log-title { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; padding: 4px 0; border: 0; background: transparent; cursor: default; text-align: left; }
.log-title strong { font-size: 13px; }
.log-title .chev { display: none; width: 16px; height: 16px; color: var(--fg-dim); transition: transform 0.15s; }
.log-last { display: none; min-width: 0; font: 11.5px var(--mono); color: var(--fg-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent); color: var(--accent-fg); font-size: 10.5px; text-align: center; line-height: 18px; }
.log-filters { display: flex; gap: 4px; padding: 0 12px 8px; border-bottom: 1px solid var(--line); overflow-x: auto; flex: none; }
.log-filters button { flex: none; padding: 2px 9px; border: 1px solid var(--line); border-radius: 999px; background: transparent; cursor: pointer; font-size: 11.5px; color: var(--fg-dim); }
.log-filters button[aria-pressed="true"] { background: var(--fg); border-color: var(--fg); color: var(--panel); }
.log-list { flex: 1; min-height: 0; overflow: auto; margin: 0; padding: 4px 0 72px; list-style: none; font: 12px/1.45 var(--mono); }
.log-list:empty::before { content: "Nothing logged yet."; display: block; padding: 10px 14px; color: var(--fg-dim); font-family: var(--sans); }
.le-btn { display: block; width: 100%; padding: 3px 14px 3px 12px; border: 0; border-left: 2px solid transparent; background: transparent; cursor: pointer; text-align: left; font: inherit; overflow-wrap: anywhere; }
.le-btn:hover { background: var(--panel-hi); }
.le-btn[aria-expanded="true"] { border-left-color: var(--accent); background: var(--panel-hi); }
.le .ts { color: var(--fg-dim); margin-right: 8px; font-variant-numeric: tabular-nums; }
.le .k { display: inline-block; min-width: 44px; margin-right: 4px; font-size: 10.5px; letter-spacing: 0.04em; text-transform: uppercase; }
.le.sent .k { color: var(--accent); }
.le.ack .k { color: var(--ok); }
.le.err .k { color: var(--err); }
.le.err .txt { color: var(--err); }
.le.event .k { color: var(--warn); }
.le.info .k { color: var(--fg-dim); }
.le pre { margin: 2px 12px 6px 14px; padding: 8px 10px; background: var(--bg); border-radius: 6px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 11.5px; }
/* Expanded: placed across the whole grid, so it covers the page and not just its own column */
.log[data-expanded] { grid-area: 1 / 1 / -1 / -1; position: absolute; inset: 0; z-index: 20; height: auto; border: 0; }
.log[data-expanded] .log-grip { display: none; }
@media (max-width: 1099px) {
    .workspace { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; grid-template-areas: "main" "log"; }
    body[data-log="closed"] .workspace { grid-template-rows: minmax(0, 1fr); grid-template-areas: "main"; }
    body[data-view="settings"] .workspace { grid-template-rows: minmax(0, 1fr); grid-template-areas: "main"; }
    .log { height: var(--log-h, 240px); border-left: 0; border-top: 1px solid var(--line); }
    .log-grip { left: 0; right: 0; top: -4px; bottom: auto; width: auto; height: 8px; cursor: ns-resize; }
    .log-grip:hover, .log-grip:focus-visible { background: linear-gradient(to bottom, transparent 3px, var(--accent) 3px 5px, transparent 5px); }
}
@media (max-width: 760px) {
    .log { height: auto; padding-bottom: env(safe-area-inset-bottom, 0px); }
    .log[data-open] { height: 50vh; }
    .log-grip { display: none; }
    .log-title { cursor: pointer; }
    .log-title .chev { display: block; }
    .log[data-open] .log-title .chev { transform: rotate(180deg); }
    .log:not([data-open]):not([data-expanded]) :is(.log-filters, .log-list, .log-tool) { display: none; }
    .log:not([data-open]):not([data-expanded]) .log-last { display: block; }
}

/* ---- Modals ---- */
.modal-bg { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; background: var(--scrim); }
.modal { width: min(420px, 100%); max-height: 86vh; overflow: auto; display: flex; flex-direction: column; gap: 12px; margin: 0; padding: 20px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); box-shadow: 0 20px 48px var(--shadow); }
.modal h2 { margin: 0; font-size: 17px; }
.modal p { margin: 0; }
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}
