/* ============================================================
   NORTHAVEN TRAIL — PROPERTY VALUE DASHBOARD
   Design System: Custom CSS Variables, WCAG 2.1 AA compliant
   ============================================================ */

/* ---------- CSS Variables / Design Tokens ---------- */
:root {
  /* Brand Colors */
  --color-trail:        #118452;   /* Forest green — Trail Area */
  --color-trail-light:  #e6f4ed;
  --color-trail-dark:   #0c6340;
  --color-buffer:       #1f7291;   /* Steel blue — Outer Buffer */
  --color-buffer-light: #e6f1f6;
  --color-dallas:       #4b5563;   /* Charcoal — Dallas citywide */
  --color-dallas-light: #f1f3f5;

  /* UI Colors */
  --color-bg:           #faf9f6;   /* Warm off-white */
  --color-surface:      #ffffff;
  --color-surface-alt:  #f5f3ef;
  --color-border:       #e5e2db;
  --color-text:         #1a1a18;   /* Near-black — 15:1 on white */
  --color-text-muted:   #4b5563;   /* 7:1 on white */
  --color-text-faint:   #5a6472;   /* 5.4:1 on #f5f3ef — clears AA on tinted surfaces too */

  /* Accent */
  --color-accent:       #118452;
  --color-accent-hover: #0c6340;
  --color-warning:      #b45309;
  --color-positive:     #166534;
  --color-negative:     #9b1c1c;

  /* Typography */
  --font-display:  'Outfit', system-ui, sans-serif;
  --font-body:     'Inter', system-ui, sans-serif;
  --font-mono:     'Courier New', monospace;

  /* Spacing */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;

  /* Radius */
  --radius-sm:  0.375rem;
  --radius-md:  0.625rem;
  --radius-lg:  1rem;
  --radius-xl:  1.5rem;
  --radius-pill: 999px;

  /* Shadow */
  --shadow-sm:  0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md:  0 4px 12px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.04);
  --shadow-lg:  0 10px 30px rgba(0,0,0,0.10), 0 4px 8px rgba(0,0,0,0.05);

  /* Transition */
  --transition-fast:   150ms ease;
  --transition-normal: 250ms ease;
  --transition-slow:   400ms ease;

  /* Header */
  --header-height: 60px;
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-body);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  font-size: 1rem;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ---------- ADA: Skip Link ---------- */
.skip-link {
  position: absolute;
  top: -100%;
  left: var(--space-4);
  background: var(--color-trail);
  color: #fff;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.9rem;
  text-decoration: none;
  z-index: 9999;
  transition: top var(--transition-fast);
}
.skip-link:focus { top: var(--space-2); }

/* ---------- ADA: Focus Ring ---------- */
:focus-visible {
  outline: 2px solid var(--color-trail);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ---------- ADA: Screen-reader only ---------- */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Links ---------- */
a { color: var(--color-trail); text-decoration: underline; }
a:hover { color: var(--color-trail-dark); }

/* ---------- Header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 200;
  height: var(--header-height);
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 var(--space-6);
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-6);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-shrink: 0;
}

.header-logo {
  display: inline-flex;
  line-height: 1;
}

.header-logo svg {
  width: 2.1rem;
  height: 2.1rem;
  display: block;
}

.header-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1rem;
  color: var(--color-text);
  line-height: 1.2;
}

.header-subtitle {
  font-size: 0.7rem;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 500;
}

.header-nav {
  display: flex;
  gap: var(--space-1);
  align-items: center;
}

.header-nav a {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--color-text-muted);
  text-decoration: none;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-pill);
  transition: all var(--transition-fast);
}

.header-nav a:hover {
  color: var(--color-trail);
  background: var(--color-trail-light);
}

/* ---------- Disclaimer Banner ---------- */
.disclaimer-banner {
  background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
  border-bottom: 1px solid #fbbf24;
  padding: var(--space-3) var(--space-6);
  font-size: 0.875rem;
  color: #92400e;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.disclaimer-banner a { color: #92400e; font-weight: 600; }
.disclaimer-icon { font-size: 1rem; flex-shrink: 0; }
.disclaimer-text { flex: 1; min-width: 0; }

/* ---------- Section Wrappers ---------- */
.section-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: var(--space-12) var(--space-6);
}

.section-heading {
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 3vw, 2.25rem);
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: var(--space-3);
  line-height: 1.2;
}

.section-subheading {
  font-size: 1rem;
  color: var(--color-text-muted);
  max-width: 72ch;
  margin-bottom: var(--space-8);
  line-height: 1.65;
}

/* ---------- KPI Section ---------- */
.kpi-section {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

/* Year Selector */
.year-selector-bar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-8);
  padding: var(--space-3) var(--space-5);
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
}

.year-selector-label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-text-muted);
  flex-shrink: 0;
}

.year-buttons {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.year-btn {
  padding: var(--space-2) var(--space-4);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-pill);
  background: var(--color-surface);
  color: var(--color-text-muted);
  font-size: 0.875rem;
  font-weight: 500;
  font-family: var(--font-body);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.year-btn:hover {
  border-color: var(--color-trail);
  color: var(--color-trail);
  background: var(--color-trail-light);
}

.year-btn { min-height: 44px; }

.year-btn.active,
.year-btn[aria-pressed="true"] {
  background: var(--color-trail);
  border-color: var(--color-trail);
  color: #fff;
  box-shadow: 0 2px 8px rgba(17,132,82,0.3);
}

.baseline-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 0.8rem;
  color: var(--color-text-faint);
}

.baseline-badge label { font-weight: 600; }

.baseline-select {
  font-family: var(--font-body);
  font-size: 0.85rem;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-1) var(--space-2);
  cursor: pointer;
  min-height: 36px;
}

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-5);
}

.kpi-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  transition: box-shadow var(--transition-normal);
  position: relative;
  overflow: hidden;
}

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--color-border);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.kpi-card--primary::before { background: var(--color-trail); }

.kpi-card:hover { box-shadow: var(--shadow-md); }

.kpi-icon {
  font-size: 1.4rem;
  margin-bottom: var(--space-3);
  display: block;
}

.kpi-label {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  margin-bottom: var(--space-2);
}

.kpi-value {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 700;
  color: var(--color-text);
  line-height: 1.1;
  margin-bottom: var(--space-2);
  min-height: 2.4rem;
}

.kpi-value--positive { color: var(--color-positive); }
.kpi-value--negative { color: var(--color-negative); }

.kpi-sub {
  font-size: 0.775rem;
  color: var(--color-text-faint);
}

/* ---------- Map Section ---------- */
.map-section {
  background: var(--color-surface-alt);
  border-bottom: 1px solid var(--color-border);
}

.segment-selector-bar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
  flex-wrap: wrap;
}

.segment-selector-label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-text-muted);
}

.segment-selector {
  font-family: var(--font-body);
  font-size: 0.9rem;
  padding: var(--space-2) var(--space-4);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  min-width: 260px;
  cursor: pointer;
}

.segment-selector:focus-visible {
  outline: 2px solid var(--color-trail);
  outline-offset: 2px;
}

.btn-clear-segment {
  font-size: 0.8rem;
  padding: var(--space-2) var(--space-3);
  background: transparent;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-pill);
  color: var(--color-text-muted);
  cursor: pointer;
  font-family: var(--font-body);
  transition: all var(--transition-fast);
}
.btn-clear-segment:hover { border-color: var(--color-trail); color: var(--color-trail); }

.segment-filter-banner {
  background: var(--color-trail-light);
  border: 1px solid var(--color-trail);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-5);
  font-size: 0.875rem;
  color: var(--color-trail-dark);
  font-weight: 500;
  margin-bottom: var(--space-5);
}

.map-detail-grid {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: var(--space-6);
  align-items: start;
}

.map-detail-grid > * { min-width: 0; }

.map-container-wrapper { position: relative; }

.map-container {
  width: 100%;
  height: 520px;
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-md);
  background: #e8e4dc;
}

.map-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  background: rgba(250,249,246,0.85);
  z-index: 10;
  border-radius: var(--radius-lg);
  font-size: 0.9rem;
  color: var(--color-text-muted);
}

.map-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-trail);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.map-legend {
  position: absolute;
  bottom: var(--space-4);
  left: var(--space-4);
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(8px);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  font-size: 0.75rem;
  color: var(--color-text-muted);
  min-width: 140px;
}

.legend-title {
  font-weight: 600;
  margin-bottom: var(--space-2);
  color: var(--color-text);
}

.legend-gradient {
  height: 10px;
  border-radius: var(--radius-pill);
  background: linear-gradient(to right, #e6f4ed, #118452, #0c6340);
  margin-bottom: var(--space-2);
}

.legend-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
}

.map-hint {
  position: absolute;
  top: var(--space-4);
  left: var(--space-4);            /* top-left, clear of the top-right zoom controls */
  background: rgba(255,255,255,0.9);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  padding: var(--space-2) var(--space-4);
  font-size: 0.75rem;
  color: var(--color-text-muted);
  pointer-events: none;
  transition: opacity 0.25s ease;
}

/* Dismissed once the user starts hovering segments, so it never sits on top
   of the hover popups. */
.map-hint.is-hidden { opacity: 0; }

/* Detail Panel */
.detail-panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: calc(var(--header-height) + var(--space-4));
}

.detail-panel-heading {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--color-trail);
  margin-bottom: var(--space-5);
  padding-bottom: var(--space-3);
  border-bottom: 2px solid var(--color-trail-light);
}

.detail-placeholder {
  text-align: center;
  padding: var(--space-8) var(--space-4);
  color: var(--color-text-faint);
}

.detail-placeholder span { font-size: 2.5rem; display: block; margin-bottom: var(--space-4); }
.detail-placeholder p { font-size: 0.875rem; line-height: 1.6; }

.detail-stat {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--color-border);
  gap: var(--space-3);
}

.detail-stat:last-child { border-bottom: none; }

.detail-stat-label {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  font-weight: 500;
}

.detail-stat-value {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-text);
  text-align: right;
}

.detail-stat-value.positive { color: var(--color-positive); }
.detail-stat-value.negative { color: var(--color-negative); }

.detail-comparison-badge {
  display: inline-block;
  margin-top: var(--space-4);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--color-trail-light);
  color: var(--color-trail-dark);
}

/* ---------- Charts Section ---------- */
.charts-section {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

/* Property-type toggle */
.property-type-bar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-5);
}

.property-type-label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-text-muted);
}

.property-type-buttons {
  display: inline-flex;
  gap: 0;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-pill);
  overflow: hidden;
  background: var(--color-surface);
}

.ptype-btn {
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-text-muted);
  background: transparent;
  border: none;
  cursor: pointer;
  padding: var(--space-2) var(--space-5);
  min-height: 40px;
  transition: all var(--transition-fast);
}

.ptype-btn:hover { color: var(--color-trail); background: var(--color-trail-light); }

.ptype-btn.active,
.ptype-btn[aria-pressed="true"] {
  background: var(--color-trail);
  color: #fff;
}

.ptype-note {
  font-size: 0.8rem;
  color: var(--color-text-faint);
  font-style: italic;
  flex: 1 1 100%;
  margin: 0;
}

.chart-tabs {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-6);
  border-bottom: 2px solid var(--color-border);
  flex-wrap: wrap;
}

.chart-tab {
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--color-text-muted);
  background: transparent;
  border: none;
  cursor: pointer;
  padding: var(--space-3) var(--space-5);
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  transition: all var(--transition-fast);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.chart-tab:hover { color: var(--color-trail); }

.chart-tab--active {
  color: #0c6340; /* 5.7:1 on the light-green pill (AA needs 4.5:1) */
  border-bottom-color: var(--color-trail);
  background: var(--color-trail-light);
}

/* ---------- Trail Milestones Strip ---------- */
.milestone-strip {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin: 0 0 var(--space-6);
  padding: 0;
}

.milestone-strip li {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-left: 3px solid var(--color-trail);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-4);
  font-size: 0.85rem;
}

.milestone-date {
  font-weight: 700;
  color: var(--color-text);
  white-space: nowrap;
}

.milestone-label { color: var(--color-text-muted); }

.charts-grid { display: grid; gap: var(--space-6); }

/* min-width: 0 lets grid/flex items shrink below their canvas content size,
   so Chart.js can resize down when the viewport narrows (WCAG reflow) */
.chart-panel { display: flex; flex-direction: column; gap: var(--space-4); min-width: 0; }
.chart-wrapper canvas { max-width: 100%; }
.chart-panel--hidden { display: none; }

.chart-wrapper {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  box-shadow: var(--shadow-sm);
  position: relative;
  height: 380px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chart-wrapper canvas { max-height: 320px; }

/* Data Tables */
.data-table-toggle { margin-top: var(--space-2); }

.data-table-summary {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  cursor: pointer;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  font-weight: 500;
  user-select: none;
}

.data-table-summary:hover { color: var(--color-trail); }

.data-table-wrapper {
  margin-top: var(--space-3);
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
}

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

.data-table caption {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  text-align: left;
  padding: var(--space-3) var(--space-4);
  font-weight: 600;
}

.data-table th {
  background: var(--color-surface-alt);
  padding: var(--space-3) var(--space-4);
  font-weight: 600;
  font-size: 0.8rem;
  text-align: left;
  color: var(--color-text-muted);
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}

.data-table td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text);
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--color-surface-alt); }

/* ---------- Methodology Section ---------- */
.methodology-section {
  background: var(--color-surface-alt);
  border-bottom: 1px solid var(--color-border);
}

.methodology-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-16);
}

.methodology-section p {
  font-size: 0.95rem;
  color: var(--color-text-muted);
  line-height: 1.75;
  margin-bottom: var(--space-4);
}

.methodology-caution {
  background: #fef3c7;
  border-left: 4px solid #f59e0b;
  padding: var(--space-4) var(--space-5);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  color: #78350f !important;
}

.methodology-sources h3 {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: var(--space-4);
  margin-top: var(--space-6);
}

.methodology-sources h3:first-child { margin-top: 0; }

.methodology-sources ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.methodology-sources li {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  line-height: 1.7;
  padding-left: var(--space-5);
  border-left: 3px solid var(--color-trail-light);
}

.methodology-sources p {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  margin: 0;
}

/* ---------- Footer ---------- */
.site-footer {
  background: var(--color-text);
  color: rgba(255,255,255,0.7);
  padding: var(--space-8) var(--space-6);
}

.footer-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.footer-inner p { font-size: 0.85rem; }
.footer-inner a { color: rgba(255,255,255,0.85); }
.footer-disclaimer { color: rgba(255,255,255,0.58); font-size: 0.775rem; } /* 5.4:1 on footer black */

.tax-rates-footnote {
  font-size: 0.775rem;
  color: var(--color-text-faint);
  margin-top: var(--space-2);
}

/* Larger zoom-control touch targets (MapLibre default is 29px) */
.maplibregl-ctrl-group button {
  width: 40px;
  height: 40px;
}

/* ---------- Mapbox tooltip overrides ---------- */
/* Keep hover popups above the zoom controls and the map hint pill. */
.maplibregl-popup { z-index: 4; }

.mapboxgl-popup-content {
  font-family: var(--font-body);
  font-size: 0.85rem;
  border-radius: var(--radius-md);
  padding: var(--space-4) var(--space-5);
  box-shadow: var(--shadow-lg);
  max-width: 280px;
  border: 1px solid var(--color-border);
}

.popup-title {
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--color-trail);
  margin-bottom: var(--space-3);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--color-border);
}

.popup-row {
  display: flex;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-1) 0;
  font-size: 0.8rem;
}

.popup-row-label { color: var(--color-text-muted); }
.popup-row-value { font-weight: 600; color: var(--color-text); }
.popup-row-value.positive { color: var(--color-positive); }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .map-detail-grid {
    grid-template-columns: 1fr;
  }

  .detail-panel {
    position: static;
    order: -1;
  }

  .methodology-grid {
    grid-template-columns: 1fr;
    gap: var(--space-8);
  }

  .header-nav { display: none; }

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

@media (max-width: 560px) {
  .section-inner { padding: var(--space-8) var(--space-4); }
  .kpi-grid { grid-template-columns: 1fr; }
  .chart-tabs { gap: 0; }
  .chart-tab { font-size: 0.8rem; padding: var(--space-2) var(--space-3); }
  .map-container { height: 360px; }
  .kpi-value { font-size: 1.6rem; }
}

/* Print-only chart report (populated on beforeprint) */
.print-charts { display: none; }

/* ---------- Print ---------- */
@page { margin: 0.5in; }

@media print {
  /* Hide interactive-only chrome, including the live chart tabs / toggle /
     grid — the print-charts block below replaces them with a static report
     covering every property type. */
  .skip-link,
  .map-hint,
  .maplibregl-ctrl,
  .maplibregl-cooperative-gesture-screen,
  .btn-clear-segment,
  .chart-tabs,
  .property-type-bar,
  .charts-grid,
  .header-nav { display: none !important; }

  /* Print report: all three chart types, grouped per property type */
  .print-charts { display: block; }
  .print-type-heading {
    font-family: var(--font-display);
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--color-text);
    margin: var(--space-6) 0 var(--space-3);
    padding-bottom: var(--space-2);
    border-bottom: 2px solid var(--color-trail);
    break-after: avoid;
    page-break-after: avoid;
  }
  .print-chart-img {
    display: block;
    width: 100%;
    max-width: 640px;
    margin: 0 auto var(--space-5);
    break-inside: avoid;
    page-break-inside: avoid;
  }

  body { background: #fff; }

  /* Sticky positioning overlaps content when paginating */
  .site-header {
    position: static;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    box-shadow: none;
  }

  /* Keep atomic blocks on one page */
  .kpi-card,
  .year-selector-bar,
  .milestone-strip li,
  .chart-wrapper,
  .data-table-wrapper,
  .data-table-toggle,
  .detail-panel,
  .map-container-wrapper,
  .map-legend,
  .methodology-sources,
  .methodology-caution {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  /* Don't leave a heading stranded at the bottom of a page */
  .section-heading,
  .section-subheading,
  h3 {
    break-after: avoid;
    page-break-after: avoid;
  }

  /* Major sections each start on a fresh page; this also stops the
     methodology section from colliding with the charts above it */
  .map-section,
  .charts-section,
  .methodology-section {
    break-before: page;
    page-break-before: always;
  }

  /* Flatten decorative depth for ink */
  .kpi-card,
  .chart-wrapper,
  .detail-panel { box-shadow: none; }
}
