:root {
  --bg: #0e1116;
  --panel: #161b23;
  --panel2: #1d242f;
  --border: #2a3342;
  --text: #e8edf4;
  --dim: #8b97a8;
  --accent: #4f8ef7;
  --live: #e5484d;
  --ok: #46a758;
  --warn: #f5a524;
  --mark: #f5484d;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.brand {
  font-weight: 800;
  font-size: 18px;
  letter-spacing: 0.5px;
}
.brand span { color: var(--accent); }

.pills { display: flex; gap: 8px; }
.pill {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.4px;
}
.pill.live { background: var(--live); color: #fff; animation: pulse 1.6s infinite; }
.pill.waiting { background: var(--warn); color: #201500; }
.pill.neutral { background: var(--panel2); color: var(--dim); border: 1px solid var(--border); }

@keyframes pulse { 50% { opacity: 0.75; } }

.spacer { flex: 1; }

button {
  background: var(--panel2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
button:hover { border-color: var(--accent); }
button.ghost { background: transparent; color: var(--dim); }
button.mark { background: var(--mark); border-color: var(--mark); color: #fff; font-weight: 800; }
button.mark:hover { filter: brightness(1.15); }
button:disabled { opacity: 0.45; cursor: default; }

main {
  flex: 1;
  display: flex;
  min-height: 0;
}

.stage {
  flex: 1;
  display: flex;
  min-width: 0;
  padding: 12px;
}

.videoWrap {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #000;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

video { flex: 1; width: 100%; min-height: 0; background: #000; }

.videoOverlay {
  position: absolute;
  inset: 0 0 44px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 12, 16, 0.88);
  text-align: center;
}
.videoOverlay.hidden { display: none; }
.overlayMsg h2 { font-size: 18px; margin-bottom: 10px; }
.overlayMsg p { color: var(--dim); }
.overlayMsg code {
  display: inline-block;
  margin-top: 4px;
  padding: 2px 8px;
  background: var(--panel2);
  border-radius: 4px;
  color: var(--accent);
  font-size: 12px;
}

.transport {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--panel);
  border-top: 1px solid var(--border);
}
.timecode {
  font: 600 13px ui-monospace, "SF Mono", Menlo, monospace;
  color: var(--dim);
  min-width: 90px;
}

.queue {
  width: 330px;
  border-left: 1px solid var(--border);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.queueHead {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 12px 14px 8px;
}
.queueHead h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--dim); }
#clipCount { color: var(--dim); font-size: 12px; }

.clipList { flex: 1; overflow-y: auto; padding: 0 10px 10px; }

.clipCard {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 8px;
  background: var(--panel2);
  cursor: pointer;
}
.clipCard.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.clipTitle {
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text);
  font: 700 14px inherit;
  outline: none;
}
.clipTitle:focus { background: var(--bg); border-radius: 4px; }
.clipMeta {
  display: flex;
  gap: 8px;
  margin: 6px 0 8px;
  font: 12px ui-monospace, "SF Mono", Menlo, monospace;
  color: var(--dim);
}
.clipMeta .status { margin-left: auto; font-weight: 700; text-transform: uppercase; font-size: 10px; letter-spacing: 0.5px; }
.status.pending { color: var(--dim); }
.status.exporting { color: var(--warn); }
.status.done { color: var(--ok); }
.status.error { color: var(--live); }
.clipErr { color: var(--live); font-size: 11px; margin-bottom: 6px; }
.clipActions { display: flex; gap: 6px; }
.clipActions button { padding: 4px 9px; font-size: 12px; }
.clipActions a {
  display: inline-block;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 6px;
  background: var(--ok);
  color: #fff;
  text-decoration: none;
}

.empty { color: var(--dim); text-align: center; padding: 30px 10px; font-size: 13px; }

.statsBar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  padding: 6px 12px;
  background: var(--panel2);
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--dim);
}
.statsFilters { display: flex; flex-wrap: wrap; gap: 5px; }
.filterChip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 11px;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  text-transform: capitalize;
}
.filterChip .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.filterChip.off { opacity: 0.4; }
.filterChip.off .dot { background: var(--dim) !important; }
.statsPlayer {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 3px 6px;
  font: inherit;
  font-size: 12px;
}
.statsSummary { font-weight: 700; color: var(--text); white-space: nowrap; }
.statsSelInfo { color: var(--dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.statsBar button { padding: 4px 10px; font-size: 12px; }
#statsAlignBtn { background: var(--accent); border-color: var(--accent); color: #fff; }

.timelineWrap {
  height: 132px;
  border-top: 1px solid var(--border);
  background: var(--panel);
}
#timeline { width: 100%; height: 100%; display: block; cursor: crosshair; }

.hidden { display: none !important; }

/* ---------- views ---------- */

.view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.clipperView main { flex: 1; display: flex; min-height: 0; }

.userEmail { color: var(--dim); font-size: 12px; }
.headerEvent { display: flex; align-items: center; gap: 10px; font-weight: 700; }

button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.12); }

/* ---------- auth ---------- */

.authView { align-items: center; justify-content: center; }
.authCard {
  width: 320px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  text-align: center;
}
.authCard h1 { font-size: 26px; font-weight: 800; }
.authCard h1 span { color: var(--accent); }
.authCard p { color: var(--dim); margin: 6px 0 18px; font-size: 13px; }
.authCard form { display: flex; flex-direction: column; gap: 10px; }
.authCard input, .stackForm input, .stackForm select, .formRow input, .formRow select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 8px 10px;
  font: inherit;
}
.authCard input:focus { border-color: var(--accent); outline: none; }
.authError { color: var(--live); font-size: 13px; margin-top: 12px; min-height: 18px; }

/* ---------- events ---------- */

.eventsView { padding: 18px 22px; overflow-y: auto; }
.eventsToolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.eventsToolbar h2 { font-size: 18px; }
.eventGrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 14px;
}
.eventCard {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.eventTop { display: flex; align-items: center; gap: 10px; }
.eventTop h3 { font-size: 15px; flex: 1; }
.badge {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.5px;
}
.badge.live { background: var(--live); color: #fff; animation: pulse 1.6s infinite; }
.badge.scheduled { background: var(--panel2); color: var(--dim); border: 1px solid var(--border); }
.badge.ended { background: var(--panel2); color: var(--dim); }
.eventMeta { display: flex; gap: 10px; align-items: center; color: var(--dim); font-size: 12px; }
.chip {
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 11px;
  color: var(--dim);
}
.eventKey { display: flex; align-items: center; gap: 8px; min-width: 0; }
.eventKey code {
  flex: 1;
  background: var(--bg);
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 11px;
  color: var(--accent);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.eventKey .copyBtn { padding: 3px 8px; font-size: 11px; }
.eventActions { display: flex; gap: 8px; }
.eventActions button { font-size: 12px; padding: 5px 12px; }

/* ---------- users / forms ---------- */

.modalCard.wide { width: 540px; max-height: 80vh; overflow-y: auto; }
.modalCard h3 { font-size: 13px; margin: 14px 0 8px; color: var(--dim); }
.stackForm { display: flex; flex-direction: column; gap: 10px; }
.stackForm label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--dim); }
.formRow { display: flex; gap: 8px; justify-content: flex-end; align-items: center; }
.formRow input { flex: 1; min-width: 0; }
.userList { display: flex; flex-direction: column; gap: 10px; }
.userRow {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.userHead { display: flex; align-items: center; gap: 8px; }
.grantList { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--dim); }
.grantList label { display: flex; align-items: center; gap: 4px; cursor: pointer; }

.modalHint { color: var(--dim); font-size: 12px; margin-bottom: 12px; }

/* ---------- system status ---------- */

.statusHead { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.statusMeta { color: var(--dim); font-size: 12px; font-family: ui-monospace, Menlo, monospace; }
.statusBody { margin-top: 12px; }
.statusGrid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}
.meter {
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
}
.meterTop { display: flex; justify-content: space-between; font-size: 12px; font-weight: 700; }
.meterPct.ok { color: var(--ok); }
.meterPct.warn { color: var(--warn); }
.meterPct.bad { color: var(--live); }
.meterBar { height: 6px; background: var(--bg); border-radius: 999px; margin: 8px 0 6px; overflow: hidden; }
.meterFill { height: 100%; border-radius: 999px; transition: width 0.4s ease; }
.meterFill.ok { background: var(--ok); }
.meterFill.warn { background: var(--warn); }
.meterFill.bad { background: var(--live); }
.meterDetail { font-size: 11px; color: var(--dim); }

.statusCards { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; margin-top: 12px; }
.statusCard { background: var(--panel2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.statusCard h4 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--dim); margin-bottom: 8px; }
.kv { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; padding: 2px 0; }
.kv > span:first-child { color: var(--dim); }
.kvNote { font-size: 10px; color: var(--dim); margin-top: 6px; word-break: break-all; }
.good { color: var(--ok); font-weight: 600; }
.bad { color: var(--live); font-weight: 600; }
.dim { color: var(--dim); }

.statusSection { font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--dim); margin: 16px 0 6px; }
.statusTable { width: 100%; border-collapse: collapse; font-size: 12px; }
.statusTable th {
  text-align: left; font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--dim); font-weight: 600; padding: 4px 8px; border-bottom: 1px solid var(--border);
}
.statusTable td { padding: 5px 8px; border-bottom: 1px solid var(--border); }
.statusTable tr:last-child td { border-bottom: none; }

.updateBanner {
  background: rgba(79,142,247,0.12);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 10px 12px;
  margin-top: 12px;
  font-size: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.updateBanner a { color: var(--accent); }
.updateCmds { display: flex; flex-direction: column; gap: 3px; color: var(--dim); }
.updateCmds code {
  background: var(--bg);
  padding: 3px 7px;
  border-radius: 4px;
  color: var(--text);
  font-size: 11px;
  user-select: all;
}
.groupChip { background: rgba(79,142,247,0.18); border-color: transparent; color: var(--accent); }
.groupList { display: flex; flex-direction: column; gap: 14px; }
.groupRow {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.groupHead { display: flex; align-items: center; gap: 8px; }
.groupHead strong { flex: 1; font-size: 14px; }
.subLabel { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--dim); margin-top: 6px; }
.checkGrid { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--dim); }
.checkGrid label { display: flex; align-items: center; gap: 4px; cursor: pointer; color: var(--text); }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}
.modal.hidden { display: none; }
.modalCard {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 24px;
  width: 420px;
}
.modalCard h2 { font-size: 15px; margin-bottom: 12px; }
.modalCard table { width: 100%; border-collapse: collapse; margin-bottom: 14px; }
.modalCard td { padding: 4px 6px; color: var(--dim); font-size: 13px; }
.modalCard td:first-child { width: 90px; color: var(--text); }
kbd {
  background: var(--panel2);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 1px 6px;
  font: 600 11px ui-monospace, Menlo, monospace;
}
