:root {
  color-scheme: dark;
  --bg: #0e1116;
  --panel: #161b22;
  --panel-2: #1c2230;
  --line: #2a3140;
  --text: #e6edf3;
  --muted: #8b98a9;
  --accent: #3fb950;
  --warn: #d29922;
  --err: #f85149;
  --idle: #6e7681;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.bar h1 { font-size: 15px; margin: 0; letter-spacing: .02em; }
.bar .meta { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.spacer { flex: 1 1 auto; }

.field { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }

select, .btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 10px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
select:hover, .btn:hover { border-color: #3d4658; background: #232b3b; }
.btn:active { transform: translateY(1px); }
.btn.small { padding: 3px 8px; font-size: 11px; }
.btn.on { border-color: var(--accent); color: var(--accent); }

.grid {
  display: grid;
  grid-template-columns: repeat(var(--cols, auto-fill), minmax(var(--min, 300px), 1fr));
  gap: 12px;
  padding: 16px;
}

.tile {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  outline: none;
}
.tile:focus-visible { border-color: var(--accent); }
.tile[hidden] { display: none; }

.stage {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #000;
  display: grid;
  place-items: center;
}
.stage img, .stage video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}
.stage video { display: none; }
.tile.live-on .stage video { display: block; }
.tile.live-on .stage img { visibility: hidden; }

.badge {
  position: absolute;
  top: 6px;
  left: 6px;
  font-size: 10px;
  letter-spacing: .08em;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(0,0,0,.6);
  color: var(--muted);
  pointer-events: none;
}
.tile.live-on .badge { color: #fff; background: rgba(248,81,73,.85); }

.overlay-msg {
  position: relative;
  z-index: 2;
  padding: 8px 12px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  max-width: 90%;
  background: rgba(0,0,0,.55);
  border-radius: 6px;
}
.overlay-msg:empty { display: none; }
.overlay-msg.error { color: var(--err); }

.tile-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-top: 1px solid var(--line);
}
.tile-bar .name { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }

.tag {
  --hue: 210;
  flex: 0 0 auto;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .04em;
  padding: 1px 6px;
  border-radius: 999px;
  color: hsl(var(--hue) 75% 74%);
  background: hsl(var(--hue) 45% 18%);
  border: 1px solid hsl(var(--hue) 40% 32%);
  white-space: nowrap;
}
.tag:empty { display: none; }
.tag[data-model]::after { content: ''; }

.dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--idle);
  flex: 0 0 auto;
}
.dot.live { background: var(--accent); box-shadow: 0 0 6px var(--accent); }
.dot.starting { background: var(--warn); }
.dot.error { background: var(--err); }

.note {
  margin: 0 16px 24px;
  padding: 12px 14px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 12px;
}

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.88);
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
}
.lightbox[hidden] { display: none; }
.lightbox-inner {
  width: min(1400px, 100%);
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
.lightbox-bar, .playback-panel, .lightbox-status { flex: 0 0 auto; }
.lightbox-bar { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.lightbox-status { padding: 8px 14px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); min-height: 32px; }

@media (max-width: 640px) {
  .grid { --min: 100%; padding: 10px; }
  .bar { gap: 8px; }
  .bar h1 { width: 100%; }
}


/* ---------------------------------------------------------- spinner ---- */
.spinner {
  position: absolute;
  width: 26px;
  height: 26px;
  border: 2px solid rgba(255,255,255,.18);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  z-index: 3;
  pointer-events: none;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2.4s; }
}

/* ------------------------------------------------------- lightbox ------ */
.viewer {
  position: relative;
  display: grid;
  place-items: center;
  background: #000;
  flex: 1 1 auto;
  min-height: 0;
}
/* Cap the height so the transport controls stay on screen on short displays. */
#lightbox-video {
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: calc(100vh - 260px);
  object-fit: contain;
  background: #000;
  display: block;
}

.tabs { display: inline-flex; gap: 2px; margin-left: 6px; }
.tab {
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--line);
  padding: 4px 12px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.tab:first-child { border-radius: 6px 0 0 6px; }
.tab:last-child { border-radius: 0 6px 6px 0; }
.tab.on { color: var(--text); background: #263041; border-color: #3d4658; }
.tab:disabled { opacity: .4; cursor: not-allowed; }

/* ------------------------------------------------------- playback ------ */
.playback-panel { padding: 10px 14px 14px; border-top: 1px solid var(--line); }
.playback-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.playback-controls input[type=date] {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; font: inherit; font-size: 12px;
}
.pb-clock { font-variant-numeric: tabular-nums; font-size: 13px; color: var(--text); }

.timeline {
  position: relative;
  height: 34px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: crosshair;
  overflow: hidden;
}
.tl-track { position: absolute; inset: 0 0 12px 0; }
.tl-seg {
  position: absolute;
  top: 4px;
  bottom: 4px;
  background: linear-gradient(180deg, #2f6f45, #285c3a);
  border-radius: 2px;
  min-width: 1px;
}
.tl-cursor {
  position: absolute;
  top: 0; bottom: 12px;
  width: 2px;
  background: var(--err);
  box-shadow: 0 0 6px var(--err);
  pointer-events: none;
}
.tl-hours {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 12px;
  display: grid;
  grid-template-columns: repeat(24, 1fr);
  font-size: 8px;
  color: var(--muted);
  pointer-events: none;
}
.tl-hours span { border-left: 1px solid var(--line); padding-left: 2px; line-height: 12px; }
.pb-summary { margin-top: 8px; font-size: 11px; color: var(--muted); }
