:root {
  /* type */
  --font-display: "Fraunces", "Times New Roman", serif;
  --font-body: "IBM Plex Sans", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", monospace;

  /* modular scale, 1.250 */
  --t-xs: 0.8rem;     /* 12.8 */
  --t-sm: 0.9rem;     /* 14.4 */
  --t-base: 1rem;     /* 16   */
  --t-md: 1.25rem;    /* 20   */
  --t-lg: 1.563rem;   /* 25   */
  --t-xl: 1.953rem;   /* 31   */
  --t-xxl: 2.441rem;  /* 39   */
  --t-xxxl: 3.052rem; /* 49   */

  /* spacing */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 24px;
  --s-6: 32px;
  --s-7: 48px;
  --s-8: 64px;

  /* colour: paper, ink, accent, muted */
  --c-paper: #faf8f4;
  --c-paper-2: #f3efe6;
  --c-ink: #1a1d24;
  --c-ink-2: #3a3f48;
  --c-muted: #6b7280;
  --c-hairline: #d9d3c5;
  --c-accent: #1d4e3a;
  --c-accent-ink: #ffffff;

  /* stage scale: warm earth tones, light → dark, with grey for on-hold */
  --c-stage-early: #d9b46a;
  --c-stage-design: #c89259;
  --c-stage-statutory: #b87344;
  --c-stage-works: #9d502c;
  --c-stage-commissioning: #7a341c;
  --c-stage-complete: #4a1810;
  --c-stage-onhold: #8a8378;

  --radius: 2px;
  --hairline: 1px solid var(--c-hairline);
  --transition: 150ms ease-out;
}

/* base ---------------------------------------------------------------- */
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font-body);
  font-size: var(--t-base);
  line-height: 1.5;
  color: var(--c-ink);
  background: var(--c-paper);
  -webkit-font-smoothing: antialiased;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  grid-template-columns: minmax(0, 1fr);
  min-height: 100vh;
}
h1, h2, h3 { font-family: var(--font-display); font-weight: 500; line-height: 1.15; margin: 0; letter-spacing: -0.01em; }
.muted { color: var(--c-muted); }
.mono { font-family: var(--font-mono); font-size: 0.92em; }
button { font: inherit; cursor: pointer; }

/* header -------------------------------------------------------------- */
.page-header {
  padding: var(--s-6) var(--s-7) var(--s-4);
  border-bottom: var(--hairline);
  display: flex;
  align-items: baseline;
  gap: var(--s-5);
  flex-wrap: wrap;
}
.masthead {
  font-family: var(--font-display);
  font-size: var(--t-xl);
  font-weight: 600;
  letter-spacing: -0.02em;
}
.masthead-dot { color: var(--c-accent); }
.strapline {
  margin: 0;
  font-size: var(--t-sm);
  color: var(--c-ink-2);
  max-width: 60ch;
}

/* filters ------------------------------------------------------------- */
.filters {
  padding: var(--s-4) var(--s-7);
  border-bottom: var(--hairline);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-5);
  background: var(--c-paper);
}
.filter-group { display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap; }
.filter-label {
  font-family: var(--font-mono);
  font-size: var(--t-xs);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--c-muted);
}
.chips { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  padding: 2px var(--s-3);
  font-size: var(--t-sm);
  border: 1px solid var(--c-hairline);
  background: transparent;
  color: var(--c-ink);
  border-radius: 999px;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.chip:hover { background: var(--c-paper-2); }
.chip.is-active {
  background: var(--c-accent);
  color: var(--c-accent-ink);
  border-color: var(--c-accent);
}
.chip-count {
  font-family: var(--font-mono);
  font-size: var(--t-xs);
  opacity: 0.7;
  /* Reserve a fixed-width slot so 1-digit ↔ 2-digit count changes don't
     reflow the chip and shift downstream filter groups. */
  display: inline-block;
  min-width: 1.6em;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.view-toggle {
  margin-left: auto;
  display: inline-flex;
  border: var(--hairline);
  border-radius: var(--radius);
  overflow: hidden;
}
.view-btn {
  padding: 4px var(--s-3);
  border: 0;
  background: transparent;
  color: var(--c-ink);
  font-size: var(--t-sm);
}
.view-btn:hover { background: var(--c-paper-2); }
.view-btn.is-active { background: var(--c-ink); color: var(--c-paper); }

/* canvas -------------------------------------------------------------- */
/* Two-column grid: map/list left, detail right. Detail column is 0fr
   when no scheme is selected; opens to the panel width and physically
   shrinks the map area so right-side pins remain visible. */
.canvas {
  position: relative;
  min-height: 0;
  overflow: hidden;
  display: grid;
  /* minmax(0, 0fr) forces a *true* 0-width track when closed; plain '0fr'
     still allocates implicit min-content if any child has min-content size,
     which leaked the close button and a sliver of the panel into view. */
  grid-template-columns: 1fr minmax(0, 0fr);
  grid-template-rows: 1fr;
  transition: grid-template-columns var(--transition);
}
.canvas.is-detail-open {
  grid-template-columns: 1fr clamp(520px, 50vw, 720px);
}
.view {
  grid-column: 1; grid-row: 1;
  min-width: 0; min-height: 320px;
  width: 100%; height: 100%;
}
.view:not(.is-active) { display: none; }
.view-map .leaflet-container { background: var(--c-paper-2); }

/* list view ----------------------------------------------------------- */
.view-list {
  padding: var(--s-5) var(--s-7);
  overflow-y: auto;
}
.list-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--t-sm);
}
.list-table th, .list-table td {
  text-align: left;
  padding: var(--s-3) var(--s-4) var(--s-3) 0;
  border-bottom: var(--hairline);
  vertical-align: top;
}
.list-table th {
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: var(--t-xs);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--c-muted);
}
.list-row { cursor: pointer; }
.list-row:hover td { background: var(--c-paper-2); }
.list-row.is-selected td { background: var(--c-paper-2); }
.list-name { font-family: var(--font-display); font-size: var(--t-md); font-weight: 500; color: var(--c-ink); }
.stage-pip {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 999px;
  margin-right: var(--s-2);
  vertical-align: middle;
}

/* detail panel -------------------------------------------------------- */
.detail {
  grid-column: 2; grid-row: 1;
  min-width: 0;
  position: relative;       /* contains the absolutely-positioned close button */
  background: var(--c-paper);
  border-left: var(--hairline);
  padding: var(--s-6);
  overflow-y: auto;
  overflow-x: hidden;
}
/* Hidden state: still in the grid (so the column-width transition is the
   only motion), just nothing to show. The 0fr column clips it. */
.detail[hidden] { display: block !important; pointer-events: none; }
.detail-close {
  position: absolute;
  top: var(--s-4); right: var(--s-4);
  width: 32px; height: 32px;
  background: transparent;
  border: 0;
  font-size: var(--t-lg);
  line-height: 1;
  color: var(--c-muted);
}
.detail-close:hover { color: var(--c-ink); }
.d-title { font-family: var(--font-display); font-size: var(--t-xl); margin: 0 0 var(--s-2); padding-right: var(--s-6); letter-spacing: -0.015em; }
.d-meta { color: var(--c-muted); font-size: var(--t-sm); margin: 0 0 var(--s-5); }
.d-meta .sep { margin: 0 var(--s-2); }

.d-timeline {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  margin-bottom: var(--s-5);
}
.d-timeline-cell {
  height: 6px;
  background: var(--c-paper-2);
  border-radius: 1px;
}
.d-timeline-cell.is-reached { background: var(--c-stage-design); }
.d-timeline-cell.is-current { background: var(--c-accent); }
.d-timeline-cell.is-onhold { background: var(--c-stage-onhold); opacity: 0.4; }
.d-timeline-cell.is-onhold-current { background: var(--c-stage-onhold); }
.d-timeline-labels {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  text-transform: uppercase;
  color: var(--c-muted);
  margin-bottom: var(--s-5);
}
.d-timeline-labels span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.d-grid {
  display: grid;
  grid-template-columns: 8.5em 1fr;
  gap: var(--s-2) var(--s-4);
  font-size: var(--t-sm);
  margin-bottom: var(--s-5);
}
.d-grid dt { color: var(--c-muted); font-family: var(--font-mono); font-size: var(--t-xs); text-transform: uppercase; letter-spacing: 0.05em; padding-top: 2px; }
.d-grid dd { margin: 0; }

.d-section-title {
  font-family: var(--font-mono);
  font-size: var(--t-xs);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--c-muted);
  margin: var(--s-5) 0 var(--s-2);
}
.d-sources { list-style: none; padding: 0; margin: 0; font-size: var(--t-sm); }
.d-sources li {
  padding: var(--s-2) 0;
  border-top: var(--hairline);
}
.d-sources a { color: var(--c-ink); text-decoration: none; border-bottom: 1px solid var(--c-hairline); }
.d-sources a:hover { color: var(--c-accent); border-bottom-color: var(--c-accent); }
.d-sources .src-meta { display: block; color: var(--c-muted); font-size: var(--t-xs); margin-top: 2px; }
.d-notes {
  font-size: var(--t-sm);
  color: var(--c-ink-2);
  border-top: var(--hairline);
  padding-top: var(--s-3);
}

/* footer / legend ----------------------------------------------------- */
.page-footer {
  padding: var(--s-3) var(--s-7);
  border-top: var(--hairline);
  font-size: var(--t-xs);
  font-family: var(--font-mono);
  color: var(--c-muted);
  display: flex;
  align-items: center;
  gap: var(--s-5);
  flex-wrap: wrap;
}
.legend { display: inline-flex; align-items: center; gap: var(--s-2); flex-wrap: wrap; margin-left: auto; }
.legend-label { text-transform: uppercase; letter-spacing: 0.08em; margin-right: var(--s-2); }
.legend-swatch { display: inline-block; width: 8px; height: 8px; border-radius: 999px; margin-left: var(--s-3); }
.legend-swatch.s-early { background: var(--c-stage-early); }
.legend-swatch.s-design { background: var(--c-stage-design); }
.legend-swatch.s-statutory { background: var(--c-stage-statutory); }
.legend-swatch.s-works { background: var(--c-stage-works); }
.legend-swatch.s-commissioning { background: var(--c-stage-commissioning); }
.legend-swatch.s-complete { background: var(--c-stage-complete); }
.legend-swatch.s-onhold { background: var(--c-stage-onhold); }

/* leaflet markers ----------------------------------------------------- */
.leaflet-marker-pin { transition: r var(--transition), stroke-width var(--transition); }

/* responsive ---------------------------------------------------------- */
@media (max-width: 720px) {
  .page-header, .filters, .view-list, .page-footer { padding-left: var(--s-4); padding-right: var(--s-4); }
  .canvas.is-detail-open { grid-template-columns: 0fr 1fr; }
  .detail { border-left: 0; }
  .legend { display: none; }
}
