/* Estilo común de las páginas públicas de Mapa Apagones (todas menos el mapa).
   Claro y legible, con la barra azul noche de la app arriba y el rayo ámbar. Si cambias algo aquí, cambia en todas las páginas a la vez. */
:root {
  color-scheme: light;
  --bg: #f4f6fa;
  --bg-glow: #e8eefb;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #536179;
  --border: #e2e8f2;
  --accent: #2257d6;
  --accent-soft: #eef3ff;
  --accent-line: #c8d7fb;
  --bolt: #f5b03c;
  --bolt-strong: #d97a06;
  --pill: #f0f3f8;
  --warn-soft: #fff7ea;
  --warn-line: #fde3b0;
  --bad-soft: #fef2f2;
  --bad-line: #fecaca;
  --row-ok: #f0fbf4;
  --row-part: #fffaeb;
  --row-pend: #ffffff;
  --navy: #0d1626;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 6px 18px rgba(15, 23, 42, .05);
  --radius: 16px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(1200px 500px at 10% -10%, var(--bg-glow), transparent 60%) no-repeat, var(--bg);
  color: var(--text);
  line-height: 1.6;
}
main { width: min(820px, calc(100% - 32px)); margin: 0 auto; padding: 16px 0 64px; }
main.wide { width: min(1080px, calc(100% - 32px)); }
a { color: var(--accent); text-decoration: none; text-underline-offset: 3px; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 3px solid var(--accent-line); outline-offset: 2px; border-radius: 6px; }

/* Cabecera: el enlace de vuelta hace de barra de marca fija */
.back {
  position: sticky; top: 10px; z-index: 10;
  display: inline-flex; align-items: center; gap: 8px; margin: 0 0 22px;
  padding: 7px 16px 7px 8px; border-radius: 999px; font-weight: 700; font-size: .95rem;
  color: var(--text);
  background: color-mix(in srgb, var(--card) 85%, transparent);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  border: 1px solid var(--border); box-shadow: var(--shadow);
}
.back::before {
  content: ''; width: 28px; height: 28px; border-radius: 50%; flex: none;
  background: rgba(255,255,255,0.07) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' width='16' height='16' fill='%23f5b03c' stroke='%23f5b03c' stroke-width='2' stroke-linejoin='round'%3E%3Cpath d='M13 2 4 14h7l-1 8 9-12h-7l1-8Z'/%3E%3C/svg%3E") no-repeat center;
}
.back:hover { text-decoration: none; border-color: var(--accent-line); }
.eyebrow, .updated { color: var(--muted); font-size: .82rem; font-weight: 600; letter-spacing: .02em; margin: 0 0 10px; }
h1 {
  font-size: clamp(1.9rem, 5vw, 2.9rem); line-height: 1.08; letter-spacing: -0.03em;
  margin: 0 0 12px; text-wrap: balance;
}
.lead { color: var(--muted); font-size: 1.1rem; margin: 0 0 20px; }
h2 { font-size: 1.2rem; letter-spacing: -0.01em; margin: 40px 0 12px; display: flex; align-items: center; gap: 10px; }
h2::before {
  content: ''; flex: none; width: 6px; height: 1.1em; border-radius: 3px;
  background: var(--bolt);
}
h3 { font-size: 1.02rem; margin: 18px 0 6px; }
p, li { color: var(--muted); }
strong { color: var(--text); }
ul, ol { padding-left: 1.25rem; }
li { margin: 4px 0; }
code { background: var(--pill); padding: 1px 6px; border-radius: 6px; font-size: .88em; overflow-wrap: anywhere; }

/* Bloques */
.notice, .card, .entry, .level, .hero, .note {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
}
.notice { margin: 16px 0; }
.notice.accent, .note { background: var(--accent-soft); border-color: var(--accent-line); color: var(--text); }
.notice.warn { background: var(--warn-soft); border-color: var(--warn-line); }
.notice.bad { background: var(--bad-soft); border-color: var(--bad-line); }
.notice p:last-child, .card p:last-child { margin-bottom: 0; }

/* Cifras */
.cards, .stats, .metrics, .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(104px, 1fr)); gap: 10px; margin: 18px 0; }
.stat, .metric, .card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.stat strong, .metric strong, .card > strong { display: block; font-size: 1.75rem; line-height: 1.15; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat span, .metric span, .card > span { display: block; color: var(--muted); font-size: .85rem; line-height: 1.35; margin-top: 4px; }

/* Enlaces y botones */
.provlinks { display: flex; flex-wrap: wrap; gap: 8px; padding: 0; list-style: none; }
.provlinks li { margin: 0; }
.provlinks a, .pill {
  display: inline-block; padding: 6px 14px; border-radius: 999px;
  background: var(--card); border: 1px solid var(--border); font-size: .9rem; font-weight: 600;
  transition: border-color .15s, transform .15s;
}
.provlinks a:hover { text-decoration: none; border-color: var(--accent); transform: translateY(-1px); }
.cta {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  margin: 10px 0; padding: 13px 22px; border-radius: 999px; min-height: 48px;
  background: rgba(245, 176, 60, 0.14); color: var(--bolt); border: 1px solid rgba(245, 176, 60, 0.45);
  font-weight: 800; box-shadow: 0 2px 8px rgba(15, 23, 42, .12);
  transition: transform .15s, box-shadow .15s;
}
.cta:hover { text-decoration: none; filter: brightness(1.05); }
@media (max-width: 560px) { .cta { display: flex; width: 100%; } }

/* Tablas */
.table-wrap { overflow-x: auto; border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; background: var(--card); }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--pill); }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.bar { height: 6px; background: var(--pill); border-radius: 999px; margin-top: 6px; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }

/* Historial de cambios */
h2.month { color: var(--muted); }
.entry { margin: 10px 0; padding: 14px 16px; }
.entry .top { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.ver { font-family: ui-monospace, monospace; font-size: .78rem; background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 2px 9px; font-weight: 700; }
.date { color: var(--muted); font-size: .85rem; }
.entry h3 { margin: 4px 0 0; }
.entry details { margin-top: 6px; }
details > summary { cursor: pointer; color: var(--accent); font-weight: 600; }
.entry ul { margin: 6px 0 0; }
details.early > summary { margin: 30px 0 10px; color: var(--text); }

/* Etiquetas de fiabilidad */
.levels { display: grid; gap: 10px; margin: 12px 0; }
.level { border-left: 5px solid var(--accent); }
.level p { margin: 4px 0 0; }

.small { color: var(--muted); font-size: .9rem; }
footer { margin-top: 48px; padding-top: 18px; border-top: 1px solid var(--border); color: var(--muted); font-size: .9rem; }
footer p { margin: 6px 0; }

/* Páginas de provincia y ciudad: lista de municipios */
ul.grid { list-style: none; padding: 0; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 0 14px; }
ul.grid li { font-size: .92rem; margin: 0; padding: 5px 0; border-bottom: 1px dashed var(--border); }

/* Página de cobertura */
.top { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; align-items: center; margin-bottom: 18px; color: var(--muted); font-size: .95rem; }
.hero { padding: 22px 24px; margin-bottom: 18px; }
.hero h1 { margin-top: 0; }
tr.complete { background: var(--row-ok); }
tr.partial { background: var(--row-part); }
tr.pending { background: var(--row-pend); }

.legend { display: flex; align-items: center; gap: 6px; margin: 10px 0 0; color: var(--muted); font-size: .9rem; }
.top .back { margin-bottom: 0; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* Tablas anchas en el móvil: desplazar en horizontal en vez de partir el texto */
.table-wrap th, .table-wrap td { white-space: nowrap; }

/* Páginas de provincia: distribuidoras con barra, pasos numerados, municipios enlazados */
.dist-list { list-style: none; padding: 0; display: grid; gap: 8px; margin: 14px 0; }
.dist-list li {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: baseline; margin: 0;
  padding: 12px 14px; border-radius: 14px; background: var(--card); border: 1px solid var(--border);
}
.dist-name { color: var(--text); font-weight: 700; }
.dist-count { color: var(--muted); font-size: .85rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.dist-list .bar { grid-column: 1 / -1; margin-top: 4px; }
.dist-list .bar i { background: var(--bolt); }

.steps { list-style: none; padding: 0; counter-reset: paso; display: grid; gap: 8px; }
.steps li {
  counter-increment: paso; position: relative; margin: 0; padding: 12px 14px 12px 52px;
  border-radius: 14px; background: var(--card); border: 1px solid var(--border);
}
.steps li::before {
  content: counter(paso); position: absolute; left: 14px; top: 12px;
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 800; font-size: .85rem; color: var(--bolt); background: rgba(245, 176, 60, 0.12);
}

ul.grid li { border-bottom: 0; padding: 0; }
ul.grid li a {
  display: block; padding: 7px 10px; border-radius: 10px; color: var(--text); font-size: .9rem;
  border: 1px solid transparent;
}
ul.grid li a:hover { text-decoration: none; background: var(--pill); border-color: var(--border); }
ul.grid { gap: 6px; }
ul.grid li a { background: var(--pill); border-color: var(--border); }
ul.grid li a:hover { border-color: var(--accent-line); }

/* =========================================================
   CLARO Y A TODO EL ANCHO (16/10)
   ========================================================= */
body { background: var(--bg); }
main, main.wide { width: min(1160px, calc(100% - 32px)); }

/* Barra de marca azul noche a todo el ancho, fija arriba (el enlace de vuelta) */
.back {
  position: sticky; top: 0; z-index: 20;
  display: flex; width: 100vw; margin: 0 0 28px calc(50% - 50vw);
  padding: 12px max(16px, calc(50vw - 580px)); border-radius: 0; border: 0;
  background: var(--navy); color: #fff; font-size: 1rem;
  -webkit-backdrop-filter: none; backdrop-filter: none; box-shadow: 0 2px 10px rgba(15, 23, 42, .12);
}
.back:hover { color: #fff; }
.back::before { background-color: rgba(255,255,255,0.08); }
.top .back { margin-bottom: 0; }

.notice.accent, .note { color: var(--text); }
.cta { background: var(--bolt); color: #1a0f00; border: 0; box-shadow: 0 2px 8px rgba(217, 122, 6, .25); }
.dist-list .bar i { background: var(--bolt-strong); }
.steps li::before { color: var(--bolt-strong); background: #fff3dc; }
th { background: #f6f8fc; }

/* PC: varias columnas para aprovechar el ancho */
@media (min-width: 900px) {
  .dist-list { grid-template-columns: repeat(2, 1fr); }
  .steps { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
  ul.grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
  .cards, .stats, .metrics { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
  .cta { min-width: 280px; }
}
main, main.wide { padding-top: 0; }

/* Botón «Volver al mapa»: pastilla redondeada como los botones del mapa, no barra a todo el ancho */
.back {
  position: sticky; top: 12px; z-index: 20;
  display: inline-flex; width: auto; margin: 16px 0 24px; padding: 8px 18px 8px 8px;
  border-radius: 999px; background: #0d1626; color: #fff; font-size: .95rem;
  box-shadow: 0 6px 18px rgba(15, 23, 42, .18);
}
.back:hover { color: #fff; background: #17223a; }
