:root {
  --paper: #f4f1ea;
  --surface: #ffffff;
  --surface-2: #faf7f1;
  --ink: #211d18;
  --ink-soft: #4a433b;
  --muted: #857a6d;
  --hairline: #e4ddd0;
  --hairline-2: #efe9dd;
  --ember: #c1440e;
  --ember-soft: #f6e6dc;
  --before: #7a53a3;   /* documento ANTES del fuego (premeditación) */
  --after: #c1440e;    /* documento DESPUÉS del fuego */
  --active: #e23a1a;
  --art50: #b42318;
  /* causas (calibradas para fondo claro) */
  --c-intencionado: #c0392b;
  --c-negligencia: #c77d15;
  --c-rayo: #2f6fb0;
  --c-otras: #8a827a;
  --c-desconocida: #a99f93;
  --c-investigacion: #7d5ba6;
  --c-sindeterminar: #9a9088;

  --sans: "IBM Plex Sans", -apple-system, "Segoe UI", sans-serif;
  --serif: "Fraunces", Georgia, serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--sans);
  background: var(--paper); color: var(--ink);
  display: grid; grid-template-rows: auto 1fr auto; height: 100vh; height: 100dvh;
  overflow: hidden; -webkit-font-smoothing: antialiased;
}
.mono { font-family: var(--mono); }

/* ---------- cabecera / masthead ---------- */
header {
  padding: 12px 16px 10px; background: var(--surface);
  border-bottom: 1px solid var(--hairline); border-top: 3px solid var(--ember);
  display: flex; align-items: baseline; gap: 6px 20px; flex-wrap: wrap;
}
.masthead h1 {
  font-family: var(--serif); font-weight: 900; font-size: 27px; line-height: .95;
  margin: 0; letter-spacing: -.02em; color: var(--ink);
}
.masthead .kicker {
  font-family: var(--mono); font-size: 10px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--ember); margin: 3px 0 0;
}
.disclaimer {
  font-size: 11.5px; color: var(--muted); line-height: 1.4; max-width: 640px;
  order: 3; flex-basis: 100%; margin: 6px 0 0; padding-top: 6px;
  border-top: 1px solid var(--hairline-2);
}
.disclaimer b { color: var(--ink-soft); font-weight: 600; }
.stats { margin-left: auto; display: flex; gap: 16px; flex-wrap: wrap; }
.stat { text-align: right; }
.stat b { font-family: var(--mono); font-size: 17px; font-weight: 600; display: block; line-height: 1; }
.stat span { font-size: 9px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.stat.art50 b { color: var(--art50); }
.stat.active b { color: var(--active); }

/* ---------- layout: móvil = una columna, tabbar alterna Lista/Mapa ---------- */
main { display: grid; grid-template-columns: 1fr; grid-template-rows: 1fr; min-height: 0; }
main > aside, main > .map-wrap { grid-area: 1 / 1; min-height: 0; min-width: 0; }
.map-wrap { position: relative; }
#map { position: absolute; inset: 0; background: var(--paper); }
body[data-view="list"] .map-wrap { display: none; }
body[data-view="map"] aside { display: none; }
aside { background: var(--surface); display: flex; flex-direction: column; min-height: 0; }

/* ---------- filtros ---------- */
.filters-toggle {
  width: 100%; text-align: left; padding: 11px 16px; background: var(--surface-2);
  border: none; border-bottom: 1px solid var(--hairline); color: var(--ink);
  font-family: var(--mono); font-size: 11px; letter-spacing: .1em; text-transform: uppercase;
  cursor: pointer;
}
.filters-toggle::after { content: " ▾"; color: var(--muted); }
body.filters-collapsed .filters-toggle::after { content: " ▸"; }
.filters { padding: 14px 16px; border-bottom: 1px solid var(--hairline); display: grid; gap: 13px; }
body.filters-collapsed .filters { display: none; }
.filters label, .list-head, .legend b {
  font-family: var(--mono); font-size: 10px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .08em;
}
.filters label { display: block; margin-bottom: 6px; }
.filters .row { display: flex; gap: 6px; flex-wrap: wrap; }
.geo input {
  width: 100%; padding: 9px 11px; border: 1px solid var(--hairline); border-radius: 8px;
  background: var(--surface-2); color: var(--ink); font-family: var(--sans); font-size: 13px;
}
.geo input:focus { outline: none; border-color: var(--ember); background: #fff; }
.year-row { display: flex; align-items: center; gap: 10px; }
.year-row select {
  flex: 1; padding: 7px 9px; border: 1px solid var(--hairline); border-radius: 8px;
  background: var(--surface-2); color: var(--ink); font-family: var(--mono); font-size: 13px;
}
.year-row select:focus { outline: none; border-color: var(--ember); }
.year-sep { color: var(--muted); }
.chip {
  font-size: 12px; padding: 4px 11px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--hairline); background: var(--surface); color: var(--ink-soft);
  user-select: none; transition: .12s;
}
.chip:hover { border-color: var(--muted); }
.chip.active { background: var(--ink); color: var(--paper); border-color: var(--ink); font-weight: 500; }
.range { display: flex; align-items: center; gap: 8px; }
.range input[type=range] { flex: 1; accent-color: var(--ember); }
#score-val { font-family: var(--mono); color: var(--ink); }
.toggle { display: flex; align-items: center; gap: 7px; font-size: 12.5px; cursor: pointer;
  text-transform: none; letter-spacing: 0; color: var(--ink-soft); }
.toggle input { accent-color: var(--art50); }

/* ---------- banner de activos ---------- */
.active-banner {
  margin: 0; padding: 10px 16px; background: #fdeee9; border-bottom: 1px solid #f3d3c7;
  color: var(--active); font-size: 12.5px; font-weight: 600; cursor: pointer;
  display: flex; align-items: center; gap: 8px;
}
.active-banner::before { content: "●"; animation: pulse 1.6s infinite; }
.active-banner.on { background: var(--active); color: #fff; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .35 } }

/* ---------- cabecera de lista + orden ---------- */
.list-head {
  padding: 9px 16px; display: flex; justify-content: space-between; align-items: center;
  border-bottom: 1px solid var(--hairline); background: var(--surface);
}
.sortswitch { display: flex; gap: 2px; }
.sortswitch button {
  font-family: var(--mono); font-size: 10px; text-transform: uppercase; letter-spacing: .06em;
  padding: 4px 8px; border: 1px solid var(--hairline); background: var(--surface);
  color: var(--muted); cursor: pointer; border-radius: 6px;
}
.sortswitch button.active { background: var(--ink); color: var(--paper); border-color: var(--ink); }

/* ---------- lista de coincidencias ---------- */
#list { overflow-y: auto; flex: 1; scrollbar-width: thin; }
.card {
  padding: 13px 16px; border-bottom: 1px solid var(--hairline-2); cursor: pointer;
  display: grid; grid-template-columns: 42px 1fr; gap: 12px; align-items: start;
  transition: background .12s;
}
.card:hover { background: var(--surface-2); }
.card.sel { background: var(--ember-soft); box-shadow: inset 3px 0 0 var(--ember); }
.badge {
  width: 42px; height: 42px; border-radius: 9px; display: grid; place-items: center;
  font-family: var(--mono); font-weight: 600; font-size: 15px;
  background: var(--surface-2); border: 1px solid var(--hairline); color: var(--muted);
}
.badge.s-hi { background: var(--ember); color: #fff; border-color: var(--ember); }
.badge.s-mid { background: var(--ember-soft); color: var(--ember); border-color: #eecfbf; }
.card .title { font-size: 13.5px; line-height: 1.4; margin: 1px 0 7px; color: var(--ink); }
.card .meta { font-size: 11.5px; color: var(--muted); display: flex; gap: 7px; flex-wrap: wrap; align-items: center; }
.card .meta + .meta { margin-top: 5px; }
.card .geo-line { color: var(--ink-soft); }
.card a.doc { color: var(--ember); text-decoration: none; font-family: var(--mono); font-size: 11px; white-space: nowrap; }
.card a.doc:hover { text-decoration: underline; }
.dotc { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }

.tag {
  font-family: var(--mono); font-size: 10px; padding: 2px 6px; border-radius: 5px;
  border: 1px solid var(--hairline); letter-spacing: .02em; white-space: nowrap;
}
.tag.dir-before { color: var(--before); border-color: #dccef0; background: #f6f1fb; }
.tag.dir-after { color: var(--after); border-color: #f0d5c8; background: #fbf0ea; }
.tag.art50 { color: #fff; background: var(--art50); border-color: var(--art50); }
.tag.tipo { color: var(--ink); font-weight: 500; }
.tag.src { color: var(--muted); }
.tag.st-activo { background: var(--active); color: #fff; border-color: var(--active); font-weight: 600; }
.tag.st-reciente { color: var(--active); border-color: #f3c9bd; background: #fdeee9; }

.empty { padding: 28px 18px; color: var(--muted); font-size: 12.5px; line-height: 1.6; }
.empty code { font-family: var(--mono); background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

/* ---------- popup del mapa ---------- */
.maplibregl-popup-content {
  background: var(--surface); color: var(--ink); border: 1px solid var(--hairline);
  border-radius: 11px; font-family: var(--sans); font-size: 12.5px; padding: 0; overflow: hidden;
  max-width: min(360px, calc(100vw - 24px)); box-shadow: 0 12px 40px rgba(70,50,30,.18);
}
.maplibregl-popup-close-button { color: var(--muted); font-size: 18px; padding: 3px 9px; right: 2px; }
.maplibregl-popup-tip { border-top-color: var(--surface) !important; border-bottom-color: var(--surface) !important; }
.pop-fire { padding: 13px 15px 14px; }
.maplibregl-popup-content h3 { font-family: var(--serif); font-weight: 600; margin: 0; font-size: 17px; padding-right: 18px; letter-spacing: -.01em; }
.maplibregl-popup-content h3 small { font-family: var(--mono); color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .06em; }
.pop-sub { margin: 6px 0 3px; display: flex; align-items: center; gap: 7px; font-size: 12px; }
.pop-sub b { font-family: var(--mono); color: var(--ember); }
.pop-paraje { font-size: 11px; color: var(--muted); }
.pop-affects { font-size: 11.5px; color: var(--ink-soft); margin-top: 6px; padding: 6px 8px;
  background: var(--surface-2); border-radius: 6px; line-height: 1.4; }
.pop-matches { margin-top: 11px; border-top: 1px solid var(--hairline); max-height: 42vh; overflow-y: auto; }
.pop-h { font-family: var(--mono); font-size: 9.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 9px 0 3px; }
.pop-empty { color: var(--muted); padding: 9px 0; }
.pop-matches .m { padding: 9px 0; border-top: 1px solid var(--hairline-2); }
.pop-matches .m:first-of-type { border-top: none; }
.m-title { line-height: 1.4; margin-bottom: 6px; }
.m-meta { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.m-meta a.doc { margin-left: auto; color: var(--ember); text-decoration: none; font-family: var(--mono); font-size: 11px; white-space: nowrap; }

/* ---------- leyenda ---------- */
.legend {
  position: absolute; bottom: 14px; right: 14px; background: rgba(255,255,255,.94);
  border: 1px solid var(--hairline); border-radius: 10px; padding: 10px 12px; font-size: 11.5px;
  backdrop-filter: blur(4px); box-shadow: 0 6px 20px rgba(70,50,30,.1);
}
.legend .li { display: flex; align-items: center; gap: 7px; margin: 3px 0; color: var(--ink-soft); }
.legend .sw { width: 12px; height: 12px; border-radius: 3px; }
.legend b { display: block; margin-bottom: 5px; color: var(--ink); }

/* ---------- conmutador Lista/Mapa (solo móvil) ---------- */
.tabbar { display: flex; background: var(--surface); border-top: 1px solid var(--hairline); }
.tabbar button {
  flex: 1; padding: 13px 8px; background: none; border: none; color: var(--muted);
  font-family: var(--mono); font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  font-weight: 500; cursor: pointer;
}
.tabbar button.active { color: var(--ember); box-shadow: inset 0 2px 0 var(--ember); }

/* ---------- pantallas anchas: dos paneles ---------- */
@media (min-width: 880px) {
  header { padding: 14px 22px 12px; gap: 8px 26px; }
  .masthead h1 { font-size: 30px; }
  .disclaimer { order: 0; flex-basis: auto; border-top: none; padding-top: 0; margin-top: 0; align-self: center; }
  main { grid-template-columns: 396px 1fr; }
  main > aside { grid-area: 1 / 1; border-right: 1px solid var(--hairline); }
  main > .map-wrap { grid-area: 1 / 2; }
  body[data-view="list"] .map-wrap { display: block; }
  body[data-view="map"] aside { display: flex; }
  .tabbar, .filters-toggle { display: none; }
  body.filters-collapsed .filters { display: grid; }
}
@media (max-width: 520px) {
  .legend { bottom: 8px; right: 8px; padding: 8px 9px; font-size: 10px; max-width: 48%; }
  .masthead h1 { font-size: 24px; }
}
