/* Control-room palette: cool studio greys, tally red for "on air" (rendering),
   green for delivered, amber for waiting. Layout: form rail left, rundown right. */
:root {
  --bg: #eef1f4;
  --surface: #ffffff;
  --sunk: #f5f7f9;
  --ink: #16202a;
  --muted: #5a6775;
  --line: #d3dae1;
  --tally: #c8102e;
  --tally-soft: #fbe7ea;
  --done: #1e7f5c;
  --done-soft: #e2f3ec;
  --wait: #a8690f;
  --wait-soft: #f8eedb;
  --focus: #2b6cb0;
  --primary: #16202a;
  --primary-ink: #ffffff;
  --display: "Barlow Condensed", "Arial Narrow", Arial, sans-serif;
  --body: "Barlow", "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10161c; --surface: #182029; --sunk: #1d2731; --ink: #e6ebf0; --muted: #95a2af;
    --line: #2a3440; --tally: #ff5468; --tally-soft: #3a1d24; --done: #4cc38a; --done-soft: #17332a;
    --wait: #e0a84b; --wait-soft: #352a17; --focus: #7fb2ec; --primary: #e6ebf0; --primary-ink: #10161c;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 var(--body); }
[hidden] { display: none !important; }
h1, h2, h3 { font-family: var(--display); margin: 0; letter-spacing: .01em; }
.brand { font-size: 24px; font-weight: 700; }
h2 { font-size: 22px; font-weight: 600; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0 0; }
.hint-inline { display: block; color: var(--muted); font-size: 12.5px; font-weight: 400; }
.error { color: var(--tally); min-height: 1.5em; margin: 0; }

input, select, button { font: inherit; color: inherit; }
input[type="text"], input:not([type]), input[type="password"], input[type="number"], select {
  width: 100%; background: var(--sunk); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px;
}
input[type="file"] { width: 100%; font-size: 14px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
label { font-weight: 600; font-size: 14px; display: block; }
label > input, label > select { margin-top: 6px; font-weight: 400; }

.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 6px; padding: 8px 14px; cursor: pointer; font-weight: 600; }
.btn:hover:not(:disabled) { border-color: var(--ink); }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--tally); }
.btn.wide { width: 100%; padding: 11px; font-size: 16px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.link-btn { background: none; border: none; color: var(--muted); cursor: pointer; padding: 4px; text-decoration: underline; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 28px; display: grid; gap: 14px; }
.login-card p { margin: 0; }

/* top bar */
.topbar { display: flex; align-items: center; gap: 16px; padding: 14px 24px; border-bottom: 1px solid var(--line); background: var(--surface); flex-wrap: wrap; }
.who { margin-left: auto; display: flex; align-items: center; gap: 8px; color: var(--muted); }
.worker-pill { display: inline-flex; align-items: center; gap: 8px; padding: 4px 12px; border-radius: 999px; background: var(--sunk); border: 1px solid var(--line); font-size: 14px; }
.tally { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.worker-pill.online .tally { background: var(--done); }
.worker-pill.busy .tally { background: var(--tally); box-shadow: 0 0 0 3px var(--tally-soft); }
.worker-pill.offline { color: var(--muted); }

/* layout */
.layout { display: grid; grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); gap: 24px; padding: 24px; max-width: 1400px; margin: 0 auto; align-items: start; }
@media (max-width: 860px) { .layout { grid-template-columns: 1fr; padding: 16px; } .topbar { padding: 12px 16px; } }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 20px; }
.new-episode { position: sticky; top: 16px; }
@media (max-width: 860px) { .new-episode { position: static; } }
#jobForm { display: grid; gap: 18px; margin-top: 14px; }
.field.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.anchor-row { display: flex; gap: 8px; margin-top: 6px; }
.anchor-row select { flex: 1; min-width: 0; }
.anchor-add { display: grid; gap: 8px; padding: 14px; background: var(--sunk); border: 1px dashed var(--line); border-radius: 8px; }
.row-actions { display: flex; gap: 10px; align-items: center; }
.advanced summary { cursor: pointer; font-weight: 600; color: var(--muted); }
.form-msg { margin: 0; min-height: 1.5em; color: var(--muted); }
.form-msg.bad { color: var(--tally); }

.upload-progress { display: grid; gap: 4px; margin-top: 8px; }
.upload-progress .bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.upload-progress .bar span { display: block; height: 100%; width: 0; background: var(--ink); transition: width .3s; }
.upload-text { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* rundown */
.rundown { min-width: 0; display: grid; gap: 14px; }
.rundown-head { display: flex; align-items: baseline; gap: 12px; }
.job-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.job { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--line); border-radius: 8px; padding: 14px 16px; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 16px; cursor: pointer; }
.job:hover { border-color: var(--muted); }
.job.selected { outline: 2px solid var(--focus); outline-offset: 1px; }
.job.s-running, .job.s-starting, .job.s-uploading { border-left-color: var(--tally); }
.job.s-done { border-left-color: var(--done); }
.job.s-queued { border-left-color: var(--wait); }
.job.s-failed, .job.s-stalled { border-left-color: var(--tally); }
.job-title { font-family: var(--display); font-size: 19px; font-weight: 600; overflow-wrap: anywhere; }
.job-meta { color: var(--muted); font-size: 13.5px; }
.job-side { text-align: right; display: grid; gap: 4px; justify-items: end; align-content: start; }
.status { font-weight: 600; font-size: 14px; display: inline-flex; align-items: center; gap: 6px; }
.status .tally { width: 8px; height: 8px; }
.s-running .status, .s-starting .status, .s-uploading .status,
.status.s-running, .status.s-starting, .status.s-uploading { color: var(--tally); }
.s-running .status .tally, .s-starting .status .tally, .s-uploading .status .tally,
.status.s-running .tally, .status.s-starting .tally, .status.s-uploading .tally { background: var(--tally); }
.s-done .status, .status.s-done { color: var(--done); }
.s-done .status .tally, .status.s-done .tally { background: var(--done); }
.s-queued .status, .status.s-queued { color: var(--wait); }
.s-queued .status .tally, .status.s-queued .tally { background: var(--wait); }
.s-failed .status, .s-stalled .status, .status.s-failed, .status.s-stalled { color: var(--tally); }
.status.s-failed .tally, .status.s-stalled .tally { background: var(--tally); }
.eta { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* the chunk strip: one cell per chunk of the episode, like clips on an edit timeline */
.strip { grid-column: 1 / -1; display: flex; gap: 2px; height: 14px; margin-top: 4px; }
.strip i { flex: 1; min-width: 1px; background: var(--line); border-radius: 1px; }
.strip i.d { background: var(--done); }
.strip i.r { background: var(--tally); }
.strip.bar i { border-radius: 0; }
.strip-label { grid-column: 1 / -1; font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
@media (prefers-reduced-motion: no-preference) { .strip i.r { animation: blink 1.2s steps(2, start) infinite; } }
@keyframes blink { to { opacity: .35; } }

/* detail */
.detail { display: grid; gap: 14px; }
.detail > p { margin: 0; }
.detail-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: start; }
.detail h3 { font-size: 24px; font-weight: 600; overflow-wrap: anywhere; }
.detail video { width: 100%; max-height: 62vh; background: #000; border-radius: 6px; }
.detail .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; font-size: 14px; margin: 0; }
.facts dt { color: var(--muted); } .facts dd { margin: 0; overflow-wrap: anywhere; }
.log { max-height: 220px; overflow: auto; background: var(--sunk); border: 1px solid var(--line); border-radius: 6px; padding: 10px; font: 12.5px/1.45 ui-monospace, Menlo, Consolas, monospace; white-space: pre-wrap; }
.notice { padding: 10px 12px; border-radius: 6px; background: var(--wait-soft); color: var(--ink); }
.notice.bad { background: var(--tally-soft); }
.empty { padding: 28px; border: 1px dashed var(--line); border-radius: 10px; color: var(--muted); text-align: center; }

/* GPU servers */
.gpus { display: grid; gap: 10px; margin-bottom: 10px; }
.gpus .rundown-head { align-items: center; }
.gpus .rundown-head .btn { margin-left: auto; }
.btn.small { padding: 6px 12px; font-size: 14px; }
.gpu-note { margin: 0; color: var(--muted); font-size: 14px; }
.gpu-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.gpu { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--wait); border-radius: 8px;
  padding: 12px 16px; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 16px; align-items: center; }
.gpu.p-ready { border-left-color: var(--done); }
.gpu.p-rendering { border-left-color: var(--tally); }
.gpu.p-failed, .gpu.p-silent { border-left-color: var(--tally); }
.gpu.p-stopped, .gpu.p-stopping { border-left-color: var(--line); }
.gpu-name { font-family: var(--display); font-size: 19px; font-weight: 600; }
.gpu-phase { font-weight: 600; font-size: 14px; display: inline-flex; gap: 6px; align-items: center; }
.gpu-phase .tally { width: 8px; height: 8px; background: var(--wait); }
.p-ready .gpu-phase { color: var(--done); } .p-ready .gpu-phase .tally { background: var(--done); }
.p-rendering .gpu-phase, .p-failed .gpu-phase, .p-silent .gpu-phase { color: var(--tally); }
.p-rendering .gpu-phase .tally, .p-failed .gpu-phase .tally, .p-silent .gpu-phase .tally { background: var(--tally); }
.p-starting .gpu-phase, .p-installing .gpu-phase { color: var(--wait); }
.gpu-meta { grid-column: 1 / -1; color: var(--muted); font-size: 13.5px; font-variant-numeric: tabular-nums; }
.gpu-cost { font-variant-numeric: tabular-nums; }
@media (prefers-reduced-motion: no-preference) {
  .p-starting .gpu-phase .tally, .p-installing .gpu-phase .tally { animation: blink 1.2s steps(2, start) infinite; }
}

.gpu-picker { display: grid; gap: 12px; }
.picker-head { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; }
.picker-head h3 { font-size: 20px; font-weight: 600; margin-right: auto; }
.seg { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg-label { padding: 0 10px; font-size: 13px; color: var(--muted); }
.seg button { border: 0; border-left: 1px solid var(--line); background: var(--surface); padding: 6px 12px; cursor: pointer; font-weight: 600; font-size: 14px; }
.seg button:first-child { border-left: 0; }
.seg button[aria-checked="true"] { background: var(--primary); color: var(--primary-ink); }
.gpu-options { display: grid; gap: 6px; max-height: 360px; overflow: auto; }
.gpu-opt { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--sunk); cursor: pointer; text-align: left; width: 100%; }
.gpu-opt:hover:not(:disabled) { border-color: var(--muted); }
.gpu-opt[aria-checked="true"] { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); background: var(--surface); }
.gpu-opt:disabled { opacity: .5; cursor: not-allowed; }
.opt-name { font-weight: 600; }
.opt-price { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.opt-sub { color: var(--muted); font-size: 13px; }
.opt-avail { font-size: 13px; text-align: right; }
.avail-HIGH { color: var(--done); } .avail-MEDIUM { color: var(--wait); } .avail-LOW { color: var(--wait); } .avail-NONE { color: var(--muted); }
.picker-foot { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; justify-content: space-between; }
.gpu-summary { margin: 0; font-variant-numeric: tabular-nums; }
@media (max-width: 560px) { .picker-head h3 { width: 100%; } .gpu { grid-template-columns: 1fr; } }
.gpus .rundown-head { flex-wrap: wrap; row-gap: 4px; }
.gpus .rundown-head h2 { white-space: nowrap; }
@media (max-width: 560px) { #gpuMeta { order: 3; flex-basis: 100%; } }
.form-msg, .gpu-note { overflow-wrap: anywhere; }

/* model choice */
.picker-model { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; }
.picker-model select { width: auto; margin: 0; padding: 6px 8px; }
.tag { display: inline-block; font-size: 12px; font-weight: 600; padding: 1px 7px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted); vertical-align: 1px; margin-left: 6px; }
.tag.experimental { color: var(--wait); border-color: var(--wait); }
.tag.preview { color: var(--focus); border-color: var(--focus); }
.gpu-model { color: var(--muted); font-family: var(--body); font-size: 14px; font-weight: 500; margin-left: 6px; }
