:root {
  color-scheme: dark;
  --bg: #070a10;
  --panel: #111722;
  --panel-2: #182130;
  --field: #0c111a;
  --ink: #e8edf5;
  --muted: #8b97ab;
  --line: #243044;
  --brand: #ffcf33;
  --brand-ink: #1a1400;
  --brand-soft: #2c2610;
  --green: #35e0a0;
  --green-soft: #0f2d24;
  --red: #ff6464;
  --red-soft: #351719;
  --amber: #ffb648;
  --amber-soft: #33260f;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif; }
h1 { font-size: 18px; margin: 0; letter-spacing: -.01em; overflow-wrap: anywhere; }
h2 { font-size: 13px; margin: 0 0 10px; font-weight: 700; }
button, textarea { font: inherit; color: inherit; }
button { min-height: 38px; padding: 7px 14px; border-radius: 9px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; font-weight: 600; }
button:hover { border-color: #46597a; }
button:focus-visible, textarea:focus-visible { outline: 3px solid rgba(255, 207, 51, .45); outline-offset: 1px; }
button.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
button.primary:hover { background: #ffdb66; }
button:disabled { opacity: .5; cursor: not-allowed; }
button[hidden], [hidden] { display: none !important; }
input:not([type="checkbox"]), select { font: inherit; color: inherit; width: 100%; min-height: 38px; padding: 7px 10px; border-radius: 9px; border: 1px solid var(--line); background: var(--field); }
input:focus-visible, select:focus-visible { outline: 3px solid rgba(255, 207, 51, .45); outline-offset: 1px; }
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: radial-gradient(ellipse at 50% 30%, #182130 0%, #070a10 100%); }
.auth-card { width: min(400px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 22px; box-shadow: var(--shadow); display: grid; gap: 10px; }
.auth-card .brand { padding: 0 0 4px; }
.auth-card label { margin-bottom: -5px; }
#auth-code-row { display: grid; gap: 5px; }
#auth-code-row label { margin: 0; }
.linkish { border: 0; background: none; color: var(--brand); min-height: 32px; }
dialog { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px; width: min(440px, calc(100vw - 32px)); color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, .6); }
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog h3 { margin: 14px 0 4px; font-size: 13px; }
dialog code { margin-top: 8px; user-select: all; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; }
.dialog-head h2 { margin: 0; font-size: 15px; }
.dialog-head button { min-height: 32px; padding: 2px 10px; }
.account-button { margin-top: 6px; width: 100%; text-align: left; font-size: 12px; font-weight: 600; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.pack-row { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin-bottom: 7px; }
.pack-row label { margin: 0; }
.pack-row select { width: auto; min-height: 32px; padding: 3px 8px; font-weight: 600; }
.pack-row .muted { margin: 0; font-size: 12px; flex: 1 1 200px; }
textarea { width: 100%; padding: 9px 11px; border-radius: 9px; border: 1px solid var(--line); background: var(--field); resize: vertical; }
label { display: block; font-weight: 600; font-size: 12px; margin-bottom: 5px; color: var(--muted); }
code { display: block; padding: 6px 8px; border-radius: 6px; background: rgba(255, 255, 255, .06); font-size: 11.5px; overflow-wrap: anywhere; margin-bottom: 8px; }
.muted { color: var(--muted); margin: 2px 0 0; font-size: 13px; }
.error { color: var(--red); margin: 6px 0 0; font-size: 13px; }
.row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

.app { display: grid; grid-template-columns: 196px minmax(0, 1fr) 290px; height: 100vh; min-height: 640px; }

.sidebar { background: var(--panel); border-right: 1px solid var(--line); padding: 14px 10px; display: flex; flex-direction: column; min-height: 0; }
.brand { display: flex; align-items: center; gap: 9px; padding: 0 6px 14px; }
.brand b { display: block; font-size: 14px; }
.brand small { color: var(--muted); font-size: 11px; }
.logo { display: grid; place-items: center; width: 34px; height: 34px; flex: none; border-radius: 10px; color: #fff; font-weight: 800; background: linear-gradient(135deg, #ffcf33, #ff8a3d); color: var(--brand-ink); }
.tabs { display: grid; gap: 2px; }
.tabs button { text-align: left; border: 0; background: none; color: var(--muted); font-weight: 600; }
.tabs button:hover { background: var(--panel-2); }
.tabs button[aria-selected="true"] { background: var(--brand-soft); color: var(--brand); }
.side-title { margin: 18px 6px 6px; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.projects { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; overflow: auto; flex: 1; align-content: start; min-height: 40px; }
.projects button { width: 100%; text-align: left; display: grid; gap: 1px; height: auto; font-weight: 500; border-color: transparent; background: var(--panel-2); }
.projects button[aria-current="true"] { border-color: var(--brand); background: var(--brand-soft); }
.projects .name { overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; font-size: 13px; overflow-wrap: anywhere; }
.projects .status { font-size: 11px; color: var(--muted); }
.health { margin-top: 10px; font-size: 12px; padding: 7px 9px; border-radius: 8px; background: var(--amber-soft); color: var(--amber); font-weight: 600; }
.health.ok { background: var(--green-soft); color: var(--green); }
.health.bad { background: var(--red-soft); color: var(--red); }

.main { display: flex; flex-direction: column; gap: 10px; padding: 14px; min-width: 0; min-height: 0; }
.head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.head-text { min-width: 0; }
.ghost { background: var(--panel); }
.head-actions { display: flex; flex-wrap: wrap; gap: 6px; flex: none; justify-content: flex-end; }
.link-button { display: inline-flex; align-items: center; min-height: 38px; padding: 7px 14px; border-radius: 9px; background: var(--brand); color: var(--brand-ink); font-weight: 600; text-decoration: none; }
.link-button:hover { background: #ffdb66; }
.link-button:focus-visible { outline: 3px solid rgba(255, 207, 51, .45); outline-offset: 1px; }
.command-top { display: flex; flex-wrap: wrap; gap: 4px 14px; justify-content: space-between; align-items: center; margin-bottom: 5px; }
.command-top label { margin: 0; }
.check { display: inline-flex; gap: 5px; align-items: center; font-weight: 600; color: var(--brand); cursor: pointer; min-width: 0; }
.check span { overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 1; overflow-wrap: anywhere; }
.check input { flex: none; margin: 0; }

.stages { list-style: none; display: flex; gap: 3px; margin: 0; padding: 0; }
.stages li { flex: 1; text-align: center; font-size: 11.5px; padding: 5px 2px; border-radius: 6px; background: var(--panel-2); color: var(--muted); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stages li.done { background: var(--green-soft); color: var(--green); }
.stages li.now { background: var(--brand); color: var(--brand-ink); }
.stages li.blocked { background: var(--red); color: #210506; }

.stage-area { position: relative; flex: 1; min-height: 300px; display: flex; }
.view { flex: 1; min-width: 0; border-radius: 14px; overflow: hidden; }
.scene-view { display: flex; flex-direction: column; background: #05070c; border: 1px solid var(--line); }
.scene-wrap { position: relative; flex: 1; min-height: 240px; background: radial-gradient(ellipse at 50% 35%, #101a2c 0%, #05070c 75%); }
#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.scene-tag { position: absolute; left: 12px; top: 10px; margin: 0; font-size: 12px; font-weight: 600; color: var(--muted); background: rgba(5, 7, 12, .7); padding: 3px 9px; border-radius: 7px; pointer-events: none; }
.scene-back { position: absolute; left: 12px; top: 10px; min-height: 32px; padding: 4px 10px; font-size: 12px; }
.scene-toast { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); max-width: 84%; padding: 7px 14px; border-radius: 10px; color: #fff; font-weight: 700; font-size: 13px; background: rgba(22, 30, 38, .88); border: 0; min-height: 0; text-align: center; }
.scene-toast:hover { filter: brightness(1.12); }
.scene-toast.red { background: #c62828; }
.scene-toast.amber { background: #a96400; }
.scene-toast.green { background: #0d7f59; }

.panel { background: var(--panel); border: 1px solid var(--line); padding: 16px; overflow: auto; }
#flow { width: 100%; height: auto; display: block; max-height: 100%; }
.node rect { fill: var(--panel-2); stroke: var(--line); stroke-width: 1.5; }
.node text { fill: var(--ink); font-size: 13px; font-weight: 600; text-anchor: middle; }
.node .sub { fill: var(--muted); font-size: 11px; font-weight: 500; }
.node.active rect { fill: var(--brand-soft); stroke: var(--brand); stroke-width: 2.5; }
.node.done rect { fill: var(--green-soft); stroke: var(--green); }
.node.red rect { fill: var(--red-soft); stroke: var(--red); stroke-width: 2.5; }
.edge { fill: none; stroke: #46597a; stroke-width: 2; }
.edge.back { stroke: var(--red); stroke-dasharray: 5 4; }
.pulse-dot { fill: var(--brand); }

.board { display: grid; grid-template-columns: repeat(4, minmax(120px, 1fr)); gap: 10px; }
.column { background: var(--panel-2); border-radius: 10px; padding: 9px; min-height: 200px; }
.column h3 { margin: 0 0 8px; font-size: 12px; color: var(--muted); }
.task { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 9px; margin-bottom: 6px; font-size: 13px; font-weight: 600; overflow-wrap: anywhere; }
.task small { display: block; font-weight: 500; color: var(--muted); font-size: 11.5px; }
.task.now { border-color: var(--brand); box-shadow: inset 3px 0 0 var(--brand); }
.task.red { border-color: var(--red); box-shadow: inset 3px 0 0 var(--red); }

.command { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 9px 11px; box-shadow: var(--shadow); }
.command-row { display: flex; gap: 8px; align-items: stretch; }
.command textarea { flex: 1; min-height: 46px; }
.command button { flex: none; }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin: 0; }
.kpis div { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 7px 11px; min-width: 0; }
.kpis dt { font-size: 11px; color: var(--muted); }
.kpis dd { margin: 0; font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.kpis dd.good { color: var(--green); }
.kpis dd.bad { color: var(--red); }

.rail { background: var(--bg); border-left: 1px solid var(--line); padding: 14px 12px; display: flex; flex-direction: column; gap: 10px; min-height: 0; overflow: auto; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px; box-shadow: var(--shadow); }
.card p { margin: 0 0 6px; font-size: 13px; overflow-wrap: anywhere; white-space: pre-wrap; }
.card.danger { background: var(--red-soft); border-color: #8a3336; }
.card.success { background: var(--green-soft); border-color: #24705a; }
.card.approval { background: var(--amber-soft); border-color: #7f6026; }

.rooms { list-style: none; margin: 0; padding: 0; display: grid; gap: 3px; }
.rooms button { width: 100%; height: auto; display: grid; grid-template-columns: 9px minmax(0, 1fr) auto; gap: 2px 8px; align-items: center; text-align: left; padding: 5px 7px; border-color: transparent; background: none; font-weight: 500; }
.rooms button:hover { background: var(--panel-2); }
.rooms button[aria-pressed="true"] { background: var(--brand-soft); }
.rooms .dot { width: 8px; height: 8px; border-radius: 50%; background: #4b5870; }
.rooms .working .dot { background: var(--green); box-shadow: 0 0 0 3px rgba(53, 224, 160, .22); }
.rooms .failed .dot, .rooms .fixing .dot { background: var(--red); box-shadow: 0 0 0 3px rgba(210, 47, 47, .2); }
.rooms .waiting .dot { background: #f0a020; box-shadow: 0 0 0 3px rgba(240, 160, 32, .25); }
.rooms .room-title { font-weight: 700; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rooms .room-state { font-size: 11px; color: var(--muted); }
.rooms .failed .room-state, .rooms .fixing .room-state { color: var(--red); font-weight: 700; }
.rooms .waiting .room-state { color: var(--amber); font-weight: 700; }
.rooms .working .room-state { color: var(--green); font-weight: 700; }
.rooms .room-agent { grid-column: 2 / 4; font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.log-card { flex: 1; display: flex; flex-direction: column; min-height: 200px; }
.log-card details { font-size: 12.5px; margin-bottom: 4px; flex: none; }
.log-card pre { max-height: 160px; overflow: auto; padding: 7px; font-size: 11px; background: var(--bg); border-radius: 6px; white-space: pre-wrap; overflow-wrap: anywhere; }
.log { list-style: none; margin: 0; padding: 0; overflow: auto; flex: 1; min-height: 80px; }
.log-view { display: flex; flex-direction: column; }
.log li { padding: 5px 0; border-top: 1px solid var(--line); font-size: 12.5px; overflow-wrap: anywhere; white-space: pre-wrap; }
.log .meta { display: block; font-size: 10.5px; color: var(--muted); }
.log .tool { color: var(--muted); }
.log .error { color: var(--red); margin: 0; font-size: 12.5px; }
.log .success { color: var(--green); }
.log .handoff { color: var(--amber); }

@media (max-width: 1180px) {
  .app { grid-template-columns: 190px minmax(0, 1fr); grid-template-rows: auto auto; height: auto; }
  .main { min-height: 680px; }
  .sidebar { grid-row: 1; }
  .rail { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--line); overflow: visible; }
  .log-card { max-height: 420px; }
}
@media (max-width: 720px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  .tabs { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .tabs button { text-align: center; padding: 7px 2px; font-size: 12.5px; }
  .projects { max-height: 130px; }
  .main { min-height: 0; padding: 10px; }
  .stage-area { min-height: 330px; flex: none; }
  .stage-area .view { min-height: 330px; }
  .stages li { font-size: 10px; }
  .command-row { flex-direction: column; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .board { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---- the big overview screen ---- */
.wall { flex: none; padding: 12px 14px 14px; background: linear-gradient(180deg, #0b1320, #070b13); border-bottom: 3px solid #1d2a40; box-shadow: inset 0 0 60px rgba(70, 130, 255, .07); font-variant-numeric: tabular-nums; }
.wall-top { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 14px; }
.wall-clock { font: 700 clamp(22px, 2.6vw, 38px)/1 ui-monospace, "SF Mono", Menlo, monospace; color: #fff; letter-spacing: .02em; }
.wall-live { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 800; letter-spacing: .1em; color: var(--muted); }
.wall-live i { width: 8px; height: 8px; border-radius: 50%; background: #4b5870; }
.wall-live.on { color: var(--green); }
.wall-live.on i { background: var(--green); box-shadow: 0 0 10px var(--green); animation: blink 1.4s infinite; }
@keyframes blink { 50% { opacity: .35; } }
.wall-name { flex: 1 1 200px; min-width: 0; color: var(--muted); font-size: 13px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; text-align: right; }
.wall-grid { display: grid; grid-template-columns: minmax(170px, 1fr) minmax(190px, .8fr) minmax(220px, 1.3fr); gap: 16px; margin-top: 10px; align-items: stretch; }
.wall-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 14px; align-content: start; margin: 0; }
.wall-stats dt { font-size: 10.5px; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.wall-stats dd { margin: 0; font-size: clamp(16px, 1.6vw, 24px); font-weight: 800; color: #fff; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.wall-stats dd.good { color: var(--green); }
.wall-stats dd.bad { color: var(--red); }
.wall-state { display: grid; place-content: center; justify-items: center; text-align: center; gap: 2px; padding: 8px; border: 1px solid #1d2a40; border-radius: 12px; background: rgba(255, 255, 255, .02); }
.wall-state b { font-size: clamp(18px, 2vw, 30px); line-height: 1.1; color: #dbe4f2; }
.wall-state small { color: var(--muted); font-size: 12px; }
.wall-state.running { border-color: #1f6e56; box-shadow: 0 0 24px rgba(53, 224, 160, .16); }
.wall-state.running b { color: var(--green); }
.wall-state.waiting { border-color: #7f6026; box-shadow: 0 0 24px rgba(255, 182, 72, .16); }
.wall-state.waiting b { color: var(--amber); }
.wall-state.blocked { border-color: #8a3336; box-shadow: 0 0 24px rgba(255, 100, 100, .18); }
.wall-state.blocked b { color: var(--red); }
.wall-state.done b { color: var(--brand); }
.wall-feed { list-style: none; margin: 0; padding: 0; min-width: 0; display: grid; gap: 3px; align-content: start; font-size: 12px; }
.wall-feed li { display: flex; gap: 8px; min-width: 0; color: #c3cede; }
.wall-feed time { flex: none; color: var(--muted); font-size: 11px; }
.wall-feed span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.wall-feed .error { color: var(--red); margin: 0; font-size: 12px; }
.wall-feed .success { color: var(--green); }
.wall-feed .handoff { color: var(--amber); }
.wall-bars { display: flex; align-items: flex-end; gap: 2px; height: 34px; margin-top: 10px; }
.wall-bars i { flex: 1; min-width: 2px; background: #4f8cff; border-radius: 2px 2px 0 0; opacity: .85; }
.wall-bars i.empty { background: #1a2436; }
.wall-caption { margin: 2px 0 0; font-size: 10.5px; color: var(--muted); }
.wall-stages { list-style: none; display: flex; flex-wrap: wrap; gap: 3px; margin: 10px 0 0; padding: 0; }
.wall-stages li { flex: 1 1 auto; text-align: center; font-size: 11.5px; font-weight: 700; padding: 3px 6px; border-radius: 5px; background: #141c2a; color: var(--muted); white-space: nowrap; }
.wall-stages li.done { background: var(--green-soft); color: var(--green); }
.wall-stages li.now { background: var(--brand); color: var(--brand-ink); }
.wall-stages li.blocked { background: var(--red); color: #210506; }
.bigscreen { position: absolute; right: 10px; top: 10px; min-height: 32px; padding: 4px 10px; font-size: 12px; background: rgba(17, 23, 34, .85); }

/* The office view shows stages and numbers on the wall, so the page gives the space back. */
body.office-view #stages, body.office-view .kpis { display: none; }
body.office-view .main { gap: 8px; padding: 10px; }
body.office-view .command { padding: 7px 10px; }
body.office-view .command textarea { min-height: 38px; }
/* Big screen mode: only the wall and the office. */
body.big-mode .sidebar, body.big-mode .rail, body.big-mode .head, body.big-mode .command, body.big-mode #stages, body.big-mode .kpis { display: none; }
body.big-mode .app { grid-template-columns: minmax(0, 1fr); }
body.big-mode .main { padding: 0; }
body.big-mode .scene-view { border: 0; border-radius: 0; }
@media (max-width: 860px) {
  .wall-grid { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .wall-name { text-align: left; flex-basis: 100%; }
  .wall-state { padding: 10px; }
}

.link-button.secondary { background: var(--panel-2); color: var(--ink); border: 1px solid var(--line); }
.link-button.secondary:hover { background: var(--line); }
button.danger { background: var(--red-soft); border-color: #8a3336; color: var(--red); }
.versions { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; max-height: 170px; overflow: auto; }
.versions li { display: flex; justify-content: space-between; gap: 8px; align-items: center; font-size: 12px; }
.versions small { display: block; color: var(--muted); font-size: 10.5px; }
.versions button { min-height: 30px; padding: 2px 8px; font-size: 11.5px; flex: none; }

.log li.empty { border: 0; color: var(--muted); padding: 8px 0; }
