/* ---------------------------------------------------------------------------
   Painel do mercado de habitação em Portugal
   Tokens de cor: paleta validada para daltonismo (deuteranopia/protanopia/
   tritanopia) — pior par adjacente ΔE 9,1 em claro e 8,4 em escuro.
   Modo escuro é escolhido, não invertido: cada tom tem o seu passo próprio.

   Três tons (aqua, amarelo, magenta) ficam abaixo de 3:1 contra a superfície
   clara. É deliberado e está compensado: nenhum gráfico depende só da cor —
   há sempre legenda, rótulos diretos nas séries selecionadas, e a tabela no
   fim da página com todos os valores em texto.

   A rampa sequencial do mapa (--seq-1 .. --seq-6, do valor mais baixo para o
   mais alto) percorre tons **vizinhos e todos frios** — turquesa → ciano →
   azul → índigo — em vez de um único azul. Um azul só distingue as classes
   apenas por lightness, e no extremo claro as classes colavam umas às outras;
   ao deixar o tom variar também, cada classe passa a ter nome próprio. Foi
   gerada em OKLCH com L estritamente monótona e medida: pior par vizinho
   ΔE 11,3 em claro e 11,4 em escuro (antes 9,1 e 9,5), e a classe mais fraca
   passou a distar ΔE 9,3 do cinzento de "sem dados" (antes 5,0 — quase
   indistinguíveis).

   A rampa inverte-se no modo escuro (--seq-1 passa a ser o tom mais escuro):
   o princípio é que o valor mais baixo recua para a superfície, e num fundo
   escuro quem recua é o escuro.
   --------------------------------------------------------------------------- */
/* Os tokens (cores, rampas, séries) já não se definem aqui: vêm do styles.css,
   que a página carrega antes deste ficheiro. Eram os mesmos, valor a valor,
   em claro e em escuro -- a paleta do casometro nasceu desta (conferido a 23
   de Setembro de 2026, tarefa 3.2). Uma cor nova do painel define-se lá. */

* { box-sizing: border-box; }
/* `html, body` vêm do styles.css. As ligações do painel herdam a cor do
   texto, e não o azul das outras páginas. */
a { color: inherit; }
/* A mesma largura e as mesmas margens do `main` das outras páginas: a linha de
   topo não pode saltar de sítio quando se muda de página. */
.wrap { max-width: 1400px; margin: 0 auto; padding: 0 16px 64px; }
@media (max-width: 720px) { .wrap { padding: 0 12px 48px; } }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

/* Estas classes existem porque a Content-Security-Policy do site não permite
   atributos `style=` no HTML (ver web/_headers). Estilo inline em marcação é
   exatamente o que uma CSP restritiva bloqueia — e é o que impede que um
   futuro bug de injeção consiga desenhar o que quiser na página. */
.header-bar {
  display: flex; justify-content: space-between;
  align-items: flex-start; gap: 16px; flex-wrap: wrap;
}
.btn-row { display: flex; gap: 8px; }
.seg.spaced { margin: 8px 0 12px; }
.stat-tile.hero { margin-bottom: 6px; }
.count-note { color: var(--text-muted); font-size: 0.82rem; }
/* especificidade acima de `.field select`, que fixa min-width: 150px */
.field select.narrow { min-width: 96px; }

/* ---------------- cabeçalho ---------------- */
header.top { padding: 6px 0 16px; }
/* O título do painel é um h2: o h1 é a marca, na linha de topo comum. */
header.top .titulo-painel { font-size: 1.55rem; margin: 0 0 6px; letter-spacing: -0.01em; }
header.top p.lede { color: var(--text-secondary); margin: 4px 0 0; max-width: 80ch; }
.vintage-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; align-items: center; }
.pill {
  display: inline-block; font-size: 0.72rem; padding: 3px 9px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-secondary);
  border: 1px solid var(--border);
}
.pill b { color: var(--text-primary); font-weight: 600; }

/* ---------------- barra de filtros ---------------- */
.filters {
  position: sticky; top: 0; z-index: 30;
  background: var(--page);
  border-bottom: 1px solid var(--border);
  padding: 12px 0;
  margin-bottom: 8px;
}
/* Pinned only where it fits in a line or two. Below this width the fields wrap
   into a column and the block grew to 509 px at 360 (60 % of the screen) and
   225 px at 768: the map, the charts and the table were read through the slit
   under it. Same breakpoint as the grids below, which go single-column here. */
@media (max-width: 960px) {
  /* Relative and not static: the pill popovers are placed inside it. */
  .filters { position: relative; }
}
/* The pill row and the actions share the first line; the fields live inside
   the popovers now (analises/app.js, «pílulas»). */
.filters-row { align-items: center; }
.filters-row .pilulas { flex: 1 1 auto; margin-top: 0; }
.filters .pop .field { margin-top: 8px; }
/* A popover with one field already says its name in the heading; the field's
   own label stays for screen readers (it names the control) but not on screen. */
.filters .pop h3 + .field:last-child > label {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}
.filters .pop .field select, .filters .pop .field input[type="search"] { max-width: none; width: 100%; }
.filters-row {
  display: flex; flex-wrap: wrap; gap: 10px 12px; align-items: flex-end;
}
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > label {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-muted); font-weight: 600;
}
.field select, .field input[type="search"], .field input[type="text"] {
  font: inherit; font-size: 0.86rem;
  background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 7px;
  padding: 6px 9px; min-width: 150px; max-width: 230px;
}
.field select:focus-visible, .field input:focus-visible, button:focus-visible {
  outline: 2px solid var(--series-1); outline-offset: 1px;
}
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 7px; overflow: hidden; }
.seg button {
  font: inherit; font-size: 0.82rem; padding: 6px 11px; cursor: pointer;
  background: var(--surface-1); color: var(--text-secondary); border: 0;
  border-right: 1px solid var(--border);
}
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--accent-fill); color: #fff; }
.filters-meta {
  margin-top: 9px; font-size: 0.8rem; color: var(--text-secondary);
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 0.78rem; padding: 3px 6px 3px 9px; border-radius: 999px;
  background: var(--surface-1); border: 1px solid var(--border);
  /* O styles.css tem um `.chip` seu (os filtros dos anúncios) e esta página
     carrega os dois: o que ele define e este não, desfaz-se aqui. */
  font-weight: 400; white-space: normal;
}
.chip .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.chip button {
  border: 0; background: transparent; cursor: pointer; color: var(--text-muted);
  font-size: 0.95rem; line-height: 1; padding: 0 3px;
}
.chip button:hover { color: var(--critical); }

/* ---------------- secções e cartões ---------------- */
section { margin: 40px 0; scroll-margin-top: 120px; }
section h2 { font-size: 1.15rem; margin: 0 0 4px; }
section .section-sub {
  color: var(--text-secondary); font-size: 0.87rem; margin: 0 0 16px; max-width: 92ch;
}
.card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 10px; padding: 16px 18px;
}
.card h3 { margin: 0 0 2px; font-size: 0.95rem; }
.card .sub { font-size: 0.78rem; color: var(--text-muted); margin: 0 0 10px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.map-layout { display: grid; grid-template-columns: minmax(0,1fr) 260px; gap: 16px; }
@media (max-width: 960px) {
  .grid-2, .grid-4, .map-layout { grid-template-columns: 1fr; }
  .grid-4 { grid-template-columns: 1fr 1fr; }
}

/* ---------------- stat tiles ---------------- */
.stat-tile .label { font-size: 0.78rem; color: var(--text-secondary); }
.stat-tile .value { font-size: 1.75rem; font-weight: 600; margin: 3px 0 2px; }
.stat-tile .delta { font-size: 0.83rem; }
/* O `.delta` do styles.css (o preço que desceu, na tabela dos anúncios) é
   `display: block` com margem; aqui o delta segue o elemento onde está. */
.delta { display: revert; margin-top: 0; }
.delta.up { color: var(--good); }
.delta.down { color: var(--div-neg); }
.stat-tile .foot { font-size: 0.76rem; color: var(--text-muted); margin-top: 5px; }

/* ---------------- legendas ---------------- */
.legend {
  display: flex; flex-wrap: wrap; gap: 12px; margin: 2px 0 12px;
  font-size: 0.81rem; color: var(--text-secondary);
}
.legend .item { display: flex; align-items: center; gap: 6px; }
.legend .swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend .swatch.line { width: 15px; height: 3px; border-radius: 2px; }
.scale-legend { display: flex; flex-direction: column; gap: 4px; font-size: 0.76rem; }
.scale-legend .row { display: flex; align-items: center; gap: 8px; color: var(--text-secondary); }
.scale-legend .box { width: 22px; height: 12px; border-radius: 3px; flex: none; }

/* ---------------- tooltip ---------------- */
#tooltip {
  position: fixed; pointer-events: none; z-index: 60;
  background: var(--text-primary); color: var(--page);
  font-size: 0.78rem; padding: 7px 10px; border-radius: 6px;
  max-width: 280px; line-height: 1.4;
  opacity: 0; transform: translate(-9999px, -9999px);
  transition: opacity 0.08s ease;
  box-shadow: 0 4px 14px rgba(0,0,0,0.28);
}
#tooltip.show { opacity: 1; }
#tooltip .t-title { font-weight: 600; margin-bottom: 3px; }
#tooltip .t-row { display: flex; justify-content: space-between; gap: 12px; }
#tooltip .t-row .k { opacity: 0.75; }
#tooltip .t-row .v { font-weight: 600; font-variant-numeric: tabular-nums; }
#tooltip .t-key { display: inline-block; width: 12px; height: 2px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }

/* ---------------- SVG ---------------- */
svg { display: block; }
svg text {
  fill: var(--text-secondary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}
svg .axis-label { fill: var(--text-muted); font-size: 10.5px; font-variant-numeric: tabular-nums; }
svg .axis-title { fill: var(--text-muted); font-size: 10.5px; }
svg .grid-line { stroke: var(--grid); stroke-width: 1; }
svg .baseline { stroke: var(--baseline); stroke-width: 1; }
svg .zero-line { stroke: var(--baseline); stroke-width: 1; }
svg .mark-label { fill: var(--text-primary); font-size: 11px; font-weight: 600; }
svg .mark-sublabel { fill: var(--text-secondary); font-size: 10.5px; }
svg .crosshair { stroke: var(--baseline); stroke-width: 1; pointer-events: none; }
.hover-target { cursor: pointer; }
.chart-scroll { overflow-x: auto; }
.chart-note { font-size: 0.76rem; color: var(--text-muted); margin-top: 8px; }

/* mapa */
.map-shape > path, .map-shape > circle {
  stroke: var(--surface-1); stroke-width: 0.5;
}
.map-shape { cursor: pointer; }
/* Same specificity, so the order decides: hover < selected < keyboard focus.
   Focus is the thickest so that a municipality already in the comparison
   still shows where the keyboard is (it used to drop to the hover width). */
.map-shape:hover > path, .map-shape:hover > circle {
  stroke: var(--text-primary); stroke-width: 1.2;
}
.map-shape.selected > path, .map-shape.selected > circle {
  stroke: var(--text-primary); stroke-width: 1.6;
}
.map-shape:focus-visible > path, .map-shape:focus-visible > circle {
  stroke: var(--text-primary); stroke-width: 2;
}
.map-shape > circle[fill="transparent"] { stroke: none; }
.map-shape:focus { outline: none; }
.map-shape.dim { opacity: 0.18; }
.map-inset-label { fill: var(--text-muted); font-size: 10px; }

/* ---------------- tabela ---------------- */
.table-tools { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 10px; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
table.data-table th, table.data-table td {
  padding: 7px 10px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.data-table th.left, table.data-table td.left { text-align: left; }
table.data-table th {
  font-size: 0.72rem; color: var(--text-muted); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.02em; cursor: pointer; user-select: none;
  position: sticky; top: 0; background: var(--surface-1); z-index: 1;
}
table.data-table th:hover { color: var(--text-primary); }
table.data-table th[aria-sort] { color: var(--text-primary); }
table.data-table tbody tr:hover { background: rgba(128,128,128,0.07); }
table.data-table tbody tr.selected { background: rgba(42,120,214,0.10); }
table.data-table td.num { font-variant-numeric: tabular-nums; }
td.pos { color: var(--good); }
td.neg { color: var(--div-neg); }
.table-scroll { max-height: 620px; overflow: auto; }

/* ---------------- rodapé / metodologia ---------------- */
details.methodology summary { cursor: pointer; font-weight: 600; padding: 5px 0; }
details.methodology ul { color: var(--text-secondary); font-size: 0.87rem; }
details.methodology li { margin-bottom: 6px; }
.source-item { margin-bottom: 10px; }
.source-item b { color: var(--text-primary); }
footer.site-footer {
  margin-top: 56px; padding-top: 18px; border-top: 1px solid var(--border);
  color: var(--text-muted); font-size: 0.78rem;
}
.empty-state {
  color: var(--text-muted); font-size: 0.87rem; padding: 26px; text-align: center;
}
.loading { opacity: 0.45; transition: opacity 0.15s ease; }

/* Touch sizes: see the same block in styles.css. */
@media (pointer: coarse) {
  .field select, .field input[type="search"], .field input[type="text"],
  .seg button { min-height: 44px; }
  .table-scroll th { height: 44px; }
  details.methodology summary { padding: 12px 0; }
}

@media print {
  .filters, .btn { display: none; }
}
