:root {
    --primary: #F37021;
    --primary-hover: #d9580b;
    --primary-glow: rgba(243, 112, 33, 0.35);
    --bg-dark: #07131e;
    --bg-surface: #0c1a29;
    --card-bg: rgba(255, 255, 255, 0.04);
    --card-border: rgba(255, 255, 255, 0.08);
    --text-main: #f0f4f8;
    --text-muted: #8fa0b5;
    --danger: #ff3344;
    --warning: #ffb800;
    --success: #00e676;
    --glass: rgba(255, 255, 255, 0.07);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Outfit', sans-serif;
}

body {
    background: var(--bg-dark);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

.cockpit-container {
    max-width: 1040px;
    width: 100%;
    margin: 0 auto;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    flex: 1;
}

/* HEADER PRINCIPAL */
.cockpit-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    background: var(--bg-surface);
    border: 1px solid var(--card-border);
    border-radius: 18px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.brand-master {
    display: flex;
    align-items: center;
    gap: 16px;
}

.brand-master-logo {
    height: 48px;
    width: auto;
    border-radius: 10px;
    box-shadow: 0 0 15px rgba(243, 112, 33, 0.25);
}

.brand-master-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.brand-master-title {
    font-size: 1.55rem;
    font-weight: 800;
    color: #fff;
    letter-spacing: 0.5px;
    line-height: 1.1;
}

.brand-master-title .accent {
    color: var(--primary);
}

.driver-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.88rem;
    color: var(--text-muted);
}

.driver-name-text {
    color: #fff;
    font-weight: 600;
}

.unit-tag {
    background: rgba(243, 112, 33, 0.15);
    border: 1px solid rgba(243, 112, 33, 0.4);
    color: var(--primary);
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 700;
}

.header-right-controls {
    display: flex;
    align-items: center;
    gap: 14px;
}

.status-indicator-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(0, 230, 118, 0.1);
    border: 1px solid rgba(0, 230, 118, 0.3);
    padding: 8px 14px;
    border-radius: 30px;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--success);
}

.status-indicator-pill.active {
    background: rgba(0, 230, 118, 0.2);
    border-color: #00e676;
}

.status-dot {
    width: 8px;
    height: 8px;
    background: var(--success);
    border-radius: 50%;
    box-shadow: 0 0 8px var(--success);
    animation: blink-dot 2s infinite ease-in-out;
}

@keyframes blink-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.settings-gear-btn {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--card-border);
    color: #fff;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.settings-gear-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    transform: rotate(30deg);
}

/* ======================================================== */
/* ÁREA CENTRAL DE VIDEO (STAGE FRAME)                      */
/* ======================================================== */

.stage-section {
    width: 100%;
}

.stage-frame {
    position: relative;
    width: 100%;
    height: 380px;
    background: #000;
    border: 1px solid var(--card-border);
    border-radius: 20px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.9), 0 8px 30px rgba(0, 0, 0, 0.4);
}

/* WEBCAM REAL: 100% OPACIDAD, ESPEJADA COMO EN UN AUTO */
#webcam {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1); /* Espejado natural para el conductor */
    z-index: 1;
}

/* CANVAS DE MALLA FACIAL */
#output_canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    transform: scaleX(-1);
    z-index: 2;
}

/* Standby inicial */
.cam-standby-overlay {
    position: absolute;
    z-index: 3;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-align: center;
    background: rgba(7, 19, 30, 0.85);
    backdrop-filter: blur(8px);
    padding: 30px;
    border-radius: 20px;
    border: 1px solid var(--card-border);
}

.standby-icon {
    font-size: 3rem;
    opacity: 0.7;
}

.cam-standby-overlay h3 {
    font-size: 1.3rem;
    color: #fff;
}

.cam-standby-overlay p {
    font-size: 0.85rem;
    color: var(--text-muted);
    max-width: 320px;
}

/* HUD DE EVENTO EN VIVO SUPERPUESTO */
.hud-event-display {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    background: rgba(7, 19, 30, 0.85);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 16px;
    padding: 10px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    text-align: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    transition: all 0.3s ease;
    max-width: 90%;
}

.hud-event-header {
    display: flex;
    align-items: center;
    gap: 8px;
}

.hud-badge-icon {
    font-size: 1.25rem;
}

.hud-event-title {
    font-size: 1.05rem;
    font-weight: 800;
    letter-spacing: 0.5px;
    color: #fff;
}

.hud-event-desc {
    font-size: 0.78rem;
    color: var(--text-muted);
}

/* Estados del HUD */
.hud-event-display.safe {
    border-color: rgba(0, 230, 118, 0.4);
}
.hud-event-display.safe .hud-event-title { color: var(--success); }

.hud-event-display.warning {
    border-color: rgba(255, 184, 0, 0.6);
    background: rgba(30, 22, 5, 0.9);
}
.hud-event-display.warning .hud-event-title { color: var(--warning); }

.hud-event-display.danger {
    border-color: rgba(255, 51, 68, 0.9);
    background: rgba(40, 5, 10, 0.95);
    box-shadow: 0 0 25px rgba(255, 51, 68, 0.6);
    animation: danger-hud 0.8s infinite alternate;
}
.hud-event-display.danger .hud-event-title { color: var(--danger); font-size: 1.15rem; }

@keyframes danger-hud {
    from { transform: translateX(-50%) scale(1); }
    to { transform: translateX(-50%) scale(1.03); }
}

/* ALERTA VISUAL DE FATIGA */
.alert-overlay {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(255, 0, 0, 0.35);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    animation: flash 0.4s infinite alternate;
}

.alert-overlay.active { display: flex; }

@keyframes flash {
    from { background: rgba(255, 0, 0, 0.25); }
    to { background: rgba(255, 0, 0, 0.65); }
}

.alert-content {
    background: #180305;
    border: 2px solid #ff3344;
    padding: 24px 30px;
    border-radius: 20px;
    text-align: center;
    box-shadow: 0 0 40px rgba(255, 51, 68, 0.9);
}

.alert-content .alert-icon { font-size: 2.8rem; }
.alert-content h2 { color: #ff3344; font-size: 1.6rem; margin: 8px 0; }
.alert-content p { color: #fff; font-size: 0.95rem; }

/* ======================================================== */
/* TELEMETRÍA Y MÉTRICAS                                    */
/* ======================================================== */

.telemetry-bar {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    width: 100%;
}

.telemetry-chip {
    background: var(--bg-surface);
    border: 1px solid var(--card-border);
    border-radius: 14px;
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chip-label {
    font-size: 0.68rem;
    text-transform: uppercase;
    font-weight: 700;
    color: var(--text-muted);
    letter-spacing: 0.5px;
}

.chip-value {
    font-size: 1.05rem;
    font-weight: 800;
    letter-spacing: 0.5px;
}

.chip-value.safe { color: var(--success); }
.chip-value.warn { color: var(--warning); }
.chip-value.danger { color: var(--danger); }

/* ======================================================== */
/* ACTION DOCK (BOTONES COMPACTOS)                          */
/* ======================================================== */

.action-dock {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    background: var(--bg-surface);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    padding: 12px 18px;
}

.dock-left, .dock-right {
    display: flex;
    align-items: center;
}

.dock-btn {
    border: none;
    border-radius: 12px;
    padding: 12px 22px;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s ease;
    font-family: 'Outfit';
}

.btn-monitor {
    background: var(--primary);
    color: #000;
    box-shadow: 0 4px 14px rgba(243, 112, 33, 0.35);
}

.btn-monitor:hover {
    background: var(--primary-hover);
    color: #fff;
    transform: translateY(-1px);
}

.btn-monitor.active {
    background: #e23b49;
    color: #fff;
    box-shadow: 0 4px 14px rgba(226, 59, 73, 0.4);
}

.btn-sos-compact {
    background: linear-gradient(135deg, #ff2233, #b80011);
    color: #fff;
    border: 1px solid #ff6677;
    box-shadow: 0 0 16px rgba(255, 34, 51, 0.45);
    font-weight: 800;
    letter-spacing: 0.5px;
}

.btn-sos-compact:hover {
    transform: scale(1.02);
    box-shadow: 0 0 24px rgba(255, 34, 51, 0.7);
}

.btn-sos-compact:active {
    transform: scale(0.97);
}

/* ======================================================== */
/* HISTORIAL DE EVENTOS                                     */
/* ======================================================== */

.history-section {
    width: 100%;
}

.history-card {
    background: var(--bg-surface);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    padding: 14px 18px;
}

.history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.history-header h4 {
    font-size: 0.88rem;
    font-weight: 700;
    color: #fff;
}

.history-count {
    font-size: 0.72rem;
    color: var(--primary);
    background: rgba(243, 112, 33, 0.12);
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 600;
}

.event-stream {
    list-style: none;
    max-height: 110px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.event-stream li {
    font-size: 0.82rem;
    color: var(--text-muted);
    padding: 4px 8px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.02);
}

.event-stream li.critical {
    color: var(--danger);
    background: rgba(255, 51, 68, 0.1);
    border-left: 3px solid var(--danger);
}

.event-empty-msg {
    color: #667e99 !important;
    font-style: italic;
    background: transparent !important;
}

/* ======================================================== */
/* MODALES Y CHECKIN                                        */
/* ======================================================== */

.overlay-screen {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(2, 8, 16, 0.95);
    backdrop-filter: blur(15px);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.checkin-card {
    background: var(--bg-surface);
    border: 1px solid var(--card-border);
    padding: 36px 32px;
    border-radius: 24px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
    text-align: center;
}

.input-group {
    text-align: left;
    margin-bottom: 14px;
}

.input-group label {
    display: block;
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-bottom: 6px;
    font-weight: 600;
}

.input-group input {
    width: 100%;
    padding: 12px 14px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--card-border);
    border-radius: 10px;
    color: #fff;
    font-size: 0.95rem;
    font-family: 'Outfit';
}

.input-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 10px var(--primary-glow);
}

.primary-btn {
    width: 100%;
    padding: 14px;
    background: var(--primary);
    color: #000;
    border: none;
    border-radius: 12px;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    font-family: 'Outfit';
    transition: all 0.2s;
}

.primary-btn:hover { background: var(--primary-hover); color: #fff; }

.secondary-btn {
    width: 100%;
    padding: 10px;
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    border: 1px solid var(--card-border);
    border-radius: 10px;
    cursor: pointer;
    font-family: 'Outfit';
}

.danger-btn {
    width: 100%;
    padding: 10px;
    background: rgba(255, 51, 68, 0.15);
    color: var(--danger);
    border: 1px solid rgba(255, 51, 68, 0.3);
    border-radius: 10px;
    margin-top: 10px;
    cursor: pointer;
    font-family: 'Outfit';
}

/* Side Menu */
.side-menu {
    position: fixed;
    top: 0; right: -320px;
    width: 320px; height: 100%;
    background: #081522;
    border-left: 1px solid var(--card-border);
    z-index: 2500;
    transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    padding: 24px;
    box-shadow: -10px 0 30px rgba(0, 0, 0, 0.5);
}

.side-menu.active { right: 0; }

.menu-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
}

.menu-header h2 { font-size: 1.15rem; font-weight: 700; color: #fff; }
.menu-header button { background: transparent; border: none; color: var(--text-muted); font-size: 1.2rem; cursor: pointer; }

.setting-group { margin-bottom: 20px; }
.setting-group label { display: block; font-size: 0.8rem; color: var(--text-muted); margin-bottom: 8px; }
.setting-group select, .setting-group input[type="range"] {
    width: 100%;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    color: #fff;
    font-family: 'Outfit';
}

.toggle-switch { cursor: pointer; position: relative; display: inline-block; width: 50px; height: 26px; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(255, 255, 255, 0.1); border-radius: 34px; transition: 0.3s;
}
.slider:before {
    position: absolute; content: ""; height: 18px; width: 18px; left: 4px; bottom: 4px;
    background: #fff; border-radius: 50%; transition: 0.3s;
}
input:checked + .slider { background: var(--primary); }
input:checked + .slider:before { transform: translateX(24px); }

/* SOS Modal */
.sos-modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.88);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
}

.sos-modal-card {
    background: #180305;
    border: 2px solid #ff3344;
    border-radius: 22px;
    padding: 28px;
    max-width: 420px;
    width: 90%;
    text-align: center;
    box-shadow: 0 0 50px rgba(255, 51, 68, 0.6);
}

.sos-modal-card h2 { color: #ff3344; font-size: 1.6rem; margin-bottom: 10px; }
.sos-modal-card p { color: #e2e8f0; font-size: 0.9rem; margin-bottom: 16px; line-height: 1.4; }

.sos-meta-box {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 12px;
    border-radius: 12px;
    text-align: left;
    font-size: 0.82rem;
    margin-bottom: 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.btn-cancel-sos {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.25);
    padding: 10px 20px;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 700;
    font-family: 'Outfit';
}

/* Loader */
.loading-screen {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(2, 8, 16, 0.95);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 3500;
}

.loader {
    width: 48px; height: 48px;
    border: 4px solid var(--card-border);
    border-top: 4px solid var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 14px;
}

@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

.btn-skip {
    margin-top: 15px;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border: 1px solid var(--card-border);
    border-radius: 20px;
    padding: 6px 16px;
    font-size: 0.8rem;
    cursor: pointer;
    font-family: 'Outfit';
}

.cockpit-footer {
    text-align: center;
    padding: 10px;
    font-size: 0.72rem;
    color: #556c82;
    margin-top: auto;
}

@media (max-width: 768px) {
    .cockpit-container { padding: 12px 14px; }
    .stage-frame { height: 290px; }
    .telemetry-bar { grid-template-columns: repeat(2, 1fr); }
    .brand-master-title { font-size: 1.25rem; }
    .brand-master-logo { height: 38px; }
    .action-dock { flex-direction: column; gap: 10px; }
    .dock-left, .dock-right { width: 100%; justify-content: center; }
    .dock-btn { width: 100%; justify-content: center; }
}

/* Estilos para estado cargando de cámara */
.btn-monitor.loading {
    background: #f59e0b !important;
    color: #000 !important;
    cursor: wait !important;
    box-shadow: 0 4px 14px rgba(245, 158, 11, 0.4) !important;
}
