/* =====================================================================
   Analitix · estilos
   Sin estilos en línea (CSP style-src 'self').
   ===================================================================== */

@font-face { font-family: "Inter"; font-style: normal; font-weight: 400; font-display: swap; src: url("../fonts/inter-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Inter"; font-style: normal; font-weight: 500; font-display: swap; src: url("../fonts/inter-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "Inter"; font-style: normal; font-weight: 600; font-display: swap; src: url("../fonts/inter-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "Inter"; font-style: normal; font-weight: 700; font-display: swap; src: url("../fonts/inter-latin-700-normal.woff2") format("woff2"); }
@font-face { font-family: "Inter"; font-style: normal; font-weight: 800; font-display: swap; src: url("../fonts/inter-latin-800-normal.woff2") format("woff2"); }

:root {
    --bg: #f1f3f8;
    --surface: #ffffff;
    --surface-2: #f7f8fc;
    --border: #e3e6ef;
    --border-strong: #cfd4e2;
    --text: #0f172a;
    --text-2: #475569;
    --muted: #64748b;
    --brand-900: #1e1b4b;
    --brand-800: #272463;
    --brand-700: #312e81;
    --brand-600: #3730a3;
    --brand-500: #4f46e5;
    --brand-100: #e0e7ff;
    --brand-50: #eef2ff;
    --select: #ea580c;
    --radius: 14px;
    --radius-sm: 9px;
    --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 1px 1px rgba(15, 23, 42, .03);
    --shadow-hover: 0 6px 20px rgba(30, 27, 75, .10);
    --font: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
    --page-max: 1440px;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

[hidden] { display: none !important; }
img { max-width: 100%; display: block; }
button, select, input { font: inherit; color: inherit; }
a { color: var(--brand-600); }

.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.skip-link {
    position: absolute; left: 12px; top: -48px; z-index: 100;
    background: #fff; color: var(--brand-700); padding: 8px 14px; border-radius: 8px;
    font-weight: 600; text-decoration: none; box-shadow: var(--shadow-hover);
}
.skip-link:focus { top: 12px; }

:focus-visible { outline: 3px solid #818cf8; outline-offset: 2px; }

/* ----------------------------------------------------------- cabecera */

.topbar {
    background: linear-gradient(100deg, #1c1a4a 0%, #272463 45%, #34319a 100%);
    color: #fff;
}
.topbar__inner {
    max-width: var(--page-max);
    margin: 0 auto;
    padding: 18px 28px;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 28px;
}
.topbar__logo { height: 46px; width: auto; }
.topbar__logo--left { height: 54px; }
.topbar__logo--right { height: auto; max-height: 28px; max-width: 280px; justify-self: end; }
.topbar__titles { min-width: 0; text-align: center; }
.topbar__title {
    margin: 0;
    font-size: clamp(20px, 2.2vw, 28px);
    font-weight: 800;
    letter-spacing: -.01em;
    line-height: 1.2;
}
.topbar__subtitle {
    margin: 4px 0 0;
    color: #c7cbf1;
    font-size: 14px;
    display: flex; flex-wrap: wrap; gap: 6px 10px; justify-content: center; align-items: center;
}

.badge {
    display: inline-flex; align-items: center;
    border-radius: 999px; padding: 2px 10px;
    font-size: 11.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
    white-space: nowrap;
}
.badge--mock { background: #fbbf24; color: #3b2601; }

/* ----------------------------------------------------------- pestañas */

/* Pestañas + filtros fijos arriba al hacer scroll (teléfono y computadora). */
.sticky-bar {
    position: sticky; top: 0; z-index: 30;
    background: var(--surface);
    box-shadow: 0 2px 10px rgba(15, 23, 42, .07);
}
.tabs {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.tabs__inner {
    max-width: var(--page-max);
    margin: 0 auto;
    padding: 0 16px;
    display: flex;
    overflow-x: auto;
    scrollbar-width: none;
}
.tabs__inner::-webkit-scrollbar { display: none; }
.tabs__item {
    flex: none;
    padding: 16px 18px 14px;
    color: var(--text-2);
    text-decoration: none;
    font-weight: 500;
    font-size: 15.5px;
    border-bottom: 3px solid transparent;
    transition: color .15s, border-color .15s, background-color .15s;
}
.tabs__item:hover { color: var(--brand-600); background: var(--surface-2); }
.tabs__item[aria-selected="true"] {
    color: var(--brand-600);
    font-weight: 600;
    border-bottom-color: var(--brand-600);
}

/* ----------------------------------------------------------- página */

.page {
    flex: 1;
    width: 100%;
    max-width: var(--page-max);
    margin: 0 auto;
    padding: 22px 28px 40px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

/* ----------------------------------------------------------- filtros */

.filters { background: var(--surface-2); border-bottom: 1px solid var(--border); }
.filters__inner {
    max-width: var(--page-max); margin: 0 auto;
    display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px;
    padding: 10px 28px;
}
.field__caption { font-size: 12px; font-weight: 600; color: var(--text-2); align-self: center; margin-right: 8px; white-space: nowrap; }
.field--pregunta { align-items: center; margin-left: auto; }
.field--pregunta .select { min-width: 250px; border-color: #a5b4fc; background-color: var(--brand-50); font-weight: 600; color: var(--brand-700); }
.filters__label { color: var(--text-2); font-weight: 500; }
.field { display: inline-flex; }
.select {
    appearance: none;
    min-width: 210px;
    padding: 8px 40px 8px 14px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%23334155' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 14px center;
    cursor: pointer;
    transition: border-color .15s, box-shadow .15s;
}
.select:hover { border-color: #a5b4fc; }
.select:focus-visible { outline: none; border-color: var(--brand-500); box-shadow: 0 0 0 3px rgba(79, 70, 229, .2); }
.select:disabled { opacity: .6; cursor: wait; }

.btn {
    border: 1px solid transparent; border-radius: var(--radius-sm);
    padding: 8px 14px; cursor: pointer; font-weight: 500;
    display: inline-flex; align-items: center; gap: 6px;
    text-decoration: none;
}
.btn--ghost { background: transparent; color: var(--brand-600); }
.btn--ghost:hover { background: var(--brand-50); }
.btn--outline { background: #fff; border-color: var(--border-strong); color: var(--text); }
.btn--outline:hover { border-color: #a5b4fc; color: var(--brand-600); }

.filters__summary {
    margin: 0 0 0 auto;
    color: var(--muted);
    font-size: 14px;
    text-align: right;
}
.filters__summary strong { color: var(--text); font-weight: 600; }

/* ----------------------------------------------------------- vistas */

.view { outline: none; transition: opacity .2s; }
.view > .source { margin: -6px 0 14px; }
.view.is-loading { opacity: .55; pointer-events: none; }

.view > .card + .card { margin-top: 20px; }
.section-head { margin: 0 0 16px; display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.section-head h2 { margin: 0; font-size: 21px; font-weight: 700; letter-spacing: -.01em; }
.section-head p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }

.panel { padding: 20px 22px 18px; min-width: 0; display: flex; flex-direction: column; }
.panel__title { margin: 0; font-size: 16.5px; font-weight: 700; }
.panel__subtitle { margin: 2px 0 12px; color: var(--muted); font-size: 13.5px; }
.panel__body { position: relative; flex: 1; min-height: 0; }
.chart-box { position: relative; height: 300px; }
.chart-box--tall { height: 380px; }
.chart-box--sim { height: 430px; }
.chart-box--scatter { height: 420px; }
.chart-scroll { overflow-x: auto; overscroll-behavior-x: contain; }

/* Pantalla dividida: columna izquierda (mapa + gráfico) y derecha (gráficos/tabla) */
.split {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px;
    align-items: start;
}
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.grid-full { grid-column: 1 / -1; }
.stack { display: grid; gap: 20px; }

/* ----------------------------------------------------------- mapa */

.map { width: 100%; height: auto; display: block; overflow: visible; }
.map__province {
    stroke: #ffffff; stroke-width: 1.2; stroke-linejoin: round;
    cursor: pointer;
    transition: opacity .2s, fill .3s;
}
.map__province:hover { stroke: var(--brand-900); stroke-width: 2; }
.map__province:focus { outline: none; }
.map__province:focus-visible { stroke: var(--brand-900); stroke-width: 2.6; }
.map__province.is-dimmed { opacity: .28; }
.map__province.is-selected { stroke: var(--select); stroke-width: 3.2; }
.map__province.is-nodata { fill: #e5e7eb; }

.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; margin-top: 12px; font-size: 12.5px; color: var(--text-2); }
.legend__ramp { display: flex; align-items: center; gap: 0; }
.legend__swatch { width: 34px; height: 10px; }
.legend__swatch:first-child { border-radius: 3px 0 0 3px; }
.legend__swatch:last-child { border-radius: 0 3px 3px 0; }
.legend__labels { display: flex; justify-content: space-between; width: 170px; font-variant-numeric: tabular-nums; }
.legend__note { color: var(--muted); }
.legend__sel { display: inline-flex; align-items: center; gap: 6px; }
.legend__sel::before { content: ""; width: 14px; height: 10px; border: 2.5px solid var(--select); border-radius: 3px; }

.map-hint { margin: 10px 0 0; color: var(--muted); font-size: 12.5px; }

.tooltip {
    position: fixed; z-index: 50; pointer-events: none;
    background: #111827; color: #fff;
    padding: 8px 12px; border-radius: 8px;
    font-size: 13px; line-height: 1.35;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .2);
    max-width: 240px;
}
.tooltip strong { display: block; font-weight: 600; }
.tooltip span { color: #cbd5e1; }

/* ----------------------------------------------------------- KPIs */

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; }
.kpi { padding: 14px 16px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); }
.kpi__label { color: var(--muted); font-size: 13px; font-weight: 500; }
.kpi__value { font-size: 28px; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.2; }
.kpi__note { color: var(--muted); font-size: 12px; }

/* ----------------------------------------------------------- radar */

.party { padding: 18px 20px 20px; border-top: 4px solid var(--party, var(--brand-600)); }
.party__head { display: flex; align-items: baseline; gap: 10px; margin: 0 0 14px; }
.party__name { margin: 0; font-size: 16px; font-weight: 700; }
.party__count { color: var(--muted); font-size: 13px; }
.parties { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; margin-top: 20px; }

.cand-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.cand {
    display: grid; grid-template-columns: 64px 1fr; gap: 6px 14px; align-items: center;
    padding: 14px; border-radius: 12px; border: 1px solid var(--border);
    background: #fff; color: inherit; text-decoration: none; text-align: left;
    cursor: pointer; transition: box-shadow .15s, border-color .15s, transform .15s;
}
.cand:hover { box-shadow: var(--shadow-hover); border-color: #c7d2fe; transform: translateY(-1px); }
.cand__photo {
    width: 64px; height: 64px; border-radius: 50%; object-fit: cover;
    border: 3px solid var(--cand, #94a3b8);
    background: #e5e7eb;
}
.cand__name { font-weight: 700; font-size: 15px; line-height: 1.25; }
.cand__party { color: var(--muted); font-size: 12.5px; }
.cand__bars { grid-column: 1 / -1; display: grid; gap: 7px; margin-top: 6px; }
.cand__cta { grid-column: 1 / -1; color: var(--brand-600); font-size: 13px; font-weight: 600; margin-top: 2px; }

.meter { display: grid; grid-template-columns: 92px 1fr 48px; align-items: center; gap: 8px; font-size: 12.5px; }
.meter__label { color: var(--text-2); }
.meter__track { height: 8px; border-radius: 99px; background: #eef0f5; overflow: hidden; }
.meter__fill { height: 100%; border-radius: 99px; background: var(--cand, var(--brand-500)); width: 0; transition: width .5s ease; }
.meter__fill--soft { opacity: .55; }
.meter__value { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }

.back { margin-bottom: 14px; }
.profile { display: grid; grid-template-columns: auto 1fr; gap: 22px; align-items: center; padding: 22px; }
.profile__photo { width: 112px; height: 112px; border-radius: 50%; border: 4px solid var(--cand, #94a3b8); object-fit: cover; }
.profile__name { margin: 0; font-size: 24px; font-weight: 800; letter-spacing: -.01em; }
.profile__party { margin: 2px 0 14px; color: var(--text-2); display: flex; align-items: center; gap: 8px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; background: var(--party, #94a3b8); }

/* ----------------------------------------------------------- tablas */

.table-wrap { overflow-x: auto; margin: 0 -4px; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table caption { text-align: left; color: var(--muted); font-size: 13px; padding: 0 4px 8px; caption-side: top; }
.table th {
    text-align: left; font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
    color: var(--text-2); padding: 10px 10px; border-bottom: 1.5px solid var(--border-strong); white-space: nowrap;
}
.table td { padding: 10px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table th.num { text-align: right; }
.table tbody tr:hover td { background: var(--surface-2); }
.table tr.is-group td { background: var(--brand-50); font-weight: 700; }
.table tr.is-group:hover td { background: #e5e9ff; }
.table tr.is-child td:first-child { padding-left: 26px; }
.table tr.is-highlight td { background: #fff7ed; }
.table tbody th { text-align: left; text-transform: none; letter-spacing: 0; font-size: 14px; font-weight: 600; color: var(--text); border-bottom: 1px solid var(--border); white-space: normal; }
.table tfoot td { font-weight: 700; border-top: 1.5px solid var(--border-strong); border-bottom: 0; }
.table .heat { border-radius: 6px; padding: 4px 7px; display: inline-block; white-space: nowrap; font-variant-numeric: tabular-nums; }
.table td.num { white-space: nowrap; }

.cell-bar { display: grid; grid-template-columns: 1fr 62px; white-space: nowrap; align-items: center; gap: 10px; min-width: 170px; }
.cell-bar__track { height: 8px; background: #eef0f5; border-radius: 99px; overflow: hidden; }
.cell-bar__fill { height: 100%; background: var(--cand, var(--brand-500)); border-radius: 99px; }
.cell-bar__fill--soft { opacity: .55; }

/* ----------------------------------------------------------- simulación */

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 0; }
.chip {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 5px 12px 5px 5px; border-radius: 999px;
    border: 1px solid var(--border-strong); background: #fff; cursor: pointer;
    font-size: 13.5px; font-weight: 500; transition: border-color .15s, background-color .15s;
}
.chip img { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--cand, #94a3b8); }
.chip:hover { border-color: #a5b4fc; }
.chip[aria-pressed="true"] { border-color: var(--brand-600); background: var(--brand-50); color: var(--brand-700); font-weight: 600; }

.detail { margin-top: 20px; }
.detail__head { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.detail__photo { width: 54px; height: 54px; border-radius: 50%; border: 3px solid var(--cand, #94a3b8); }
.detail__title { margin: 0; font-size: 17px; font-weight: 700; }
.detail__sub { margin: 0; color: var(--muted); font-size: 13.5px; }

.source { margin: -4px 0 12px; color: var(--muted); font-size: 13px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.badge--live { background: #dcfce7; color: #14532d; }
.notice { margin: 0 0 12px; padding: 8px 12px; border-radius: 8px; background: #fff7ed; color: #9a3412; font-size: 13.5px; }
.cell-n { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; font-weight: 400; }
.cell-n--small { color: #b45309; }
.footnote { margin: 10px 0 0; color: var(--muted); font-size: 12.5px; }
.detail__close { margin-left: auto; }
.empty {
    padding: 28px; text-align: center; color: var(--muted);
    border: 1.5px dashed var(--border-strong); border-radius: 12px; background: var(--surface-2);
}

/* ----------------------------------------------------------- estados */

.skeleton { position: relative; overflow: hidden; background: #e9ecf3; border-color: transparent; }
.skeleton::after {
    content: ""; position: absolute; inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .55), transparent);
    transform: translateX(-100%);
    animation: shimmer 1.3s infinite;
}
.skeleton--hero { height: 520px; }
@keyframes shimmer { to { transform: translateX(100%); } }

.alert { padding: 22px; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.alert p { margin: 0; color: var(--text-2); }

/* ----------------------------------------------------------- pie */

.footer {
    max-width: var(--page-max); width: 100%; margin: 0 auto;
    padding: 0 28px 32px; color: var(--text-2); font-size: 13px;
}
.footer p { margin: 2px 0; }
.footer__muted { color: var(--muted); }
.noscript { padding: 20px; text-align: center; }

/* ----------------------------------------------------------- responsive */

/* ----------------------------------------------------------- v2: secciones 1, 2 y 5 */

.dash-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; align-items: start; }
.muted { color: var(--muted); }

.cand-grid--wide { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.cand-panel { margin-top: 20px; }
.cand-grid--wide .cand { grid-template-columns: 56px 1fr; }
.cand-grid--wide .cand__photo { width: 56px; height: 56px; }

.kpis--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.kpis--5 { grid-template-columns: repeat(5, minmax(0, 1fr)); margin-bottom: 20px; padding: 16px; }
.kpi--accent { background: #fff4e6; border-color: #f6c28b; }
.kpi--accent .kpi__label { color: #9a3412; font-weight: 600; }
.kpi--accent .kpi__value { color: #c2410c; }
.kpi--accent .kpi__note { color: #9a3412; }
.kpi__value--sm { font-size: 18px; font-weight: 700; padding: 6px 0 4px; }

.radar-split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; margin-top: 20px; }
.detail-panel { scroll-margin-top: 130px; }
.detail-charts { display: grid; grid-template-columns: minmax(0, .8fr) minmax(0, 1.2fr); gap: 16px; align-items: start; }
.mini-title { margin: 14px 0 6px; font-size: 13px; font-weight: 700; color: var(--text-2); text-transform: uppercase; letter-spacing: .05em; }
.detail-charts .mini-title { margin-top: 4px; }
.chart-box--pie-sm { height: 220px; }
.chart-box--scale { height: 220px; }

.table--matrix tr.is-clickable { cursor: pointer; }
.table--matrix tr.is-selected td { background: #fff7ed !important; box-shadow: inset 0 0 0 0 transparent; }
.table--matrix tr.is-selected td:first-child { box-shadow: inset 4px 0 0 var(--select); }
.row-btn {
    background: none; border: 0; padding: 0; cursor: pointer; text-align: left;
    font: inherit; font-weight: inherit; color: var(--text);
}
.row-btn:hover { color: var(--brand-600); text-decoration: underline; }
.table--matrix .cell-n { display: block; }

.table--seg { font-size: 13.5px; }
.table--seg th, .table--seg td { padding: 7px 6px; }
.table--seg .th-group { text-align: center; border-bottom: 1px solid var(--border); }
.table--seg tr.is-total th, .table--seg tr.is-total td { border-top: 1.5px solid var(--border-strong); }
.pchip { display: inline-block; min-width: 58px; text-align: right; padding: 3px 7px; border-radius: 6px; font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.pchip--empty { background: transparent; color: var(--muted); font-weight: 400; }

.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; margin: 0 0 12px; }
.seg__btn { border: 0; background: #fff; padding: 7px 12px; cursor: pointer; font-size: 13.5px; font-weight: 500; color: var(--text-2); }
.seg__btn + .seg__btn { border-left: 1px solid var(--border-strong); }
.seg__btn[aria-pressed="true"] { background: var(--brand-50); color: var(--brand-700); font-weight: 600; }

.map__points { pointer-events: none; }
.map__point { opacity: .8; stroke: #ffffff; stroke-width: .5; }
.legend__dot { display: inline-flex; align-items: center; gap: 6px; }
.legend__dotmark { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

.table-wrap--scroll { max-height: 420px; overflow-y: auto; }
.table-wrap--scroll thead th, .table-wrap--malla thead th { position: sticky; top: 0; background: var(--surface); z-index: 1; }

#malla { scroll-margin-top: 130px; margin-top: 20px; }
.malla__head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 10px 16px; margin-bottom: 8px; }
.malla__tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.table-wrap--malla { max-height: 620px; overflow: auto; border: 1px solid var(--border); border-radius: 10px; margin: 0; }
.table--malla { font-size: 13px; }
.table--malla th { text-transform: none; letter-spacing: 0; font-size: 12px; vertical-align: bottom; }
.table--malla th.col-q { white-space: normal; min-width: 180px; max-width: 260px; }
.table--malla td.col-q { white-space: normal; min-width: 180px; max-width: 260px; }
.clamp { display: -webkit-box; -webkit-box-orient: vertical; overflow: hidden; }
.clamp--2 { -webkit-line-clamp: 2; line-clamp: 2; }
.clamp--3 { -webkit-line-clamp: 3; line-clamp: 3; }
.table--malla td { white-space: nowrap; padding: 7px 10px; }
.table--malla .empty-cell { text-align: center; color: var(--muted); padding: 24px; }

.chooser { position: relative; }
.chooser > summary { list-style: none; cursor: pointer; }
.chooser > summary::-webkit-details-marker { display: none; }
.chooser__count { color: var(--muted); font-weight: 400; }
.chooser__panel {
    position: absolute; right: 0; top: calc(100% + 6px); z-index: 25;
    width: min(420px, 86vw); max-height: 360px; overflow: auto;
    background: #fff; border: 1px solid var(--border-strong); border-radius: 10px;
    box-shadow: var(--shadow-hover); padding: 8px;
}
.chooser__actions { display: flex; gap: 4px; border-bottom: 1px solid var(--border); padding-bottom: 6px; margin-bottom: 6px; }
.chooser__item { display: flex; gap: 8px; align-items: flex-start; padding: 6px 6px; border-radius: 6px; font-size: 13.5px; cursor: pointer; }
.chooser__item:hover { background: var(--surface-2); }
.chooser__item input { margin-top: 3px; }
.pager { display: flex; align-items: center; gap: 8px; }
.pager__info { font-size: 13px; color: var(--text-2); white-space: nowrap; }
.btn--sm { padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: .45; cursor: default; }

/* ----------------------------------------------------------- v3: tablas por sexo y edad (Secciones 3 y 4) */

.panel__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.panel__head .btn { flex: none; }
.panel.is-open { border-color: var(--brand-500); box-shadow: 0 0 0 2px rgba(79, 70, 229, .15); }
.panel__head .btn[aria-pressed="true"] { background: var(--brand-50); border-color: var(--brand-500); color: var(--brand-700); }
.mov-detail { margin-bottom: 20px; scroll-margin-top: 130px; }
#sim-detalle { scroll-margin-top: 130px; }
.hint-line { margin: -6px 0 0; color: var(--muted); font-size: 13.5px; }
.seg-grid { display: grid; grid-template-columns: minmax(0, .85fr) minmax(0, 1.6fr); gap: 24px; align-items: start; }
.seg-table { min-width: 0; }
.seg-table .mini-title { margin-top: 0; }
.table--segs th[scope="col"] { vertical-align: bottom; }
.table--segs th[scope="col"] .cell-n { text-transform: none; letter-spacing: 0; font-weight: 400; }
.table--segs tbody th { font-weight: 500; }
.table--segs tr.is-selected th, .table--segs tr.is-selected td { background: #fff7ed; }
.table--segs tr.is-selected th { box-shadow: inset 4px 0 0 var(--select); font-weight: 700; }
.table--segs .dot { margin-right: 8px; vertical-align: middle; }

@media (max-width: 1180px) {
    .seg-grid { grid-template-columns: 1fr; }
    .split { grid-template-columns: 1fr; }
    .parties { grid-template-columns: 1fr; }
    .dash-grid { grid-template-columns: 1fr; }
    .radar-split { grid-template-columns: 1fr; }
    .kpis--5 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
    body { font-size: 14.5px; }
    .topbar__inner { grid-template-columns: 1fr 1fr; padding: 14px 16px; gap: 10px 16px; }
    .topbar__titles { grid-column: 1 / -1; grid-row: 2; }
    .topbar__logo { height: 34px; width: auto; }
    .topbar__logo--left { height: 40px; }       /* logo Intelligence Research (izquierda) */
    .topbar__logo--right { height: auto; max-height: 20px; max-width: 100%; justify-self: end; }  /* logo Analitix (derecha) */
    .page { padding: 16px 16px 32px; }
    .footer { padding: 0 16px 24px; }
    .grid-2 { grid-template-columns: 1fr; }
    /* barra fija compacta: región y provincia lado a lado */
    .filters__inner { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 8px; padding: 8px 12px; }
    .filters__label { display: none; }
    .field, .select { width: 100%; min-width: 0; }
    .select { padding: 7px 30px 7px 10px; font-size: 14px; background-position: right 10px center; }
    .field--pregunta { grid-column: 1 / -1; order: -1; margin-left: 0; }
    .field--pregunta .select { min-width: 0; }
    .field__caption { display: none; }
    #filtro-limpiar { grid-column: 1 / -1; justify-self: start; padding: 2px 4px; font-size: 13px; }
    .filters__summary { grid-column: 1 / -1; margin: 0; text-align: left; font-size: 12.5px;
        white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .detail-panel, #malla, .mov-detail, #sim-detalle { scroll-margin-top: 175px; }
    .panel { padding: 16px 14px 14px; }
    .table--segs { font-size: 13px; }
    .table--segs th, .table--segs td { padding: 7px 4px; }
    .table--segs thead th { font-size: 10.5px; letter-spacing: .02em; white-space: normal; }
    .table--segs .heat { padding: 3px 5px; }
    .table--segs .dot { margin-right: 5px; }
    .panel__head { flex-wrap: wrap; }
    .kpis--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .kpis--5 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .kpi__value { font-size: 23px; }
    .detail-charts { grid-template-columns: 1fr; }
    /* en teléfono la matriz muestra solo los % (sin barras) para que quepa sin scroll */
    .table--matrix .cell-bar { min-width: 0; grid-template-columns: auto; justify-items: end; }
    .table--matrix .cell-bar__track { display: none; }
    .cand-grid--wide { grid-template-columns: 1fr; }
    .malla__tools { width: 100%; justify-content: space-between; }
    .chooser__panel { right: auto; left: 0; }
    .chart-box { height: 270px; }
    .chart-box--vbar { min-width: 560px; }
    .chart-box--donut { height: 330px; }
    .chart-box--sim { height: 400px; min-width: 780px; }
    .chart-box--scatter { min-width: 640px; }
    .table { font-size: 13.5px; }
    .table th, .table td { padding: 9px 6px; }
    .table--sim { font-size: 12.5px; }
    .table--sim th, .table--sim td { padding: 8px 3px; }
    .table--sim thead th { font-size: 10.5px; letter-spacing: .02em; }
    .table--sim .heat { padding: 3px 5px; }
    .detail__head { flex-wrap: wrap; }
    .chart-scroll { margin: 0 -22px; padding: 0 22px; }
    .chart-box--scatter { height: 340px; }
    .profile { grid-template-columns: 1fr; text-align: left; }
    .tabs__item { padding: 10px 12px 8px; font-size: 14px; }
    .meter { grid-template-columns: 84px 1fr 44px; }
}

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

/* ----------------------------------------------------------- acceso (inicio de sesión) */

/* Sin sesión: solo se ve la cabecera y el formulario. */
body.is-locked .topbar,
body.is-locked .sticky-bar,
body.is-locked .page,
body.is-locked .footer { display: none !important; }
/* sin sesión: fondo de la marca a toda la pantalla (también mientras se verifica la sesión) */
body.is-locked {
    background:
        radial-gradient(1000px 520px at 50% 0%, rgba(99, 102, 241, .35), transparent 70%),
        linear-gradient(160deg, #15133a 0%, #272463 55%, #34319a 100%);
    background-attachment: fixed;
}

.topbar__right { display: flex; flex-direction: column; align-items: flex-end; gap: 10px; justify-self: end; min-width: 0; }

.acceso {
    flex: 1;
    min-height: 100vh; min-height: 100dvh;
    display: flex; justify-content: center; align-items: center;
    padding: 32px 16px;
}
.acceso__wrap { width: 100%; max-width: 420px; display: flex; flex-direction: column; align-items: center; gap: 24px; }
.acceso__logos { display: flex; align-items: center; justify-content: center; gap: 20px; }
.acceso__logo--ir { height: 52px; width: auto; }
.acceso__logo--ax { height: auto; max-height: 24px; width: auto; }
.acceso__sep { width: 1px; height: 36px; background: rgba(255, 255, 255, .3); }
.acceso__foot { margin: 0; color: #c7cbf1; font-size: 12.5px; text-align: center; }
.acceso__card {
    width: 100%; max-width: 420px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: 0 18px 50px rgba(30, 27, 75, .12), 0 2px 6px rgba(15, 23, 42, .05);
    padding: 30px 30px 26px;
    display: flex; flex-direction: column; gap: 14px;
}
.acceso__brand { display: flex; align-items: center; gap: 10px; }
.acceso__shield {
    width: 38px; height: 38px; border-radius: 11px;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--brand-50); color: var(--brand-600);
    border: 1px solid var(--brand-100);
}
.acceso__eyebrow { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--brand-600); }
.acceso__title { margin: 4px 0 0; font-size: 23px; font-weight: 800; letter-spacing: -.015em; line-height: 1.25; }
.acceso__lead { margin: -6px 0 4px; color: var(--text-2); font-size: 14.5px; }
.acceso__who { margin: -4px 0 0; color: var(--text-2); font-size: 14px; }
.acceso__field { display: flex; flex-direction: column; gap: 6px; }
.acceso__field label { font-size: 14px; font-weight: 600; color: var(--text); }
.acceso__help { margin: 0; font-size: 12.5px; color: var(--muted); }
.acceso__note { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); text-align: center; }
.acceso__msg {
    border-radius: 10px; padding: 10px 12px; font-size: 14px; line-height: 1.4;
    border: 1px solid;
}
.acceso__msg--error { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.acceso__msg--ok { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }

.input-wrap { position: relative; display: flex; }
.input {
    width: 100%;
    padding: 11px 14px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: #fff;
    font-size: 15px;
    transition: border-color .15s, box-shadow .15s;
}
.input-wrap--pwd .input { padding-right: 86px; }
.input:hover { border-color: #a5b4fc; }
.input:focus-visible { outline: none; border-color: var(--brand-500); box-shadow: 0 0 0 3px rgba(79, 70, 229, .2); }
.input-wrap__toggle {
    position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
    border: 0; background: transparent; color: var(--brand-600);
    font-size: 13px; font-weight: 600; padding: 6px 10px; border-radius: 7px; cursor: pointer;
}
.input-wrap__toggle:hover { background: var(--brand-50); }

.btn--primary { background: var(--brand-600); color: #fff; font-weight: 600; }
.btn--primary:hover { background: var(--brand-700); }
.btn--primary:disabled { opacity: .7; cursor: wait; }
.btn--block { width: 100%; justify-content: center; padding: 11px 14px; font-size: 15px; }
.acceso__card .btn--primary { margin-top: 4px; }
.acceso__card .btn--ghost { margin-top: -6px; }

/* ----------------------------------------------------------- cuenta en la cabecera */

.user { position: relative; }
.user__btn {
    display: inline-flex; align-items: center; gap: 8px;
    background: rgba(255, 255, 255, .1);
    border: 1px solid rgba(255, 255, 255, .22);
    color: #fff; border-radius: 999px;
    padding: 3px 12px 3px 3px; cursor: pointer;
    font-size: 13.5px; font-weight: 500;
    max-width: 220px;
}
.user__btn:hover, .user__btn[aria-expanded="true"] { background: rgba(255, 255, 255, .18); }
.user__avatar {
    width: 26px; height: 26px; border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    background: #fff; color: var(--brand-700); font-size: 11.5px; font-weight: 800; letter-spacing: .02em;
    flex: none;
}
.user__name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user__caret { flex: none; opacity: .85; }
.user__menu {
    position: absolute; right: 0; top: calc(100% + 8px); z-index: 60;
    min-width: 230px;
    background: var(--surface); color: var(--text);
    border: 1px solid var(--border); border-radius: 12px;
    box-shadow: 0 16px 40px rgba(15, 23, 42, .18);
    padding: 6px;
}
.user__head { display: flex; flex-direction: column; padding: 8px 10px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.user__head strong { font-size: 14px; }
.user__head span { font-size: 12.5px; color: var(--muted); }
.user__item {
    display: block; width: 100%; text-align: left;
    border: 0; background: transparent; padding: 9px 10px; border-radius: 8px;
    font-size: 14px; cursor: pointer;
}
.user__item:hover, .user__item:focus-visible { background: var(--brand-50); color: var(--brand-700); outline: none; }
.user__item--danger:hover, .user__item--danger:focus-visible { background: #fef2f2; color: #b91c1c; }

.toast {
    position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 90;
    max-width: calc(100% - 32px);
    background: #14532d; color: #fff; border-radius: 10px; padding: 10px 16px;
    font-size: 14px; box-shadow: 0 10px 30px rgba(15, 23, 42, .25);
    transition: opacity .5s;
}
.toast.is-out { opacity: 0; }

@media (max-width: 760px) {
    .topbar__right { gap: 8px; }
    .user__btn { font-size: 12.5px; padding: 2px 10px 2px 2px; }
    .user__avatar { width: 22px; height: 22px; font-size: 10px; }
    .user__name { max-width: 90px; }
    .acceso { padding: 24px 16px; align-items: flex-start; }
    .acceso__wrap { gap: 18px; }
    .acceso__logo--ir { height: 42px; }
    .acceso__logo--ax { max-height: 20px; }
    .acceso__card { padding: 24px 20px 22px; border-radius: 16px; }
    .acceso__title { font-size: 21px; }
    .input { font-size: 16px; } /* evita el zoom automático en iPhone */
    .toast { left: 16px; right: 16px; transform: none; max-width: none; text-align: center; bottom: 16px; }
}
