/* Operator console — phone first. Tokens mirror the app/marketing set. */
:root {
  --bg: #0b1220;
  --bg-elevated: #131c2e;
  --text: #e8eef8;
  --muted: #8fa3bf;
  --border: #24314a;
  --accent: #5b9fd4;
  --good: #4ec98a;
  --warn: #e0a336;
  --bad: #e4695f;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}

.muted { color: var(--muted); }
.error { color: var(--bad); font-size: 13px; }

/* ---------- top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) 16px 12px;
  /* Tinted surface, no separator line — the tint IS the boundary. */
  background: color-mix(in srgb, var(--bg-elevated) 88%, transparent);
  backdrop-filter: blur(8px);
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand h1 { margin: 0; font-size: 18px; font-weight: 600; letter-spacing: -0.01em; }
.brand p { margin: 1px 0 0; font-size: 11px; }

.dot {
  width: 8px; height: 8px; border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 20%, transparent);
  flex: none;
}

.icon-btn {
  flex: none;
  width: 40px; height: 40px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

/* ---------- form controls (dark, consistent) ---------- */

input, select, textarea {
  background: color-mix(in srgb, var(--bg) 70%, var(--bg-elevated));
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 9px;
  padding: 9px 11px;
  font: inherit;
  font-size: 13px;
  min-width: 0;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent);
}
input::placeholder, textarea::placeholder { color: color-mix(in srgb, var(--muted) 70%, transparent); }
/* Number spinners are desktop furniture — the console is a phone app. */
input[type="number"] { appearance: textfield; -moz-appearance: textfield; width: 90px; text-align: right; }
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type="search"] { width: 100%; }
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn:active { color: var(--text); }
.icon-btn[data-busy="1"] svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- layout ---------- */

main { padding: 14px 16px 32px; max-width: 780px; margin: 0 auto; }
.center { text-align: center; padding: 48px 0; }

.btn {
  border: 1px solid var(--border);
  background: var(--accent);
  color: #0b1220;
  font-weight: 600;
  font-size: 15px;
  border-radius: 12px;
  padding: 12px 20px;
  cursor: pointer;
  margin-top: 12px;
}

/* ---------- stats ---------- */

.stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
@media (min-width: 640px) { .stats { grid-template-columns: repeat(4, 1fr); } }

.stat {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
}
.stat .label { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.stat .value { font-size: 26px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: 11px; color: var(--muted); }
.stat .sub.alert { color: var(--accent); }

/* ---------- tab bar ----------
   A normal navigator, not capsules: full-width strip, underlined active
   tab, horizontal scroll when the phone runs out of width. */

.chips {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  padding: 10px 0 0;
  margin-top: 4px;
  border-bottom: 1px solid var(--border);
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: none;
  border: none;
  background: transparent;
  color: var(--muted);
  border-radius: 0;
  padding: 10px 13px 11px;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
}
.chip[aria-selected="true"] {
  color: var(--text);
  font-weight: 600;
  border-bottom-color: var(--accent);
}

/* ---------- drawer navigation ---------- */

#drawer-scrim {
  position: fixed;
  inset: 0;
  background: rgba(4, 8, 16, 0.62);
  z-index: 90;
}
#drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: min(78vw, 300px);
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  z-index: 91;
  padding: max(14px, env(safe-area-inset-top)) 0 14px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.drawer-item {
  padding: 13px 18px;
  cursor: pointer;
  border-left: 3px solid transparent;
}
.drawer-item:active { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.drawer-item.active {
  background: color-mix(in srgb, var(--accent) 13%, transparent);
  border-left-color: var(--accent);
}
.drawer-item .title { font-size: 14.5px; font-weight: 600; }
.drawer-item .desc { font-size: 11.5px; margin-top: 2px; }

/* hidden must win over .chips { display:flex } — this was the stray
   border line under the header. */
.chips[hidden] { display: none; }

/* The model actually set, as a plain note on the tappable row. */
.modelnow {
  font-family: ui-monospace, monospace;
  font-size: 12.5px;
  margin-top: 5px;
  word-break: break-all;
}

/* Prompt rows are tappable cards. */
li.promptrow { cursor: pointer; }
li.promptrow:active { background: color-mix(in srgb, var(--accent) 10%, transparent); }
li.promptrow .navgo { align-self: center; color: var(--muted); font-size: 20px; padding: 0 4px; }

/* ---------- full-screen sheet (prompt editor) ---------- */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(4, 8, 16, 0.8);
  display: flex;
  align-items: flex-start;
  padding: max(10px, env(safe-area-inset-top)) 10px 10px;
}
.sheetpanel {
  /* Size to content; cap at the viewport. Short prompts get a compact
     card, long ones scroll INSIDE the body (never the page behind). */
  flex: 0 1 auto;
  width: 100%;
  max-height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.sheethead {
  border-bottom: 1px solid var(--border);
  padding: 10px 12px 8px;
}
.sheethead .headrow {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}
.sheethead .title { font-size: 14px; font-weight: 600; }
.sheethead .desc { font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheetmodes { display: flex; gap: 6px; margin-top: 8px; }
.sheetmodes .btn.on { outline: 2px solid var(--accent); }
.sheetbody {
  flex: 0 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 12px;
  gap: 10px;
}
.prompttext {
  margin: 0;
  font-family: ui-monospace, monospace;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}
.promptedit {
  flex: 1;
  min-height: 45vh;
  width: 100%;
  font-family: ui-monospace, monospace;
  font-size: 12px;
  line-height: 1.5;
  resize: none;
}
.sheetfoot { display: flex; gap: 8px; }
.sheetrow { display: flex; gap: 8px; flex-wrap: wrap; }
.histrow {
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.histrow .title { font-size: 13px; font-weight: 600; }
.histrow .desc { font-size: 12px; margin-top: 2px; }
.histmeta { font-size: 12px; }
/* Per-project stage controls */
.stagerow { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.btn.mini { padding: 6px 10px; font-size: 12px; }
.btn.mini:disabled { opacity: 0.45; pointer-events: none; }
.cacheflag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--muted);
  user-select: none;
}
.cacheflag input { accent-color: var(--accent); }
.btn.mini.danger { background: transparent; border: 1px solid var(--border); color: #e08585; }
.runnow {
  margin-top: 8px;
  font-size: 12px;
  color: var(--accent);
  line-height: 1.4;
}

/* A claimed slot that produced nothing. Warm rather than accent-coloured:
   .runnow means "working", and this means the opposite — somebody paid and
   is waiting on us. It should not read as progress at a glance. */
.stalled {
  margin-top: 8px;
  font-size: 12px;
  line-height: 1.4;
  color: #e0b070;
  border-left: 2px solid #e0b070;
  padding-left: 8px;
}

.dctx, .dold, .dnew { display: block; }
.dold { color: #e08585; background: color-mix(in srgb, #a33 16%, transparent); }
.dnew { color: #8fd49b; background: color-mix(in srgb, #2a7 14%, transparent); }

/* ---------- sections ---------- */

section.group { margin-top: 18px; }
section.group > h2 {
  margin: 0 0 6px;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}
section.group > h2 .count { font-weight: 400; color: var(--muted); font-size: 12px; }

ul.list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
}
ul.list li {
  padding: 11px 13px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
}
ul.list li + li { border-top: 1px solid color-mix(in srgb, var(--border) 70%, transparent); }
ul.list .main { min-width: 0; flex: 1; }
ul.list .title { font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
ul.list .title a { color: inherit; }
ul.list .desc { font-size: 12px; color: var(--muted); margin-top: 2px; }
/* Support messages are the one thing here you have to read in full — a
   truncated one is useless, since the detail you need is usually at the
   end. Clamped by default so the list stays scannable, opened by tapping
   the message; whitespace is preserved because people paste logs. */
ul.list .msg {
  font-size: 12.5px; color: var(--muted); margin-top: 3px;
  white-space: pre-wrap; overflow-wrap: anywhere; cursor: pointer;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
ul.list .msg.open {
  display: block; -webkit-line-clamp: none;
}
ul.list .msg-more {
  display: inline-block; margin-top: 3px; font-size: 11px;
  color: var(--accent); cursor: pointer; user-select: none;
}
ul.list .when {
  font-size: 11px; color: var(--muted); flex: none;
  display: flex; flex-direction: column; align-items: flex-end; gap: 6px;
}
/* Soft secondary action — enough to find on a phone, quiet enough not to
   compete with the message body. */
ul.list .dismiss {
  appearance: none; border: 1px solid var(--border);
  background: var(--bg-elevated); color: var(--muted);
  border-radius: 6px; padding: 3px 8px; font-size: 11px;
  cursor: pointer; line-height: 1.2;
}
ul.list .dismiss:hover { color: var(--text); border-color: var(--accent); }
ul.list .dismiss:disabled { opacity: 0.5; cursor: wait; }
.empty { border: 1px solid var(--border); border-radius: 14px; padding: 16px; font-size: 12.5px; color: var(--muted); }
.tag {
  display: inline-block; margin-top: 5px;
  background: var(--bg-elevated); color: var(--muted);
  border-radius: 5px; padding: 2px 6px; font-size: 10.5px;
}
/* Topic sits inline in the title row, so it must not carry the block
   margin the status tags use below the text. */
.tag.topic { margin-top: 0; color: var(--accent); vertical-align: middle; }
/* The reads line sets several tags side by side, and .tag only carries a
   top margin — enough when a row holds one. Give this line its own
   horizontal rhythm rather than adding side margins to every tag in the
   console, which would reflow the ones that sit alone. */
.desc.reads { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.desc.reads .tag { margin-top: 0; }
.tag.good { color: var(--good); }
.tag.warn { color: var(--warn); }
.tag.bad { color: var(--bad); }

/* ---------- config tab ---------- */

.confighint { font-size: 12px; margin: 14px 2px 0; }
/* Sticky so the filter stays reachable while scrolling a long registry —
   the reason it exists is that the list outgrew one screen. */
.configsearch { position: sticky; top: 0; z-index: 5; padding: 10px 0 6px;
  background: var(--bg); }
.configsearch input { width: 100%; box-sizing: border-box; }
ul.list li.setting { align-items: center; }
ul.list li.setting .title { white-space: normal; }
ul.list li.setting .meta {
  font-size: 10.5px; color: var(--muted); margin-top: 3px;
  font-variant-numeric: tabular-nums;
}
ul.list li.setting input {
  width: 92px; flex: none;
  background: var(--bg-elevated); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; font-size: 14px; text-align: right;
  font-variant-numeric: tabular-nums;
}
ul.list li.setting input:focus { outline: none; border-color: var(--accent); }
ul.list li.setting input::placeholder { color: var(--muted); opacity: 0.6; }
ul.list li.setting.overridden input { border-color: var(--accent); }
ul.list li.setting .reset { color: var(--accent); cursor: pointer; user-select: none; }

.savebar {
  position: sticky; bottom: 12px; margin-top: 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: 14px; padding: 10px 14px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}
.savebar .btn.save { margin-top: 0; padding: 8px 18px; font-size: 14px; }
.savebar .btn.save:disabled { opacity: 0.6; cursor: wait; }

/* ---- project detail: the runs of one project ------------------------- */

/* The way back. A detail view reached by link needs one, because the
   drawer only knows about pages. */
.crumb {
  margin: 0 0 10px;
  font-size: 12px;
}
.crumb a { color: var(--accent); text-decoration: none; }

.detail-title {
  margin: 0 0 2px;
  font-size: 17px;
  font-weight: 600;
}

/* What a run wrote. Indented under the run it belongs to, and allowed to
   scroll sideways rather than wrap: these are paths, and a wrapped path is
   harder to read than a scrolled one. */
ul.files {
  list-style: none;
  margin: 6px 0 0;
  padding: 0 0 0 2px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-height: 240px;
  overflow: auto;
}
ul.files li {
  font-size: 11.5px;
  white-space: nowrap;
}
ul.files a {
  color: var(--accent);
  text-decoration: none;
  font-family: ui-monospace, monospace;
}
ul.files a:hover { text-decoration: underline; }
