:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --border: #dfe3e8;
  --text: #1c2430;
  --muted: #6b7684;
  --accent: #2f6feb;
  --accent-soft: rgba(47, 111, 235, 0.16);
  --accent-text: #ffffff;
  --live: #1f9d55;
  --warn: #c2680a;
  --danger: #cc3b3b;
  --track: #e7eaee;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181d;
    --panel: #1c2128;
    --border: #2c333c;
    --text: #e4e8ee;
    --muted: #97a1ae;
    --accent: #4c8dff;
    --accent-soft: rgba(76, 141, 255, 0.22);
    --live: #39c07a;
    --warn: #e0a24a;
    --danger: #e86a6a;
    --track: #262d36;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

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

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

.topbar h1 { font-size: 16px; margin: 0; letter-spacing: -0.01em; }

.tabs { display: flex; gap: 4px; }

.tab {
  background: none;
  border: none;
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
}

.tab:hover { background: var(--bg); color: var(--text); }
.tab.active { background: var(--accent); color: var(--accent-text); }
/* Outranks the generic button:hover, which would paint accent text on the accent fill. */
.tab.active:hover { background: var(--accent); color: var(--accent-text); }

.zone {
  margin-left: auto;
  font-size: 12px;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 3px 8px;
  border-radius: 999px;
}

main { padding: 24px; max-width: 1180px; margin: 0 auto; }

@media (max-width: 640px) {
  .topbar { padding: 12px 16px; }
  .zone { margin-left: 0; }
  main { padding: 16px; }
  .view-head { flex-wrap: wrap; }
}

.view { display: none; }
.view.active { display: block; }

.view-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.view-head h2 { font-size: 15px; margin: 0; }
.view-head .primary { margin-left: auto; }

.hint { color: var(--muted); font-size: 12px; margin: 0; }

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

.row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.row + .row { margin-top: 12px; }
.row .grow { flex: 1; min-width: 200px; }

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
}

input, select {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 9px;
  min-width: 180px;
}

input:disabled { opacity: 0.6; cursor: not-allowed; }

button {
  font: inherit;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 12px;
  cursor: pointer;
}

button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
button:disabled { opacity: 0.5; cursor: default; }

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

button.primary:hover:not(:disabled) { opacity: 0.9; color: var(--accent-text); }
button.link { border: none; background: none; color: var(--accent); padding: 4px 6px; }
button.danger:hover:not(:disabled) { border-color: var(--danger); color: var(--danger); }

a.link {
  color: var(--accent);
  text-decoration: none;
  padding: 4px 6px;
  display: inline-block;
}

a.link:hover { text-decoration: underline; }

/* Wide tables scroll on their own instead of pushing the whole page sideways. */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
}

.grid {
  width: 100%;
  border-collapse: collapse;
}

.grid th, .grid td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.grid th { font-size: 12px; color: var(--muted); font-weight: 500; }
.grid tr:last-child td { border-bottom: none; }
.grid td.actions { text-align: right; }
.grid tr.clickable { cursor: pointer; }
.grid tr.clickable:hover td { background: var(--bg); }

.badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
}

.badge.live, .badge.ready { color: var(--live); border-color: var(--live); }
.badge.stale, .badge.building, .badge.queued { color: var(--warn); border-color: var(--warn); }
.badge.failed { color: var(--danger); border-color: var(--danger); }
.badge.recording { color: #fff; background: var(--live); border-color: var(--live); }
.badge.waiting_for_recording { color: var(--accent); border-color: var(--accent); }

.error-text { color: var(--danger); }

code.url {
  display: inline-block;
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
}

label.inline { flex-direction: row; align-items: center; gap: 8px; margin-left: auto; }
label.inline select { min-width: 160px; }

.empty { color: var(--muted); font-size: 13px; padding: 16px 2px; }

/* ---------------------------------------------------------------- timeline */

.timeline { user-select: none; }

.tl-track {
  position: relative;
  height: 64px;
  background: var(--track);
  border-radius: 8px;
  cursor: crosshair;
  overflow: hidden;
  touch-action: none;
}

.tl-coverage { position: absolute; inset: 0; }

.tl-block {
  position: absolute;
  top: 0;
  bottom: 0;
  background: linear-gradient(var(--accent), var(--accent));
  opacity: 0.45;
}

.tl-window {
  position: absolute;
  top: 0;
  bottom: 0;
  border-left: 1px dashed var(--muted);
  border-right: 1px dashed var(--muted);
  background: rgba(127, 127, 127, 0.12);
}

.tl-selection {
  position: absolute;
  top: 0;
  bottom: 0;
  background: var(--accent-soft);
  border-top: 2px solid var(--accent);
  border-bottom: 2px solid var(--accent);
}

/*
 * The two handles never overlap: the start handle's hit area sits entirely to the
 * left of its position and the end handle's entirely to the right. Centring both
 * would stack them on top of each other once the selection gets narrow, and
 * whichever came last in the DOM would silently win every grab.
 */
.tl-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 14px;
  cursor: ew-resize;
  background: var(--accent);
  opacity: 0.95;
}

.tl-handle[data-handle="start"] {
  margin-left: -14px;
  border-radius: 3px 0 0 3px;
}

.tl-handle[data-handle="end"] {
  border-radius: 0 3px 3px 0;
}

.tl-handle::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 2px;
  height: 20px;
  margin: -10px 0 0 -1px;
  background: var(--accent-text);
  opacity: 0.9;
}

.tl-handle:hover { opacity: 1; }

.tl-readout {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

.tl-readout .stamp { font-size: 14px; }
.tl-readout .arrow { color: var(--muted); }

.tl-readout .length {
  margin-left: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--accent);
}

.tl-playhead {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  margin-left: -1px;
  background: var(--text);
  pointer-events: none;
}

.tl-ticks {
  position: relative;
  height: 18px;
  margin-top: 6px;
}

.tl-tick {
  position: absolute;
  font-size: 11px;
  color: var(--muted);
  transform: translateX(-50%);
  white-space: nowrap;
}

/* ------------------------------------------------------------------ player */

#preview-body video {
  width: 100%;
  max-height: 460px;
  background: #000;
  border-radius: 8px;
  display: block;
}

.playhead {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin: 14px 0;
  flex-wrap: wrap;
}

.label { font-size: 12px; color: var(--muted); }

.stamp {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 15px;
  letter-spacing: -0.01em;
}

.stamp-field { flex: 0 0 auto; }

.stamp-input {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 14px;
  min-width: 230px;
}

#preview-body video { margin-top: 12px; }
#preview-body .timeline { margin: 12px 0 8px; }

.connection-grid {
  display: grid;
  grid-template-columns: max-content 1fr max-content;
  gap: 8px 12px;
  align-items: center;
  margin: 12px 0;
}

.connection-grid .stamp-input { width: 100%; min-width: 0; }

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 12px;
}

.marks { align-items: stretch; }

.mark {
  flex: 1;
  min-width: 320px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.mark-head { display: flex; align-items: center; gap: 10px; }
.mark-head button { margin-left: auto; font-size: 12px; padding: 4px 8px; }
.nudge { display: flex; gap: 4px; flex-wrap: wrap; }
.nudge button { font-size: 12px; padding: 4px 8px; }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 50;
  max-width: 80vw;
}

.toast.error { background: var(--danger); color: #fff; }

/* -------------------------------------------------------------------- login */

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.login-card {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-card h1 { font-size: 18px; margin: 0 0 4px; }
.login-card input { min-width: 0; width: 100%; }
#login-error { color: var(--danger); }

.user-badge { font-size: 12px; color: var(--muted); }

/* ------------------------------------------------------------------ dialogs */

.dialog {
  width: min(480px, calc(100vw - 32px));
  padding: 0;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}

.dialog.wide { width: min(760px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(10, 14, 20, 0.45); }

.dialog-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.dialog-head h3 { font-size: 15px; margin: 0; }
.dialog-head [data-close-dialog] { margin-left: auto; }

.dialog-body { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.dialog-body input { min-width: 0; }

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.dialog-section { padding: 14px 16px; }
.dialog-section + .dialog-section { border-top: 1px solid var(--border); }
.dialog-section h4 { font-size: 13px; margin: 0 0 10px; }
.dialog-section .connection-grid { margin-top: 0; }

.notice {
  margin: 12px 16px 0;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  background: var(--accent-soft);
}
