/* Object Impact Model — themeable analytics UI.
   Two themes share one set of variable names, so every rule below (and every colour read
   from JS) follows whichever theme is active. Light is Metabase-inspired: near-white canvas,
   white cards lifted by soft shadows rather than hard borders, #509EE3 accent. */
:root,
:root[data-theme="light"] {
  --bg: #f9fbfc;
  --panel: #ffffff;
  --panel-2: #f4f6f8;
  --border: #e3e8ec;
  --border-2: #ccd5db;
  --text: #2e353b;
  --text-dim: #5f6b76;
  --text-faint: #949aab;
  --accent: #509ee3;
  --accent-soft: rgba(80, 158, 227, 0.12);
  /* darker than the dark-theme values so they stay legible on white */
  --sev-low: #189f6d;
  --sev-medium: #b8860b;
  --sev-high: #d4691a;
  --sev-critical: #d0342c;
  --kind-signal: #b8860b;
  --kind-receiver: #8b5cf6;
  --kind-action: #0d9aa8;
  --kind-outcome: #d6438f;
  --kind-object: #509ee3;
  --kind-external: #64748b;
  --edge-oo: #b6c0c9;
  --edge-outcome: #d6438f;
  --shadow-1: 0 1px 3px rgba(20, 30, 40, 0.08), 0 1px 2px rgba(20, 30, 40, 0.04);
  --shadow-2: 0 4px 12px rgba(20, 30, 40, 0.10);
  --shadow-pop: 0 8px 24px rgba(20, 30, 40, 0.14);
  --shadow-drawer: -12px 0 40px rgba(20, 30, 40, 0.12);
  --node-stroke-lighten: 0.55;   /* graph nodes: how far to darken strokes for contrast */
  --on-accent: #ffffff;          /* text on an accent-filled button */
  --overlay: rgba(255, 255, 255, 0.94);
  --overlay-2: rgba(255, 255, 255, 0.97);
  --scrim: rgba(15, 25, 35, 0.35);
  --accent-tint: rgba(80, 158, 227, 0.07);
  --accent-press: rgba(80, 158, 227, 0.20);
  --surface-soft: rgba(20, 30, 40, 0.02);
  --sev-low-bg: rgba(24, 159, 109, 0.12);
  --sev-medium-bg: rgba(184, 134, 11, 0.12);
  --sev-high-bg: rgba(212, 105, 26, 0.12);
  --sev-critical-bg: rgba(208, 52, 44, 0.11);
  --ext-tint: rgba(100, 116, 139, 0.07);
  --ext-label: #64748b;
  --node-lit-stroke: #1f2933;
  --label-shadow: 0 1px 3px rgba(255, 255, 255, 0.95);
  --radius: 8px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: "SF Mono", "JetBrains Mono", Menlo, monospace;
}
:root[data-theme="dark"] {
  --bg: #0b0e14;
  --panel: #11151f;
  --panel-2: #171c29;
  --border: #232a3a;
  --border-2: #2e3750;
  --text: #dbe2f0;
  --text-dim: #8b94ab;
  --text-faint: #5b6379;
  --accent: #4c9aff;
  --accent-soft: rgba(76, 154, 255, 0.14);
  --sev-low: #57d9a3;
  --sev-medium: #ffc400;
  --sev-high: #ff8b00;
  --sev-critical: #ef5350;
  --kind-signal: #ffc400;
  --kind-receiver: #b586f9;
  --kind-action: #79e2f2;
  --kind-outcome: #f883c4;
  --kind-object: #4c9aff;
  --kind-external: #8fa3bf;
  --edge-oo: #5b6379;
  --edge-outcome: #f883c4;
  --shadow-1: none;
  --shadow-2: none;
  --shadow-pop: 0 8px 24px rgba(0, 0, 0, 0.6);
  --shadow-drawer: -12px 0 40px rgba(0, 0, 0, 0.45);
  --node-stroke-lighten: 1;
  --on-accent: #06131f;
  --overlay: rgba(17, 21, 31, 0.92);
  --overlay-2: rgba(13, 17, 26, 0.96);
  --scrim: rgba(4, 6, 10, 0.6);
  --accent-tint: rgba(76, 154, 255, 0.05);
  --accent-press: rgba(76, 154, 255, 0.22);
  --surface-soft: rgba(255, 255, 255, 0.015);
  --sev-low-bg: rgba(87, 217, 163, 0.15);
  --sev-medium-bg: rgba(255, 196, 0, 0.13);
  --sev-high-bg: rgba(255, 139, 0, 0.15);
  --sev-critical-bg: rgba(239, 83, 80, 0.16);
  --ext-tint: rgba(143, 163, 191, 0.06);
  --ext-label: #b9a3d6;
  --node-lit-stroke: #ffffff;
  --label-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  font-size: 14px;
}

/* ---------- Layout ---------- */
#app { display: flex; flex-direction: column; height: 100vh; }
header {
  display: flex; align-items: center; gap: 16px;
  padding: 0 16px; height: 52px; flex-shrink: 0;
  background: var(--panel); border-bottom: 1px solid var(--border);
  z-index: 30;
}
.brand { display: flex; align-items: baseline; gap: 8px; white-space: nowrap; }
.brand .logo { font-weight: 700; font-size: 15px; letter-spacing: 0.5px; color: var(--accent); }
.brand .sub { font-size: 11px; color: var(--text-dim); }
.brand .edition-link {
  font-size: 10.5px; color: var(--text-dim); text-decoration: none;
  border: 1px solid var(--border-2); border-radius: 10px; padding: 1px 8px; margin-left: 2px;
  white-space: nowrap;
}
.brand .edition-link:hover { border-color: var(--accent); color: var(--accent); }
.brand .edition-switcher {
  font-size: 10.5px; color: var(--text-dim); background: var(--bg); font-family: var(--font);
  border: 1px solid var(--border-2); border-radius: 10px; padding: 2px 6px; margin-left: 2px;
  white-space: nowrap; cursor: pointer; max-width: 190px;
}
.brand .edition-switcher:hover, .brand .edition-switcher:focus { border-color: var(--accent); color: var(--accent); }
.brand .edition-switcher optgroup { font-style: normal; font-weight: 700; color: var(--text); background: var(--panel); }
.brand .edition-switcher option { color: var(--text); background: var(--panel); font-weight: 400; }
nav.tabs { display: flex; gap: 2px; margin-left: 8px; }
nav.tabs button {
  background: none; border: none; color: var(--text-dim); font-family: var(--font);
  font-size: 13px; padding: 6px 12px; cursor: pointer; border-radius: 6px;
  white-space: nowrap;
}
nav.tabs button:hover { color: var(--text); background: var(--panel-2); }
nav.tabs button.active { color: var(--accent); background: var(--accent-soft); font-weight: 600; }

.omnibox { position: relative; margin-left: auto; width: 320px; min-width: 180px; }
.omnibox input {
  width: 100%; padding: 7px 12px 7px 30px; border-radius: 6px;
  border: 1px solid var(--border-2); background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 13px; outline: none;
}
.omnibox input:focus { border-color: var(--accent); }
.omnibox .icon { position: absolute; left: 9px; top: 7px; color: var(--text-dim); font-size: 13px; }
.omnibox .results {
  position: absolute; top: 38px; left: 0; right: 0; max-height: 420px; overflow-y: auto;
  background: var(--panel-2); border: 1px solid var(--border-2); border-radius: var(--radius);
  box-shadow: var(--shadow-pop); display: none; z-index: 100;
}
.omnibox .results.open { display: block; }
.omnibox .result {
  padding: 8px 12px; cursor: pointer; display: flex; align-items: center; gap: 8px;
  border-bottom: 1px solid var(--border);
}
.omnibox .result:last-child { border-bottom: none; }
.omnibox .result:hover, .omnibox .result.sel { background: var(--accent-soft); }
.omnibox .result .kind {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px;
  padding: 2px 6px; border-radius: 4px; background: var(--panel); color: var(--text-dim);
  flex-shrink: 0;
}
.omnibox .result .name { font-size: 13px; }

#helpBtn, #themeBtn {
  width: 26px; height: 26px; border-radius: 50%; margin-left: 10px; flex-shrink: 0;
  background: var(--panel-2); border: 1px solid var(--border-2); color: var(--text-dim);
  font-family: var(--font); font-weight: 700; font-size: 13px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; line-height: 1;
}
#themeBtn { margin-left: auto; font-size: 14px; }
.omnibox + #themeBtn { margin-left: 10px; }
#helpBtn:hover, #themeBtn:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- Guided tour ---------- */
.tour-overlay {
  display: none; position: fixed; inset: 0; background: var(--scrim); z-index: 500;
}
.tour-target-glow {
  position: relative; z-index: 501; outline: 2px solid var(--accent); outline-offset: 3px;
  border-radius: 6px; box-shadow: 0 0 0 6px var(--accent-press), 0 0 24px var(--accent-soft);
}
.tour-tooltip {
  display: none; position: fixed; z-index: 502; width: 300px; max-width: calc(100vw - 20px);
  background: var(--panel); border: 1px solid var(--accent); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow-pop);
}
.tour-tooltip .tt-step { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: var(--accent); margin-bottom: 4px; }
.tour-tooltip .tt-title { font-size: 14.5px; font-weight: 700; margin-bottom: 6px; }
.tour-tooltip .tt-body { font-size: 12.5px; line-height: 1.55; color: var(--text-dim); margin-bottom: 12px; }
.tour-tooltip .tt-actions { display: flex; justify-content: flex-end; gap: 8px; }
.tour-tooltip .tt-actions button {
  font-family: var(--font); font-size: 12px; font-weight: 600; padding: 6px 12px; border-radius: 6px; cursor: pointer;
}
.tour-tooltip .tt-next { background: var(--accent); border: 1px solid var(--accent); color: var(--on-accent); }
.tour-tooltip .tt-back, .tour-tooltip .tt-skip { background: none; border: 1px solid var(--border-2); color: var(--text-dim); }
.tour-tooltip .tt-back { margin-right: auto; }
.omnibox .result .ctx { font-size: 11px; color: var(--text-dim); margin-left: auto; text-align: right; max-width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#body { display: flex; flex: 1; min-height: 0; position: relative; }

/* ---------- Left rail ---------- */
aside#rail {
  width: 230px; flex-shrink: 0; overflow-y: auto;
  background: var(--panel); border-right: 1px solid var(--border);
  padding: 12px;
}
aside#rail h3 {
  font-size: 10px; text-transform: uppercase; letter-spacing: 1px;
  color: var(--text-dim); margin: 14px 0 6px;
}
aside#rail h3:first-child { margin-top: 0; }
.rail-row { display: flex; align-items: center; gap: 7px; padding: 3px 2px; cursor: pointer; border-radius: 4px; font-size: 12.5px; color: var(--text); user-select: none; }
.rail-row:hover { background: var(--panel-2); }
.rail-row input { accent-color: var(--accent); cursor: pointer; }
.rail-row .swatch { width: 9px; height: 9px; border-radius: 2px; flex-shrink: 0; }
.rail-row .count { margin-left: auto; font-size: 10.5px; color: var(--text-dim); font-family: var(--mono); }
.rail-note { font-size: 11px; color: var(--text-dim); line-height: 1.5; padding: 4px 2px; }
.rail-btn {
  width: 100%; margin-top: 6px; padding: 6px; border-radius: 6px; cursor: pointer;
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border-2);
  font-family: var(--font); font-size: 12px;
}
.rail-btn:hover { border-color: var(--accent); color: var(--accent); }
.rail-btn.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* ---------- Saved views ---------- */
.saved-view-row {
  display: flex; align-items: center; gap: 6px; padding: 4px 2px; border-radius: 4px; font-size: 12.5px;
}
.saved-view-row:hover { background: var(--panel-2); }
.saved-view-row .sv-name { flex: 1; cursor: pointer; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.saved-view-row .sv-name:hover { color: var(--accent); }
.saved-view-row .sv-name::before { content: "★ "; color: var(--accent); }
.saved-view-row .sv-remove {
  background: none; border: none; color: var(--text-faint); cursor: pointer; font-size: 11px; padding: 2px 4px; flex-shrink: 0;
}
.saved-view-row .sv-remove:hover { color: var(--sev-critical); }
.save-view-form { margin-top: 6px; }
.save-view-form .sv-name-input {
  width: 100%; background: var(--bg); border: 1px solid var(--border-2); border-radius: 6px;
  color: var(--text); font-family: var(--font); font-size: 12px; padding: 6px 8px; margin-bottom: 6px;
}
.save-view-form .sv-form-actions { display: flex; gap: 6px; }
.save-view-form .sv-save, .save-view-form .sv-cancel {
  font-family: var(--font); font-size: 12px; font-weight: 600; padding: 5px 12px; border-radius: 6px; cursor: pointer;
}
.save-view-form .sv-save { background: var(--accent); border: 1px solid var(--accent); color: var(--on-accent); }
.save-view-form .sv-cancel { background: none; border: 1px solid var(--border-2); color: var(--text-dim); }

/* ---------- Main ---------- */
main#main { flex: 1; min-width: 0; position: relative; overflow: hidden; background: var(--bg); }
.view { position: absolute; inset: 0; display: none; overflow-y: auto; }
.view.active { display: block; }
#view-graph { overflow: hidden; }
#view-graph svg { display: block; width: 100%; height: 100%; cursor: grab; }
#view-graph svg:active { cursor: grabbing; }

.graph-hud {
  position: absolute; left: 12px; top: 12px; z-index: 10;
  display: flex; flex-direction: column; gap: 6px; pointer-events: none;
}
.hud-chip {
  pointer-events: auto; background: var(--overlay); border: 1px solid var(--border-2);
  border-radius: 6px; padding: 6px 10px; font-size: 12px; color: var(--text-dim);
  max-width: 380px; backdrop-filter: blur(4px);
}
.hud-chip b { color: var(--text); }
.hud-chip .x { cursor: pointer; color: var(--accent); margin-left: 8px; }

/* on-canvas legend */
.graph-legend {
  position: absolute; left: 12px; bottom: 12px; z-index: 10;
  background: var(--overlay); border: 1px solid var(--border-2);
  border-radius: 8px; padding: 10px 12px; max-width: 260px; backdrop-filter: blur(4px);
}
.graph-legend .lg-title { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-dim); margin-bottom: 7px; }
.graph-legend .lg-shapes { display: flex; gap: 14px; margin-bottom: 9px; }
.graph-legend .lg-shape { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--text); }
.graph-legend .lg-shape svg { flex-shrink: 0; }
.graph-legend .lg-cats { display: grid; grid-template-columns: 1fr 1fr; gap: 3px 10px; }
.graph-legend .lg-cat { display: flex; align-items: center; gap: 6px; font-size: 10.5px; color: var(--text-dim); cursor: pointer; }
.graph-legend .lg-cat:hover { color: var(--text); }
.graph-legend .lg-cat.off { opacity: 0.35; text-decoration: line-through; }
.graph-legend .lg-cat .sw { width: 9px; height: 9px; border-radius: 2px; flex-shrink: 0; }
.graph-legend .lg-collapse { position: absolute; top: 8px; right: 10px; cursor: pointer; color: var(--text-dim); font-size: 12px; }
.graph-legend .lg-collapse:hover { color: var(--text); }
.graph-legend.collapsed .lg-shapes, .graph-legend.collapsed .lg-cats, .graph-legend.collapsed .lg-edge-note { display: none; }
.graph-legend .lg-edge-note { font-size: 10px; color: var(--text-faint); line-height: 1.4; margin-top: 9px; padding-top: 8px; border-top: 1px dashed var(--border-2); }

/* start-here hint chips */
.start-hint { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.start-hint .hub {
  cursor: pointer; padding: 3px 9px; border-radius: 20px; font-size: 11.5px;
  background: var(--accent-soft); border: 1px solid var(--accent); color: var(--accent);
}
.start-hint .hub:hover { background: var(--accent); color: var(--on-accent); }

.graph-tooltip {
  position: fixed; z-index: 200; pointer-events: auto; display: none;
  background: var(--overlay-2); border: 1px solid var(--border-2); border-radius: var(--radius);
  padding: 10px 12px; max-width: 300px; box-shadow: var(--shadow-pop);
}
.graph-tooltip .t-kind { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-dim); }
.graph-tooltip .t-kind .t-isolate-cat { color: var(--accent); cursor: pointer; text-transform: none; letter-spacing: normal; }
.graph-tooltip .t-kind .t-isolate-cat:hover { text-decoration: underline; }
.graph-tooltip .t-name { font-size: 14px; font-weight: 600; margin: 2px 0 4px; }
.graph-tooltip .t-def { font-size: 12px; color: var(--text-dim); line-height: 1.45; }

/* graph elements */
.link { stroke-opacity: 0.30; transition: stroke-opacity 0.15s; }
/* relationship-strength tiers (object↔object edges only) — how many matrix conditions
   actually connect the two objects. Declared before .dim/.lit/.hidden (same specificity)
   so those interaction states still win when applied. */
.link.oo-w0 { stroke-opacity: 0.20; }
.link.oo-w1 { stroke-opacity: 0.35; }
.link.oo-w2 { stroke-opacity: 0.48; }
.link.oo-w3 { stroke-opacity: 0.60; }
.link.oo-w4 { stroke-opacity: 0.72; }
.link.dim { stroke-opacity: 0.04; }
.link.lit { stroke-opacity: 0.95; stroke-width: 2px; }
.link.hidden { stroke-opacity: 0; }
.link-oimpact { stroke-opacity: 0.22; }
.node { cursor: pointer; }
.node text {
  font-family: var(--font); fill: var(--text); pointer-events: none;
  /* paint-order puts the stroke down first, so it knocks a halo out of whatever is behind
     the glyphs — link lines no longer read through the text. --bg follows the theme. */
  paint-order: stroke;
  stroke: var(--bg); stroke-width: 3px; stroke-linejoin: round;
}
/* Every node is labelled, so non-priority names read as a quieter layer than the hubs. */
.node text.minor { fill: var(--text-dim); }
/* Hairline tying a nudged label back to the node it belongs to. */
.node .leader { stroke: var(--border-2); stroke-width: 1px; opacity: 0.55; pointer-events: none; }
.node.dim { opacity: 0.12; }
.node.lit circle, .node.lit rect, .node.lit path { stroke: var(--node-lit-stroke); stroke-width: 1.6px; }

/* ---------- Capability map ---------- */
#view-capability { padding: 20px; }
.cap-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.cap-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;  box-shadow: var(--shadow-1); }
.cap-card .cap-head { padding: 10px 14px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 8px; }
.cap-card .cap-head .swatch { width: 10px; height: 10px; border-radius: 3px; }
.cap-card .cap-head .t { font-weight: 600; font-size: 13.5px; }
.cap-card .cap-head .n { margin-left: auto; font-size: 11px; color: var(--text-dim); font-family: var(--mono); }
.cap-card .cap-desc { padding: 8px 14px 0; font-size: 11.5px; color: var(--text-dim); line-height: 1.45; }
.cap-severity-bar { display: flex; height: 16px; margin: 10px 14px 0; border-radius: 3px; overflow: hidden; background: var(--panel-2); }
.cap-severity-bar .csb-seg { display: flex; align-items: center; justify-content: center;
  overflow: hidden; font-size: 10px; font-weight: 700; color: #fff;
  font-variant-numeric: tabular-nums; text-shadow: 0 0 3px rgba(0, 0, 0, .5); }
.cap-severity-bar .csb-seg.sev-Critical { background: var(--sev-critical); }
.cap-severity-bar .csb-seg.sev-High { background: var(--sev-high); }
.cap-severity-bar .csb-seg.sev-Medium { background: var(--sev-medium); }
.cap-severity-bar .csb-seg.sev-Low { background: var(--sev-low); }
.cap-card .chips { padding: 10px 12px 12px; display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 4px 9px; border-radius: 20px;
  background: var(--panel-2); border: 1px solid var(--border-2); font-size: 12px;
  cursor: pointer; color: var(--text); white-space: nowrap;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip .dot { width: 6px; height: 6px; border-radius: 50%; }
.chip.star::after { content: "★"; font-size: 9px; color: var(--sev-medium); }

/* ---------- Matrix ---------- */
#view-matrix { padding: 16px 20px; }
.matrix-toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.matrix-toolbar input, .matrix-toolbar select {
  background: var(--panel); color: var(--text); border: 1px solid var(--border-2);
  border-radius: 6px; padding: 6px 10px; font-family: var(--font); font-size: 12.5px; outline: none;
}
.matrix-toolbar input:focus, .matrix-toolbar select:focus { border-color: var(--accent); }
.matrix-toolbar input { width: 240px; }
.matrix-toolbar .spacer { flex: 1; }
.matrix-count { font-size: 12px; color: var(--text-dim); font-family: var(--mono); }
.btn {
  background: var(--accent-soft); color: var(--accent); border: 1px solid var(--accent);
  border-radius: 6px; padding: 6px 12px; font-family: var(--font); font-size: 12.5px; cursor: pointer;
}
.btn:hover { background: var(--accent); color: var(--on-accent); }
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); max-height: calc(100vh - 170px); }
table.matrix { border-collapse: collapse; width: 100%; min-width: 1100px; font-size: 12.5px; }
table.matrix th {
  position: sticky; top: 0; background: var(--panel-2); text-align: left; padding: 9px 10px;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-dim);
  border-bottom: 1px solid var(--border-2); cursor: pointer; user-select: none; white-space: nowrap; z-index: 5;
}
table.matrix th:hover { color: var(--accent); }
table.matrix td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; line-height: 1.4; }
table.matrix tr:hover td { background: var(--accent-tint); }
table.matrix td .link-like { color: var(--accent); cursor: pointer; }
table.matrix td .link-like:hover { text-decoration: underline; }
.sev { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.sev-Low { background: var(--sev-low-bg); color: var(--sev-low); }
.sev-Medium { background: var(--sev-medium-bg); color: var(--sev-medium); }
.sev-High { background: var(--sev-high-bg); color: var(--sev-high); }
.sev-Critical { background: var(--sev-critical-bg); color: var(--sev-critical); }

/* ---------- Chains ---------- */
#view-chains { display: none; height: 100%; }
#view-chains.active { display: flex; }
.chain-list { width: 300px; flex-shrink: 0; overflow-y: auto; border-right: 1px solid var(--border); background: var(--panel); }
.chain-item { padding: 12px 14px; border-bottom: 1px solid var(--border); cursor: pointer; }
.chain-item:hover { background: var(--panel-2); }
.chain-item.active { background: var(--accent-soft); border-left: 3px solid var(--accent); padding-left: 11px; }
.chain-item .t { font-size: 13px; font-weight: 600; margin-bottom: 3px; }
.chain-item .d { font-size: 11.5px; color: var(--text-dim); line-height: 1.4; }
.chain-detail { flex: 1; overflow-y: auto; padding: 20px 26px; }
.chain-detail h2 { font-size: 18px; margin-bottom: 6px; }
.chain-detail .desc { color: var(--text-dim); font-size: 13px; line-height: 1.5; max-width: 720px; margin-bottom: 8px; }
.chain-actions { margin: 10px 0 18px; display: flex; gap: 8px; }
.chain-steps { position: relative; max-width: 780px; }
.chain-step { display: flex; gap: 14px; position: relative; padding-bottom: 20px; }
.chain-step::before {
  content: ""; position: absolute; left: 15px; top: 32px; bottom: -2px; width: 2px;
  background: var(--border-2);
}
.chain-step:last-child::before { display: none; }
.chain-step .marker {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0; z-index: 1;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; font-family: var(--mono);
  border: 2px solid var(--border-2); background: var(--panel);
}
.chain-step .content { padding-top: 2px; }
.chain-step .node-name { font-size: 14px; font-weight: 600; cursor: pointer; }
.chain-step .node-name:hover { color: var(--accent); }
.chain-step .node-kind { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-dim); margin-left: 8px; }
.chain-step .note { font-size: 12.5px; color: var(--text-dim); margin-top: 3px; line-height: 1.45; }

/* ---------- Signals ---------- */
#view-signals { padding: 16px 20px; }
.sig-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 12px; }
.sig-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; cursor: pointer;  box-shadow: var(--shadow-1); }
.sig-card:hover { border-color: var(--kind-signal); }
.sig-card .t { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 13.5px; margin-bottom: 5px; }
.sig-card .t::before { content: "◆"; color: var(--kind-signal); font-size: 10px; }
.sig-card .d { font-size: 12px; color: var(--text-dim); line-height: 1.45; margin-bottom: 8px; }
.sig-card .meta { display: flex; flex-wrap: wrap; gap: 5px; }

/* ---------- Outcomes ---------- */
#view-outcomes { padding: 16px 20px; }
.out-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; margin-bottom: 18px; }
.out-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; cursor: pointer;
 box-shadow: var(--shadow-1); }
.out-card:hover, .out-card.active { border-color: var(--kind-outcome); }
.out-card.active { background: var(--accent-tint); }
.out-card .t { font-weight: 700; font-size: 14px; color: var(--kind-outcome); margin-bottom: 4px; }
.out-card .d { font-size: 12px; color: var(--text-dim); line-height: 1.45; margin-bottom: 6px; }
.out-card .n { font-size: 11px; font-family: var(--mono); color: var(--text-dim); }
.out-detail h3 { font-size: 14px; margin: 14px 0 8px; color: var(--text); }

/* ---------- Drawer ---------- */
#drawer {
  position: absolute; top: 0; right: 0; bottom: 0; width: 420px; max-width: 92vw;
  background: var(--panel); border-left: 1px solid var(--border-2);
  transform: translateX(100%); transition: transform 0.22s ease, width 0.2s ease; z-index: 40;
  display: flex; flex-direction: column; box-shadow: var(--shadow-drawer);
}
#drawer.open { transform: translateX(0); }
#drawer.wide { width: min(860px, 65vw); }
#drawer .drawer-head .expand {
  background: none; border: 1px solid var(--border-2); color: var(--text-dim);
  font-size: 14px; cursor: pointer; padding: 3px 8px; border-radius: 5px; flex-shrink: 0;
}
#drawer .drawer-head .expand:hover { color: var(--text); background: var(--panel-2); }
#drawer .drawer-head {
  padding: 14px 18px; border-bottom: 1px solid var(--border); flex-shrink: 0;
  display: flex; align-items: flex-start; gap: 10px;
}
#drawer .drawer-head .kind-tag {
  font-size: 10px; text-transform: uppercase; letter-spacing: 1px; padding: 3px 8px;
  border-radius: 4px; background: var(--panel-2); color: var(--text-dim); margin-bottom: 4px; display: inline-block;
}
#drawer .drawer-head .kind-tag .drawer-isolate-cat { color: var(--accent); cursor: pointer; }
#drawer .drawer-head .kind-tag .drawer-isolate-cat:hover { text-decoration: underline; }
#drawer .drawer-head h2 { font-size: 17px; line-height: 1.3; }
#drawer .drawer-head .close {
  margin-left: auto; background: none; border: none; color: var(--text-dim);
  font-size: 20px; cursor: pointer; padding: 2px 6px; border-radius: 4px;
}
#drawer .drawer-head .close:hover { color: var(--text); background: var(--panel-2); }
#drawer .drawer-body { overflow-y: auto; padding: 14px 18px 30px; flex: 1; }
#drawer .drawer-body h4 {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-dim);
  margin: 16px 0 6px;
}
#drawer .drawer-body h4:first-child { margin-top: 0; }
#drawer .drawer-body p { font-size: 13px; line-height: 1.55; color: var(--text); }
#drawer .drawer-body p.dim { color: var(--text-dim); font-size: 12.5px; }
#drawer .drawer-body ul { list-style: none; }
#drawer .drawer-body ul li {
  font-size: 12.5px; line-height: 1.5; color: var(--text); padding: 3px 0 3px 14px; position: relative;
}
#drawer .drawer-body ul li::before { content: "–"; position: absolute; left: 0; color: var(--text-dim); }
#drawer .chips { display: flex; flex-wrap: wrap; gap: 6px; }
#drawer .mini-row {
  border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; margin-bottom: 6px;
  font-size: 12px; line-height: 1.45;
}
#drawer .mini-row .c { color: var(--text); }
#drawer .mini-row .m { color: var(--text-dim); margin-top: 3px; }

/* ---------- Drawer: two-tab business view ---------- */
#drawer .drawer-tabs {
  display: flex; gap: 4px; margin: -2px 0 14px; position: sticky; top: 0;
  background: var(--panel); padding-top: 2px; z-index: 3;
}
#drawer .drawer-tab {
  flex: 1; text-align: center; padding: 8px 10px; cursor: pointer; font-size: 12.5px;
  color: var(--text-dim); border: 1px solid var(--border); border-radius: 7px; background: var(--bg);
  font-weight: 600; user-select: none;
}
#drawer .drawer-tab:hover { color: var(--text); border-color: var(--border-2); }
#drawer .drawer-tab.active { color: var(--accent); background: var(--accent-soft); border-color: var(--accent); }
#drawer .drawer-tab .tcount { font-weight: 400; opacity: 0.7; font-size: 11px; }
#drawer .tab-panel { display: none; }
#drawer .tab-panel.active { display: block; }

/* lead summary */
#drawer .lead {
  font-size: 13.5px; line-height: 1.55; color: var(--text);
  border-left: 3px solid var(--accent); padding: 2px 0 2px 12px; margin-bottom: 4px;
}
#drawer .lead .why { display: block; color: var(--text-dim); font-size: 12.5px; margin-top: 5px; }

/* vertical lineage */
#drawer .lineage {
  border: 1px solid var(--border); border-radius: 8px; padding: 12px 12px 6px; margin: 6px 0 4px;
  background: var(--surface-soft);
}
#drawer .lin-stage { text-align: center; }
#drawer .lin-label {
  font-size: 9.5px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-dim); margin-bottom: 5px;
}
#drawer .lin-stage .chips { justify-content: center; }
#drawer .lin-self {
  display: inline-block; font-weight: 700; font-size: 13.5px; padding: 6px 14px; border-radius: 8px;
  background: var(--accent-soft); border: 1px solid var(--accent); color: var(--accent);
}
#drawer .lin-arrow { text-align: center; color: var(--text-faint); font-size: 14px; line-height: 1.4; margin: 3px 0; }

/* recommendation plays */
#drawer .play {
  border: 1px solid var(--border); border-left-width: 3px; border-radius: 7px;
  padding: 9px 11px; margin-bottom: 9px; background: var(--panel-2);
}
#drawer .play.sv-Critical { border-left-color: var(--sev-critical); }
#drawer .play.sv-High { border-left-color: var(--sev-high); }
#drawer .play.sv-Medium { border-left-color: var(--sev-medium); }
#drawer .play.sv-Low { border-left-color: var(--sev-low); }
#drawer .play .play-if { font-size: 13px; color: var(--text); font-weight: 600; margin: 5px 0 6px; line-height: 1.4; }
#drawer .play .play-do, #drawer .play .play-protect { font-size: 12.5px; color: var(--text-dim); line-height: 1.5; margin-top: 4px; display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }
#drawer .play .play-do b, #drawer .play .play-protect b { color: var(--text); font-weight: 500; }
#drawer .play .play-watch { font-size: 11.5px; color: var(--text-dim); margin-top: 7px; padding-top: 6px; border-top: 1px dashed var(--border-2); }
#drawer .play .play-watch b { color: var(--accent); font-weight: 500; }
#drawer .watch-item { display: flex; align-items: flex-start; gap: 8px; font-size: 12.5px; line-height: 1.45; padding: 4px 0; color: var(--text); }
#drawer .watch-item .sev { flex-shrink: 0; }
#drawer .metric-tags { display: flex; flex-wrap: wrap; gap: 5px; }
#drawer .metric-tag { font-size: 11.5px; padding: 3px 9px; border-radius: 5px; background: var(--panel-2); border: 1px solid var(--border); color: var(--text-dim); }

/* rail is graph-only; hide it on every other view and let content use full width */
#body.no-rail aside#rail { display: none; }

/* ---------- Diagnose CTA button (in drawer) ---------- */
#drawer .diagnose-btn {
  display: block; width: 100%; margin: 4px 0 2px; padding: 9px 12px; cursor: pointer;
  background: var(--accent-soft); border: 1px solid var(--accent); color: var(--accent);
  border-radius: 7px; font-size: 12.5px; font-weight: 600; font-family: var(--font); text-align: left;
}
#drawer .diagnose-btn:hover { background: var(--accent-press); }

/* ---------- External-forces lineage stage ---------- */
#drawer .lin-stage.external-stage { padding: 8px 8px 4px; border: 1px dashed var(--kind-receiver); border-radius: 8px; background: var(--ext-tint); }
#drawer .lin-stage.external-stage .lin-label { color: var(--ext-label); }

/* Internal ‖ External branches (merge into the object below). Stacked full-width, not
   side-by-side — at higher chip counts (e.g. ICICI's macro external factors) a 50/50 split left
   too little room per branch and chips wrapped onto several lines each, reading as cramped and
   overlapping. Each branch now gets the drawer's full width. */
#drawer .lin-parallel { display: flex; flex-direction: column; gap: 8px; }
#drawer .lin-branch { width: 100%; border: 1px solid var(--border); border-radius: 8px; padding: 8px 8px 4px; }
#drawer .lin-branch.internal { border-top: 2px solid var(--accent); background: var(--accent-soft); }
#drawer .lin-branch.external { border: 1px dashed var(--kind-receiver); background: var(--ext-tint); }
#drawer .lin-branch.external .lin-label { color: var(--ext-label); }
#drawer .lin-branch .chips { justify-content: flex-start; }
#drawer .lin-branch .chip { white-space: normal; max-width: 100%; word-break: break-word; text-align: left; }

/* ---------- Hedge playbook card ---------- */
#drawer .play.hedge { border-left-color: var(--kind-external); }
#drawer .play.hedge .hedge-tag { display: inline-block; font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: var(--ext-label); background: var(--ext-tint); border-radius: 4px; padding: 2px 7px; margin-bottom: 6px; }
#drawer .play.hedge .play-if { font-weight: 500; }

/* ---------- Hero tab ---------- */
#tabs button.tab-hero { color: var(--accent); }
#tabs button.tab-hero.active { color: var(--on-accent); }

/* ---------- External Factors dictionary ---------- */
#view-external { padding: 20px; }
.xf-intro { max-width: 900px; margin-bottom: 18px; }
.xf-intro h2 { font-size: 18px; margin-bottom: 6px; }
.xf-intro p { font-size: 13px; color: var(--text-dim); line-height: 1.55; }
.xf-group { margin-bottom: 22px; }
.xf-group-head { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; margin-bottom: 3px; }
.xf-group-head .swatch { width: 11px; height: 11px; border-radius: 3px; }
.xf-group-head .n { margin-left: 6px; font-size: 11px; color: var(--text-dim); background: var(--panel-2); border-radius: 10px; padding: 1px 8px; }
.xf-group-desc { font-size: 12px; color: var(--text-dim); margin-bottom: 10px; }
.xf-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.xf-card { background: var(--panel); border: 1px solid var(--border); border-left: 3px solid var(--border-2); border-radius: var(--radius); padding: 11px 13px; cursor: pointer;  box-shadow: var(--shadow-1); }
.xf-card:hover { border-color: var(--border-2); background: var(--panel-2); }
.xf-card .t { display: flex; align-items: baseline; gap: 8px; font-weight: 600; font-size: 13.5px; margin-bottom: 5px; flex-wrap: wrap; }
.xf-card .t .ctrl { font-size: 10.5px; font-weight: 400; color: var(--text-dim); margin-left: auto; }
.xf-card .d { font-size: 12px; color: var(--text-dim); line-height: 1.45; margin-bottom: 7px; }
.xf-card .hits { font-size: 11px; color: var(--text-faint); }

/* ---------- Diagnose view ---------- */
#view-diagnose { overflow: hidden; }
.dg-wrap { display: flex; height: 100%; }
.dg-picker { width: 240px; flex-shrink: 0; overflow-y: auto; border-right: 1px solid var(--border); background: var(--panel); padding: 16px 14px 30px; }
.dg-picker-head { font-size: 13px; font-weight: 700; margin-bottom: 4px; }
.dg-picker-sub { font-size: 11.5px; color: var(--text-dim); line-height: 1.5; margin-bottom: 14px; }
.dg-pick-group { margin-bottom: 12px; }
.dg-pick-area { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-faint); margin-bottom: 5px; }
.dg-pick { display: block; width: 100%; text-align: left; background: none; border: 1px solid transparent; color: var(--text-dim); font-family: var(--font); font-size: 12.5px; padding: 6px 9px; border-radius: 6px; cursor: pointer; margin-bottom: 2px; }
.dg-pick:hover { color: var(--text); background: var(--panel-2); }
.dg-pick.active { color: var(--accent); background: var(--accent-soft); border-color: var(--accent); font-weight: 600; }

.dg-panel { flex: 1; min-width: 0; overflow-y: auto; padding: 22px 26px 40px; }
.dg-empty { color: var(--text-faint); font-size: 14px; margin-top: 40px; }
.dg-head { margin-bottom: 18px; }
.dg-diag { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-dim); }
.dg-diag .dir { color: var(--sev-high); font-weight: 700; margin-left: 4px; }
.dg-head h2 { font-size: 22px; margin: 4px 0 6px; }
.dg-def { font-size: 13px; color: var(--text-dim); line-height: 1.5; max-width: 760px; }
.dg-formula { display: inline-block; margin-top: 9px; font-family: var(--mono); font-size: 12px; color: var(--text); background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px; }
.dg-rel { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }

.dg-triage { background: var(--panel); border: 1px solid var(--border-2); border-radius: 10px; padding: 14px 16px; margin-bottom: 20px; }
.dg-triage-likely { font-size: 13px; margin-bottom: 12px; line-height: 1.5; }
.dg-triage-likely b { color: var(--text); }
.dg-triage-title { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-dim); margin-bottom: 8px; }
.dg-triage-list { list-style: none; counter-reset: t; margin: 0; padding: 0; }
.dg-triage-list li { display: flex; align-items: baseline; gap: 10px; padding: 4px 0; counter-increment: t; }
.dg-triage-list li::before { content: counter(t); flex-shrink: 0; width: 18px; height: 18px; line-height: 18px; text-align: center; font-size: 11px; font-weight: 700; border-radius: 50%; background: var(--panel-2); color: var(--text-dim); }
.dg-triage-item { background: none; border: none; font-family: var(--font); font-size: 13px; font-weight: 600; cursor: pointer; padding: 0; text-align: left; }
.dg-triage-item.internal { color: var(--accent); }
.dg-triage-item.external { color: var(--sev-high); }
.dg-triage-item:hover { text-decoration: underline; }
.dg-triage-ind { font-size: 11.5px; color: var(--text-faint); }

.dg-lanes { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.dg-lane { border: 1px solid var(--border); border-radius: 10px; padding: 12px; background: var(--panel); }
.dg-lane.internal { border-top: 3px solid var(--accent); }
.dg-lane.external { border-top: 3px solid var(--sev-high); }
.dg-lane-head { font-size: 12.5px; font-weight: 600; color: var(--text-dim); margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.dg-lane-tag { font-size: 9.5px; letter-spacing: 1px; padding: 2px 7px; border-radius: 4px; font-weight: 700; }
.dg-lane.internal .dg-lane-tag { color: var(--accent); background: var(--accent-soft); }
.dg-lane.external .dg-lane-tag { color: var(--sev-high); background: var(--sev-high-bg); }
.dg-lane-empty { font-size: 12px; color: var(--text-faint); }

.dg-driver { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; background: var(--panel-2); border-left: 3px solid var(--border-2);  box-shadow: var(--shadow-1); }
.dg-driver.internal { border-left-color: var(--accent); }
.dg-driver.external { border-left-color: var(--sev-high); }
.dg-driver.flash { animation: dgflash 1.2s ease; }
@keyframes dgflash { 0%,100% { background: var(--panel-2); } 25% { background: var(--accent-press); } }
.dg-driver-label { font-size: 13.5px; font-weight: 600; display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.dg-driver-label .dg-ctrl { font-size: 10px; font-weight: 400; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; margin-left: auto; }
.dg-driver-ind { font-size: 11.5px; color: var(--text-dim); margin: 6px 0; }
.dg-feed { font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--sev-medium); background: var(--sev-medium-bg); border-radius: 4px; padding: 1px 6px; margin-left: 4px; }
.dg-driver-diag { font-size: 12px; color: var(--text-dim); font-style: italic; line-height: 1.45; }
.dg-fix, .dg-hedge { margin-top: 9px; padding-top: 8px; border-top: 1px dashed var(--border-2); display: flex; flex-wrap: wrap; align-items: center; gap: 7px; font-size: 12px; color: var(--text-dim); }
.dg-fix-tag { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--accent); }
.dg-hedge-txt { color: var(--text-dim); }

/* ---------- User-added ("custom") reasons — shared between drawer + Diagnose ---------- */
.chip.chip-custom { border: 1px dashed currentColor; background: transparent; }
.add-reason-slot { margin-top: 6px; text-align: center; }
.add-reason-btn {
  background: none; border: 1px dashed var(--border-2); color: var(--text-dim);
  font-family: var(--font); font-size: 11.5px; padding: 5px 10px; border-radius: 6px; cursor: pointer;
}
.add-reason-btn:hover { color: var(--text); border-color: var(--accent); }
.custom-form { text-align: left; padding-top: 4px; }
.custom-form .cf-label, .custom-form .cf-note {
  width: 100%; background: var(--bg); border: 1px solid var(--border-2); border-radius: 6px;
  color: var(--text); font-family: var(--font); font-size: 12.5px; padding: 6px 8px; margin-bottom: 6px; resize: vertical;
}
.custom-form .cf-actions { display: flex; gap: 6px; }
.custom-form .cf-save, .custom-form .cf-cancel {
  font-family: var(--font); font-size: 12px; font-weight: 600; padding: 5px 12px; border-radius: 6px; cursor: pointer;
}
.custom-form .cf-save { background: var(--accent); border: 1px solid var(--accent); color: var(--on-accent); }
.custom-form .cf-cancel { background: none; border: 1px solid var(--border-2); color: var(--text-dim); }
.remove-custom-btn {
  background: none; border: 1px solid var(--sev-critical); color: var(--sev-critical);
  font-family: var(--font); font-size: 12px; padding: 6px 12px; border-radius: 6px; cursor: pointer;
}
.remove-custom-btn:hover { background: var(--sev-critical-bg); }
#drawer .lin-branch .add-reason-slot { margin-top: 4px; }
.dg-driver.custom { border-style: dashed; }
.dg-custom-actions { margin-top: 8px; padding-top: 6px; border-top: 1px dashed var(--border-2); }
.dg-export-footer { margin-top: 16px; }
.export-link {
  background: none; border: 1px dashed var(--border-2); color: var(--text-dim);
  font-family: var(--font); font-size: 11.5px; padding: 6px 10px; border-radius: 6px; cursor: pointer; width: 100%;
}
.export-link:hover { color: var(--accent); border-color: var(--accent); }

/* ---------- Evidence-grade external factors (drawer) ---------- */
.xf-score-badge {
  font-size: 10.5px; color: var(--accent); background: var(--accent-soft); border: 1px solid var(--accent);
  border-radius: 5px; padding: 2px 8px; margin-left: 2px; white-space: nowrap;
}
#drawer .causal-chain { display: flex; flex-direction: column; gap: 8px; margin-bottom: 4px; }
#drawer .cc-step { border-left: 2px solid var(--border-2); padding-left: 10px; }
#drawer .cc-step-label { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-dim); margin-bottom: 3px; }
#drawer .cc-step ul { margin: 0; }
#drawer .kpi-impact-table { display: flex; flex-direction: column; gap: 6px; }
#drawer .kpi-row { display: flex; align-items: baseline; gap: 8px; font-size: 12.5px; padding: 6px 8px; background: var(--panel-2); border-radius: 6px; flex-wrap: wrap; }
#drawer .kpi-name { font-weight: 600; text-transform: capitalize; min-width: 130px; }
#drawer .kpi-dir.up { color: var(--sev-critical); }
#drawer .kpi-dir.down { color: var(--sev-low); }
#drawer .kpi-range { color: var(--text-dim); font-size: 11.5px; }
#drawer .severity-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 6px; }
#drawer .sg-cell { display: flex; align-items: center; gap: 6px; font-size: 11.5px; padding: 4px 0; }
#drawer .sg-label { color: var(--text-dim); text-transform: capitalize; }
#drawer .cascade-list ul { margin: 0; }
#drawer .case-study-card { border: 1px solid var(--border); border-radius: 7px; padding: 9px 11px; margin-bottom: 8px; background: var(--panel-2); }
#drawer .cs-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
#drawer .cs-year { font-size: 11px; color: var(--text-dim); font-family: var(--mono); }
#drawer .cs-source { font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.5px; padding: 1px 7px; border-radius: 4px; }
#drawer .cs-source.measured { color: var(--sev-low); background: var(--sev-low-bg); }
#drawer .cs-source.analyst_estimate { color: var(--sev-medium); background: var(--sev-medium-bg); }
#drawer .cs-event { font-size: 12.5px; font-weight: 500; margin-bottom: 4px; }
#drawer .cs-impact { font-size: 12px; line-height: 1.45; }
#drawer .monitoring-table { display: flex; flex-direction: column; gap: 5px; }
#drawer .mon-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: baseline; font-size: 12px; padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px; }
#drawer .mon-signal { font-weight: 600; flex: 1 1 160px; }
#drawer .mon-source { font-size: 11px; }
#drawer .mon-meta { font-size: 10.5px; color: var(--text-faint); }

/* ---------- Research brief (External Factors dictionary, per category) ---------- */
.research-brief {
  margin: 8px 0 14px; border: 1px solid var(--border-2); border-radius: 8px; padding: 10px 14px;
  background: var(--accent-tint);
}
.research-brief summary { cursor: pointer; font-size: 12.5px; font-weight: 600; color: var(--text); list-style: none; }
.research-brief summary::-webkit-details-marker { display: none; }
.research-brief[open] summary { margin-bottom: 10px; }
.research-brief h4 { font-size: 10.5px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-dim); margin: 12px 0 5px; }
.research-brief h4:first-of-type { margin-top: 4px; }
.rb-summary { font-size: 12.5px; line-height: 1.55; color: var(--text-dim); }
.rb-list { margin: 0; padding-left: 16px; font-size: 12px; line-height: 1.6; color: var(--text-dim); }
.rb-list li { margin-bottom: 3px; }
.rb-list b { color: var(--text); }

/* ---------- Responsive ---------- */
#railToggle { display: none; background: none; border: 1px solid var(--border-2); color: var(--text-dim); border-radius: 6px; padding: 4px 9px; cursor: pointer; font-size: 14px; }
@media (max-width: 1100px) {
  .brand .sub { display: none; }
  #railToggle { display: block; }
  aside#rail { position: absolute; left: 0; top: 0; bottom: 0; z-index: 35; transform: translateX(-100%); transition: transform 0.2s; box-shadow: var(--shadow-pop); }
  aside#rail.open { transform: translateX(0); }
  .omnibox { width: 200px; }
}
@media (max-width: 820px) {
  nav.tabs { overflow-x: auto; scrollbar-width: none; }
  #view-chains { flex-direction: column; }
  .chain-list { width: 100%; max-height: 38%; border-right: none; border-bottom: 1px solid var(--border); }
  .dg-lanes { grid-template-columns: 1fr; }
  .dg-wrap { flex-direction: column; }
  .dg-picker { width: 100%; max-height: 32%; border-right: none; border-bottom: 1px solid var(--border); }
}
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 5px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- Ripple cascade (iteration 11) ---------- */
.node.ripple-h0 > circle:first-of-type { stroke: var(--node-lit-stroke); stroke-width: 3.5; filter: drop-shadow(0 0 6px var(--accent-press)); }
.node.ripple-h1 > circle:first-of-type { stroke: var(--sev-critical); stroke-width: 2.6; }
.node.ripple-h2 > circle:first-of-type { stroke: var(--sev-high); stroke-width: 2.2; }
.node.ripple-h3 > circle:first-of-type { stroke: var(--sev-medium); stroke-width: 1.8; }

.ripple-panel {
  position: absolute; right: 12px; top: 12px; bottom: 12px; z-index: 10;
  width: 290px; overflow-y: auto;
  background: var(--overlay); border: 1px solid var(--border-2);
  border-radius: 8px; padding: 12px; backdrop-filter: blur(4px);
}
.ripple-panel .rp-head { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-dim); margin-bottom: 8px; }
.ripple-panel .rp-src { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.ripple-panel .rp-src-note { font-size: 11px; color: var(--text-dim); font-style: italic; }
.ripple-panel .rp-hop { margin-bottom: 10px; }
.ripple-panel .rp-hop-head { font-size: 11px; font-weight: 600; color: var(--text); margin-bottom: 5px; padding-left: 7px; border-left: 3px solid var(--border-2); }
.ripple-panel .rp-hop-1 .rp-hop-head { border-left-color: var(--sev-critical); }
.ripple-panel .rp-hop-2 .rp-hop-head { border-left-color: var(--sev-high); }
.ripple-panel .rp-hop-3 .rp-hop-head { border-left-color: var(--sev-medium); }
.ripple-panel .rp-outcomes .rp-hop-head { border-left-color: var(--kind-outcome); }
.ripple-panel .rp-hop-head .n { color: var(--text-dim); font-weight: 400; }
.ripple-panel .rp-row { display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 2px 0; }
.ripple-panel .rp-row .sev { flex-shrink: 0; font-size: 10px; padding: 1px 6px; }
.ripple-panel .rp-via { flex-shrink: 0; font-size: 10px; color: var(--text-faint); }
.ripple-panel .rp-note { font-size: 10.5px; color: var(--text-faint); line-height: 1.5; margin-top: 6px; padding-top: 8px; border-top: 1px solid var(--border); }

/* ---------- Systemic-driver badge (Diagnose) ---------- */
.dg-systemic {
  margin-top: 7px; padding: 5px 8px; border-radius: 6px; font-size: 11px; line-height: 1.6;
  background: var(--ext-tint); border: 1px dashed var(--kind-receiver); color: var(--text-dim);
}
.dg-systemic-link { color: var(--accent); cursor: pointer; font-weight: 600; }
.dg-systemic-link:hover { text-decoration: underline; }

/* ---------- Category coupling heatmap (Capability Map) ---------- */
.coupling-map {
  margin: 16px 16px 0; padding: 12px 14px;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
}
.coupling-map summary { cursor: pointer; font-size: 13px; font-weight: 600; color: var(--text); }
.coupling-map .cm-caption { font-size: 11.5px; color: var(--text-dim); margin: 8px 0 10px; line-height: 1.55; }
.coupling-map .cm-caption b { color: var(--text); }
.coupling-map .cm-scroll { overflow-x: auto; }
.coupling-map .cm-grid { display: grid; gap: 2px; align-items: center; width: max-content; }
.coupling-map .cm-corner { }
.coupling-map .cm-col { display: flex; justify-content: center; }
.coupling-map .cm-col .sw, .coupling-map .cm-row-label .sw { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }
.coupling-map .cm-row-label { display: flex; align-items: center; gap: 6px; font-size: 10.5px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 8px; }
.coupling-map .cm-cell { width: 22px; height: 22px; border-radius: 3px; background: var(--panel-2); }
.coupling-map .cm-cell.on { cursor: pointer; }
.coupling-map .cm-cell.on:hover { outline: 1px solid var(--accent); }

/* ---------- Diagnose metric combobox (iteration 14) ---------- */
.dg-combo { position: relative; margin: 0 0 18px; max-width: 560px; }
.dg-combo-label {
  display: block; font-size: 10px; text-transform: uppercase; letter-spacing: 1.1px;
  color: var(--text-faint); margin-bottom: 5px;
}
.dg-combo-field { position: relative; }
.dg-combo-field input {
  width: 100%; padding: 9px 30px 9px 12px; border-radius: 7px;
  border: 1px solid var(--border-2); background: var(--panel); color: var(--text);
  font-family: var(--font); font-size: 14px; outline: none;
}
.dg-combo-field input::placeholder { color: var(--text); opacity: 0.85; }
.dg-combo-field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.dg-combo-field input:focus::placeholder { color: var(--text-faint); opacity: 1; }
.dg-combo-caret { position: absolute; right: 11px; top: 9px; color: var(--text-dim); pointer-events: auto; cursor: pointer; font-size: 12px; }
.dg-combo-list {
  display: none; position: absolute; z-index: 60; left: 0; right: 0; top: 100%; margin-top: 4px;
  max-height: 340px; overflow-y: auto; background: var(--panel); border: 1px solid var(--border-2);
  border-radius: 8px; box-shadow: var(--shadow-pop);
}
.dg-combo-list.open { display: block; }
.dg-combo-group {
  font-size: 10px; text-transform: uppercase; letter-spacing: 1.1px; color: var(--text-faint);
  padding: 9px 12px 4px; background: var(--panel-2); position: sticky; top: 0;
}
.dg-combo-opt { padding: 8px 12px; cursor: pointer; border-bottom: 1px solid var(--border); }
.dg-combo-opt:last-child { border-bottom: none; }
.dg-combo-opt:hover, .dg-combo-opt.kb { background: var(--accent-soft); }
.dg-combo-opt.active { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.dg-combo-opt .n { display: block; font-size: 13.5px; font-weight: 600; color: var(--text); }
.dg-combo-opt .d { display: block; font-size: 11.5px; color: var(--text-dim); margin-top: 2px; }
.dg-combo-empty { padding: 14px 12px; font-size: 12.5px; color: var(--text-dim); }

/* ---------- Actions / Teams registry views ---------- */
#view-actions, #view-teams { overflow-y: auto; padding: 22px 24px 40px; }
.rg-intro { max-width: 780px; margin-bottom: 22px; }
.rg-intro h2 { font-size: 20px; margin-bottom: 8px; }
.rg-intro p { font-size: 13.5px; color: var(--text-dim); line-height: 1.6; }
.rg-group { margin-bottom: 26px; }
.rg-group-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.rg-group-head .dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.rg-group-head .t { font-size: 14px; font-weight: 650; }
.rg-group-head .n { font-size: 11px; color: var(--text-faint); background: var(--panel-2); border-radius: 10px; padding: 1px 8px; }
.rg-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.rg-cards.wide { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }
.rg-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 13px 15px; cursor: pointer; box-shadow: var(--shadow-1);
  transition: border-color 0.15s ease, transform 0.15s ease;
}
.rg-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.rg-card .t { font-size: 13.5px; font-weight: 650; display: flex; align-items: center; gap: 7px; margin-bottom: 5px; }
.rg-card .t .dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.rg-card .d { font-size: 12px; color: var(--text-dim); line-height: 1.5; }
.rg-meta { font-size: 11.5px; color: var(--text-dim); margin-top: 8px; line-height: 1.5; }
.rg-meta .lbl { font-size: 10px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--text-faint); margin-right: 4px; }
.rg-meta.dim { color: var(--text-faint); font-style: italic; }
.rg-stats { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 9px; font-size: 11.5px; color: var(--text-dim); }

/* ---------- Analyst Dashboard ---------- */
#view-dashboard { padding: 16px 20px; overflow-y: auto; }
.dash-intro { max-width: 780px; margin-bottom: 18px; }
.dash-intro h2 { font-size: 20px; margin-bottom: 8px; }
.dash-intro p { font-size: 13.5px; color: var(--text-dim); line-height: 1.6; }
.dash-intro code { font-size: 11.5px; background: var(--panel-2); border-radius: 4px; padding: 1px 5px; }
table.dash-table { min-width: 900px; }
.dash-cat { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-dim); white-space: nowrap; }
.dash-cat .dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.dash-value { font-family: var(--mono); font-size: 13.5px; font-weight: 650; color: var(--text); white-space: nowrap; }
.dash-trend { display: flex; align-items: baseline; gap: 6px; }
/* Direction only, not a judgment — up/down here means the number moved, not that it's good or
   bad (a falling Gross NPA is welcome, a falling FII holding is merely notable), so both arrows
   share one neutral colour; only the glyph differs. */
.dash-trend-arrow { font-size: 12px; font-weight: 700; flex-shrink: 0; color: var(--text-dim); }
.dash-trend-arrow.dash-trend-flat { color: var(--text-faint); }
.dash-trend-note { font-size: 11.5px; color: var(--text-dim); line-height: 1.4; }

/* ---------- generic utility ---------- */
.dim { color: var(--text-dim); }

/* ---------- Add-a-stock page ---------- */
.add-stock-main { overflow-y: auto; }
.add-stock-wrap { max-width: 720px; margin: 0 auto; padding: 40px 20px 60px; }
.add-stock-intro h1 { font-size: 24px; margin-bottom: 10px; }
.add-stock-intro p { font-size: 13.5px; color: var(--text-dim); line-height: 1.6; margin-bottom: 26px; }
.add-stock-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px 24px; box-shadow: var(--shadow-1); margin-bottom: 18px;
}
.add-stock-field { margin-bottom: 16px; }
.add-stock-field:last-child { margin-bottom: 0; }
.add-stock-field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.add-stock-field label .dim { font-weight: 400; color: var(--text-faint); }
.add-stock-row { display: flex; gap: 16px; }
.add-stock-row .add-stock-field { flex: 1; }
.add-stock-field input[type="text"], .add-stock-field select, .add-stock-field textarea {
  width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--border-2);
  border-radius: 6px; padding: 8px 11px; font-family: var(--font); font-size: 13px; outline: none;
  box-sizing: border-box;
}
.add-stock-field textarea { font-family: var(--mono); font-size: 12px; line-height: 1.5; resize: vertical; }
.add-stock-field input:focus, .add-stock-field select:focus, .add-stock-field textarea:focus { border-color: var(--accent); }
.add-stock-actions { display: flex; align-items: center; justify-content: flex-end; gap: 14px; margin-top: 6px; }
.add-stock-error { font-size: 12px; color: var(--sev-critical); flex: 1; }
.add-stock-steps h2 { font-size: 16px; margin-bottom: 14px; }
.add-stock-ol { list-style: decimal; padding-left: 20px; }
.add-stock-ol li { font-size: 13px; line-height: 1.65; color: var(--text); margin-bottom: 14px; }
.add-stock-ol code { font-size: 11.5px; background: var(--panel-2); border-radius: 4px; padding: 1px 6px; }
.add-stock-code {
  display: flex; align-items: center; gap: 10px; margin-top: 8px;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px;
  padding: 10px 12px; overflow-x: auto;
}
.add-stock-code pre { font-family: var(--mono); font-size: 12px; color: var(--accent); white-space: pre; margin: 0; flex: 1; }
.add-stock-copy { flex-shrink: 0; white-space: nowrap; }
.add-stock-note { font-size: 12px; color: var(--text-faint); line-height: 1.6; }
.add-stock-note code { background: var(--panel-2); border-radius: 4px; padding: 1px 5px; }
.add-stock-note a { color: var(--accent); }
.add-stock-detail { margin-top: 10px; font-size: 12px; color: var(--text-dim); }
.add-stock-detail ol { padding-left: 18px; }
.add-stock-detail li { margin-bottom: 8px; line-height: 1.55; }
.add-stock-detail code { font-size: 11px; background: var(--panel-2); border-radius: 4px; padding: 1px 5px; }
.rg-stats b { color: var(--text); }
.rg-stats .hot { color: var(--sev-high); }
.rg-chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 9px; }
.rg-more { font-size: 11px; color: var(--text-faint); align-self: center; }

/* ---------- coverage honesty ---------- */
.cov-badge {
  display: inline-block; font-size: 10px; letter-spacing: 0.4px; margin-left: 6px;
  color: var(--text-faint); border: 1px dashed var(--border-2); border-radius: 9px; padding: 0 7px;
}
.chip.unmodelled { opacity: 0.55; border-style: dashed; }
.cov-empty {
  border: 1px dashed var(--border-2); border-radius: var(--radius);
  padding: 14px 16px; background: var(--surface-soft);
}
.cov-empty-t { font-size: 13px; font-weight: 650; color: var(--text-dim); margin-bottom: 8px; }
.cov-empty p { font-size: 12.5px; color: var(--text-dim); line-height: 1.6; margin-bottom: 8px; }
.cov-empty p:last-child { margin-bottom: 0; }

/* ---------- architecture layout (click an object) ---------- */
.arch-h {
  font-family: var(--font); font-size: 10px; font-weight: 700;
  letter-spacing: 1.4px; fill: var(--text-faint);
}
.arch-h.focus { fill: var(--accent); font-size: 11px; }

/* ---------- per-view help panel ---------- */
.help-panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: 460px; max-width: 92vw; z-index: 520;
  background: var(--panel); border-left: 1px solid var(--border);
  box-shadow: var(--shadow-drawer); display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform 0.22s ease; visibility: hidden;
}
.help-panel.open { transform: none; visibility: visible; }
.help-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 16px 18px 12px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.help-kicker { font-size: 10px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--accent); font-weight: 600; }
.help-head h3 { font-size: 18px; margin-top: 3px; }
.help-head button {
  background: none; border: none; color: var(--text-dim); font-size: 22px; line-height: 1;
  cursor: pointer; padding: 0 4px; font-family: var(--font);
}
.help-head button:hover { color: var(--text); }
.help-body { overflow-y: auto; padding: 16px 18px 26px; }
.help-body h4 {
  font-size: 11px; text-transform: uppercase; letter-spacing: 1.1px; color: var(--text-faint);
  margin: 18px 0 8px;
}
.help-body ul, .help-body ol { margin: 0; padding-left: 20px; }
.help-body li { font-size: 13px; color: var(--text-dim); line-height: 1.6; margin-bottom: 8px; }
.help-body li b { color: var(--text); }
.help-answers {
  font-size: 13.5px; color: var(--text-dim); line-height: 1.6;
  background: var(--accent-soft); border-left: 3px solid var(--accent);
  padding: 10px 12px; border-radius: 0 6px 6px 0;
}
.help-answers b { color: var(--text); }
.help-shot { margin: 16px 0 0; }
.help-shot img { width: 100%; height: auto; border-radius: 6px; border: 1px solid var(--border-2); display: block; }
.help-shot figcaption { font-size: 11px; color: var(--text-faint); margin-top: 6px; line-height: 1.5; }
.help-next {
  font-size: 12.5px; color: var(--text-dim); line-height: 1.6; margin-top: 16px;
  padding: 10px 12px; background: var(--surface-soft); border: 1px dashed var(--border-2); border-radius: 6px;
}
.help-foot { margin-top: 20px; display: flex; flex-direction: column; gap: 8px; }
.help-tour {
  background: var(--accent); border: 1px solid var(--accent); color: var(--on-accent);
  font-family: var(--font); font-size: 13px; font-weight: 600; padding: 9px 14px;
  border-radius: 7px; cursor: pointer;
}
.help-foot .dim { font-size: 11.5px; color: var(--text-faint); }
.help-foot code { font-family: var(--mono); font-size: 11px; }

/* ============================================================================
   SHARE-PRICE LAYER — direction palette, history panel, path-to-price strip
   ----------------------------------------------------------------------------
   Direction colour is a SECOND axis, orthogonal to light/dark: `data-dir-palette`
   on <html> picks how up and down are coloured, so all four combinations are
   real, designed states rather than an accident of inheritance.

     terminal    green up / red down — what every Indian broker terminal uses
     accessible  blue up / amber down — safe for deuteranopia and protanopia

   Colour NEVER carries direction alone anywhere in this layer: an arrow glyph
   and an explicit +/- sign travel with every value (see .dir in history.js), so
   the terminal palette stays readable for a red-green colourblind reader and in
   greyscale print. The accessible palette is for people who would rather not
   rely on that pairing at all.
   ========================================================================== */
:root,
:root[data-theme="light"],
:root[data-dir-palette="terminal"],
:root[data-theme="light"][data-dir-palette="terminal"] {
  --dir-up: #0f8a52;            /* 4.4:1 on #f9fbfc */
  --dir-down: #cf3a2e;          /* 4.6:1 */
  --dir-flat: #7a8794;
  --dir-up-soft: rgba(15, 138, 82, 0.13);
  --dir-down-soft: rgba(207, 58, 46, 0.13);
}
:root[data-theme="light"][data-dir-palette="accessible"],
:root[data-dir-palette="accessible"] {
  --dir-up: #1667c9;            /* blue  — 5.1:1 on #f9fbfc */
  --dir-down: #a35c00;          /* amber — 4.7:1 */
  --dir-flat: #7a8794;
  --dir-up-soft: rgba(22, 103, 201, 0.13);
  --dir-down-soft: rgba(163, 92, 0, 0.13);
}
:root[data-theme="dark"],
:root[data-theme="dark"][data-dir-palette="terminal"] {
  --dir-up: #35c98d;            /* stepped for the dark ground, not inverted */
  --dir-down: #ff6f61;
  --dir-flat: #75839a;
  --dir-up-soft: rgba(53, 201, 141, 0.16);
  --dir-down-soft: rgba(255, 111, 97, 0.16);
}
:root[data-theme="dark"][data-dir-palette="accessible"] {
  --dir-up: #63a9ff;
  --dir-down: #e2a13c;
  --dir-flat: #75839a;
  --dir-up-soft: rgba(99, 169, 255, 0.16);
  --dir-down-soft: rgba(226, 161, 60, 0.16);
}

.dir { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.dir-up { color: var(--dir-up); }
.dir-down { color: var(--dir-down); }
.dir-flat { color: var(--dir-flat); }

/* ---- history panel ---- */
.hist { margin: 14px 0 6px; padding: 12px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--panel-2); }
.hist-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 9px; }
.hist-range { margin-left: auto; font-size: 11px; color: var(--text-faint);
  font-variant-numeric: tabular-nums; }
.hist-toggles { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 10px; }
.hist-grp { display: inline-flex; border: 1px solid var(--border-2); border-radius: 5px;
  overflow: hidden; }
.hist-btn { padding: 3px 11px; font-size: 11.5px; cursor: pointer; color: var(--text-dim);
  background: var(--panel); border-right: 1px solid var(--border); user-select: none; }
.hist-grp .hist-btn:last-child { border-right: 0; }
.hist-btn:hover:not(.disabled):not(.on) { background: var(--panel-2); color: var(--text); }
.hist-btn.on { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.hist-btn.disabled { opacity: .38; cursor: not-allowed; }
/* The SVG is generated at the box's measured pixel width, so width:100% renders it 1:1 and
   its text is never stretched by preserveAspectRatio. */
.hist-chart { width: 100%; }
.hist-svg { width: 100%; height: auto; display: block; overflow: visible; }
.hist-bar { fill: var(--accent); }
.hist-bar-up { fill: var(--dir-up); }
.hist-bar-down { fill: var(--dir-down); }
.hist-bar-last { stroke: var(--text); stroke-width: 1.2; }
.hist-bar-null { fill: var(--dir-flat); opacity: .3; }
.hist-zero { stroke: var(--text-faint); stroke-width: 1.2; opacity: .55; }
.hist-grid { stroke: var(--border-2); stroke-width: 1; opacity: .5; }
.hist-ytick { fill: var(--text-faint); font-size: 9px; text-anchor: end;
  font-variant-numeric: tabular-nums; }
/* The value on the bar. Tabular figures so a column of labels lines up, and a
   paint-order stroke so a label that overlaps its own bar stays readable. */
.hist-val { fill: var(--text); font-size: 9.5px; font-weight: 600; text-anchor: middle;
  font-variant-numeric: tabular-nums; paint-order: stroke;
  stroke: var(--panel-2); stroke-width: 2.6px; stroke-linejoin: round; }
.hist-val-null { fill: var(--text-faint); font-weight: 400; }
.hist-tick { fill: var(--text-faint); font-size: 9px; text-anchor: middle; }
.hist-tick-rot { text-anchor: end; }
.hist-unit { fill: var(--text-faint); font-size: 8.5px; letter-spacing: .05em;
  text-transform: uppercase; }
.hist-summary { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 4px; }
.hist-stat { flex: 1 1 88px; padding: 7px 9px; background: var(--panel);
  border: 1px solid var(--border); border-radius: 5px; }
.hist-stat-k { font-size: 9.5px; letter-spacing: .06em; text-transform: uppercase;
  color: var(--text-faint); }
.hist-stat-v { font-size: 14px; font-weight: 600; margin-top: 2px;
  font-variant-numeric: tabular-nums; }
.hist-sub { display: block; font-size: 10px; font-weight: 400; color: var(--text-faint); }
.hist-note, .hist-gap, .hist-formula { font-size: 11.5px; color: var(--text-dim);
  line-height: 1.5; margin-top: 9px; }
.hist-gap { padding: 7px 9px; background: var(--dir-down-soft); border-radius: 5px; }
.hist-formula code { font-size: 11px; }
.hist-warn { font-size: 11.5px; line-height: 1.5; margin-top: 9px; padding: 8px 10px;
  border-left: 3px solid var(--sev-high); background: var(--panel); border-radius: 0 5px 5px 0;
  color: var(--text-dim); }
.hist-point { display: flex; align-items: baseline; gap: 10px; padding: 10px 0 2px; }
.hist-point-v { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.hist-point-m { font-size: 11.5px; color: var(--text-faint); }
.hist-empty { padding: 20px; text-align: center; color: var(--text-faint); font-size: 12px; }
.hist-table-wrap { margin-top: 10px; }
.hist-table-wrap summary { cursor: pointer; font-size: 11.5px; color: var(--text-dim); }
.hist-table-scroll { overflow-x: auto; margin-top: 7px; }
.hist-table { width: 100%; border-collapse: collapse; font-size: 11.5px;
  font-variant-numeric: tabular-nums; }
.hist-table th { text-align: left; font-size: 9.5px; letter-spacing: .05em;
  text-transform: uppercase; color: var(--text-faint); font-weight: 500;
  border-bottom: 1px solid var(--border-2); padding: 5px 8px; }
.hist-table td { padding: 4px 8px; border-bottom: 1px solid var(--border); }
.hist-table td.num, .hist-table th.num { text-align: right; }

/* ---- provenance chips ---- */
.prov { font-size: 9.5px; letter-spacing: .05em; font-weight: 700; padding: 2px 6px;
  border-radius: 3px; text-transform: uppercase; }
.prov-known { background: var(--dir-up-soft); color: var(--dir-up); }
.prov-derived { background: var(--accent-soft); color: var(--accent); }
.prov-feed { background: var(--dir-down-soft); color: var(--dir-down); }

/* ---- source conflict: two feeds disagreeing, shown rather than silently resolved ---- */
.conflict { margin: 12px 0; padding: 10px 12px; border: 1px solid var(--sev-high);
  border-left-width: 3px; border-radius: 0 6px 6px 0; background: var(--panel-2); }
.conflict-h { font-size: 11.5px; font-weight: 700; color: var(--sev-high); margin-bottom: 7px; }
.conflict-row { display: flex; gap: 8px; font-size: 11px; margin-bottom: 4px; align-items: baseline; }
.conflict-row span { flex: 0 0 118px; color: var(--text-faint); }
.conflict-row code { font-size: 10.5px; color: var(--text-dim); word-break: break-word; }
.conflict-res { font-size: 11.5px; line-height: 1.5; color: var(--text-dim); margin-top: 7px;
  padding-top: 7px; border-top: 1px solid var(--border); }

/* ---- Price Command Center ---- */
.price-wrap { padding: 22px 26px 60px; max-width: 1080px; }
.price-hero { display: flex; gap: 26px; flex-wrap: wrap; align-items: flex-start;
  justify-content: space-between; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.price-eyebrow { font-size: 10.5px; letter-spacing: .09em; text-transform: uppercase;
  color: var(--text-faint); }
.price-big { font-size: 46px; font-weight: 700; line-height: 1.05; margin: 4px 0;
  font-variant-numeric: tabular-nums; }
.price-sub { display: flex; gap: 12px; align-items: baseline; flex-wrap: wrap; }
.dir-big { font-size: 17px; }
.price-vs { font-size: 12px; color: var(--text-dim); }
.price-facts { display: flex; gap: 22px; flex-wrap: wrap; }
.price-facts div { display: flex; flex-direction: column; gap: 2px; }
.price-facts span { font-size: 10px; letter-spacing: .06em; text-transform: uppercase;
  color: var(--text-faint); }
.price-facts b { font-size: 14px; font-variant-numeric: tabular-nums; }
.price-caveat { margin: 14px 0; padding: 9px 12px; font-size: 11.5px; line-height: 1.55;
  color: var(--text-dim); background: var(--panel-2); border-left: 3px solid var(--sev-medium);
  border-radius: 0 5px 5px 0; }
.price-wrap h3 { margin: 26px 0 4px; font-size: 15px; }
.price-cards { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 10px; }
.price-card { flex: 1 1 260px; padding: 12px 14px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--panel); }
.price-card h4 { margin: 0 0 9px; font-size: 12px; color: var(--text-dim); }
.attr-bar { display: flex; height: 19px; border-radius: 5px; overflow: hidden;
  background: var(--panel-2); }
.attr-seg { height: 100%; display: flex; align-items: center; justify-content: center;
  overflow: hidden; }
.attr-seg-v { font-size: 10px; font-weight: 700; color: var(--on-accent);
  font-variant-numeric: tabular-nums; white-space: nowrap;
  text-shadow: 0 0 3px rgba(0, 0, 0, .45); }
.attr-market { background: var(--text-faint); }
.attr-sector { background: var(--accent); }
.attr-idio.seg-up { background: var(--dir-up); }
.attr-idio.seg-down { background: var(--dir-down); }
.attr-legend { display: flex; flex-direction: column; gap: 4px; margin-top: 9px; }
.attr-key { display: flex; align-items: center; gap: 6px; font-size: 11.5px;
  color: var(--text-dim); }
.attr-dot { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }
.attr-dot.attr-idio { background: var(--dir-up); }
.attr-note { margin-top: 8px; font-size: 10.5px; color: var(--text-faint); line-height: 1.45; }
.price-table-wrap { overflow-x: auto; margin-top: 8px; }
.price-table { width: 100%; border-collapse: collapse; font-size: 12px;
  font-variant-numeric: tabular-nums; }
.price-table th { text-align: left; font-size: 9.5px; letter-spacing: .05em;
  text-transform: uppercase; color: var(--text-faint); font-weight: 500; padding: 6px 10px;
  border-bottom: 1px solid var(--border-2); white-space: nowrap; }
.price-table td { padding: 5px 10px; border-bottom: 1px solid var(--border); }
.price-table td.num, .price-table th.num { text-align: right; }

/* ---- causal chain to Share Price (app/chain.js) ----
   The chain is rendered from the COMPUTED price_path, so the depth chip and the number
   of arrows always agree. Hypothesised hops are marked in both the header count and the
   ladder, so a weak link in a long chain cannot hide behind the chain's length. */
.chain { margin: 10px 0 4px; padding: 9px 11px; background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 6px; }
.ch-top { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 7px; }
.ch-depth, .ch-role, .ch-weak { font-size: 10px; letter-spacing: .05em; text-transform: uppercase;
  padding: 2px 7px; border-radius: 3px; font-weight: 600; }
.ch-depth { background: var(--accent-soft); color: var(--accent); }
.ch-role { border: 1px solid var(--border-2); color: var(--text-dim); }
.ch-role-leading { border-color: var(--dir-up); color: var(--dir-up); }
.ch-weak { background: var(--dir-down-soft); color: var(--dir-down); }
.ch-crumbs { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; font-size: 11.5px;
  line-height: 1.7; }
.ch-node { padding: 2px 7px; border-radius: 3px; background: var(--panel);
  border: 1px solid var(--border); color: var(--text-dim); }
.ch-self { color: var(--text); font-weight: 600; border-color: var(--border-2); }
.ch-price { background: var(--accent); color: var(--on-accent); border-color: var(--accent);
  font-weight: 600; }
.ch-arrow { color: var(--text-faint); }
.ch-toggle { margin-top: 8px; background: none; border: 0; padding: 0; cursor: pointer;
  font: inherit; font-size: 11px; color: var(--accent); }
.ch-toggle:hover { text-decoration: underline; }
.ch-ladder { margin-top: 9px; display: flex; flex-direction: column; gap: 7px; }
.ch-hop { padding: 8px 10px; background: var(--panel); border: 1px solid var(--border);
  border-left: 3px solid var(--border-2); border-radius: 0 5px 5px 0; }
.ch-hop.ch-supported_mechanism { border-left-color: var(--dir-up); }
.ch-hop.ch-observed_association { border-left-color: var(--accent); }
.ch-hop.ch-hypothesized { border-left-color: var(--sev-medium); }
.ch-hop-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 11px; }
.ch-hop-n { width: 16px; height: 16px; border-radius: 50%; background: var(--panel-2);
  color: var(--text-faint); font-size: 9.5px; display: inline-flex; align-items: center;
  justify-content: center; flex: none; }
.ch-hop-path { color: var(--text); font-weight: 600; }
.ch-hop-path em { color: var(--text-faint); font-style: normal; }
.ch-type, .ch-hz, .ch-status { font-size: 9.5px; letter-spacing: .04em; text-transform: uppercase;
  padding: 1.5px 6px; border-radius: 3px; }
.ch-type { background: var(--panel-2); color: var(--text-faint); }
.ch-hz { border: 1px solid var(--border); color: var(--text-faint); }
.ch-status { font-weight: 700; }
.ch-s-supported_mechanism { background: var(--dir-up-soft); color: var(--dir-up); }
.ch-s-observed_association { background: var(--accent-soft); color: var(--accent); }
.ch-s-hypothesized { background: var(--dir-down-soft); color: var(--dir-down); }
.ch-mech { font-size: 11.5px; line-height: 1.5; color: var(--text-dim); margin-top: 5px; }
.ch-meta { font-size: 10.5px; color: var(--text-faint); margin-top: 4px; line-height: 1.45; }

/* ── Correlation Lab ─────────────────────────────────────────────────────────
   Reuses the direction tokens (--dir-up/--dir-down), which are palette-switched,
   so every sign here reads the same way as the rest of the app — and, as
   everywhere else, colour never carries direction alone: an arrow and an
   explicit sign travel with each r. */
.pg-wrap { padding: 18px 22px 40px; max-width: 1180px; }
.pg-wrap h3 { margin: 30px 0 4px; font-size: 15px; }
.pg-wrap h3:first-child { margin-top: 0; }
.pg-wrap > p.dim { font-size: 12px; line-height: 1.6; max-width: 80ch; }

.pg-controls { display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin: 14px 0 12px; padding: 12px 14px; background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 8px; }
.pg-field { display: flex; align-items: center; gap: 7px; font-size: 11px;
  letter-spacing: .06em; text-transform: uppercase; color: var(--text-faint); }
.pg-sel { max-width: 260px; padding: 5px 8px; font-size: 12px; color: var(--text);
  background: var(--panel); border: 1px solid var(--border-2); border-radius: 5px; }
.pg-swap { cursor: pointer; font-size: 15px; color: var(--text-dim); user-select: none;
  padding: 2px 5px; border-radius: 4px; }
.pg-swap:hover { background: var(--panel); color: var(--text); }
.pg-grp { display: inline-flex; border: 1px solid var(--border-2); border-radius: 5px;
  overflow: hidden; }
.pg-btn { padding: 4px 10px; font-size: 11.5px; cursor: pointer; color: var(--text-dim);
  background: var(--panel); border-right: 1px solid var(--border); user-select: none;
  white-space: nowrap; }
.pg-grp .pg-btn:last-child { border-right: 0; }
.pg-btn:hover:not(.disabled):not(.on) { background: var(--panel-2); color: var(--text); }
.pg-btn.on { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.pg-btn.disabled { opacity: .38; cursor: not-allowed; }

/* The dependency banner sits ABOVE the number on purpose: by the time a reader has
   seen r = 1.00 the damage is done. */
.pg-dep { font-size: 12px; line-height: 1.55; padding: 10px 12px; border-radius: 0 6px 6px 0;
  margin-bottom: 12px; background: var(--panel-2); border-left: 3px solid var(--sev-medium);
  color: var(--text-dim); }
.pg-dep-identity, .pg-dep-compositional { border-left-color: var(--sev-critical); }
.pg-dep-component { border-left-color: var(--sev-high); }
.pg-dep-tag { display: inline-block; font-size: 9.5px; font-weight: 700; letter-spacing: .07em;
  color: var(--text); margin-right: 8px; }
.pg-refuse { font-size: 12.5px; line-height: 1.6; padding: 14px 16px; border-radius: 8px;
  background: var(--panel-2); border: 1px dashed var(--border-2); color: var(--text-dim); }

.pg-headline { display: flex; align-items: center; gap: 26px; flex-wrap: wrap;
  padding: 14px 16px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--panel); }
.pg-r-v { font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; }
.pg-r-k { display: block; font-size: 9.5px; letter-spacing: .07em; text-transform: uppercase;
  color: var(--text-faint); }
.pg-facts { display: flex; gap: 22px; flex-wrap: wrap; }
.pg-facts > div span { display: block; font-size: 9.5px; letter-spacing: .06em;
  text-transform: uppercase; color: var(--text-faint); }
.pg-facts > div b { font-size: 14px; font-variant-numeric: tabular-nums; }
.pg-chip { display: inline-block; padding: 2px 7px; border-radius: 4px; font-size: 9.5px;
  font-weight: 700; letter-spacing: .05em; background: var(--panel-2);
  border: 1px solid var(--border-2); color: var(--text-dim); margin-right: 4px; }
.pg-ok { color: var(--dir-up); border-color: var(--dir-up); }
.pg-no { color: var(--dir-down); border-color: var(--dir-down); }
.pg-warn { color: var(--sev-medium); border-color: var(--sev-medium); }
.pg-arith { color: var(--text-faint); }

.pg-charts { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 14px; }
.pg-chart { flex: 1 1 300px; padding: 10px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--panel); }
.pg-svg { width: 100%; height: auto; display: block; overflow: visible; }
.pg-grid { stroke: var(--border-2); stroke-width: 1; opacity: .45; }
.pg-zero { stroke: var(--text-faint); stroke-width: 1.2; opacity: .6; }
.pg-xtick, .pg-ytick { fill: var(--text-faint); font-size: 9px;
  font-variant-numeric: tabular-nums; }
.pg-xtick { text-anchor: middle; }
.pg-ytick { text-anchor: end; }
.pg-axlab { fill: var(--text-dim); font-size: 10px; text-anchor: middle; }
.pg-dot { fill: var(--accent); fill-opacity: .8; stroke: var(--panel); stroke-width: 1.2; }
.pg-dotlab { fill: var(--text-faint); font-size: 8.5px; }
.pg-lx { fill: none; stroke: var(--accent); stroke-width: 1.8; }
.pg-lx-d { fill: var(--accent); }
.pg-lx-t { fill: var(--accent); }
.pg-ly { fill: none; stroke: var(--sev-high); stroke-width: 1.8; stroke-dasharray: 4 3; }
.pg-ly-d { fill: var(--sev-high); }
.pg-ly-t { fill: var(--sev-high); }
.pg-legend { font-size: 9.5px; font-weight: 600; }

.pg-infl { margin-top: 12px; font-size: 11.5px; line-height: 1.55; color: var(--text-dim);
  padding: 8px 11px; background: var(--panel-2); border-radius: 5px; }
.pg-infl-bad { border-left: 3px solid var(--sev-critical); border-radius: 0 5px 5px 0; }

.pg-edge { margin-top: 12px; padding: 11px 13px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--panel); font-size: 12px; line-height: 1.55; }
.pg-edge-none { color: var(--text-dim); border-style: dashed; }
.pg-edge-h { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 6px;
  font-family: var(--mono); font-size: 11px; }
.pg-edge-m { color: var(--text-dim); }
.pg-edge-n { margin-top: 6px; font-size: 11px; color: var(--text-faint); line-height: 1.5; }

.pg-scan-bar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin: 10px 0; }
.pg-check { display: flex; align-items: center; gap: 6px; font-size: 11.5px;
  color: var(--text-dim); cursor: pointer; }
.pg-selfcheck { margin-left: auto; font-size: 10.5px; }
.pg-table-wrap { overflow-x: auto; margin-top: 6px; border: 1px solid var(--border);
  border-radius: 8px; }
.pg-table { width: 100%; border-collapse: collapse; font-size: 12px;
  font-variant-numeric: tabular-nums; }
.pg-table th { text-align: left; font-size: 9.5px; letter-spacing: .05em; text-transform: uppercase;
  color: var(--text-faint); font-weight: 500; padding: 7px 10px; background: var(--panel-2);
  border-bottom: 1px solid var(--border-2); white-space: nowrap; }
.pg-table td { padding: 6px 10px; border-bottom: 1px solid var(--border); }
.pg-table tbody tr { cursor: pointer; }
.pg-table tbody tr:hover { background: var(--panel-2); }
.pg-table .num { text-align: right; }

.pg-cards { display: flex; gap: 12px; flex-wrap: wrap; margin: 12px 0; }
.pg-card { flex: 1 1 170px; padding: 12px 14px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--panel); }
.pg-card b { display: block; font-size: 26px; font-weight: 700;
  font-variant-numeric: tabular-nums; }
.pg-card span { font-size: 11px; color: var(--text-dim); line-height: 1.45; display: block;
  margin-top: 3px; }
.pg-card-hi { border-color: var(--accent); }
.pg-caveat { margin-top: 12px; font-size: 11.5px; line-height: 1.55; padding: 10px 12px;
  color: var(--text-dim); background: var(--panel-2); border-left: 3px solid var(--sev-medium);
  border-radius: 0 5px 5px 0; }
.hist-corr { border-right: 0; border: 1px solid var(--border-2); border-radius: 5px; }
