/* Control-room palette: graphite surfaces, tally red for program, tally green for preview. */
:root {
  --bg: #0c0e12;
  --panel: #14171d;
  --panel-2: #1b1f27;
  --line: #262b35;
  --fg: #e9ecf1;
  --muted: #8c94a3;
  --program: #ff3b4f;
  --preview: #2ed47a;
  --accent: #4f8cff;
  --warn: #f5b13d;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 13px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 960px;
}
button, input, select {
  font: inherit; color: var(--fg);
}
button {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 11px;
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: #3a4150; }
button:disabled { opacity: .45; cursor: default; }
button:focus-visible, input:focus-visible, select:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
input:not([type]), input[type="number"], input[type="text"], input[type="password"], select {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  width: 100%;
}
input[type="range"] { accent-color: var(--accent); width: 100%; }
input[type="color"] { width: 48px; height: 30px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: none; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 12px; margin: 8px 0 0; }
.empty { color: var(--muted); margin: 8px 2px; }
.spacer { flex: 1; }
label { color: var(--muted); font-size: 12px; display: block; margin: 8px 0 4px; }
label.inline { display: inline-flex; align-items: center; gap: 6px; margin: 0; }
label.check { color: var(--fg); font-size: 13px; }
.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.error { color: #ff8a96; margin: 8px 0 0; }

/* Top bar */
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.topbar > * { white-space: nowrap; flex: none; }
.topbar .spacer { flex: 1; }
.topbar select { width: auto; }
.brand { font-weight: 700; letter-spacing: .01em; display: flex; align-items: center; gap: 8px; margin-right: 6px; }
.wordmark b { color: var(--program); font-weight: inherit; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--program); box-shadow: 0 0 0 3px #ff3b4f33; }
.room { display: inline-flex; gap: 8px; align-items: baseline; }
.room .label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .1em; }
.room .code { font: 600 15px/1 var(--mono); letter-spacing: .16em; }
.conn { color: var(--muted); font-size: 12px; }
.conn.ok { color: var(--preview); }
.rec { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; min-width: 112px; justify-content: center; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: #ff3b4f88; }
.rec[aria-pressed="true"] { background: var(--program); border-color: var(--program); }
.rec[aria-pressed="true"] .rec-dot { background: #fff; animation: blink 1s steps(2) infinite; }
.rec[aria-pressed="true"] #recLabel { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.golive { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; min-width: 112px; justify-content: center; }
.live-dot { width: 10px; height: 10px; border-radius: 50%; border: 2px solid #ff3b4f88; }
.golive[aria-pressed="true"] { background: #2a0d12; border-color: var(--program); }
.golive[aria-pressed="true"] .live-dot { background: var(--program); border-color: var(--program); animation: blink 1s steps(2) infinite; }
.golive[aria-pressed="true"] #liveLabel { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.golive.confirm { background: var(--program); border-color: var(--program); color: #fff; }
@keyframes blink { 50% { opacity: .2; } }
@media (prefers-reduced-motion: reduce) { .rec[aria-pressed="true"] .rec-dot, .golive[aria-pressed="true"] .live-dot { animation: none; } }

/* Workspace */
.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  min-height: 0;
}
.inspector { background: var(--panel); min-height: 0; overflow: auto; border-left: 1px solid var(--line); }
/* Source bin: a multiview strip under Preview and Program. */
.bin { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px 12px; }
.panel-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }
.panel-head h2 .muted { margin-left: 6px; letter-spacing: 0; }
h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); margin: 0; font-weight: 600; }

/* Source tiles */
.tiles { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.tile {
  position: relative;
  background: var(--panel-2);
  border: 2px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  user-select: none;
}
.tile[data-tally="preview"] { border-color: var(--preview); }
.tile[data-tally="program"] { border-color: var(--program); }
.tile[aria-selected="true"] { box-shadow: 0 0 0 2px var(--accent); }
.tile canvas { display: block; width: 100%; aspect-ratio: 16 / 9; background: #000; }
.tile .meta { display: flex; align-items: center; gap: 6px; padding: 5px 7px; min-width: 0; }
.tile .num { font: 600 11px/1 var(--mono); color: var(--muted); border: 1px solid var(--line); border-radius: 3px; padding: 2px 4px; }
.tile .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.tile .kind { color: var(--muted); font-size: 11px; }
.tile .badges { position: absolute; top: 6px; left: 6px; display: flex; gap: 4px; }
.tile .badge { font: 600 10px/1 var(--mono); padding: 3px 5px; border-radius: 3px; background: #000a; color: #fff; }
.tile .badge.live { background: var(--program); }
.tile .badge.pv { background: var(--preview); color: #04170c; }
.tile .badge.warn { background: var(--warn); color: #241600; }
.tile .remove { position: absolute; top: 4px; right: 4px; padding: 2px 7px; font-size: 12px; background: #000a; border-color: transparent; opacity: 0; }
.tile:hover .remove, .tile:focus-within .remove { opacity: 1; }
.tile .mini-meter { height: 3px; background: #0006; }
.tile .mini-meter i { display: block; height: 100%; width: 0; background: var(--preview); }
.add-row { display: flex; flex-wrap: wrap; gap: 6px; }
.add-row button { padding: 6px 10px; }
.tile .clip-bar { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: #0008; }
.tile .clip-bar i { display: block; height: 100%; width: 0; background: var(--accent); }
.tile .media-wrap { position: relative; }

/* Monitors */
.monitors { padding: 14px; display: flex; flex-direction: column; gap: 12px; min-width: 0; overflow: auto; }
.monitor-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.monitor { margin: 0; min-width: 0; }
.monitor figcaption { display: flex; gap: 8px; align-items: baseline; margin-bottom: 6px; }
.monitor .tag { font: 700 11px/1 var(--mono); letter-spacing: .12em; text-transform: uppercase; padding: 4px 6px; border-radius: 3px; }
.monitor.preview .tag { background: var(--preview); color: #04170c; }
.monitor.program .tag { background: var(--program); color: #fff; }
.monitor canvas { display: block; width: 100%; aspect-ratio: 16 / 9; background: #000; border-radius: 6px; border: 2px solid var(--line); }
.monitor.preview canvas { border-color: #2ed47a66; }
.monitor.program canvas { border-color: #ff3b4f88; }

.switcher {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px;
}
.group { display: flex; align-items: center; gap: 6px; }
/* Layout buttons: a frame with lighter tiles; floating tiles outlined so they read on top. */
.layout-btn { padding: 4px; display: inline-grid; gap: 6px; border-radius: 8px; }
.layout-btn .layout-icon { display: block; width: 44px; height: auto; }
.layout-btn .layout-icon .frame { fill: #1d2129; }
.layout-btn .layout-icon .slot { fill: #5b6475; }
.layout-btn .layout-icon .slot.over { fill: #8a93a6; stroke: #1d2129; stroke-width: 2.5; }
.layout-btn[aria-pressed="true"] { border-color: var(--preview); background: #2ed47a1a; }
.layout-btn[aria-pressed="true"] .layout-icon .slot { fill: var(--preview); }
.layout-btn[aria-pressed="true"] .layout-icon .slot.over { fill: #9ff0c4; }
.layouts .layout-name { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.all-layouts { white-space: nowrap; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.icon-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; padding: 0; }
.icon-btn svg { width: 20px; height: 20px; fill: currentColor; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; }
.icon-btn[aria-pressed="true"] { border-color: var(--accent); background: #4f8cff2a; color: #fff; }

/* Layout panel */
.layout-dialog { width: min(880px, calc(100vw - 32px)); max-height: calc(100vh - 48px); overflow: auto; padding: 18px 20px 20px; }
.layout-dialog-head { display: flex; align-items: center; gap: 12px; position: sticky; top: -18px; background: var(--panel); padding: 4px 0 8px; z-index: 1; }
.layout-dialog-head h2 { margin: 0; flex: 1; }
.layout-dialog .close { font-size: 20px; border-radius: 50%; }
.layout-section { margin-top: 14px; }
.layout-section-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.layout-section-head h3 { margin: 0; font-size: 15px; }
.link { background: none; border: 0; color: #a99cff; font-weight: 600; padding: 2px 4px; }
.link:hover { text-decoration: underline; }
.layout-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.layout-grid .layout-btn { width: 100%; padding: 8px; background: var(--panel-2); }
.layout-grid .layout-btn .layout-icon { width: 100%; }
.layout-grid .layout-name { font-size: 12px; color: var(--muted); text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slots button { font-family: var(--mono); min-width: 34px; }
.slots button[aria-pressed="true"] { border-color: var(--accent); background: #4f8cff22; }
.transition select { width: auto; }
.transition input[type="range"] { width: 110px; }
.transition output { font: 12px var(--mono); color: var(--muted); min-width: 40px; }
.take { font-weight: 700; letter-spacing: .06em; text-transform: uppercase; padding: 12px 18px; min-width: 84px; }
.takes-group { display: flex; gap: 8px; margin-left: auto; }
.take.cut { background: #2a303c; }
.take.auto { background: var(--program); border-color: var(--program); color: #fff; }
.take:disabled { opacity: .4; }

/* Inspector */
.tabs { display: grid; grid-template-columns: repeat(6, 1fr); border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); z-index: 1; }
.tabs button { border: 0; border-radius: 0; background: none; padding: 10px 4px; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button[aria-selected="true"] { color: var(--fg); border-bottom-color: var(--accent); }
.tabpanel { padding: 12px; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px 12px; margin: 0 0 12px; }
legend { padding: 0 6px; font-weight: 600; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row2 > div { min-width: 0; }
.toggle { width: 100%; margin-top: 10px; font-weight: 600; }
.toggle[aria-pressed="true"] { background: var(--program); border-color: var(--program); color: #fff; }

.master, .strip { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.strips { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 8px; }
.strip-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; }
.strip-head strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.strip .controls { display: flex; gap: 6px; align-items: center; margin-top: 6px; }
.strip .controls button[aria-pressed="true"] { background: var(--program); border-color: var(--program); }
.meter { height: 8px; background: #0008; border-radius: 4px; overflow: hidden; margin: 4px 0 6px; }
.meter i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--preview) 0 70%, var(--warn) 70% 88%, var(--program) 88%); background-size: 100% 100%; }
.strip.closed .meter i { filter: grayscale(1) brightness(.6); }

.cam-details dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 8px 0 12px; }
.cam-details dt { color: var(--muted); }
.cam-details dd { margin: 0; font-variant-numeric: tabular-nums; }
.cam-details .actions { display: flex; flex-wrap: wrap; gap: 6px; }

.takes { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.takes li { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; display: grid; gap: 4px; }
.takes .take-name { font-family: var(--mono); font-size: 12px; overflow-wrap: anywhere; }
.takes a { color: var(--accent); }

.dests { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 8px; }
.dest { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; display: grid; gap: 6px; }
.dest[data-state="live"] { border-color: #ff3b4f88; }
.dest-head { display: flex; align-items: center; gap: 8px; min-width: 0; }
.dest-head label { flex: 1; min-width: 0; }
.dest-head strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dest .svc { font-size: 11px; }
.dest .state { font: 600 11px/1 var(--mono); padding: 3px 6px; border-radius: 3px; background: #0006; color: var(--muted); white-space: nowrap; }
.dest .state[data-state="live"] { background: var(--program); color: #fff; }
.dest .state[data-state="connecting"], .dest .state[data-state="retrying"] { background: var(--warn); color: #241600; }
.dest .state[data-state="error"] { background: #ff8a9633; color: #ff8a96; }
.dest .dest-msg { margin: 0; font-size: 12px; overflow-wrap: anywhere; }
.dest .dest-msg.error { color: #ff8a96; }
.dest .dest-actions { display: flex; gap: 6px; }
.dest .dest-actions button { padding: 4px 9px; font-size: 12px; }
#relayInfo.error { color: var(--warn); }

/* Dialogs */
dialog {
  background: var(--panel); color: var(--fg);
  border: 1px solid var(--line); border-radius: 12px;
  padding: 20px; width: min(440px, calc(100vw - 32px));
}
dialog::backdrop { background: #000a; }
dialog h2 { font-size: 18px; text-transform: none; letter-spacing: 0; color: var(--fg); margin: 0 0 10px; }
.steps { margin: 0 0 12px; padding-left: 18px; color: var(--muted); }
.steps li { margin: 4px 0; }
#qrImg { display: block; margin: 8px auto 12px; background: #fff; border-radius: 8px; padding: 8px; }
.url-row { display: flex; gap: 8px; align-items: center; }
.url-row code { flex: 1; min-width: 0; overflow-wrap: anywhere; font: 13px var(--mono); background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* Video clip sources */
.tile .clip-time { position: absolute; right: 6px; bottom: 8px; background: #000c; font-variant-numeric: tabular-nums; }
.clip-controls { display: grid; gap: 4px; margin-top: 4px; }
.clip-controls .actions { display: flex; gap: 6px; }
.clip-controls .actions button { flex: 1; }
.tile .loop-btn { position: absolute; left: 6px; bottom: 8px; padding: 3px 7px; font: 600 11px/1.2 var(--mono); background: #000c; border-color: #ffffff33; }
.tile .loop-btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.clip-controls .toggle-loop[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Audio */
.audio-head { margin-top: 14px; }
.loudness { display: flex; justify-content: space-between; align-items: baseline; margin-top: 6px; }
.loudness .big { font: 600 22px/1 var(--mono); font-variant-numeric: tabular-nums; }
.lufs-bar { position: relative; height: 6px; border-radius: 3px; background: #0008; margin: 6px 0 2px; overflow: visible; }
.lufs-bar i { display: block; height: 100%; width: 0; border-radius: 3px; background: var(--muted); }
.lufs-bar i.ok { background: var(--preview); }
.lufs-bar i.loud { background: var(--warn); }
.lufs-bar .target { position: absolute; top: -3px; width: 2px; height: 12px; background: #fff; left: calc((60 - 14) / 60 * 100%); }
.clip-led { font: 700 10px/1 var(--mono); background: var(--program); color: #fff; border-radius: 3px; padding: 3px 5px; }
.notice { background: #4f8cff1a; border: 1px solid #4f8cff55; border-radius: 6px; padding: 8px 10px; margin: 8px 0; display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.strip .gear { padding: 2px 8px; font-size: 16px; line-height: 1.2; }
.strip .gear[aria-expanded="true"] { border-color: var(--accent); }
.strip .advanced { display: grid; gap: 4px; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); }
.strip .advanced .row2 { align-items: end; }
.strip .tag { font: 600 10px/1 var(--mono); color: var(--muted); border: 1px solid var(--line); border-radius: 3px; padding: 2px 4px; margin-left: 6px; }
.strip .tag.warn { color: var(--warn); border-color: var(--warn); }
.device-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: end; }

/* Portrait (9:16) program preview beside Program */
.monitor-row.with-portrait { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; }
.monitor.portrait canvas { aspect-ratio: 9 / 16; width: auto; height: 240px; border-color: #ff3b4f88; }
.monitor.portrait figcaption { white-space: nowrap; }
.monitor .tag + .orient-label, .orient-label { font: 600 11px/1 var(--mono); color: var(--muted); border: 1px solid var(--line); border-radius: 3px; padding: 3px 5px; }
.dest .orient { display: inline-flex; gap: 4px; margin-left: auto; }
.dest .orient button { padding: 3px 6px; display: inline-flex; align-items: center; gap: 4px; font-size: 12px; }
.dest .orient button svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.dest .orient button[aria-pressed="true"] { border-color: var(--accent); background: #4f8cff2a; color: #fff; }
.dest .orient button:disabled { opacity: .5; }
.dest .orient button[aria-pressed="true"]:disabled { opacity: .85; }
.monitor.portrait .tag { background: var(--program); color: #fff; }

/* People: guest invites, waiting room, backstage and stage */
.tab-badge { display: inline-block; min-width: 16px; padding: 1px 4px; margin-left: 2px; border-radius: 8px; background: var(--warn); color: #241600; font: 700 10px/14px var(--mono); }
.people-options { display: grid; gap: 2px; margin: 10px 0; }
.people-section { margin-top: 14px; }
.people { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.person { display: grid; grid-template-columns: 84px 1fr; gap: 10px; align-items: start; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px; }
.person.waiting { grid-template-columns: 1fr; }
.person video { width: 84px; aspect-ratio: 16 / 9; object-fit: cover; background: #000; border-radius: 4px; transform: scaleX(-1); }
.person .who { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; min-width: 0; }
.person .who strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.person .tag { font: 600 10px/1 var(--mono); padding: 3px 5px; border-radius: 3px; background: #000a; color: var(--muted); border: 1px solid var(--line); }
.person .tag.stage { color: var(--preview); border-color: #1d5a39; }
.person .tag.live { background: var(--program); border-color: var(--program); color: #fff; }
.person .tag.warn { background: var(--warn); border-color: var(--warn); color: #241600; }
.person .actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.person .actions button { padding: 4px 8px; font-size: 12px; }
.person .actions .primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.person .actions .danger { color: #ffb3bc; }
