/* =========================================================
   senales.css — vista «Monitoreo Señales» (#page-senales) v5.5.6
   Acotado a #page-senales y al diálogo #senConfirm.
   tailwind.min.css está precompilado y no trae utilidades
   responsivas nuevas: el diseño adaptable vive aquí.
   El color solo codifica severidad.
   ========================================================= */

#page-senales {
    --sen-critico: #e11d48;
    --sen-alerta: #f59e0b;
    --sen-degradando: #f97316;
    --sen-sin_lectura: #64748b;
    --sen-borde: rgba(255, 255, 255, 0.06);
    --sen-cols: 1.25rem minmax(0, 1fr) 8.5rem 10.5rem 6.5rem 1.25rem;
}

#page-senales [hidden],
.sen-modal[hidden] { display: none !important; }

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

.sen-ico { width: 1.1rem; height: 1.1rem; flex: none; }

/* ---------- Franja superior: contadores = filtros ---------- */
.sen { display: flex; flex-direction: column; gap: 1rem; }

.sen-top {
    display: flex;
    align-items: stretch;
    gap: 1rem;
}

.sen-kpis {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.75rem;
}

.sen-kpi {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: 0.15rem;
    min-height: 72px;
    padding: 0.75rem 1rem;
    border-radius: var(--radius, 10px);
    border: 1px solid var(--sen-borde);
    border-left: 4px solid var(--sen-c, var(--sen-sin_lectura));
    background: var(--bg-surface, #1f2229);
    color: var(--text-primary, #f8fafc);
    text-align: left;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.sen-kpi--critico { --sen-c: var(--sen-critico); }
.sen-kpi--alerta { --sen-c: var(--sen-alerta); }
.sen-kpi--degradando { --sen-c: var(--sen-degradando); }
.sen-kpi--sin_lectura { --sen-c: var(--sen-sin_lectura); }

.sen-kpi:hover { background: var(--bg-surface-hover, #2a2e37); }
.sen-kpi:focus-visible,
.sen-fila:focus-visible,
.sen-miembro:focus-visible,
.sen-btn-icono:focus-visible,
.sen-btn-resolver:focus-visible {
    outline: 2px solid var(--primary, #3b82f6);
    outline-offset: 2px;
}
.sen-kpi--activo {
    border-color: var(--sen-c);
    box-shadow: inset 0 0 0 1px var(--sen-c);
    background: var(--bg-surface-hover, #2a2e37);
}
.sen-kpi[aria-disabled="true"] { cursor: default; opacity: 0.75; }
.sen-kpi[aria-disabled="true"]:hover { background: var(--bg-surface, #1f2229); }

.sen-kpi-n {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}
.sen-kpi-l {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary, #94a3b8);
}

.sen-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    justify-content: center;
    gap: 0.4rem;
    min-width: 9rem;
}
.sen-actualizado { font-size: 0.8rem; color: var(--text-secondary, #94a3b8); white-space: nowrap; }
.sen-btn-icono { min-width: 44px; min-height: 44px; padding: 0; }
.sen-girando .sen-ico,
.sen-girando svg { animation: sen-giro 0.9s linear infinite; }
@keyframes sen-giro { to { transform: rotate(360deg); } }

/* ---------- Puntos de severidad ---------- */
.sen-dot {
    display: inline-block;
    width: 0.7rem; height: 0.7rem;
    border-radius: 50%;
    flex: none;
    background: var(--sen-sin_lectura);
}
.sen-dot--critico { background: var(--sen-critico); box-shadow: 0 0 0 3px rgba(225, 29, 72, 0.2); }
.sen-dot--alerta { background: var(--sen-alerta); }
.sen-dot--degradando { background: var(--sen-degradando); }
.sen-dot--sin_lectura { background: transparent; border: 2px solid var(--sen-sin_lectura); }

/* ---------- Aviso: colector detenido ---------- */
.sen-aviso {
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
    padding: 0.9rem 1rem;
    border-radius: var(--radius, 10px);
    border: 1px solid rgba(245, 158, 11, 0.35);
    background: rgba(245, 158, 11, 0.08);
    color: #fde68a;
}
.sen-aviso .sen-ico { margin-top: 0.15rem; color: var(--sen-alerta); }
.sen-aviso-titulo { font-weight: 700; font-size: 0.9rem; }
.sen-aviso-texto { font-size: 0.85rem; color: #fcd34d; opacity: 0.9; }

/* ---------- Tarjeta con la lista ---------- */
.sen-card { padding: 1rem 1rem 0.5rem; }
.sen-card:hover { transform: none; }

.sen-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--sen-borde);
}
.sen-titulo { display: flex; align-items: baseline; gap: 0.5rem; }
.sen-total { font-size: 0.8rem; font-weight: 600; color: var(--text-secondary, #94a3b8); }

.sen-filtros { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.sen-buscar { position: relative; display: block; }
.sen-buscar .sen-ico {
    position: absolute; left: 0.75rem; top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted, #64748b);
    pointer-events: none;
}
#senBuscar { padding-left: 2.25rem; width: 16rem; min-height: 44px; }
#senZona { min-height: 44px; min-width: 11rem; }

.sen-cabecera {
    display: grid;
    grid-template-columns: var(--sen-cols) 7.5rem;
    gap: 0.75rem;
    padding: 0.6rem 0.75rem 0.4rem;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-muted, #64748b);
}

.sen-lista { list-style: none; margin: 0; padding: 0; }
.sen-lista[aria-busy="true"] .sen-item:not(.sen-esqueleto) { opacity: 0.6; }

.sen-item {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    border-top: 1px solid var(--sen-borde);
}
.sen-item:first-child { border-top: 0; }
.sen-item--antigua { opacity: 0.7; }

.sen-fila {
    position: relative;
    flex: 1;
    min-width: 0;
    display: grid;
    grid-template-columns: var(--sen-cols);
    gap: 0.75rem;
    align-items: center;
    min-height: 56px;
    padding: 0.6rem 0.75rem;
    background: none;
    border: 0;
    border-radius: 8px;
    color: inherit;
    text-align: left;
    font: inherit;
    cursor: pointer;
}
.sen-fila:hover { background: var(--bg-element, rgba(255, 255, 255, 0.05)); }
.sen-fila[aria-disabled="true"] { cursor: default; }
.sen-fila[aria-disabled="true"]:hover { background: none; }
.sen-fila .sen-dot { justify-self: center; }

.sen-principal { display: flex; flex-direction: column; min-width: 0; }
/* En escritorio, zona/señal/desde son celdas de la grilla; en móvil, una línea aparte */
.sen-datos { display: contents; }
.sen-cliente,
.sen-motivo {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sen-cliente { font-weight: 600; color: var(--text-primary, #f8fafc); }
.sen-motivo { font-size: 0.8rem; color: var(--text-secondary, #94a3b8); }
.sen-zona { font-size: 0.85rem; color: var(--text-secondary, #94a3b8); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sen-valor { font-family: var(--font-technical, monospace); font-size: 0.82rem; white-space: nowrap; }
/* El color de la señal depende de su propio valor (senClaseValor), no de la fila */
.sen-valor--critico { color: #fb7185; }
.sen-valor--alerta { color: #fbbf24; }
.sen-valor--degradando { color: #fb923c; }
.sen-valor--ok { color: var(--text-secondary, #94a3b8); }
.sen-valor--vieja,
.sen-valor--vacio { color: var(--text-muted, #64748b); }
.sen-edad { font-size: 0.8rem; color: var(--text-muted, #64748b); white-space: nowrap; }
.sen-chevron { color: var(--text-muted, #64748b); }

.sen-accion { width: 7.5rem; display: flex; justify-content: flex-end; padding-right: 0.5rem; }
.sen-btn-resolver {
    min-height: 44px;
    background: rgba(16, 185, 129, 0.12);
    color: #34d399;
    border: 1px solid rgba(16, 185, 129, 0.3);
}
.sen-btn-resolver:hover { background: var(--success, #10b981); color: #fff; }
.sen-btn-resolver:disabled { opacity: 0.6; cursor: wait; }

/* Detalle expandible (grupos e infraestructura) */
.sen-detalle {
    flex-basis: 100%;
    padding: 0 0.75rem 0.75rem 2.75rem;
}
.sen-detalle-texto {
    font-size: 0.82rem;
    color: var(--text-secondary, #94a3b8);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}
.sen-miembros {
    list-style: none;
    margin: 0; padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
    gap: 0.35rem;
}
.sen-miembro {
    width: 100%;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto auto;
    column-gap: 0.5rem;
    align-items: center;
    min-height: 44px;
    padding: 0.4rem 0.6rem;
    border-radius: 8px;
    border: 1px solid var(--sen-borde);
    background: rgba(255, 255, 255, 0.02);
    color: inherit;
    text-align: left;
    font: inherit;
}
button.sen-miembro { cursor: pointer; }
button.sen-miembro:hover { background: var(--bg-element, rgba(255, 255, 255, 0.05)); }
.sen-miembro .sen-chevron { grid-row: 1 / span 2; grid-column: 2; }
.sen-miembro-nombre { font-size: 0.85rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sen-miembro-linea { font-size: 0.75rem; color: var(--text-muted, #64748b); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sen-miembro--sin-cliente { opacity: 0.75; }

/* Estados vacío / error / nota */
.sen-vacio {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 2.5rem 1rem;
    text-align: center;
}
.sen-vacio-ico { width: 2rem; height: 2rem; color: var(--text-muted, #64748b); }
.sen-vacio-ico.sen-ok { color: var(--success, #10b981); }
.sen-vacio-ico.sen-error { color: var(--sen-critico); }
.sen-vacio-titulo { font-weight: 600; }
.sen-vacio-texto { font-size: 0.85rem; color: var(--text-secondary, #94a3b8); }
.sen-nota { font-size: 0.8rem; color: var(--text-muted, #64748b); padding: 0.75rem; text-align: center; }

.sen-antiguas { margin-top: 0.5rem; border-top: 1px solid var(--sen-borde); }
.sen-antiguas > summary {
    min-height: 44px;
    display: flex;
    align-items: center;
    padding: 0.5rem 0.75rem;
    font-size: 0.82rem;
    color: var(--text-secondary, #94a3b8);
    cursor: pointer;
}

.sen-antiguas-barra { display: flex; justify-content: flex-end; padding: 0 0.75rem 0.5rem; }
.sen-antiguas-barra:empty { display: none; }

/* Esqueleto */
.sen-esqueleto { padding: 0.9rem 0.75rem; gap: 0.75rem; flex-wrap: nowrap; }
.sen-esq-dot { width: 0.7rem; height: 0.7rem; border-radius: 50%; flex: none; margin-left: 0.3rem; }
.sen-esq-cuerpo { flex: 1; display: flex; flex-direction: column; gap: 0.35rem; }
.sen-esq-l1 { width: 45%; height: 0.9rem; }
.sen-esq-l2 { width: 70%; height: 0.7rem; }

/* ---------- Diálogo de confirmación (colgado de <body>) ---------- */
.sen-modal {
    position: fixed;
    inset: 0;
    z-index: 160;   /* por encima de .top-nav (101) y de los otros modales (150) */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.sen-modal-fondo {
    position: absolute;
    inset: 0;
    background: rgba(2, 6, 23, 0.75);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
}
.sen-modal-caja {
    position: relative;
    width: 100%;
    max-width: 26rem;
    padding: 1.5rem;
    border-radius: 1rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: #172033;
    color: var(--text-primary, #f8fafc);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}
.sen-modal-titulo { font-size: 1.05rem; font-weight: 700; margin-bottom: 0.5rem; }
.sen-modal-texto { font-size: 0.92rem; color: var(--text-secondary, #94a3b8); overflow-wrap: anywhere; }
.sen-modal-texto strong { color: var(--text-primary, #f8fafc); }
.sen-modal-botones { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1.25rem; }

/* ---------- Teléfonos y tablets angostas (< 768 px): tarjetas apiladas ---------- */
@media (max-width: 767.98px) {
    .sen-top { flex-direction: column; gap: 0.6rem; }
    .sen-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.5rem; }
    .sen-kpi { min-height: 64px; padding: 0.6rem 0.8rem; }
    .sen-kpi-n { font-size: 1.5rem; }
    .sen-meta { flex-direction: row; align-items: center; justify-content: space-between; min-width: 0; }

    .sen-card { padding: 0.75rem 0.5rem 0.5rem; }
    .sen-toolbar { flex-direction: column; align-items: stretch; gap: 0.6rem; padding: 0 0.25rem 0.6rem; }
    .sen-filtros { display: grid; grid-template-columns: minmax(0, 1fr); }
    #senBuscar, #senZona { width: 100%; font-size: 16px; }  /* 16px: evita el zoom de iOS al enfocar */
    .sen-cabecera { display: none; }

    .sen-item {
        flex-direction: column;
        align-items: stretch;
        margin: 0.5rem 0.25rem 0;
        border: 1px solid var(--sen-borde);
        border-left: 4px solid var(--sen-sin_lectura);
        border-radius: var(--radius, 10px);
        background: rgba(255, 255, 255, 0.02);
    }
    .sen-item:first-child { border-top: 1px solid var(--sen-borde); }
    .sen-item--critico { border-left-color: var(--sen-critico); }
    .sen-item--alerta { border-left-color: var(--sen-alerta); }
    .sen-item--degradando { border-left-color: var(--sen-degradando); }

    /* Tarjeta: punto + cliente/motivo arriba; zona · señal · antigüedad en una línea debajo */
    .sen-fila {
        display: grid;
        grid-template-columns: 1rem minmax(0, 1fr) auto;
        column-gap: 0.6rem;
        row-gap: 0.35rem;
        align-items: start;
        padding: 0.75rem;
    }
    .sen-fila .sen-dot { margin-top: 0.45rem; }
    .sen-cliente, .sen-motivo { white-space: normal; overflow-wrap: anywhere; }
    .sen-fila .sen-chevron { margin-top: 0.2rem; }
    .sen-datos {
        display: flex;
        flex-wrap: wrap;
        column-gap: 0.5rem;
        row-gap: 0.1rem;
        grid-column: 2 / 4;
        grid-row: 2;
        font-size: 0.78rem;
    }
    .sen-zona, .sen-valor, .sen-edad { font-size: 0.78rem; max-width: 100%; }
    .sen-valor--vacio { display: none; }

    .sen-accion { width: auto; padding: 0 0.75rem 0.75rem; }
    .sen-btn-resolver { width: 100%; }
    .sen-detalle { padding: 0 0.75rem 0.75rem; }
    .sen-antiguas-barra { padding: 0 0.25rem 0.5rem; }
    .sen-antiguas-barra .btn { width: 100%; }
    .sen-miembros { grid-template-columns: minmax(0, 1fr); }

    .sen-modal { align-items: flex-end; padding: 0; }
    .sen-modal-caja {
        max-width: none;
        border-radius: 1rem 1rem 0 0;
        padding-bottom: calc(1.5rem + env(safe-area-inset-bottom));
    }
    .sen-modal-botones { flex-direction: column-reverse; }
    .sen-modal-botones .btn { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
    .sen-girando .sen-ico, .sen-girando svg { animation: none; }
}
