/* ===== heatmap.css =====
   Mapa de calor: casos por distrito × prioridad / estatus.
   Color relativo por fila via --hm-i (0–100).
   ============================================================ */

/* -----------------------------------------------------------------------
   Toggle
----------------------------------------------------------------------- */
.hm-toggle {
    display: flex;
    gap: 4px;
    padding: 4px;
    background: rgba(255,255,255,.06);
    border: 1px solid var(--stroke);
    border-radius: var(--radius-sm);
}

.hm-toggle-btn {
    padding: 6px 16px;
    border-radius: calc(var(--radius-sm) - 2px);
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
    white-space: nowrap;
}

.hm-toggle-btn.is-active {
    background: var(--azul, #1A6FBF);
    color: #fff;
}

.hm-toggle-btn:not(.is-active):hover {
    background: rgba(255,255,255,.08);
    color: var(--text);
}

/* -----------------------------------------------------------------------
   Visibilidad de vistas
----------------------------------------------------------------------- */
.hm-wrap.is-hidden { display: none; }

/* -----------------------------------------------------------------------
   Grid
   hm-grid--N define las columnas: label + N distritos + total
----------------------------------------------------------------------- */
.hm-grid {
    display: grid;
    width: 100%;
    overflow-x: auto;
    row-gap: 3px;
}

/* 8 distritos → label(180px) + 8 × 1fr + total(72px) */
.hm-grid--8 { grid-template-columns: 180px repeat(8, 1fr) 72px; }
.hm-grid--7 { grid-template-columns: 180px repeat(7, 1fr) 72px; }
.hm-grid--6 { grid-template-columns: 180px repeat(6, 1fr) 72px; }

/* -----------------------------------------------------------------------
   Encabezado
----------------------------------------------------------------------- */
.hm-head-row {
    display: contents;
}

.hm-head-cell {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    padding: 6px 4px 10px;
    gap: 3px;
    border-bottom: 1px solid var(--stroke);
}

.hm-head-cell--total {
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-muted);
}

.hm-dist-num {
    font-size: 13px;
    font-weight: 900;
    color: var(--text);
    letter-spacing: -.01em;
}

.hm-dist-name {
    font-size: 10px;
    color: var(--text-muted);
    text-align: center;
    line-height: 1.2;
    max-width: 80px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* -----------------------------------------------------------------------
   Filas de datos
----------------------------------------------------------------------- */
.hm-data-row {
    display: contents;
}

/* Label de fila */
.hm-label-cell {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 12px 0 0;
    min-width: 0;
}

.hm-row-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
}

/* -----------------------------------------------------------------------
   Celda de dato — estructura base
   El color viene de las filas (.hm-prio-N, .hm-estado-X)
   --hm-i (0-100) controla la opacidad dentro de cada color de fila
----------------------------------------------------------------------- */
.hm-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px 6px;
    border-radius: 6px;
    font-size: 15px;
    font-weight: 800;
    letter-spacing: -.02em;
    text-align: center;
    cursor: default;
    transition: transform .1s;
    color: rgba(255,255,255, calc( .45 + var(--hm-i, 0) * .0055 ));
}

/* -----------------------------------------------------------------------
   Colores por prioridad  — minimo ~12% opacidad, maximo ~85%
----------------------------------------------------------------------- */
.hm-data-row.hm-prio-5 .hm-cell {
    background: rgba(192, 64, 64,   calc( .12 + var(--hm-i, 0) * .0073 ));
}
.hm-data-row.hm-prio-4 .hm-cell {
    background: rgba(200, 104, 48,  calc( .12 + var(--hm-i, 0) * .0073 ));
}
.hm-data-row.hm-prio-3 .hm-cell {
    background: rgba(200, 144, 16,  calc( .12 + var(--hm-i, 0) * .0073 ));
}
.hm-data-row.hm-prio-2 .hm-cell {
    background: rgba(26, 111, 191,  calc( .12 + var(--hm-i, 0) * .0073 ));
}
.hm-data-row.hm-prio-1 .hm-cell {
    background: rgba(58, 74, 98,    calc( .18 + var(--hm-i, 0) * .0067 ));
}

/* -----------------------------------------------------------------------
   Colores por estatus
----------------------------------------------------------------------- */
.hm-data-row.hm-estado-abierto .hm-cell {
    background: rgba(26, 111, 191,  calc( .12 + var(--hm-i, 0) * .0073 ));
}
.hm-data-row.hm-estado-cerrado .hm-cell {
    background: rgba(26, 138, 106,  calc( .12 + var(--hm-i, 0) * .0073 ));
}
.hm-data-row.hm-estado-suspendido .hm-cell {
    background: rgba(107, 122, 141, calc( .15 + var(--hm-i, 0) * .0070 ));
}

/* -----------------------------------------------------------------------
   Colores por perfil de usuario
   Pastor azul #1A6FBF | Esposa morado #7C3AED | Hijo verde #1A8A6A | Hija naranja #C2500F
----------------------------------------------------------------------- */
.hm-data-row.hm-perfil-pastor .hm-cell {
    background: rgba(26, 111, 191,  calc( .12 + var(--hm-i, 0) * .0073 ));
}
.hm-data-row.hm-perfil-esposa .hm-cell {
    background: rgba(124, 58, 237,  calc( .12 + var(--hm-i, 0) * .0073 ));
}
.hm-data-row.hm-perfil-hijo .hm-cell {
    background: rgba(26, 138, 106,  calc( .12 + var(--hm-i, 0) * .0073 ));
}
.hm-data-row.hm-perfil-hija .hm-cell {
    background: rgba(194, 80, 15,   calc( .12 + var(--hm-i, 0) * .0073 ));
}

/* Dot indicador en la columna label */
.hm-perfil-dot {
    display: inline-block;
    width: 9px;
    height: 9px;
    border-radius: 3px;
    flex-shrink: 0;
    margin-right: 6px;
}
.hm-perfil-dot--pastor { background: #1A6FBF; }
.hm-perfil-dot--esposa { background: #7C3AED; }
.hm-perfil-dot--hijo   { background: #1A8A6A; }
.hm-perfil-dot--hija   { background: #C2500F; }

.hm-cell:hover {
    transform: scale(1.08);
    z-index: 1;
    position: relative;
}

/* Celda sin dato */
.hm-zero {
    font-size: 12px;
    font-weight: 400;
    opacity: .4;
}

/* -----------------------------------------------------------------------
   Columna total por fila
----------------------------------------------------------------------- */
.hm-total-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px 8px;
    font-size: 14px;
    font-weight: 800;
    color: var(--text);
    letter-spacing: -.02em;
}

/* -----------------------------------------------------------------------
   Fila de totales (pie)
----------------------------------------------------------------------- */
.hm-foot-row {
    display: contents;
}

.hm-foot-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px 6px;
    border-top: 1px solid var(--stroke-strong);
    font-size: 13px;
    font-weight: 900;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .04em;
}

.hm-foot-cell--grand {
    color: var(--text);
}

/* Label en fila pie */
.hm-foot-row .hm-label-cell {
    padding: 10px 12px 10px 0;
    border-top: 1px solid var(--stroke-strong);
    font-size: 11px;
    font-weight: 900;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .06em;
}

/* -----------------------------------------------------------------------
   Badges de prioridad en label
----------------------------------------------------------------------- */
.hm-prio-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 1px 7px;
    border-radius: 6px;
    font-size: 10px;
    font-weight: 900;
    letter-spacing: .04em;
    border: 1px solid;
    white-space: nowrap;
    flex-shrink: 0;
}
.hm-prio-5 { background:rgba(192,64,64,.28);   color:#ff6b6b;              border-color:rgba(192,64,64,.40); }
.hm-prio-4 { background:rgba(200,104,48,.24);  color:#ff9f5a;              border-color:rgba(200,104,48,.36); }
.hm-prio-3 { background:rgba(200,144,16,.22);  color:#f5c542;              border-color:rgba(200,144,16,.34); }
.hm-prio-2 { background:rgba(26,111,191,.22);  color:var(--cielo,#5BAAE0); border-color:rgba(26,111,191,.34); }
.hm-prio-1 { background:rgba(255,255,255,.08); color:var(--text-muted);    border-color:rgba(255,255,255,.12); }

/* -----------------------------------------------------------------------
   Leyenda de escala
----------------------------------------------------------------------- */
.hm-legend {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 16px;
    justify-content: flex-end;
}

.hm-legend-label {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 600;
}

.hm-legend-scale {
    width: 120px;
    height: 10px;
    border-radius: 5px;
    /* gradiente transparente -> color solido, representa baja -> alta intensidad */
    background: linear-gradient(
        to right,
        rgba(255,255,255,.06),
        rgba(255,255,255,.65)
    );
}

/* -----------------------------------------------------------------------
   Light mode
----------------------------------------------------------------------- */
body.light .hm-toggle {
    background: rgba(0,0,0,.04);
}

body.light .hm-toggle-btn:not(.is-active):hover {
    background: rgba(0,0,0,.06);
}

/* Light mode: texto oscuro, mismos colores base con mayor saturacion */
body.light .hm-cell {
    color: rgba(0, 0, 0, calc( .55 + var(--hm-i, 0) * .0045 ));
}
body.light .hm-data-row.hm-prio-5 .hm-cell {
    background: rgba(192, 64, 64,   calc( .10 + var(--hm-i, 0) * .008 ));
}
body.light .hm-data-row.hm-prio-4 .hm-cell {
    background: rgba(200, 104, 48,  calc( .10 + var(--hm-i, 0) * .008 ));
}
body.light .hm-data-row.hm-prio-3 .hm-cell {
    background: rgba(200, 144, 16,  calc( .10 + var(--hm-i, 0) * .008 ));
}
body.light .hm-data-row.hm-prio-2 .hm-cell {
    background: rgba(26, 111, 191,  calc( .10 + var(--hm-i, 0) * .008 ));
}
body.light .hm-data-row.hm-prio-1 .hm-cell {
    background: rgba(58, 74, 98,    calc( .10 + var(--hm-i, 0) * .008 ));
}
body.light .hm-data-row.hm-estado-abierto .hm-cell {
    background: rgba(26, 111, 191,  calc( .10 + var(--hm-i, 0) * .008 ));
}
body.light .hm-data-row.hm-estado-cerrado .hm-cell {
    background: rgba(26, 138, 106,  calc( .10 + var(--hm-i, 0) * .008 ));
}
body.light .hm-data-row.hm-estado-suspendido .hm-cell {
    background: rgba(107, 122, 141, calc( .10 + var(--hm-i, 0) * .008 ));
}
body.light .hm-data-row.hm-perfil-pastor .hm-cell {
    background: rgba(26, 111, 191,  calc( .10 + var(--hm-i, 0) * .008 ));
}
body.light .hm-data-row.hm-perfil-esposa .hm-cell {
    background: rgba(124, 58, 237,  calc( .10 + var(--hm-i, 0) * .008 ));
}
body.light .hm-data-row.hm-perfil-hijo .hm-cell {
    background: rgba(26, 138, 106,  calc( .10 + var(--hm-i, 0) * .008 ));
}
body.light .hm-data-row.hm-perfil-hija .hm-cell {
    background: rgba(194, 80, 15,   calc( .10 + var(--hm-i, 0) * .008 ));
}

body.light .hm-prio-1 {
    background: rgba(0,0,0,.06);
    color: #64748b;
    border-color: rgba(0,0,0,.12);
}

/* Leyenda light: sin cambio especial, la escala es decorativa */

/* -----------------------------------------------------------------------
   Responsive
----------------------------------------------------------------------- */
@media (max-width: 1100px) {
    .hm-grid--8,
    .hm-grid--7,
    .hm-grid--6 {
        overflow-x: auto;
        display: block; /* scroll horizontal */
    }

    /* Reconstruye el grid dentro del bloque scrollable */
    .hm-grid--8 > *,
    .hm-grid--7 > *,
    .hm-grid--6 > * {
        display: grid;
    }
    .hm-grid--8 > * { grid-template-columns: 160px repeat(8, minmax(60px,1fr)) 64px; }
    .hm-grid--7 > * { grid-template-columns: 160px repeat(7, minmax(60px,1fr)) 64px; }
    .hm-grid--6 > * { grid-template-columns: 160px repeat(6, minmax(60px,1fr)) 64px; }

    .hm-head-row,
    .hm-data-row,
    .hm-foot-row {
        display: grid;
    }

    .hm-dist-name { display: none; }
}

@media (max-width: 700px) {
    .hm-toggle { flex-wrap: wrap; }
}
