:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --series-1: #2a78d6;
  --series-1-wash: rgba(42, 120, 214, 0.1);
  --series-2: #b3752d;
  --delta-neg: #e34948;
  --border: rgba(11, 11, 11, 0.1);
  --scroll-shadow: rgba(11, 11, 11, 0.25);
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --series-1: #3987e5;
    --series-1-wash: rgba(57, 135, 229, 0.1);
    --series-2: #d4922f;
    --delta-neg: #e66767;
    --border: rgba(255, 255, 255, 0.1);
    --scroll-shadow: rgba(255, 255, 255, 0.25);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --page: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --baseline: #383835;
  --series-1: #3987e5;
  --series-1-wash: rgba(57, 135, 229, 0.1);
  --series-2: #d4922f;
  --delta-neg: #e66767;
  --border: rgba(255, 255, 255, 0.1);
  --scroll-shadow: rgba(255, 255, 255, 0.25);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.4;
}
.wrap { max-width: 780px; margin: 0 auto; padding: 24px 20px 64px; }

.topnav {
  position: sticky; top: 0; z-index: 10;
  background: var(--surface-1); border-bottom: 1px solid var(--border);
}
.topnav-inner {
  position: relative;
  max-width: 780px; margin: 0 auto; padding: 8px 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.topnav-toggle {
  display: none; flex-direction: column; justify-content: center; gap: 5px;
  width: 36px; height: 36px; padding: 0; border: none; background: none; cursor: pointer; flex: none;
}
.topnav-toggle-bar { display: block; width: 100%; height: 2px; background: var(--text-primary); border-radius: 1px; }
.topnav-tagline { background: var(--page); border-top: 1px solid var(--border); }
.topnav-tagline-inner {
  max-width: 780px; margin: 0 auto; padding: 6px 20px;
  font-size: 0.78rem; color: var(--text-muted); text-align: center;
}
.topnav-logo {
  font-weight: 700; font-size: 1.05rem; color: var(--text-primary); text-decoration: none;
  flex: none; line-height: 0;
}
/* The wordmark inside the PNG sits in the upper ~40% of the file (the
   house icon extends further below the text than above it), so centering
   the image's own box still leaves the visible text ~5px above the nav
   links' baseline - nudge down to compensate. */
.topnav-logo-img { display: block; height: 50px; width: auto; margin-top: 5px; }
/* The logo PNG has dark text + a blue icon on a transparent background -
   inverting it in dark mode flips the text to white (readable again) and,
   as a side effect, turns the blue icon a warm orange that lands almost
   exactly on --series-2's dark-mode value (#d4922f) - a happy coincidence
   that keeps it on-brand without needing a second generated asset. */
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .topnav-logo-img { filter: invert(1); }
}
:root[data-theme="dark"] .topnav-logo-img { filter: invert(1); }
.topnav-links { display: flex; align-items: center; gap: 18px; }
.topnav-links a {
  color: var(--text-secondary); text-decoration: none; font-size: 0.92rem; font-weight: 500;
}
.topnav-links a:hover { color: var(--text-primary); }
.topnav-links a.active { color: var(--series-1); }

header h1 { font-size: 1.4rem; margin: 0 0 4px; }
.subtitle { color: var(--text-secondary); margin: 0 0 20px; }
.subtitle strong { color: var(--text-primary); font-weight: 600; }

.area-picker { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 6px; margin-bottom: 16px; }
.area-picker label { color: var(--text-secondary); font-size: 0.85rem; }
.area-picker select {
  font: inherit; color: var(--text-primary); background: var(--surface-1);
  border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px; max-width: 220px;
}
.nav-go {
  font: inherit; font-weight: 600; color: #fff; background: var(--series-1);
  border: none; border-radius: 6px; padding: 7px 16px; cursor: pointer;
}
.nav-go:hover { opacity: 0.9; }

.breadcrumbs { font-size: 0.85rem; margin-bottom: 12px; }
.breadcrumbs a { color: var(--series-1); text-decoration: none; }
.breadcrumbs a:hover { text-decoration: underline; }
.crumb-current { color: var(--text-secondary); }
.crumb-sep { color: var(--text-muted); margin: 0 6px; }

.viz-root {
  position: relative;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  margin-bottom: 24px;
}
.chart { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; }
.chart .axis-label { fill: var(--text-muted); font-size: 11px; }
.chart .series-line {
  fill: none; stroke: var(--series-1); stroke-width: 2;
  stroke-linejoin: round; stroke-linecap: round;
}
.chart .series-area { fill: var(--series-1-wash); stroke: none; }
.chart .end-dot { fill: var(--series-1); stroke: var(--surface-1); stroke-width: 2; }
.chart .crosshair { stroke: var(--text-muted); stroke-width: 1; }
.chart .hover-dot { fill: var(--series-1); stroke: var(--surface-1); stroke-width: 2; }
.chart .compare-line { fill: none; stroke-linejoin: round; stroke-linecap: round; }
.chart .compare-line-muted { stroke: var(--text-muted); stroke-width: 1.5; stroke-dasharray: 5 4; }
.chart .compare-line-accent-a { stroke: var(--series-2); stroke-width: 2; }
.chart .compare-line-accent-b { stroke: var(--text-muted); stroke-width: 1.5; stroke-dasharray: 1.5 3; }
.chart .hover-dot-compare-muted { fill: var(--text-muted); }
.chart .hover-dot-compare-accent-a { fill: var(--series-2); }
.chart .hover-dot-compare-accent-b { fill: var(--text-muted); }

.chart-legend { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 6px 0 0; font-size: 0.8rem; color: var(--text-secondary); }
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-swatch { display: inline-block; width: 16px; height: 0; border-top: 2px solid var(--series-1); }
.legend-compare-muted .legend-swatch { border-top: 2px dashed var(--text-muted); }
.legend-compare-accent-a .legend-swatch { border-top: 2px solid var(--series-2); }
.legend-compare-accent-b .legend-swatch { border-top: 2px dotted var(--text-muted); }

.tooltip {
  position: absolute; pointer-events: none;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 6px;
  padding: 6px 10px; font-size: 0.85rem; white-space: nowrap;
  box-shadow: 0 2px 8px var(--border);
}
.tooltip .tip-period { color: var(--text-secondary); margin-bottom: 2px; }
.tooltip .tip-row { display: flex; align-items: center; gap: 6px; }
.tooltip .tip-name { color: var(--text-secondary); margin-right: auto; }
.tooltip .tip-value { color: var(--text-primary); font-weight: 600; }
.tooltip .tip-swatch {
  display: inline-block; width: 10px; height: 2px; background: var(--series-1); flex: none;
}
.tooltip .tip-swatch-compare { background: none; height: 0; }
.tooltip .tip-swatch-compare-muted { border-top: 2px dashed var(--text-muted); }
.tooltip .tip-swatch-compare-accent-a { background: var(--series-2); border-top: none; height: 2px; }
.tooltip .tip-swatch-compare-accent-b { border-top: 2px dotted var(--text-muted); }

.data-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.data-table caption { text-align: left; color: var(--text-secondary); margin-bottom: 6px; }
.data-table th, .data-table td { text-align: left; padding: 4px 8px; border-bottom: 1px solid var(--grid); }
.data-table td:nth-child(n+2), .data-table th:nth-child(n+2) { text-align: right; font-variant-numeric: tabular-nums; }

footer { color: var(--text-muted); font-size: 0.8rem; }
footer a { color: inherit; }

.note {
  background: var(--surface-1); border: 1px solid var(--border); border-left: 3px solid var(--series-1);
  border-radius: 4px; padding: 10px 14px; color: var(--text-secondary); font-size: 0.85rem;
  margin: 0 0 20px;
}
.note strong { color: var(--text-primary); }

.callout {
  background: var(--series-1-wash); border: 1px solid var(--series-1); border-radius: 8px;
  padding: 14px 18px; color: var(--text-primary); font-size: 0.92rem; line-height: 1.5;
  margin: 0 0 20px; display: flex; flex-direction: column; gap: 8px;
}
.callout p { margin: 0; }
.callout strong { color: var(--text-primary); }
.callout-source { font-size: 0.78rem; color: var(--text-muted); }
.callout-source a { color: var(--text-muted); text-decoration: underline; }
.callout-source a:hover { color: var(--text-secondary); }

.glossary {
  display: grid; grid-template-columns: auto 1fr; gap: 4px 12px;
  font-size: 0.82rem; color: var(--text-secondary); margin: -8px 0 24px;
}
.glossary dt { color: var(--text-primary); font-weight: 600; white-space: nowrap; }
.glossary dd { margin: 0; }

th[title], .stat-label[title] { cursor: help; text-decoration: underline dotted var(--text-muted); text-underline-offset: 3px; }

.stat-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat-tile {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px;
  display: flex; flex-direction: column; gap: 4px;
}
.stat-label { color: var(--text-secondary); font-size: 0.78rem; }
.stat-value { color: var(--text-primary); font-size: 1.1rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat-sub { color: var(--text-muted); font-size: 0.75rem; font-variant-numeric: tabular-nums; }

.delta-pos { color: var(--series-1); font-weight: 600; font-variant-numeric: tabular-nums; }
.delta-neg { color: var(--delta-neg); font-weight: 600; font-variant-numeric: tabular-nums; }
.delta { color: var(--text-muted); }

.table-scroll {
  overflow-x: auto; margin-bottom: 24px;
  /* Fades the edge toward any hidden content, and the fade disappears once
     scrolled all the way in that direction - signals "more data this way"
     without JS. Classic "local + scroll" background-attachment trick. */
  background:
    linear-gradient(to right, var(--page) 30%, rgba(0, 0, 0, 0)),
    linear-gradient(to left, var(--page) 30%, rgba(0, 0, 0, 0)) 100% 0,
    radial-gradient(farthest-side at 0 50%, var(--scroll-shadow), rgba(0, 0, 0, 0)),
    radial-gradient(farthest-side at 100% 50%, var(--scroll-shadow), rgba(0, 0, 0, 0)) 100% 0;
  background-repeat: no-repeat;
  background-color: var(--page);
  background-size: 40px 100%, 40px 100%, 14px 100%, 14px 100%;
  background-attachment: local, local, scroll, scroll;
}

.history-older { margin: -12px 0 24px; }
.history-older summary {
  cursor: pointer; color: var(--series-1); font-size: 0.85rem; padding: 6px 0;
  list-style: none;
}
.history-older summary::-webkit-details-marker { display: none; }
.history-older summary::before { content: "▸ "; }
.history-older[open] summary::before { content: "▾ "; }
.history-older .table-scroll { margin-top: 8px; }
.price-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; white-space: nowrap; }
.price-table th, .price-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--grid); }
.price-table th { color: var(--text-secondary); font-weight: 600; font-size: 0.78rem; }
.price-table td:nth-child(2), .price-table td:nth-child(4), .price-table td:nth-child(5),
.price-table td:nth-child(6), .price-table td:nth-child(7) { font-variant-numeric: tabular-nums; }
.price-table a { color: var(--series-1); text-decoration: none; }
.price-table a:hover { text-decoration: underline; }

.spark path { fill: none; stroke: var(--text-muted); stroke-width: 1.5; }
.spark circle { fill: var(--series-1); }

.map-root {
  position: relative; border: 1px solid var(--border);
  border-radius: 8px; padding: 8px; margin-bottom: 12px;
  overflow-x: auto;
  /* Same "local + scroll" fade trick as .table-scroll, tuned to this card's
     own --surface-1 background instead of the page background - a forced
     min-width map (see .map-svg below) can scroll horizontally, and without
     this the hidden side (e.g. Norte on the régions map) just looks missing
     rather than "scroll to see more". */
  background:
    linear-gradient(to right, var(--surface-1) 30%, rgba(0, 0, 0, 0)),
    linear-gradient(to left, var(--surface-1) 30%, rgba(0, 0, 0, 0)) 100% 0,
    radial-gradient(farthest-side at 0 50%, var(--scroll-shadow), rgba(0, 0, 0, 0)),
    radial-gradient(farthest-side at 100% 50%, var(--scroll-shadow), rgba(0, 0, 0, 0)) 100% 0;
  background-repeat: no-repeat;
  background-color: var(--surface-1);
  background-size: 40px 100%, 40px 100%, 14px 100%, 14px 100%;
  background-attachment: local, local, scroll, scroll;
}
.map-svg { display: block; width: 100%; height: auto; }
.map-area path { stroke: var(--surface-1); stroke-width: 1; cursor: pointer; }
.map-area:hover path, .map-area:focus path { stroke: var(--text-primary); stroke-width: 2; }
.map-area:focus { outline: none; }

.map-legend { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; color: var(--text-secondary); font-size: 0.82rem; }
.legend-bar { width: 200px; height: 12px; border-radius: 3px; overflow: hidden; }

.map-wrap--small { max-width: 420px; margin: 0 auto; }

.landing-hero { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 24px; margin-bottom: 16px; }
.landing-hero .map-wrap--small { flex: 1 1 320px; margin: 0; }
.landing-hero-list { flex: 1 1 280px; min-width: 240px; }
.landing-hero-list .region-list { margin-bottom: 0; }

.region-list-caption { margin: 0 0 8px; color: var(--text-muted); font-size: 0.82rem; }

.region-list { list-style: none; margin: 0 0 16px; padding: 0; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.region-list li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--surface-1); }
.region-list li:last-child { border-bottom: none; }
.region-list a { color: var(--text-primary); text-decoration: none; font-weight: 500; }
.region-list a:hover { color: var(--series-1); text-decoration: underline; }
.region-list b { flex-shrink: 0; white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--text-secondary); font-weight: 600; }

@media (max-width: 640px) {
  .topnav-toggle { display: flex; }
  .topnav-links {
    display: none; position: absolute; top: 100%; left: 0; right: 0; z-index: 20;
    flex-direction: column; align-items: stretch; gap: 0;
    background: var(--surface-1); border: 1px solid var(--border); border-top: none;
    box-shadow: 0 8px 16px var(--scroll-shadow);
  }
  .topnav-links--open { display: flex; }
  .topnav-links a { padding: 12px 20px; border-top: 1px solid var(--border); }
  .topnav-links a:first-child { border-top: none; }

  .wrap { padding: 16px 14px 48px; }

  /* Stack the region/concelho/freguesia picker instead of wrapping mid-pair. */
  .area-picker { flex-direction: column; align-items: stretch; }
  .area-picker label { margin-top: 4px; }
  .area-picker select { max-width: none; width: 100%; }
  .nav-go { width: 100%; margin-top: 4px; }

  /* Keep the core comparison (name, price, the two % deltas) visible without
     horizontal scroll; the dropped columns are still on each area's own page. */
  .price-table th:nth-child(3), .price-table td:nth-child(3),
  .price-table th:nth-child(6), .price-table td:nth-child(6),
  .price-table th:nth-child(7), .price-table td:nth-child(7) { display: none; }

  /* SVG text scales with the viewBox, so below this width it'd shrink past
     legible - scroll/pinch-zoom the map itself instead of shrinking further.
     Only for dense maps (many small shapes, e.g. Lisboa's 24 freguesias) -
     .map-root--fluid (e.g. the régions map) overrides this back to none
     below, since those shapes stay legible at any width and forcing a
     minimum here just hides content off-screen for no benefit. */
  .map-root { -webkit-overflow-scrolling: touch; }
  .map-svg { min-width: 480px; }
  .map-root--fluid .map-svg { min-width: 0; }

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