/* Common Thread lab chat: "shop counter receipt" direction.
   Paper + ink neutrals, one chili-vermilion accent shared with the shaders, IBM Plex Sans/Mono. */
:root {
  --paper: #f4f4f2;
  --surface: #ffffff;
  --ink: #161514;
  --ink-2: #4a4845;
  --ink-3: #8a8782;
  --rule: #d9d8d4;
  --accent: #d4471f;
  --accent-ink: #ffffff;
  --ok: #2f7d4f;
  --warn: #b26a00;
  --stage: #171614;
  --radius: 3px;
  --sans: "IBM Plex Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #121211;
    --surface: #1b1a19;
    --ink: #ecebe8;
    --ink-2: #b9b7b2;
    --ink-3: #7d7a75;
    --rule: #2e2d2b;
    --accent: #ec6a43;
    --accent-ink: #120a07;
    --ok: #5cbf86;
    --warn: #e0a34a;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #121211; --surface: #1b1a19; --ink: #ecebe8; --ink-2: #b9b7b2; --ink-3: #7d7a75;
  --rule: #2e2d2b; --accent: #ec6a43; --accent-ink: #120a07; --ok: #5cbf86; --warn: #e0a34a; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.5 var(--sans);
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  min-height: 100dvh;
}
button, input, textarea { font: inherit; color: inherit; }
.mono { font-family: var(--mono); }
.dim { color: var(--ink-3); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ── top bar ── */
.bar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px 20px; border-bottom: 1px solid var(--ink);
  background: var(--surface);
}
.brand { display: flex; align-items: baseline; gap: 12px; min-width: 0; }
.wordmark { font-weight: 600; letter-spacing: 0.22em; font-size: 15px; }
.sub { color: var(--ink-3); font-size: 12px; font-family: var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.modules { display: flex; gap: 6px; }
.chip {
  font: 12px/1 var(--mono); padding: 5px 7px; border: 1px solid var(--rule); border-radius: var(--radius);
  background: transparent; cursor: pointer;
}
.chip[aria-pressed="true"] { border-color: var(--ink); background: var(--ink); color: var(--paper); }

/* ── buttons ── */
button { cursor: pointer; }
.primary {
  background: var(--accent); color: var(--accent-ink); border: 1px solid var(--accent);
  padding: 8px 14px; border-radius: var(--radius); font-weight: 500;
}
.primary:hover { filter: brightness(1.06); }
.primary:disabled { opacity: 0.45; cursor: not-allowed; }
.ghost { background: transparent; border: 1px solid var(--rule); border-radius: var(--radius); padding: 6px 10px; }
.ghost:hover { border-color: var(--ink-2); }
.ghost.small { padding: 2px 6px; font-size: 12px; }
.ghost.icon { width: 30px; height: 28px; padding: 0; line-height: 1; }
.ghost[aria-pressed="true"], .ghost[aria-expanded="true"] { border-color: var(--ink); }
.linkish { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.seg { display: inline-flex; border: 1px solid var(--ink); border-radius: var(--radius); overflow: hidden; }
.seg button { background: transparent; border: 0; padding: 5px 10px; font-size: 13px; }
.seg button + button { border-left: 1px solid var(--ink); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── layout ── */
.layout {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, 46%);
  min-height: 0;
}
.layout[data-modality="text"] { grid-template-columns: minmax(0, 1fr); }
.layout[data-modality="text"] .side { display: none; }

.chat { display: grid; grid-template-rows: 1fr auto auto; min-height: 0; border-right: 1px solid var(--rule); }
.log { list-style: none; margin: 0; padding: 20px 20px 8px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; min-height: 0; }

.msg { max-width: min(560px, 92%); }
.msg.you { align-self: flex-end; }
.msg.you .bubble { background: var(--ink); color: var(--paper); border-radius: var(--radius); padding: 8px 12px; }
.msg.bot .bubble { white-space: pre-wrap; }
.msg .meta { font: 11px/1 var(--mono); color: var(--ink-3); margin-top: 6px; }
.msg.bot .bubble::before {
  content: "SANDANG"; display: block; font: 600 10px/1 var(--mono); letter-spacing: 0.18em; color: var(--accent); margin-bottom: 6px;
}
.msg.system .bubble { font: 12px/1.4 var(--mono); color: var(--warn); border-left: 2px solid var(--warn); padding-left: 10px; }
.msg.bot[data-modality="video"] .bubble .full { display: none; }

/* receipts */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; margin-top: 10px; }
.card {
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius);
  padding: 10px 12px 12px; font-size: 13px; position: relative;
}
.card.wide { grid-column: 1 / -1; }
.card h3 { font-size: 14px; font-weight: 600; margin: 0; }
.card .price { font-family: var(--mono); font-size: 13px; color: var(--ink); margin-top: 2px; }
.card .lines { margin: 8px 0 0; padding: 8px 0 0; border-top: 1px dashed var(--rule); list-style: none; color: var(--ink-2); }
.card .tags { display: flex; gap: 6px; margin-top: 8px; font: 11px/1 var(--mono); color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.06em; }
.card button.pick { position: absolute; inset: 0; background: transparent; border: 0; border-radius: var(--radius); }
.card:has(button.pick:hover) { border-color: var(--ink-2); }
.card table { border-collapse: collapse; font: 12px/1.6 var(--mono); margin-top: 8px; width: 100%; }
.card th { text-align: left; color: var(--ink-3); font-weight: 400; border-bottom: 1px dashed var(--rule); }
.card td, .card th { padding: 2px 8px 2px 0; }
.timeline { list-style: none; margin: 10px 0 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 14px 1fr auto; gap: 8px; align-items: baseline; padding: 2px 0; color: var(--ink-3); }
.timeline li.done { color: var(--ink); }
.timeline li::before { content: ""; width: 8px; height: 8px; border: 1.5px solid currentColor; border-radius: 50%; }
.timeline li.done::before { background: var(--accent); border-color: var(--accent); }
.timeline .date { font: 11px var(--mono); color: var(--ink-3); }

.quick { display: flex; gap: 8px; flex-wrap: wrap; padding: 6px 20px 10px; }
.quick button {
  background: var(--surface); border: 1px solid var(--ink); border-radius: var(--radius);
  padding: 5px 10px; font-size: 13px;
}
.quick button:hover { background: var(--ink); color: var(--paper); }

.composer { display: flex; gap: 8px; padding: 12px 20px 16px; border-top: 1px solid var(--rule); background: var(--surface); }
.composer input { flex: 1; min-width: 0; border: 1px solid var(--ink); border-radius: var(--radius); padding: 9px 12px; background: var(--paper); }

/* ── stage ── */
.side { display: flex; flex-direction: column; gap: 0; min-height: 0; overflow-y: auto; }
.stage-wrap { position: relative; background: var(--stage); aspect-ratio: 16 / 10; }
#stage { width: 100%; height: 100%; display: block; }
.stage-empty {
  position: absolute; inset: 0; display: grid; place-content: center; text-align: center; gap: 4px;
  color: #b9b7b2; font-size: 14px; padding: 16px;
}
.stage-empty p { margin: 0; }
.stage-empty .hint { font-size: 13px; color: #8a8782; }
.stage-empty .linkish { color: #ec6a43; }
.caption-row { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; padding: 12px 16px 8px; }
.caption { margin: 0; font-size: 14px; min-height: 2.6em; }
.stage-controls { display: flex; gap: 4px; align-items: center; flex-shrink: 0; }
.stage-controls .mono { font-size: 12px; margin-left: 6px; min-width: 3.5em; }
.meter { height: 2px; background: var(--rule); margin: 0 16px; }
#progress { height: 100%; width: 0; background: var(--accent); }

.editor { margin: 16px; border: 1px solid var(--ink); border-radius: var(--radius); background: var(--surface); }
.editor header { display: flex; justify-content: space-between; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--rule); font-size: 13px; }
.editor textarea {
  width: 100%; min-height: 200px; border: 0; resize: vertical; padding: 12px; background: var(--paper);
  font: 13px/1.55 var(--mono); tab-size: 2;
}
.editor-actions { display: flex; gap: 12px; align-items: center; padding: 8px 12px; border-top: 1px solid var(--rule); }
.tests { list-style: none; margin: 0; padding: 0 12px 12px; font: 12px/1.6 var(--mono); }
.tests .pass { color: var(--ok); }
.tests .fail { color: var(--accent); }

/* ── debug ── */
.debug { border-top: 1px solid var(--ink); background: var(--surface); max-height: 38vh; overflow: auto; }
.debug-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.debug section { padding: 10px 16px; border-right: 1px solid var(--rule); min-width: 0; }
.debug h2 { font: 600 11px/1 var(--mono); letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-3); margin: 0 0 8px; }
.debug pre { margin: 0; font: 12px/1.5 var(--mono); white-space: pre-wrap; word-break: break-word; }
.debug table { border-collapse: collapse; font: 12px/1.5 var(--mono); width: 100%; }
.debug td, .debug th { padding: 1px 8px 1px 0; text-align: left; }
.debug th { color: var(--ink-3); font-weight: 400; }
.debug tr.chosen td { color: var(--accent); }
.bar-cell { width: 80px; }
.pbar { height: 6px; background: var(--accent); }

/* ── controls ── */
.controls {
  display: flex; gap: 16px; align-items: center; flex-wrap: wrap;
  padding: 10px 20px; border-top: 1px solid var(--ink); background: var(--surface);
}
.temp { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.temp input[type="range"] { width: 140px; accent-color: var(--accent); }
.temp output { width: 3em; font-size: 12px; }
.temp.auto input, .temp.auto output { opacity: 0.4; }

@media (max-width: 820px) {
  body { font-size: 14px; }
  .bar { padding: 10px 16px; flex-wrap: wrap; }
  .sub { display: none; }
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .side { order: -1; max-height: 46dvh; border-bottom: 1px solid var(--rule); }
  .layout:not(.has-visual) .side { display: none; }
  .chat { border-right: 0; }
  .log, .quick, .composer { padding-left: 16px; padding-right: 16px; }
  .controls { padding: 8px 16px; gap: 10px; }
  .debug-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
[hidden] { display: none !important; }
