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

/* Theme variables: chrome only (surfaces, text, borders). Score/category/overlay
   colors are data semantics and stay identical in both themes. */
:root {
  --surface: #fff;
  --surface-2: #f8f9fa;
  --surface-3: #f5f5f5;
  --hover: #f5f7ff;
  --accent-bg: #e8f0fe;
  --track: #eee;
  --border: #ddd;
  --border-2: #f0f0f0;
  --text: #1a1a1a;
  --text-2: #555;
  --text-muted: #888;
  --text-faint: #bbb;
  --accent: #1a73e8;
}
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: var(--surface-2); color: var(--text); height: 100vh; overflow: hidden; }

#app { display: flex; height: 100vh; }

.sidebar {
  width: 380px; min-width: 380px; background: var(--surface); display: flex; flex-direction: column;
  border-right: 1px solid var(--border); z-index: 1000; position: relative;
}
.sidebar-header {
  padding: 16px 20px; background: #1a73e8; color: #fff; position: relative;
}
.sidebar-header h1 { font-size: 18px; font-weight: 700; letter-spacing: -0.3px; }
.sidebar-header .subtitle { font-size: 12px; opacity: 0.85; margin-top: 2px; }

.sidebar-controls { padding: 12px 16px; border-bottom: 1px solid var(--border); }
.sidebar-controls select, .sidebar-controls input {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px;
  font-size: 13px; background: var(--surface); color: var(--text); outline: none;
}
.sidebar-controls select:focus, .sidebar-controls input:focus { border-color: #1a73e8; }
.sidebar-controls label { display: block; font-size: 11px; font-weight: 600; color: var(--text-2); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.5px; }
.sidebar-controls > div + div { margin-top: 10px; }

.filters-panel { margin-top: 10px; }
.filters-panel summary {
  cursor: pointer; font-size: 11px; font-weight: 600; color: var(--text-2);
  text-transform: uppercase; letter-spacing: 0.5px; list-style: none;
  display: flex; align-items: center; gap: 6px; user-select: none;
}
.filters-panel summary::-webkit-details-marker { display: none; }
.filters-panel summary::before { content: '▸'; font-size: 9px; color: var(--text-muted); transition: transform 0.15s; }
.filters-panel[open] summary::before { transform: rotate(90deg); }
.filter-active-count {
  font-size: 10px; font-weight: 600; color: #1a73e8; background: var(--accent-bg);
  padding: 1px 6px; border-radius: 8px; text-transform: none; letter-spacing: 0;
}
.filter-rule {
  display: flex; align-items: center; gap: 6px; margin-top: 6px;
  font-size: 12px; color: var(--text-2); background: var(--hover); border: 1px solid var(--border-2);
  border-radius: 6px; padding: 4px 8px;
}
.filter-rule .filter-rule-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filter-rule .filter-rule-cond { flex-shrink: 0; font-variant-numeric: tabular-nums; }
.filter-rule .filter-rule-remove {
  border: none; background: none; color: var(--text-muted); cursor: pointer; font-size: 14px;
  padding: 0 2px; line-height: 1; flex-shrink: 0;
}
.filter-rule .filter-rule-remove:hover { color: #c62828; }
.filter-add-row { display: grid; grid-template-columns: 1fr 50px 62px 42px; gap: 6px; margin-top: 8px; }
.filter-add-row select, .filter-add-row input { padding: 6px; font-size: 12px; }
.filter-add-row button {
  border: 1px solid #1a73e8; background: var(--surface); color: #1a73e8; border-radius: 6px;
  font-size: 12px; font-weight: 600; cursor: pointer;
}
.filter-add-row button:hover { background: #1a73e8; color: #fff; }
.filter-match-count { font-size: 11px; color: #1a73e8; font-weight: 600; margin-top: 8px; }
.filter-clear-btn {
  margin-top: 6px; border: none; background: none; color: var(--text-2); font-size: 11px;
  cursor: pointer; text-decoration: underline; padding: 0;
}
.filter-clear-btn:hover { color: #c62828; }
.filter-hint { font-size: 10px; color: var(--text-muted); margin-top: 6px; line-height: 1.4; }

.commute-controls { margin-top: 8px; }
.commute-controls select { margin-bottom: 8px; }
.sidebar-controls .commute-enable {
  display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-2);
  font-weight: 400; text-transform: none; letter-spacing: 0; margin-bottom: 8px; cursor: pointer;
}
.commute-enable input { width: auto; cursor: pointer; }
.commute-slider-row { display: flex; align-items: center; gap: 8px; }
.commute-slider-row input[type="range"] { flex: 1; padding: 0; }
.commute-slider-row span { font-size: 11px; color: var(--text-2); min-width: 46px; text-align: right; font-variant-numeric: tabular-nums; }

.about-h { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); margin: 16px 0 6px; }
.about-h:first-child { margin-top: 0; }
.about-p { font-size: 12px; color: var(--text-2); line-height: 1.55; }
.about-list { font-size: 12px; color: var(--text-2); line-height: 1.55; padding-left: 18px; }
.about-list li { margin-bottom: 3px; }
.about-table { width: 100%; font-size: 11px; border-collapse: collapse; }
.about-table td { padding: 6px 8px; border-bottom: 1px solid var(--border-2); vertical-align: top; }
.about-table .about-src { width: 175px; font-weight: 600; color: var(--text); }
.about-table .about-years { font-weight: 400; color: var(--text-muted); font-size: 10px; margin-top: 2px; }
.about-table .about-inds { color: var(--text-2); line-height: 1.5; }

.area-list { flex: 1; overflow-y: auto; }
.area-item {
  padding: 10px 16px; border-bottom: 1px solid var(--border-2); cursor: pointer;
  display: flex; align-items: center; gap: 10px; transition: background 0.15s;
}
.area-item:hover { background: var(--hover); }
.area-item.selected { background: var(--accent-bg); border-left: 3px solid #1a73e8; }
.area-item .score-badge {
  width: 40px; height: 40px; border-radius: 8px; display: flex; align-items: center;
  justify-content: center; font-size: 14px; font-weight: 700; color: #fff; flex-shrink: 0;
}
.area-item .area-info { flex: 1; min-width: 0; }
.area-item .area-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.area-item .area-meta { font-size: 11px; color: var(--text-muted); margin-top: 1px; }
.area-item .classification-tag {
  font-size: 10px; font-weight: 600; padding: 2px 6px; border-radius: 3px;
  display: inline-block; margin-top: 3px;
}
.area-item .compare-btn {
  padding: 4px 8px; font-size: 11px; border: 1px solid var(--border); border-radius: 4px;
  background: var(--surface); cursor: pointer; color: var(--text-2); flex-shrink: 0; transition: all 0.15s;
}
.area-item .compare-btn:hover { border-color: #1a73e8; color: #1a73e8; }
.area-item .compare-btn.active { background: #1a73e8; color: #fff; border-color: #1a73e8; }

.sidebar-footer {
  padding: 10px 16px; border-top: 1px solid var(--border);
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px;
  background: var(--surface-2);
}
.sidebar-footer button {
  padding: 6px 4px; font-size: 11px; border: 1px solid var(--border); border-radius: 4px;
  background: var(--surface); cursor: pointer; color: var(--text-2); transition: all 0.15s;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-footer button:hover { border-color: #1a73e8; color: #1a73e8; }

.map-container { flex: 1; position: relative; }
#map { height: 100%; width: 100%; }

.detail-panel {
  position: absolute; top: 0; right: 0; width: 440px; height: 100%; background: var(--surface);
  box-shadow: -2px 0 12px rgba(0,0,0,0.1); z-index: 1000; overflow-y: auto;
  transform: translateX(100%); transition: transform 0.25s ease;
}
.detail-panel.open { transform: translateX(0); }

.detail-header {
  padding: 16px 20px; background: var(--surface-2); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 1;
}
.detail-header .close-btn {
  position: absolute; top: 12px; right: 12px; width: 28px; height: 28px; border: none;
  background: none; cursor: pointer; font-size: 18px; color: var(--text-muted); border-radius: 4px;
}
.detail-header .close-btn:hover { background: var(--track); color: var(--text); }
.detail-header-inner { display: flex; align-items: center; gap: 14px; }
.detail-header-inner .big-score {
  width: 56px; height: 56px; border-radius: 12px; display: flex; align-items: center;
  justify-content: center; font-size: 22px; font-weight: 800; color: #fff; flex-shrink: 0;
}
.detail-header-info h2 { font-size: 16px; font-weight: 700; margin-bottom: 2px; }
.detail-header-info .detail-meta { font-size: 12px; color: var(--text-2); }
.listing-links { display: flex; gap: 6px; margin-top: 6px; }
.listing-links a {
  padding: 3px 8px; font-size: 11px; border: 1px solid var(--border); border-radius: 4px;
  background: var(--surface); color: var(--text-2); text-decoration: none; transition: all 0.15s;
}
.listing-links a:hover, .listing-links a:focus-visible { border-color: #1a73e8; color: #1a73e8; }
.listing-links .shortlist-pin {
  padding: 3px 8px; font-size: 11px; border: 1px solid var(--border); border-radius: 4px;
  background: var(--surface); color: var(--text-2); cursor: pointer; transition: all 0.15s;
}
.listing-links .shortlist-pin:hover, .listing-links .shortlist-pin:focus-visible { border-color: #f9a825; color: #b8860b; }
.listing-links .shortlist-pin.active { background: #fff8e1; border-color: #f9a825; color: #b8860b; }

.area-item .pin-btn {
  padding: 4px 7px; font-size: 12px; border: 1px solid var(--border); border-radius: 4px;
  background: var(--surface); cursor: pointer; color: var(--text-faint); flex-shrink: 0; transition: all 0.15s;
}
.area-item .pin-btn:hover { border-color: #f9a825; color: #f9a825; }
.area-item .pin-btn.active { color: #f9a825; border-color: #f9a825; background: #fff8e1; }

.sidebar-footer .shortlist-count {
  display: inline-block; font-size: 10px; font-weight: 700; color: #fff;
  background: #1a73e8; padding: 0 5px; border-radius: 8px; margin-left: 2px;
}

.shortlist-modal {
  background: var(--surface); border-radius: 10px; max-width: calc(100vw - 32px); max-height: 85vh;
  overflow: auto; box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}
.shortlist-body { padding: 0 16px 16px; overflow-x: auto; }
.shortlist-table { border-collapse: collapse; font-size: 12px; width: 100%; }
.shortlist-table th, .shortlist-table td {
  padding: 6px 10px; border-bottom: 1px solid var(--border-2); text-align: left;
  white-space: nowrap; vertical-align: top;
}
.shortlist-table td:first-child { color: var(--text-muted); font-weight: 600; font-size: 11px; }
.shortlist-table td.sl-best { background: var(--accent-bg); }
.sl-action {
  padding: 3px 8px; font-size: 11px; border: 1px solid var(--border); border-radius: 4px;
  background: var(--surface); cursor: pointer; color: var(--text-2); transition: all 0.15s;
}
.sl-action:hover, .sl-action:focus-visible { border-color: #1a73e8; color: #1a73e8; }
.sl-action.sl-remove:hover, .sl-action.sl-remove:focus-visible { border-color: #c62828; color: #c62828; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #333; color: #fff; padding: 8px 14px; border-radius: 6px;
  font-size: 12px; z-index: 10002; opacity: 0; transition: opacity 0.2s; pointer-events: none;
}
.toast.show { opacity: 1; }

.detail-tabs {
  display: flex; gap: 6px; padding: 8px 16px; border-bottom: 1px solid var(--border);
  background: var(--surface-2); flex-wrap: wrap;
}
.detail-tab-btn {
  padding: 5px 10px; font-size: 12px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-2); cursor: pointer; transition: all 0.15s;
}
.detail-tab-btn:hover { border-color: #1a73e8; color: #1a73e8; }
.detail-tab-btn.active { background: #1a73e8; color: #fff; border-color: #1a73e8; }
.detail-tab-content { display: none; }
.detail-tab-content.active { display: block; }

.detail-overall {
  padding: 16px 20px; display: flex; align-items: center; gap: 16px;
  border-bottom: 1px solid var(--border-2);
}
.detail-overall .big-score {
  width: 64px; height: 64px; border-radius: 12px; display: flex; align-items: center;
  justify-content: center; font-size: 24px; font-weight: 800; color: #fff;
}
.detail-overall .score-label { font-size: 12px; color: var(--text-muted); }
.detail-overall .classification-label { font-size: 14px; font-weight: 600; margin-top: 2px; }

.detail-section { padding: 14px 20px; border-bottom: 1px solid var(--border-2); }
.detail-section h3 { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); margin-bottom: 10px; }

.score-bar-row { display: flex; align-items: center; margin-bottom: 8px; }
.score-bar-label { width: 130px; font-size: 12px; color: var(--text-2); flex-shrink: 0; }
.score-bar-track { flex: 1; height: 8px; background: var(--track); border-radius: 4px; overflow: hidden; }
.score-bar-fill { height: 100%; border-radius: 4px; transition: width 0.4s ease; }
.score-bar-value { width: 36px; text-align: right; font-size: 12px; font-weight: 600; color: var(--text); margin-left: 8px; }

.score-explain-overall { padding: 12px 20px; border-bottom: 1px solid var(--border-2); }
.score-explain-overall h4 { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); margin-bottom: 6px; }
.score-explain-overall .score-formula { font-size: 12px; color: var(--text-2); margin-bottom: 8px; }
.score-chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.score-chip { font-size: 11px; padding: 4px 8px; border-radius: 12px; background: var(--accent-bg); color: #1a73e8; font-weight: 600; }

.score-breakdown details { border-bottom: 1px solid var(--border-2); padding: 8px 20px; }
.score-breakdown summary { cursor: pointer; font-size: 12px; font-weight: 600; color: var(--text); list-style: none; }
.score-breakdown summary::-webkit-details-marker { display: none; }
.score-breakdown .score-summary { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.score-breakdown .score-summary span { font-size: 11px; color: var(--text-2); }
.score-breakdown table { width: 100%; font-size: 11px; margin-top: 8px; }
.score-breakdown th { text-align: left; font-size: 10px; color: var(--text-muted); font-weight: 600; padding-bottom: 6px; }
.score-breakdown td { padding: 4px 0; vertical-align: top; }
.score-breakdown .ind-weight { text-align: right; font-variant-numeric: tabular-nums; }
.score-breakdown .ind-value { text-align: right; font-variant-numeric: tabular-nums; }
.score-breakdown .ind-tag { font-size: 9px; padding: 2px 5px; border-radius: 8px; background: #fff3e0; color: #e65100; margin-left: 6px; }
.score-breakdown .ind-dir { font-size: 10px; color: var(--text-2); margin-left: 6px; }

.custom-weights-banner {
  padding: 8px 16px; background: #fff8e1; color: #7a5a00; font-size: 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  border-bottom: 1px solid #f1e3b0;
}
.custom-weights-banner button {
  background: none; border: none; color: #1a73e8; font-size: 12px; cursor: pointer;
  padding: 0; text-decoration: underline;
}

.weights-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 10001;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.weights-modal {
  background: var(--surface); border-radius: 10px; width: 100%; max-width: 520px; max-height: 80vh;
  overflow-y: auto; box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}
.weights-header {
  display: flex; align-items: center; justify-content: space-between; padding: 14px 16px;
  border-bottom: 1px solid var(--border-2); position: sticky; top: 0; background: var(--surface); z-index: 1;
}
.weights-header h3 { font-size: 14px; font-weight: 700; }
.weights-close { border: none; background: none; font-size: 18px; cursor: pointer; color: var(--text-muted); }
.weights-section { padding: 12px 16px; border-bottom: 1px solid var(--border-2); }
.weights-section h4 { font-size: 12px; font-weight: 700; color: var(--text-2); margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.5px; }
.weights-row { display: grid; grid-template-columns: 1fr 1fr 52px; gap: 8px; align-items: center; margin-bottom: 8px; }
.weights-row label { font-size: 12px; color: var(--text-2); }
.weights-row input[type="range"] { width: 100%; }
.weights-row .weights-value { font-size: 11px; text-align: right; color: var(--text-2); font-variant-numeric: tabular-nums; }
.weights-footer { padding: 12px 16px; display: flex; justify-content: space-between; gap: 8px; }
.weights-footer button { padding: 7px 10px; border-radius: 6px; font-size: 12px; cursor: pointer; }
.weights-reset { background: none; border: 1px solid var(--border); color: var(--text-2); }
.weights-cancel { background: var(--surface); border: 1px solid var(--border); color: var(--text-2); }
.weights-apply { background: #1a73e8; color: #fff; border: none; font-weight: 600; }
.preset-active-label { font-size: 11px; font-weight: 400; color: #1a73e8; text-transform: none; letter-spacing: 0; margin-left: 6px; }
.preset-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.preset-chip {
  padding: 4px 10px; font-size: 12px; border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); color: var(--text-2); cursor: pointer; transition: all 0.15s;
}
.preset-chip:hover, .preset-chip:focus-visible { border-color: #1a73e8; color: #1a73e8; }
.preset-chip.active { background: #1a73e8; color: #fff; border-color: #1a73e8; }
.user-preset-item { display: inline-flex; align-items: center; gap: 1px; }
.preset-del { border: none; background: none; color: var(--text-muted); cursor: pointer; font-size: 14px; padding: 0 3px; line-height: 1; }
.preset-del:hover, .preset-del:focus-visible { color: #c62828; }
.preset-save-row { display: flex; gap: 6px; margin-top: 10px; }
.preset-save-row input { flex: 1; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; font-size: 12px; outline: none; }
.preset-save-row input:focus { border-color: #1a73e8; }
.preset-save-row button {
  padding: 6px 10px; border: 1px solid #1a73e8; background: var(--surface); color: #1a73e8;
  border-radius: 6px; font-size: 12px; font-weight: 600; cursor: pointer;
}
.preset-save-row button:hover { background: #1a73e8; color: #fff; }

.indicator-table { width: 100%; font-size: 12px; }
.indicator-table td { padding: 6px 0; vertical-align: top; }
.indicator-table .ind-label { color: var(--text-2); white-space: nowrap; }
.indicator-table .ind-value { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.indicator-table .ind-unit { color: var(--text-muted); font-weight: 400; margin-left: 2px; }
.indicator-table .ind-proxy { color: #e65100; }
.indicator-table .ind-year { color: var(--text-faint); font-weight: 400; font-size: 10px; margin-left: 2px; }
.indicator-table .ind-trend { display: inline-flex; align-items: center; gap: 3px; }
.indicator-table .ind-arrow { font-size: 10px; font-weight: 700; }
.indicator-table .ind-arrow.up { color: #2E7D32; }
.indicator-table .ind-arrow.down { color: #C62828; }
.indicator-table .ind-arrow.flat { color: var(--text-muted); }
.ind-viz-row { display: flex; align-items: center; gap: 6px; justify-content: flex-end; margin-top: 6px; }
.ind-sparkline { display: inline-block; vertical-align: middle; cursor: pointer; border-radius: 3px; padding: 1px 2px; transition: background 0.15s; }
.ind-sparkline:hover { background: var(--accent-bg); }
.ind-sparkline svg { display: block; }

.ind-group-header { padding: 8px 0 4px; border-bottom: 1px solid var(--border-2); margin-top: 6px; }
.ind-group-header:first-child { margin-top: 0; }
.ind-group-label { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: #1a73e8; }

/* Land use & workplace sector charts */
.land-use-bar { display: flex; height: 28px; border-radius: 4px; overflow: hidden; width: 100%; }
.land-use-bar .lu-seg { min-width: 2px; transition: width 0.3s; }
.land-use-legend { display: flex; flex-wrap: wrap; gap: 8px 14px; margin-top: 8px; }
.land-use-legend .lu-item { display: flex; align-items: center; gap: 4px; font-size: 11px; color: var(--text-2); }
.land-use-legend .lu-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.wp-sector-row { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.wp-sector-label { width: 140px; font-size: 12px; color: var(--text-2); flex-shrink: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wp-sector-track { flex: 1; height: 16px; background: var(--track); border-radius: 3px; overflow: hidden; }
.wp-sector-fill { height: 100%; border-radius: 3px; transition: width 0.3s; }
.wp-sector-val { width: 44px; text-align: right; font-size: 11px; font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; flex-shrink: 0; }

/* Schools tab */
.edu-type-section { padding: 10px 20px; border-bottom: 1px solid var(--border-2); }
.edu-type-header { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.edu-type-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.edu-type-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-2); }
.edu-type-count { font-size: 11px; color: var(--text-muted); font-weight: 400; }
.edu-type-pctl { margin-bottom: 10px; }
.edu-pctl-track { height: 6px; background: var(--track); border-radius: 3px; position: relative; overflow: visible; }
.edu-pctl-fill { height: 100%; border-radius: 3px; }
.edu-pctl-label { font-size: 10px; color: var(--text-muted); margin-top: 2px; }
.edu-school-item { padding: 6px 0; border-bottom: 1px solid var(--border-2); }
.edu-school-item:last-child { border-bottom: none; }
.edu-school-name { font-size: 12px; font-weight: 600; color: var(--text); }
.edu-school-addr { font-size: 11px; color: var(--text-muted); }
.edu-school-gpa { display: inline-flex; align-items: center; gap: 6px; margin-top: 3px; }
.edu-gpa-badge { font-size: 12px; font-weight: 700; color: #fff; padding: 2px 8px; border-radius: 10px; }
.edu-gpa-chart { background: var(--surface-2); border-radius: 4px; padding: 4px; margin-top: 4px; }
.edu-no-schools { padding: 20px; text-align: center; color: var(--text-faint); font-size: 13px; }

.trend-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 10001;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.trend-modal {
  background: var(--surface); border-radius: 10px; width: 100%; max-width: 560px; max-height: 85vh;
  overflow-y: auto; box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}
.trend-modal-header {
  display: flex; align-items: center; justify-content: space-between; padding: 14px 16px;
  border-bottom: 1px solid var(--border-2); position: sticky; top: 0; background: var(--surface); z-index: 1;
}
.trend-modal-header h3 { font-size: 14px; font-weight: 700; }
.trend-modal-header .trend-close { border: none; background: none; font-size: 18px; cursor: pointer; color: var(--text-muted); }
.trend-modal-body { padding: 16px; }
.trend-chart-container { position: relative; width: 100%; height: 220px; margin-bottom: 16px; }
.trend-chart-container svg { width: 100%; height: 100%; }
.trend-summary { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.trend-stat { text-align: center; padding: 10px; background: var(--surface-2); border-radius: 8px; }
.trend-stat-value { font-size: 18px; font-weight: 700; color: var(--text); }
.trend-stat-label { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.3px; margin-top: 2px; }
.trend-table { width: 100%; font-size: 12px; border-collapse: collapse; }
.trend-table th { text-align: left; font-size: 10px; color: var(--text-muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--border-2); }
.trend-table td { padding: 5px 8px; border-bottom: 1px solid var(--border-2); font-variant-numeric: tabular-nums; }
.trend-table tr:hover { background: var(--surface-2); }
.trend-table .change-up { color: #2E7D32; font-weight: 600; }
.trend-table .change-down { color: #C62828; font-weight: 600; }
.trend-table .change-flat { color: var(--text-muted); }

.ind-dist { display: inline-flex; align-items: center; gap: 3px; cursor: pointer; vertical-align: middle; }
.ind-dist:hover .ind-dist-track { background: #d2e3fc; }
.ind-dist-track { width: 48px; height: 8px; background: var(--track); border-radius: 4px; position: relative; overflow: hidden; transition: background 0.15s; }
.ind-dist-fill { height: 100%; border-radius: 4px; position: absolute; left: 0; top: 0; opacity: 0.3; }
.ind-dist-marker { position: absolute; top: -1px; width: 3px; height: 10px; border-radius: 1px; }
.ind-dist-pct { font-size: 9px; color: var(--text-muted); font-weight: 600; min-width: 22px; text-align: right; font-variant-numeric: tabular-nums; }

.dist-modal { background: var(--surface); border-radius: 10px; width: 100%; max-width: 580px; max-height: 85vh; overflow-y: auto; box-shadow: 0 8px 24px rgba(0,0,0,0.2); }
.dist-modal-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border-2); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.dist-modal-header h3 { font-size: 14px; font-weight: 700; }
.dist-modal-body { padding: 16px; }
.dist-histogram { position: relative; width: 100%; height: 180px; margin-bottom: 12px; }
.dist-histogram svg { width: 100%; height: 100%; }
.dist-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 16px; }
.dist-stat { text-align: center; padding: 8px 6px; background: var(--surface-2); border-radius: 8px; }
.dist-stat-value { font-size: 16px; font-weight: 700; color: var(--text); }
.dist-stat-label { font-size: 9px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.3px; margin-top: 2px; }
.dist-area-list { max-height: 240px; overflow-y: auto; }
.dist-area-row { display: grid; grid-template-columns: 36px 1fr 80px 48px; gap: 6px; align-items: center; padding: 4px 6px; font-size: 11px; border-bottom: 1px solid var(--border-2); }
.dist-area-row:hover { background: var(--surface-2); }
.dist-area-row.highlight { background: var(--accent-bg); font-weight: 600; }
.dist-area-rank { color: var(--text-muted); text-align: right; font-variant-numeric: tabular-nums; }
.dist-area-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dist-area-val { text-align: right; font-variant-numeric: tabular-nums; }
.dist-area-bar { display: block; height: 6px; background: var(--track); border-radius: 3px; overflow: hidden; }
.dist-area-bar-fill { display: block; height: 100%; border-radius: 3px; }

.info-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 14px; height: 14px; border-radius: 50%; background: #e8e8e8;
  color: var(--text-muted); font-size: 9px; font-weight: 700; font-style: normal;
  cursor: help; margin-left: 4px; vertical-align: middle;
  position: relative; flex-shrink: 0;
}
.info-icon:hover { background: #1a73e8; color: #fff; }
.info-tip { display: none; }
.info-tip-global {
  display: none; position: fixed; width: 220px; padding: 8px 10px;
  background: #333; color: #fff; font-size: 11px; font-weight: 400;
  line-height: 1.4; border-radius: 6px; z-index: 10000;
  pointer-events: none; text-align: left; white-space: normal;
}
.info-tip-global::after {
  content: ''; position: absolute; left: 50%;
  transform: translateX(-50%); border: 5px solid transparent;
}
.info-tip-global.above::after { top: 100%; border-top-color: var(--text); }
.info-tip-global.below::after { bottom: 100%; border-bottom-color: var(--text); }

.sidebar-controls select optgroup { font-weight: 700; color: var(--text-2); font-size: 12px; }
.sidebar-controls select option { font-weight: 400; color: var(--text); padding-left: 8px; }

.risk-flag {
  display: inline-block; padding: 3px 8px; border-radius: 4px; font-size: 11px;
  font-weight: 600; margin: 2px 4px 2px 0;
}
.risk-flag.warning { background: #fff3e0; color: #e65100; }
.risk-flag.info { background: #e3f2fd; color: #1565c0; }

.notes-section { padding: 14px 20px; }
.notes-section h3 { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); margin-bottom: 10px; }
.note-item { margin-bottom: 12px; }
.note-item label { font-size: 12px; color: var(--text-2); display: block; margin-bottom: 4px; }
.star-rating { display: inline-flex; gap: 2px; cursor: pointer; }
.star-rating .star { font-size: 16px; color: #ddd; transition: color 0.1s; }
.star-rating .star.filled { color: #f9a825; }
.star-rating .star:hover { color: #f9a825; }
.star-rating .star:focus-visible, .info-icon:focus-visible { outline: 2px solid #1a73e8; outline-offset: 1px; border-radius: 3px; }
/* Leaflet's focusable SVG polygons otherwise receive a rectangular browser
   focus box that does not follow the area geometry. Selection is represented
   by the dedicated polygon-shaped selection outline instead. */
.leaflet-container path.leaflet-interactive:focus { outline: none; }
.note-text {
  width: 100%; margin-top: 4px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 4px;
  font-size: 12px; font-family: inherit; resize: vertical; min-height: 36px;
}
.note-text:focus { border-color: #1a73e8; outline: none; }
.save-notes-btn {
  width: 100%; padding: 8px; background: #1a73e8; color: #fff; border: none;
  border-radius: 6px; font-size: 13px; font-weight: 600; cursor: pointer;
  margin-top: 8px; transition: background 0.15s;
}
.save-notes-btn:hover { background: #1557b0; }

.compare-panel .compare-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0; }
.compare-panel .compare-col { padding: 12px 16px; }
.compare-panel .compare-col:first-child { border-right: 1px solid var(--border-2); }
.compare-panel .compare-col h4 { font-size: 13px; font-weight: 700; margin-bottom: 8px; }
.compare-bar-row { display: flex; align-items: center; margin-bottom: 6px; gap: 6px; }
.compare-bar-label { font-size: 11px; width: 100%; text-align: center; color: var(--text-2); padding: 0 0 4px; }
.compare-bars { display: flex; gap: 4px; align-items: center; }
.compare-bar { height: 6px; border-radius: 3px; }
.compare-val { font-size: 11px; font-weight: 600; width: 30px; font-variant-numeric: tabular-nums; }
.compare-val.left { text-align: right; }
.compare-val.right { text-align: left; }
.compare-better { font-weight: 700; }

.clear-compare-btn {
  padding: 6px 14px; background: none; border: 1px solid var(--border); border-radius: 4px;
  font-size: 12px; cursor: pointer; color: var(--text-2); margin: 8px 20px;
}
.clear-compare-btn:hover { border-color: #c62828; color: #c62828; }

.map-toggles {
  position: absolute; bottom: 20px; left: 12px; z-index: 999; background: var(--surface);
  padding: 10px 14px; border-radius: 6px; box-shadow: 0 1px 4px rgba(0,0,0,0.2);
  font-size: 12px; display: flex; flex-direction: column; gap: 6px;
}
.map-toggles .toggle-row { display: flex; align-items: center; gap: 6px; }
.map-toggles input { cursor: pointer; }
.map-toggles label { cursor: pointer; user-select: none; }
.map-toggles .opacity-row { display: flex; align-items: center; gap: 6px; }
.map-toggles .opacity-row input[type="range"] { width: 96px; }
.map-toggles .opacity-row span { font-size: 10px; color: var(--text-2); min-width: 28px; }
.map-toggles .toggle-swatch {
  width: 14px; height: 3px; border-radius: 2px; flex-shrink: 0;
}
.map-toggles .toggle-group-label {
  font-size: 10px; font-weight: 700; color: var(--text-muted); text-transform: uppercase;
  letter-spacing: 0.5px; margin-top: 4px;
}
.map-toggles .toggle-group-label:first-child { margin-top: 0; }

.legend {
  position: absolute; bottom: 20px; right: 12px; z-index: 999; background: var(--surface);
  padding: 10px 14px; border-radius: 6px; box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}
.legend-title { font-size: 11px; font-weight: 700; margin-bottom: 6px; color: var(--text-2); }
.legend-row { display: flex; align-items: center; gap: 6px; margin-bottom: 3px; }
.legend-color { width: 20px; height: 10px; border-radius: 2px; }
.legend-label { font-size: 10px; color: var(--text-2); }

.compare-ind-row:hover { background: var(--hover); }

/* Age Pyramid */
.pyramid-header { display: flex; justify-content: space-between; align-items: baseline; }
.pyramid-subtitle { font-size: 11px; color: var(--text-muted); font-weight: 400; text-transform: none; letter-spacing: 0; }
.pyramid-subtitle .male-label { color: #4285f4; }
.pyramid-subtitle .female-label { color: #ea4335; }
.pyramid { display: flex; flex-direction: column; gap: 1px; }
.pyramid-row {
  display: grid; grid-template-columns: 1fr 42px 1fr; align-items: center; height: 16px;
}
.pyramid-bar-left { display: flex; justify-content: flex-end; }
.pyramid-bar-right { display: flex; justify-content: flex-start; }
.pyramid-bar {
  height: 12px; border-radius: 2px; min-width: 1px;
  transition: width 0.3s ease;
}
.pyramid-bar.male { background: #4285f4; }
.pyramid-bar.female { background: #ea4335; }
.pyramid-bar[data-pct] { position: relative; }
.pyramid-bar[data-pct]:hover::after {
  content: attr(data-pct);
  position: absolute; top: -20px; white-space: nowrap;
  font-size: 10px; font-weight: 600; color: var(--text); background: var(--surface);
  padding: 1px 5px; border-radius: 4px; box-shadow: 0 1px 4px rgba(0,0,0,0.15);
  pointer-events: none; z-index: 2;
}
.pyramid-bar-left .pyramid-bar[data-pct]:hover::after { right: 0; }
.pyramid-bar-right .pyramid-bar[data-pct]:hover::after { left: 0; }
.pyramid-label {
  text-align: center; font-size: 9px; color: var(--text-muted); font-variant-numeric: tabular-nums;
  line-height: 16px; white-space: nowrap;
}
.pyramid-axis {
  display: grid; grid-template-columns: 1fr 42px 1fr;
  font-size: 9px; color: var(--text-faint); margin-top: 2px;
}
.pyramid-axis span:first-child { text-align: right; padding-right: 4px; }
.pyramid-axis span:last-child { text-align: left; padding-left: 4px; }
.pyramid-axis span:nth-child(2) { text-align: center; }

.pyramid-compact .pyramid-row { height: 12px; }
.pyramid-compact .pyramid-bar { height: 9px; }
.pyramid-compact .pyramid-label { font-size: 8px; line-height: 12px; }
.pyramid-compact .pyramid-header { flex-direction: column; align-items: flex-start; gap: 2px; }
.pyramid-compact .pyramid-header h3 { font-size: 11px; margin-bottom: 0; }
.pyramid-compact .pyramid-subtitle { font-size: 10px; }
.lang-compact .score-bar-label { width: 100px; font-size: 11px; }
.lang-compact .score-bar-value { font-size: 11px; }
.lang-compact { margin-bottom: 5px; }

.addr-search { position: relative; }
.addr-suggestions {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 1200;
  background: var(--surface); border: 1px solid var(--border); border-radius: 0 0 6px 6px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.12); max-height: 220px; overflow-y: auto;
}
.addr-suggestion {
  display: block; width: 100%; text-align: left; padding: 7px 10px; font-size: 12px;
  color: var(--text); background: var(--surface); border: none; border-bottom: 1px solid var(--border-2);
  cursor: pointer;
}
.addr-suggestion:last-child { border-bottom: none; }
.addr-suggestion:hover, .addr-suggestion.active { background: var(--accent-bg); }

.pin-card {
  position: absolute; top: 12px; left: 12px; z-index: 1000; width: 260px;
  background: var(--surface); border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.2);
  font-size: 12px; overflow: hidden;
}
.pin-card-header {
  display: flex; align-items: flex-start; gap: 8px; padding: 10px 12px;
  background: #fce4ec; border-bottom: 1px solid #f3c9d6;
}
.pin-card-header .pin-card-addr { flex: 1; font-weight: 600; color: #880e4f; line-height: 1.3; }
.pin-card-close {
  border: none; background: none; font-size: 15px; color: var(--text-muted); cursor: pointer;
  padding: 0 2px; line-height: 1; flex-shrink: 0;
}
.pin-card-close:hover, .pin-card-close:focus-visible { color: #c62828; }
.pin-card-body { padding: 8px 12px 10px; }
.pin-card-row { display: flex; justify-content: space-between; gap: 8px; padding: 3px 0; }
.pin-card-row .pin-card-label { color: var(--text-muted); }
.pin-card-row .pin-card-value { font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.pin-card-note { font-size: 10px; color: var(--text-faint); margin-top: 4px; }
.pin-commute-src { font-size: 9px; color: #a34a6b; margin-left: 3px; }

/* On mobile the pin card docks to the bottom of the map (see the mobile block). */

.loading-overlay {
  position: fixed; inset: 0; background: var(--surface); display: flex; align-items: center;
  justify-content: center; z-index: 9999; flex-direction: column; gap: 12px;
}
.loading-overlay .spinner {
  width: 32px; height: 32px; border: 3px solid var(--border-2); border-top-color: #1a73e8;
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-overlay .loading-text { font-size: 14px; color: var(--text-muted); }

.mobile-toggle {
  display: none; position: fixed; top: 10px; left: 10px; z-index: 1200;
  width: 44px; height: 44px; background: #1a73e8; color: #fff; border: none;
  border-radius: 8px; font-size: 18px; cursor: pointer; box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

/* Mobile-only elements: hidden on desktop */
.drawer-backdrop { display: none; }
.map-toggles-fab { display: none; }

/* ---- Mobile layout (one-handed use) ---- */
@media (max-width: 768px) {
  /* Sidebar becomes an off-canvas drawer over the map */
  .sidebar {
    position: fixed; left: -100%; z-index: 1100; height: 100dvh;
    width: min(380px, 88vw); min-width: 0; transition: left 0.3s;
  }
  .sidebar.open { left: 0; }
  .drawer-backdrop.visible {
    display: block; position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.35); z-index: 1050;
  }
  .mobile-toggle { display: block; }

  /* Detail panel becomes a bottom sheet (~58% height, internally scrollable) */
  .detail-panel {
    top: auto; bottom: 0; left: 0; right: 0; width: 100%; height: 58dvh;
    transform: translateY(100%); border-radius: 14px 14px 0 0;
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.25);
  }
  .detail-panel.open { transform: translateY(0); }
  .detail-header { border-radius: 14px 14px 0 0; }
  .detail-header::before {
    content: ''; display: block; width: 36px; height: 4px; border-radius: 2px;
    background: #d0d0d0; margin: 0 auto 8px;
  }

  /* Map-toggles panel collapses behind a "Layers" FAB */
  .map-toggles { display: none; }
  .map-toggles.expanded {
    display: flex; bottom: 72px; max-height: 55dvh; overflow-y: auto; z-index: 1001;
  }
  .map-toggles-fab {
    display: flex; align-items: center; justify-content: center;
    position: absolute; bottom: 20px; left: 12px; z-index: 1002; /* above sheet + expanded panel */
    min-height: 44px; padding: 0 16px; border: none; border-radius: 22px;
    background: var(--surface); color: var(--text); font-size: 13px; font-weight: 600;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3); cursor: pointer;
  }
  .map-toggles-fab[aria-expanded="true"] { background: #1a73e8; color: #fff; }

  /* Compact legend so it fits next to the FAB */
  .legend { padding: 6px 8px; max-width: 132px; }
  .legend-title { font-size: 10px; margin-bottom: 4px; }
  .legend-label { font-size: 9px; }

  /* Pin card docks full-width at the bottom of the map, above the sheet */
  .pin-card { top: auto; bottom: 12px; left: 8px; right: 8px; width: auto; z-index: 1001; }
  .detail-panel.open ~ .pin-card { bottom: calc(58dvh + 10px); }

  /* The Layers FAB rides above the open bottom sheet too */
  .detail-panel.open ~ .map-toggles-fab { bottom: calc(58dvh + 10px); }

  /* Modals go full-screen-ish */
  .trend-overlay, .weights-overlay { padding: 0; align-items: stretch; }
  .trend-modal, .dist-modal, .weights-modal, .shortlist-modal {
    width: 100vw; max-width: 100vw; max-height: 100dvh; border-radius: 0;
  }

  /* Tap targets ≥ 40px for primary controls */
  .area-item { padding: 12px 16px; }
  .area-item .pin-btn, .area-item .compare-btn { min-width: 40px; min-height: 40px; }
  .sidebar-footer button { padding: 12px 4px; }
  .detail-tab-btn { padding: 10px 14px; }
  .detail-header .close-btn { width: 40px; height: 40px; font-size: 22px; }
  .pin-card-close { padding: 8px 10px; font-size: 18px; }
}

/* Very small screens: tighten further */
@media (max-width: 480px) {
  .sidebar { width: 88vw; }
  .detail-header-inner .big-score { width: 44px; height: 44px; font-size: 18px; }
  .score-bar-label { width: 104px; font-size: 11px; }
  .compare-panel .compare-col { padding: 10px 8px; }
}

input[type="file"] { display: none; }

/* Satellite basemap: white choropleth borders vanish over imagery — darken
   them (hover/selection strokes set other colors, so they are unaffected) */
body.satellite-basemap .leaflet-overlay-pane path[stroke="#fff"] { stroke: #333; }

/* Print: when the shortlist modal is open, print just its table cleanly
   (browser print-to-PDF is the export path) */
@media print {
  body:has(#shortlistOverlay) #app,
  body:has(#shortlistOverlay) .mobile-toggle,
  body:has(#shortlistOverlay) .pin-card,
  body:has(#shortlistOverlay) .toast,
  body:has(#shortlistOverlay) .info-tip-global { display: none !important; }
  #shortlistOverlay { position: static !important; inset: auto !important; padding: 0 !important; background: none !important; display: block !important; }
  #shortlistOverlay .shortlist-modal { box-shadow: none !important; border-radius: 0 !important; max-width: none !important; max-height: none !important; overflow: visible !important; }
  #shortlistOverlay .shortlist-body { overflow: visible !important; padding: 0 !important; }
  #shortlistOverlay .trend-modal-header { position: static !important; border-bottom: 1px solid #000; }
  #shortlistOverlay .trend-close, #shortlistOverlay .sl-action { display: none !important; }
  #shortlistOverlay .shortlist-table th, #shortlistOverlay .shortlist-table td { padding: 4px 8px; font-size: 10px; white-space: normal; }
}

.pin-card-actions { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 12px 10px; }
.pin-save-row { display: flex; gap: 6px; width: 100%; }
.pin-save-row input { flex: 1; padding: 5px 8px; border: 1px solid var(--border); border-radius: 4px; font-size: 12px; outline: none; }
.pin-save-row input:focus { border-color: #1a73e8; }
.lp-edit { width: 150px; padding: 4px 6px; border: 1px solid var(--border); border-radius: 4px; font-size: 11px; outline: none; }
.lp-edit:focus { border-color: #1a73e8; }

.similar-area-row {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 40px;
  padding: 6px; border: none; background: none; border-bottom: 1px solid var(--border-2);
  cursor: pointer; text-align: left; font-size: 12px; font-family: inherit;
}
.similar-area-row:last-of-type { border-bottom: none; }
.similar-area-row:hover, .similar-area-row:focus-visible { background: var(--hover); }
.similar-score {
  width: 34px; height: 28px; border-radius: 6px; color: #fff; font-weight: 700;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 12px;
}
.similar-name { flex: 1; color: var(--text); font-weight: 600; min-width: 0; }
.similar-name .similar-pc { color: var(--text-muted); font-weight: 400; font-size: 11px; }
.similar-hint { color: var(--text-muted); font-size: 10px; flex-shrink: 0; }

.pin-rings-toggle {
  display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--text-2);
  margin-top: 6px; cursor: pointer; user-select: none;
}
.pin-rings-toggle input { cursor: pointer; }

/* ---- Dark theme (data-theme on <html>; chrome only, data colors untouched) ---- */
[data-theme="dark"] {
  --surface: #202124;
  --surface-2: #17181a;
  --surface-3: #26272b;
  --hover: #2a2f3a;
  --accent-bg: #1e3a5f;
  --track: #3c4043;
  --border: #3c4043;
  --border-2: #2e2f33;
  --text: #e8eaed;
  --text-2: #bdc1c6;
  --text-muted: #9aa0a6;
  --text-faint: #6f7378;
}

/* Leaflet chrome */
[data-theme="dark"] .leaflet-container { background: #17181a; }
[data-theme="dark"] .leaflet-control-attribution { background: rgba(32, 33, 36, 0.8); color: var(--text-muted); }
[data-theme="dark"] .leaflet-control-attribution a { color: var(--text-2); }
[data-theme="dark"] .leaflet-bar a { background: var(--surface); color: var(--text); border-bottom-color: var(--border); }
[data-theme="dark"] .leaflet-bar a.leaflet-disabled { background: var(--surface-3); color: var(--text-faint); }
[data-theme="dark"] .leaflet-popup-content-wrapper,
[data-theme="dark"] .leaflet-popup-tip { background: var(--surface); color: var(--text); }
[data-theme="dark"] .leaflet-container a.leaflet-popup-close-button { color: var(--text-muted); }
[data-theme="dark"] .leaflet-tooltip { background: var(--surface); color: var(--text); border-color: var(--border); }
[data-theme="dark"] .leaflet-tooltip-top::before { border-top-color: var(--surface); }
[data-theme="dark"] .leaflet-tooltip-bottom::before { border-bottom-color: var(--surface); }
[data-theme="dark"] .leaflet-tooltip-left::before { border-left-color: var(--surface); }
[data-theme="dark"] .leaflet-tooltip-right::before { border-right-color: var(--surface); }

/* JS templates carry inline greys — centralized dark remap (semantic score
   colors use other hex values, so these substring matches never touch them) */
[data-theme="dark"] [style*="color:#333"], [data-theme="dark"] [style*="color: #333"] { color: var(--text) !important; }
[data-theme="dark"] [style*="color:#444"], [data-theme="dark"] [style*="color:#555"] { color: var(--text-2) !important; }
[data-theme="dark"] [style*="color:#666"], [data-theme="dark"] [style*="color:#777"] { color: var(--text-2) !important; }
[data-theme="dark"] [style*="color:#888"], [data-theme="dark"] [style*="color:#999"] { color: var(--text-muted) !important; }
[data-theme="dark"] [style*="color:#aaa"], [data-theme="dark"] [style*="color:#bbb"] { color: var(--text-faint) !important; }
[data-theme="dark"] [style*="background:#f5f5f5"],
[data-theme="dark"] [style*="background:#fafafa"],
[data-theme="dark"] [style*="background:#f8f9fa"],
[data-theme="dark"] [style*="background: #f8f9fa"] { background: var(--surface-3) !important; }

/* SVG chart axis/label fills are hardcoded in the builders — override the
   grey fills only; colored semantic labels keep their own fills */
[data-theme="dark"] svg text[fill="#999"],
[data-theme="dark"] svg text[fill="#888"],
[data-theme="dark"] svg text[fill="#666"] { fill: var(--text-muted); }

/* Selection outline: near-black would vanish on dark tiles → flip to light
   (attribute-scoped like the satellite border rule; hover/other strokes untouched) */
[data-theme="dark"] .leaflet-selection-pane path[stroke="#1a1a1a"] { stroke: #f1f3f4; }

/* Light-tinted specials that would glow on dark surfaces */
[data-theme="dark"] .custom-weights-banner { background: #3a331d; color: #e7ce8a; border-color: #4a4126; }
[data-theme="dark"] .pin-card-header { background: #3a2230; border-color: #4d2c3f; }
[data-theme="dark"] .pin-card-header .pin-card-addr { color: #f3a8c4; }
[data-theme="dark"] .addr-suggestion { background: var(--surface); color: var(--text); border-color: var(--border-2); }
[data-theme="dark"] .addr-suggestion:hover, [data-theme="dark"] .addr-suggestion.active { background: var(--hover); }

/* Theme toggle (sits on the always-blue header brand bar) */
.theme-toggle {
  position: absolute; top: 14px; right: 14px; width: 32px; height: 32px;
  border: 1px solid rgba(255, 255, 255, 0.5); border-radius: 50%; background: none;
  color: #fff; font-size: 15px; cursor: pointer; line-height: 1;
}
.theme-toggle:hover, .theme-toggle:focus-visible { background: rgba(255, 255, 255, 0.15); }

/* Print always uses the light palette regardless of the active theme */
@media print {
  :root, [data-theme="dark"] {
    --surface: #fff; --surface-2: #f8f9fa; --surface-3: #f5f5f5; --hover: #f5f7ff;
    --accent-bg: #e8f0fe; --track: #eee; --border: #ddd; --border-2: #f0f0f0;
    --text: #1a1a1a; --text-2: #555; --text-muted: #888; --text-faint: #bbb;
    --accent: #1a73e8;
  }
}
