/* styles.css — one shell, seventeen contracts.
 *
 * Dark by default (theme.js sets data-theme before first paint so the page never
 * flashes), light on request. The palette is deliberately narrow: the output is
 * dense structured text, and colour is reserved for the three things a reader
 * must not miss - a contract met, a contract broken, and something that costs
 * money.
 */

:root {
  --bg: #0e1116;
  --panel: #151a21;
  --panel-2: #1b212a;
  --line: #262e39;
  --text: #e6ebf2;
  --muted: #97a3b4;
  --accent: #6aa9ff;
  --accent-dim: #21344f;
  --ok: #58c98a;
  --ok-dim: #17301f;
  --warn: #e5b45c;
  --warn-dim: #322611;
  --bad: #f0736a;
  --bad-dim: #38191a;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

:root[data-theme="light"] {
  --bg: #f7f9fc;
  --panel: #ffffff;
  --panel-2: #f0f3f8;
  --line: #dde3ec;
  --text: #131820;
  --muted: #5a6779;
  --accent: #1f66d0;
  --accent-dim: #dfeaff;
  --ok: #1c7a4a;
  --ok-dim: #e2f5eb;
  --warn: #8a6410;
  --warn-dim: #fbf1dc;
  --bad: #b6342a;
  --bad-dim: #fbe6e4;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }

a { color: var(--accent); }
a:hover { text-decoration: underline; }

/* ------------------------------------------------------------------ chrome */

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand .sep { color: var(--muted); }
.brand .back { font-size: 13px; }
.topbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.credits { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; }

main { max-width: 1060px; margin: 0 auto; padding: 20px 16px 60px; }

.hero {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}
.hero h1 { margin: 0 0 10px; font-size: 26px; line-height: 1.2; }
.hero p { margin: 0 0 10px; max-width: 70ch; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 18px;
}
.panel h2 { margin: 0 0 6px; font-size: 17px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.hint { margin: 0 0 12px; color: var(--muted); font-size: 13px; max-width: 78ch; }

/* ----------------------------------------------------------------- inputs */

/* The intake form is rebuilt from the registry on every task change, so it is
 * laid out by the fields it happens to contain rather than by a fixed grid. */
.form { display: block; margin: 0; }
.form:empty { display: none; }

.field { display: block; margin: 0 0 14px; }
.field.inline { display: inline-flex; align-items: center; gap: 8px; margin: 0; }
.field .label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field.inline .label { margin: 0; white-space: nowrap; }
.field .help { display: block; font-size: 12px; color: var(--muted); margin-top: 4px; max-width: 78ch; }

input[type="text"], input[type="number"], textarea, select {
  width: 100%;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  font: inherit;
}
textarea { resize: vertical; min-height: 72px; font-family: var(--mono); font-size: 13px; }
.field.inline select { width: auto; min-width: 200px; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* A required field that is still empty is marked ON the field. The sentence
 * beside the run button is easy to miss when everything above it is filled in. */
.field.invalid > .label { color: var(--warn); font-weight: 600; }
.field.invalid input,
.field.invalid textarea,
.field.invalid select { border-color: var(--warn); }
.field.invalid input:focus,
.field.invalid textarea:focus { outline-color: var(--warn); }

.meter.blocked { color: var(--warn); }

button {
  font: inherit;
  border-radius: 8px;
  border: 1px solid var(--line);
  padding: 8px 13px;
  cursor: pointer;
  background: var(--panel-2);
  color: var(--text);
}
button:hover { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: not-allowed; border-color: var(--line); }
button.primary { background: var(--accent); border-color: var(--accent); color: #08111d; font-weight: 600; }
:root[data-theme="light"] button.primary { color: #fff; }
button.ghost { background: transparent; }
button.mini { padding: 3px 9px; font-size: 12px; }
button.mini.accent { border-color: var(--accent); color: var(--accent); }

.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 10px; }
.runbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 14px 0 6px; }
.meter { color: var(--muted); font-size: 13px; flex: 1 1 260px; min-width: 0; }

/* --------------------------------------------------------------- routing */

.suggest { margin: 10px 0; }
.suggest-list { display: flex; flex-direction: column; gap: 6px; }
.suggest-btn {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  text-align: left; width: 100%; padding: 9px 11px;
}
.suggest-btn .why { font-size: 12px; color: var(--muted); }
.suggest-btn.demoted { border-style: dashed; opacity: .8; }

/* ------------------------------------------------------ pick-mode toggle
 *
 * Two routes to one decision, so exactly one panel is mounted at a time. The
 * toggle reads as a segmented control rather than as two buttons, because the
 * choice is "which way in", not "which action".
 */
.pickmode {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  margin: 0 0 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
}
.mode-btn {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  padding: 6px 14px;
  border-radius: 7px;
}
.mode-btn:hover { color: var(--text); border-color: var(--line); }
.mode-btn.on {
  background: var(--panel);
  border-color: var(--accent);
  color: var(--text);
  font-weight: 600;
}

@media (max-width: 560px) {
  .pickmode { display: flex; width: 100%; }
  .mode-btn { flex: 1; padding: 6px 8px; }
}

/* -------------------------------------------------------------- switcher */

.switcher { display: flex; flex-direction: column; gap: 12px; }
.group-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-bottom: 5px; }
.group-name { font-weight: 600; font-size: 13px; }
.group-blurb { font-size: 12px; color: var(--muted); }
.group-lanes { display: flex; gap: 8px; flex-wrap: wrap; }
.lane-btn { font-size: 13px; }
.lane-btn.on { background: var(--accent-dim); border-color: var(--accent); color: var(--text); font-weight: 600; }

.lane-about { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.lane-about .makes { margin: 0 0 6px; }
.lane-about p { margin: 0 0 5px; font-size: 13px; }

.stagebar { display: flex; gap: 8px; flex-wrap: wrap; margin: 4px 0 12px; }
.stage-btn { font-size: 13px; }
.stage-btn.on { background: var(--accent-dim); border-color: var(--accent); font-weight: 600; }

.gate {
  margin: 0 0 14px; padding: 9px 12px;
  border-left: 3px solid var(--warn);
  background: var(--warn-dim);
  border-radius: 0 8px 8px 0;
  font-size: 13px;
}

/* ------------------------------------------------- steps this stage follows */

.steps-panel {
  margin: 0 0 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
}
.steps-panel > summary {
  cursor: pointer;
  padding: 9px 12px;
  font-size: 13px;
  font-weight: 600;
  list-style: none;
  border-radius: var(--radius);
}
.steps-panel > summary::-webkit-details-marker { display: none; }
.steps-panel > summary::before {
  content: "\25B8";
  display: inline-block;
  width: 1em;
  margin-right: 2px;
  font-size: 12px;
  line-height: 1;
  text-align: center;
  color: var(--muted);
  transform-origin: 50% 50%;
  transition: transform 120ms ease;
}
.steps-panel[open] > summary::before { transform: rotate(90deg); }
.steps-panel > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

#steps-body { padding: 2px 12px 10px; }

.steplist { margin: 0; padding: 0; list-style: none; }
.step-row {
  padding: 8px 0 9px;
  border-top: 1px solid var(--line);
}
.step-row:first-child { border-top: none; }
.step-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.step-n {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 5px;
  white-space: nowrap;
  flex: none;
}
.step-t { font-size: 13px; font-weight: 600; }
.step-d { margin: 3px 0 0; font-size: 13px; color: var(--muted); max-width: 78ch; }
.step-src { margin: 4px 0 0; font-size: 12px; color: var(--muted); }
.step-src-app { font-style: italic; }
.step-ref { font-family: var(--mono); font-size: 11.5px; }
.step-foot {
  margin: 10px 0 0;
  padding-top: 9px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
  max-width: 78ch;
}

/* ----------------------------------------------------------------- notes */

.note { margin: 10px 0; padding: 9px 12px; border-radius: 8px; font-size: 13px; border: 1px solid transparent; }
.note-ok { background: var(--ok-dim); border-color: var(--ok); }
.note-warn { background: var(--warn-dim); border-color: var(--warn); }
.note-bad { background: var(--bad-dim); border-color: var(--bad); }
.note-info { background: var(--panel-2); border-color: var(--line); color: var(--muted); }

.badge {
  font-size: 11px; font-weight: 500; color: var(--muted);
  border: 1px solid var(--line); border-radius: 20px; padding: 1px 8px; margin-left: 6px;
  vertical-align: middle;
}

/* -------------------------------------------------------------- progress */

.progress { margin: 14px 0; padding: 12px; background: var(--panel-2); border-radius: 8px; border: 1px solid var(--line); }
.progress-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 8px; }
.progress-meta { display: flex; gap: 12px; align-items: baseline; font-variant-numeric: tabular-nums; font-size: 12.5px; }
/* The output budget is what predicts a truncated package, so it changes colour
 * as it approaches the selected model's cap rather than only reading out. */
#progress-tokens.near-cap { color: var(--warn); font-weight: 600; }
.steps { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.steps .step {
  font-size: 12px; padding: 3px 9px; border-radius: 20px;
  border: 1px solid var(--line); color: var(--muted);
}
.steps .step.done { border-color: var(--ok); color: var(--ok); }
.steps .step.now { border-color: var(--accent); color: var(--accent); font-weight: 600; }

/* ---------------------------------------------------------------- output */

.result-head { margin: 16px 0 8px; }
.result-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.out-section {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin: 12px 0;
  background: var(--panel-2);
}
.out-section.out-extra { border-style: dashed; }
.out-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.out-head h3 { margin: 0; font-size: 15px; }
.out-section h4 { margin: 12px 0 4px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.out-section p { margin: 0 0 9px; max-width: 82ch; }
.out-section ul, .out-section ol { margin: 0 0 10px; padding-left: 22px; }
.out-section li { margin-bottom: 3px; }
.out-section li.checked::marker { content: "\2713  "; color: var(--ok); }
.out-section li.unchecked::marker { content: "\25CB  "; color: var(--muted); }

.fence { margin: 10px 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.fence-bar {
  display: flex; align-items: center; justify-content: flex-end; gap: 6px;
  padding: 5px 8px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.fence-tag { margin-right: auto; font-size: 11px; color: var(--muted); font-family: var(--mono); }
pre.block { margin: 0; padding: 12px; overflow-x: auto; background: var(--bg); }
pre.block code { font-family: var(--mono); font-size: 12.5px; white-space: pre-wrap; word-break: break-word; }

.table-wrap { overflow-x: auto; margin: 10px 0; border: 1px solid var(--line); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; min-width: 520px; font-size: 12.5px; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--panel); font-weight: 600; white-space: nowrap; }
th.col-extra { color: var(--bad); }
tbody tr:last-child td { border-bottom: none; }

.findings { list-style: none; padding: 0; margin: 8px 0; }
.findings li { font-size: 12.5px; padding: 3px 0; border-bottom: 1px solid var(--line); }
.findings li:last-child { border-bottom: none; }
.findings strong { text-transform: uppercase; font-size: 10.5px; margin-right: 6px; }
.findings .sev-error strong { color: var(--bad); }
.findings .sev-warn strong { color: var(--warn); }
.findings .sev-info strong { color: var(--muted); }

.para-map { font-size: 12.5px; color: var(--muted); }
.para-map li.extra { color: var(--bad); }

.lint { margin: 12px 0; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel-2); }
.lint h3 { margin: 0 0 6px; font-size: 14px; }

.render { margin: 16px 0; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel-2); }
.render h3 { margin: 0 0 8px; font-size: 15px; }
img.preview { max-width: 100%; height: auto; border-radius: 8px; border: 1px solid var(--line); display: block; margin-top: 10px; }

/* ------------------------------------------------------- the history popup
 *
 * Anchored under the header on a wide screen, full-width sheet on a narrow one.
 * The backdrop is what makes it dismissible without a close button being the
 * only way out.
 */
.backdrop {
  position: fixed; inset: 0; z-index: 30;
  background: rgba(0, 0, 0, .45);
}
:root[data-theme="light"] .backdrop { background: rgba(20, 26, 35, .28); }

.popover {
  position: fixed;
  top: 58px; right: 14px;
  z-index: 31;
  width: min(460px, calc(100vw - 28px));
  max-height: min(70vh, 640px);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 16px 44px rgba(0, 0, 0, .35);
  overflow: hidden;
}
.popover-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.popover-head h2 { margin: 0; font-size: 15px; }
.popover-body { padding: 12px 14px; overflow-y: auto; flex: 1; }
.popover-body .field { margin-bottom: 10px; }
.popover-foot {
  display: flex; gap: 8px; flex-wrap: wrap;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  background: var(--panel-2);
}

@media (max-width: 560px) {
  .popover {
    top: auto; bottom: 0; right: 0; left: 0;
    width: 100%;
    max-height: 80vh;
    border-radius: var(--radius) var(--radius) 0 0;
  }
}

/* --------------------------------------------------------------- history */

.history { list-style: none; margin: 10px 0 0; padding: 0; }
.history-item { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--line); padding: 6px 0; }
.history-open {
  flex: 1; display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  text-align: left; background: transparent; border: none; padding: 4px 2px;
}
.history-open:hover { color: var(--accent); }
.history-meta { font-size: 12px; color: var(--muted); }

/* ---------------------------------------------------------------- footer */

.foot { border-top: 1px solid var(--line); padding: 18px 16px 40px; }
.foot p { max-width: 1060px; margin: 0 auto 8px; font-size: 12.5px; color: var(--muted); }
.foot a { color: var(--muted); }
.foot a:hover { color: var(--accent); }

/* ---------------------------------------------------------------- toasts */

.toasts { position: fixed; right: 14px; bottom: 14px; display: flex; flex-direction: column; gap: 8px; z-index: 40; max-width: min(420px, 92vw); }
.toast { padding: 9px 13px; border-radius: 8px; font-size: 13px; border: 1px solid var(--line); background: var(--panel); box-shadow: 0 6px 20px rgba(0,0,0,.28); }
.toast-ok { border-color: var(--ok); }
.toast-err { border-color: var(--bad); }

/* ------------------------------------------------------- docs pages
 *
 * api.html and tokens.html obey the same CSP as the app, so their theme
 * bootstrap and tab switcher are external files and they share this stylesheet
 * rather than carrying an inline <style> block.
 */

.doc { max-width: 900px; margin: 0 auto; padding: 24px 16px 64px; }
.doc h1 { font-size: 27px; margin: 0 0 14px; }
.doc h2 { font-size: 19px; margin: 34px 0 10px; padding-top: 14px; border-top: 1px solid var(--line); }
.doc h3 { font-size: 15px; margin: 0 0 6px; }
.doc p { max-width: 78ch; margin: 0 0 12px; }
.doc code { font-family: var(--mono); font-size: 12.5px; background: var(--panel-2); padding: 1px 5px; border-radius: 4px; }
.doc pre code { background: none; padding: 0; }
.doc table { margin: 12px 0; display: block; overflow-x: auto; }

a.link { font-size: 13px; }
a.back, a.backlink { font-size: 13px; }
.topactions { display: flex; align-items: center; gap: 10px; }
.topup { font-size: 13px; }

.step { margin: 20px 0 26px; }

.codegroup { margin: 10px 0 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.tabs { display: flex; flex-wrap: wrap; gap: 2px; padding: 5px 6px; background: var(--panel); border-bottom: 1px solid var(--line); }
.tab {
  font-size: 12px; padding: 3px 10px; border-radius: 6px;
  border: 1px solid transparent; background: transparent; color: var(--muted);
}
.tab:hover { color: var(--text); border-color: var(--line); }
.tab.active { background: var(--accent-dim); border-color: var(--accent); color: var(--text); font-weight: 600; }
.codegroup pre { margin: 0; padding: 12px; overflow-x: auto; background: var(--bg); }
.codegroup pre code { font-family: var(--mono); font-size: 12.5px; white-space: pre; }

.contract {
  border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 14px; margin: 8px 0; background: var(--panel);
}
.contract summary { cursor: pointer; font-size: 13.5px; }
.contract summary:hover { color: var(--accent); }
.contract pre.block { border: 1px solid var(--line); border-radius: 6px; margin: 6px 0 10px; }
.sections { margin: 4px 0 4px 4px; padding-left: 20px; font-size: 12.5px; }
.sections li { margin-bottom: 2px; }

/* tokens.html */
.statebox { border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; margin: 14px 0; background: var(--panel); }
.statebox strong { display: block; margin-bottom: 4px; font-size: 13px; }
.statebox p { margin: 0 0 4px; }
.tokenrow { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 8px 0; }
.tokenbox {
  flex: 1 1 320px; min-width: 0;
  font-family: var(--mono); font-size: 12.5px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 9px 11px; word-break: break-all;
}
.mono { font-family: var(--mono); }
.small { font-size: 12px; }

/* ------------------------------------------------------------ small screens */

@media (max-width: 640px) {
  main { padding: 14px 10px 48px; }
  .panel { padding: 14px; }
  .hero h1 { font-size: 21px; }
  .field.inline { display: block; width: 100%; }
  .field.inline select { width: 100%; }
  .runbar, .row { gap: 8px; }
  .meter { flex-basis: 100%; }
}
