/* Palette values are the validated defaults from the dataviz reference instance.
   Two series colors only — blue (long) and red (short) — which clears every CVD
   and contrast gate in both modes with no warnings. */

/* Declared on :root ONLY. Putting the light values on .viz-root as well would
   shadow the dark overrides below for every element inside it, while `body`'s
   inherited `color` still resolved from :root — which renders white text on
   white cards in dark mode. One declaration site per mode. */
:root {
  color-scheme: light;

  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --wash: rgba(11, 11, 11, 0.04);

  --long: #2a78d6;
  --short: #e34948;

  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;
  --delta-up: #006300;
  --delta-down: #d03b3b;

  --radius: 10px;
  --radius-sm: 4px;
  --font: system-ui, -apple-system, 'Segoe UI', sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme='light'])) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --wash: rgba(255, 255, 255, 0.06);
    --long: #3987e5;
    --short: #e66767;
    --delta-up: #0ca30c;
    --delta-down: #e66767;
  }
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --page: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --gridline: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.1);
  --wash: rgba(255, 255, 255, 0.06);
  --long: #3987e5;
  --short: #e66767;
  --delta-up: #0ca30c;
  --delta-down: #e66767;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.viz-root {
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px 20px 64px;
}

/* ------------------------------------------------------------------ topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.topbar-left {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}
h1 {
  font-size: 17px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.01em;
}
.freshness {
  font-size: 12px;
  color: var(--text-muted);
}
.topbar-right {
  display: flex;
  gap: 8px;
}
.icon-btn {
  font: inherit;
  font-size: 12px;
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-secondary);
  cursor: pointer;
}
.icon-btn:hover {
  background: var(--wash);
  color: var(--text-primary);
}
.icon-btn[aria-pressed='true'] {
  background: var(--text-primary);
  color: var(--surface-1);
  border-color: var(--text-primary);
}

/* ------------------------------------------------------------------ banner */
.banner {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 16px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  border: 1px solid var(--border);
}
.banner-warning {
  background: color-mix(in srgb, var(--warning) 12%, var(--surface-1));
  border-color: color-mix(in srgb, var(--warning) 40%, var(--border));
}

/* ------------------------------------------------------------------- cards */
.stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.card,
.hero-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}
.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
h2 {
  font-size: 13px;
  font-weight: 600;
  margin: 0;
  letter-spacing: 0.01em;
}
.card-sub {
  margin: 3px 0 0;
  font-size: 12px;
  color: var(--text-muted);
  max-width: 62ch;
}
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: start; /* let each card size to its content instead of stretching */
  gap: 16px;
}
@media (max-width: 820px) {
  .two-col {
    grid-template-columns: 1fr;
  }
}

/* -------------------------------------------------------------------- hero */
.hero-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 32px;
  flex-wrap: wrap;
}
.stat-label {
  margin: 0 0 4px;
  font-size: 12px;
  color: var(--text-muted);
}
.hero-number {
  margin: 0;
  font-size: clamp(30px, 6vw, 42px);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.05;
}
.hero-delta {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--text-secondary);
}
.stat-row {
  display: flex;
  gap: 28px;
  margin: 0;
  flex-wrap: wrap;
}
.stat {
  min-width: 92px;
}
.stat dt {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 3px;
}
.stat dd {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.stat .sub {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
  display: block;
  margin-top: 1px;
}
.up {
  color: var(--delta-up);
}
.down {
  color: var(--delta-down);
}

/* ------------------------------------------------------------------ charts */
.chart-figure {
  margin: 0;
}
.chart {
  width: 100%;
}
.chart svg {
  display: block;
  width: 100%;
  overflow: visible;
}
.chart-caption {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 8px;
}
.grid-line {
  stroke: var(--gridline);
  stroke-width: 1;
}
.axis-line {
  stroke: var(--baseline);
  stroke-width: 1;
}
.axis-label {
  fill: var(--text-muted);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}
.series-line {
  fill: none;
  stroke: var(--long);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.series-area {
  fill: var(--long);
  opacity: 0.1;
}
.crosshair {
  stroke: var(--text-muted);
  stroke-width: 1;
  stroke-dasharray: 3 3;
}
.focus-dot {
  fill: var(--long);
  stroke: var(--surface-1);
  stroke-width: 2;
}

.range-toggle {
  display: flex;
  gap: 2px;
  background: var(--wash);
  padding: 2px;
  border-radius: var(--radius-sm);
}
.range-btn {
  font: inherit;
  font-size: 12px;
  padding: 4px 10px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: 3px;
  cursor: pointer;
}
.range-btn.is-active {
  background: var(--surface-1);
  color: var(--text-primary);
  font-weight: 500;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

/* --------------------------------------------------------- allocation bars */
.alloc-row {
  display: grid;
  grid-template-columns: minmax(88px, 132px) 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 5px 0;
}
.alloc-name {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.alloc-track {
  height: 12px;
  background: var(--wash);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.alloc-fill {
  height: 100%;
  background: var(--long);
  border-radius: var(--radius-sm);
  min-width: 2px;
}
.alloc-value {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
  white-space: nowrap;
}
.alloc-pct {
  color: var(--text-muted);
  margin-left: 5px;
}

/* ----------------------------------------------------------- net exposure */
.exposure {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.exp-row {
  display: grid;
  grid-template-columns: 62px 1fr 150px;
  align-items: center;
  gap: 12px;
  padding: 6px 0;
  border-radius: var(--radius-sm);
}
.exp-row:hover {
  background: var(--wash);
}
.exp-symbol {
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.exp-track {
  position: relative;
  height: 18px;
}
/* The zero line is the reference the whole chart is read against. */
.exp-zero {
  position: absolute;
  left: 50%;
  top: -2px;
  bottom: -2px;
  width: 1px;
  background: var(--baseline);
}
.exp-bar {
  position: absolute;
  top: 3px;
  height: 12px;
  border-radius: var(--radius-sm);
}
.exp-bar-long {
  background: var(--long);
  left: 50%;
}
.exp-bar-short {
  background: var(--short);
  right: 50%;
}
.exp-meta {
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}
/* Below ~560px a 150px meta column squeezes the bar track down to nothing.
   Drop the meta onto its own line so the bars keep their full width. */
@media (max-width: 560px) {
  .exp-row {
    grid-template-columns: 56px 1fr;
    row-gap: 2px;
  }
  .exp-meta {
    grid-column: 2;
    text-align: left;
  }
}
.exp-hedged {
  color: var(--delta-up);
  font-weight: 500;
}
.legend {
  display: flex;
  gap: 14px;
  font-size: 12px;
  color: var(--text-secondary);
}
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  display: inline-block;
}
.swatch-long {
  background: var(--long);
}
.swatch-short {
  background: var(--short);
}

/* ------------------------------------------------------------------ tables */
.table-scroll {
  overflow-x: auto;
  margin: 0 -20px;
  padding: 0 20px;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
.data-table th {
  text-align: left;
  font-weight: 500;
  font-size: 11px;
  color: var(--text-muted);
  padding: 0 12px 7px 0;
  border-bottom: 1px solid var(--gridline);
  white-space: nowrap;
}
.data-table td {
  padding: 7px 12px 7px 0;
  border-bottom: 1px solid var(--gridline);
  white-space: nowrap;
}
.data-table tbody tr:last-child td {
  border-bottom: none;
}
.data-table tbody tr:hover {
  background: var(--wash);
}
.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.sym {
  font-weight: 600;
}
.dim {
  color: var(--text-muted);
}
.side-long {
  color: var(--long);
  font-weight: 500;
}
.side-short {
  color: var(--short);
  font-weight: 500;
}
.checkbox {
  font-size: 12px;
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

/* ------------------------------------------------------------ source list */
.source-list {
  display: flex;
  flex-direction: column;
}
.source-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--gridline);
  font-size: 12.5px;
}
.source-row:last-child {
  border-bottom: none;
}
.source-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.source-addr {
  color: var(--text-muted);
  font-size: 11px;
  margin-left: 6px;
}
.source-value {
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}
/* Status is never carried by color alone — every badge ships an icon and a word. */
.status {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 20px;
  border: 1px solid var(--border);
  white-space: nowrap;
}
.status-ok {
  color: var(--delta-up);
  border-color: color-mix(in srgb, var(--good) 35%, transparent);
}
.status-stale {
  color: color-mix(in srgb, var(--warning) 78%, var(--text-primary));
  border-color: color-mix(in srgb, var(--warning) 45%, transparent);
}
.status-error {
  color: var(--critical);
  border-color: color-mix(in srgb, var(--critical) 40%, transparent);
}
/* Deliberately neutral, not red: "out of reach from here" is a fact about the
   runner's location, not a fault to be chased. */
.status-unreachable {
  color: var(--text-muted);
  border-color: var(--border);
}
.source-error {
  font-size: 11px;
  color: var(--text-muted);
  padding: 0 0 8px;
  max-width: 100%;
  white-space: normal;
}

/* ----------------------------------------------------------------- tooltip */
.tooltip {
  position: fixed;
  pointer-events: none;
  background: var(--text-primary);
  color: var(--surface-1);
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  font-size: 11.5px;
  line-height: 1.45;
  opacity: 0;
  transition: opacity 0.1s;
  z-index: 100;
  max-width: 260px;
  font-variant-numeric: tabular-nums;
}
.tooltip.is-visible {
  opacity: 1;
}
.tooltip b {
  font-weight: 600;
}

/* ------------------------------------------------------------------ footer */
.footer {
  margin-top: 28px;
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
}
.empty {
  color: var(--text-muted);
  font-size: 12.5px;
  padding: 12px 0;
}

/* Privacy mode — blur figures for screen sharing without changing layout. */
body.private .hero-number,
body.private .stat dd,
body.private .alloc-value,
body.private .source-value,
body.private .exp-meta,
body.private .data-table td.num,
body.private .axis-label {
  filter: blur(7px);
  user-select: none;
}

/* A holding excluded from the total stays visible so the call can be checked. */
.row-excluded td {
  opacity: 0.55;
}
.tag-dup {
  font-size: 10px;
  font-weight: 500;
  padding: 1px 5px;
  border-radius: 3px;
  border: 1px solid var(--border);
  color: var(--text-muted);
  vertical-align: middle;
  cursor: help;
}

/* ------------------------------------------------------------- by asset */
.asset-row {
  cursor: pointer;
}
.asset-row:focus-visible {
  outline: 2px solid var(--long);
  outline-offset: -2px;
}
.disclosure {
  color: var(--text-muted);
  font-size: 10px;
  display: inline-block;
  width: 10px;
}
.share-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-end;
}
.share-track {
  width: 62px;
  height: 6px;
  background: var(--wash);
  border-radius: 3px;
  overflow: hidden;
  flex: none;
}
/* One measure, one color: bar length carries magnitude, so colouring by rank
   would encode nothing and cost the only free channel. */
.share-fill {
  height: 100%;
  background: var(--long);
  border-radius: 3px;
}
.share-pct {
  min-width: 42px;
  text-align: right;
  color: var(--text-secondary);
}
.asset-detail td {
  padding: 0 0 8px;
  background: var(--wash);
}
.loc-list {
  display: flex;
  flex-direction: column;
  padding: 6px 0 2px 22px;
}
.loc-row {
  display: grid;
  grid-template-columns: minmax(120px, 1.6fr) 90px 1fr 110px;
  gap: 12px;
  padding: 3px 12px 3px 0;
  font-size: 12px;
  color: var(--text-secondary);
}
.loc-where {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.loc-kind {
  color: var(--text-muted);
  font-size: 11px;
}
.loc-amt,
.loc-val {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.loc-val {
  color: var(--text-primary);
}
@media (max-width: 560px) {
  .loc-row {
    grid-template-columns: 1fr auto;
    row-gap: 1px;
  }
  .loc-kind {
    display: none;
  }
}
.loc-src {
  color: var(--text-muted);
  font-size: 11px;
  margin-left: 6px;
}
.loc-rest .loc-where,
.loc-rest .loc-val {
  color: var(--text-muted);
  font-style: italic;
}
