/* ==========================================================================
   Tokens + fonts — Azure Monochrome
   ========================================================================== */

:root {
  --bg: #F3F6F8;
  --surface: #FFFFFF;
  --surface-2: #ECF1F4;
  --line: #DFE6EB;
  --ink: #10222E;
  --ink-muted: #5C6D78; /* darkened from spec's #6A7A85: that value fell to 3.9:1 on --surface-2, below the 4.5:1 floor */
  --ink-inverse: #EAF2F7;
  --surface-dark: #10222E;
  --accent: #2274A5;
  --accent-hi: #6EB6DE;
  --accent-soft: #A9D6EC;
  --accent-deep: #123B54;

  --font-display: "Space Grotesk", sans-serif;
  --font-body: "Plus Jakarta Sans", sans-serif;
  --font-mono: "JetBrains Mono", monospace;

  --page-max: 1280px;
  --gutter: 24px;

  font-family: var(--font-body);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
}

a {
  color: var(--accent);
}

a:hover {
  color: var(--accent-deep);
}

@media (prefers-reduced-motion: no-preference) {
  a,
  button,
  .pill,
  tbody tr,
  thead th,
  .select-field select,
  .rail-card,
  .gl-marker {
    transition: color 150ms ease, background-color 150ms ease, border-color 150ms ease, transform 150ms ease, box-shadow 150ms ease;
  }
}

/* ==========================================================================
   Header band
   ========================================================================== */

.header-band {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 1.75rem var(--gutter) 1.25rem;
}

.header-inner {
  max-width: var(--page-max);
  margin: 0 auto;
}

.header-top {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.header-titles h1 {
  margin: 0 0 0.35rem;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(2.75rem, 4vw, 3.25rem);
  letter-spacing: -0.02em;
  line-height: 1.05;
  color: var(--ink);
}

.subtitle {
  margin: 0;
  color: var(--ink-muted);
  font-size: 0.95rem;
}

.header-controls {
  display: flex;
  align-items: flex-end;
  gap: 0.85rem;
  flex-wrap: wrap;
}

.result-count {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--ink-muted);
  white-space: nowrap;
  padding-bottom: 0.55rem;
}

.control-field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.select-field select {
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 0.8rem;
  min-width: 190px;
  max-width: 260px;
}

.select-field select:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.funding-toggle {
  display: flex;
  gap: 0.35rem;
}

.pill {
  appearance: none;
  border: none;
  padding: 0.4rem 0.75rem;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--ink-muted);
  font-family: var(--font-body);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.pill:hover {
  color: var(--ink);
}

.pill.is-active {
  background: var(--accent);
  color: var(--ink-inverse);
}

.pill.is-active:hover {
  background: var(--accent-deep);
  color: var(--ink-inverse);
}

.snapshot-note {
  margin: 0.75rem 0 0;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.02em;
  color: var(--ink-muted);
}

.snapshot-note a {
  color: var(--ink-muted);
  text-decoration-color: var(--line);
}

.snapshot-note a:hover {
  color: var(--accent);
}

/* ==========================================================================
   Stat row
   ========================================================================== */

.stats {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 1.25rem var(--gutter) 0;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 14px;
}

.stat-tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1rem 1.1rem;
}

.stat-tile.stat-dark {
  background: var(--surface-dark);
  border-color: var(--surface-dark);
}

.stat-value {
  display: block;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1.75rem, 3vw, 2.1rem);
  letter-spacing: -0.03em;
  line-height: 1.05;
  color: var(--ink);
}

.stat-dark .stat-value {
  color: var(--accent-hi);
}

.stat-label {
  display: block;
  margin-top: 0.3rem;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.stat-dark .stat-label {
  color: var(--ink-inverse);
  opacity: 0.7;
}

/* ==========================================================================
   Main band — directory rail / map / directory rail
   ========================================================================== */

.main-band {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 1.25rem var(--gutter);
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr) 250px;
  gap: 14px;
  align-items: stretch;
}

.map-panel {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  min-height: 560px;
}

#map {
  width: 100%;
  height: 100%;
  min-height: 560px;
}

.rail {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  max-height: 560px;
  overflow-y: auto;
  padding-right: 2px;
}

.rail-card {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.65rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
}

.rail-card:hover {
  border-color: var(--accent-soft);
}

.rail-card.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.rail-chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.7rem;
  height: 1.7rem;
  border-radius: 5px;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 500;
}

.rail-info {
  min-width: 0;
}

.rail-name {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 0.875rem;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rail-meta {
  margin-top: 0.15rem;
  font-size: 0.6875rem;
  color: var(--ink-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ==========================================================================
   Map: MapLibre GL overrides — markers, popup, controls
   ========================================================================== */

.gl-marker {
  width: 26px;
  height: 26px;
  border-radius: 99px;
  border: 2px solid #FFFFFF;
  box-shadow: 0 1px 4px rgba(16, 34, 46, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
}

.gl-marker.is-active {
  transform: scale(1.2308); /* 32px drawn size from a 26px base element */
  box-shadow: 0 2px 8px rgba(16, 34, 46, 0.28), 0 0 0 3px var(--accent-soft);
}

.maplibregl-popup-content {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(16, 34, 46, 0.16);
  padding: 0.85rem 1rem;
  font-family: var(--font-body);
}

.maplibregl-popup-tip {
  display: none;
}

.popup-name {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 0.95rem;
  color: var(--ink);
  margin-bottom: 0.2rem;
}

.popup-meta {
  font-size: 0.8rem;
  color: var(--ink-muted);
  line-height: 1.4;
}

.popup-district {
  margin-top: 0.35rem;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
}

.popup-link {
  display: inline-block;
  margin-top: 0.55rem;
  font-size: 0.8rem;
  color: var(--accent);
}

.maplibregl-ctrl-group {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: none;
  overflow: hidden;
}

.maplibregl-ctrl-group button {
  background: var(--surface);
}

.maplibregl-ctrl-group button + button {
  border-top: 1px solid var(--line);
}

.maplibregl-ctrl-group button:hover {
  background: var(--surface-2);
}

.maplibregl-ctrl-attrib {
  font-size: 9px;
}

.maplibregl-ctrl-attrib a {
  color: var(--ink-muted);
}

/* ==========================================================================
   Legend bar
   ========================================================================== */

.legend-bar {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 0 var(--gutter);
}

.sector-legend {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1rem 1.25rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  color: var(--ink-muted);
}

.legend-dot {
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 50%;
  border: 1px solid var(--line);
  flex: none;
}

.legend-count {
  opacity: 0.75;
}

/* ==========================================================================
   Full table
   ========================================================================== */

.table-section {
  max-width: var(--page-max);
  margin: 1.25rem auto 0;
  padding: 0 var(--gutter) 1.5rem;
}

.table-scroll {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

thead th {
  text-align: left;
  padding: 0.7rem 0.8rem;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  color: var(--ink-muted);
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

thead th:hover {
  color: var(--ink);
}

thead th.sorted {
  color: var(--accent);
}

tbody td {
  padding: 0.7rem 0.8rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

tbody tr {
  cursor: pointer;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover {
  background: var(--surface-2);
}

tbody tr.active {
  background: var(--accent-soft);
}

tbody tr.active .row-index {
  background: var(--surface);
}

.row-index {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.9rem;
  height: 1.9rem;
  padding: 0 0.3rem;
  margin-right: 0.6rem;
  border-radius: 5px;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--ink);
  background: var(--surface-2);
  vertical-align: middle;
}

.company-cell {
  display: flex;
  align-items: flex-start;
}

.company-text {
  min-width: 0;
}

.company-name {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 0.95rem;
  color: var(--ink);
}

.company-desc {
  display: block;
  font-size: 0.8rem;
  color: var(--ink-muted);
  margin-top: 0.2rem;
  max-width: 340px;
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
}

.funding-figure {
  font-family: var(--font-mono);
  font-weight: 500;
  color: var(--accent);
  white-space: nowrap;
}

.dash {
  color: var(--ink-muted);
  font-family: var(--font-mono);
}

/* stacked rows under 700px */
@media (max-width: 700px) {
  thead {
    display: none;
  }

  tbody,
  tbody tr,
  tbody td {
    display: block;
    width: 100%;
  }

  tbody tr {
    border-bottom: 1px solid var(--line);
    padding: 0.7rem 0.8rem 0.9rem;
  }

  tbody td {
    padding: 0.15rem 0;
    border-bottom: none;
  }

  tbody td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-family: var(--font-mono);
    font-size: 0.62rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink-muted);
    margin-top: 0.4rem;
  }

  tbody td:first-child[data-label]::before {
    display: none;
  }
}

/* ==========================================================================
   Footer
   ========================================================================== */

.site-footer {
  border-top: 1px solid var(--line);
  margin-top: 0.5rem;
}

.footer-inner {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 1.25rem var(--gutter) 2rem;
}

.footer-note {
  margin: 0;
  font-size: 0.8rem;
  color: var(--ink-muted);
}

.footer-credit {
  margin: 0.4rem 0 0;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--ink-muted);
}

.footer-credit a {
  color: var(--ink-muted);
  text-decoration-color: var(--line);
}

.footer-credit a:hover {
  color: var(--accent);
}

/* ==========================================================================
   Detail drawer
   ========================================================================== */

.detail-drawer {
  position: fixed;
  right: 0;
  top: 0;
  bottom: 0;
  width: min(380px, 90vw);
  background: var(--surface);
  border-left: 1px solid var(--line);
  box-shadow: -8px 0 24px rgba(16, 34, 46, 0.15);
  padding: 1.5rem;
  overflow-y: auto;
  z-index: 1000;
}

.detail-drawer[hidden] {
  display: none;
}

.drawer-close {
  position: absolute;
  top: 0.75rem;
  right: 0.9rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--ink-muted);
  line-height: 1;
}

.drawer-close:hover {
  color: var(--ink);
}

#drawer-content h2 {
  margin-top: 0.2rem;
  margin-bottom: 0.3rem;
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink);
}

#drawer-content p {
  font-size: 0.9rem;
  color: var(--ink);
}

#drawer-content dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.5rem 0.8rem;
  font-size: 0.85rem;
  margin-top: 1rem;
}

#drawer-content dt {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-muted);
  padding-top: 0.1rem;
}

#drawer-content dd {
  margin: 0;
}

/* ==========================================================================
   Responsive: collapse the 3-column band under 1200px
   ========================================================================== */

@media (max-width: 1199px) {
  .stats {
    grid-template-columns: repeat(3, 1fr);
  }

  .main-band {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Promote each rail's cards to be direct grid items of .main-band, so the
     two rails read as one continuous, index-ordered list instead of two
     separate stacked blocks. */
  .rail-left,
  .rail-right {
    display: contents;
  }

  .rail-card {
    max-width: none;
  }

  .map-panel {
    grid-column: 1 / -1;
    order: -1;
    min-height: 420px;
  }

  #map {
    min-height: 420px;
  }
}

@media (max-width: 699px) {
  .stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .main-band {
    grid-template-columns: 1fr;
  }

  .header-top {
    align-items: flex-start;
  }

  .header-controls {
    width: 100%;
  }

  .select-field select {
    min-width: 0;
    flex: 1;
  }
}
