/* =========================================================================
   BMD — operations console
   Hand-written, no framework: the whole file is served from the same box that
   renders the pages, and an ARM free-tier instance should not be shipping a
   200 KB utility bundle to draw twelve screens.

   Structure:
     1. tokens      2. reset      3. layout/shell   4. typography
     5. surfaces    6. data       7. status         8. pipeline
     9. forms      10. feed      11. utilities     12. responsive
   ========================================================================= */

/* ---------- 1. tokens --------------------------------------------------- */
:root {
  /* Surfaces are layered rather than outlined: each step up is a lighter
     plane, so depth reads without heavy borders everywhere. */
  --bg:          #0b0e14;
  --surface-1:   #111721;
  --surface-2:   #161d29;
  --surface-3:   #1d2532;
  --line:        #232c3b;
  --line-strong: #2f3a4d;

  --text:        #e8edf7;
  --text-dim:    #97a3b8;
  --text-faint:  #64708a;

  --accent:      #5b8dfb;
  --accent-soft: rgba(91, 141, 251, .14);
  --ok:          #3fbf72;
  --ok-soft:     rgba(63, 191, 114, .13);
  --warn:        #e0a33a;
  --warn-soft:   rgba(224, 163, 58, .13);
  --bad:         #f0564f;
  --bad-soft:    rgba(240, 86, 79, .13);
  --idle:        #6b7590;

  /* One 4px rhythm for everything, so unrelated components still line up. */
  --s1: 4px;  --s2: 8px;  --s3: 12px; --s4: 16px;
  --s5: 24px; --s6: 32px; --s7: 48px;

  --r-sm: 6px; --r-md: 10px; --r-lg: 14px;

  --shadow-sm: 0 1px 2px rgba(0,0,0,.28);
  --shadow-md: 0 4px 16px rgba(0,0,0,.34);
  --shadow-lg: 0 12px 40px rgba(0,0,0,.46);

  --sidebar-w: 216px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
          system-ui, sans-serif;
  --mono: "JetBrains Mono", "Cascadia Mono", ui-monospace, Consolas, monospace;

  color-scheme: dark;
}

/* ---------- 2. reset ---------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--accent); text-decoration: none; transition: color .12s ease; }
a:hover { color: #86aefc; }

img { max-width: 100%; }
[hidden] { display: none !important; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--line-strong); border-radius: 5px;
  border: 2px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover { background: #3d4a61; }

/* ---------- 3. layout / shell ------------------------------------------ */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  position: fixed; inset: 0 auto 0 0;
  width: var(--sidebar-w);
  display: flex; flex-direction: column;
  background: var(--surface-1);
  border-right: 1px solid var(--line);
  padding-top: env(safe-area-inset-top, 0px);
  z-index: 40;
}

.brand {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s5) var(--s4) var(--s4);
  color: var(--text);
  font-size: 15px; font-weight: 650; letter-spacing: -.01em;
}
.brand:hover { color: var(--text); }
.brand-mark {
  width: 30px; height: 30px; flex: none;
  display: grid; place-items: center;
  border-radius: 8px;
  background: linear-gradient(140deg, var(--accent), #8b5cf6);
  font-size: 15px;
  box-shadow: 0 2px 10px rgba(91,141,251,.36);
}
.brand small {
  display: block; font-size: 11px; font-weight: 500;
  color: var(--text-faint); letter-spacing: .02em;
}

.nav { flex: 1; padding: var(--s2) var(--s3); overflow-y: auto; }
.nav-group {
  margin: var(--s4) 0 var(--s2);
  padding: 0 var(--s2);
  font-size: 10px; font-weight: 700; letter-spacing: .1em;
  text-transform: uppercase; color: var(--text-faint);
}
.nav-group:first-child { margin-top: var(--s2); }

.nav a {
  display: flex; align-items: center; gap: var(--s3);
  padding: 8px var(--s3);
  margin-bottom: 2px;
  border-radius: var(--r-sm);
  color: var(--text-dim); font-weight: 500;
  transition: background .12s ease, color .12s ease;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.on {
  background: var(--accent-soft); color: #a7c4ff; font-weight: 600;
  box-shadow: inset 2px 0 0 var(--accent);
}
.nav-icon { width: 16px; text-align: center; font-size: 14px; flex: none; }
.nav-count {
  margin-left: auto;
  min-width: 20px; padding: 1px 6px;
  border-radius: 20px;
  background: var(--bad); color: #fff;
  font-size: 10px; font-weight: 700; text-align: center;
  font-variant-numeric: tabular-nums;
}
.nav a.on .nav-count { background: var(--accent); }

.sidebar-foot {
  padding: var(--s3) var(--s4);
  padding-bottom: calc(var(--s3) + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line);
  font-size: 11px; color: var(--text-faint);
}
.sidebar-foot .row { justify-content: space-between; }

.main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: var(--s4);
  padding: var(--s4) var(--s5);
  padding-top: calc(var(--s4) + env(safe-area-inset-top, 0px));
  background: rgba(11,14,20,.86);
  backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { margin: 0; font-size: 18px; font-weight: 650; letter-spacing: -.015em; }
.topbar .sub { font-size: 12px; color: var(--text-faint); margin-top: 1px; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: var(--s2); }

.content { padding: var(--s5); max-width: 1680px; }

/* mobile sidebar toggle, hidden on desktop */
.nav-toggle { display: none; }

/* ---------- 4. typography ---------------------------------------------- */
h2 { font-size: 15px; font-weight: 640; margin: 0 0 var(--s3); letter-spacing: -.01em; }
h3 {
  font-size: 10px; font-weight: 700; letter-spacing: .1em;
  text-transform: uppercase; color: var(--text-faint);
  margin: 0 0 var(--s3);
}
.mono { font-family: var(--mono); font-size: 12px; }
.num  { font-variant-numeric: tabular-nums; text-align: right; }
.muted { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.small { font-size: 12px; }
.tiny  { font-size: 11px; }
.strong { font-weight: 620; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- 5. surfaces ------------------------------------------------- */
.panel {
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--s4) var(--s5) var(--s5);
  margin-bottom: var(--s4);
}
.panel-head {
  display: flex; align-items: center; gap: var(--s3);
  margin: 0 0 var(--s4);
}
.panel-head h2 { margin: 0; }
.panel-head .spacer { margin-left: auto; }
.panel-flush { padding-left: 0; padding-right: 0; }
.panel-flush .panel-head,
.panel-flush > p { padding-left: var(--s5); padding-right: var(--s5); }

.grid { display: grid; gap: var(--s4); }
.g2 { grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); }
.g3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.g4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.row { display: flex; gap: var(--s2); align-items: center; flex-wrap: wrap; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); }
.stack { display: flex; flex-direction: column; gap: var(--s2); }

/* --- metric tiles --- */
.metric {
  position: relative; overflow: hidden;
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--s4);
  transition: border-color .15s ease, transform .15s ease;
}
.metric:hover { border-color: var(--line-strong); }
.metric::before {
  content: ""; position: absolute; inset: 0 auto 0 0; width: 3px;
  background: var(--idle);
}
.metric.is-ok::before   { background: var(--ok); }
.metric.is-warn::before { background: var(--warn); }
.metric.is-bad::before  { background: var(--bad); }
.metric.is-accent::before { background: var(--accent); }

.metric .k {
  font-size: 10px; font-weight: 700; letter-spacing: .09em;
  text-transform: uppercase; color: var(--text-faint);
}
.metric .v {
  margin-top: var(--s2);
  font-size: 28px; font-weight: 660; line-height: 1.1;
  letter-spacing: -.02em; font-variant-numeric: tabular-nums;
}
.metric .v .unit { font-size: 15px; font-weight: 500; color: var(--text-faint); }
.metric .s { margin-top: var(--s1); font-size: 12px; color: var(--text-dim); }
.metric.is-ok .v   { color: var(--ok); }
.metric.is-warn .v { color: var(--warn); }
.metric.is-bad .v  { color: var(--bad); }

/* ---------- 6. data ----------------------------------------------------- */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  position: sticky; top: 0;
  padding: var(--s2) var(--s3);
  background: var(--surface-1);
  color: var(--text-faint);
  font-size: 10px; font-weight: 700; letter-spacing: .09em;
  text-transform: uppercase; text-align: left; white-space: nowrap;
  border-bottom: 1px solid var(--line);
}
tbody td {
  padding: 10px var(--s3);
  border-bottom: 1px solid rgba(35,44,59,.6);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background .1s ease; }
tbody tr:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.empty {
  padding: var(--s6) var(--s4);
  text-align: center; color: var(--text-faint);
}
.empty-icon { font-size: 26px; opacity: .45; display: block; margin-bottom: var(--s2); }
.empty-title { color: var(--text-dim); font-weight: 550; margin-bottom: 2px; }

/* --- progress bars --- */
.bar {
  height: 6px; border-radius: 3px;
  background: var(--surface-3); overflow: hidden;
}
.bar > i {
  display: block; height: 100%; border-radius: 3px;
  background: var(--accent);
  transition: width .4s cubic-bezier(.4,0,.2,1);
}
.bar.ok   > i { background: var(--ok); }
.bar.warn > i { background: var(--warn); }
.bar.bad  > i { background: var(--bad); }

/* ---------- 7. status --------------------------------------------------- */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 20px;
  background: var(--surface-3); color: var(--text-dim);
  font-size: 11px; font-weight: 600; white-space: nowrap;
}
.pill.ok     { background: var(--ok-soft);     color: var(--ok); }
.pill.warn   { background: var(--warn-soft);   color: var(--warn); }
.pill.bad    { background: var(--bad-soft);    color: var(--bad); }
.pill.info   { background: var(--accent-soft); color: var(--accent); }
.pill::before {
  content: ""; width: 5px; height: 5px; border-radius: 50%;
  background: currentColor; flex: none;
}
.pill.plain::before { display: none; }

.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--idle); flex: none; }
.dot.live { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.dot.live::after {
  content: ""; display: block; width: 100%; height: 100%;
  border-radius: 50%; background: var(--ok);
  animation: pulse 2s ease-out infinite;
}
@keyframes pulse {
  0%   { transform: scale(1);   opacity: .7; }
  100% { transform: scale(3.2); opacity: 0; }
}

/* ---------- 8. pipeline / board ---------------------------------------- */
.board {
  display: flex; gap: var(--s3);
  overflow-x: auto; padding-bottom: var(--s4);
  scroll-snap-type: x proximity;
}
.col {
  flex: 0 0 252px; scroll-snap-align: start;
  display: flex; flex-direction: column;
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  max-height: calc(100vh - 210px);
}
.col-head {
  display: flex; align-items: center; gap: var(--s2);
  padding: var(--s3) var(--s3) var(--s2);
  border-bottom: 1px solid var(--line);
}
.col-head .name {
  font-size: 11px; font-weight: 700; letter-spacing: .07em;
  text-transform: uppercase; color: var(--text-dim);
}
.col-head .count {
  margin-left: auto; min-width: 20px; padding: 1px 7px;
  border-radius: 20px; background: var(--surface-3);
  font-size: 11px; font-weight: 700; color: var(--text-dim);
  text-align: center; font-variant-numeric: tabular-nums;
}
.col-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--idle); }
.col-body { padding: var(--s2); overflow-y: auto; flex: 1; }

.card {
  display: block;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: var(--s3);
  margin-bottom: var(--s2);
  color: var(--text);
  transition: transform .12s ease, border-color .12s ease, box-shadow .12s ease;
}
.card:hover {
  color: var(--text); transform: translateY(-1px);
  border-color: var(--line-strong); box-shadow: var(--shadow-md);
}
.card-top { display: flex; align-items: center; gap: var(--s2); margin-bottom: 6px; }
.card-id { font-family: var(--mono); font-size: 10px; color: var(--text-faint); }
.card .t {
  font-size: 12.5px; font-weight: 560; line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-meta {
  display: flex; gap: var(--s3); flex-wrap: wrap;
  margin-top: var(--s2); font-size: 11px; color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}
.card-err {
  margin-top: 6px; padding: 5px 7px;
  background: var(--bad-soft); border-radius: var(--r-sm);
  font-size: 11px; color: var(--bad);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.card-note {
  margin-top: 6px; font-size: 11px; color: var(--ok); font-weight: 550;
}

/* --- stage strip --- */
.steps { display: flex; gap: 3px; flex-wrap: wrap; }
.step {
  flex: 1 1 74px; min-width: 74px;
  padding: 7px 6px; border-radius: var(--r-sm);
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 10.5px; font-weight: 550; text-align: center;
  color: var(--text-faint);
  position: relative;
}
.step.done { border-color: rgba(63,191,114,.4); color: var(--ok); background: var(--ok-soft); }
.step.now  {
  border-color: var(--accent); color: #a7c4ff; background: var(--accent-soft);
  box-shadow: 0 0 0 1px var(--accent) inset;
}
.step.bad  { border-color: rgba(240,86,79,.4); color: var(--bad); background: var(--bad-soft); }

/* ---------- 9. forms / buttons ----------------------------------------- */
button, .btn {
  display: inline-flex; align-items: center; gap: 6px;
  font: inherit; font-size: 13px; font-weight: 550;
  padding: 7px 13px; border-radius: var(--r-sm);
  border: 1px solid var(--line-strong);
  background: var(--surface-2); color: var(--text);
  cursor: pointer; white-space: nowrap;
  transition: background .12s ease, border-color .12s ease, transform .08s ease;
}
button:hover, .btn:hover {
  background: var(--surface-3); border-color: #3d4a61; color: var(--text);
}
button:active, .btn:active { transform: translateY(1px); }
button:disabled { opacity: .45; cursor: not-allowed; transform: none; }

.btn-primary, button.primary {
  background: var(--accent); border-color: var(--accent); color: #fff;
  box-shadow: 0 1px 6px rgba(91,141,251,.3);
}
.btn-primary:hover, button.primary:hover {
  background: #6f9bfc; border-color: #6f9bfc; color: #fff;
}
.btn-ok, button.ok { background: var(--ok); border-color: var(--ok); color: #05210f; }
.btn-ok:hover, button.ok:hover { background: #4fd183; border-color: #4fd183; color: #05210f; }
.btn-danger, button.danger {
  background: var(--bad-soft); border-color: rgba(240,86,79,.45); color: var(--bad);
}
.btn-danger:hover, button.danger:hover { background: rgba(240,86,79,.22); color: #ff7a74; }
button.ghost, .btn.ghost { background: transparent; border-color: var(--line); }
.btn-sm { padding: 4px 9px; font-size: 12px; }

input[type=text], input[type=password], input[type=url], textarea, select {
  font: inherit; width: 100%;
  padding: 8px 11px; border-radius: var(--r-sm);
  border: 1px solid var(--line-strong);
  background: var(--bg); color: var(--text);
  transition: border-color .12s ease, box-shadow .12s ease;
}
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input::placeholder { color: var(--text-faint); }
textarea { font-family: var(--mono); font-size: 12.5px; line-height: 1.6; resize: vertical; }

label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 5px; }
.field { margin-bottom: var(--s4); }
.check {
  display: inline-flex; align-items: center; gap: 7px;
  margin: 0; cursor: pointer; color: var(--text); font-size: 13px;
}
.check input { width: auto; accent-color: var(--accent); }

pre {
  background: var(--bg); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: var(--s3) var(--s4);
  overflow-x: auto; font-family: var(--mono); font-size: 12px; line-height: 1.6;
  white-space: pre-wrap; word-break: break-word; color: var(--text-dim);
  margin: 0;
}

/* ---------- 10. live feed ---------------------------------------------- */
.feed {
  font-family: var(--mono); font-size: 11.5px;
  max-height: 380px; overflow-y: auto;
}
.feed-row {
  display: flex; gap: var(--s3); align-items: baseline;
  padding: 5px var(--s2);
  border-radius: var(--r-sm);
  border-left: 2px solid transparent;
  animation: slidein .25s ease;
}
.feed-row:hover { background: var(--surface-2); }
.feed-row time { color: var(--text-faint); flex: 0 0 54px; }
.feed-row .src {
  color: var(--accent); flex: 0 0 70px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.feed-row .msg { flex: 1; min-width: 0; color: var(--text-dim); }
.feed-row.warn  { border-left-color: var(--warn); }
.feed-row.warn .msg  { color: var(--warn); }
.feed-row.error { border-left-color: var(--bad); background: rgba(240,86,79,.05); }
.feed-row.error .msg { color: var(--bad); }
@keyframes slidein { from { opacity: 0; transform: translateY(-3px); } }

/* ---------- console (bottom-right notifications) ------------------------ */
#console {
  position: fixed; right: var(--s5); bottom: var(--s5); z-index: 100;
  display: flex; flex-direction: column; align-items: flex-end;
  gap: var(--s2);
  max-width: 400px;
}
#console[hidden] { display: none !important; }

.console-bar {
  display: flex; align-items: center; gap: var(--s2);
  padding: 4px 6px 4px var(--s3);
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: 20px;
  font-size: 11px; color: var(--text-dim);
  box-shadow: var(--shadow-md);
}
.console-bar button {
  padding: 2px 7px; font-size: 11px; line-height: 1.4;
  border-radius: 12px; border-color: transparent;
  background: transparent; color: var(--text-faint);
}
.console-bar button:hover { background: var(--surface-3); color: var(--text); }
.console-bar .count {
  min-width: 17px; padding: 0 5px; border-radius: 10px;
  background: var(--bad); color: #fff;
  font-size: 10px; font-weight: 700; text-align: center;
}

.toast {
  display: flex; gap: var(--s3); align-items: flex-start; width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-left: 3px solid var(--accent);
  border-radius: var(--r-md);
  padding: var(--s3) var(--s3) var(--s3) var(--s4);
  font-size: 12.5px;
  box-shadow: var(--shadow-lg);
  animation: toastin .28s cubic-bezier(.2,.9,.3,1);
}
.toast.warn  { border-left-color: var(--warn); }
.toast.error { border-left-color: var(--bad); }
.toast .ti { flex: none; }
.toast .tbody { flex: 1; min-width: 0; word-break: break-word; }
.toast .tx {
  flex: none; padding: 0 5px; margin: -2px -2px 0 0;
  border: none; background: transparent;
  color: var(--text-faint); font-size: 14px; line-height: 1;
  border-radius: var(--r-sm);
}
.toast .tx:hover { background: var(--surface-3); color: var(--text); }
@keyframes toastin { from { opacity: 0; transform: translateX(24px); } }

/* When muted, a single dot is left so the console can be brought back. */
#console-restore {
  position: fixed; right: var(--s5); bottom: var(--s5); z-index: 99;
  width: 34px; height: 34px; padding: 0;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--surface-2); border: 1px solid var(--line-strong);
  color: var(--text-faint); font-size: 14px;
  box-shadow: var(--shadow-md);
}
#console-restore:hover { color: var(--text); border-color: var(--accent); }
#console-restore[hidden] { display: none !important; }

/* ---------- 10b. library gallery + player ------------------------------ */
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--s4);
}

.tile {
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  overflow: hidden;
  transition: border-color .15s ease, transform .15s ease, box-shadow .15s ease;
}
.tile:hover {
  border-color: var(--line-strong);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.tile-media {
  position: relative;
  aspect-ratio: 16 / 9;
  background: var(--surface-3);
  overflow: hidden;
}
.tile-media img {
  width: 100%; height: 100%; object-fit: cover; display: block;
  transition: transform .3s cubic-bezier(.3,0,.2,1);
}
.tile:hover .tile-media img { transform: scale(1.04); }
.tile-noimg {
  width: 100%; height: 100%;
  display: grid; place-items: center;
  font-size: 34px; opacity: .25;
}

.tile-play {
  position: absolute; inset: 0; margin: auto;
  width: 54px; height: 54px; padding: 0;
  display: grid; place-items: center;
  border: none; border-radius: 50%;
  background: rgba(11,14,20,.72);
  backdrop-filter: blur(4px);
  color: #fff; font-size: 17px; line-height: 1;
  opacity: 0; transform: scale(.85);
  transition: opacity .16s ease, transform .16s ease, background .16s ease;
}
.tile:hover .tile-play,
.tile-play:focus-visible { opacity: 1; transform: scale(1); }
.tile-play:hover { background: var(--accent); }

.tile-dur {
  position: absolute; right: 8px; bottom: 8px;
  padding: 2px 6px; border-radius: 4px;
  background: rgba(11,14,20,.85);
  font-family: var(--mono); font-size: 11px; color: #fff;
  font-variant-numeric: tabular-nums;
}
.tile-badge { position: absolute; left: 8px; top: 8px; }

.tile-body { padding: var(--s3); }
.tile-title {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
  color: var(--text); font-size: 13px; font-weight: 560; line-height: 1.4;
}
.tile-title:hover { color: var(--accent); text-decoration: none; }
.tile-meta {
  display: flex; flex-wrap: wrap; gap: var(--s3);
  margin-top: 6px; font-size: 11px; color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}
.tile-meta .ok-text { color: var(--ok); }
.tile-actions {
  display: flex; gap: 6px; align-items: center;
  margin-top: var(--s3); padding-top: var(--s3);
  border-top: 1px solid var(--line);
}
.tile-actions .btn:last-child { margin-left: auto; }

/* --- modal player --- */
.viewer { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; }
.viewer-backdrop {
  position: absolute; inset: 0;
  background: rgba(5,7,11,.82);
  backdrop-filter: blur(6px);
  animation: fadein .18s ease;
}
.viewer-box {
  position: relative;
  width: min(1180px, 94vw);
  background: var(--surface-1);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  animation: popin .2s cubic-bezier(.2,.9,.3,1);
}
.viewer-head {
  display: flex; align-items: center; gap: var(--s2);
  padding: var(--s3) var(--s4);
  border-bottom: 1px solid var(--line);
}
.viewer-title {
  flex: 1; min-width: 0;
  font-weight: 580; font-size: 14px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.viewer-box video {
  display: block; width: 100%;
  max-height: min(72vh, 660px);
  background: #000;
}
@keyframes fadein { from { opacity: 0; } }
@keyframes popin  { from { opacity: 0; transform: scale(.97) translateY(6px); } }

/* --- inline player on the detail page --- */
.player {
  width: 100%; display: block;
  max-height: 60vh; background: #000;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
}

/* ---------- 11. utilities ---------------------------------------------- */
.thumb {
  border-radius: var(--r-md); border: 1px solid var(--line);
  display: block; box-shadow: var(--shadow-sm);
}
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px var(--s4); font-size: 13px; }
.kv dt { color: var(--text-dim); }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

.banner {
  display: flex; gap: var(--s3); align-items: flex-start;
  padding: var(--s3) var(--s4);
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: var(--surface-2);
  margin-bottom: var(--s4); font-size: 13px;
}
.banner.warn { border-color: rgba(224,163,58,.35); background: var(--warn-soft); }
.banner.bad  { border-color: rgba(240,86,79,.35);  background: var(--bad-soft); }
.banner.ok   { border-color: rgba(63,191,114,.35); background: var(--ok-soft); }
.banner .bi { font-size: 16px; flex: none; line-height: 1.4; }
.banner strong { display: block; margin-bottom: 2px; }

.tag-list { display: flex; flex-wrap: wrap; gap: 5px; }

/* ---------- 11b. discovery feed ---------------------------------------- */
/* Cards are portrait because the clips are. A 16:9 tile would letterbox every
   vertical thumbnail into a strip too small to judge, and judging at a glance
   is the entire job of this page. */
.clip-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(205px, 1fr));
  gap: var(--s4);
}

.clip-card {
  display: flex;
  flex-direction: column;
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  overflow: hidden;
  transition: border-color .15s ease, transform .15s ease, box-shadow .15s ease;
}
.clip-card:hover {
  border-color: var(--line-strong);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.clip-thumb {
  position: relative;
  display: block;
  aspect-ratio: 3 / 4;
  background: var(--surface-3);
  overflow: hidden;
}
.clip-thumb img {
  width: 100%; height: 100%; object-fit: cover; display: block;
  transition: transform .3s cubic-bezier(.3,0,.2,1);
}
.clip-card:hover .clip-thumb img { transform: scale(1.04); }
.clip-thumb-empty {
  display: flex; align-items: center; justify-content: center;
  height: 100%; font-size: 28px; font-weight: 700;
  color: var(--text-faint); letter-spacing: 2px;
}

/* The score is the one number worth reading from across the room. */
.clip-score {
  position: absolute; top: 8px; left: 8px;
  min-width: 26px; padding: 3px 7px;
  border-radius: var(--r-sm);
  background: rgba(11,14,20,.82);
  border: 1px solid var(--line-strong);
  font-size: 12px; font-weight: 700; text-align: center;
  color: var(--text-dim);
  backdrop-filter: blur(4px);
}
.clip-score.hot { color: #fff; background: rgba(240,86,79,.88); border-color: transparent; }

.clip-dur {
  position: absolute; right: 8px; bottom: 8px;
  padding: 2px 6px; border-radius: var(--r-sm);
  background: rgba(11,14,20,.82);
  font-size: 11px; font-variant-numeric: tabular-nums; color: var(--text-dim);
}

.clip-body {
  display: flex; flex-direction: column; gap: 6px;
  padding: var(--s3); flex: 1;
}
.clip-title {
  margin: 0; font-size: 13px; line-height: 1.35; font-weight: 600;
  /* Two lines, then ellipsis: titles on these platforms run to 300 characters
     and an unclamped one would push every card to a different height. */
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.clip-meta { display: flex; align-items: center; gap: 6px; font-size: 11px; }
.clip-stats { display: flex; flex-wrap: wrap; gap: 8px; color: var(--text-faint); }
.clip-actions {
  display: flex; align-items: center; gap: 6px;
  margin-top: auto; padding-top: var(--s2);
}
/* The hand-picked excerpt, folded away unless one is set. A card is already
   dense, and the field is used on the few clips you watched, not on all of
   them - but when it is set, it has to be visible without a click. */
.clip-excerpt { border-top: 1px solid var(--surface-3); padding-top: 6px; }
.clip-excerpt summary {
  cursor: pointer; color: var(--text-dim); list-style: none;
}
.clip-excerpt summary::-webkit-details-marker { display: none; }
.clip-excerpt summary:hover { color: var(--text); }
.clip-excerpt input { padding: 4px 6px; font-size: 12px; }

/* ---------- 11d. live refresh ------------------------------------------ */
/* The switch in the top bar. Off is a real choice: on a slow connection, or
   while reading a long page, a region swapping under the cursor is worse than
   pressing refresh. */
.live-toggle {
  font-size: 12px; color: var(--text-dim); gap: 6px;
  padding: 4px 9px; border-radius: var(--r-sm); background: var(--surface-2);
}
.live-toggle:hover { color: var(--text); }

/* ---------- 11c. toolbars and tabs ------------------------------------- */
.toolbar {
  display: flex; align-items: center; gap: var(--s3);
  margin-bottom: var(--s4); flex-wrap: wrap;
}
.tabs { display: flex; gap: 2px; background: var(--surface-2);
        padding: 3px; border-radius: var(--r-md); flex-wrap: wrap; }
.tab {
  padding: 5px 11px; border-radius: var(--r-sm);
  font-size: 13px; color: var(--text-dim); text-decoration: none;
  display: inline-flex; align-items: center; gap: 6px;
  transition: background .12s ease, color .12s ease;
}
.tab:hover { color: var(--text); background: var(--surface-3); }
.tab.on { background: var(--accent); color: #fff; }
.tab-count {
  font-size: 11px; padding: 0 5px; border-radius: 8px;
  background: rgba(255,255,255,.14); font-variant-numeric: tabular-nums;
}
.tab.on .tab-count { background: rgba(0,0,0,.22); }

select.compact, input.compact {
  padding: 5px 9px; font-size: 13px; width: auto;
}
.row.wrap { flex-wrap: wrap; }

/* ---------- 12. responsive --------------------------------------------- */
@media (max-width: 960px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform .22s cubic-bezier(.4,0,.2,1);
    box-shadow: var(--shadow-lg);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open::after {
    content: ""; position: fixed; inset: 0; z-index: 35;
    background: rgba(0,0,0,.55);
  }
  .main { margin-left: 0; }
  .nav-toggle { display: inline-flex; }
  .content { padding: var(--s4); }
  .topbar { padding: var(--s3) var(--s4); }
  #toasts { right: var(--s3); left: var(--s3); bottom: var(--s3); max-width: none; }
}

@media (max-width: 560px) {
  .col { flex-basis: 84vw; }
  .metric .v { font-size: 24px; }
  .content { padding: var(--s3); }
  /* Two across rather than one: at this width a single-column feed of
     portrait cards is one clip per screen, which is unusable for scanning. */
  .clip-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .clip-actions { flex-direction: column; align-items: stretch; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}

/* =========================================================================
   13. Clipping: campaigns, moments, payouts
   ========================================================================= */
.table-wrap { overflow-x: auto; }
tr.on td { background: var(--accent-soft); }
.timeline {
  position: relative; height: 8px; border-radius: 4px;
  background: var(--surface-3); overflow: hidden;
}
.timeline i {
  position: absolute; top: 0; bottom: 0; min-width: 3px;
  background: var(--accent); border-radius: 4px;
}
.moment .panel-head h2 { flex: 1 1 auto; min-width: 0; }
.halt-form { display: inline-flex; }
