/* Map
   The county, drawn as SVG, and the list beside it. No tiles and no basemap:
   every line here comes from coordinates served by this origin.

   On the three colours. A map is the hardest case for categorical colour —
   any two marks can end up touching, so every pair has to be separable, not
   just neighbouring ones in a legend. Three hues survive that test; eight do
   not. So colour carries three families and the glyph carries the category,
   which means identity never rests on colour alone. The hues are the first
   three slots of the validated categorical palette, stepped for each theme
   rather than flipped. */

:root {
  --fam-industry: #2a78d6;
  --fam-public: #eb6834;
  --fam-knowledge: #1baf7a;
  --fam-other: #6b7589;

  --map-water: #e9ecf1;
  --map-land: #fbfcfe;
  --map-town: #e2e9f6;
  --map-town-line: #c2cde3;
  --map-road: #a3b0c8;
  --map-label: #6d7a90;

  --map-water-fill: #b7d4ef;
  --map-water-line: #7ba7d4;
  --map-campus: #e6eede;
  --map-base: #efe6e0;
  --map-base-line: #cbb9ad;
  --map-rail: #9aa3b4;
  --map-street: #c2ccdd;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --fam-industry: #3987e5;
    --fam-public: #d95926;
    --fam-knowledge: #199e70;
    --fam-other: #8b96ab;

    --map-water: #0a101c;
    --map-land: #19223a;
    --map-town: #202c48;
    --map-town-line: #2d3a59;
    --map-road: #3a476a;
    --map-label: #8794ad;

    --map-water-fill: #16304d;
    --map-water-line: #27547f;
    --map-campus: #1d2b2a;
    --map-base: #2b2420;
    --map-base-line: #4a3b33;
    --map-rail: #46506b;
    --map-street: #2b3857;
  }
}
:root[data-theme="dark"] {
  --fam-industry: #3987e5;
  --fam-public: #d95926;
  --fam-knowledge: #199e70;
  --fam-other: #8b96ab;

  --map-water: #0a101c;
  --map-land: #19223a;
  --map-town: #202c48;
  --map-town-line: #2d3a59;
  --map-road: #3a476a;
  --map-label: #8794ad;

  --map-water-fill: #16304d;
  --map-water-line: #27547f;
  --map-campus: #1d2b2a;
  --map-base: #2b2420;
  --map-base-line: #4a3b33;
  --map-rail: #46506b;
  --map-street: #2b3857;
}

/* --------------------------------------------------------------- controls */

.map-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 0 0 12px;
}
.map-search {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1 1 260px;
  min-width: 0;
  padding: 0 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  color: var(--muted);
}
.map-search:focus-within { border-color: var(--focus); }
.map-search input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  padding: 8px 0;
}
.map-search input:focus { outline: none; }
.map-controls select,
.map-pick select {
  padding: 8px 10px;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--r);
  font: inherit;
}
.map-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
.map-toggle:has(input:checked) { color: var(--ink); border-color: var(--line-strong); }
.btn-small { padding: 7px 10px; font-size: 13px; }

/* -------------------------------------------------------------- the legend */

.map-key {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  margin: 0 0 14px;
}
.map-key-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
}
.map-key-family {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  padding-right: 2px;
}
.map-key-family::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  margin-right: 5px;
  vertical-align: 0;
  background: var(--fam-other);
}
.map-key-family[data-family="industry"]::before { background: var(--fam-industry); }
.map-key-family[data-family="public"]::before { background: var(--fam-public); }
.map-key-family[data-family="knowledge"]::before { background: var(--fam-knowledge); }

.map-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px 4px 5px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.map-chip:hover { border-color: var(--line-strong); }
.map-chip[aria-pressed="true"] {
  border-color: var(--ink);
  background: var(--surface-2);
  font-weight: 600;
}
.map-chip.is-off { opacity: 0.45; }
.map-chip-glyph { width: 16px; height: 16px; flex: none; }
.map-chip-n {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}

/* --------------------------------------------------------------- the stage */

.map-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 16px;
  align-items: start;
}
.map-stage { min-width: 0; }
.map-canvas {
  position: relative;
  background: var(--map-water);
  border: 1px solid var(--line);
  border-radius: var(--r);
  overflow: hidden;
}
#map-svg {
  display: block;
  width: 100%;
  height: auto;
  /* Vertical swipes still scroll the page: the map must never be a pit you
     scroll into and can't get out of. Dragging to pan is a mouse gesture. */
  touch-action: pan-y;
  cursor: grab;
}
#map-svg.is-dragging { cursor: grabbing; }
.map-foot { margin: 8px 2px 0; }

.map-zoom {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
/* .btn-icon is built for the navy masthead, so its label is white. On a pale
   map panel that is white on white — give these their own ink. */
.map-zoom .btn,
.map-detail-close {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  line-height: 1;
}
.map-zoom .btn:hover,
.map-detail-close:hover { color: var(--ink); border-color: var(--line-strong); }

.map-tip {
  position: absolute;
  z-index: 3;
  transform: translate(12px, -50%);
  max-width: 230px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 6px 9px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r);
  box-shadow: 0 4px 14px rgb(0 0 0 / 0.14);
  font-size: 12.5px;
  line-height: 1.4;
  pointer-events: none;
}
.map-tip.is-flipped { transform: translate(calc(-100% - 12px), -50%); }
.map-tip strong { font-size: 13px; }

/* ------------------------------------------------------------ the geometry */

.map-county { fill: var(--map-land); stroke: none; }
.map-county-line {
  fill: none;
  stroke: var(--line-strong);
  stroke-width: 1.4;
  vector-effect: non-scaling-stroke;
}
.map-town {
  fill: var(--map-town);
  stroke: var(--map-town-line);
  stroke-width: 0.8;
  vector-effect: non-scaling-stroke;
}
.map-road {
  fill: none;
  stroke: var(--map-road);
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}
.map-road-interstate { stroke-width: 2.2; }
.map-road-toll { stroke-width: 1.8; stroke-dasharray: 7 4; }
.map-road-us { stroke-width: 1.5; }
.map-road-state { stroke-width: 1; }
.map-road-other { stroke-width: 0.8; opacity: 0.75; }
.map-road-secondary { stroke-width: 0.7; opacity: 0.8; }

/* Water, campuses, rail, streets. None of this is data — it is the
   difference between a dot on a white rectangle and a dot somewhere. */
.map-lake {
  fill: var(--map-water-fill);
  stroke: var(--map-water-line);
  stroke-width: 0.6;
  vector-effect: non-scaling-stroke;
}
.map-river {
  fill: none;
  stroke: var(--map-water-line);
  stroke-width: 0.9;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}
.map-campus { fill: var(--map-campus); stroke: none; }
.map-base {
  fill: var(--map-base);
  stroke: var(--map-base-line);
  stroke-width: 0.8;
  stroke-dasharray: 4 3;
  vector-effect: non-scaling-stroke;
}
.map-rail {
  fill: none;
  stroke: var(--map-rail);
  stroke-width: 0.9;
  stroke-dasharray: 5 4;
  vector-effect: non-scaling-stroke;
}
.map-street {
  fill: none;
  stroke: var(--map-street);
  stroke-width: 0.9;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

/* Detail by zoom. Drawing everything at once makes a map of roads rather
   than a map of companies; drawing only the county line leaves dots on an
   empty rectangle. So it arrives as you go in. */
.map-layer { display: none; }
#map-svg[data-detail="1"] .map-layer-near,
#map-svg[data-detail="2"] .map-layer-near { display: inline; }
#map-svg[data-detail="2"] .map-layer-close { display: inline; }
/* Secondary roads live in the roads group rather than a layer group, so they
   are gated on their own: in from the middle zoom, like the rest of "near". */
#map-svg[data-detail="0"] .map-road-secondary { display: none; }

.map-label {
  fill: var(--map-label);
  font: 600 10px var(--sans);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-anchor: middle;
  paint-order: stroke;
  stroke: var(--map-land);
  stroke-width: 3;
  stroke-linejoin: round;
}

/* ---------------------------------------------------------------- the pins */

.pin { cursor: pointer; }
.pin-hit { fill: transparent; }

/* --pin-scale is set by the view from the SVG's rendered width, so a glyph is
   the same size on screen whether the map has the whole window or half of a
   folded layout. Everything inside a pin is written in drawing units and
   scaled here, once. */
.map-canvas { --pin-scale: 1; }
#map-pins .pin-glyph,
#map-pins .pin-hit { transform: scale(var(--pin-scale)); }
.pin-glyph > * {
  /* A hairline of surface colour between marks, so two touching glyphs read
     as two things rather than one blob. */
  stroke: var(--surface);
  stroke-width: 1.6;
  paint-order: stroke;
}
.pin-hole { fill: var(--surface); stroke: none; }

.pin-industry .pin-glyph > *:not(.pin-hole) { fill: var(--fam-industry); }
.pin-public .pin-glyph > *:not(.pin-hole) { fill: var(--fam-public); }
.pin-knowledge .pin-glyph > *:not(.pin-hole) { fill: var(--fam-knowledge); }
.pin-other .pin-glyph > *:not(.pin-hole) { fill: var(--fam-other); }

/* Placed to the middle of a town rather than to a building. Drawn washed out
   with its own outline, so nobody reads a guess as a street address. */
.pin.is-approx .pin-glyph > *:not(.pin-hole) {
  fill-opacity: 0.22;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-dasharray: 2.4 1.8;
}
.pin.is-approx.pin-industry { color: var(--fam-industry); }
.pin.is-approx.pin-public { color: var(--fam-public); }
.pin.is-approx.pin-knowledge { color: var(--fam-knowledge); }
.pin.is-approx.pin-other { color: var(--fam-other); }
.pin.is-approx .pin-hole { display: none; }

#map-pins .pin:hover .pin-glyph { transform: scale(calc(var(--pin-scale) * 1.3)); }
#map-pins .pin.is-selected .pin-glyph { transform: scale(calc(var(--pin-scale) * 1.45)); }
.pin.is-selected .pin-glyph > *:not(.pin-hole) {
  stroke: var(--ink);
  stroke-width: 2;
  fill-opacity: 1;
  stroke-dasharray: none;
}

/* ---------------------------------------------------------------- the side */

.map-side {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.map-count { padding: 0 2px; font-variant-numeric: tabular-nums; }
.map-list {
  max-height: 62vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 4px;
}
.map-group + .map-group { margin-top: 6px; }
.map-group > h3 {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin: 0;
  padding: 7px 8px 5px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  font: 600 11px var(--sans);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.map-group > h3 .n { font-variant-numeric: tabular-nums; }

.map-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 8px;
  background: none;
  border: 0;
  border-radius: 4px;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.map-row:hover { background: var(--surface-2); }
.map-row.is-selected { background: var(--info-bg); }
/* No coordinates, so there is no dot to go to — still a finding, still listed. */
.map-row.is-unplaced .map-row-glyph { opacity: 0.4; }
.map-row.is-unplaced .map-row-name { color: var(--muted); }

.map-row-glyph { width: 16px; height: 16px; flex: none; }
.map-row-glyph[data-family="industry"] .pin-glyph > *:not(.pin-hole) { fill: var(--fam-industry); }
.map-row-glyph[data-family="public"] .pin-glyph > *:not(.pin-hole) { fill: var(--fam-public); }
.map-row-glyph[data-family="knowledge"] .pin-glyph > *:not(.pin-hole) { fill: var(--fam-knowledge); }
.map-row-glyph[data-family="other"] .pin-glyph > *:not(.pin-hole) { fill: var(--fam-other); }
.map-chip-glyph[data-family="industry"] .pin-glyph > *:not(.pin-hole) { fill: var(--fam-industry); }
.map-chip-glyph[data-family="public"] .pin-glyph > *:not(.pin-hole) { fill: var(--fam-public); }
.map-chip-glyph[data-family="knowledge"] .pin-glyph > *:not(.pin-hole) { fill: var(--fam-knowledge); }
.map-chip-glyph[data-family="other"] .pin-glyph > *:not(.pin-hole) { fill: var(--fam-other); }

.map-row-text { min-width: 0; display: flex; flex-direction: column; }
.map-row-name {
  font-weight: 600;
  font-size: 13.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.map-row-sub {
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.map-flag {
  margin-left: auto;
  flex: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--gold-bg);
  color: var(--gold);
  font: 700 11px var(--sans);
  line-height: 16px;
  text-align: center;
}

/* -------------------------------------------------------------- the detail */

.map-detail {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r);
  padding: 12px;
}
.map-detail-top {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 8px;
}
.map-detail-top > div { flex: 1; min-width: 0; }
.map-detail-top h2 {
  font: 600 16px/1.3 var(--display);
  text-wrap: pretty;
}
.map-detail-top .map-row-glyph { margin-top: 3px; }
.map-detail-close { margin: -4px -4px 0 0; flex: none; }

.map-what { margin: 0 0 8px; font-size: 13.5px; }
.map-tie {
  margin: 0 0 10px;
  padding: 8px 10px;
  background: var(--surface-2);
  border-radius: 4px;
  font-size: 13px;
}
.map-tie strong { color: var(--muted); font-weight: 600; }

.map-fields { margin: 0; display: grid; gap: 5px; }
.map-field { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 8px; }
.map-field dt {
  font-size: 11.5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  padding-top: 1px;
}
.map-field dd { margin: 0; font-size: 13px; overflow-wrap: anywhere; }

.map-detail-links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
  font-size: 13px;
}
.map-detail-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding-top: 9px;
  border-top: 1px solid var(--line);
  font-size: 12.5px;
}
.map-sources { display: flex; flex-wrap: wrap; gap: 8px; }
.map-conf {
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
}
.map-conf-ok { background: var(--ok-bg); color: var(--ok); }
.map-conf-check { background: var(--gold-bg); color: var(--gold); }

/* ------------------------------------------------------------- narrow view */

@media (max-width: 1000px) {
  .map-layout { grid-template-columns: minmax(0, 1fr); }
  .map-list { max-height: none; }
}

@media (prefers-reduced-motion: reduce) {
  /* Still scaled to the column — just not grown on hover. */
  #map-pins .pin:hover .pin-glyph { transform: scale(var(--pin-scale)); }
}
