/* =============================================================================
 * MEDInteraction360 — Pantallas de sala (TV)
 * -----------------------------------------------------------------------------
 * digiturno_pantalla.php (llamado de pacientes) y sala_espera_publica.php
 * (turnos del día). Acero cepillado oscuro con el teal / cian / navy del
 * proyecto, brillo diagonal y letra grande para leer a 5 m en un TV 1920x1080.
 * Bajan bien a celular (una columna) y nunca hacen scroll horizontal.
 * Animaciones solo si el equipo no pidió reducir movimiento.
 * ========================================================================== */

:root {
    --tv-teal: #00a290;
    --tv-teal-dk: #008a7a;
    --tv-cyan: #00a2c0;
    --tv-navy: #001260;
    --tv-mint: #9fe7dc;
    --tv-oro: #ffd54f;
    --tv-ambar: #ffb74d;
    --tv-texto: #f2f8fb;
    --tv-suave: #a9c4d1;
    --tv-linea: rgba(255, 255, 255, .12);
    --tv-brillo: linear-gradient(115deg, rgba(255, 255, 255, .10) 0%, rgba(255, 255, 255, 0) 24%, rgba(255, 255, 255, .05) 44%, rgba(255, 255, 255, 0) 60%);
    /* Placa de acero oscuro: degradado + líneas finas de "cepillado" */
    --tv-placa:
        repeating-linear-gradient(90deg, rgba(255, 255, 255, .018) 0 1px, rgba(255, 255, 255, 0) 1px 3px),
        linear-gradient(160deg, #18323f 0%, #0f2430 45%, #0b1c27 100%);
    --tv-relieve: inset 0 1px rgba(255, 255, 255, .14), inset 0 -1px rgba(0, 0, 0, .45);
    --tv-sombra: 0 18px 40px -20px rgba(0, 0, 0, .8);
    --tv-gutter: clamp(14px, 1.6vw, 34px);
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
    margin: 0;
}

body.tv {
    min-height: 100vh;
    overflow-x: hidden;
    font-family: 'Manrope', system-ui, -apple-system, 'Segoe UI', sans-serif;
    color: var(--tv-texto);
    background:
        radial-gradient(1200px 700px at 85% -10%, rgba(0, 162, 192, .22), rgba(0, 162, 192, 0) 60%),
        radial-gradient(900px 600px at -10% 110%, rgba(0, 162, 144, .20), rgba(0, 162, 144, 0) 60%),
        repeating-linear-gradient(90deg, rgba(255, 255, 255, .012) 0 1px, rgba(255, 255, 255, 0) 1px 4px),
        linear-gradient(180deg, #071822 0%, #0a2230 55%, #061520 100%);
    background-attachment: fixed;
    -webkit-font-smoothing: antialiased;
}

.tv-wrap {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ── Encabezado ─────────────────────────────────────────────────────────── */
.tv-head {
    position: relative;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px 24px;
    padding: clamp(10px, 1.2vw, 22px) var(--tv-gutter);
    background: var(--tv-brillo), linear-gradient(90deg, #001a3d 0%, #0b2f45 50%, #003f46 100%);
    border-bottom: 1px solid var(--tv-linea);
    box-shadow: inset 0 -1px rgba(0, 0, 0, .4), 0 10px 30px -18px rgba(0, 0, 0, .9);
}

.tv-head::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: -1px;
    height: 3px;
    background: linear-gradient(90deg, var(--tv-teal) 0%, var(--tv-cyan) 50%, rgba(0, 162, 192, 0) 100%);
}

.tv-marca {
    display: flex;
    align-items: center;
    gap: clamp(10px, 1vw, 18px);
    min-width: 0;
}

.tv-marca-ico {
    display: grid;
    flex: 0 0 auto;
    place-items: center;
    width: clamp(44px, 3.6vw, 70px);
    height: clamp(44px, 3.6vw, 70px);
    font-size: clamp(20px, 1.7vw, 32px);
    color: #ffffff;
    background: var(--tv-brillo), linear-gradient(135deg, #00a2c0 0%, #00a290 50%, #008a7a 100%);
    border-radius: 16px;
    box-shadow: inset 0 1px rgba(255, 255, 255, .4), 0 8px 18px -8px rgba(0, 162, 144, .8);
}

.tv-titulo {
    margin: 0;
    font-size: clamp(22px, 2.2vw, 44px);
    font-weight: 800;
    line-height: 1.05;
    letter-spacing: -.01em;
}

.tv-wordmark {
    margin-top: 3px;
    font-size: clamp(12px, .95vw, 18px);
    font-weight: 800;
    letter-spacing: .2em;
    text-transform: uppercase;
    color: var(--tv-suave);
}

.tv-wordmark b {
    color: var(--tv-mint);
}

.tv-head-der {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 10px clamp(14px, 1.6vw, 30px);
}

.tv-reloj {
    text-align: right;
    line-height: 1;
}

.tv-hora {
    font-size: clamp(30px, 3.2vw, 64px);
    font-weight: 800;
    letter-spacing: .02em;
    font-variant-numeric: tabular-nums;
}

.tv-fecha {
    margin-top: 4px;
    font-size: clamp(13px, 1vw, 20px);
    font-weight: 700;
    color: var(--tv-suave);
    text-transform: capitalize;
}

/* Botón de sonido (los navegadores bloquean el audio hasta un clic) */
.tv-sonido {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-height: 48px;
    padding: 10px 18px;
    font: inherit;
    font-size: clamp(14px, 1vw, 19px);
    font-weight: 800;
    color: #1a1300;
    background: var(--tv-brillo), linear-gradient(135deg, #ffe082 0%, #ffca28 55%, #ffb300 100%);
    border: 0;
    border-radius: 14px;
    box-shadow: inset 0 1px rgba(255, 255, 255, .6), 0 10px 22px -10px rgba(255, 193, 7, .8);
    cursor: pointer;
}

.tv-sonido:focus-visible {
    outline: 3px solid #ffffff;
    outline-offset: 3px;
}

.tv-sonido.is-activo {
    color: var(--tv-mint);
    background: rgba(0, 162, 144, .14);
    box-shadow: inset 0 0 0 1px rgba(159, 231, 220, .35);
}

/* ── Cuerpo ─────────────────────────────────────────────────────────────── */
.tv-main {
    flex: 1 1 auto;
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
    gap: var(--tv-gutter);
    padding: var(--tv-gutter);
}

.tv-panel {
    position: relative;
    min-width: 0;
    padding: clamp(16px, 1.6vw, 32px);
    background: var(--tv-brillo), var(--tv-placa);
    border: 1px solid var(--tv-linea);
    border-radius: clamp(16px, 1.4vw, 26px);
    box-shadow: var(--tv-relieve), var(--tv-sombra);
}

.tv-etq {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0 0 clamp(10px, 1vw, 18px);
    font-size: clamp(14px, 1.15vw, 22px);
    font-weight: 800;
    letter-spacing: .2em;
    text-transform: uppercase;
    color: var(--tv-mint);
}

.tv-etq .tv-n {
    margin-left: auto;
    padding: 2px 12px;
    font-size: .95em;
    letter-spacing: 0;
    color: #ffffff;
    background: rgba(255, 255, 255, .1);
    border-radius: 999px;
    font-variant-numeric: tabular-nums;
}

/* ── Llamado actual ─────────────────────────────────────────────────────── */
.tv-llamado {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: clamp(260px, 48vh, 620px);
    overflow: hidden;
}

.tv-llamado::before {
    /* línea de pulso (ECG) de fondo */
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 6%;
    height: 34%;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='256' height='120' viewBox='0 0 256 120'%3E%3Cpath d='M0 72H70l7-12 7 12h12l8-48 10 82 8-50 6 16h22l6-9 7 9H256' fill='none' stroke='%2300a2c0' stroke-opacity='.18' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / auto 100% repeat-x;
    pointer-events: none;
}

.tv-nuevo {
    align-self: flex-start;
    display: none;
    margin-bottom: 10px;
    padding: 6px 16px;
    font-size: clamp(14px, 1.1vw, 22px);
    font-weight: 800;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: #1a1300;
    background: linear-gradient(135deg, #ffe082, #ffb300);
    border-radius: 999px;
}

.tv-llamado.is-nuevo .tv-nuevo {
    display: inline-block;
}

.tv-nombre {
    position: relative;
    margin: 0;
    font-size: clamp(48px, 7.4vw, 160px);
    font-weight: 800;
    line-height: 1;
    letter-spacing: -.02em;
    word-break: break-word;
    color: transparent;
    background: linear-gradient(180deg, #ffffff 0%, #e6f3f7 45%, #a8c7d3 100%);
    -webkit-background-clip: text;
    background-clip: text;
    text-shadow: 0 2px 0 rgba(0, 0, 0, .0);
}

.tv-destino {
    position: relative;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 16px;
    margin-top: clamp(14px, 1.6vw, 30px);
    font-size: clamp(26px, 3.3vw, 70px);
    font-weight: 800;
    line-height: 1.1;
    color: var(--tv-oro);
}

.tv-destino small {
    font-size: .48em;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--tv-suave);
}

.tv-destino i {
    font-size: .8em;
}

.tv-meta {
    position: relative;
    margin-top: clamp(10px, 1vw, 18px);
    font-size: clamp(14px, 1.2vw, 24px);
    font-weight: 700;
    color: var(--tv-suave);
}

.tv-bienvenida {
    position: relative;
    font-size: clamp(30px, 3.6vw, 76px);
    font-weight: 800;
    line-height: 1.1;
}

.tv-bienvenida small {
    display: block;
    margin-top: 12px;
    font-size: .45em;
    font-weight: 700;
    color: var(--tv-suave);
}

/* Llamado nuevo: halo cian + placa encendida */
.tv-llamado.is-nuevo {
    border-color: rgba(0, 162, 192, .8);
    animation: tvHalo 1.2s ease-in-out 5;
}

@keyframes tvHalo {
    0%, 100% { box-shadow: var(--tv-relieve), var(--tv-sombra), 0 0 0 0 rgba(0, 162, 192, 0); }
    50% { box-shadow: var(--tv-relieve), var(--tv-sombra), 0 0 0 10px rgba(0, 162, 192, .45), 0 0 60px rgba(0, 162, 192, .5); }
}

/* Historial de llamados */
.tv-historial {
    grid-column: 1 / 2;
}

.tv-hist-lista {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: clamp(8px, .8vw, 16px);
    margin: 0;
    padding: 0;
    list-style: none;
}

.tv-hist-lista li {
    min-width: 0;
    padding: clamp(10px, .9vw, 18px);
    background: rgba(255, 255, 255, .05);
    border: 1px solid var(--tv-linea);
    border-radius: 14px;
}

.tv-hist-lista b {
    display: block;
    font-size: clamp(18px, 1.6vw, 32px);
    font-weight: 800;
    word-break: break-word;
}

.tv-hist-lista span {
    display: block;
    margin-top: 2px;
    font-size: clamp(13px, 1vw, 20px);
    font-weight: 700;
    color: var(--tv-oro);
}

.tv-hist-lista small {
    font-size: clamp(12px, .9vw, 17px);
    font-weight: 700;
    color: var(--tv-suave);
    font-variant-numeric: tabular-nums;
}

.tv-hist-vacio {
    grid-column: 1 / -1;
    font-size: clamp(15px, 1.1vw, 22px);
    font-weight: 600;
    color: var(--tv-suave);
}

/* Lista de espera (columna derecha) */
.tv-espera {
    grid-row: 1 / span 2;
    grid-column: 2 / 3;
    display: flex;
    flex-direction: column;
}

.tv-lista {
    display: flex;
    flex-direction: column;
    gap: clamp(8px, .7vw, 14px);
    margin: 0;
    padding: 0;
    list-style: none;
}

.tv-fila {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: clamp(10px, .9vw, 18px);
    min-height: clamp(54px, 5vw, 92px);
    padding: clamp(8px, .7vw, 14px) clamp(10px, .9vw, 18px);
    background: rgba(255, 255, 255, .05);
    border: 1px solid var(--tv-linea);
    border-radius: 14px;
}

.tv-fila:first-child {
    background: linear-gradient(90deg, rgba(0, 162, 144, .22), rgba(0, 162, 192, .08));
    border-color: rgba(0, 162, 144, .45);
}

.tv-turno {
    display: grid;
    place-items: center;
    min-width: clamp(40px, 3.4vw, 66px);
    height: clamp(40px, 3.4vw, 66px);
    padding: 0 6px;
    font-size: clamp(18px, 1.7vw, 34px);
    font-weight: 800;
    color: #ffffff;
    background: var(--tv-brillo), linear-gradient(135deg, #00a2c0 0%, #00a290 50%, #008a7a 100%);
    border-radius: 12px;
    box-shadow: inset 0 1px rgba(255, 255, 255, .35);
    font-variant-numeric: tabular-nums;
}

.tv-fila-nombre {
    min-width: 0;
    font-size: clamp(20px, 1.9vw, 38px);
    font-weight: 800;
    line-height: 1.1;
    word-break: break-word;
}

.tv-fila-nombre small {
    display: block;
    margin-top: 2px;
    font-size: .55em;
    font-weight: 700;
    color: var(--tv-suave);
}

.tv-fila-der {
    text-align: right;
    font-size: clamp(14px, 1.1vw, 22px);
    font-weight: 800;
    color: var(--tv-mint);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.tv-fila-der small {
    display: block;
    font-size: .8em;
    font-weight: 700;
    color: var(--tv-suave);
}

.tv-vacio {
    padding: clamp(14px, 1.4vw, 28px);
    font-size: clamp(17px, 1.4vw, 28px);
    font-weight: 700;
    line-height: 1.3;
    color: var(--tv-suave);
    text-align: center;
    border: 1px dashed var(--tv-linea);
    border-radius: 14px;
}

.tv-vacio i {
    display: block;
    margin-bottom: 8px;
    font-size: 1.6em;
    color: var(--tv-mint);
}

.tv-mas {
    margin-top: 10px;
    font-size: clamp(14px, 1vw, 20px);
    font-weight: 700;
    color: var(--tv-suave);
    text-align: center;
}

/* ── Pie ────────────────────────────────────────────────────────────────── */
.tv-pie {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 6px 20px;
    padding: clamp(8px, .8vw, 14px) var(--tv-gutter);
    font-size: clamp(14px, 1.05vw, 21px);
    font-weight: 700;
    color: var(--tv-suave);
    background: rgba(0, 0, 0, .25);
    border-top: 1px solid var(--tv-linea);
}

.tv-pie b {
    color: var(--tv-texto);
}

.tv-pie i {
    margin-right: 8px;
    color: var(--tv-mint);
}

/* ── Sala de espera pública ─────────────────────────────────────────────── */
.tv-sala {
    display: flex;
    flex-direction: column;
    gap: var(--tv-gutter);
    padding: var(--tv-gutter);
    flex: 1 1 auto;
}

.tv-resumen {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: var(--tv-gutter);
}

.tv-cuenta {
    display: flex;
    align-items: center;
    gap: clamp(10px, 1vw, 18px);
    padding: clamp(12px, 1.1vw, 22px);
}

.tv-cuenta-ico {
    display: grid;
    flex: 0 0 auto;
    place-items: center;
    width: clamp(42px, 3.4vw, 68px);
    height: clamp(42px, 3.4vw, 68px);
    font-size: clamp(18px, 1.5vw, 30px);
    border-radius: 14px;
    box-shadow: inset 0 1px rgba(255, 255, 255, .35);
}

.tv-cuenta b {
    display: block;
    font-size: clamp(30px, 3vw, 62px);
    font-weight: 800;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

.tv-cuenta span {
    font-size: clamp(13px, 1vw, 20px);
    font-weight: 800;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--tv-suave);
}

.tv-cuenta--espera .tv-cuenta-ico { color: #1a1300; background: linear-gradient(135deg, #ffe082, #ffb300); }
.tv-cuenta--llamado .tv-cuenta-ico { color: #ffffff; background: linear-gradient(135deg, #4dd0e1, #00a2c0); }
.tv-cuenta--consulta .tv-cuenta-ico { color: #ffffff; background: linear-gradient(135deg, #26c6a6, #008a7a); }
.tv-cuenta--atendido .tv-cuenta-ico { color: #0b1c27; background: linear-gradient(135deg, #e3ebf2, #a9c4d1); }

.tv-banner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px clamp(14px, 1.4vw, 28px);
    padding: clamp(14px, 1.3vw, 26px) clamp(16px, 1.6vw, 32px);
}

.tv-banner[hidden] {
    display: none;
}

.tv-banner .tv-etq {
    margin: 0;
}

.tv-banner-nombre {
    font-size: clamp(30px, 3.4vw, 72px);
    font-weight: 800;
    line-height: 1.05;
    word-break: break-word;
}

.tv-banner-dest {
    font-size: clamp(20px, 2.1vw, 44px);
    font-weight: 800;
    color: var(--tv-oro);
}

.tv-banner.is-nuevo {
    border-color: rgba(0, 162, 192, .8);
    animation: tvHalo 1.2s ease-in-out 4;
}

.tv-turnos {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 560px), 1fr));
    gap: clamp(8px, .7vw, 14px);
    margin: 0;
    padding: 0;
    list-style: none;
}

.tv-turnos .tv-fila {
    grid-template-columns: auto minmax(0, 1fr) auto;
}

.tv-turnos .tv-fila:first-child {
    background: rgba(255, 255, 255, .05);
    border-color: var(--tv-linea);
}

.tv-turnos .tv-fila.is-llamado {
    background: linear-gradient(90deg, rgba(0, 162, 192, .26), rgba(0, 162, 192, .06));
    border-color: rgba(0, 162, 192, .6);
}

.tv-turnos .tv-fila.is-atendido {
    opacity: .6;
}

/* Chips de estado */
.tv-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    font-size: clamp(13px, 1vw, 20px);
    font-weight: 800;
    white-space: nowrap;
    border-radius: 999px;
}

.tv-chip::before {
    content: "";
    width: .6em;
    height: .6em;
    border-radius: 50%;
    background: currentColor;
}

.tv-chip--espera { color: #ffd54f; background: rgba(255, 213, 79, .14); box-shadow: inset 0 0 0 1px rgba(255, 213, 79, .4); }
.tv-chip--llamado { color: #7fe3f2; background: rgba(0, 162, 192, .2); box-shadow: inset 0 0 0 1px rgba(127, 227, 242, .5); }
.tv-chip--consulta { color: #6ff0cf; background: rgba(0, 162, 144, .18); box-shadow: inset 0 0 0 1px rgba(111, 240, 207, .4); }
.tv-chip--atendido { color: #c8d6df; background: rgba(255, 255, 255, .08); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .2); }

.tv-chip--llamado::before {
    animation: tvLatido 1.2s ease-in-out infinite;
}

@keyframes tvLatido {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: .35; transform: scale(.7); }
}

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 1100px) {
    .tv-main {
        grid-template-columns: minmax(0, 1fr);
    }
    .tv-espera,
    .tv-historial {
        grid-column: auto;
        grid-row: auto;
    }
    .tv-hist-lista {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .tv-resumen {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 600px) {
    .tv-head {
        flex-direction: column;
        align-items: flex-start;
    }
    .tv-head-der {
        justify-content: space-between;
        width: 100%;
    }
    .tv-reloj {
        text-align: left;
    }
    .tv-llamado {
        min-height: 0;
    }
    .tv-fila,
    .tv-turnos .tv-fila {
        grid-template-columns: auto minmax(0, 1fr);
    }
    .tv-fila-der,
    .tv-fila > .tv-chip {
        grid-column: 2 / 3;
        justify-self: start;
        text-align: left;
    }
}

@media (prefers-reduced-motion: reduce) {
    .tv-llamado.is-nuevo,
    .tv-banner.is-nuevo,
    .tv-chip--llamado::before {
        animation: none !important;
    }
}

/* ── Volver al sistema ───────────────────────────────────────────────── */
/* Flota arriba al centro (entre la marca y el reloj); en el televisor se
   oculta tras 4 s sin uso. */
.tv-volver {
    position: fixed;
    top: 14px;
    left: 50%;
    z-index: 50;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    padding: 0 16px;
    border: 1px solid rgba(153, 246, 228, .35);
    border-radius: 999px;
    background: linear-gradient(180deg, rgba(15, 46, 66, .95), rgba(4, 25, 40, .95));
    box-shadow: 0 8px 24px -10px rgba(0, 0, 0, .8), inset 0 1px rgba(255, 255, 255, .12);
    color: #ccfbf1;
    font: 700 15px/1 'Manrope', system-ui, sans-serif;
    text-decoration: none;
    opacity: 0;
    transform: translate(-50%, -6px);
    pointer-events: none;
    transition: opacity .2s ease, transform .2s ease;
}

body.tv-con-volver .tv-volver,
.tv-volver:focus-visible {
    opacity: 1;
    transform: translate(-50%, 0);
    pointer-events: auto;
}

.tv-volver:hover {
    color: #fff;
    border-color: rgba(153, 246, 228, .7);
    text-decoration: none;
}

.tv-volver:focus-visible {
    outline: 3px solid rgba(45, 212, 191, .6);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    .tv-volver { transition: none; }
}
