:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --text: #16213a;
  --muted: #5b6680;
  --border: #dde3ee;
  --brand: #123a8a;
  --brand-2: #1f63d6;
  --brand-soft: #e7eefc;
  --shadow: 0 1px 2px rgba(16, 33, 70, .06), 0 6px 20px rgba(16, 33, 70, .07);
  --stripe: linear-gradient(90deg, #f2b705 0 25%, #d7262e 25% 50%, #2aa34a 50% 75%, #1f63d6 75%);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1424; --surface: #161e33; --text: #e6ebf5; --muted: #9aa6c1;
    --border: #27314b; --brand: #8fb0ff; --brand-2: #6d97ff; --brand-soft: #1d2a4a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1424; --surface: #161e33; --text: #e6ebf5; --muted: #9aa6c1;
  --border: #27314b; --brand: #8fb0ff; --brand-2: #6d97ff; --brand-soft: #1d2a4a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}
a { color: inherit; }

/* ---------- Encabezado ---------- */
.topbar {
  background: #123a8a;
  color: #fff;
  position: relative;
}
.topbar::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: var(--stripe); }
.topbar-inner {
  max-width: 1200px; margin: 0 auto; padding: 14px 16px 18px;
  display: flex; align-items: center; gap: 14px;
}
.logo {
  width: 40px; height: 40px; border-radius: 10px; background: rgba(255,255,255,.14);
  display: grid; place-items: center; flex: none;
}
.topbar h1 { font-size: 17px; margin: 0; font-weight: 650; letter-spacing: .2px; }
.topbar p { margin: 0; font-size: 13px; opacity: .8; }
.topbar .spacer { flex: 1; }
.btn-tema {
  background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.25); color: #fff;
  border-radius: 8px; padding: 6px 10px; cursor: pointer; font: inherit; font-size: 13px;
}

/* ---------- Menú principal ---------- */
.hero { max-width: 1200px; margin: 0 auto; padding: 32px 16px 8px; }
.hero h2 { font-size: clamp(24px, 4vw, 34px); margin: 0 0 6px; line-height: 1.15; color: var(--brand); }
.hero p { margin: 0; color: var(--muted); max-width: 720px; }
.resumen { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.chip {
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px;
  padding: 6px 14px; font-size: 13px; color: var(--muted);
}
.chip b { color: var(--text); font-variant-numeric: tabular-nums; }

.herramientas { max-width: 1200px; margin: 0 auto; padding: 18px 16px 0; }
.buscar {
  width: 100%; max-width: 380px; padding: 10px 14px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit;
}
.buscar:focus { outline: 2px solid var(--brand-2); outline-offset: 1px; }

.grid {
  max-width: 1200px; margin: 0 auto; padding: 18px 16px 48px;
  display: grid; gap: 18px; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
}
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  overflow: hidden; text-decoration: none; display: flex; flex-direction: column;
  box-shadow: var(--shadow); transition: transform .15s, border-color .15s;
}
.card:hover, .card:focus-visible { transform: translateY(-3px); border-color: var(--brand-2); outline: none; }
.card .cover { aspect-ratio: 3 / 4; background: var(--brand-soft); overflow: hidden; }
.card .cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card .info { padding: 12px 14px 14px; }
.card .info small { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .6px; }
.card .info h3 { margin: 2px 0 6px; font-size: 18px; }
.card .meta { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.vacio { grid-column: 1 / -1; color: var(--muted); text-align: center; padding: 40px 0; }

footer { text-align: center; color: var(--muted); font-size: 12px; padding: 0 16px 28px; }

/* ---------- Visor por provincia ---------- */
.visor-body { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
.visor-body .topbar-inner { max-width: none; }
.volver {
  color: #fff; text-decoration: none; font-size: 13px; padding: 6px 10px; border-radius: 8px;
  background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.25); white-space: nowrap;
}
.layout { flex: 1; display: flex; min-height: 0; }
.sidebar {
  width: 300px; flex: none; background: var(--surface); border-right: 1px solid var(--border);
  overflow-y: auto; padding: 16px 0 24px;
}
.sidebar h4 {
  margin: 16px 18px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted);
}
.sidebar h4:first-child { margin-top: 0; }
.sel-prov {
  margin: 0 16px; width: calc(100% - 32px); padding: 9px 10px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text); font: inherit; font-weight: 600;
}
.ficha { display: flex; gap: 12px; margin: 14px 16px 4px; align-items: center; }
.ficha img { width: 58px; border-radius: 6px; border: 1px solid var(--border); }
.ficha .meta { font-size: 13px; color: var(--muted); line-height: 1.6; }
.acciones { display: flex; gap: 8px; margin: 12px 16px 0; }
.acciones a {
  flex: 1; text-align: center; text-decoration: none; font-size: 13px; padding: 8px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg);
}
.acciones a.prim { background: var(--brand-2); color: #fff; border-color: var(--brand-2); }
.caps { list-style: none; margin: 0; padding: 0 8px; counter-reset: c; }
.caps button {
  width: 100%; text-align: left; background: none; border: 0; color: var(--text); font: inherit; font-size: 14px;
  padding: 8px 10px; border-radius: 8px; cursor: pointer; display: flex; gap: 10px; align-items: baseline;
}
.caps button:hover { background: var(--brand-soft); }
.caps button.activo { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.caps .num { color: var(--muted); font-size: 12px; min-width: 22px; font-variant-numeric: tabular-nums; }
.caps .pag { margin-left: auto; white-space: nowrap; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.visor { flex: 1; min-width: 0; background: #525659; }
.visor iframe { width: 100%; height: 100%; border: 0; display: block; }
.btn-menu { display: none; }

@media (max-width: 820px) {
  .btn-menu {
    display: inline-block; background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.25);
    color: #fff; border-radius: 8px; padding: 6px 10px; font: inherit; font-size: 13px;
  }
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 20; width: min(300px, 86vw);
    transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow);
  }
  .sidebar.abierto { transform: none; }
  .topbar p { display: none; }
  .topbar h1 { font-size: 15px; }
}
