/* Layout: a working tool. Fixed side panel (search, filters, results, details) beside a full-height map.
   On phones the map sits on top and the panel scrolls below it. */
:root {
  --bg: #f3f5f5;          /* panel ground, cool grey with a fjord tint */
  --surface: #ffffff;
  --ink: #142126;
  --ink-2: #4a5a60;
  --ink-3: #75858b;
  --line: #d8dfe0;
  --accent: #0d5d70;      /* fjord blue: UI selection, links, value-chain cells */
  --accent-soft: #dcecef;
  --sea: #dfe8ea;
  --land: #fbfcfb;
  --land-other: #edf0ee;
  --county-line: #a9b7ba;
  --muni-line: #c9d3d4;
  --focus: #0d5d70;
  --shadow: 0 1px 2px rgba(20, 33, 38, .08), 0 6px 20px rgba(20, 33, 38, .08);

  /* categorical pin colours (validated set, light) */
  --t-company: #2a78d6;
  --t-university: #eb6834;
  --t-public: #1baf7a;
  --t-network: #6250d6;
  --t-funder: #eda100;
  --t-project: #e87ba4;
  --t-other: #75858b;
  --t-inactive: #a3aeb1;

  --f-display: "Barlow Semi Condensed", "Arial Narrow", "Roboto Condensed", system-ui, sans-serif;
  --f-body: "Barlow", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --side-w: 380px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12181b; --surface: #192125; --ink: #e6ecec; --ink-2: #aab7ba; --ink-3: #7f8e92; --line: #2a3539;
    --accent: #5fb7c9; --accent-soft: #1d3a42; --sea: #0e1417; --land: #1d2529; --land-other: #161d20;
    --county-line: #4b5b60; --muni-line: #2f3b3f; --focus: #5fb7c9;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .35);
    --t-company: #3987e5; --t-university: #d95926; --t-public: #199e70; --t-network: #9085e9;
    --t-funder: #c98500; --t-project: #d55181; --t-other: #7f8e92; --t-inactive: #5b686c;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12181b; --surface: #192125; --ink: #e6ecec; --ink-2: #aab7ba; --ink-3: #7f8e92; --line: #2a3539;
  --accent: #5fb7c9; --accent-soft: #1d3a42; --sea: #0e1417; --land: #1d2529; --land-other: #161d20;
  --county-line: #4b5b60; --muni-line: #2f3b3f; --focus: #5fb7c9;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .35);
  --t-company: #3987e5; --t-university: #d95926; --t-public: #199e70; --t-network: #9085e9;
  --t-funder: #c98500; --t-project: #d55181; --t-other: #7f8e92; --t-inactive: #5b686c;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 var(--f-body); }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.app { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); height: 100%; }

/* ---------------------------------------------------------------- side panel */
.side {
  display: flex; flex-direction: column; min-height: 0; min-width: 0;
  border-right: 1px solid var(--line); background: var(--bg);
}
.masthead {
  padding-block: 20px 12px;
  padding-left: max(20px, env(safe-area-inset-left, 0px)); padding-right: 20px;
}
.eyebrow {
  margin: 0 0 4px; font: 600 12px/1.2 var(--f-display); letter-spacing: .08em; text-transform: uppercase; color: var(--accent);
}
h1 { margin: 0; font: 700 26px/1.1 var(--f-display); letter-spacing: -.005em; text-wrap: balance; }
.tally { margin: 8px 0 0; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.tally b { color: var(--ink); font-weight: 600; }

.tools { display: flex; flex-direction: column; gap: 8px; padding-left: max(20px, env(safe-area-inset-left, 0px)); padding-right: 20px; padding-block: 0 12px; }
.search { position: relative; display: block; }
.search svg { position: absolute; left: 11px; top: 50%; width: 17px; height: 17px; transform: translateY(-50%); fill: none; stroke: var(--ink-3); stroke-width: 1.8; stroke-linecap: round; }
.search input {
  width: 100%; padding: 9px 12px 9px 36px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface);
}
.search input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }

.filters { border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.filters summary {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px; cursor: pointer; list-style: none;
  font: 600 14px/1.2 var(--f-display); letter-spacing: .04em; text-transform: uppercase; color: var(--ink-2);
}
.filters summary::-webkit-details-marker { display: none; }
.filters summary::after { content: ""; margin-left: auto; width: 7px; height: 7px; border: solid var(--ink-3); border-width: 0 1.6px 1.6px 0; transform: rotate(45deg) translateY(-2px); transition: transform .15s; }
.filters[open] summary::after { transform: rotate(-135deg) translateY(-1px); }
.filter-count { min-width: 20px; padding: 1px 6px; border-radius: 10px; background: var(--accent); color: var(--surface); font: 600 12px/1.4 var(--f-body); text-align: center; letter-spacing: 0; }
.filter-body { display: flex; flex-direction: column; gap: 12px; padding: 4px 12px 12px; max-height: 46vh; overflow: auto; }
fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
legend { padding: 0; margin-bottom: 6px; font-size: 13px; color: var(--ink-2); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); cursor: pointer; font-size: 13px; line-height: 1.3; color: var(--ink-2);
}
.chip:hover { border-color: var(--ink-3); }
.chip[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--ink); }
.chip .glyph { width: 16px; height: 16px; font-size: 9px; }
select { width: 100%; padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.link-btn { align-self: flex-start; padding: 0; border: 0; background: none; color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; font-size: 13px; }

/* glyph: the coloured letter disc used for pins, legend, chips and list rows */
.glyph {
  display: inline-grid; place-items: center; flex: none; width: 22px; height: 22px; border-radius: 50%;
  background: var(--c, var(--t-other)); color: #fff; font: 700 11px/1 var(--f-display); letter-spacing: 0;
}
.glyph.is-project { border-radius: 3px; transform: rotate(45deg) scale(.86); }
.glyph.is-project > span { transform: rotate(-45deg); }

/* results list */
.list-wrap { flex: 1; min-height: 0; overflow: auto; border-top: 1px solid var(--line); }
.list-head {
  position: sticky; top: 0; z-index: 1; margin: 0; padding: 10px 20px 8px; background: var(--bg);
  font: 600 13px/1.2 var(--f-display); letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3);
}
.results { list-style: none; margin: 0; padding: 0 8px 16px; }
.results button {
  display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 2px 10px; align-items: start; width: 100%;
  padding: 8px 12px; border: 0; border-radius: 6px; background: none; text-align: left; cursor: pointer;
}
.results button:hover, .results button.is-hot { background: var(--surface); }
.results .glyph { grid-row: span 2; margin-top: 1px; }
.results .name { font-weight: 600; overflow-wrap: anywhere; }
.results .meta { font-size: 13px; color: var(--ink-2); overflow-wrap: anywhere; }
.empty { padding: 12px 20px; color: var(--ink-2); }

/* detail view */
.detail { flex: 1; min-height: 0; overflow: auto; border-top: 1px solid var(--line); padding: 14px 20px 24px; }
.back { display: inline-flex; align-items: center; gap: 6px; margin-bottom: 12px; padding: 0; border: 0; background: none; color: var(--accent); cursor: pointer; font-size: 14px; }
.back::before { content: ""; width: 7px; height: 7px; border: solid currentColor; border-width: 0 0 1.6px 1.6px; transform: rotate(45deg); }
.kind { display: flex; align-items: center; gap: 8px; margin: 0 0 6px; font: 600 13px/1.2 var(--f-display); letter-spacing: .06em; text-transform: uppercase; color: var(--ink-2); }
.detail h2 { margin: 0 0 4px; font: 700 24px/1.15 var(--f-display); text-wrap: balance; overflow-wrap: anywhere; }
.facts { margin: 0 0 14px; color: var(--ink-2); font-size: 14px; font-variant-numeric: tabular-nums; }
.desc { margin: 0 0 18px; max-width: 62ch; }
.desc.is-missing { color: var(--ink-3); font-style: italic; }
.detail h3 { margin: 20px 0 8px; font: 600 13px/1.2 var(--f-display); letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); }

/* the value chain drawn as a battery: seven cells and a terminal */
.chain { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)) 4px; gap: 2px; align-items: stretch; }
.chain .cell { height: 26px; border-radius: 3px; border: 1.5px solid var(--line); background: var(--surface); }
.chain .cell.on { border-color: var(--accent); background: var(--accent); }
.chain .terminal { height: 12px; align-self: center; border-radius: 0 2px 2px 0; background: var(--line); }
.chain-labels { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)) 4px; gap: 2px; margin-top: 5px; }
.chain-labels span { font: 500 10.5px/1.2 var(--f-display); color: var(--ink-3); hyphens: manual; min-width: 0; }
.chain-labels span.on { color: var(--ink); font-weight: 700; }
.chain-note { margin: 8px 0 0; font-size: 13px; color: var(--ink-3); }

.rows { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.rows button, .rows .row {
  display: flex; align-items: baseline; gap: 8px; width: 100%; padding: 6px 8px; margin: 0 -8px; border: 0; border-radius: 6px;
  background: none; text-align: left; cursor: pointer;
}
.rows .row { cursor: default; }
.rows button:hover { background: var(--surface); }
.rows .main { font-weight: 500; overflow-wrap: anywhere; }
.rows .sub { margin-left: auto; padding-left: 8px; font-size: 13px; color: var(--ink-2); white-space: nowrap; }
.rows .glyph { align-self: center; width: 18px; height: 18px; font-size: 9px; }
.ext { display: inline-flex; gap: 6px; align-items: center; margin-top: 20px; font-weight: 500; overflow-wrap: anywhere; }
.loc-note { margin: 6px 0 0; font-size: 13px; color: var(--ink-3); }

.side-foot { padding: 10px 20px; padding-left: max(20px, env(safe-area-inset-left, 0px)); border-top: 1px solid var(--line); font-size: 12px; color: var(--ink-3); }

/* ---------------------------------------------------------------- map stage */
.stage { position: relative; min-width: 0; min-height: 0; }
.map { position: absolute; inset: 0; background: var(--sea); }
.leaflet-container { background: var(--sea); font: 13px/1.4 var(--f-body); }
.leaflet-container a { color: var(--accent); }
.leaflet-control-attribution { background: color-mix(in srgb, var(--surface) 80%, transparent) !important; color: var(--ink-3); }
.leaflet-bar a { background: var(--surface); color: var(--ink); border-color: var(--line); }
.leaflet-bar a:hover { background: var(--bg); }
.leaflet-bar { border: 1px solid var(--line) !important; box-shadow: var(--shadow) !important; }
.leaflet-top.leaflet-right { top: env(safe-area-inset-top, 0px); right: env(safe-area-inset-right, 0px); }

.crumbs {
  position: absolute; z-index: 500; top: 12px; left: 12px; right: 64px; display: flex; flex-wrap: wrap; align-items: center; gap: 2px;
  pointer-events: none;
}
.crumbs > * { pointer-events: auto; }
.crumbs button, .crumbs span {
  padding: 6px 10px; border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow);
  font: 600 14px/1.2 var(--f-display); letter-spacing: .02em;
}
.crumbs button { color: var(--accent); cursor: pointer; border-radius: 6px; }
.crumbs button:hover { background: var(--bg); }
.crumbs span { border-radius: 6px; color: var(--ink); }
.crumbs i { color: var(--ink-3); font-style: normal; padding: 0 2px; }

.legend {
  position: absolute; z-index: 500; left: 12px; bottom: 22px; display: grid; gap: 4px 12px; grid-template-columns: repeat(2, auto);
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: var(--shadow);
  font-size: 12.5px; color: var(--ink-2);
}
.legend .item { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.legend .glyph { width: 16px; height: 16px; font-size: 8.5px; }
.legend .hint { grid-column: 1 / -1; margin-top: 4px; padding-top: 6px; border-top: 1px solid var(--line); color: var(--ink-3); white-space: normal; max-width: 300px; }

/* map shapes (Leaflet sets fill/stroke attributes; these rules win) */
.shape-country, .shape-lake, .shape-county { fill-opacity: 1; }
.shape-country { fill: var(--land-other); stroke: var(--county-line); stroke-width: .8; }
.shape-lake { fill: var(--sea); stroke: none; }
.shape-county { fill: var(--land); stroke: var(--county-line); stroke-width: 1; transition: fill .15s; }
.shape-county.is-empty { fill: var(--land-other); }
.shape-county.is-dim { fill: var(--land-other); }
.shape-county.is-hover { fill: var(--accent-soft); }
.shape-county.is-scope { fill: var(--land); stroke: var(--ink-3); stroke-width: 1.6; }
.shape-muni { fill: none; stroke: var(--muni-line); stroke-width: .8; pointer-events: none; }
.has-tiles .shape-county { fill-opacity: .25; }
.has-tiles .shape-county.is-dim { fill: var(--bg); fill-opacity: .45; }
.has-tiles .shape-county.is-scope { fill: transparent; fill-opacity: 0; }
.has-tiles .shape-lake { display: none; }  /* countries stay underneath, beyond the edge of the tile area */
.link-line { stroke: var(--accent); stroke-width: 1.6; stroke-dasharray: 4 4; fill: none; }
.fan-line { stroke: var(--ink-3); stroke-width: 1; fill: none; }

/* aggregate bubbles: donut ring split by type, count in the middle */
.agg { display: grid; place-items: center; cursor: pointer; }
.agg svg { overflow: visible; filter: drop-shadow(0 1px 2px rgba(20, 33, 38, .25)); }
.agg .hole { fill: var(--surface); }
.agg text { fill: var(--ink); font: 700 13px var(--f-display); font-variant-numeric: tabular-nums; }
.agg.is-faded { opacity: .55; }
.agg:hover .hole, .agg:focus-visible .hole { fill: var(--accent-soft); }
.agg-label {
  position: absolute; left: 100%; top: 50%; transform: translate(4px, -50%); white-space: nowrap; pointer-events: none;
  font: 600 13px/1 var(--f-display); color: var(--ink); text-shadow: 0 0 3px var(--land), 0 0 3px var(--land), 0 0 2px var(--land);
}

/* individual pins */
.pin { display: grid; place-items: center; cursor: pointer; }
.pin .glyph { width: 24px; height: 24px; font-size: 11px; box-shadow: 0 0 0 2px var(--surface), 0 1px 3px rgba(0, 0, 0, .35); transition: transform .12s; }
.pin .glyph.is-project { transform: rotate(45deg) scale(.82); }
.pin:hover .glyph:not(.is-project), .pin.is-hot .glyph:not(.is-project) { transform: scale(1.18); }
.pin:hover .glyph.is-project, .pin.is-hot .glyph.is-project { transform: rotate(45deg) scale(1); }
.pin.is-selected .glyph { box-shadow: 0 0 0 2px var(--surface), 0 0 0 5px var(--accent), 0 2px 6px rgba(0, 0, 0, .35); }
.pin.is-ghost .glyph { opacity: .9; }
.leaflet-marker-icon:focus-visible { outline: none; }
.leaflet-marker-icon:focus-visible .glyph, .leaflet-marker-icon:focus-visible svg { outline: 2px solid var(--focus); outline-offset: 3px; border-radius: 50%; }

.leaflet-tooltip.tip {
  padding: 6px 9px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--ink); box-shadow: var(--shadow);
  font: 13px/1.35 var(--f-body);
}
.leaflet-tooltip.tip::before { display: none; }
.tip b { font-weight: 600; }
.tip small { display: block; color: var(--ink-2); font-size: 12px; }

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

/* ---------------------------------------------------------------- phones */
@media (max-width: 760px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto; height: auto; }
  .stage { order: -1; height: 62vh; min-height: 340px; }
  .side { border-right: 0; border-top: 1px solid var(--line); }
  .masthead { padding-block: 14px 10px; padding-right: max(16px, env(safe-area-inset-right, 0px)); padding-left: max(16px, env(safe-area-inset-left, 0px)); }
  .tools, .side-foot { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
  .list-head { padding-left: 16px; }
  .detail { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
  h1 { font-size: 22px; }
  .list-wrap, .detail { overflow: visible; }
  .legend { left: 8px; bottom: 18px; grid-template-columns: repeat(3, auto); font-size: 11.5px; padding: 6px 8px; gap: 3px 8px; }
  .legend .hint { display: none; }
  .crumbs { top: 8px; left: 8px; }
}

.agg { position: relative; }
.agg-icon, .pin-icon { background: none; border: 0; }
.fan-dot { fill: var(--ink-3); stroke: none; }

.side-foot { display: flex; flex-direction: column; gap: 6px; }
.bg-status { padding: 6px 8px; border-left: 3px solid var(--t-funder); background: var(--surface); color: var(--ink-2); overflow-wrap: anywhere; }

/* no longer active / bankrupt / acquired: same letter, grey and hollow */
.glyph.is-inactive { background: var(--surface); color: var(--ink-3); box-shadow: inset 0 0 0 2px var(--t-inactive); }
.pin .glyph.is-inactive { box-shadow: inset 0 0 0 2px var(--t-inactive), 0 0 0 2px var(--surface), 0 1px 3px rgba(0, 0, 0, .25); }
.pin.is-selected .glyph.is-inactive { box-shadow: inset 0 0 0 2px var(--t-inactive), 0 0 0 2px var(--surface), 0 0 0 5px var(--accent); }
.results button.is-inactive .name { color: var(--ink-2); font-weight: 500; }
.legend .item-wide { grid-column: 1 / -1; }
.status-line { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; margin: 2px 0 12px; color: var(--ink-2); font-size: 14px; }
.status-pill { padding: 2px 8px; border: 1px solid var(--t-inactive); border-radius: 999px; font: 600 12px/1.4 var(--f-display);
  letter-spacing: .04em; text-transform: uppercase; color: var(--ink-2); }
