:root {
  --bg:          #F5F4EF;
  --bg-card:     #FFFFFF;
  --navy:        #1F3864;
  --teal:        #2A9D8F;
  --light-teal:  #D0EFEC;
  --red:         #C0392B;
  --light-red:   #FDECEA;
  --mid-grey:    #C8C7C2;
  --dark-text:   #1A1A1A;
  --muted-text:  #6B6B6B;
  --border:      #E8E7E2;
}

/* ── Reset ────────────────────────────────────────────────────────────── */
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', Arial, sans-serif;
  background-color: var(--bg);
  color: var(--dark-text);
  font-size: 14px;
  line-height: 1.5;
}

h1, h2, h3 { font-weight: inherit; }

/* ── Page header ──────────────────────────────────────────────────────── */
#page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  padding: 24px 48px;
  border-bottom: 1px solid var(--border);
}

#wordmark {
  font-family: 'Playfair Display', serif;
  font-size: 22px;
  font-weight: 400;
  line-height: 1.25;
  color: var(--dark-text);
}

#header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

#place-selector {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ── Settings menu ────────────────────────────────────────────────────── */
#settings { position: relative; }

#settings-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--muted-text);
  cursor: pointer;
}
#settings-btn:hover { color: var(--dark-text); border-color: var(--mid-grey); }
#settings-btn:focus-visible { outline: none; border-color: var(--teal); box-shadow: 0 0 0 2px var(--light-teal); }
#settings-btn[aria-expanded="true"] { color: var(--dark-text); border-color: var(--mid-grey); }

#settings-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 180px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 6px 24px rgba(31, 56, 100, 0.14);
  padding: 5px;
  z-index: 1000;
}
#settings-menu.hidden { display: none; }

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  color: var(--dark-text);
  background: none;
  border: none;
  border-radius: 4px;
  padding: 9px 10px;
  cursor: pointer;
  text-align: left;
}
.menu-item:hover { background: var(--bg); }
.menu-item svg { flex-shrink: 0; color: var(--muted-text); }
.menu-item .fs-exit { display: none; }
.menu-item.is-fullscreen .fs-enter { display: none; }
.menu-item.is-fullscreen .fs-exit { display: inline; }

#place-label {
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted-text);
}

.select-wrap {
  position: relative;
  width: 240px;
}

.select-wrap::after {
  content: '';
  position: absolute;
  right: 13px;
  top: 50%;
  width: 7px;
  height: 7px;
  border-right: 1.5px solid var(--muted-text);
  border-bottom: 1.5px solid var(--muted-text);
  transform: translateY(-65%) rotate(45deg);
  pointer-events: none;
}

#msa-select {
  width: 100%;
  font-family: 'Inter', sans-serif;
  font-size: 15px;
  padding: 7px 30px 7px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--dark-text);
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  cursor: pointer;
}

#msa-select:focus {
  outline: none;
  border-color: var(--teal);
  box-shadow: 0 0 0 2px var(--light-teal);
}

/* ── Main content ─────────────────────────────────────────────────────── */
#content {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 48px 60px;
  opacity: 1;
  transition: opacity 0.2s ease;
}

#content.fading {
  opacity: 0;
}

/* ── Authority header ─────────────────────────────────────────────────── */
#authority-header {
  padding: 36px 0 0;
}

#breadcrumb {
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted-text);
  margin-bottom: 10px;
}

#authority-name-row {
  display: flex;
  align-items: baseline;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

#authority-name {
  font-family: 'Playfair Display', serif;
  font-size: 42px;
  font-weight: 700;
  color: var(--dark-text);
  margin-bottom: 0;
}

.tier-pill {
  display: inline-block;
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 13px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  position: relative;
  top: -4px;
}

.tier-pill.tier-established { background: var(--navy); color: #ffffff; }
.tier-pill.tier-existing     { background: var(--teal); color: #ffffff; }
.tier-pill.tier-dpp          { background: var(--mid-grey); color: var(--dark-text); }

#meta-row {
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  color: var(--muted-text);
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
}

#meta-row .meta-sep { color: var(--mid-grey); }
#meta-row a { color: var(--teal); text-decoration: none; }
#meta-row a:hover { text-decoration: underline; }

#deep-dive-link {
  margin-top: 10px;
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  font-weight: 500;
}
#deep-dive-link a { color: var(--teal); text-decoration: none; }
#deep-dive-link a:hover { text-decoration: underline; }

/* ── Boundary map ─────────────────────────────────────────────────────── */
#map-section {
  padding: 28px 0;
}

#boundary-map {
  height: 350px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-card);
}

#map-caption {
  margin-top: 10px;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-style: italic;
  color: var(--muted-text);
}

/* ── Indicator table ──────────────────────────────────────────────────── */
#indicators-sections {
  padding-bottom: 20px;
}

#indicator-table {
  width: 100%;
  border-collapse: collapse;
}

#indicator-table thead th {
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted-text);
  text-align: left;
  padding: 0 12px 12px 0;
  border-bottom: 1px solid var(--border);
}

#indicator-table thead th.col-latest,
#indicator-table thead th.col-vs-england,
#indicator-table thead th.col-change {
  width: 18%;
}

#indicator-table thead th.col-rank {
  width: 14%;
  text-align: right;
}

#indicator-table tbody tr.group-row td {
  font-family: 'Playfair Display', serif;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted-text);
  background: #F0EFE9;
  padding: 10px 12px;
  border-top: none;
}

#indicator-table tbody tr.indicator-row {
  transition: background-color 0.1s ease;
}

#indicator-table tbody tr.indicator-row:hover {
  background-color: rgba(0,0,0,0.02);
}

#indicator-table tbody tr.indicator-row td {
  border-top: 1px solid var(--border);
  padding: 16px 12px 16px 0;
  vertical-align: top;
}

.cell-indicator { width: 32%; }

.ind-name {
  font-family: 'Playfair Display', serif;
  font-size: 16px;
  font-weight: 700;
  color: var(--dark-text);
  margin-bottom: 3px;
}

.ind-source {
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  font-style: italic;
  color: var(--muted-text);
}

.latest-value {
  font-family: 'Inter', sans-serif;
  font-size: 18px;
  font-weight: 600;
  color: var(--dark-text);
}

.latest-unit {
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  color: var(--muted-text);
  margin-top: 2px;
}

.delta {
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  font-weight: 600;
}

.delta.pos     { color: var(--teal); }
.delta.neg     { color: var(--red); }
.delta.neutral { color: var(--muted-text); }

.sub-line {
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  color: var(--muted-text);
  margin-top: 2px;
}

.cell-rank {
  text-align: right;
}

.rank-num {
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  font-weight: 700;
  color: var(--dark-text);
}

.rank-denom {
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  color: var(--muted-text);
}

.pending {
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  font-style: italic;
  color: var(--muted-text);
}

/* ── Responsive ───────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  #page-header { padding: 20px 24px; }
  #content { padding: 0 24px 48px; }
  #authority-name { font-size: 32px; }
  .select-wrap { width: 200px; }
  #indicator-table { font-size: 13px; }
  #indicator-table thead th.col-vs-england { display: none; }
  #indicator-table tbody td.cell-vs-england { display: none; }
}

/* ── Leaflet override ─────────────────────────────────────────────────── */
.leaflet-control-attribution {
  font-size: 10px !important;
}

/* ── Deep dive (inline narrative block below the indicator table) ───────── */
#deep-dive-section:not(:empty) {
  margin-top: 12px;
  padding-top: 32px;
  border-top: 1px solid var(--border);
}

.deep-dive-heading h2 {
  font-family: 'Playfair Display', serif;
  font-size: 26px;
  font-weight: 700;
  color: var(--dark-text);
}

.profile-intro {
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  color: var(--muted-text);
  max-width: 720px;
  margin: 8px 0 0;
}

.profile-section {
  padding: 32px 0;
  display: flex;
  align-items: stretch;
  gap: 36px;
}

.profile-section.reverse {
  flex-direction: row-reverse;
}

.profile-charts {
  flex: 1.4 1 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 12px;
}

.profile-chart-wrap img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 2px;
}

.profile-caption {
  margin-top: 2px;
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  font-style: italic;
  color: var(--muted-text);
}

.profile-text {
  flex: 1 1 0;
  aspect-ratio: 1 / 1;
  align-self: center;
  display: flex;
  align-items: center;
  background: var(--bg);
  padding: 28px;
}

.profile-insight {
  font-family: 'Playfair Display', serif;
  font-size: 18px;
  line-height: 1.45;
  color: var(--dark-text);
}

@media (max-width: 768px) {
  .profile-section h2 { font-size: 20px; }
  .profile-section, .profile-section.reverse {
    flex-direction: column;
  }
  .profile-text {
    aspect-ratio: auto;
  }
}

/* ── Chart panels ─────────────────────────────────────────────────────── */
#housing-panel {
  padding: 34px 0 10px;
  border-top: 1px solid var(--border);
}

.panel-head h2 {
  font-family: 'Playfair Display', serif;
  font-size: 22px;
  color: var(--navy);
}

.panel-sub {
  margin-top: 5px;
  font-size: 13px;
  color: var(--muted-text);
  max-width: 62ch;
}

/* One control row scoping the panel below it, never controls inside the card. */
.panel-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 18px;
  margin: 20px 0 14px;
}

.ctl { display: flex; flex-direction: column; gap: 5px; }

.ctl-label {
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted-text);
}

.ctl-label b {
  font-weight: 600;
  color: var(--dark-text);
  text-transform: none;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
}

.ctl .select-wrap { width: 190px; }

.ctl select {
  width: 100%;
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  padding: 7px 30px 7px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-card);
  color: var(--dark-text);
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}

.ctl select:focus,
.ctl-btn:focus-visible,
#housing-period:focus-visible {
  outline: none;
  border-color: var(--teal);
  box-shadow: 0 0 0 2px var(--light-teal);
}

.ctl-period { flex: 1 1 220px; min-width: 200px; }

#housing-period {
  width: 100%;
  accent-color: var(--teal);
  cursor: pointer;
  margin-bottom: 4px;
}

.ctl-btn {
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-card);
  color: var(--dark-text);
  cursor: pointer;
}

.ctl-btn[aria-pressed="true"] {
  background: var(--light-teal);
  border-color: var(--teal);
}

.panel-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 18px 20px 16px;
}

.panel-source {
  margin-top: 12px;
  font-size: 12px;
  color: var(--muted-text);
}

.housing-summary {
  margin-top: 6px;
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--dark-text);
  max-width: 78ch;
}

.housing-note { font-size: 13px; color: var(--muted-text); }

/* ── Strip plot ───────────────────────────────────────────────────────── */
.strip-plot { position: relative; }

.sp-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 4px;
  font-size: 12px;
  color: var(--muted-text);   /* text never wears the series colour */
}

.sp-key { display: inline-flex; align-items: center; gap: 6px; }

.sp-key i {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
}

.sp-key-ctx i { background: var(--mid-grey); }
.sp-key-hi  i { background: var(--teal); }

.sp-svg-wrap { position: relative; }
.sp-svg { display: block; width: 100%; overflow: visible; }

.sp-iqr { fill: var(--navy); opacity: 0.06; }

.sp-dot {
  fill: var(--mid-grey);
  fill-opacity: 0.7;
  transition: r 0.15s ease;
}

/* 2px surface ring keeps overlapping highlighted dots legible. */
.sp-dot.is-highlight {
  fill: var(--teal);
  fill-opacity: 1;
  stroke: var(--bg-card);
  stroke-width: 2;
}

.sp-dot.is-hover {
  stroke: var(--navy);
  stroke-width: 2;
}

.sp-rule line { stroke-width: 1.5; }
.sp-median line    { stroke: var(--navy); }
.sp-median-hi line { stroke: var(--teal); }

.sp-rule text {
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  fill: var(--muted-text);
}

/* Recessive, solid hairline axis — never dashed. */
.sp-axis path.domain,
.sp-axis line { stroke: var(--border); shape-rendering: crispEdges; }

.sp-axis text.sp-tick {
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  fill: var(--muted-text);
  font-variant-numeric: tabular-nums;
}

.sp-axis-label {
  font-family: 'Inter', sans-serif;
  font-size: 11.5px;
  fill: var(--muted-text);
}

.sp-tooltip {
  position: absolute;
  transform: translateX(-50%);
  pointer-events: none;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 5px 9px;
  font-size: 12px;
  line-height: 1.35;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  transition: opacity 0.12s ease;
  z-index: 5;
}

.sp-tt-label { display: block; color: var(--dark-text); font-weight: 500; }
.sp-tt-value { display: block; color: var(--muted-text); font-variant-numeric: tabular-nums; }

/* ── Table view (the WCAG-clean twin of the chart) ────────────────────── */
.housing-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 14px;
  font-size: 13px;
}

.housing-table th,
.housing-table td {
  text-align: left;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
}

.housing-table th {
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted-text);
  font-weight: 500;
}

.housing-table td:nth-child(2),
.housing-table td:nth-child(3) { font-variant-numeric: tabular-nums; }

@media (max-width: 768px) {
  .panel-controls { gap: 14px; }
  .ctl, .ctl .select-wrap { width: 100%; }
  .ctl-period { flex-basis: 100%; }
}
