/* SMA ELECTORAL 2027 — diseño minimalista.
   Regla: la interfaz es neutra (grises + tinta); el color se reserva para los partidos. */
:root {
  --bg: #F6F6F4; --card: #FFFFFF; --card-2: #F1F1EF; --border: #E6E6E2; --border-strong: #D4D4CF;
  --text: #18181B; --text-2: #52525B; --muted: #8B8B93;
  --accent: #18181B; --accent-2: #3F3F46; --accent-soft: #EFEFEC;
  /* Partidos: colores institucionales (solo para datos). PRI rojo vs MORENA guinda bien separados en tono y brillo. */
  --pri: #E30613; --pan: #0057B8; --morena: #6E1A37; --alianza: #D6006F; --mc: #FF7A00;
  --pvem: #2E9E44; --pt: #B3261E; --prd: #F2C200; --na: #00A3A6; --pes: #5B2C83; --indep: #8A8A8A; --empate: #71717A;
  --ok: #2F855A; --ok-bg: #F0F7F3; --warn: #B7791F; --warn-bg: #FBF6EC; --bad: #C53030; --bad-bg: #FBF1F1;
  --shadow: 0 1px 2px rgba(24,24,27,.04);
  --r-sm: 8px; --r-md: 12px; --r-lg: 16px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111113; --card: #18181B; --card-2: #212124; --border: #2C2C30; --border-strong: #3A3A3F;
    --text: #F4F4F5; --text-2: #C4C4CA; --muted: #8B8B93; --accent: #F4F4F5; --accent-2: #D4D4D8; --accent-soft: #26262A;
    --pri: #FF4D4F; --pan: #4C8DFF; --morena: #C2557A; --alianza: #FF4FA3; --mc: #FF9533; --pvem: #4CC266; --pt: #E05A4F; --prd: #FFD43B;
    --ok: #68D391; --ok-bg: #16231C; --warn: #F6C454; --warn-bg: #272114; --bad: #FC8181; --bad-bg: #2A1717;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111113; --card: #18181B; --card-2: #212124; --border: #2C2C30; --border-strong: #3A3A3F;
  --text: #F4F4F5; --text-2: #C4C4CA; --muted: #8B8B93; --accent: #F4F4F5; --accent-2: #D4D4D8; --accent-soft: #26262A;
  --pri: #FF4D4F; --pan: #4C8DFF; --morena: #C2557A; --alianza: #FF4FA3; --mc: #FF9533; --pvem: #4CC266; --pt: #E05A4F; --prd: #FFD43B;
  --ok: #68D391; --ok-bg: #16231C; --warn: #F6C454; --warn-bg: #272114; --bad: #FC8181; --bad-bg: #2A1717;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5; min-height: 100vh; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--text); text-underline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.hidden { display: none !important; }

/* ---------- Layout ---------- */
.topbar { position: sticky; top: 0; z-index: 500; background: var(--card); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 1rem; padding: .55rem 1.25rem; }
.brand { display: flex; align-items: center; gap: .65rem; min-width: 0; }
.brand-badge { background: var(--text); color: var(--card); font-weight: 700; font-size: .75rem; padding: .3rem .5rem; border-radius: 6px; letter-spacing: .02em; white-space: nowrap; }
.brand-title { font-weight: 650; font-size: .92rem; letter-spacing: -.01em; white-space: nowrap; }
.brand-sub { font-size: .74rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .spacer { flex: 1; }
.user-chip { display: flex; align-items: center; gap: .5rem; font-size: .85rem; color: var(--text-2); }
.user-chip .rol { color: var(--muted); font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }

.shell { display: grid; grid-template-columns: 210px minmax(0, 1fr); min-height: calc(100vh - 53px); }
.sidenav { background: var(--bg); border-right: 1px solid var(--border); padding: 1rem .6rem; position: sticky; top: 53px; height: calc(100vh - 53px); overflow-y: auto; }
.sidenav .grupo { font-size: .68rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; margin: 1.1rem .65rem .3rem; }
.sidenav .grupo:first-child { margin-top: 0; }
.nav-btn { display: flex; align-items: center; gap: .6rem; width: 100%; text-align: left; background: none; border: 0; padding: .45rem .65rem; border-radius: 7px; cursor: pointer; color: var(--text-2); font-weight: 500; font-size: .9rem; }
.nav-btn:hover { background: var(--card-2); color: var(--text); }
.nav-btn.active { background: var(--card); color: var(--text); font-weight: 600; box-shadow: inset 0 0 0 1px var(--border); }
.nav-btn .ico { display: none; }
main.content { padding: 1.5rem 1.75rem 3rem; min-width: 0; max-width: 1400px; }
.view-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.view-head h1 { font-size: 1.4rem; font-weight: 700; letter-spacing: -.02em; }
.view-head p { color: var(--text-2); font-size: .9rem; max-width: 70ch; margin-top: .15rem; }

.menu-toggle { display: none; background: none; border: 1px solid var(--border); border-radius: var(--r-sm); padding: .35rem .6rem; cursor: pointer; }

/* ---------- Cards / grids ---------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--r-md); box-shadow: var(--shadow); padding: 1.15rem 1.25rem; min-width: 0; }
.card + .card { margin-top: 1rem; }
.card h2 { font-size: .98rem; font-weight: 650; margin-bottom: .15rem; letter-spacing: -.01em; }
.card h3 { font-size: .72rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 1.1rem 0 .5rem; }
.card .sub { color: var(--muted); font-size: .84rem; margin-bottom: .9rem; }
.grid { display: grid; gap: 1rem; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.mt { margin-top: 1rem; }

.kpi { background: var(--card); border: 1px solid var(--border); border-radius: var(--r-md); padding: .95rem 1.05rem; box-shadow: var(--shadow); position: relative; border-top-width: 1px !important; border-top-color: var(--border) !important; }
.kpi .lbl { font-size: .72rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.kpi .val { font-size: 1.6rem; font-weight: 700; letter-spacing: -.02em; margin-top: .2rem; font-variant-numeric: tabular-nums; color: var(--text) !important; }
.kpi .desc { font-size: .8rem; color: var(--muted); }
.kpi .info { position: absolute; top: .55rem; right: .55rem; }

/* ---------- Buttons / inputs ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; border: 1px solid var(--border-strong); background: var(--card); color: var(--text); padding: .48rem .9rem; border-radius: var(--r-sm); font-weight: 550; font-size: .86rem; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--card-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--card); }
.btn-primary:hover { background: var(--accent-2); }
.btn-ghost { background: none; border-color: transparent; color: var(--text-2); }
.btn-danger { color: var(--bad); }
.btn-sm { padding: .28rem .6rem; font-size: .8rem; }
.btn-lg { padding: .85rem 1.2rem; font-size: 1rem; }
.btn-info { border: 1px solid var(--border); background: var(--card); border-radius: 99px; width: 1.5rem; height: 1.5rem; font-size: .72rem; cursor: pointer; color: var(--muted); font-weight: 700; vertical-align: 1px; }
.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

.input, select.input, textarea.input { width: 100%; background: var(--card); border: 1px solid var(--border-strong); border-radius: var(--r-sm); padding: .52rem .7rem; }
.input:focus { outline: 2px solid var(--text); outline-offset: -1px; }
label.field { display: block; font-size: .8rem; font-weight: 550; color: var(--text-2); margin-bottom: .75rem; }
label.field .input { margin-top: .3rem; font-weight: 400; color: var(--text); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .25rem .75rem; }

/* Segmentado tipo "píldora": pista gris, opción activa blanca */
.seg { display: inline-flex; background: var(--card-2); border-radius: 9px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: none; padding: .38rem .75rem; font-weight: 550; font-size: .83rem; cursor: pointer; color: var(--text-2); border-radius: 7px; }
.seg button:hover { color: var(--text); }
.seg button.active { background: var(--card); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08), 0 0 0 1px var(--border); }

.chips { display: flex; gap: .4rem; flex-wrap: wrap; }
.chip { border: 1px solid var(--border); background: var(--card); border-radius: 99px; padding: .25rem .7rem; font-size: .8rem; font-weight: 550; cursor: pointer; color: var(--text-2); text-decoration: none; }
.chip.active { background: var(--text); color: var(--card); border-color: var(--text); }

/* ---------- Badges: punto de color + texto neutro ---------- */
.badge { display: inline-flex; align-items: center; gap: .35rem; font-size: .78rem; font-weight: 600; white-space: nowrap; color: var(--text); }
.badge::before { content: ""; width: .55rem; height: .55rem; border-radius: 50%; background: var(--muted); flex: none; }
.b-PRI::before { background: var(--pri); } .b-PAN::before { background: var(--pan); } .b-MORENA::before { background: var(--morena); }
.b-ALIANZA::before { background: var(--alianza); } .b-MC::before { background: var(--mc); }
.b-PVEM::before { background: var(--pvem); } .b-PT::before { background: var(--pt); } .b-PRD::before { background: var(--prd); }
.b-NA::before { background: var(--na); } .b-PES::before { background: var(--pes); } .b-INDEP::before { background: var(--indep); }
.b-ok::before { background: var(--ok); } .b-warn::before { background: var(--warn); } .b-bad::before { background: var(--bad); }
.b-bad { color: var(--bad); }
.dot { display: inline-block; width: .6rem; height: .6rem; border-radius: 50%; }
.sem-VERDE { background: var(--ok); } .sem-AMARILLO { background: var(--warn); } .sem-ROJO { background: var(--bad); } .sem-GRIS { background: var(--border-strong); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--r-sm); }
table.data { width: 100%; border-collapse: collapse; font-size: .85rem; }
table.data th { text-align: left; background: var(--card); color: var(--muted); font-weight: 600; font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; padding: .55rem .75rem; border-bottom: 1px solid var(--border); white-space: nowrap; position: sticky; top: 0; z-index: 1; }
table.data td { padding: .5rem .75rem; border-bottom: 1px solid var(--border); font-variant-numeric: tabular-nums; vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data tr.click { cursor: pointer; }
table.data tr.click:hover td { background: var(--card-2); }
table.data td.r, table.data th.r { text-align: right; }
.scroll-y { max-height: 480px; overflow-y: auto; }

/* ---------- Explorer ---------- */
.explorer { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 1rem; align-items: start; }
.sec-list { max-height: calc(100vh - 230px); overflow-y: auto; margin: 0 -1.25rem -1.15rem; border-top: 1px solid var(--border); }
.sec-item { padding: .65rem 1.25rem; border-bottom: 1px solid var(--border); cursor: pointer; }
.sec-item:hover { background: var(--card-2); }
.sec-item.sel { background: var(--card-2); box-shadow: inset 3px 0 0 var(--text); }
.sec-item .top { display: flex; justify-content: space-between; gap: .5rem; align-items: center; }
.sec-item .n { font-weight: 650; }
.sec-item .com { font-size: .78rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.votebar { display: flex; height: 10px; border-radius: 99px; overflow: hidden; background: var(--card-2); }
.votebar span { display: block; height: 100%; }
.vote-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: .6rem; }
.vbox { border: 1px solid var(--border); border-radius: var(--r-sm); padding: .6rem .75rem; background: var(--card); }
.vbox .p { font-size: .72rem; font-weight: 600; letter-spacing: .03em; color: var(--text-2) !important; display: flex; align-items: center; gap: .35rem; }
.vbox .v { font-size: 1.3rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.vbox .pct { font-size: .75rem; color: var(--muted); }

.diag { display: flex; gap: .8rem; padding: .85rem 1rem; border-radius: var(--r-sm); border: 1px solid var(--border); border-left: 3px solid var(--muted); margin: .9rem 0; background: var(--card); }
.diag.ok { border-left-color: var(--ok); }
.diag.warn { border-left-color: var(--warn); }
.diag.bad { border-left-color: var(--bad); }
.diag > div:first-child:not(:only-child) { display: none; } /* sin íconos decorativos */
.diag .t { font-weight: 650; margin-bottom: .15rem; }
.diag .d { font-size: .87rem; color: var(--text-2); }

/* ---------- Sliders ---------- */
.sliders { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1rem 1.5rem; }
.slider label { display: flex; justify-content: space-between; gap: .5rem; font-weight: 550; font-size: .85rem; }
.slider label b { font-variant-numeric: tabular-nums; color: var(--text); font-weight: 650; }
.slider input[type=range] { width: 100%; accent-color: var(--text); margin: .35rem 0 .1rem; }
.slider .h { font-size: .75rem; color: var(--muted); }

/* ---------- Charts (SVG propio) ---------- */
.chart { width: 100%; }
.chart text { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .axis { stroke: var(--border); }
.legend { display: flex; gap: .9rem; flex-wrap: wrap; font-size: .78rem; color: var(--text-2); margin-top: .35rem; align-items: center; }
.legend i { display: inline-block; width: .65rem; height: .65rem; border-radius: 50%; margin-right: .35rem; vertical-align: -1px; }

/* ---------- Mapa ---------- */
.mapa-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 1rem; align-items: start; }
.mapa-wrap { position: relative; border-radius: var(--r-md); overflow: hidden; border: 1px solid var(--border); background: var(--card-2); }
#mapa-leaflet { height: calc(100vh - 215px); min-height: 440px; }
.mapa-side { display: flex; flex-direction: column; gap: 1rem; }
.mapa-side .card { padding: 1rem 1.05rem; }
.ley-fila { display: flex; align-items: center; justify-content: space-between; padding: .35rem 0; font-size: .88rem; }
.ley-fila .sw { display: inline-flex; gap: 2px; margin-right: .5rem; }
.ley-fila .sw i { width: .7rem; height: .9rem; border-radius: 2px; display: inline-block; }
.ley-fila b { font-variant-numeric: tabular-nums; }
.mapa-bar { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; justify-content: space-between; margin-bottom: .9rem; }
.leaflet-container { font-family: var(--font) !important; background: var(--card-2) !important; }
.osm-gris { filter: grayscale(1) contrast(.9) brightness(1.05); }
/* Nombres de colonias y comunidades: aparecen al acercar el mapa para no saturarlo */
.leaflet-tooltip.lbl-mapa { background: none; border: 0; box-shadow: none; padding: 0; color: var(--text); font-size: .68rem; font-weight: 600;
  text-shadow: 0 0 3px var(--card), 0 0 3px var(--card), 0 0 2px var(--card); white-space: nowrap; display: none; pointer-events: none; }
.leaflet-tooltip.lbl-mapa::before { display: none; }
.ver-colonias .leaflet-tooltip.lbl-colonia, .ver-comunidades .leaflet-tooltip.lbl-comunidad { display: block; }
.leaflet-tooltip.lbl-colonia { font-weight: 500; color: var(--text-2); }
.chk { display: flex; gap: .4rem; align-items: center; color: var(--text-2); cursor: pointer; }
.relato { font-size: .87rem; color: var(--text-2); }
.relato p { margin: 0 0 .55rem; }
.relato .lead { color: var(--text); font-size: .93rem; }
.relato ul { padding-left: 0; list-style: none; margin: 0 0 .55rem; }
.relato li { margin: .35rem 0; }
.relato .ojo { border-left: 3px solid var(--warn); padding-left: .6rem; color: var(--text); }
.leaflet-tooltip.tt { background: var(--card); color: var(--text); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 4px 14px rgba(0,0,0,.12); padding: .45rem .6rem; font-size: .8rem; }
.leaflet-tooltip.tt::before { display: none; }
.tile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(58px, 1fr)); gap: 3px; }
.tile { aspect-ratio: 1.15; border-radius: 5px; display: flex; flex-direction: column; align-items: center; justify-content: center; color: #fff; font-weight: 650; font-size: .8rem; cursor: pointer; position: relative; }
.tile small { font-size: .62rem; font-weight: 500; opacity: .9; }
.tile:hover { outline: 2px solid var(--text); }

/* ---------- Ayuda de cada pantalla ---------- */
.ayuda { margin-bottom: 1rem; background: var(--card); border: 1px solid var(--border); border-radius: var(--r-md); padding: .65rem 1rem; font-size: .88rem; color: var(--text-2); }
.ayuda summary { cursor: pointer; font-weight: 600; color: var(--text); font-size: .85rem; list-style: none; display: flex; align-items: center; gap: .45rem; }
.ayuda summary::-webkit-details-marker { display: none; }
.ayuda summary::before { content: "?"; display: inline-grid; place-items: center; width: 1.15rem; height: 1.15rem; border-radius: 50%; border: 1px solid var(--border-strong); font-size: .7rem; color: var(--muted); }
.ayuda[open] summary { margin-bottom: .55rem; }
.ayuda p { color: var(--text); margin-bottom: .35rem; }
.ayuda ul { padding-left: 1.1rem; margin: .2rem 0 .4rem; }
.ayuda li { margin: .15rem 0; }
.ayuda dl { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: .5rem 1.25rem; margin-top: .6rem; padding-top: .6rem; border-top: 1px solid var(--border); }
.ayuda dt { font-weight: 600; color: var(--text); font-size: .82rem; }
.ayuda dd { font-size: .8rem; }

/* ---------- ¿Qué pasó con los votos? ---------- */
details.flujo { border: 1px solid var(--border); border-radius: var(--r-sm); padding: .6rem .85rem; margin-bottom: .5rem; background: var(--card); }
details.flujo summary { cursor: pointer; display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
details.flujo[open] summary { margin-bottom: .5rem; }
details.flujo .ctx { font-size: .84rem; color: var(--text-2); border-left: 3px solid var(--border-strong); padding-left: .6rem; margin-bottom: .5rem; }
details.flujo ul { padding-left: 1.1rem; font-size: .87rem; }
details.flujo li { margin: .3rem 0; }

/* ---------- Pestañas ---------- */
.tabs { display: flex; gap: 1.25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: .55rem 0; font-weight: 550; font-size: .88rem; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button.active { color: var(--text); border-bottom-color: var(--text); }

/* ---------- Laboratorio en dos columnas ---------- */
.lab { display: grid; grid-template-columns: 330px minmax(0, 1fr); gap: 1rem; align-items: start; }
.lab-ctrl { position: sticky; top: 70px; max-height: calc(100vh - 85px); overflow-y: auto; }
.lab-ctrl .sliders { grid-template-columns: 1fr; gap: 1rem; }
.lab-ctrl .seg { display: flex; flex-wrap: nowrap; width: 100%; }
.lab-ctrl .seg button { flex: 1; padding: .38rem .3rem; white-space: nowrap; }
.lab-ctrl h3:first-child { margin-top: 0; }
.headline { font-size: 1.35rem; font-weight: 700; letter-spacing: -.02em; display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.headline .sw { width: .8rem; height: .8rem; border-radius: 50%; display: inline-block; }
details.mas { margin-top: 1rem; border-top: 1px solid var(--border); padding-top: .8rem; }
details.mas summary { cursor: pointer; font-size: .85rem; font-weight: 550; color: var(--text-2); }
details.mas[open] summary { margin-bottom: .9rem; }

/* ---------- Bingo ---------- */
.prom-item { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .7rem .2rem; border-bottom: 1px solid var(--border); }
.prom-item .nm { font-weight: 600; }
.estado-btns { display: flex; gap: .35rem; }
.estado-btns .btn { min-width: 44px; min-height: 40px; }
.estado-btns .btn.on-VOTO { background: var(--ok); color: #fff; border-color: var(--ok); }
.estado-btns .btn.on-NO_ASISTIO { background: var(--bad); color: #fff; border-color: var(--bad); }
.progress { height: 8px; background: var(--card-2); border-radius: 99px; overflow: hidden; position: relative; }
.progress > span { display: block; height: 100%; background: var(--text); }
.progress > i { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--bad); }

/* ---------- Chat ---------- */
.chat { display: flex; flex-direction: column; gap: .75rem; max-height: 60vh; overflow-y: auto; padding: .25rem; }
.msg { padding: .75rem .9rem; border-radius: var(--r-md); max-width: 85%; white-space: pre-wrap; font-size: .9rem; }
.msg.yo { background: var(--text); color: var(--card); align-self: flex-end; }
.msg.ia { background: var(--card-2); display: flex; gap: .6rem; align-items: flex-start; }
.msg.ia .msg-txt { flex: 1; }
.msg-pie { margin-top: .5rem; padding-top: .45rem; border-top: 1px solid var(--border); white-space: normal; }
.btn-voz { flex: none; display: inline-grid; place-items: center; width: 2rem; height: 2rem; border-radius: 50%; border: 1px solid var(--border);
  background: var(--card); color: var(--text-2); cursor: pointer; margin-top: -.15rem; }
.btn-voz:hover { color: var(--text); border-color: var(--border-strong); }
.btn-voz.sonando { background: var(--text); color: var(--card); border-color: var(--text); }
.btn-voz .spinner { width: .8rem; height: .8rem; }

/* ---------- Modal / toast ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(17,17,19,.5); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 1rem; }
.modal { background: var(--card); border-radius: var(--r-lg); max-width: 680px; width: 100%; max-height: 90vh; overflow-y: auto; padding: 1.4rem; box-shadow: 0 20px 50px rgba(0,0,0,.2); }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: .8rem; }
.modal-head h2 { font-size: 1.05rem; font-weight: 650; }
.formula { background: var(--card-2); border-radius: var(--r-sm); padding: .55rem .75rem; font-family: var(--mono); font-size: .82rem; margin: .35rem 0 .7rem; overflow-x: auto; }
#toast { position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--card); padding: .65rem 1rem; border-radius: var(--r-sm); font-weight: 550; font-size: .87rem; z-index: 1100; box-shadow: 0 8px 24px rgba(0,0,0,.18); max-width: calc(100% - 2rem); }
#toast.err { background: var(--bad); color: #fff; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem; background: var(--bg); }
.login-card { width: 100%; max-width: 380px; }
.login-card .brand { margin-bottom: 1.25rem; }
.alert { padding: .65rem .8rem; border-radius: var(--r-sm); font-size: .87rem; margin-bottom: .8rem; }
.alert.err { background: var(--bad-bg); color: var(--bad); }
.alert.info { background: var(--card-2); color: var(--text-2); }

.empty { text-align: center; padding: 2rem 1rem; color: var(--muted); }
.spinner { display: inline-block; width: 1rem; height: 1rem; border: 2px solid var(--border-strong); border-top-color: var(--text); border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Panel "¿Cómo se calculó?" */
.fundamento { margin-top: .9rem; border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--card); padding: .55rem .8rem; }
.fundamento summary { cursor: pointer; font-weight: 550; color: var(--text-2); font-size: .88rem; }
.fundamento h4 { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: .9rem 0 .35rem; font-weight: 600; }
.fundamento ul { margin: 0; padding-left: 1.1rem; font-size: .86rem; color: var(--text-2); }
.fundamento li { margin: .2rem 0; }
.fundamento code { white-space: normal; font-size: .8rem; }
.fundamento [class^="tag-"] { font-size: .7rem; font-weight: 600; white-space: nowrap; display: inline-flex; align-items: center; gap: .3rem; }
.fundamento [class^="tag-"]::before { content: ""; width: .5rem; height: .5rem; border-radius: 50%; }
.fundamento .tag-ok::before { background: var(--ok); } .fundamento .tag-warn::before { background: var(--warn); } .fundamento .tag-bad::before { background: var(--bad); }

/* Indicador de conexión / pendientes (web-app sin internet) */
.net { display: inline-flex; align-items: center; gap: .4rem; border: 1px solid var(--border); background: var(--card); color: var(--text-2);
  border-radius: 99px; padding: .18rem .6rem; font-size: .74rem; font-weight: 550; cursor: pointer; white-space: nowrap; }
.net .pt { width: .5rem; height: .5rem; border-radius: 50%; background: var(--ok); }
.net.off { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.net.off .pt { background: var(--warn); }
.pend { font-size: .7rem; font-weight: 600; color: var(--warn); background: var(--warn-bg); border-radius: 99px; padding: .05rem .45rem; margin-left: .35rem; }

/* ---------- Responsive ---------- */
@media (max-width: 1200px) {
  .mapa-layout { grid-template-columns: 1fr; }
  #mapa-leaflet { height: 62vh; }
  .mapa-side { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
}
@media (max-width: 1100px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .explorer, .lab { grid-template-columns: 1fr; }
  .lab-ctrl { position: static; max-height: none; }
  .sec-list { max-height: 300px; }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidenav { position: fixed; left: 0; top: 53px; width: 250px; z-index: 600; transform: translateX(-100%); transition: transform .2s; background: var(--card); box-shadow: 0 10px 30px rgba(0,0,0,.12); }
  .sidenav.open { transform: none; }
  .menu-toggle { display: inline-block; }
  .g2, .g3 { grid-template-columns: 1fr; }
  main.content { padding: 1rem 16px 3rem; }
  .brand-sub, .user-chip .nm, .brand-title { display: none; }
}
@media (max-width: 520px) {
  .g4 { grid-template-columns: 1fr 1fr; }
  .kpi .val { font-size: 1.3rem; }
  .topbar { padding: .5rem 16px; gap: .5rem; }
  .net { font-size: .68rem; padding: .15rem .5rem; }
}
