:root {
  --bg: #f5f6f8; --panel: #fff; --text: #1d2228; --muted: #6b7480; --line: #e2e5ea; --line2: #c9ced6;
  --accent: #1c5cab; --accent-soft: #e8f0fb; --nav: #14263d;
  --ok: #1b7f3b; --ok-soft: #e5f4ea; --ko: #b42318; --ko-soft: #fdecea;
  --warn: #9a6700; --warn-soft: #fff4d6; --info: #1f5fad; --info-soft: #e8f0fb;
  /* series de gráficos: paleta categórica validada (orden fijo) */
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s8: #e34948;
  --grid: #e9ebee; --axis: #6b7480;
  --radius: 8px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: inherit; }
a.link { color: var(--info); text-decoration: none; }
a.link:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 10px; }
h3 { font-size: 12px; margin: 14px 0 6px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
code { background: #eef0f2; padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.muted { color: var(--muted); } .small { font-size: 12px; } .nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 14px; }
.mt { margin-top: 16px; } .mb { margin-bottom: 12px; }

/* cabecera */
.top { display: flex; align-items: center; gap: 16px; padding: 0 20px; height: 48px; background: var(--nav); color: #fff; position: sticky; top: 0; z-index: 30; }
.top .brand { font-weight: 700; text-decoration: none; letter-spacing: .02em; white-space: nowrap; }
.top .brand span { color: #7fb4f0; }
.top nav { display: flex; gap: 2px; overflow-x: auto; min-width: 0; }
.top nav a { color: #cfd8e3; text-decoration: none; padding: 6px 10px; border-radius: 6px; white-space: nowrap; }
.top nav a:hover, .top nav a.on { color: #fff; background: #23395a; }
.top nav .sep { width: 1px; background: #33496a; margin: 6px 6px; }
.top .user { margin-left: auto; display: flex; gap: 10px; align-items: center; color: #cfd8e3; font-size: 13px; white-space: nowrap; }
.top .user form { margin: 0; }
.top .user button { background: none; border: 1px solid #3a5070; color: #cfd8e3; border-radius: 6px; padding: 3px 8px; cursor: pointer; font: inherit; }
.wrap { padding: 18px 20px 48px; max-width: 1600px; margin: 0 auto; }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.crumbs a { text-decoration: none; } .crumbs a:hover { text-decoration: underline; }
.head { display: flex; justify-content: space-between; align-items: flex-end; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }

/* avisos */
.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 10px; border: 1px solid transparent; }
.flash.ok { background: var(--ok-soft); color: var(--ok); }
.flash.error { background: var(--ko-soft); color: var(--ko); }
.flash.clave { background: var(--warn-soft); color: #6b4800; border-color: #f2d58a; font-weight: 600; }
.aviso { padding: 8px 12px; border-radius: 6px; background: var(--warn-soft); color: var(--warn); margin-bottom: 10px; font-size: 13px; }
.nota { padding: 8px 12px; border-radius: 6px; background: var(--info-soft); color: var(--info); margin-bottom: 10px; font-size: 13px; }

/* paneles, tablas */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; }
.panel.p0 { padding: 0; overflow: auto; }
.panel > h2:first-child { margin-top: 0; }
.panel .sub { font-size: 12px; color: var(--muted); margin: -6px 0 10px; }
table.grid { width: 100%; border-collapse: collapse; background: var(--panel); }
table.grid th, table.grid td { padding: 6px 9px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
table.grid th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbfc; position: sticky; top: 0; }
table.grid th a { text-decoration: none; }
table.grid th a.on { color: var(--text); }
table.grid tr:last-child td { border-bottom: 0; }
table.grid tbody tr:hover td { background: #fafbfc; }
table.grid td.hm { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; font-size: 12.5px; }
table.compact td, table.compact th { padding: 4px 8px; }
tr[data-href] { cursor: pointer; }

/* cifras */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin: 4px 0 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; }
.stat b { display: block; font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }
.stat small { display: block; font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.stat.hero { grid-column: span 2; }
.stat.hero b { font-size: 34px; }

/* filtros */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.filters .grupo { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; max-width: 100%; }
.filters label.mini { font-size: 11px; color: var(--muted); }
.filters input[type=number] { width: 90px; }
.filters input[type=date] { width: 140px; }
input[type=text], input[type=password], input[type=email], input[type=number], input[type=search], input[type=date], input[type=file], select, textarea {
  padding: 6px 8px; border: 1px solid var(--line2); border-radius: 6px; background: #fff; font: inherit; color: inherit; max-width: 100%; }
label.f { display: block; margin-bottom: 10px; }
label.f > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; font-weight: 600; }
label.chk { display: inline-flex; gap: 6px; align-items: center; font-size: 13px; }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 6px; border: 1px solid var(--line2); background: #fff; cursor: pointer; font: inherit; text-decoration: none; color: var(--text); white-space: nowrap; }
.btn:hover { border-color: #9aa3ad; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--ko); border-color: #f1b5ae; }
.btn.sm { padding: 3px 8px; font-size: 12px; }
form.inline { display: inline; margin: 0; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.b-activo, .b-ok { background: var(--ok-soft); color: var(--ok); }
.b-vendido { background: var(--info-soft); color: var(--info); }
.b-warn { background: var(--warn-soft); color: var(--warn); }
.b-bad { background: var(--ko-soft); color: var(--ko); }
.b-sin { background: #eef0f2; color: #57606a; }
.bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; min-width: 60px; }
.bar i { display: block; height: 100%; background: var(--s1); border-radius: 0 3px 3px 0; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 12px; flex-wrap: wrap; }
.tabs a { border: 0; background: none; padding: 8px 14px; font: inherit; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; text-decoration: none; }
.tabs .on { color: var(--text); border-color: var(--accent); font-weight: 600; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chip { background: #eef0f2; border-radius: 4px; padding: 1px 6px; font-size: 11.5px; text-decoration: none; white-space: nowrap; }
dl.kv { display: grid; grid-template-columns: 42% 1fr; gap: 4px 10px; margin: 0; font-size: 13px; }
dl.kv dt { color: var(--muted); } dl.kv dd { margin: 0; word-break: break-word; }
.up { color: var(--ko); } .down { color: var(--ok); }

/* gráficos */
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .base { stroke: #c9ced6; stroke-width: 1; }
.chart .ax { fill: var(--axis); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .ax.lbl { font-size: 11px; font-style: italic; }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart .hit:hover { fill: rgba(42,120,214,.06); }
.chart .ring, .chart .dot { stroke: var(--panel); stroke-width: 2; }
.chart .dot { cursor: pointer; opacity: .85; }
.chart .dot:hover { opacity: 1; stroke: var(--text); }
.chart .recta { stroke: var(--text); stroke-width: 1.5; stroke-dasharray: 5 4; opacity: .55; }
.leyenda { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-bottom: 4px; flex-wrap: wrap; }
.leyenda i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; }
#tip { position: fixed; pointer-events: none; z-index: 80; background: #1d2228; color: #fff; font-size: 12px; padding: 5px 8px; border-radius: 5px; max-width: 340px; display: none; box-shadow: 0 2px 8px rgba(0,0,0,.2); }

.login { max-width: 380px; margin: 9vh auto; }
.login .panel { padding: 22px; }
@media print {
  .top, .noprint, .filters { display: none !important; }
  body { background: #fff; }
  .wrap { padding: 0; max-width: none; }
  .panel { box-shadow: none; break-inside: avoid; }
}
@media (max-width: 760px) {
  .wrap { padding: 12px 16px 30px; }
  .top { padding: 6px 10px; gap: 6px 8px; height: auto; flex-wrap: wrap; }
  .top nav { order: 3; width: 100%; }
  .filters input[type=date] { width: 130px; }
  .top .user span { display: none; }
  .grid2 { grid-template-columns: 1fr; }
  .stat.hero { grid-column: span 1; }
  table.grid .hide-sm { display: none; }
}

/* mapa */
#mapa { height: 640px; border-radius: 6px; background: #eef0f2; }
.leyenda-mapa { display: flex; gap: 10px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-left: 8px; }
.leyenda-mapa i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: -1px; }
.popup { font-size: 13px; line-height: 1.5; min-width: 220px; }
.popup .muted { font-size: 12px; }
.swatch { display: inline-block; width: 11px; height: 11px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.25); }
@media (max-width: 760px) { #mapa { height: 460px; } }

.chart .ax.eti { fill: var(--text); font-size: 11.5px; }
.chart .ax.val { fill: var(--muted); font-size: 11px; }
.chart .seg { cursor: crosshair; }
.chart .seg:hover { opacity: .85; }
.leyenda i { border-radius: 2px; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; }
.chart.mapa { max-height: 520px; }
.chart .prov { stroke: #fff; stroke-width: .8; stroke-linejoin: round; cursor: pointer; }
.chart .prov:hover { stroke: var(--text); stroke-width: 1.5; }
.chart .prov.fondo { fill: #eceef1; cursor: default; }
.chart .prov.fondo:hover { stroke: #fff; stroke-width: .8; }
.chart .recuadro { fill: none; stroke: #c9ced6; stroke-width: 1; stroke-dasharray: 3 3; }
.chart .burbuja { stroke: #fff; stroke-width: 1; opacity: .85; cursor: pointer; }
.chart .burbuja:hover { opacity: 1; stroke: var(--text); }
.fuente-mapa { font-size: 10.5px; color: var(--muted); margin-top: 2px; }
/* cruces y tablas visuales */
.cruce-wrap { overflow-x: auto; }
table.cruce td.hm { min-width: 62px; }
table.cruce td.eti, table.cruce th:first-child { position: sticky; left: 0; background: var(--panel); z-index: 1; white-space: nowrap; }
table.cruce .tot { background: #f6f7f9; font-weight: 600; }
table.cruce tfoot td { border-top: 2px solid var(--line2); }
td.celda-barra { position: relative; min-width: 90px; }
td.celda-barra .cb { position: absolute; left: 4px; top: 25%; height: 50%; background: #d7e7fb; border-radius: 0 3px 3px 0; max-width: calc(100% - 8px); }
td.celda-barra .cv { position: relative; }
td.tinte { transition: background .1s; }
.selector-cruce { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.presets { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0 12px; }
.mini-mapas { display: grid; grid-template-columns: repeat(auto-fit, minmax(460px, 1fr)); gap: 14px; }
@media (max-width: 760px) { .mini-mapas { grid-template-columns: 1fr; } }

/* menú agrupado */
.top nav.menu { overflow: visible; gap: 4px; }
.top .grupo-menu { position: relative; }
.top .grupo-menu > span { display: block; color: #cfd8e3; padding: 6px 10px; border-radius: 6px; cursor: pointer; white-space: nowrap; }
.top .grupo-menu.on > span, .top .grupo-menu:hover > span, .top .grupo-menu:focus-within > span { color: #fff; background: #23395a; }
.top .submenu { display: none; position: absolute; top: 100%; left: 0; min-width: 220px; background: var(--nav); border: 1px solid #33496a;
  border-radius: 8px; padding: 6px; box-shadow: 0 8px 24px rgba(0,0,0,.25); z-index: 50; }
.top .grupo-menu:hover .submenu, .top .grupo-menu:focus-within .submenu { display: block; }
.top .submenu a { display: block; padding: 7px 10px; }
@media (max-width: 760px) { .top nav.menu { flex-wrap: wrap; } .top .submenu { position: fixed; left: 10px; right: 10px; top: auto; } }

.seg-toggle { display: inline-flex; border: 1px solid var(--line2); border-radius: 8px; overflow: hidden; }
.seg-toggle a { padding: 6px 14px; text-decoration: none; color: var(--muted); font-size: 13px; background: #fff; }
.seg-toggle a + a { border-left: 1px solid var(--line2); }
.seg-toggle a.on { background: var(--accent); color: #fff; font-weight: 600; }
table.cruce.pulsable td.hm a, table.cruce.pulsable th a, table.cruce.pulsable td.eti a { color: inherit; text-decoration: none; display: block; }
table.cruce.pulsable td.hm:hover { outline: 2px solid var(--text); outline-offset: -2px; cursor: pointer; }
table.cruce .sel { outline: 2px solid #eb6834; outline-offset: -2px; }
.tabs { position: sticky; top: 48px; background: var(--bg); z-index: 20; padding-top: 4px; }
#mapa { scroll-margin-top: 64px; }

/* mapa de municipios */
.mapa-mun { position: relative; }
.mm-barra { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 6px; }
.mm-buscar { min-width: 260px; }
.mm-svg { max-height: var(--alto, 560px); cursor: grab; background: #fbfcfd; border-radius: 6px; }
.mm-svg:active { cursor: grabbing; }
.chart path.mun { stroke: #fff; stroke-width: .12; vector-effect: non-scaling-stroke; }
.chart path.mun:hover { stroke: var(--text); stroke-width: 1.2; }
.chart path.mun.marcado { stroke: #eb6834; stroke-width: 2.5; }
.chart .mm-prov path { fill: none; stroke: #6b7480; stroke-width: .7; vector-effect: non-scaling-stroke; pointer-events: none; }
.mm-ficha { position: absolute; right: 12px; top: 56px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: var(--shadow); padding: 10px 12px; font-size: 13px; line-height: 1.6; min-width: 220px; }
.mapa-mun:has(svg) .mm-cargando { display: none; }
