/* ===== RESET & BASE ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', 'Consolas', monospace;
    background: #0a0a0a;
    color: #e0e0e0;
    min-height: 100vh;
    overflow: hidden;
}

/* ===== PANTALLAS ===== */
.pantalla {
    display: none;
    width: 100vw;
    height: 100vh;
}

.pantalla.activa {
    display: flex;
    justify-content: center;
    align-items: center;
}

/* ===== BOTONES ===== */
.btn {
    padding: 12px 32px;
    border: none;
    border-radius: 6px;
    font-size: 16px;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.btn:hover {
    transform: scale(1.03);
}

.btn-primary {
    background: #00cc99;
    color: #0a0a0a;
    font-weight: bold;
}

.btn-primary:hover {
    background: #00ffbb;
}

.btn-secondary {
    background: #222;
    color: #aaa;
    border: 1px solid #444;
}

.btn-secondary:hover {
    background: #333;
    color: #fff;
}

.btn-danger {
    background: #cc2200;
    color: white;
    font-weight: bold;
}

.btn-danger:hover {
    background: #ff3300;
}

/* ===== PANTALLA LOGIN ===== */
.login-card {
    background: #111;
    border: 1px solid #333;
    border-radius: 12px;
    padding: 50px 40px;
    text-align: center;
    max-width: 420px;
    width: 90%;
}

.titulo-principal {
    font-size: 36px;
    color: #00ffcc;
    letter-spacing: 4px;
    margin-bottom: 8px;
}

.subtitulo {
    color: #777;
    font-size: 14px;
    margin-bottom: 40px;
}

.form-group {
    margin-bottom: 30px;
    text-align: left;
}

.form-group label {
    display: block;
    font-size: 12px;
    color: #888;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.form-group input {
    width: 100%;
    padding: 12px 16px;
    background: #0a0a0a;
    border: 1px solid #444;
    border-radius: 6px;
    color: #fff;
    font-size: 16px;
    font-family: inherit;
}

.form-group input:focus {
    outline: none;
    border-color: #00ffcc;
}

.login-card .btn {
    width: 100%;
    margin-bottom: 12px;
}

.estado-conexion {
    margin-top: 20px;
    font-size: 12px;
    color: #666;
}

.dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 4px;
}

.dot.online {
    background: #00ff66;
}

.dot.offline {
    background: #ff3300;
}

/* ===== PANTALLA DETECCION ===== */
.deteccion-layout {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* Header */
.det-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(0, 0, 0, 0.85);
    padding: 8px 16px;
    height: 48px;
    z-index: 10;
}

.det-titulo {
    font-size: 18px;
    color: #00ffcc;
    font-weight: bold;
    letter-spacing: 2px;
}

.det-estado {
    padding: 4px 24px;
    border-radius: 4px;
    font-weight: bold;
    font-size: 14px;
    letter-spacing: 2px;
    text-align: center;
    border: 2px solid;
}

.det-estado.operativo {
    color: #00ff66;
    border-color: #00ff66;
    background: rgba(0, 255, 102, 0.1);
}

.det-estado.somnolencia {
    color: #ffa500;
    border-color: #ffa500;
    background: rgba(255, 165, 0, 0.1);
}

.det-estado.microsueno {
    color: #ff2200;
    border-color: #ff2200;
    background: rgba(255, 0, 0, 0.15);
    animation: parpadeo 0.5s infinite;
}

@keyframes parpadeo {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.det-header-right {
    display: flex;
    gap: 20px;
    font-size: 14px;
}

#det-incidentes {
    color: #ff6666;
    font-weight: bold;
}

#det-tiempo {
    color: #aaa;
}

/* Video container */
.video-container {
    flex: 1;
    position: relative;
    background: #000;
    overflow: hidden;
}

#video {
    width: 100%;
    height: 100%;
    object-fit: fill;
    transform: scaleX(-1);
}

#canvas-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    transform: scaleX(-1);
}

/* Calibracion */
.calibracion-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.3);
    z-index: 5;
}

.calibracion-overlay.oculto {
    display: none;
}

.calibracion-barra {
    background: rgba(0, 0, 0, 0.7);
    padding: 16px 32px;
    border-radius: 8px;
    border: 1px solid #00ffcc;
    text-align: center;
}

#calibracion-texto {
    color: #00ffcc;
    font-size: 14px;
    letter-spacing: 1px;
}

.calibracion-progreso {
    margin-top: 10px;
    width: 300px;
    height: 8px;
    background: #222;
    border-radius: 4px;
    overflow: hidden;
}

.calibracion-fill {
    height: 100%;
    width: 0%;
    background: #00ffcc;
    transition: width 0.1s;
}

/* Alerta microsueno */
.alerta-microsueno {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 28px;
    font-weight: bold;
    color: #ff2200;
    text-shadow: 0 0 20px rgba(255, 0, 0, 0.8);
    letter-spacing: 3px;
    z-index: 6;
    animation: parpadeo 0.5s infinite;
}

.alerta-microsueno.oculto {
    display: none;
}

/* Sin rostro */
.sin-rostro {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 22px;
    font-weight: bold;
    color: #ff2200;
    text-shadow: 0 0 15px rgba(255, 0, 0, 0.6);
    letter-spacing: 2px;
    z-index: 6;
}

.sin-rostro.oculto {
    display: none;
}

/* Borde de estado en video */
.video-container.borde-operativo {
    border: 3px solid #00ff66;
}

.video-container.borde-somnolencia {
    border: 3px solid #ffa500;
}

.video-container.borde-microsueno {
    border: 3px solid #ff2200;
    animation: borde-flash 0.5s infinite;
}

@keyframes borde-flash {
    0%, 100% { border-color: #ff2200; }
    50% { border-color: #880000; }
}

/* Footer / Panel inferior */
.det-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(0, 0, 0, 0.85);
    padding: 10px 16px;
    z-index: 10;
}

.det-info {
    display: flex;
    gap: 20px;
}

.info-item {
    text-align: center;
}

.info-label {
    display: block;
    font-size: 10px;
    color: #666;
    letter-spacing: 1px;
}

.info-valor {
    font-size: 18px;
    font-weight: bold;
    color: #00ff66;
}

.info-valor.somnolencia {
    color: #ffa500;
}

.info-valor.microsueno {
    color: #ff2200;
}

/* Gauges */
.det-gauge-container {
    display: flex;
    gap: 6px;
    align-items: flex-end;
}

.gauge {
    width: 14px;
    height: 80px;
    background: #111;
    border: 1px solid #333;
    border-radius: 3px;
    position: relative;
    overflow: hidden;
}

.gauge-fill {
    position: absolute;
    bottom: 0;
    width: 100%;
    height: 0%;
    background: #00ff66;
    transition: height 0.15s, background 0.15s;
}

.gauge-thr-line {
    position: absolute;
    left: 0;
    width: 100%;
    height: 2px;
    background: #ff2200;
    bottom: 50%;
}

/* Log eventos */
.log-eventos {
    position: absolute;
    bottom: 70px;
    left: 10px;
    z-index: 10;
    font-size: 12px;
}

.log-evento {
    margin-bottom: 2px;
    opacity: 0.8;
}

.log-evento.operativo { color: #00ff66; }
.log-evento.somnolencia { color: #ffa500; }
.log-evento.microsueno { color: #ff2200; }

/* ===== PANTALLA REPORTE ===== */
#pantalla-reporte.activa {
    display: flex;
    justify-content: center;
    align-items: center;
}

.reporte-card {
    background: #111;
    border: 1px solid #333;
    border-radius: 12px;
    padding: 40px;
    max-width: 600px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
}

.reporte-card h2 {
    color: #00ffcc;
    margin-bottom: 24px;
    text-align: center;
    letter-spacing: 2px;
}

.reporte-contenido {
    margin-bottom: 24px;
}

.reporte-fila {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid #222;
}

.reporte-fila .label {
    color: #888;
}

.reporte-fila .valor {
    color: #fff;
    font-weight: bold;
}

.reporte-fila .valor.critico {
    color: #ff2200;
}

.reporte-eventos {
    margin-top: 16px;
}

.reporte-eventos h3 {
    color: #aaa;
    font-size: 14px;
    margin-bottom: 8px;
}

.reporte-evento-item {
    font-size: 12px;
    padding: 4px 0;
    border-bottom: 1px solid #1a1a1a;
}

.reporte-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.reporte-actions .btn {
    flex: 1;
}

/* ===== PANTALLA HISTORIAL ===== */
#pantalla-reportes.activa {
    display: flex;
    justify-content: center;
    align-items: center;
}

.reportes-card {
    background: #111;
    border: 1px solid #333;
    border-radius: 12px;
    padding: 40px;
    max-width: 700px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
}

.reportes-card h2 {
    color: #00ffcc;
    margin-bottom: 24px;
    text-align: center;
}

.reportes-lista {
    margin-bottom: 20px;
}

.reporte-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    background: #0a0a0a;
    border: 1px solid #222;
    border-radius: 6px;
    margin-bottom: 8px;
}

.reporte-item-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.reporte-item-operador {
    color: #fff;
    font-weight: bold;
}

.reporte-item-fecha {
    font-size: 12px;
    color: #666;
}

.reporte-item-stats {
    display: flex;
    gap: 16px;
    font-size: 13px;
}

.stat-inc {
    color: #ff6666;
}

.stat-dur {
    color: #aaa;
}

.reportes-vacio {
    text-align: center;
    color: #555;
    padding: 40px;
}

/* ===== RESPONSIVE MOBILE ===== */
@media (max-width: 768px) {
    body {
        overflow: auto;
    }

    /* Login */
    .login-card {
        padding: 30px 20px;
    }

    .titulo-principal {
        font-size: 26px;
    }

    /* Header deteccion */
    .det-header {
        padding: 6px 10px;
        height: auto;
        flex-wrap: wrap;
        gap: 4px;
    }

    .det-titulo {
        font-size: 14px;
    }

    .det-estado {
        padding: 3px 12px;
        font-size: 11px;
        order: 3;
        width: 100%;
        margin-top: 4px;
    }

    .det-header-right {
        gap: 10px;
        font-size: 12px;
    }

    /* Video */
    .video-container {
        min-height: 50vh;
    }

    /* Calibracion */
    .calibracion-barra {
        padding: 12px 16px;
    }

    #calibracion-texto {
        font-size: 11px;
    }

    .calibracion-progreso {
        width: 200px;
    }

    /* Alertas */
    .alerta-microsueno {
        font-size: 18px;
        letter-spacing: 1px;
    }

    .sin-rostro {
        font-size: 16px;
    }

    /* Footer */
    .det-footer {
        padding: 8px 10px;
        flex-wrap: wrap;
        gap: 8px;
    }

    .det-info {
        gap: 12px;
        width: 100%;
        justify-content: center;
    }

    .info-valor {
        font-size: 14px;
    }

    .info-label {
        font-size: 9px;
    }

    .det-gauge-container {
        display: none;
    }

    .det-footer .btn-danger {
        width: 100%;
        padding: 10px;
        font-size: 14px;
    }

    /* Log eventos */
    .log-eventos {
        bottom: 120px;
        font-size: 10px;
    }

    /* Reporte */
    .reporte-card {
        padding: 20px 16px;
    }

    .reporte-fila {
        flex-direction: column;
        gap: 2px;
    }

    .reporte-fila .label {
        font-size: 12px;
    }

    .reporte-fila .valor {
        font-size: 14px;
    }

    .reporte-actions {
        flex-direction: column;
    }

    /* Historial */
    .reportes-card {
        padding: 20px 16px;
    }

    .reporte-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
    }
}
