:root {
  --bg: #0f1115;
  --bg-1: #16191f;
  --bg-2: #1d2129;
  --bg-3: #262b35;
  --line: #2e3440;
  --text: #e6e9ef;
  --muted: #8b93a3;
  --accent: #5b8def;
  --accent-2: #3fb27f;
  --danger: #e0574b;
  --warn: #dfa02c;

  --q-pristine: #a97bf0;
  --q-excellent: #3fb27f;
  --q-good: #41b6c4;
  --q-fair: #dfa02c;
  --q-poor: #e0574b;

  --rail: 260px;
  --topbar: 52px;
}

* { box-sizing: border-box; }

/*
 * Several elements below are toggled with the `hidden` attribute while also
 * carrying an explicit `display` (grid/flex). Author rules beat the UA
 * `[hidden]` rule regardless of specificity, so without this they stay laid out
 * and keep intercepting clicks while "hidden".
 */
[hidden] { display: none !important; }

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

button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.spacer { flex: 1; }
.tc { font-variant-numeric: tabular-nums; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* ------------------------------- controls -------------------------------- */

button {
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 11px;
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
button:hover:not(:disabled) { background: #303643; border-color: #3d4450; }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover:not(:disabled) { background: #6d9bf5; }
button.primary.alt { background: var(--accent-2); border-color: var(--accent-2); }
button.primary.alt:hover:not(:disabled) { background: #4dc48f; }
button.ghost { background: transparent; }
button.ghost:hover:not(:disabled) { background: var(--bg-3); }
button.danger { color: var(--danger); border-color: #4a2a28; }
button.danger:hover:not(:disabled) { background: #35211f; }
/* Anchor styled as a button (downloads must stay real links). */
a.btnlink {
  display: inline-block;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 11px;
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
a.btnlink:hover { background: var(--bg-3); border-color: #3d4450; }

button.linklike {
  background: none; border: none; color: var(--accent);
  padding: 0; text-decoration: underline; cursor: pointer;
}

input, select, textarea {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 9px;
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; }
select { cursor: pointer; }

label { display: block; font-size: 12px; color: var(--muted); }
label input, label select, label textarea { margin-top: 4px; color: var(--text); }

.inline-check {
  display: inline-flex; align-items: center; gap: 6px;
  white-space: nowrap; font-size: 12px; color: var(--muted);
}
.inline-check input { width: auto; margin: 0; }

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

.login-screen {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  background: radial-gradient(1200px 600px at 50% -10%, #1b2130, var(--bg));
}
.login-card {
  width: 340px; padding: 26px;
  background: var(--bg-1); border: 1px solid var(--line); border-radius: 12px;
  display: grid; gap: 14px;
  box-shadow: 0 24px 60px rgba(0,0,0,.5);
}
.login-card h1 { margin: 0; font-size: 22px; letter-spacing: -.2px; }
.login-card p { margin: -6px 0 4px; font-size: 13px; }
.login-error { color: var(--danger); font-size: 13px; }

/* -------------------------------- layout --------------------------------- */

#app {
  display: grid;
  grid-template-columns: 1fr var(--rail);
  grid-template-rows: var(--topbar) 1fr;
  grid-template-areas: "top top" "main rail";
  height: 100%;
}

.topbar {
  grid-area: top;
  display: flex; align-items: center; gap: 14px;
  padding: 0 14px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: -.2px; }
.tabs { display: flex; gap: 4px; }
.tab { background: transparent; border-color: transparent; color: var(--muted); }
.tab.active { background: var(--bg-3); color: var(--text); border-color: var(--line); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.topbar-right select { width: auto; min-width: 150px; max-width: 240px; }
#new-dataset { padding: 6px 10px; }

.presence { display: flex; gap: -6px; }
.avatar {
  width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 11px; font-weight: 700; color: #0d0f13;
  border: 2px solid var(--bg-1); margin-left: -6px;
  cursor: default;
}
.me { font-size: 12px; color: var(--muted); }

main { grid-area: main; overflow: auto; position: relative; }
.view { padding: 14px; }
.view#view-editor { padding: 0; height: 100%; }

.rail {
  grid-area: rail;
  background: var(--bg-1);
  border-left: 1px solid var(--line);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.rail-section { padding: 12px; border-bottom: 1px solid var(--line); }
.rail-section.grow { flex: 1; overflow: auto; }
.rail-section h3 {
  margin: 0 0 8px; font-size: 11px; text-transform: uppercase;
  letter-spacing: .08em; color: var(--muted);
}
.rail-presence { display: grid; gap: 7px; }
.rail-person { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.rail-person .what { color: var(--muted); font-size: 11px; margin-left: auto; text-align: right; }
.rail-activity { display: grid; gap: 6px; font-size: 12px; }
.act { color: var(--muted); }
.act b { color: var(--text); font-weight: 600; }
.act.chat { color: var(--text); }
.chat-form input { background: var(--bg-2); }

/* -------------------------------- browse --------------------------------- */

.browse-bar {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 12px; flex-wrap: wrap;
}
.browse-bar select { width: auto; min-width: 140px; }
.browse-bar input[type="search"], .browse-bar input { width: 240px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}
.card {
  background: var(--bg-1); border: 1px solid var(--line); border-radius: 9px;
  overflow: hidden; cursor: pointer; position: relative;
  transition: border-color .12s, transform .12s;
}
.card:hover { border-color: var(--accent); transform: translateY(-2px); }
.card .thumb {
  width: 100%; aspect-ratio: 2/3; object-fit: cover;
  background: var(--bg-2); display: block;
}
.card .meta { padding: 8px 9px; }
.card .name {
  font-size: 13px; font-weight: 600;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card .sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.card .badges { position: absolute; top: 6px; left: 6px; right: 6px; display: flex; gap: 4px; flex-wrap: wrap; }
.card .clip-count {
  position: absolute; bottom: 6px; right: 6px;
  background: rgba(12,14,18,.85); border: 1px solid var(--line);
  border-radius: 20px; padding: 1px 7px; font-size: 11px;
}
.browse-more { display: grid; place-items: center; padding: 16px; }

/* Full-width rows inside the card grid: show header and season dividers. */
.show-head {
  grid-column: 1 / -1;
  display: flex; align-items: center; gap: 14px;
  padding: 2px 0 6px;
}
.show-title { font-size: 17px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.season-head {
  grid-column: 1 / -1;
  display: flex; align-items: baseline; gap: 10px;
  margin: 10px 0 -2px;
  padding-bottom: 5px;
  border-bottom: 1px solid var(--line);
  font-size: 13px; font-weight: 600;
}
.epcode { color: var(--accent); font-variant-numeric: tabular-nums; }

.qbadge {
  font-size: 10px; font-weight: 700; letter-spacing: .03em;
  padding: 2px 6px; border-radius: 20px;
  background: rgba(12,14,18,.86); border: 1px solid currentColor;
  text-transform: uppercase;
}
.q-pristine { color: var(--q-pristine); }
.q-excellent { color: var(--q-excellent); }
.q-good { color: var(--q-good); }
.q-fair { color: var(--q-fair); }
.q-poor { color: var(--q-poor); }
.tag-chip {
  font-size: 10px; padding: 1px 6px; border-radius: 20px;
  background: rgba(12,14,18,.8); border: 1px solid var(--line); color: var(--muted);
}

/* -------------------------------- editor --------------------------------- */

.editor-empty { display: grid; place-items: center; height: 100%; color: var(--muted); }
.editor { display: grid; grid-template-columns: 1fr 340px; height: 100%; overflow: hidden; }
/* overflow-y:auto rather than hidden so the transport and timelines stay
   reachable if the window is ever too short to fit them. */
.editor-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden auto; }

/*
 * The stage absorbs whatever height is left over, and clips: a video element
 * keeps its own intrinsic height even when its container is squeezed, so without
 * overflow:hidden it paints straight over the timelines below it.
 */
.stage {
  flex: 1 1 auto;
  min-height: 120px;
  background: #000;
  position: relative;
  overflow: hidden;
}
/* Absolute fill so the video tracks the stage box exactly, never overflowing. */
.stage video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  display: block;
}
.buffering {
  position: absolute; top: 10px; left: 12px;
  background: rgba(0,0,0,.7); border-radius: 5px; padding: 3px 9px;
  font-size: 12px; color: var(--muted);
}

/* Controls and timelines keep their natural height; the stage gives way instead. */
.transport {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; background: var(--bg-1); border-top: 1px solid var(--line);
  flex-wrap: wrap;
  flex: 0 0 auto;
}
.transport button { padding: 5px 10px; }
.transport select { width: auto; }
.tc-group { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--muted); }
.tc-group #tc-current { font-size: 14px; color: var(--text); }
.tc-group.in-out b { color: var(--text); }

.timelines {
  background: var(--bg-1); border-top: 1px solid var(--line); padding: 8px 12px 10px;
  flex: 0 0 auto;
}
.timelines canvas { display: block; width: 100%; cursor: crosshair; border-radius: 6px; background: var(--bg-2); }
#tl-overview { margin-bottom: 6px; }
.tl-tools {
  display: flex; align-items: center; gap: 14px; margin-top: 8px;
  font-size: 12px; color: var(--muted); flex-wrap: wrap;
}
.tl-tools label { display: flex; align-items: center; gap: 7px; }
.tl-tools input[type="range"] { width: 150px; }
.legend { display: inline-flex; align-items: center; gap: 5px; }
.sw { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
.sw.mine { background: var(--accent); }
.sw.theirs { background: #c05fc9; }
.sw.cut { background: var(--warn); }

.editor-side {
  border-left: 1px solid var(--line); background: var(--bg-1);
  overflow: auto; padding: 12px; display: grid; gap: 12px;
  align-content: start;
}
.src-head .src-title { font-weight: 700; font-size: 15px; }
.src-head .src-sub { font-size: 12px; margin-top: 2px; }

.quality-card {
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 9px; padding: 10px;
}
.quality-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.quality-head .label { font-weight: 700; }
.qmeter { height: 6px; border-radius: 4px; background: var(--bg-3); overflow: hidden; }
.qmeter i { display: block; height: 100%; border-radius: 4px; }
.qnotes { margin: 8px 0 0; padding-left: 16px; font-size: 11px; color: var(--muted); }
.qnotes li { margin: 2px 0; }

.panel {
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 9px; padding: 12px; display: grid; gap: 10px;
}
.panel h3 { margin: 0; font-size: 13px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions button { flex: 1; min-width: 90px; }

.preset-note { font-size: 11px; color: var(--muted); }
.warn {
  background: #34281a; border: 1px solid #5a4425; color: #f0c579;
  border-radius: 7px; padding: 8px; font-size: 12px;
}
.warn b { color: #ffdca5; }

.tag-suggest { display: flex; gap: 5px; flex-wrap: wrap; margin-top: -4px; }
.tag-suggest button { padding: 1px 8px; font-size: 11px; border-radius: 20px; color: var(--muted); }

.comments { display: grid; gap: 7px; max-height: 220px; overflow: auto; }
.comment { font-size: 12px; }
.comment .who { font-weight: 600; }
.comment-form { display: flex; gap: 6px; }

/* ------------------------------ clip list -------------------------------- */

.clip-list { display: grid; gap: 8px; }
.clip-row {
  display: grid; grid-template-columns: 128px 1fr auto;
  gap: 12px; align-items: center;
  background: var(--bg-1); border: 1px solid var(--line);
  border-radius: 9px; padding: 8px;
}
.clip-row:hover { border-color: #39414f; }
.clip-row .shot {
  width: 128px; aspect-ratio: 16/9; object-fit: cover;
  border-radius: 6px; background: var(--bg-2); cursor: pointer;
}
.clip-row .cap { font-size: 13px; }
.clip-row .cap.empty { color: var(--muted); font-style: italic; }
.clip-meta { font-size: 11px; color: var(--muted); margin-top: 3px; display: flex; gap: 10px; flex-wrap: wrap; }
.clip-actions { display: flex; gap: 6px; align-items: center; }
.status-pill {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  padding: 2px 7px; border-radius: 20px; border: 1px solid currentColor;
}
.st-draft { color: var(--muted); }
.st-ready { color: var(--accent); }
.st-approved { color: var(--accent-2); }
.st-rejected { color: var(--danger); }
.lock-pill { font-size: 10px; padding: 2px 7px; border-radius: 20px; background: var(--bg-3); }

/* -------------------------------- jobs ----------------------------------- */

.job-list { display: grid; gap: 8px; }
.job-row {
  background: var(--bg-1); border: 1px solid var(--line);
  border-radius: 9px; padding: 10px;
  display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center;
}
.job-title { font-size: 13px; }
.job-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.bar { height: 5px; background: var(--bg-3); border-radius: 4px; overflow: hidden; margin-top: 7px; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 4px; transition: width .3s; }
.job-row.done .bar i { background: var(--accent-2); }
.job-row.failed .bar i { background: var(--danger); }
.job-err { color: var(--danger); font-size: 11px; margin-top: 5px; word-break: break-word; }

/* ------------------------------- toasts ---------------------------------- */

.toasts {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  display: grid; gap: 8px; z-index: 50; pointer-events: none;
}
.toast {
  background: var(--bg-3); border: 1px solid var(--line);
  border-radius: 8px; padding: 9px 14px; font-size: 13px;
  box-shadow: 0 10px 30px rgba(0,0,0,.45);
  animation: rise .18s ease-out;
}
.toast.err { border-color: #5a2f2b; color: #f3b0a9; }
.toast.ok { border-color: #2c5443; color: #a7e6c8; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

@media (max-width: 1100px) {
  #app { grid-template-columns: 1fr; grid-template-areas: "top" "main"; }
  .rail { display: none; }
  .editor { grid-template-columns: 1fr; }
  .editor-side { border-left: none; border-top: 1px solid var(--line); }
}
