/* ══════════════════════════════════════════════════════════════════════════
   Registre — sistema de diseño
   Dirección: atlas administratif imprimé. Papel cálido, filetes finos,
   serif editorial, vermellón de cuño y azul institucional.
   Restricción de partida: cero dependencias, cero JS de terceros, LCP textual.
   ══════════════════════════════════════════════════════════════════════════ */

@font-face {
  font-family: 'Fraunces';
  src: url('/assets/fonts/fraunces.woff2') format('woff2-variations');
  font-weight: 400 900;
  font-display: swap;
  font-style: normal;
}
@font-face {
  font-family: 'Instrument Sans';
  src: url('/assets/fonts/instrument-sans.woff2') format('woff2-variations');
  font-weight: 400 700;
  font-display: swap;
  font-style: normal;
}

:root {
  --paper:       #f7f3ea;
  --paper-2:     #f1ece0;
  --paper-3:     #e8e2d3;
  --ink:         #16181d;
  --ink-2:       #3d4149;
  --ink-3:       #6b7079;
  --rule:        #d4cdba;
  --rule-strong: #b3aa93;
  --vermillon:   #b8402a;
  --vermillon-2: #93321f;
  --bleu:        #1b3a6b;
  --bleu-2:      #2c5490;
  --wash:        #fffdf8;

  --font-display: 'Fraunces', 'Iowan Old Style', Georgia, 'Times New Roman', serif;
  --font-sans: 'Instrument Sans', ui-sans-serif, -apple-system, 'Segoe UI', Roboto, sans-serif;

  --measure: 68ch;
  --gutter: clamp(1rem, 4vw, 2.5rem);
  --shell: 1180px;

  --shadow-card: 0 1px 0 var(--rule), 0 2px 14px -8px rgba(22, 24, 29, .28);
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper:       #14161a;
    --paper-2:     #1a1d22;
    --paper-3:     #22262c;
    --ink:         #ece5d6;
    --ink-2:       #bdb6a8;
    --ink-3:       #8b8578;
    --rule:        #2f343b;
    --rule-strong: #454c55;
    --vermillon:   #e2705a;
    --vermillon-2: #f08a72;
    --bleu:        #8fb3e8;
    --bleu-2:      #a9c6f2;
    --wash:        #1a1d22;
    --shadow-card: 0 1px 0 var(--rule), 0 2px 14px -8px rgba(0, 0, 0, .5);
  }
}
:root[data-theme='dark'] {
  --paper: #14161a; --paper-2: #1a1d22; --paper-3: #22262c;
  --ink: #ece5d6; --ink-2: #bdb6a8; --ink-3: #8b8578;
  --rule: #2f343b; --rule-strong: #454c55;
  --vermillon: #e2705a; --vermillon-2: #f08a72;
  --bleu: #8fb3e8; --bleu-2: #a9c6f2; --wash: #1a1d22;
}
:root[data-theme='light'] {
  --paper: #f7f3ea; --paper-2: #f1ece0; --paper-3: #e8e2d3;
  --ink: #16181d; --ink-2: #3d4149; --ink-3: #6b7079;
  --rule: #d4cdba; --rule-strong: #b3aa93;
  --vermillon: #b8402a; --vermillon-2: #93321f;
  --bleu: #1b3a6b; --bleu-2: #2c5490; --wash: #fffdf8;
}

/* ── base ───────────────────────────────────────────────────────────────── */

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

body {
  margin: 0;
  background-color: var(--paper);
  /* grano de papel: SVG inline, ~300 bytes, sin petición de red */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)' opacity='.035'/%3E%3C/svg%3E");
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 17px;
  line-height: 1.6;
  font-feature-settings: 'kern' 1;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 600;
  font-variation-settings: 'SOFT' 0, 'WONK' 1;
  line-height: 1.12;
  letter-spacing: -.015em;
  margin: 0 0 .5em;
  text-wrap: balance;
}
h1 { font-size: clamp(1.9rem, 1.2rem + 2.6vw, 3.1rem); }
h2 { font-size: clamp(1.35rem, 1.1rem + 1vw, 1.8rem); margin-top: 2.4em; }
h3 { font-size: 1.12rem; font-family: var(--font-sans); font-weight: 600; letter-spacing: 0; margin-top: 1.8em; }
p  { margin: 0 0 1em; max-width: var(--measure); }

a { color: var(--bleu); text-decoration-thickness: 1px; text-underline-offset: .16em; }
a:hover { color: var(--vermillon); }
a:focus-visible, button:focus-visible, input:focus-visible {
  outline: 2px solid var(--vermillon);
  outline-offset: 2px;
  border-radius: 2px;
}

.shell { max-width: var(--shell); margin-inline: auto; padding-inline: var(--gutter); }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}
.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 99;
  background: var(--ink); color: var(--paper); padding: .7rem 1.1rem;
}
.skip-link:focus { left: .5rem; top: .5rem; }

/* ── cabecera ───────────────────────────────────────────────────────────── */

.masthead {
  border-bottom: 1px solid var(--rule);
  background: var(--wash);
  position: relative;
}
.masthead::after {
  content: ''; position: absolute; inset-inline: 0; bottom: -4px; height: 3px;
  background: repeating-linear-gradient(90deg, var(--rule) 0 6px, transparent 6px 12px);
  opacity: .55;
}
.masthead__inner {
  display: flex; align-items: center; gap: 1.5rem;
  min-height: 68px; flex-wrap: wrap; padding-block: .7rem;
}
.wordmark {
  font-family: var(--font-display);
  font-weight: 700;
  font-variation-settings: 'SOFT' 0, 'WONK' 1;
  font-size: 1.22rem;
  letter-spacing: -.02em;
  color: var(--ink);
  text-decoration: none;
  display: inline-flex; align-items: baseline; gap: .5rem;
  white-space: nowrap;
}
.wordmark:hover { color: var(--ink); }
.wordmark__mark {
  font-family: var(--font-sans); font-size: .66rem; font-weight: 600;
  letter-spacing: .14em; text-transform: uppercase;
  color: var(--paper); background: var(--vermillon);
  padding: .22em .5em .2em; border-radius: 2px;
  transform: rotate(-1.5deg);
}
.masthead__nav { margin-inline-start: auto; display: flex; gap: 1.25rem; font-size: .9rem; }
.masthead__nav a { color: var(--ink-2); text-decoration: none; }
.masthead__nav a:hover { color: var(--vermillon); text-decoration: underline; }

/* ── buscador ───────────────────────────────────────────────────────────── */

.search { position: relative; width: 100%; max-width: 34rem; }
.search__field {
  display: flex; align-items: stretch;
  border: 1.5px solid var(--rule-strong);
  background: var(--wash);
  border-radius: 3px;
}
.search__field:focus-within { border-color: var(--vermillon); }
.search input {
  flex: 1; min-width: 0;
  font: inherit; font-size: 1rem;
  padding: .7rem .85rem;
  border: 0; background: transparent; color: var(--ink);
  border-radius: 3px 0 0 3px;
}
.search input::placeholder { color: var(--ink-3); }
.search button {
  font: inherit; font-weight: 600; font-size: .9rem;
  padding: 0 1.1rem; cursor: pointer;
  border: 0; border-inline-start: 1.5px solid var(--rule-strong);
  background: var(--ink); color: var(--paper);
  border-radius: 0 2px 2px 0;
}
.search button:hover { background: var(--vermillon); }
.search__results {
  position: absolute; z-index: 30; inset-inline: 0; top: calc(100% + 4px);
  background: var(--wash); border: 1px solid var(--rule-strong);
  box-shadow: var(--shadow-card);
  max-height: 20rem; overflow-y: auto;
  display: none;
}
.search__results[data-open] { display: block; }
.search__results a {
  display: flex; justify-content: space-between; gap: 1rem; align-items: baseline;
  padding: .55rem .85rem; text-decoration: none; color: var(--ink);
  border-bottom: 1px solid var(--rule);
}
.search__results a:last-child { border-bottom: 0; }
.search__results a:hover, .search__results a[data-active] { background: var(--paper-2); color: var(--vermillon); }
.search__results .cp { font-variant-numeric: tabular-nums; color: var(--ink-3); font-size: .88rem; }
.search__empty { padding: .7rem .85rem; color: var(--ink-3); font-size: .92rem; }

/* ── migas ──────────────────────────────────────────────────────────────── */

.breadcrumb {
  font-size: .86rem; color: var(--ink-3);
  padding-block: .9rem .2rem;
  display: flex; flex-wrap: wrap; gap: .35rem;
}
.breadcrumb ol { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: .35rem; }
.breadcrumb li::after { content: '›'; margin-inline-start: .4rem; color: var(--rule-strong); }
.breadcrumb li:last-child::after { content: none; }
.breadcrumb a { color: var(--ink-3); text-decoration: none; }
.breadcrumb a:hover { color: var(--vermillon); text-decoration: underline; }

/* ── cuño de código postal ──────────────────────────────────────────────── */

.stamp {
  display: inline-block; position: relative;
  padding: .55rem 1rem .5rem;
  background: var(--wash);
  color: var(--vermillon);
  font-family: var(--font-sans);
  font-weight: 600; font-size: clamp(1.3rem, 1rem + 1.6vw, 2rem);
  font-variant-numeric: tabular-nums;
  letter-spacing: .11em;
  border: 2px solid var(--vermillon);
  border-radius: 3px;
  transform: rotate(-1deg);
}
.stamp::before {
  content: ''; position: absolute; inset: 3px;
  border: 1px dashed var(--vermillon); opacity: .45; border-radius: 2px;
}
.stamp-row { display: flex; flex-wrap: wrap; gap: .8rem; align-items: center; margin-block: 1.2rem 1.6rem; }
.stamp--sm { font-size: 1rem; padding: .3rem .6rem; letter-spacing: .09em; border-width: 1.5px; }

/* ── portada de página ──────────────────────────────────────────────────── */

.page-head { padding-block: 1rem 0; position: relative; }
.page-head__eyebrow {
  font-size: .76rem; font-weight: 600; letter-spacing: .16em; text-transform: uppercase;
  color: var(--vermillon); margin-bottom: .7rem;
}
.page-head__ghost {
  position: absolute; inset-block-start: -1rem; inset-inline-end: 0;
  font-family: var(--font-display); font-weight: 700;
  font-size: clamp(6rem, 18vw, 13rem); line-height: .78;
  color: var(--ink); opacity: .045; pointer-events: none; user-select: none;
  font-variant-numeric: tabular-nums; letter-spacing: -.04em;
}
.lede { font-size: 1.08rem; color: var(--ink-2); max-width: var(--measure); }
.lede strong { color: var(--ink); font-weight: 600; }

/* respuesta directa: el bloque que Google cita */
.answer {
  border-inline-start: 3px solid var(--vermillon);
  background: var(--wash);
  padding: 1rem 1.2rem;
  margin-block: 1.4rem;
  max-width: var(--measure);
  box-shadow: var(--shadow-card);
}
.answer p { margin: 0; font-size: 1.06rem; }
.answer p + p { margin-top: .6rem; }

/* ── ficha de datos ─────────────────────────────────────────────────────── */

.fiche {
  border: 1px solid var(--rule-strong);
  background: var(--wash);
  margin-block: 1.6rem;
  box-shadow: var(--shadow-card);
}
.fiche__title {
  font-family: var(--font-sans); font-size: .74rem; font-weight: 600;
  letter-spacing: .15em; text-transform: uppercase; color: var(--ink-3);
  padding: .6rem .95rem; border-bottom: 1px solid var(--rule);
  background: var(--paper-2);
  display: flex; justify-content: space-between; gap: 1rem; align-items: center;
}
.fiche__grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 15rem), 1fr));
}
.fiche__row {
  padding: .6rem .95rem;
  border-bottom: 1px solid var(--rule);
  border-inline-end: 1px solid var(--rule);
  display: flex; flex-direction: column; gap: .12rem;
}
.fiche__k { font-size: .76rem; letter-spacing: .05em; color: var(--ink-3); text-transform: uppercase; }
.fiche__v { font-size: 1.02rem; font-weight: 500; font-variant-numeric: tabular-nums; }
.fiche__v small { font-weight: 400; color: var(--ink-3); font-size: .8rem; }

/* ── tablas ─────────────────────────────────────────────────────────────── */

.table-wrap { overflow-x: auto; margin-block: 1.2rem; }
table { border-collapse: collapse; width: 100%; font-size: .96rem; }
caption { text-align: left; color: var(--ink-3); font-size: .86rem; padding-bottom: .5rem; }
th, td { text-align: left; padding: .55rem .75rem; border-bottom: 1px solid var(--rule); }
th {
  font-size: .76rem; letter-spacing: .08em; text-transform: uppercase;
  color: var(--ink-3); font-weight: 600; border-bottom: 1.5px solid var(--rule-strong);
  white-space: nowrap;
}
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: var(--paper-2); }

/* ── rejilla de enlaces (comunas, departamentos) ────────────────────────── */

.index-grid {
  list-style: none; margin: 1.2rem 0; padding: 0;
  display: grid; gap: 0;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 16rem), 1fr));
  border-top: 1px solid var(--rule);
}
.index-grid li { border-bottom: 1px solid var(--rule); }
.index-grid a {
  display: flex; justify-content: space-between; gap: .6rem; align-items: baseline;
  padding: .5rem .2rem; text-decoration: none; color: var(--ink);
}
.index-grid a:hover { color: var(--vermillon); background: var(--paper-2); }
.index-grid .cp {
  font-variant-numeric: tabular-nums; font-size: .86rem; color: var(--ink-3);
  white-space: nowrap;
}
.index-grid a:hover .cp { color: var(--vermillon); }

/* ── tarjetas ───────────────────────────────────────────────────────────── */

/* Rejilla reglada. Los filetes van en cada tarjeta, no en el fondo del
   contenedor: si la última fila queda incompleta, el hueco es papel y no
   un bloque de color. */
.cards {
  list-style: none; padding: 0; margin: 1.4rem 0;
  display: grid; gap: 0;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 17rem), 1fr));
  border-block: 1px solid var(--rule);
}
.card {
  background: var(--wash); padding: 1rem 1.05rem;
  border-inline-end: 1px solid var(--rule);
  border-block-start: 1px solid var(--rule);
  margin-block-start: -1px;
}
.card:first-child { border-inline-start: 1px solid var(--rule); }
.card a { text-decoration: none; color: var(--ink); font-weight: 600; font-family: var(--font-display); font-size: 1.1rem; }
.card a:hover { color: var(--vermillon); }
.card p { font-size: .88rem; color: var(--ink-3); margin: .35rem 0 0; }
.card__meta { font-size: .82rem; color: var(--ink-3); font-variant-numeric: tabular-nums; margin-top: .5rem; }

/* ── mapa perezoso ──────────────────────────────────────────────────────── */

.map {
  position: relative; aspect-ratio: 16 / 9; width: 100%;
  border: 1px solid var(--rule-strong); background: var(--paper-2);
  margin-block: 1.2rem; overflow: hidden; box-shadow: var(--shadow-card);
}
.map__placeholder {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: .7rem; cursor: pointer; border: 0; width: 100%;
  background:
    repeating-linear-gradient(0deg, transparent 0 39px, var(--rule) 39px 40px),
    repeating-linear-gradient(90deg, transparent 0 39px, var(--rule) 39px 40px),
    var(--paper-2);
  color: var(--ink-2); font: inherit;
}
.map__placeholder span {
  background: var(--wash); border: 1.5px solid var(--rule-strong);
  padding: .5rem .9rem; font-size: .92rem; font-weight: 500;
  box-shadow: var(--shadow-card);
}
.map__coords { font-variant-numeric: tabular-nums; font-size: .82rem; color: var(--ink-3); }

/* ── FAQ ────────────────────────────────────────────────────────────────── */

.faq { margin-block: 1.4rem; border-top: 1px solid var(--rule); }
.faq details { border-bottom: 1px solid var(--rule); }
.faq summary {
  cursor: pointer; padding: .85rem .2rem; font-weight: 600;
  list-style: none; display: flex; justify-content: space-between; gap: 1rem; align-items: center;
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after { content: '+'; color: var(--vermillon); font-size: 1.3rem; line-height: 1; }
.faq details[open] summary::after { content: '−'; }
.faq details > div { padding: 0 .2rem 1rem; color: var(--ink-2); }
.faq details > div > p:last-child { margin-bottom: 0; }

/* ── nota de procedencia ────────────────────────────────────────────────── */

.provenance {
  font-size: .84rem; color: var(--ink-3);
  border: 1px dashed var(--rule-strong);
  padding: .75rem .95rem; margin-block: 1.8rem;
  background: var(--paper-2);
}
.provenance strong { color: var(--ink-2); font-weight: 600; }

/* ── publicidad: altura reservada, CLS = 0 ──────────────────────────────── */

.ad {
  margin-block: 1.8rem;
  display: flex; align-items: center; justify-content: center;
  contain: layout size style;
  background: var(--paper-2);
  border: 1px dashed var(--rule);
  overflow: hidden;
}
.ad::before {
  content: 'Publicité'; font-size: .68rem; letter-spacing: .14em; text-transform: uppercase;
  color: var(--ink-3);
}
.ad:has(ins[data-ad-status='filled'])::before { content: none; }
.ad--leaderboard { height: 280px; }
.ad--inline { height: 280px; }
@media (min-width: 768px) {
  .ad--leaderboard { height: 90px; }
  .ad--inline { height: 250px; }
}
.ad ins { display: block; width: 100%; height: 100%; }

/* ── pie ────────────────────────────────────────────────────────────────── */

.footer {
  margin-top: 4rem; border-top: 2px solid var(--rule-strong);
  background: var(--wash); padding-block: 2.2rem 2.6rem;
  font-size: .9rem;
}
.footer__grid {
  display: grid; gap: 2rem;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 13rem), 1fr));
}
.footer h2 {
  font-family: var(--font-sans); font-size: .74rem; font-weight: 600;
  letter-spacing: .15em; text-transform: uppercase; color: var(--ink-3);
  margin: 0 0 .8rem;
}
.footer ul { list-style: none; margin: 0; padding: 0; display: grid; gap: .4rem; }
.footer a { color: var(--ink-2); text-decoration: none; }
.footer a:hover { color: var(--vermillon); text-decoration: underline; }
.footer__legal {
  margin-top: 2rem; padding-top: 1.2rem; border-top: 1px solid var(--rule);
  color: var(--ink-3); font-size: .84rem;
  display: flex; flex-wrap: wrap; gap: .4rem 1.2rem; align-items: center;
}
.footer__legal a { color: var(--ink-3); }

/* ── paginación ─────────────────────────────────────────────────────────── */

.pagination { display: flex; flex-wrap: wrap; gap: .4rem; margin-block: 1.6rem; }
.pagination a, .pagination span {
  padding: .4rem .75rem; border: 1px solid var(--rule-strong);
  text-decoration: none; color: var(--ink-2); font-variant-numeric: tabular-nums;
  font-size: .9rem; background: var(--wash);
}
.pagination [aria-current] { background: var(--ink); color: var(--paper); border-color: var(--ink); }

/* ── utilidades ─────────────────────────────────────────────────────────── */

.stack > * + * { margin-top: 1rem; }
.muted { color: var(--ink-3); }
.rule { border: 0; border-top: 1px solid var(--rule); margin-block: 2.2rem; }
main { padding-bottom: 2rem; }
.chip-row { display: flex; flex-wrap: wrap; gap: .4rem; margin-block: .8rem; list-style: none; padding: 0; }
.chip {
  display: inline-block; padding: .28rem .6rem; font-size: .86rem;
  border: 1px solid var(--rule-strong); background: var(--wash);
  text-decoration: none; color: var(--ink-2); border-radius: 2px;
  font-variant-numeric: tabular-nums;
}
.chip:hover { border-color: var(--vermillon); color: var(--vermillon); }
