:root {
  --bg: #0e1015;
  --panel: #171a21;
  --panel-2: #1e222b;
  --line: #262b34;
  --line-strong: #333a46;
  --text: #e8ebf1;
  --muted: #8b93a3;
  --faint: #5c6474;
  --accent: #5b8cff;
  --accent-soft: rgba(91, 140, 255, .14);
  --ok: #3fb950;
  --warn: #d29922;
  --bad: #f85149;
  --radius: 9px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  display: flex;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 13.5px/1.55 ui-sans-serif, system-ui, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ---------- nav ---------- */
.nav {
  width: 220px;
  flex: 0 0 220px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -.01em;
  padding: 4px 8px 20px;
  display: flex;
  flex-direction: column;
}
.brand span {
  font-weight: 400;
  font-size: 11px;
  letter-spacing: .02em;
  color: var(--faint);
  margin-top: 4px;
}
.navitem {
  background: none;
  border: 0;
  color: var(--muted);
  text-align: left;
  padding: 9px 11px;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
  font-weight: 500;
  transition: background .12s ease, color .12s ease;
}
.navitem:hover { background: var(--panel-2); color: var(--text); }
.navitem.active { background: var(--accent-soft); color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }

/* domain group: a parent row that expands to a sub-menu of screens */
.navgroup { display: flex; flex-direction: column; gap: 2px; }
.navdomain {
  background: none; border: 0; color: var(--text); text-align: left;
  padding: 9px 11px; border-radius: 6px; cursor: pointer; font: inherit; font-weight: 640;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.navdomain:hover { background: var(--panel-2); }
.navdomain::after { content: "▸"; color: var(--faint); font-size: 10px; transition: transform .12s ease; }
.navdomain.expanded::after { transform: rotate(90deg); }
.navsub {
  display: flex; flex-direction: column; gap: 2px;
  margin: 2px 0 6px 10px; padding-left: 8px; border-left: 1px solid var(--line);
}
.navsub.collapsed { display: none; }
.navsub .navitem { padding: 6px 11px; font-size: 12px; font-weight: 500; }

.navnone { font-size: 11px; color: var(--faint); font-style: italic; padding: 4px 11px; }

.navfoot { margin-top: auto; }
.conn { font-size: 11px; color: var(--faint); padding: 8px; word-break: break-all; }
.conn.bad { color: var(--bad); }
.conn.ok { color: var(--ok); }

/* ---------- layout ---------- */
/* full content width — tables and text use all the space to the right */
.main { flex: 1; padding: 30px 34px; min-width: 0; }
h1 { font-size: 21px; font-weight: 700; letter-spacing: -.02em; margin: 0 0 5px; }
h2 { font-size: 14px; font-weight: 620; letter-spacing: -.01em; margin: 0 0 12px; }
/* design rule 6: the page description is a FIXED 2-line block (full width, long
   text clamps with …) so every page's table starts at the same vertical spot. */
.sub {
  color: var(--muted);
  margin: 0 0 24px;
  line-height: 1.55;
  min-height: 3.1em;                 /* always reserve 2 lines */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 20px;
}

/* signature: accent eyebrow-tick so each section reads as its own instrument panel */
.card h2 { display: inline-flex; align-items: center; gap: 9px; }
.card h2::before {
  content: "";
  flex: 0 0 auto;
  width: 3px;
  height: 15px;
  border-radius: 2px;
  background: var(--accent);
}
.hint { color: var(--muted); font-size: 12px; line-height: 1.5; margin: 2px 0 16px; max-width: 78ch; }
.hint .mono, .sub .mono, .cardhint .mono { color: var(--text); }

/* design rule 6: fixed-height in-card hint slot — one line, full width, present
   on every card (blank when a page has nothing to say) so the table below always
   starts at the same Y across pages. Longer text clamps rather than pushing down. */
.cardhint {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  min-height: 1.5em;
  margin: 0 0 14px;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ---------- banner ---------- */
.banner {
  border-radius: var(--radius);
  padding: 13px 15px;
  margin-bottom: 20px;
  border: 1px solid var(--warn);
  background: rgba(210, 153, 34, .09);
  font-size: 13px;
}
.banner.bad { border-color: var(--bad); background: rgba(248, 81, 73, .09); }
.banner pre {
  margin: 10px 0 0;
  padding: 11px 12px;
  background: #0a0c10;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow-x: auto;
  font-size: 12px;
  color: #c9d1d9;
}
.hidden { display: none !important; }

/* ---------- table ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
/* design rule 5: every data cell is ONE size, and never wraps (a wrapped cell
   makes rows different heights across pages). Long text ellipsizes via the
   per-column max-width; it does not wrap. */
td { font-size: 12.5px; white-space: nowrap; height: 42px; }
td.mono, td .mono { font-size: 12.5px; }
/* design rule 4: filler rows keep the box a constant 10-row height */
tr.filler td { color: transparent; }
tr.filler:hover td { background: none; }
th {
  color: var(--faint);
  font-weight: 600;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .07em;
  padding-top: 6px;
  padding-bottom: 8px;
}
tbody tr, table tr { transition: background .1s ease; }
td:first-child, th:first-child { padding-left: 4px; }
td:last-child, th:last-child { padding-right: 4px; }
tr:last-child td { border-bottom: 0; }
.tablewrap { overflow-x: auto; margin: 0 -4px; }

/* clickable audit rows (Activity) get a hover cue */
.actrow:hover td { background: var(--panel-2); }

/* pager: page-of-N + prev/next under a paginated table */
.pager { display: flex; justify-content: space-between; align-items: center; gap: 14px; margin-top: 14px; }
.pager .btn { padding: 6px 13px; }

/* ---------- links ---------- */
a { color: var(--accent); text-decoration: none; font-weight: 500; }
a:hover { text-decoration: underline; }

/* ---------- tags: three deliberate roles ---------- */
/* 1 · neutral metadata — recedes (read-only, post, ai_answer, async, last 100) */
.tag {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 5px;
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: .01em;
  background: var(--panel-2);
  border: 1px solid transparent;
  color: var(--faint);
  vertical-align: middle;
}
/* 2 · status — tinted, carries state */
.tag.on   { color: var(--ok);   background: rgba(63, 185, 80, .12);  border-color: rgba(63, 185, 80, .28); }
.tag.warn { color: var(--warn); background: rgba(210, 153, 34, .12); border-color: rgba(210, 153, 34, .3); }
.tag.off  { color: var(--faint); }

/* 3 · live count — a numeric badge that pops */
.count {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  background: var(--panel-2);
  color: var(--muted);
  vertical-align: middle;
}
.count.live { background: var(--accent); color: #fff; }

.mono { font-family: ui-monospace, "Cascadia Code", "SF Mono", Consolas, monospace; font-size: 12px; }
.mono.id { color: var(--text); }

/* ---------- buttons ---------- */
button.btn {
  background: var(--accent);
  border: 1px solid var(--accent);
  color: #fff;
  padding: 8px 15px;
  border-radius: 7px;
  cursor: pointer;
  font: inherit;
  font-weight: 550;
  transition: filter .12s ease, background .12s ease, border-color .12s ease;
}
button.btn:hover { filter: brightness(1.08); }
button.btn.ghost { background: transparent; border-color: var(--line-strong); color: var(--text); }
button.btn.ghost:hover { background: var(--panel-2); filter: none; }
button.btn.danger { background: transparent; border-color: rgba(248, 81, 73, .5); color: var(--bad); }
button.btn.danger:hover { background: rgba(248, 81, 73, .1); filter: none; }
button.btn:disabled { opacity: .4; cursor: not-allowed; filter: none; }
.row { display: flex; gap: 9px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 14px; margin-bottom: 12px; }
.spread h2 { margin-bottom: 0; }

/* ---------- form fields ---------- */
label.field { display: flex; flex-direction: column; gap: 5px; font-size: 11.5px; font-weight: 500; color: var(--muted); min-width: 150px; }
input[type=text], input[type=number], input[type=date], select {
  background: var(--panel-2);
  border: 1px solid var(--line-strong);
  color: var(--text);
  border-radius: 7px;
  padding: 8px 10px;
  font: inherit;
  transition: border-color .12s ease;
}
input::placeholder { color: var(--faint); }
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
/* Long-form config fields (pillar instruction_md, jsonb blocks) — same chrome as
   the inputs above, vertical-resize only so a card can never blow up sideways. */
textarea {
  background: var(--panel-2);
  border: 1px solid var(--line-strong);
  color: var(--text);
  border-radius: 7px;
  padding: 9px 11px;
  font: inherit;
  line-height: 1.55;
  width: 100%;
  resize: vertical;
  transition: border-color .12s ease;
}
textarea.mono { font-family: ui-monospace, "Cascadia Code", "SF Mono", Consolas, monospace; font-size: 12px; }
textarea::placeholder { color: var(--faint); }
textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
label.field.wide { min-width: 100%; }
.fieldnote { font-size: 11px; color: var(--faint); }
.fieldnote.label-only { color: var(--warn); }

/* schema-driven forms (lib/schemaform.js) — group heading + per-field error slot */
.sfgroup { margin-bottom: 18px; }
.sfgrp {
  color: var(--faint); font-size: 10.5px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .07em; margin: 0 0 9px;
}
.sferr { min-height: 1em; }
.sferr.bad { color: var(--bad); }

.checks { display: flex; flex-wrap: wrap; gap: 7px; }
.check {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 7px 11px;
  cursor: pointer;
  font-size: 12.5px;
  transition: border-color .12s ease;
}
.check:hover { border-color: var(--line-strong); }
.check input { accent-color: var(--accent); }

.switch { cursor: pointer; accent-color: var(--accent); width: 17px; height: 17px; }

/* ---------- review-queue title cell (framed thumbnail, aligned row) ---------- */
.qcell { display: flex; align-items: center; gap: 11px; }
.qcell .thumb {
  flex: 0 0 auto;
  width: 54px; height: 36px;
  object-fit: cover;
  border-radius: 5px;
  border: 1px solid var(--line-strong);
}
.qcell .qtitle { line-height: 1.4; }

/* ---------- toast ---------- */
.toast {
  position: fixed; right: 22px; bottom: 22px;
  background: var(--panel-2);
  border: 1px solid var(--line-strong);
  border-left: 3px solid var(--ok);
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 13px;
  max-width: 420px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .4);
}
.toast.bad { border-left-color: var(--bad); }

.empty { color: var(--faint); font-style: italic; padding: 8px 0; }

/* ---------- subscribers popover (see-more, body-anchored so the table's
   overflow never clips it and the row height never changes — rules 4 & 5) ---------- */
.subsmore {
  background: none; border: 0; color: var(--accent); cursor: pointer;
  font: inherit; font-size: 12.5px; font-weight: 500; padding: 0;
}
.subsmore:hover { text-decoration: underline; }
.popover {
  position: absolute; z-index: 50;
  background: var(--panel-2);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 8px;
  min-width: 160px; max-width: 280px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
}
.popover .prow { padding: 5px 8px; font-size: 12.5px; font-family: ui-monospace, Consolas, monospace; color: var(--text); border-radius: 5px; }
.popover .prow + .prow { margin-top: 1px; }

/* edit-mode row affordances on the Campaign screen */
.camprow.editable:hover td { background: var(--panel-2); cursor: pointer; }
.xdel { background: none; border: 0; color: var(--bad); cursor: pointer; font-size: 15px; line-height: 1; padding: 2px 6px; border-radius: 5px; }
.xdel:hover { background: rgba(248, 81, 73, .12); }

/* ---------- recent-trends feed: topic anchors, meta recedes ---------- */
.feeditem { padding: 10px 0; border-bottom: 1px solid var(--line); }
.feeditem:first-of-type { padding-top: 2px; }
.feeditem:last-child { border-bottom: 0; padding-bottom: 2px; }
.feeditem > div:first-child { font-weight: 500; color: var(--text); }
.feedmeta { color: var(--faint); font-size: 11px; margin-top: 3px; letter-spacing: .01em; }

/* ---------- responsive safety (desktop tool, but don't break narrow) ---------- */
@media (max-width: 760px) {
  body { flex-direction: column; }
  .nav { width: 100%; flex: none; height: auto; position: static; flex-direction: row; flex-wrap: wrap; gap: 4px; }
  .navfoot { margin-left: auto; }
  .main { padding: 20px 16px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ---------- studio mockup additions (M4) ---------- */
.studio { display: grid; grid-template-columns: 300px 1fr 320px; gap: 20px; align-items: start; }
.studio .card { margin-bottom: 0; }
.canvas11 { width: 100%; aspect-ratio: 1/1; border-radius: 8px; overflow: hidden; position: relative; border: 1px solid var(--line-strong); background: linear-gradient(135deg,#3a4456,#232a38 55%,#2d3648); }
.canvas916 { width: 300px; aspect-ratio: 9/16; margin: 0 auto; border-radius: 8px; overflow: hidden; position: relative; border: 1px solid var(--line-strong); background: linear-gradient(160deg,#31465a,#1d2532 60%,#2b3244); }
.imgph { position:absolute; inset:0; display:flex; align-items:center; justify-content:center; color:var(--faint); font-size:12px; letter-spacing:.05em; text-transform:uppercase; }
/* RAZ-174: the poster preview is the export canvas itself (no DOM text layer —
   the dead .shade/.postertext mockup rules were removed with it), and the video
   overlay's geometry (bar height, rank position/size/colour, safe-zone bands) is
   set INLINE by m4-studio-video.js from m4_templates.spec — the SAME numbers the
   export PNG uses. Only non-geometry styling may live here. */
.vtopbar { position:absolute; top:0; left:0; right:0; display:flex; align-items:center; justify-content:center; }
.vranks { position:absolute; display:block; }
.vrank { text-shadow:0 1px 3px rgba(0,0,0,.7); white-space:pre; overflow:hidden; }
.vrank .vlabel { line-height:inherit; }
.safezone { position:absolute; inset:0; pointer-events:none; }
.safezone .sztop { position:absolute; top:0; left:0; right:0; border-bottom:1px dashed rgba(255,201,67,.55); }
.safezone .szbot { position:absolute; bottom:0; left:0; right:0; border-top:1px dashed rgba(255,201,67,.55); }
.safezone .szright { position:absolute; top:0; bottom:0; right:0; border-left:1px dashed rgba(255,201,67,.55); }
.clipslot { display:flex; align-items:center; gap:10px; padding:9px 0; border-bottom:1px solid var(--line); }
.clipslot:last-child { border-bottom:0; }
.clipthumb { flex:0 0 auto; width:44px; height:66px; border-radius:5px; border:1px solid var(--line-strong); background:linear-gradient(150deg,#3a4456,#232a38); display:flex; align-items:center; justify-content:center; color:var(--faint); font-size:10px; }
.clipmeta { flex:1; min-width:0; }
.clipmeta .cname { font-size:12.5px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.clipmeta .cdur { font-size:11px; color:var(--faint); margin-top:2px; }
.trim { display:flex; align-items:center; gap:8px; margin-top:5px; }
.trim input[type=range] { flex:1; accent-color: var(--accent); height:3px; }
.trim .tval { font-size:11px; color:var(--muted); font-variant-numeric:tabular-nums; white-space:nowrap; }
.progress { height:8px; border-radius:6px; background:var(--panel-2); border:1px solid var(--line); overflow:hidden; }
.progress > div { height:100%; width:62%; background:var(--accent); }
.statgrid { display:grid; grid-template-columns:repeat(4,1fr); gap:12px; margin-bottom:20px; }
.stat { background:var(--panel); border:1px solid var(--line-strong); border-radius:var(--radius); padding:14px 16px; }
.stat .sv { font-size:20px; font-weight:700; font-variant-numeric:tabular-nums; }
.stat .sl { font-size:11px; color:var(--muted); margin-top:3px; text-transform:uppercase; letter-spacing:.06em; }
.mixrow { display:flex; gap:9px; align-items:center; }
.mixrow .field { min-width:110px; }
