:root {
  color-scheme: dark;
  --bg-canvas: #101319;
  --bg-surface: #171b23;
  --bg-elevated: #202631;
  --bg-subtle: #292f3b;
  --border-subtle: #2c3340;
  --border-strong: #444f61;
  --text-primary: #f3f5f8;
  --text-secondary: #bac4d2;
  --text-muted: #9ba7b9;
  --accent-primary: #77e4b6;
  --accent-ink: #09251b;
  --accent-primary-soft: rgba(119, 228, 182, 0.1);
  --accent-secondary: #bbc3ff;
  --accent-secondary-soft: rgba(154, 166, 255, 0.13);
  --status-success: #77e4b6;
  --status-warning: #f1ba73;
  --status-danger: #ff9c9c;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-card: 0 2px 8px rgba(0, 0, 0, 0.14);
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "SFMono-Regular", Consolas, monospace;
  --workspace-gutter: clamp(18px, 4vw, 60px);
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) var(--bg-canvas);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg-canvas: #f3f5f7;
  --bg-surface: #ffffff;
  --bg-elevated: #edf0f3;
  --bg-subtle: #e3e8ed;
  --border-subtle: #d5dde5;
  --border-strong: #aebac8;
  --text-primary: #18212d;
  --text-secondary: #3f4d60;
  --text-muted: #536276;
  --accent-primary: #096a4b;
  --accent-ink: #ffffff;
  --accent-primary-soft: rgba(9, 106, 75, 0.09);
  --accent-secondary: #484aae;
  --accent-secondary-soft: rgba(72, 74, 174, 0.09);
  --status-success: #096a4b;
  --status-warning: #875006;
  --status-danger: #a52929;
  --shadow-card: 0 2px 8px rgba(25, 45, 70, 0.05);
}

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

html,
body {
  min-height: 100vh;
  background-color: var(--bg-canvas);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

.app-shell {
  display: grid;
  grid-template-columns: 64px 256px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background-color: var(--bg-surface);
  border-right: 1px solid var(--border-subtle);
  padding: 24px 16px;
  position: sticky;
  top: 0;
  height: 100dvh;
  overflow-y: auto;
}

.brand-lockup,
.brand-identity {
  display: flex;
  align-items: center;
}

.brand-lockup {
  justify-content: space-between;
  margin: 0 8px 28px;
}

.brand-identity {
  gap: 12px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 33px;
  height: 33px;
  border-radius: 10px;
  background: var(--accent-primary);
  color: var(--accent-ink);
}

.brand-mark::before {
  content: "";
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-radius: 50%;
  background: radial-gradient(circle, currentColor 0 2px, transparent 2.5px);
}

.brand-name {
  font-size: 19px;
  font-weight: 750;
  letter-spacing: -0.045em;
}

.studio-nav {
  display: grid;
  gap: 24px;
}

.mobile-nav-toggle.btn {
  display: none;
}

.nav-section-label {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  margin: 0 12px 6px;
}

.nav-list {
  display: grid;
  gap: 3px;
  list-style: none;
}

.nav-btn {
  position: relative;
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  min-height: 40px;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.nav-btn:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.nav-btn.active {
  background: var(--accent-primary-soft);
  border-color: var(--accent-primary-soft);
  color: var(--accent-primary);
  font-weight: 650;
}

.nav-btn.active::before {
  content: "";
  position: absolute;
  inset: 9px auto 9px -1px;
  width: 3px;
  border-radius: 4px;
  background: var(--accent-primary);
}

.workspace {
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px var(--workspace-gutter);
  min-height: 68px;
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-canvas);
}

.topbar-search {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  max-width: 490px;
  min-width: 0;
}

.topbar-search input {
  flex: 1;
  min-width: 0;
  background: var(--bg-surface);
}

.search-key {
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  color: var(--text-muted);
  padding: 0 5px;
  font-family: var(--font-mono);
}

.content-area {
  padding: clamp(24px, 4vw, 54px) var(--workspace-gutter) 64px;
  max-width: 1440px;
  margin: 0 auto;
}

.tab-panel {
  display: none;
  flex-direction: column;
  gap: 22px;
}

.tab-panel.active {
  display: flex;
}

.page-header,
.card-header,
.result-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.page-header {
  margin-bottom: 4px;
}

.page-title {
  font-size: clamp(28px, 4vw, 48px);
  font-weight: 740;
  line-height: 1.12;
  letter-spacing: -0.05em;
}

.page-subtitle {
  color: var(--text-secondary);
  font-size: 15px;
  margin-top: 9px;
  max-width: 68ch;
}

.card,
.metric-card,
.trace-panel {
  min-width: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: clamp(14px, 2vw, 24px);
  box-shadow: var(--shadow-card);
}

.card-header {
  margin-bottom: 14px;
}

.card-title {
  font-size: 16px;
  font-weight: 680;
  line-height: 1.35;
  letter-spacing: -0.02em;
}

.card-meta {
  font-size: 13px;
  color: var(--text-muted);
}

.card-title + .card-meta {
  margin-top: 3px;
}

.result-heading h2 {
  font-size: 19px;
  letter-spacing: -0.025em;
}

.result-heading h3 {
  font-size: 15px;
}

/* Grids */
.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

@media (max-width: 1100px) {
  .grid-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .grid-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .grid-4,
  .grid-3,
  .grid-2 {
    grid-template-columns: 1fr;
  }
}

/* Metric Cards */
.metric-label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

.metric-value {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.03em;
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
}

.metric-foot {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

/* Inputs & Buttons */
input[type="text"],
input[type="number"],
input[type="search"],
select,
textarea {
  background-color: var(--bg-canvas);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 9px 12px;
  min-height: 40px;
  max-width: 100%;
  font: inherit;
  transition: border-color 0.12s ease;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--text-secondary);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background-color: var(--bg-elevated);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  transition: background-color 0.12s ease, border-color 0.12s ease;
}

.btn:hover {
  background-color: var(--bg-subtle);
  border-color: var(--border-strong);
}

.btn-primary {
  background-color: var(--accent-primary);
  color: var(--accent-ink);
  border-color: var(--accent-primary);
  font-weight: 600;
}

.btn-primary:hover {
  opacity: 0.9;
  background-color: var(--accent-primary);
  border-color: var(--accent-primary);
}

.btn-accent {
  background-color: var(--accent-primary);
  color: var(--accent-ink);
  border-color: var(--accent-primary);
  font-weight: 600;
}

.btn-sm {
  min-height: 34px;
  padding: 5px 10px;
  font-size: 12px;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 3px;
}

a {
  color: var(--accent-primary);
  text-underline-offset: 3px;
}

.toolbar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* Badges & Pills */
.pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  border: 1px solid var(--border-subtle);
  background-color: var(--bg-elevated);
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.pill-emerald {
  background-color: var(--accent-primary-soft);
  color: var(--accent-primary);
  border-color: rgba(16, 185, 129, 0.28);
}

.pill-indigo {
  background-color: var(--accent-secondary-soft);
  color: var(--accent-secondary);
  border-color: rgba(99, 102, 241, 0.28);
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  border-radius: var(--radius-sm);
  background-color: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  font-size: 12px;
  color: var(--text-primary);
  cursor: pointer;
}

.tag-chip:hover {
  border-color: var(--accent-primary);
}

/* Container-Query Responsive Tables (`responsive-table`) */
.table-container {
  width: 100%;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.data-table.earnings-table {
  min-width: 0;
}

.earnings-table th[scope="row"] {
  font-size: 12px;
  text-transform: none;
  letter-spacing: 0;
}

.data-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-subtle);
}

.data-table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-primary);
}

.data-table tr:hover td {
  background-color: var(--bg-elevated);
}

.data-table caption {
  text-align: left;
  font-weight: 650;
  padding-bottom: 6px;
}

.data-table td {
  vertical-align: top;
}

@media (max-width: 860px) {
  .data-table {
    min-width: 520px;
  }
}

/* Progress Bars & Sparklines */
.bar-track {
  width: 100%;
  height: 6px;
  background-color: var(--bg-elevated);
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background-color: var(--accent-primary);
  border-radius: 999px;
}

/* 7x24 Heatmap */
.heatmap-grid {
  display: grid;
  grid-template-columns: 44px repeat(24, minmax(0, 1fr));
  gap: 3px;
  align-items: center;
  font-size: 10px;
  font-family: var(--font-mono);
}

.heatmap-cell {
  height: 20px;
  border-radius: 3px;
}

/* 3x3 Saliency Grid */
.saliency-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.saliency-cell {
  background-color: var(--bg-canvas);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 10px;
  font-size: 12px;
}

/* Documentation Typography */
.doc-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.doc-h2 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-subtle);
}

.doc-code {
  font-family: var(--font-mono);
  font-size: 12px;
  background-color: var(--bg-canvas);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 12px;
  overflow-x: auto;
  color: var(--text-primary);
  line-height: 1.55;
}

.mono {
  font-family: var(--font-mono);
}

/* Sub-navigation Segmented Bar */
.subnav-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 6px;
  margin-bottom: 20px;
  overflow-x: auto;
}

.subnav-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.subnav-btn:hover {
  color: var(--text-primary);
  background-color: var(--bg-elevated);
}

.subnav-btn.active {
  color: var(--text-primary);
  background-color: var(--bg-elevated);
  border-color: var(--border-subtle);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.subnav-badge {
  font-size: 11px;
  font-family: var(--font-mono);
  padding: 2px 7px;
  border-radius: 12px;
  background: var(--bg-subtle);
  color: var(--text-secondary);
}

.subnav-btn.active .subnav-badge {
  background: var(--accent-primary-soft);
  color: var(--accent-primary);
}

.sub-panel {
  display: none;
  flex-direction: column;
  gap: 20px;
}

.sub-panel.active {
  display: flex;
}

/* Research forms and results */
.research-panel,
.stack,
.research-response {
  display: grid;
  gap: 16px;
}

.research-panel > .card-header {
  margin-bottom: 0;
}

.outlier-form {
  border-top: 2px solid var(--accent-primary);
}

.research-form {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px;
}

.field {
  display: grid;
  gap: 5px;
  min-width: 0;
  max-width: 100%;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
}

.field-grow {
  flex: 1 1 210px;
}

.field :is(input, select, textarea) {
  width: 100%;
  min-width: 0;
}

.field textarea {
  resize: vertical;
}

fieldset.field {
  border: 0;
}

.field legend {
  margin-bottom: 5px;
}

.segment-control {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  min-height: 40px;
  padding: 3px;
  background: var(--bg-canvas);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
}

.segment-control label {
  position: relative;
  flex: 1;
}

.segment-control input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.segment-control span {
  display: grid;
  place-items: center;
  min-height: 32px;
  padding: 4px 11px;
  border-radius: 5px;
  white-space: nowrap;
  cursor: pointer;
}

.segment-control input:checked + span {
  background: var(--accent-primary-soft);
  color: var(--accent-primary);
}

.segment-control input:focus-visible + span {
  outline: 2px solid var(--accent-primary);
}

.result-state {
  grid-column: 1 / -1;
  color: var(--text-secondary);
  background: var(--bg-surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  padding: 16px;
  overflow-wrap: anywhere;
}

.research-panel .result-state {
  background: var(--bg-canvas);
}

.grid-2:empty,
.grid-3:empty,
.grid-4:empty,
#estimate-results:empty,
#vsm-snapshot-details:empty {
  display: none;
}

.metric-card > .pill {
  margin-top: 8px;
}

.provenance-legend,
.sample-metrics,
.result-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
}

.result-meta {
  justify-content: space-between;
}

.sample-metrics dl,
.result-metrics > div {
  background: var(--bg-canvas);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
}

.result-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.sample-metrics dt,
.result-metrics dt,
.evidence-list small {
  font-size: 12px;
  color: var(--text-muted);
}

.sample-metrics dd,
.result-metrics dd {
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.result-card {
  display: grid;
  align-content: start;
  gap: 12px;
  overflow-wrap: anywhere;
}

.result-card .card-title a {
  color: inherit;
}

.evidence-list {
  padding-left: 18px;
  font-size: 13px;
}

.evidence-list small {
  display: block;
}

.fleet-brands-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr));
  gap: 14px;
}

.creator-tools summary,
.result-card summary,
.vph-details summary {
  cursor: pointer;
  font-weight: 640;
}

.vph-details dl {
  display: grid;
  gap: 3px;
  min-width: 125px;
  margin: 6px 0;
  color: var(--text-secondary);
  font-size: 12px;
}

.vph-details dl > div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

#vsm-snapshot-details {
  padding: 12px 16px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
}

.creator-tools[open] summary {
  margin-bottom: 14px;
}

.heatmap-grid {
  min-width: 395px;
}

@media (max-width: 760px) {
  .app-shell {
    grid-template-columns: minmax(0, 1fr);
  }

  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border-subtle);
    padding: 12px var(--workspace-gutter);
  }

  .brand-lockup {
    margin: 0;
  }

  .mobile-nav-toggle.btn {
    display: inline-flex;
  }

  .studio-nav {
    display: none;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    padding-top: 16px;
  }

  .sidebar:has(.mobile-nav-toggle[aria-expanded="true"]) .studio-nav {
    display: grid;
  }

  .topbar {
    position: static;
    min-height: 0;
    gap: 8px;
  }

  .search-key {
    display: none;
  }

  .page-subtitle {
    font-size: 14px;
  }

  .tab-panel {
    gap: 16px;
  }

  .research-form > .field {
    flex: 1 1 135px;
  }

  .outlier-form fieldset.field,
  .research-form > .field-grow {
    flex-basis: 100%;
  }
}

@media (max-width: 390px) {
  .studio-nav {
    grid-template-columns: minmax(0, 1fr);
  }

  .topbar {
    flex-wrap: wrap;
  }

  .topbar-search {
    flex-basis: 100%;
  }
}

/* v4 UI polish */

/* Grid children may shrink so wide tables and code scroll inside their card instead of clipping. */
.grid-2 > *,
.grid-3 > *,
.grid-4 > * {
  min-width: 0;
}

.table-container {
  max-width: 100%;
}

.grid-2 .data-table:not(.earnings-table) {
  min-width: 460px;
}

#kw-details {
  container-type: inline-size;
}

@container (width < 936px) {
  #kw-details > .grid-2 {
    grid-template-columns: minmax(0, 1fr);
  }
}

.data-table .pill,
.data-table .slot-time,
.data-table .slot-jitter {
  white-space: nowrap;
}

.data-table .pill {
  max-width: none;
}

.doc-code {
  max-width: 100%;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* Numbers never split mid-value in stat grids and earnings tables. */
.result-metrics dd,
.sample-metrics dd,
.metric-value,
.earnings-table td {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  overflow-wrap: normal;
}

.result-metrics {
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
}

.earnings-table th[scope="row"] {
  white-space: nowrap;
}

/* Channel cards: tier pill wraps under the name and URL instead of overlapping them. */
.brand-card-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 6px;
}

.brand-card-id {
  flex: 1 1 140px;
  min-width: 0;
}

.brand-card-domain {
  font-size: 11px;
  color: var(--text-muted);
  overflow-wrap: anywhere;
}

.brand-card-tier {
  flex: 0 0 auto;
  white-space: nowrap;
}

/* Departures toolbar: status filters stay together; the destructive reset sits apart. */
.dep-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 10px 20px;
}

.dep-toolbar .toolbar-row + .toolbar-row {
  padding-left: 20px;
  border-left: 1px solid var(--border-strong);
}

.btn-danger-quiet {
  color: var(--status-danger);
  border-color: transparent;
  background: transparent;
}

.btn-danger-quiet:hover {
  border-color: var(--status-danger);
  background: transparent;
}

@media (max-width: 720px) {
  .dep-toolbar .toolbar-row + .toolbar-row {
    padding-left: 0;
    border-left: 0;
  }
}

.inspect-card {
  position: relative;
}

.inspect-card:hover,
.inspect-card:focus-within {
  border-color: var(--accent-primary);
}

.inspect-card-link {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.inspect-card-link::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
}

.inspector-drawer {
  position: fixed;
  inset: 0 0 0 auto;
  width: min(100%, 496px);
  max-width: 100%;
  height: 100%;
  max-height: 100%;
  margin: 0;
  border: 0;
  border-left: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-primary);
  box-shadow: -12px 0 48px rgba(0, 0, 0, 0.26);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.inspector-drawer[open] {
  animation: inspector-enter 180ms ease-out;
}

body:has(.inspector-drawer[open]) {
  overflow: hidden;
}

.inspector-drawer::backdrop {
  background: rgba(8, 12, 18, 0.6);
}

@keyframes inspector-enter {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

@media (prefers-reduced-motion: reduce) {
  .inspector-drawer[open] { animation: none; }
}

.inspector-header,
.inspector-body {
  padding: 20px clamp(16px, 4vw, 26px);
}

.inspector-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  border-bottom: 1px solid var(--border-subtle);
}

.inspector-header h2 {
  margin-block: 4px;
  font-size: clamp(19px, 4vw, 24px);
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.inspector-header .btn {
  flex-shrink: 0;
}

.inspector-body {
  gap: 18px;
}

.inspector-section {
  min-width: 0;
  padding-top: 16px;
  border-top: 1px solid var(--border-subtle);
}

.inspector-section h3 {
  font-size: 14px;
}

.inspector-facts dd {
  white-space: normal;
  overflow-wrap: anywhere;
}

.inspector-body [data-inspector="earnings"]:empty,
.inspector-body [data-inspector="status"]:empty {
  display: none;
}

.inspector-body [data-inspector="source"] {
  text-decoration: none;
}

#campaign-draft,
#outlier-advanced[open] > .research-form {
  margin-top: 12px;
}

#outlier-advanced summary {
  cursor: pointer;
  color: var(--text-secondary);
}

/* v4.2 Research Hub */

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Brand rail: compact far-left switcher for Brand DNA workspaces. */
.brand-rail {
  position: sticky;
  top: 0;
  height: 100dvh;
  overflow-y: auto;
  padding: 20px 10px;
  background: var(--bg-canvas);
  border-right: 1px solid var(--border-subtle);
}

.brand-rail-list {
  display: grid;
  gap: 10px;
  list-style: none;
}

.brand-rail-btn {
  position: relative;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  color: var(--text-secondary);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: -0.02em;
  cursor: pointer;
}

.brand-rail-btn::after {
  content: "";
  position: absolute;
  inset: auto 8px 5px;
  height: 3px;
  border-radius: 3px;
  background: var(--brand-color, var(--border-strong));
}

.brand-rail-btn:hover {
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.brand-rail-btn[aria-pressed="true"] {
  color: var(--accent-primary);
  border-color: var(--accent-primary);
  background: var(--accent-primary-soft);
}

.brand-rail-btn:focus-visible,
.research-hub-link:focus-visible,
.filter-pill:focus-visible,
.kw-tab:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

.brand-rail-status {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  overflow-wrap: anywhere;
}

.brand-rail-status:empty {
  display: none;
}

/* Research hub: one shared query across Keywords, Long-form, Shorts and Channels. */
.research-hub {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 4px;
  padding: 8px var(--workspace-gutter);
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-surface);
}

.research-hub-label {
  margin-right: 8px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.research-hub-link {
  padding: 6px 12px;
  border-radius: 999px;
  color: var(--text-secondary);
  font-size: 13px;
  text-decoration: none;
}

.research-hub-link:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.research-hub-link[aria-current="page"] {
  background: var(--accent-primary-soft);
  color: var(--accent-primary);
  font-weight: 650;
}

.research-hub-query {
  margin-left: auto;
  max-width: 40ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Outlier presets: a single scrolling row of pills. */
.filter-pill-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.filter-pill-bar > * {
  flex: 0 0 auto;
}

.filter-pill-label {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 650;
}

.filter-pill {
  padding: 6px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--bg-surface);
  color: var(--text-secondary);
  font: inherit;
  font-size: 12px;
  white-space: nowrap;
  cursor: pointer;
}

.filter-pill:hover {
  color: var(--text-primary);
}

.filter-pill[aria-pressed="true"] {
  border-color: var(--accent-primary);
  background: var(--accent-primary-soft);
  color: var(--accent-primary);
  font-weight: 650;
}

.filter-pill-summary {
  margin-left: 4px;
  white-space: nowrap;
}

/* Outlier grid: visual-first cards, 3-4 columns on desktop. */
.outlier-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr));
  gap: 16px;
  align-items: start;
}

.outlier-grid:empty {
  display: none;
}

.outlier-card {
  display: grid;
  gap: 10px;
  padding: 0;
  overflow: hidden;
}

.outlier-card > :not(.outlier-thumb) {
  margin-inline: 14px;
}

.outlier-card > :last-child {
  margin-bottom: 14px;
}

.outlier-thumb {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: var(--bg-elevated);
  overflow: hidden;
}

.outlier-thumb.is-short {
  aspect-ratio: 9 / 16;
  width: min(100%, 200px);
  margin: 12px auto 0;
  border-radius: var(--radius-sm);
}

.outlier-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.outlier-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.outlier-card .card-title {
  font-size: 14px;
  line-height: 1.35;
}

.outlier-card .card-title a {
  color: inherit;
  text-decoration: none;
}

.outlier-card .result-metrics {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.outlier-card .result-metrics > div {
  padding: 6px 9px;
}

.lift-pill {
  font-weight: 700;
}

.lift-2 {
  color: #8cc8ff;
  background: rgba(96, 165, 250, 0.14);
  border-color: rgba(96, 165, 250, 0.35);
}

.lift-5 {
  color: #d4b2ff;
  background: rgba(167, 112, 250, 0.15);
  border-color: rgba(167, 112, 250, 0.38);
}

.lift-10 {
  color: #ffab98;
  background: rgba(255, 107, 84, 0.15);
  border-color: rgba(255, 107, 84, 0.4);
}

:root[data-theme="light"] .lift-2 { color: #1d5fae; }
:root[data-theme="light"] .lift-5 { color: #6a2fbf; }
:root[data-theme="light"] .lift-10 { color: #b1321b; }

.vph-badge {
  font-variant-numeric: tabular-nums;
}

/* Keyword split: KPI rail on the left, tabbed tables on the right. */
.kw-split-wrap {
  container-type: inline-size;
}

.kw-split {
  display: grid;
  grid-template-columns: minmax(220px, 260px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

@container (width < 820px) {
  .kw-split {
    grid-template-columns: minmax(0, 1fr);
  }

  .kw-rail-cards {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  }
}

.kw-rail,
.kw-table-panel {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.kw-rail-cards {
  display: grid;
  gap: 10px;
}

.kw-rail-cards .metric-card {
  padding: 12px 14px;
  box-shadow: none;
  background: var(--bg-canvas);
}

.kw-rail-cards .metric-value {
  font-size: 24px;
}

.kw-rail-sample {
  display: grid;
  gap: 6px;
}

.kw-table-panel > .card-header {
  margin-bottom: 0;
}

.kw-tabs {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-canvas);
}

.kw-tab {
  padding: 6px 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.kw-tab[aria-selected="true"] {
  background: var(--accent-primary-soft);
  color: var(--accent-primary);
  font-weight: 650;
}

.kw-panel {
  min-width: 0;
}

.kw-panel .table-container {
  max-width: 100%;
  overflow-x: auto;
}

.niche-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr));
  gap: 14px;
}

.niche-grid:empty {
  display: none;
}

/* Breakout channels on the Channels view. */
#channel-breakouts .data-table td:last-child {
  white-space: nowrap;
}

/* Inspector drawer v2 */
.inspector-preview {
  aspect-ratio: 16 / 9;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #000;
}

.inspector-preview.is-short {
  aspect-ratio: 9 / 16;
  width: min(100%, 260px);
  margin-inline: auto;
}

.inspector-preview iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
}

.median-compare {
  display: grid;
  gap: 8px;
}

.median-row {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--text-secondary);
}

.median-bar {
  height: 10px;
  border-radius: 999px;
  background: var(--bg-elevated);
  overflow: hidden;
}

.median-bar span {
  display: block;
  height: 100%;
  min-width: 3px;
  border-radius: inherit;
  background: var(--accent-primary);
}

.median-row.is-baseline .median-bar span {
  background: var(--border-strong);
}

.median-row strong {
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
}

.inspector-brief {
  max-height: 280px;
  font-size: 12px;
}

@media (max-width: 760px) {
  .brand-rail {
    position: static;
    height: auto;
    padding: 8px var(--workspace-gutter);
    border-right: 0;
    border-bottom: 1px solid var(--border-subtle);
  }

  .brand-rail-list {
    display: flex;
    overflow-x: auto;
  }

  .brand-rail-btn {
    width: 40px;
    height: 40px;
  }

  .research-hub-query {
    margin-left: 0;
    flex-basis: 100%;
  }
}
