/* STATIC web app. Cable-run and label-maker: quiet, dense where useful, very
   legible in a dim closet or in sunlight. The one loud thing is the scan tape. */

/* ==== tokens ============================================================== */
@font-face { font-family: "Barlow"; font-weight: 400; font-style: normal; font-display: swap;
             src: url("vendor/fonts/barlow-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow"; font-weight: 500; font-style: normal; font-display: swap;
             src: url("vendor/fonts/barlow-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow"; font-weight: 600; font-style: normal; font-display: swap;
             src: url("vendor/fonts/barlow-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow Condensed"; font-weight: 600; font-style: normal; font-display: swap;
             src: url("vendor/fonts/barlow-condensed-latin-600-normal.woff2") format("woff2"); }

:root {
  /* dark first */
  --rack: #1A2026;
  --panel: #232B32;
  --panel-2: #2C363E;
  --ink: #E8ECEE;
  --steel: #8E9AA3;
  --line: #34404A;
  --cat6: #3F8CDB;
  --live: #E5534B;
  --tape: #F2F0E6;
  --tape-unsure: #F4D35E;
  --ok: #3FB27F;
  /* text on --cat6 / --live: white is only 3.5:1 on the dark-mode blue, so dark ink */
  --on-cat6: #0E1418;
  --on-live: #0E1418;
  --scrim: rgba(8, 11, 14, 0.6);
  --float: 0 10px 32px rgba(0, 0, 0, 0.45);
  --font: "Barlow", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --narrow: "Barlow Condensed", "Barlow", system-ui, sans-serif;
  --r-control: 6px;
  --r-sheet: 12px;
  --kb: 0px;            /* height the phone keyboard covers (visualViewport), set by app.js */
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --rack: #EEF1F2; --panel: #FFFFFF; --panel-2: #E3E8EA; --ink: #182026; --steel: #5C6870;
    --line: #D3DADD; --cat6: #2369B8; --live: #C93C35; --ok: #1F8A5A;
    --on-cat6: #FFFFFF; --on-live: #FFFFFF;
    --scrim: rgba(24, 32, 38, 0.4); --float: 0 10px 32px rgba(24, 32, 38, 0.18);
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --rack: #EEF1F2; --panel: #FFFFFF; --panel-2: #E3E8EA; --ink: #182026; --steel: #5C6870;
  --line: #D3DADD; --cat6: #2369B8; --live: #C93C35; --ok: #1F8A5A;
  --on-cat6: #FFFFFF; --on-live: #FFFFFF;
  --scrim: rgba(24, 32, 38, 0.4); --float: 0 10px 32px rgba(24, 32, 38, 0.18);
  color-scheme: light;
}

/* ==== base ================================================================ */
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body {
  display: flex; flex-direction: column;
  height: var(--app-h, 100dvh);
  background: var(--rack); color: var(--ink);
  font: 400 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8;
      stroke-linecap: round; stroke-linejoin: round; flex: none; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
button:disabled { opacity: 0.45; cursor: default; }
:focus-visible { outline: 2px solid var(--cat6); outline-offset: 2px; }
:focus:not(:focus-visible) { outline: none; }
h1, h2, h3 { font-weight: 600; }
.help { margin: 0; color: var(--steel); font-size: 15px; }
.readout { font: 600 15px/1 var(--narrow); font-variant-numeric: tabular-nums; }
/* buttons: one accent, quiet secondaries */
.primary, .buttons button, .sheet-buttons button, .detail-actions button, .big-three button, .test-row button {
  min-height: 44px; padding: 0 16px; border-radius: var(--r-control);
  background: var(--cat6); color: var(--on-cat6); font-weight: 600;
}
.secondary, .buttons button.secondary, .sheet-buttons button.secondary, .detail-actions .secondary,
.big-three .secondary, .test-row .secondary {
  background: var(--panel-2); color: var(--ink); font-weight: 500;
}
.danger, .detail-actions .danger { background: var(--live); color: var(--on-live); }
.link-btn { min-height: 44px; color: var(--cat6); font-weight: 600; text-align: left; }
.field { display: block; font-size: 15px; color: var(--steel); }
.field input {
  display: block; width: 100%; margin-top: 4px; min-height: 44px; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: var(--r-control);
  background: var(--panel-2); color: var(--ink); font-size: 16px;   /* 16px: no zoom on iPhone */
}
.field input:focus { outline: 2px solid var(--cat6); outline-offset: -1px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--steel); flex: none; }
.dot.ok { background: var(--ok); }
.dot.bad { background: var(--live); }
.dot.busy { background: var(--cat6); }
.live { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
.live i { width: 8px; height: 8px; border-radius: 50%; background: var(--live); flex: none; animation: blink 1.6s infinite; }
.live span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ==== chat: layout, header, messages, composer ============================= */
.app { flex: 1; min-height: 0; display: flex; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.top {
  display: flex; align-items: center; gap: 8px;
  min-height: 56px; padding: 6px 12px; padding-top: calc(6px + env(safe-area-inset-top));
  padding-left: calc(12px + env(safe-area-inset-left)); padding-right: calc(12px + env(safe-area-inset-right));
  border-bottom: 1px solid var(--line); background: var(--rack);
}
.brand { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.chat-title { min-width: 0; min-height: 44px; padding: 0 8px; border-radius: var(--r-control);
              font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-title:hover { background: var(--panel-2); }
.private-tag { display: inline-flex; align-items: center; gap: 4px; flex: none; font-size: 13px; font-weight: 500;
               color: var(--steel); }
.private-tag svg { width: 16px; height: 16px; }
.head-status { display: inline-flex; align-items: center; gap: 6px; flex: none; font-size: 13px; font-weight: 500;
               color: var(--steel); white-space: nowrap; }
.actions { display: flex; align-items: center; gap: 4px; position: relative; }
.pc-actions { display: flex; gap: 4px; }
.tool {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-width: 44px; height: 44px; padding: 0 10px; border-radius: var(--r-control);
  color: var(--ink); font-size: 15px; font-weight: 500;
}
.tool:hover { background: var(--panel-2); }
.tool.on { background: var(--cat6); color: var(--on-cat6); }
.tool.only-icon { padding: 0; color: var(--steel); }
.tool.only-icon:hover, #private-btn.on { color: var(--ink); }
#private-btn.on { background: var(--panel-2); }
.pc-btn, .tool.menu-btn { display: none; }

/* phones: Screen / Control / Screenshot sit in a small "PC" menu */
@media (max-width: 720px) {
  .pc-btn { display: inline-flex; }
  .head-status span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .head-status.say span { position: static; width: auto; height: auto; clip: auto; }
  .pc-actions {
    position: absolute; top: calc(100% + 6px); right: 44px; z-index: 30;
    flex-direction: column; gap: 0; min-width: 200px; padding: 4px;
    background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-sheet); box-shadow: var(--float);
    visibility: hidden; opacity: 0; transform: translateY(-4px); transition: opacity .12s, transform .12s, visibility .12s;
  }
  .pc-actions.open { visibility: visible; opacity: 1; transform: none; }
  .pc-actions .tool { justify-content: flex-start; width: 100%; padding: 0 12px; }
}

.page { flex: 1; min-height: 0; display: flex; flex-direction: column; width: 100%; }
main {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  padding: 16px max(16px, env(safe-area-inset-right)) 16px max(16px, env(safe-area-inset-left));
  display: flex; flex-direction: column; gap: 12px;
}
main > * { width: 100%; max-width: 760px; margin-left: auto; margin-right: auto; }
/* empty chat: one question, four big actions */
.hint { margin: auto; padding: 24px 0; }
.hint h2 { margin: 0 0 16px; font-size: 24px; text-align: center; }
.big-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; max-width: 520px; margin: 0 auto; }
.big-actions button {
  display: flex; flex-direction: column; align-items: flex-start; gap: 12px;
  min-height: 96px; padding: 16px; border-radius: var(--r-sheet);
  background: var(--panel); border: 1px solid var(--line); text-align: left; font-size: 16px; font-weight: 600;
}
.big-actions button svg { color: var(--cat6); }
.big-actions button:hover { border-color: var(--cat6); }

/* STATIC's reply: plain text on the page, no bubble, 68ch. Yours: a --panel-2 block */
.msg { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.static { max-width: 68ch; margin-left: 0; align-self: flex-start; }
main > .msg.static { margin-left: auto; margin-right: auto; max-width: 760px; }
.msg.static > * { max-width: 68ch; }
.msg.you {
  align-self: flex-end; width: auto; max-width: min(85%, 560px); margin-right: max(0px, calc((100% - 760px) / 2));
  margin-left: auto; padding: 8px 12px; border-radius: var(--r-sheet); background: var(--panel-2);
}
.msg code { font: 0.92em ui-monospace, SFMono-Regular, Menlo, monospace; padding: 1px 4px;
            border-radius: 4px; background: var(--panel-2); }
.msg.note { align-self: center; text-align: center; color: var(--steel); font-size: 15px; }
.msg.error { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 12px;
             border-radius: var(--r-sheet); border: 1px solid var(--line); border-left: 4px solid var(--live);
             background: var(--panel); white-space: normal; }
.msg.error button { min-height: 44px; padding: 0 16px; border-radius: var(--r-control); background: var(--cat6);
                    color: var(--on-cat6); font-weight: 600; }
.msg.typing::after { content: "•••"; letter-spacing: 2px; color: var(--steel); animation: blink 1.2s infinite; }
.msg .status-label { color: var(--steel); font-size: 15px; }
.msg .status-label::after { content: " •••"; letter-spacing: 2px; animation: blink 1.2s infinite; }

/* formatted replies (Markdown) */
.msg.md { white-space: normal; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 12px; }
.md h1, .md h2, .md h3, .md h4 { margin: 16px 0 8px; line-height: 1.3; }
.md h1 { font-size: 24px; } .md h2 { font-size: 19px; } .md h3, .md h4 { font-size: 16px; }
.md ul, .md ol { margin: 0 0 12px; padding-left: 24px; }
.md li { margin: 4px 0; }
.md li > p { margin: 0; }
.md strong { font-weight: 600; }
.md a { color: var(--cat6); text-underline-offset: 2px; }
.md blockquote { margin: 0 0 12px; padding: 0 12px; border-left: 3px solid var(--line); color: var(--steel); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.md pre { position: relative; margin: 0 0 12px; padding: 12px; padding-top: 40px; border-radius: var(--r-control);
          overflow-x: auto; background: var(--panel); border: 1px solid var(--line); }
.md pre code { padding: 0; background: none; font-size: 14px; line-height: 1.5; white-space: pre; }
.md .copy { position: absolute; top: 4px; right: 4px; min-height: 32px; padding: 0 12px; border-radius: var(--r-control);
            font-size: 13px; font-weight: 600; background: var(--panel-2); color: var(--ink); }
@media (hover: hover) and (pointer: fine) {
  .md pre { padding-top: 12px; }
  .md .copy { opacity: 0; }
  .md pre:hover .copy, .md .copy:focus-visible { opacity: 1; }
}
.md .table-wrap { overflow-x: auto; margin: 0 0 12px; }
.md table { border-collapse: collapse; font-size: 15px; }
.md th, .md td { border: 1px solid var(--line); padding: 4px 8px; text-align: left; vertical-align: top; }
.md th { background: var(--panel); font-weight: 600; }
.md .katex-display { margin: 8px 0 12px; overflow-x: auto; overflow-y: hidden; padding: 2px 0; }
/* 👍/👎: small and quiet until hovered or tapped */
.rate { display: flex; gap: 4px; margin-top: -8px; }
.rate button { width: 44px; height: 36px; border-radius: var(--r-control); font-size: 15px;
               opacity: 0.6; filter: grayscale(1); }
.rate button:hover, .rate button:focus-visible, .rate button.on { opacity: 1; filter: none; background: var(--panel-2); }
.chip-yes { display: inline-flex; margin-top: 8px; min-height: 44px; padding: 0 16px; border-radius: var(--r-control);
            background: var(--panel-2); color: var(--ink); font-weight: 600; }

/* photos and files in messages */
.msg .photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 4px; }
.msg .photos + .text { margin-top: 8px; }
.msg .photos img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: var(--r-control);
                   cursor: zoom-in; background: var(--panel-2); }
.msg .photos:has(> img:only-child) { grid-template-columns: 1fr; }
.msg .photos img:only-child { aspect-ratio: auto; max-height: 340px; object-fit: contain; }
.msg.has-photos.you { width: min(85%, 340px); padding: 4px; }
.msg.has-photos .text { padding: 2px 8px 4px; }
.msg.shot { width: min(100%, 420px); }
.shot img { display: block; width: 100%; border-radius: var(--r-control); cursor: zoom-in; }
.shot .shot-actions { display: flex; gap: 16px; padding: 8px 0 0; font-size: 15px; }
.shot .shot-actions a { color: var(--cat6); font-weight: 600; min-height: 44px; display: inline-flex; align-items: center; }
.files { display: flex; flex-direction: column; gap: 4px; }
.photos + .files, .files + .text { margin-top: 8px; }
.file-chip { display: flex; align-items: center; gap: 12px; min-width: 0; padding: 8px; border-radius: var(--r-control);
             text-decoration: none; color: inherit; background: var(--panel); border: 1px solid var(--line); }
a.file-chip:hover { border-color: var(--cat6); }
.file-chip .badge { flex: none; width: 36px; height: 36px; border-radius: 4px; display: grid; place-items: center;
                    font: 600 13px/1 var(--narrow); color: #fff; background: #5C6870; }
.file-chip .badge.pdf { background: #B23A33; }
.file-chip .badge.doc { background: #2369B8; }
.file-chip .badge.sheet { background: #1F7A50; }
.file-chip .badge.slides { background: #A35A00; }
.file-chip .meta { min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.file-chip .name { font-size: 15px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-chip .sub { font-size: 13px; color: var(--steel); }

/* composer: task chips, attachments, the bar */
.composer {
  flex: none; padding: 8px 12px; padding-bottom: calc(8px + max(env(safe-area-inset-bottom), 0px));
  padding-left: calc(12px + env(safe-area-inset-left)); padding-right: calc(12px + env(safe-area-inset-right));
  border-top: 1px solid var(--line); background: var(--rack);
}
.composer > * { max-width: 760px; margin-left: auto; margin-right: auto; }
.tasks { display: flex; gap: 8px; overflow-x: auto; margin-bottom: 8px; scrollbar-width: none; }
.task-chip { display: inline-flex; align-items: center; gap: 8px; flex: none; max-width: 100%; height: 36px;
             padding: 0 4px 0 12px; border-radius: var(--r-control); background: var(--panel-2); font-size: 15px; }
.task-chip i { width: 8px; height: 8px; border-radius: 50%; background: var(--cat6); flex: none; }
.task-chip span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 60vw; }
.task-chip button { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 4px; color: var(--steel); }
.task-chip button:hover { color: var(--ink); background: var(--line); }
.task-chip button svg { width: 16px; height: 16px; }
.bar { display: flex; align-items: flex-end; gap: 4px; padding: 4px; border-radius: var(--r-sheet);
       background: var(--panel); border: 1px solid var(--line); }
.bar:focus-within { border-color: var(--cat6); }
.composer.dragging .bar { border-color: var(--cat6); border-style: dashed; }
.bar textarea {
  flex: 1; min-width: 0; min-height: 44px; max-height: calc(6 * 1.5em + 20px); resize: none;
  padding: 10px 4px; border: 0; outline: 0; background: none; color: var(--ink);
  font-size: 16px; line-height: 1.5; overflow-y: auto;
}
.bar textarea::placeholder { color: var(--steel); }
.attach, .round { width: 44px; height: 44px; display: grid; place-items: center; flex: none; border-radius: var(--r-control);
                  color: var(--steel); }
.attach:hover, .round:hover { color: var(--ink); background: var(--panel-2); }
.round.send { background: var(--cat6); color: var(--on-cat6); }
.round.stop { background: var(--live); color: var(--on-live); }
.round.stop svg { fill: currentColor; stroke: none; }
/* the mic: full round, its state on the button itself */
.round.mic { position: relative; border-radius: 50%; }
.round.mic::before { content: ""; position: absolute; inset: -2px; border-radius: 50%; border: 2px solid transparent;
                     transform: scale(calc(1 + var(--level, 0) * 0.5)); pointer-events: none; }
.round.mic.recording { background: var(--live); color: var(--on-live); }
.round.mic.recording::before { border-color: var(--live); }
.round.mic.thinking { color: var(--cat6); }
.round.mic.thinking::before { border-color: var(--cat6); border-right-color: transparent; animation: spin 1s linear infinite; }
.round.mic.speaking { background: var(--panel-2); color: var(--ink); }
.round.mic.speaking::before { border-color: var(--cat6); }
.attachments { display: flex; gap: 8px; margin-bottom: 8px; overflow-x: auto; padding: 6px 2px 2px; }
.attachments .thumb { position: relative; flex: none; }
.attachments img { width: 64px; height: 64px; object-fit: cover; border-radius: var(--r-control); display: block;
                   border: 1px solid var(--line); }
.attachments .file-chip { width: 200px; height: 64px; flex: none; }
.attachments .remove { position: absolute; top: -6px; right: -6px; width: 24px; height: 24px; border-radius: 50%;
                       display: grid; place-items: center; background: var(--ink); color: var(--rack); }
.attachments .remove::after { content: ""; position: absolute; inset: -10px; }   /* a 44px target */
.attachments .remove svg { width: 12px; height: 12px; stroke-width: 2.6; }

/* conversation mode: a big state ring, what Jacob is saying, End */
.round.talk { width: auto; min-width: 44px; padding: 0 10px; gap: 6px; display: inline-flex; align-items: center; justify-content: center;
              color: var(--ink); font-size: 15px; font-weight: 500; }
.round.talk span { display: none; }
@media (min-width: 560px) { .round.talk span { display: inline; } }
.conv-bar { display: flex; align-items: center; gap: 12px; padding: 8px; border-radius: var(--r-sheet);
            background: var(--panel); border: 1px solid var(--line); }
.conv-ring { position: relative; flex: none; width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center;
             background: var(--panel-2); color: var(--ink); }
.conv-ring svg { width: 28px; height: 28px; }
.conv-ring::before { content: ""; position: absolute; inset: -4px; border-radius: 50%; border: 3px solid transparent;
                     transform: scale(calc(1 + var(--level, 0) * 0.25)); transition: transform 80ms linear; }
.conv-bar[data-state="listening"] .conv-ring { background: var(--live); color: var(--on-live); }
.conv-bar[data-state="listening"] .conv-ring::before { border-color: var(--live); }
.conv-bar[data-state="thinking"] .conv-ring::before, .conv-bar[data-state="starting"] .conv-ring::before {
  border-color: var(--cat6); border-right-color: transparent; animation: spin 1s linear infinite; }
.conv-bar[data-state="speaking"] .conv-ring { background: var(--cat6); color: var(--on-cat6); }
.conv-bar[data-state="working"] .conv-ring::before { border-color: var(--cat6); border-style: dashed; }
.conv-bar[data-state="paused"] .conv-ring { background: var(--tape-unsure); color: #15191C; }
.conv-mid { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.conv-state { font-size: 19px; font-weight: 600; }
.conv-text { color: var(--steel); font-size: 15px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.conv-end { flex: none; min-height: 44px; padding: 0 16px; border-radius: var(--r-control); background: var(--panel-2); font-weight: 600; }

/* ==== sidebar ============================================================= */
.sidebar {
  width: 288px; flex: none; display: flex; flex-direction: column; gap: 8px;
  padding: 12px 8px calc(8px + env(safe-area-inset-bottom));
  padding-top: calc(12px + env(safe-area-inset-top)); padding-left: calc(8px + env(safe-area-inset-left));
  background: var(--panel); border-right: 1px solid var(--line);
}
.side-top { display: flex; align-items: baseline; gap: 12px; padding: 0 8px 4px; }
h1 { margin: 0; font-size: 19px; letter-spacing: 0.04em; }
.status { display: inline-flex; align-items: center; gap: 6px; color: var(--steel); font-size: 13px; min-width: 0; white-space: nowrap; }
.status.ok .dot { background: var(--ok); }
.status.bad .dot { background: var(--live); }
.new-chat { display: flex; align-items: center; justify-content: center; gap: 8px; }
.search { display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 12px; border-radius: var(--r-control);
          background: var(--panel-2); color: var(--steel); }
.search svg { width: 18px; height: 18px; }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; color: var(--ink); font-size: 16px; }
.search:focus-within { outline: 2px solid var(--cat6); }
.chat-list { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.chat-group { margin: 12px 8px 4px; font-size: 13px; font-weight: 600; color: var(--steel); }
.chat-item { position: relative; display: flex; align-items: center; border-radius: var(--r-control); }
.chat-item:hover, .chat-item.active { background: var(--panel-2); }
.chat-item.active::before { content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 2px; background: var(--cat6); }
.chat-item .open { flex: 1; min-width: 0; min-height: 44px; text-align: left; padding: 0 12px; font-size: 15px;
                   white-space: nowrap; overflow: hidden; text-overflow: ellipsis; -webkit-touch-callout: none; user-select: none; }
.chat-item .lock { flex: none; width: 16px; height: 16px; margin-left: 12px; color: var(--steel); }
.chat-item .lock + .open { padding-left: 6px; }
.chat-item .act { width: 40px; height: 44px; display: none; place-items: center; border-radius: var(--r-control); color: var(--steel); flex: none; }
.chat-item .act svg { width: 18px; height: 18px; }
.chat-item .act:hover { color: var(--ink); background: var(--line); }
.chat-item.acts .act { display: grid; }   /* long-press on a phone */
@media (hover: hover) and (pointer: fine) { .chat-item:hover .act, .chat-item:focus-within .act { display: grid; } }
.chat-empty { padding: 12px; color: var(--steel); font-size: 15px; }
.scrim { position: fixed; inset: 0; z-index: 14; background: var(--scrim); }
@media (max-width: 900px) {
  .sidebar { position: fixed; top: 0; bottom: 0; left: 0; z-index: 15; width: min(320px, 86vw);
             transform: translateX(-102%); visibility: hidden; box-shadow: var(--float);
             transition: transform 180ms ease-out, visibility 0s 180ms; }
  .sidebar.open { transform: none; visibility: visible; transition: transform 180ms ease-out; }
  .tool.menu-btn { display: inline-flex; }
}
@media (min-width: 901px) { .scrim { display: none !important; } }

/* ==== viewer (live screen) ================================================ */
.viewer { flex: none; display: flex; flex-direction: column; background: #000; border-bottom: 1px solid var(--line); }
.viewer canvas { display: block; width: 100%; height: auto; max-height: 55vh; object-fit: contain; background: #000; }
.viewer-bar, .remote-bar {
  display: flex; align-items: center; gap: 4px; padding: 4px 8px; padding-left: calc(12px + env(safe-area-inset-left));
  background: var(--panel); color: var(--steel); font-size: 13px; font-weight: 500;
}
.viewer-bar .live, .remote-bar .live { flex: 1; }
.viewer-bar .live.slow span { color: var(--ink); }
.bar-btn { display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
           min-width: 52px; height: 52px; padding: 0 6px; border-radius: var(--r-control); color: var(--ink);
           font-size: 13px; font-weight: 500; }
.bar-btn:hover, .bar-btn.on { background: var(--panel-2); }
.bar-btn.on { color: var(--cat6); }
@media (min-width: 721px) {
  .viewer-bar .bar-btn { flex-direction: row; gap: 6px; height: 44px; padding: 0 10px; font-size: 15px; }
}
.viewer.full, .viewer:fullscreen { position: fixed; inset: 0; z-index: 10; }
.viewer.full canvas, .viewer:fullscreen canvas { flex: 1; min-height: 0; height: 100%; max-height: none; }

/* ==== remote control ====================================================== */
.remote { position: fixed; inset: 0; z-index: 20; display: flex; flex-direction: column; background: #000; color: var(--ink); }
.stage { position: relative; flex: 1; min-height: 0; overflow: hidden; touch-action: none; cursor: default;
         -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.stage canvas { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.touch-dot { position: absolute; width: 36px; height: 36px; margin: -18px 0 0 -18px; border-radius: 50%;
             border: 2px solid rgba(255,255,255,.9); background: rgba(63,140,219,.35); pointer-events: none; }
.touch-dot.pop { animation: pop .35s ease-out forwards; }
.remote-help { position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); margin: 0;
               width: max-content; max-width: calc(100% - 24px); padding: 8px 12px; border-radius: var(--r-sheet);
               background: var(--panel); color: var(--ink); font-size: 15px; text-align: center; box-shadow: var(--float);
               pointer-events: none; transition: opacity .6s; }
.remote-bar { padding-bottom: calc(4px + env(safe-area-inset-bottom)); overflow-x: auto; }
.remote-bar .bar-btn { flex: none; }
@media (max-width: 420px) { .remote-bar .live span { display: none; } .remote-bar .live { flex: 0 0 auto; margin-right: auto; } }
.keys-row { display: flex; flex-wrap: wrap; gap: 8px; padding: 8px; background: var(--rack);
            padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
.keys-row button { min-width: 44px; height: 44px; padding: 0 12px; border-radius: var(--r-control);
                   background: var(--panel-2); color: var(--ink); font-size: 15px; font-weight: 500; }
.keys-row button.on { background: var(--cat6); color: var(--on-cat6); box-shadow: inset 0 -3px 0 rgba(0,0,0,.25); }
@media (max-width: 600px) { .keys-row { flex-wrap: nowrap; overflow-x: auto; } .keys-row button { flex: none; } }
.kb-input { position: fixed; left: 0; bottom: 0; width: 1px; height: 1px; opacity: 0; border: 0; padding: 0; font-size: 16px; }
/* sideways phone: controls move to the right edge so the screen gets the full height */
@media (orientation: landscape) and (max-height: 560px) {
  .remote { flex-direction: row; flex-wrap: wrap; }
  .stage { order: 0; height: 100%; }
  .remote-bar { order: 1; flex-direction: column; justify-content: center; height: 100%; overflow-y: auto;
                padding: 4px calc(4px + env(safe-area-inset-right)) 4px 4px; }
  .remote-bar .live { flex: 0; margin: 0 0 8px; }
  .remote-bar .live span { display: none; }
  .remote-bar .bar-btn { height: 48px; }
  .keys-row { order: 2; position: absolute; left: 0; right: 68px; bottom: 0; flex-wrap: nowrap; overflow-x: auto; }
  .keys-row button { flex: none; }
}

/* ==== scan ================================================================ */
.scan { position: fixed; inset: 0; z-index: 20; display: flex; flex-direction: column; background: #000; color: #E8ECEE; }
.scan-stage { position: relative; flex: 1; min-height: 0; overflow: hidden; }
.scan-stage video, .scan-stage img, .scan-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.scan-top { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 12px;
            padding: 4px 4px 4px 16px; padding-top: calc(4px + env(safe-area-inset-top));
            background: linear-gradient(rgba(0,0,0,.7), rgba(0,0,0,0)); font-size: 15px; font-weight: 500; }
.scan-top .live { flex: 1; }
.scan-fps { font: 600 15px/1 var(--narrow); font-variant-numeric: tabular-nums; color: #E8ECEE; white-space: nowrap; }
.field-dot { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: #E8ECEE; }
.field-dot i { width: 8px; height: 8px; border-radius: 50%; border: 2px solid var(--tape-unsure); }
.scan-icon { width: 44px; height: 44px; display: grid; place-items: center; border-radius: var(--r-control); color: #E8ECEE; flex: none; }
.scan-icon:hover { background: rgba(255,255,255,.12); }
.menu { position: absolute; z-index: 5; min-width: 220px; padding: 4px; border-radius: var(--r-sheet);
        background: var(--panel); border: 1px solid var(--line); box-shadow: var(--float); }
.menu button { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 44px; padding: 0 12px;
               border-radius: var(--r-control); text-align: left; font-size: 16px; }
.menu button:hover, .menu button.on { background: var(--panel-2); }
.menu button.on svg { color: var(--tape-unsure); }
.scan-menu { top: calc(52px + env(safe-area-inset-top)); right: 8px; }
.scan-note { position: absolute; left: 50%; top: calc(60px + env(safe-area-inset-top)); transform: translateX(-50%); margin: 0;
             width: max-content; max-width: calc(100% - 32px); padding: 8px 12px; border-radius: var(--r-sheet);
             background: rgba(10, 13, 16, .82); color: #E8ECEE; font-size: 15px; text-align: center; pointer-events: none; }
.scan-note.scan-caption { top: auto; bottom: 16px; max-height: 40%; overflow: auto; text-align: left; pointer-events: auto; }
.coach { position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); margin: 0; width: max-content;
         max-width: calc(100% - 32px); padding: 8px 12px; border-radius: var(--r-sheet);
         background: var(--tape); color: #15191C; font-size: 15px; font-weight: 500; text-align: center; }
.coach::after { content: ""; position: absolute; left: 50%; bottom: -6px; width: 12px; height: 12px; margin-left: -6px;
                background: var(--tape); transform: rotate(45deg); }
.scan-bar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px;
            padding: 8px 16px; padding-bottom: calc(8px + env(safe-area-inset-bottom)); background: #0E1316; }
.scan-btn { position: relative; justify-self: center; display: flex; flex-direction: column; align-items: center; gap: 2px;
            min-width: 72px; min-height: 56px; padding: 4px 8px; border-radius: var(--r-control); color: #E8ECEE;
            font-size: 13px; font-weight: 500; }
.scan-btn:hover { background: rgba(255,255,255,.08); }
.scan-btn.teaching { background: var(--tape); color: #15191C; }
.ask-btn { position: relative; width: 72px; height: 72px; border-radius: 50%; display: grid; place-items: center;
           background: var(--cat6); color: var(--on-cat6); }
.ask-btn svg { width: 30px; height: 30px; }
.ask-btn::before { content: ""; position: absolute; inset: -5px; border-radius: 50%; border: 3px solid transparent;
                   transform: scale(calc(1 + var(--level, 0) * 0.35)); }
.ask-btn.recording { background: var(--live); color: var(--on-live); }
.ask-btn.recording::before { border-color: var(--live); }
.ask-btn.holding::before { border-color: var(--tape); }
.badge-count { position: absolute; top: 0; right: 10px; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
               background: var(--tape-unsure); color: #15191C; font: 600 13px/20px var(--narrow); }

/* ==== sheets (teach, confirm) ============================================= */
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 6; max-height: 80%; overflow-y: auto;
  padding: 8px 16px 16px; padding-bottom: calc(16px + env(safe-area-inset-bottom) + var(--kb));
  border-radius: var(--r-sheet) var(--r-sheet) 0 0; background: var(--panel); color: var(--ink); box-shadow: var(--float);
  animation: sheet-up 180ms ease-out;
}
@media (min-width: 721px) { .sheet { left: 50%; right: auto; width: 440px; margin-left: -220px; border-radius: var(--r-sheet);
                                     bottom: calc(104px + env(safe-area-inset-bottom)); } }
.sheet-grip { width: 36px; height: 4px; margin: 0 auto 12px; border-radius: 2px; background: var(--line); }
.sheet h2 { margin: 0 0 8px; font-size: 19px; }
.sheet .help { margin-bottom: 16px; }
.sheet .field { margin-bottom: 16px; }
.sheet-buttons { display: flex; gap: 8px; }
.sheet-buttons button { flex: 1; }
.teach-step { display: block; }
#teach-capture { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 8px 0; }
.ring { width: 72px; height: 72px; transform: rotate(-90deg); }
.ring circle { fill: none; stroke: var(--panel-2); stroke-width: 4; }
.ring .fill { stroke: var(--cat6); stroke-dasharray: 125.7; stroke-dashoffset: 125.7; }
.ring.go .fill { transition: stroke-dashoffset var(--capture, 2s) linear; stroke-dashoffset: 0; }
.confirm-head { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; }
.confirm-head img { width: 88px; height: 88px; object-fit: cover; border-radius: var(--r-control); background: #000; flex: none; }
.confirm-head h2 { margin: 0; }
.big-three { display: grid; grid-template-columns: 1fr 1fr 1.4fr; gap: 8px; }
.big-three button { min-height: 56px; font-size: 16px; }
.big-three .no { background: var(--panel-2); color: var(--ink); }
#ask-other-form { margin-top: 16px; }

/* ==== review and my objects (full screen over the scan) =================== */
.review, .objects-screen { position: absolute; inset: 0; z-index: 7; display: flex; flex-direction: column; gap: 12px;
                           padding: 0 max(16px, calc((100% - 720px) / 2)) 16px;
                           padding-bottom: calc(16px + env(safe-area-inset-bottom));
                           background: var(--rack); color: var(--ink); overflow-y: auto; }
.screen-head { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; gap: 8px; margin: 0 -12px;
               padding: 4px 12px 4px 0; padding-top: calc(4px + env(safe-area-inset-top)); background: var(--rack); }
.screen-head .scan-icon { color: var(--ink); }
.screen-head .scan-icon:hover { background: var(--panel-2); }
.screen-head h2 { flex: 1; margin: 0; font-size: 19px; }
.review-cards { position: relative; flex: 1; min-height: 280px; }
.review-card { position: absolute; inset: 0; display: flex; flex-direction: column; gap: 12px; padding: 12px;
               border-radius: var(--r-sheet); background: var(--panel); border: 1px solid var(--line);
               touch-action: none; user-select: none; transition: transform .18s ease-out, opacity .18s; }
.review-card img { flex: 1; min-height: 0; width: 100%; object-fit: contain; border-radius: var(--r-control); background: #000; }
.review-card .q { font-size: 19px; font-weight: 600; }
.review-card.yes { box-shadow: inset 6px 0 0 var(--ok); }
.review-card.no { box-shadow: inset -6px 0 0 var(--live); }
.review-empty { margin: auto; max-width: 32ch; text-align: center; color: var(--steel); font-size: 16px; }
.review-hint { text-align: center; font-size: 13px; }
.objects-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.objects-list button { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 72px; padding: 8px;
                       border-radius: var(--r-control); background: var(--panel); text-align: left; }
.objects-list button:hover { background: var(--panel-2); }
.objects-list img, .objects-list .noimg { width: 56px; height: 56px; object-fit: cover; border-radius: var(--r-control);
                                          background: #000; flex: none; }
.objects-list .stripe { width: 4px; align-self: stretch; border-radius: 2px; flex: none; }
.objects-list .info { display: flex; flex-direction: column; min-width: 0; }
.objects-list .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.objects-list .sub { font-size: 13px; color: var(--steel); }
.objects-empty { color: var(--steel); }
.detail-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.detail-actions button { padding: 0 8px; }
.pictures { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.pictures .pic { position: relative; }
.pictures img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: var(--r-control); background: #000; }
.pictures .pic button { position: absolute; top: 2px; right: 2px; width: 44px; height: 44px; display: grid; place-items: center;
                        border-radius: var(--r-control); background: rgba(10, 13, 16, .7); color: #E8ECEE; }
.pictures .pic button svg { width: 18px; height: 18px; }

/* ==== settings ============================================================ */
dialog { border: 0; padding: 0; color: var(--ink); background: var(--panel); }
dialog::backdrop { background: var(--scrim); }
.settings { width: min(480px, calc(100% - 32px)); max-height: min(720px, calc(100dvh - 32px));
            border-radius: var(--r-sheet); box-shadow: var(--float); }
.settings[open] { display: flex; }
.settings form { display: flex; flex-direction: column; width: 100%; min-height: 0; max-height: inherit; }
.settings-head { display: flex; align-items: center; padding: 8px 8px 0 20px; }
.settings-head h2 { flex: 1; margin: 0; font-size: 19px; }
.settings-head .bar-btn { min-width: 44px; height: 44px; }
.settings-body:focus { outline: none; }
.settings-body { flex: 1; min-height: 0; overflow-y: auto; padding: 0 20px 8px; }
.settings h3 { margin: 20px 0 8px; font-size: 15px; color: var(--steel); }
.settings h3:first-child { margin-top: 8px; }
.settings .field { margin-bottom: 12px; }
.settings-msg { margin: 8px 20px 0; padding: 8px 12px; border-left: 4px solid var(--live); background: var(--panel-2);
                border-radius: 4px; color: var(--ink); font-size: 15px; }
.test-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 52px; padding: 4px 0; cursor: pointer; }
.switch-row > span { display: flex; flex-direction: column; font-size: 16px; }
.switch-row small { margin-top: 2px; color: var(--steel); font-size: 13px; line-height: 1.4; }
/* a real switch: a styled checkbox with role=switch */
input[role="switch"] { appearance: none; position: relative; flex: none; width: 48px; height: 28px; margin: 0;
                       border-radius: 14px; background: var(--steel); cursor: pointer; transition: background .12s; }
input[role="switch"]::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
                              background: #fff; transition: transform .12s; }
input[role="switch"]:checked { background: var(--cat6); }
input[role="switch"]:checked::after { transform: translateX(20px); }
.range-row { display: block; padding: 8px 0; }
.range-row > span { display: flex; align-items: baseline; gap: 6px; font-size: 16px; }
input[type="range"] { width: 100%; height: 44px; margin: 0; accent-color: var(--cat6); }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; border-radius: var(--r-control); background: var(--panel-2); }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; }
.segmented span { display: grid; place-items: center; min-height: 40px; border-radius: 4px; font-weight: 500; cursor: pointer; }
.segmented input:checked + span { background: var(--panel); box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.segmented input:focus-visible + span { outline: 2px solid var(--cat6); }
.prompt-btn { width: 100%; }
.prompt-view { max-height: 35vh; overflow: auto; margin: 8px 0; padding: 8px 12px; border: 1px solid var(--line);
               border-radius: var(--r-control); background: var(--rack); font-size: 13px; line-height: 1.45;
               white-space: pre-wrap; overflow-wrap: anywhere; }
#versions { margin-top: 12px; font-size: 13px; }
.buttons { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px; padding-bottom: calc(12px + env(safe-area-inset-bottom));
           border-top: 1px solid var(--line); }
/* phones: settings is a bottom sheet */
@media (max-width: 720px) {
  .settings { width: 100%; max-width: none; max-height: 92dvh; margin: auto 0 0; border-radius: var(--r-sheet) var(--r-sheet) 0 0; }
  .settings[open] { animation: sheet-up 180ms ease-out; }
  .buttons button { flex: 1; }
}

/* ==== photo viewer ======================================================== */
.lightbox { width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0; overflow: hidden;
            background: rgba(0, 0, 0, 0.94); }
.lightbox[open] { display: grid; place-items: center; }
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; touch-action: none; transform-origin: 0 0; }
.lightbox-close { position: fixed; top: calc(8px + env(safe-area-inset-top)); right: 8px; min-width: 44px; height: 44px;
                  color: #fff; background: rgba(255, 255, 255, 0.14); }

/* ==== toasts ============================================================== */
.toasts { position: fixed; left: 50%; bottom: calc(var(--toast-bottom, 88px) + var(--kb)); z-index: 40;
          transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 8px;
          width: max-content; max-width: calc(100% - 32px); pointer-events: none; }
.toast { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 4px 4px 4px 16px; border-radius: var(--r-sheet);
         background: var(--ink); color: var(--rack); font-size: 15px; font-weight: 500; box-shadow: var(--float);
         pointer-events: auto; animation: toast-in 180ms ease-out; }
.toast:not(:has(button)) { padding-right: 16px; }
.toast.error { border-left: 4px solid var(--live); }
.toast button { min-height: 36px; padding: 0 12px; border-radius: var(--r-control); font-weight: 600; color: var(--rack);
                background: color-mix(in srgb, var(--rack) 16%, transparent); }

/* ==== motion ============================================================== */
@keyframes pop { to { transform: scale(1.8); opacity: 0; } }
@keyframes blink { 50% { opacity: 0.35; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes sheet-up { from { transform: translateY(100%); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0s !important; animation-iteration-count: 1 !important; transition: none !important; }
  .live i, .msg.typing::after, .msg .status-label::after { animation: blink 1.6s infinite !important; }   /* the one idle signal */
}
