/* Forge — dark, mobile-first. Served under style-src 'self': everything visual lives here; the HTML
   carries no style attributes and the JS only sets individual CSSOM properties (widths, positions).
   Money is shown in the neutral text colour on purpose: no green for money (Caliper's convention),
   and lane progress counts toward the READ, not toward "profit". */

:root {
  color-scheme: dark;
  --bg: #0b0e17;
  --bg-2: #0f1320;
  --panel: #141a2a;
  --panel-2: #1b2236;
  --line: #273049;
  --line-2: #38435f;
  --text: #ece7da;
  --muted: #a4aac1;
  --faint: #767d9a;
  --ember: #f0a04b;        /* brand + primary action; never used to colour money */
  --ember-ink: #1c1106;
  --neutral-fill: #8b9dc3; /* progress + money bars */
  --warn: #e8a33a;
  --bad: #e2573f;
  --bad-bg: #2a1614;
  --focus: #ffd08a;
  --src-agent: #8fb0ff;
  --src-owner: #d7adff;
  --src-system: #a4aac1;
  --radius: 12px;
  --tap: 44px;
  --gutter: 16px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 8px; }
h1 { font-size: 24px; }
h2 { font-size: 19px; }
h3 { font-size: 16px; }
h4 { font-size: 14px; margin-top: 16px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
p { margin: 0 0 8px; }
a { color: var(--ember); }
code { font-family: var(--mono); font-size: 12.5px; }

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%);
  white-space: nowrap; border: 0;
}
.muted { color: var(--muted); }
.small { font-size: 13px; }
.strong { font-weight: 700; }
.pre { white-space: pre-wrap; }
.noscript { padding: var(--gutter); }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- controls ---------- */
button, .btn {
  font: inherit;
  font-size: 15px;
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid var(--line-2);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
  touch-action: manipulation;
}
button:hover:not(:disabled):not([aria-disabled="true"]), .btn:hover { border-color: var(--faint); }
button:disabled { opacity: .55; cursor: not-allowed; }
/* In-flight decision buttons are aria-disabled (not disabled) so keyboard focus stays on them. */
button[aria-disabled="true"] { opacity: .55; cursor: progress; }
.btn-primary { background: var(--ember); color: var(--ember-ink); border-color: transparent; font-weight: 650; }
.btn-primary:hover:not(:disabled):not([aria-disabled="true"]) { border-color: transparent; filter: brightness(1.06); }
.btn-danger { background: var(--bad-bg); color: #ffb9ab; border-color: #6b2e27; }
.btn-quiet { background: transparent; border-color: transparent; color: var(--muted); padding: 0 10px; }
.btn-quiet:hover:not(:disabled):not([aria-disabled="true"]) { color: var(--text); border-color: var(--line-2); }
.btn-small { font-size: 14px; margin-top: 8px; }
.btn-block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-row > button { flex: 1 1 auto; }
.row { display: flex; flex-wrap: wrap; gap: 8px; }

input, textarea {
  font: inherit;
  font-size: 16px; /* 16px stops iOS zooming the page on focus */
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line-2);
  background: var(--bg-2);
  color: var(--text);
}
textarea { min-height: 88px; resize: vertical; line-height: 1.4; }
label { display: block; font-weight: 600; margin: 12px 0 6px; }
.form-msg { color: #ffb9ab; min-height: 1.5em; margin: 10px 0; }
.form-msg:empty { min-height: 0; margin: 0; }
.form-msg.ok { color: var(--text); }

/* ---------- boot + login ---------- */
.boot {
  min-height: 100vh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; padding: var(--gutter); text-align: center; color: var(--muted);
}
.login {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: var(--gutter);
}
.login-card {
  width: 100%; max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.login-brand h1 { margin: 0; }
.login-card .btn-primary { margin-top: 8px; }

/* ---------- top bar + tabs ---------- */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px;
  padding: 10px var(--gutter);
  border-bottom: 1px solid var(--line);
  background: var(--bg-2);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px;
  margin: 0; padding: 4px 10px; min-height: 32px;
  border-radius: 999px; border: 1px solid var(--line-2);
  font-size: 13px; color: var(--muted); background: var(--panel);
}
.chip .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--faint); flex: none; }
.chip-working { color: var(--text); border-color: #6b4a22; }
.chip-working .dot { background: var(--ember); box-shadow: 0 0 0 3px rgba(240, 160, 75, .2); }
.chip-idle .dot, .chip-unknown .dot { background: var(--neutral-fill); }
.chip-idle, .chip-unknown { color: var(--text); }
.chip-error { color: #ffb9ab; border-color: #6b2e27; }
.chip-error .dot { background: var(--bad); }
.chip-offline .dot, .chip-never .dot { background: #4a5068; }
.chip-no_contact .dot, .chip-loading .dot { background: transparent; border: 2px solid var(--faint); }
.chip-not_reported .dot { background: transparent; border: 2px dashed var(--faint); }
.account { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin-left: auto; }
.me-name { color: var(--muted); font-size: 14px; padding: 0 6px; }

.tabs {
  position: sticky; top: 0; z-index: 10;
  display: flex; gap: 2px;
  padding: 0 4px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;            /* the tab strip scrolls on itself, never the page */
  scrollbar-width: thin;
}
.tabs [role="tab"] {
  flex: 1 0 auto;
  min-height: var(--tap);
  min-width: 0;
  padding: 0 8px;
  font-size: 14px;
  white-space: nowrap;
  border: 0; border-radius: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
}
.tabs [role="tab"][aria-selected="true"] { color: var(--text); border-bottom-color: var(--ember); font-weight: 650; }
.tabs [role="tab"]:hover { color: var(--text); }
.count { font-size: 13px; color: inherit; }

.banner {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px;
  margin: 12px var(--gutter) 0;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #6b4a22;
  background: #221a10;
  color: #ffd9a6;
  font-size: 14px;
}
.banner span { flex: 1 1 200px; }

/* ---------- panels ---------- */
.panels { max-width: 960px; margin: 0 auto; padding: 16px var(--gutter) 24px; }
.panel { outline: none; }
.panel-title { margin-bottom: 12px; }
.tab-error {
  padding: 12px; border-radius: 10px;
  border: 1px solid #6b2e27; background: var(--bad-bg); color: #ffb9ab;
}
.notice {
  padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line-2); background: var(--panel-2);
}
.empty {
  padding: 18px 16px; border-radius: var(--radius);
  border: 1px dashed var(--line-2); background: var(--bg-2);
}
.empty-title { font-weight: 650; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin: 0 0 14px;
}
.card-head { margin-bottom: 8px; }
.card-head h3 { margin-bottom: 4px; }
.meta { color: var(--muted); font-size: 13.5px; margin: 0 0 2px; }
.meta.money { color: var(--text); }

/* ---------- station ---------- */
.station-wrap {
  position: relative;
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
}
#station-canvas {
  display: block;
  margin: 0 auto;
  max-width: 100%;
  border-radius: 8px;
  background: #0a0d1c;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.tip {
  position: absolute; z-index: 5;
  max-width: min(300px, calc(100% - 8px));
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line-2);
  background: rgba(10, 13, 22, .97);
  box-shadow: 0 10px 28px rgba(0, 0, 0, .55);
  font-size: 13px; line-height: 1.45;
  pointer-events: none;
}
.tip.pinned { pointer-events: auto; }
.tip strong { display: block; margin-bottom: 4px; font-size: 14px; }
.tip div { color: var(--muted); }
.tip-action { margin-top: 8px; width: 100%; }

.summary { max-width: 760px; margin: 16px auto 0; }
.facts { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.fact {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px;
}
.fact-k { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--faint); margin-bottom: 2px; }
.fact-v { display: block; font-weight: 600; }
.fact-sub { margin: 6px 0 0; padding-left: 18px; color: var(--muted); font-size: 14px; }
.fact-sub li { margin: 2px 0; }
.lanes-sub strong { color: var(--text); font-weight: 600; }

/* ---------- approvals ---------- */
.brief {
  margin: 8px 0 12px; padding: 10px 12px;
  border-radius: 10px; background: var(--bg-2); border: 1px solid var(--line);
}
.brief p:last-child { margin-bottom: 0; }
.brief-label { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--faint); margin-bottom: 4px; }
details.brief summary { cursor: pointer; min-height: 32px; font-weight: 600; }
.draft-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 250px), 1fr));
  gap: 12px;
}
.draft {
  margin: 0;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  display: flex; flex-direction: column; gap: 8px;
  min-width: 0;
}
.thumb {
  display: block; width: 100%; padding: 0; min-height: 0;
  border-radius: 8px; overflow: hidden;
  border: 1px solid var(--line); background: #000;
}
.thumb img { display: block; width: 100%; height: auto; max-height: 260px; object-fit: contain; background: #000; }
.thumb-missing {
  display: flex; align-items: center; justify-content: center;
  min-height: 120px; padding: 12px;
  color: var(--faint); font-size: 13px; text-align: center;
  border-radius: 8px; border: 1px dashed var(--line-2);
}
.draft figcaption { font-size: 13px; color: var(--muted); }
.draft-id { color: var(--text); font-weight: 650; }
.draft-more summary { cursor: pointer; font-size: 13px; color: var(--muted); min-height: 32px; display: flex; align-items: center; }
.draft-more p { font-size: 13px; margin: 6px 0 0; }
.decision .btn-row > button { flex: 1 1 30%; min-width: 0; padding: 0 10px; }
.note-form label { margin-top: 0; font-size: 14px; }
.note-form .muted.small { margin: 4px 0 8px; }
.decided { margin: 0; font-weight: 650; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line-2); }
.decided-approved { border-color: #3d5585; background: #141d33; }
.decided-changes { border-color: #6b4a22; background: #221a10; color: #ffd9a6; }
.decided-rejected { border-color: #6b2e27; background: var(--bad-bg); color: #ffb9ab; }
.decided-note { font-size: 13px; color: var(--muted); margin: 6px 0 0; }

/* ---------- bars (neutral; amber/red only for spend vs cap) ---------- */
.bars { display: grid; gap: 12px; margin: 10px 0; }
.bar-label { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2px 12px; font-size: 14px; margin-bottom: 5px; }
.bar-text { color: var(--muted); }
.bar-track {
  position: relative; height: 10px;
  border-radius: 6px; overflow: hidden;
  background: #0d1221; border: 1px solid var(--line);
}
.bar-fill { height: 100%; background: var(--neutral-fill); }
.bar-warn { background: var(--warn); }
.bar-over { background: var(--bad); }
.bar-tick { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--warn); }
.bar-note { margin: -6px 0 0; }
.verdict { font-weight: 650; margin: 4px 0 6px; }

/* ---------- lanes ---------- */
.lane-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 6px 12px; }
.badge {
  display: inline-block; font-size: 12.5px; padding: 2px 10px; border-radius: 999px;
  border: 1px solid var(--line-2); color: var(--muted); white-space: nowrap;
}
.badge-lit { color: var(--text); border-color: #6b4a22; }
.lane-planned { background: var(--bg-2); border-style: dashed; }
.lane-planned h3 { color: var(--muted); }
details.reg { margin-top: 12px; }
details.reg summary { cursor: pointer; min-height: var(--tap); display: flex; align-items: center; font-weight: 600; }
.kv { display: grid; grid-template-columns: minmax(0, max-content) minmax(0, 1fr); gap: 6px 14px; margin: 6px 0 0; }
.kv dt { color: var(--muted); font-size: 14px; }
.kv dd { margin: 0; }
.kv-money dd { text-align: right; }
.rows { list-style: none; margin: 0; padding: 0; }
.rows .row {
  display: flex; flex-direction: column; gap: 2px;
  padding: 8px 0; border-top: 1px solid var(--line);
}
.rows .row:first-child { border-top: 0; }
.row-title { font-weight: 600; }
.row-meta { color: var(--muted); font-size: 13.5px; }

/* ---------- activity ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.filter { font-size: 14px; border-radius: 999px; padding: 0 16px; }
.filter.on { background: var(--text); color: var(--bg); border-color: var(--text); font-weight: 650; }
.events { list-style: none; margin: 0 0 12px; padding: 0; }
.event { padding: 10px 0; border-top: 1px solid var(--line); }
.event:first-child { border-top: 0; }
.event-top { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.event-msg { margin: 0 0 2px; }
.src {
  display: inline-block; min-width: 52px; text-align: center;
  padding: 1px 8px; border-radius: 999px; border: 1px solid currentColor;
  font-size: 12px; font-weight: 650;
}
.src-agent { color: var(--src-agent); }
.src-owner { color: var(--src-owner); }
.src-system, .src-other { color: var(--src-system); }
.kind { color: var(--text); background: var(--panel-2); padding: 1px 6px; border-radius: 6px; }

/* ---------- footer ---------- */
.foot { max-width: 960px; margin: 0 auto; padding: 0 var(--gutter) 28px; color: var(--faint); font-size: 13px; }

/* ---------- dialogs ---------- */
.dialog {
  width: calc(100% - 24px);
  max-width: 440px;
  padding: 18px;
  border-radius: var(--radius);
  border: 1px solid var(--line-2);
  background: var(--panel);
  color: var(--text);
}
.dialog::backdrop { background: rgba(3, 5, 10, .78); }
.dialog .row { margin-top: 8px; }
.dialog .row > button { flex: 1 1 auto; }
.lightbox { max-width: min(1400px, calc(100% - 24px)); padding: 12px; }
.lightbox-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.lightbox-cap { margin: 0; font-size: 14px; color: var(--muted); flex: 1 1 auto; min-width: 0; }
.lightbox img { display: block; max-width: 100%; max-height: 72vh; margin: 0 auto 10px; object-fit: contain; background: #000; }
.lightbox .btn { width: 100%; }

@media (min-width: 720px) {
  .topbar { padding: 12px 24px; }
  .facts { grid-template-columns: 1fr 1fr; }
  .facts .fact:last-child { grid-column: 1 / -1; }
  .rows .row { flex-direction: row; justify-content: space-between; align-items: baseline; gap: 12px; }
  .row-meta { text-align: right; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
