/* ─────────────────────────────────────────────────────────────────────────
   Design tokens — "Reverse" research tool
   Dark "studio" theme by default, light "notebook" theme via [data-theme=light]
   Density via [data-density=compact|comfy]
   ───────────────────────────────────────────────────────────────────────── */
:root {
  /* base palette — dark / studio */
  --bg:           #0a0c10;
  --bg-soft:      #0e1116;
  --panel:        #131820;
  --panel-2:      #181e28;
  --panel-3:      #1f2632;
  --hover:        #1a2030;
  --line:         rgba(255,255,255,0.07);
  --line-strong:  rgba(255,255,255,0.14);
  --text:         #e6e9ef;
  --text-mid:     #b6bdc8;
  --text-dim:     #7d8590;
  --text-faint:   #545b66;

  /* accents — vintage 1920s amber + cool data hues */
  --accent:       #e8a93b;
  --accent-soft:  rgba(232,169,59,0.14);
  --accent-strong:#f6c061;

  --c-vision:     #5cc8ff;   /* video / motion */
  --c-audio:      #c78bff;   /* audio / sfx */
  --c-fusion:     #7ee59b;   /* cross-modal */
  --c-query:      #f0b341;   /* query / analytics */
  --c-ingest:     #b6bdc8;   /* generic / ingest */
  --c-warn:       #ef6868;
  --c-ok:         #7ee59b;
  --c-pend:       #f0b341;

  /* density */
  --row-h:        32px;
  --pad-x:        16px;
  --pad-y:        14px;
  --radius:       8px;
  --radius-lg:    12px;
  --radius-sm:    4px;

  /* type */
  --font-sans:    "IBM Plex Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono:    "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --font-serif:   "IBM Plex Serif", Georgia, serif;
}

[data-theme="light"] {
  --bg:           #f5f1e6;
  --bg-soft:      #efeadb;
  --panel:        #ffffff;
  --panel-2:      #faf6ec;
  --panel-3:      #f0ebde;
  --hover:        #efeadb;
  --line:         rgba(20,16,8,0.08);
  --line-strong:  rgba(20,16,8,0.16);
  --text:         #1a1a18;
  --text-mid:     #4a463c;
  --text-dim:     #6e6857;
  --text-faint:   #98937e;
  --accent:       #b07a14;
  --accent-soft:  rgba(176,122,20,0.12);
  --accent-strong:#8c5e10;
  --c-vision:     #1c6ea8;
  --c-audio:      #6e3aa6;
  --c-fusion:     #2c8c54;
  --c-query:      #a36300;
  --c-warn:       #b03434;
  --c-ok:         #2c8c54;
  --c-pend:       #a36300;
}

[data-density="compact"] {
  --row-h: 26px;
  --pad-x: 12px;
  --pad-y: 9px;
}
[data-density="comfy"] {
  --row-h: 40px;
  --pad-x: 22px;
  --pad-y: 20px;
}

/* ─────────────────────────────────────────────────────────────────────────
   Reset / base
   ───────────────────────────────────────────────────────────────────────── */
* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-feature-settings: "ss01", "cv11";
}
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; padding: 0; }
a { color: inherit; text-decoration: none; }

::selection { background: var(--accent-soft); color: var(--text); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 6px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); background-clip: content-box; border: 2px solid transparent; }

/* ─────────────────────────────────────────────────────────────────────────
   App shell
   ───────────────────────────────────────────────────────────────────────── */
.app {
  display: grid;
  grid-template-columns: 248px 1fr;
  height: 100vh;
  background: var(--bg);
  overflow: hidden;
}
[data-density="compact"] .app { grid-template-columns: 220px 1fr; }
[data-density="comfy"]   .app { grid-template-columns: 280px 1fr; }

/* Sidebar */
.sidebar {
  background: var(--bg-soft);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--line);
}
.brand-mark {
  width: 28px; height: 28px;
  border-radius: 7px;
  background:
    radial-gradient(circle at 30% 30%, var(--accent-strong), var(--accent) 45%, #6b3e0a 100%);
  display: grid; place-items: center;
  color: #1a0f00;
  font-family: var(--font-mono);
  font-weight: 700; font-size: 12px;
  letter-spacing: -0.04em;
  box-shadow: 0 0 0 1px rgba(232,169,59,0.25), 0 0 24px -8px var(--accent);
}
.brand-name { font-weight: 600; letter-spacing: -0.01em; font-size: 14px; }
.brand-name small { display: block; color: var(--text-dim); font-weight: 400; font-size: 10.5px; letter-spacing: 0.06em; text-transform: uppercase; margin-top: 1px; }

.proj-card {
  margin: 12px 12px 6px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  display: flex; gap: 10px; align-items: center;
}
.proj-thumb {
  width: 40px; height: 28px;
  background: linear-gradient(135deg, #2b1e08 0%, #4a330d 50%, #d49432 100%);
  border-radius: 4px;
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
}
.proj-thumb::before {
  content: "";
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at 70% 30%, rgba(255,255,255,0.4) 0%, transparent 40%);
}
.proj-meta { min-width: 0; flex: 1; }
.proj-meta b { font-size: 12px; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.proj-meta span { font-size: 10.5px; color: var(--text-dim); font-family: var(--font-mono); }

.nav-section { padding: 10px 14px 4px; font-size: 10px; font-weight: 600; color: var(--text-faint); letter-spacing: 0.1em; text-transform: uppercase; }
.nav-list { display: flex; flex-direction: column; padding: 0 8px; gap: 1px; flex: 1; overflow-y: auto; min-height: 0; }
.nav-item {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  color: var(--text-mid);
  font-size: 12.5px;
  width: 100%;
  text-align: left;
  position: relative;
}
.nav-item:hover { background: var(--hover); color: var(--text); }
.nav-item.is-active { background: var(--panel); color: var(--text); }
.nav-item.is-active::before {
  content: "";
  position: absolute;
  left: -8px; top: 6px; bottom: 6px;
  width: 2px;
  background: var(--accent);
  border-radius: 2px;
}
.nav-item .stage-id {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-faint);
  letter-spacing: -0.02em;
}
.nav-item.is-active .stage-id { color: var(--accent); }
.nav-item .stage-hero {
  font-size: 9.5px;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
}

.sidebar-foot { border-top: 1px solid var(--line); padding: 10px 14px; display: flex; align-items: center; gap: 8px; color: var(--text-dim); font-size: 11px; }
.sidebar-foot .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--c-ok); }

/* Main pane */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  height: 52px;
  flex-shrink: 0;
}
.crumbs {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--text-dim);
  font-family: var(--font-mono);
}
.crumbs b { color: var(--text); font-weight: 500; }
.crumbs .sep { color: var(--text-faint); }
.topbar-spacer { flex: 1; }
.topbar-search {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  width: 320px;
  color: var(--text-dim);
  font-size: 12px;
  font-family: var(--font-mono);
}
.topbar-search:focus-within { border-color: var(--line-strong); color: var(--text); }
.topbar-search input { background: none; border: 0; outline: 0; flex: 1; color: inherit; font-family: inherit; font-size: 12px; }
.topbar-search kbd {
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--bg);
  color: var(--text-faint);
  border: 1px solid var(--line);
}
.icon-btn {
  width: 30px; height: 30px;
  border-radius: 6px;
  display: grid; place-items: center;
  color: var(--text-mid);
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn svg { width: 16px; height: 16px; }
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--line-strong);
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  background: var(--panel);
}
.btn:hover { background: var(--hover); }
.btn.btn-primary {
  background: var(--accent);
  color: #1a0f00;
  border-color: var(--accent);
}
.btn.btn-primary:hover { background: var(--accent-strong); }
.btn.btn-ghost { background: transparent; border-color: transparent; color: var(--text-mid); }
.btn.btn-ghost:hover { background: var(--hover); color: var(--text); }
.btn .kbd { font-family: var(--font-mono); font-size: 10px; color: var(--text-faint); margin-left: 4px; }

/* Content area */
.content {
  flex: 1;
  overflow: auto;
  padding: 24px;
  min-height: 0;
}
[data-density="compact"] .content { padding: 16px; }
[data-density="comfy"]   .content { padding: 32px; }

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 22px;
  gap: 24px;
}
.page-head h2 {
  font-size: 22px;
  font-weight: 600;
  margin: 0 0 4px;
  letter-spacing: -0.02em;
  display: flex; align-items: center; gap: 12px;
}
.page-head h2 .stagetag {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 2px 7px;
  border-radius: 4px;
  letter-spacing: 0.04em;
  font-weight: 500;
}
.page-head p { margin: 0; color: var(--text-dim); font-size: 13px; max-width: 60ch; }
.page-actions { display: flex; align-items: center; gap: 8px; }

/* Reusable panel */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}
.panel-hd {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  gap: 12px;
}
.panel-hd h3 { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-mid); }
.panel-hd .panel-sub { color: var(--text-dim); font-family: var(--font-mono); font-size: 11px; }

/* Tag / pill */
.tag {
  display: inline-flex; align-items: center; gap: 4px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  padding: 2px 7px;
  border-radius: 3px;
  background: var(--panel-3);
  color: var(--text-mid);
  border: 1px solid var(--line);
  letter-spacing: 0.02em;
}
.tag.tag-vision { color: var(--c-vision); background: color-mix(in oklab, var(--c-vision) 12%, transparent); border-color: color-mix(in oklab, var(--c-vision) 20%, transparent); }
.tag.tag-audio  { color: var(--c-audio);  background: color-mix(in oklab, var(--c-audio)  12%, transparent); border-color: color-mix(in oklab, var(--c-audio)  20%, transparent); }
.tag.tag-fusion { color: var(--c-fusion); background: color-mix(in oklab, var(--c-fusion) 12%, transparent); border-color: color-mix(in oklab, var(--c-fusion) 20%, transparent); }
.tag.tag-query  { color: var(--c-query);  background: color-mix(in oklab, var(--c-query)  12%, transparent); border-color: color-mix(in oklab, var(--c-query)  20%, transparent); }
.tag.tag-ingest { color: var(--c-ingest); }

/* Status dot */
.status {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--font-mono);
}
.status .d { width: 6px; height: 6px; border-radius: 50%; display: inline-block; }
.status.done    .d { background: var(--c-ok); }
.status.ready   .d { background: var(--c-pend); box-shadow: 0 0 0 3px color-mix(in oklab, var(--c-pend) 22%, transparent); }
.status.queued  .d { background: var(--text-faint); }

/* Mono numbers */
.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* Tables */
.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.tbl th {
  text-align: left;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-soft);
  position: sticky; top: 0; z-index: 1;
}
.tbl td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  font-family: var(--font-mono);
  color: var(--text-mid);
}
.tbl tr:hover td { background: var(--hover); color: var(--text); }
.tbl tr.is-active td { background: var(--accent-soft); color: var(--text); }
[data-density="compact"] .tbl td, [data-density="compact"] .tbl th { padding: 5px 10px; }
[data-density="comfy"]   .tbl td, [data-density="comfy"]   .tbl th { padding: 12px 14px; }

/* Stat cards */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat-label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 500; }
.stat-value { font-size: 26px; font-weight: 500; letter-spacing: -0.02em; font-family: var(--font-mono); }
.stat-foot  { font-size: 11px; color: var(--text-dim); display: flex; align-items: center; gap: 6px; }
.stat-foot .up { color: var(--c-ok); }
.stat-foot .down { color: var(--c-warn); }

/* Notebook (light surface variant for SFX pure-audio screens) */
.notebook {
  background:
    repeating-linear-gradient(0deg, transparent 0 31px, color-mix(in oklab, var(--text-faint) 14%, transparent) 31px 32px),
    var(--panel);
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
}
[data-theme="dark"] .notebook,
:root:not([data-theme]) .notebook,
:root .notebook {
  background:
    repeating-linear-gradient(0deg, transparent 0 31px, rgba(255,255,255,0.025) 31px 32px),
    var(--panel);
}

/* Selection bar (footer on lists when items selected) */
.selbar {
  position: sticky; bottom: 0;
  background: var(--panel-2);
  border-top: 1px solid var(--line-strong);
  padding: 8px 16px;
  display: flex; align-items: center; gap: 12px;
  font-size: 12px;
}

/* Animations */
@keyframes blink { 0%,100% { opacity: 1 } 50% { opacity: 0.3 } }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: 0.55 } }
@keyframes shine { 0% { transform: translateX(-100%); } 100% { transform: translateX(200%); } }
@keyframes spin  { to { transform: rotate(360deg); } }

.skel {
  background: linear-gradient(90deg, var(--panel-2) 0%, var(--panel-3) 50%, var(--panel-2) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.6s linear infinite;
  border-radius: 4px;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* Real channel + video title stay blurred on the public mockup */
.redact { filter: blur(8px); user-select: none; }
