:root {
  color-scheme: dark;
  --bg: #14161a;
  --panel: #1d2025;
  --panel-2: #23262c;
  --border: #33373f;
  --text: #e8eaee;
  --muted: #8b909c;
  --accent: #4da3ff;
  --good: #3ecf6f;
  --bad: #ff5c5c;
  --warn: #ffb84d;
}

* { 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;
}

/* ---------- Setup page ---------- */

.setup-wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

/* Operator View's cue table (and its Q Message field especially) benefits
   from much more horizontal room than Setup's forms need — this is meant
   to be used full-screen/prominently during a live show. */
.queue-wrap {
  max-width: none;
  padding-left: 32px;
  padding-right: 32px;
}

header.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

header.top h1 {
  font-size: 20px;
  margin: 0;
}

.status-row {
  display: flex;
  gap: 14px;
  align-items: center;
  font-size: 13px;
  color: var(--muted);
}

.dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--bad);
  margin-right: 6px;
}
.dot.on { background: var(--good); }
.dot.warn { background: var(--warn); }

.tc-readout {
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 22px;
  letter-spacing: 1px;
}
.tc-readout.disabled-readout { color: var(--muted); opacity: 0.5; }

.view-tabs {
  display: flex;
  gap: 2px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 2px;
}
.view-tab {
  padding: 4px 12px;
  border-radius: 5px;
  font-size: 13px;
  cursor: pointer;
  color: var(--muted);
}
.view-tab.active {
  background: var(--accent);
  color: #08111c;
  font-weight: 600;
  cursor: default;
}
.dot.dot-disabled { background: var(--border); }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
  margin-bottom: 18px;
}

.panel h2 {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 0 0 14px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 5px;
}

input[type="text"],
input[type="number"],
select {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 14px;
}

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  vertical-align: middle;
  margin-right: 6px;
}

.field { margin-bottom: 12px; }
.checkbox-field { display: flex; align-items: center; gap: 8px; }
.checkbox-field label { margin: 0; color: var(--text); font-size: 14px; flex: 1; }
.color-swatch {
  width: 32px;
  height: 24px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: none;
  cursor: pointer;
}

button {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #08111c; font-weight: 600; }
button.danger { border-color: var(--bad); color: var(--bad); }
button.small { padding: 5px 10px; font-size: 12px; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

table.cues {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.queue-table {
  min-width: 1150px;
  table-layout: fixed;
}
.queue-table td {
  overflow: hidden;
}
table.cues th {
  text-align: left;
  color: var(--muted);
  font-weight: 500;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
table.cues td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
table.cues tr.disabled { opacity: 0.45; }
table.cues tr.active-row { background: rgba(77,163,255,0.08); }
.tag {
  display: inline-block;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--muted);
  margin-right: 4px;
}

.inline-type {
  display: block;
  width: auto;
  font-size: 11px;
  padding: 2px 4px;
  margin-bottom: 4px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
}

.table-scroll { overflow-x: auto; }

.inline-tc-wrap { display: flex; align-items: center; gap: 4px; margin-right: 8px; }
input.inline-tc {
  width: 112px;
  box-sizing: border-box;
  flex-shrink: 0;
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 13px;
  padding: 5px 6px;
}
.tc-capture-btn {
  flex-shrink: 0;
  padding: 5px 6px;
  font-size: 12px;
  line-height: 1.4;
}
input.inline-field {
  width: 100%;
  min-width: 90px;
  box-sizing: border-box;
  font-size: 13px;
  padding: 5px 7px;
  background: transparent;
  border: 1px solid transparent;
}
input.inline-field:hover { border-color: var(--border); }
input.inline-field:focus { background: var(--panel-2); border-color: var(--accent); }
.inline-offset {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 228px;
}
.inline-offset select {
  width: 84px;
  flex-shrink: 0;
  padding: 4px 5px;
  font-size: 12px;
}
.inline-offset input[type="number"] {
  width: 42px;
  padding: 4px 5px;
  font-size: 12px;
}
.inline-offset-unit {
  color: var(--muted);
  font-size: 12px;
  margin-right: 2px;
}
.inline-duration {
  display: flex;
  align-items: center;
  gap: 6px;
}
input.inline-duration-num {
  width: 52px;
  padding: 4px 5px;
  font-size: 12px;
}
.inline-slider-unit {
  color: var(--muted);
  font-size: 12px;
}
.muted { color: var(--muted); }

/* ---------- Spreadsheet-styled cue table (colors sampled from the
   Cue_List_Dark.xlsx template) — shared by Setup's cue table and the
   Operator View queue. ---------- */
table.cues-styled th:nth-child(1) { background: #3B82F6; color: #0B0D10; border-radius: 4px 4px 0 0; }
table.cues-styled th:nth-child(2),
table.cues-styled th:nth-child(3) { background: #A78BFA; color: #0B0D10; }
table.cues-styled th:nth-child(4) { background: #FB923C; color: #0B0D10; }
table.cues-styled th:nth-child(5) { background: #34D399; color: #0B0D10; }
table.cues-styled th:nth-child(6) { background: #F472B6; color: #0B0D10; }
table.cues-styled th { font-weight: 700; }
table.cues-styled tbody tr:nth-child(odd) td { background: #1F2229; }
table.cues-styled tbody tr:nth-child(even) td { background: #262A33; }
table.cues-styled tr.active-row td { background: rgba(77,163,255,0.18) !important; }
table.cues-styled tr.disabled td { opacity: 0.45; }

/* Live validation highlighting, matching the spreadsheet's colour key */
td.cell-dup-tc { background: #713F12 !important; color: #FDE68A; }
td.cell-missing-message { background: #7F1D1D !important; }
td.cell-offset-negative .inline-offset input,
td.cell-offset-negative .inline-offset select { color: #FECACA; }
td.cell-offset-positive .inline-offset input,
td.cell-offset-positive .inline-offset select { color: #A7F3D0; }
td.cell-duration-set .inline-duration-num { color: #6EE7B7; }
td.badge-action .inline-type { background: #9A3412; color: #FFEDD5; border-color: #9A3412; }
td.badge-info .inline-type { background: #1E3A8A; color: #DBEAFE; border-color: #1E3A8A; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 22px;
  width: 560px;
  max-width: 92vw;
  max-height: 88vh;
  overflow-y: auto;
}
.modal h2 { margin-top: 0; }
textarea {
  width: 100%;
  min-height: 90px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
}
.hidden { display: none !important; }
.help { font-size: 12px; color: var(--muted); margin-top: 4px; }

.sim-controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.sim-controls input[type="text"] { width: 140px; }

/* ---------- Operator layout editor (mini preview on Setup page) ---------- */

.layout-preview-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 16px;
}
.layout-preview {
  position: relative;
  width: 100%;
  max-width: 560px;
  aspect-ratio: 16 / 9;
  background: #000;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.layout-chip {
  position: absolute;
  transform: translate(-50%, -50%);
  cursor: grab;
  touch-action: none;
  user-select: none;
  white-space: nowrap;
}
.layout-chip:active { cursor: grabbing; }
.layout-chip-text {
  color: #fff;
  font-weight: 700;
  padding: 2px 6px;
  border: 1px dashed rgba(255,255,255,0.3);
  border-radius: 4px;
}
.layout-chip-countdown {
  color: #9a9a9a;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  padding: 2px 6px;
  border: 1px dashed rgba(255,255,255,0.3);
  border-radius: 4px;
}
.layout-chip-progress {
  height: 10px;
  background: linear-gradient(90deg, #4da3ff, #3ecf6f);
  border-radius: 999px;
  border: 1px dashed rgba(255,255,255,0.5);
}
.layout-chip-timecode {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  padding: 2px 6px;
  border: 1px dashed rgba(255,255,255,0.3);
  border-radius: 4px;
}
.layout-chip-text.bg-on, .layout-chip-countdown.bg-on {
  /* background-color set inline via JS to match the chosen color */
  border-radius: 6px;
}
.layout-chip-timecode.chip-disabled { opacity: 0.35; }

/* ---------- Operator page ---------- */

html.operator, body.operator {
  height: 100%;
  background: #000;
  overflow: hidden;
}
.op-wrap {
  position: relative;
  height: 100vh;
  width: 100vw;
  text-align: center;
}
/* Position/size are set via JS as inline CSS variables, from Setup page
   settings — these are just sane fallbacks if that hasn't happened yet. */
.op-text {
  position: absolute;
  left: var(--text-x, 50%);
  top: var(--text-y, 50%);
  max-width: 90vw;
  width: max-content;
  transform: translate(-50%, -50%);
  color: #fff;
  font-weight: 700;
  line-height: 1.15;
  white-space: pre-wrap;
  font-size: var(--text-size, 8vw);
  transition: transform 0.45s ease, opacity 0.35s ease;
}
.op-text.pending { color: #7a7a7a; opacity: 0.85; }
.op-countdown {
  position: absolute;
  left: var(--countdown-x, 90%);
  top: var(--countdown-y, 85%);
  transform: translate(-50%, -50%);
  color: #7a7a7a;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: var(--countdown-size, 4vw);
}
.op-empty { color: #222; font-size: 3vw; }

/* Standalone timecode readout — independent of any cue, toggled on/off
   from the Setup page, always ticking while shown. */
.op-timecode {
  position: absolute;
  left: var(--timecode-x, 50%);
  top: var(--timecode-y, 8%);
  transform: translate(-50%, -50%);
  color: var(--timecode-color, #fff);
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: var(--timecode-size, 3vw);
}

/* Optional plain background fill behind cue text / countdown — no border,
   independently toggleable per element, with a chosen color (Setup page). */
.op-text.op-bg {
  background: var(--text-bg-color, #3c3c3c);
  border-radius: 14px;
  padding: 0.35em 0.9em;
}
.op-countdown.op-bg {
  background: var(--countdown-bg-color, #3c3c3c);
  border-radius: 10px;
  padding: 0.2em 0.5em;
}

/* Cue text slide in/out (Setup page toggle + direction). These come after
   .op-text.pending so they win the opacity/transform tie-break without
   needing !important. */
.op-text.op-slide-off-left { transform: translate(-50%, -50%) translateX(-130vw); opacity: 0; }
.op-text.op-slide-off-right { transform: translate(-50%, -50%) translateX(130vw); opacity: 0; }
.op-text.op-slide-jump { transition: none; }

.op-progress-wrap {
  position: absolute;
  left: var(--progress-x, 50%);
  top: var(--progress-y, 93%);
  width: var(--progress-width, 84%);
  height: var(--progress-height, 1.4vh);
  transform: translate(-50%, -50%);
  background: #1c1c1c;
  border: 1px solid #333;
  border-radius: 999px;
  overflow: hidden;
}
.op-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #4da3ff, #3ecf6f);
}

/* Explicit fullscreen control — browsers require a real click on this
   page (not a remote trigger from Setup) to grant fullscreen, so this is
   the one bit of "UI" the otherwise-clean Operator output needs. Fades
   out on idle so it doesn't sit on top of the live display. */
.op-fullscreen-btn {
  position: fixed;
  bottom: 16px;
  left: 16px;
  z-index: 10;
  background: rgba(20, 20, 20, 0.75);
  color: #ccc;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  opacity: 0.85;
  transition: opacity 0.4s ease;
}
.op-fullscreen-btn:hover { opacity: 1; border-color: rgba(255, 255, 255, 0.5); }
.op-fullscreen-btn.idle { opacity: 0; pointer-events: none; }
