/* ==========================================================================
   1. VARIÁVEIS, TEMAS E ACESSIBILIDADE
   Tokens base definidos em ux/ux-tokens.css (Sprint UX-001)
   ========================================================================== */

/* ---------------------------------------------------------------------------
   PATCH DE LIMPEZA — Z-index + tipografia mínima (a11y)
   Escala canônica: --z-* em ux/ux-tokens.css
   --------------------------------------------------------------------------- */
:root {
    /* Fallback se tokens ainda não carregaram */
    --z-base: 1;
    --z-raised: 10;
    --z-sticky: 100;
    --z-sidebar: 200;
    --z-topbar: 300;
    --z-dropdown: 400;
    --z-overlay: 500;
    --z-modal: 600;
    --z-drawer: 650;
    --z-toast: 700;
    --z-ialtum: 850;
    --z-spotlight: 880;
    --z-login: 900;
    --z-boot: 950;
}

/* Camadas principais — usam a escala (sem milhões) */
#toastContainer { z-index: var(--z-toast) !important; }
#loginScreen { z-index: var(--z-login) !important; }
.overlay { z-index: var(--z-overlay) !important; }
.landing-overlay { z-index: var(--z-modal) !important; }
.celebration-overlay { z-index: var(--z-spotlight) !important; }
.context-panel { z-index: var(--z-drawer) !important; }
.sidebar { z-index: var(--z-sidebar); }
.topbar { z-index: var(--z-topbar); }
.theme-dropdown { z-index: var(--z-dropdown); }
.ai-drawer,
#aiDrawer.ai-drawer { z-index: var(--z-ialtum) !important; }
.btn-ialtum { z-index: var(--z-ialtum) !important; }
#airbase-boot-error { z-index: var(--z-boot) !important; }

/* Camadas de produto (overlays que usavam milhões) */
.first-impact-overlay,
.wow-moment-overlay { z-index: var(--z-spotlight) !important; }
.flight-briefing-overlay { z-index: var(--z-modal) !important; }
.flight-debriefing-overlay { z-index: calc(var(--z-modal) + 10) !important; }
.ialtum-proactive-chip { z-index: 13050 !important; }
.login-pilot-transition { z-index: calc(var(--z-login) + 20) !important; }
.pm-toast,
.dopamine-toast { z-index: var(--z-toast) !important; }

/* Piso tipográfico 11px — labels/captions legíveis sem perder o tom premium */
.oswald.login-hint,
.oswald.login-role-hint,
.oswald.login-kicker,
.oswald.login-section-label,
.oswald.login-hero-tagline,
.oswald.login-demo-divider,
.oswald.topbar-meta,
.oswald.topbar-route,
.sidebar-kicker,
.nav-title,
.btn-topbar {
    font-size: max(11px, 0.6875rem);
}

body.high-contrast { --text-muted: var(--text-main); --border-card: var(--accent); --bg-card: var(--bg-base); border-width: 2px; }
body.reduce-motion * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
body.large-text { font-size: 110%; }

body.theme-gestao:not(.light-mode) {
    background-image: radial-gradient(ellipse 70% 45% at 50% 0%, rgba(12, 43, 91, 0.14) 0%, transparent 55%);
}
body.theme-time:not(.light-mode) {
    --bg-base: #070910;
    --bg-card: rgba(14, 18, 28, 0.78);
    --border-card: rgba(92, 154, 255, 0.12);
    background-image: radial-gradient(ellipse 60% 40% at 85% 0%, rgba(92, 154, 255, 0.1) 0%, transparent 50%);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { background-color: var(--bg-base); color: var(--text-main); font-family: var(--font-body); font-size: var(--text-body); line-height: var(--leading-body); height: 100vh; overflow: hidden; transition: background 0.4s ease, color 0.4s ease, font-size 0.4s ease; }
::-webkit-scrollbar { width: 4px; } ::-webkit-scrollbar-track { background: transparent; } ::-webkit-scrollbar-thumb { background: var(--text-muted); }

.cinzel { font-family: var(--font-display); transition: font-size var(--duration-normal) ease; }
.oswald { font-family: var(--font-ui); text-transform: uppercase; letter-spacing: var(--tracking-ui); }

/* ==========================================================================
   2. UTILITÁRIOS E BOTÕES
   ========================================================================== */
.mb-4 { margin-bottom: var(--space-1); } .mb-8 { margin-bottom: var(--space-2); } .mb-12 { margin-bottom: var(--space-3); } .mb-16 { margin-bottom: var(--space-4); } .mb-24 { margin-bottom: var(--space-6); } .mb-32 { margin-bottom: var(--space-7); }
.mt-8 { margin-top: var(--space-2); } .mt-16 { margin-top: var(--space-4); } .mt-24 { margin-top: var(--space-6); }
.flex { display: flex; } .align-center { align-items: center; } .gap-4 { gap: var(--space-1); } .gap-8 { gap: var(--space-2); } .gap-16 { gap: var(--space-4); } .gap-24 { gap: var(--space-6); }
.justify-between { justify-content: space-between; } .text-center { text-align: center; } .w-100 { width: 100%; }

.btn-gold {
    background: linear-gradient(135deg, var(--accent-premium) 0%, #c49a3f 100%);
    color: var(--preto);
    border: none;
    padding: var(--space-3) var(--space-6);
    border-radius: var(--radius-md);
    font-size: var(--text-body);
    font-weight: 600;
    cursor: pointer;
    transition: var(--transicao);
    font-family: var(--font-ui);
    letter-spacing: var(--tracking-ui);
}
body.light-mode .btn-gold { color: var(--preto); }
body.dark-mode .btn-gold {
    box-shadow: 0 4px 16px rgba(212, 174, 87, 0.15);
}
body.dark-mode .btn-gold:hover {
    box-shadow: 0 8px 24px rgba(212, 174, 87, 0.22);
}
.btn-gold:hover { transform: translateY(-2px); box-shadow: var(--shadow-premium); filter: brightness(1.06); }
.btn-outline { background: transparent; border: 1px solid var(--border-card); color: var(--text-main); padding: var(--space-3) var(--space-6); border-radius: var(--radius-md); font-size: var(--text-label); cursor: pointer; transition: var(--transicao); font-family: var(--font-ui); }
.btn-outline:hover { border-color: var(--accent); color: var(--accent); box-shadow: 0 0 0 1px var(--accent-muted); background: var(--accent-muted); }
.btn-small { padding: 6px 12px; font-size: 11px; }

.card { background: var(--bg-card); border: 1px solid var(--border-card); border-radius: var(--radius-xl); padding: var(--space-6); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); transition: var(--transicao); position: relative; box-shadow: var(--shadow-sm); overflow: hidden; }
.card.interactive:hover { transform: translateY(-3px); border-color: rgba(92, 154, 255, 0.35); box-shadow: var(--shadow-md); cursor: pointer; }

.status-stable { border-left: 4px solid var(--success) !important; }
.status-alert { border-left: 4px solid var(--alert) !important; }
.status-danger { border-left: 4px solid var(--danger) !important; background: linear-gradient(90deg, rgba(192,57,43,0.05), transparent); }
.status-info { border-left: 4px solid var(--info) !important; }

.grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: var(--space-6); margin-bottom: var(--space-6); }
.col-3 { grid-column: span 3; } .col-4 { grid-column: span 4; } .col-6 { grid-column: span 6; } .col-8 { grid-column: span 8; } .col-12 { grid-column: span 12; }

.badge { padding: 4px 8px; border-radius: 4px; font-size: 11px; font-family: 'Oswald'; letter-spacing: 1px; display: inline-block; border: 1px solid transparent; }
.badge.roi { background: rgba(46, 139, 87, 0.1); color: var(--success); border-color: rgba(46, 139, 87, 0.3); }
.badge.impact { background: rgba(212, 174, 87, 0.1); color: var(--ouro); border-color: rgba(212, 174, 87, 0.3); }
.badge.xp { background: rgba(92, 154, 255, 0.1); color: var(--info); border-color: rgba(92, 154, 255, 0.3); }
.badge.danger { background: rgba(192, 57, 43, 0.1); color: var(--danger); border-color: rgba(192, 57, 43, 0.3); }

.progress-bg { background: var(--border-card); height: 6px; border-radius: 3px; width: 100%; overflow: hidden; margin-top: 8px; }
.progress-bar { height: 100%; background: var(--accent); transition: width 1s ease; }

.pulse-dot { width: 8px; height: 8px; background: var(--success); border-radius: 50%; box-shadow: 0 0 8px var(--success); animation: pulse 2s infinite; display: inline-block; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(46,139,87,0.7); } 70% { box-shadow: 0 0 0 8px rgba(46,139,87,0); } 100% { box-shadow: 0 0 0 0 rgba(46,139,87,0); } }

/* Componentes de View Internos */
.sub-nav { display: flex; gap: 16px; border-bottom: 1px solid var(--border-card); margin-bottom: 24px; padding-bottom: 8px; }
.sub-nav-item { font-family: 'Oswald'; font-size: 11px; color: var(--text-muted); cursor: pointer; padding-bottom: 8px; border-bottom: 2px solid transparent; transition: var(--transicao); }
.sub-nav-item:hover { color: var(--text-main); }
.sub-nav-item.active { color: var(--accent); border-bottom-color: var(--accent); }

.op-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 24px; padding-bottom: 24px; border-bottom: 1px solid var(--border-card); }
.op-stats { display: flex; gap: 24px; background: var(--bg-card); padding: 12px 24px; border-radius: 8px; border: 1px solid var(--border-card); }
.stat-item { display: flex; flex-direction: column; }

.timeline { border-left: 2px solid var(--border-card); padding-left: 24px; margin-left: 12px; }
.timeline-item { position: relative; margin-bottom: 24px; }
.timeline-item::before { content: ''; position: absolute; left: -31px; top: 0; width: 12px; height: 12px; border-radius: 50%; background: var(--accent); border: 2px solid var(--bg-base); }

#toastContainer { position: fixed; top: 84px; right: 18px; left: auto; bottom: auto; transform: none; z-index: var(--z-toast); display: flex; flex-direction: column; align-items: flex-end; gap: 8px; max-width: min(420px, calc(100vw - 36px)); }
.toast {
    background: var(--chrome-panel, rgba(14, 18, 28, 0.94));
    border: 1px solid var(--chrome-accent-line, rgba(92, 154, 255, 0.35));
    color: var(--text-main);
    padding: 12px 24px;
    border-radius: var(--radius-md);
    font-family: var(--font-ui);
    font-size: 11px;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    box-shadow: var(--shadow-md);
    animation: slideUp 0.3s forwards, fadeOut 0.5s 3.5s forwards;
    display: flex;
    align-items: center;
    gap: 12px;
}
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }

/* ==========================================================================
   3. ESTRUTURA PRINCIPAL E NAVEGAÇÃO
   ========================================================================== */
#loginScreen { position: fixed; inset: 0; background: var(--bg-base); z-index: var(--z-login); display: flex; justify-content: center; align-items: center; transition: opacity 0.8s, visibility 0.8s; }
.login-box input { width: 100%; padding: 14px; background: var(--bg-base); border: 1px solid var(--border-card); margin-bottom: 16px; color: var(--text-main); font-family: 'Oswald'; border-radius: 8px; transition: var(--transicao);}

#appLayout { display: none; height: 100vh; opacity: 0; transition: opacity 1s; flex-direction: row; }
#appLayout.is-active { display: flex; opacity: 1; }
.sidebar { width: 280px; background: var(--glass-bg); border-right: 1px solid var(--border-card); display: flex; flex-direction: column; z-index: 100; backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); transition: var(--transicao); }
.main-wrapper { flex: 1; display: flex; flex-direction: column; overflow: hidden; position: relative;}

.sidebar-header { min-height: 80px; height: auto; padding: 12px 8px; display: flex; flex-direction: column; justify-content: center; align-items: center; border-bottom: 1px solid var(--border-card); overflow: visible; }
.nav-section { margin-top: 24px; margin-bottom: 12px; }
.nav-title { padding: 0 24px; font-size: var(--text-label); color: var(--text-muted); margin-bottom: 12px; letter-spacing: var(--tracking-wide); line-height: var(--leading-normal); }

.nav-item { padding: 11px 24px; display: flex; align-items: center; gap: 12px; color: var(--text-muted); font-size: 13px; cursor: pointer; transition: var(--transicao); border-left: 3px solid transparent; position: relative; line-height: 1.35; }
.nav-item:hover { color: var(--text-main); background: linear-gradient(90deg, rgba(128,128,128,0.05) 0%, transparent 100%); }
.nav-item.active { color: var(--text-main); border-left-color: var(--accent); background: linear-gradient(90deg, var(--accent-muted) 0%, transparent 100%); }
.nav-item.active::after { content: ''; position: absolute; right: 0; top: 50%; transform: translateY(-50%); width: 3px; height: 3px; border-radius: 50%; background: var(--accent-premium); opacity: 0.85; }

.topbar { height: 72px; border-bottom: 1px solid var(--border-card); display: flex; justify-content: space-between; align-items: center; padding: 0 40px; background: var(--glass-bg); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); z-index: 90; transition: var(--transicao); }
.content { flex: 1; padding: var(--space-8); overflow-y: auto; scroll-behavior: smooth; position: relative; }
.view-section { display: none; } .view-section.active { display: block; animation: fadeIn 0.5s forwards; max-width: none; width: 100%; margin-left: auto; margin-right: auto; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.btn-topbar { background: transparent; border: 1px solid var(--border-card); color: var(--text-main); padding: 8px 16px; border-radius: 20px; display: flex; align-items: center; gap: 8px; cursor: pointer; transition: var(--transicao); font-size: 11px; font-family: 'Oswald'; position: relative; }
.btn-topbar:hover { border-color: var(--accent); color: var(--accent); background: var(--bg-card); }

.theme-dropdown { position: absolute; top: 50px; right: 0; background: var(--bg-base); border: 1px solid var(--border-card); border-radius: 8px; padding: 8px; display: none; flex-direction: column; gap: 4px; box-shadow: var(--shadow-card); z-index: 100; min-width: 180px; }
.theme-dropdown.show { display: flex; animation: fadeIn 0.3s; }
.theme-opt { padding: 8px 16px; font-size: 11px; color: var(--text-muted); cursor: pointer; border-radius: 4px; transition: var(--transicao); font-family: 'Oswald'; display: flex; align-items: center; gap: 8px;}
.theme-opt:hover { background: var(--bg-card); color: var(--text-main); }

/* ==========================================================================
   4. INTELIGÊNCIA DE BORDO (IA) E CONTEXTO TÁTICO
   Visual do painel contextual: ux/ux-modals.css
   ========================================================================== */
.ctx-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-bottom: 32px; }
.ctx-group { padding-bottom: 12px; border-bottom: 1px solid var(--border-card); }

.ai-drawer { position: fixed; top: 0; right: -350px; width: 350px; height: 100vh; background: linear-gradient(180deg, #111111 0%, #050505 100%); border-left: 1px solid rgba(212, 174, 87, 0.2); box-shadow: -10px 0 30px rgba(0,0,0,0.8); z-index: var(--z-ialtum); display: flex; flex-direction: column; transition: right 0.5s cubic-bezier(0.16, 1, 0.3, 1); }
.ai-drawer.aberto, .ai-drawer.open { right: 0; }
.ai-header { padding: 20px 24px; border-bottom: 1px solid var(--border-card); display: flex; justify-content: space-between; align-items: flex-start; }
.ai-chat { flex: 1; padding: 24px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.ai-input-area { padding: 16px 24px; border-top: 1px solid var(--border-card); background: rgba(0,0,0,0.2); }
.ai-input-area input { width: 100%; padding: 12px 16px; background: var(--bg-base); border: 1px solid var(--border-card); border-radius: 8px; color: var(--text-main); font-family: 'Merriweather'; font-size: 12px; outline:none;}

.ai-card { background: rgba(255,255,255,0.02); border: 1px solid rgba(255,255,255,0.05); border-radius: 8px; padding: 16px; position: relative; }
.ai-card::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: #d4ae57; border-radius: 8px 0 0 8px; }
.ai-card.risco-critico::before { background: #e74c3c; }
.ai-card-title { font-size: 11px; color: #888; text-transform: uppercase; margin-bottom: 8px; letter-spacing: 1.5px; }
.ai-card-text { font-size: 13px; color: #e0e0e0; line-height: 1.4; margin-bottom: 16px; }
.ai-card-btn { background: transparent; border: 1px solid #d4ae57; color: #d4ae57; padding: 8px 12px; font-size: 11px; border-radius: 4px; cursor: pointer; text-transform: uppercase; letter-spacing: 1px; width: 100%; transition: all 0.3s; }
.ai-card-btn:hover { background: rgba(212, 174, 87, 0.1); }

/* ==========================================================================
   5. DEBRIEFING, REFORÇO EMOCIONAL E MODAIS
   Visual premium: ux/ux-modals.css
   ========================================================================== */
.overlay { position: fixed; inset: 0; z-index: 3000; display: none; justify-content: center; align-items: center; opacity: 0; transition: opacity 0.4s; pointer-events: none; }
.overlay.show, .overlay.ativo { display: flex; opacity: 1; pointer-events: auto; }

.landing-overlay { position: fixed; inset: 0; z-index: var(--z-modal); display: flex; align-items: center; justify-content: center; opacity: 0; visibility: hidden; transition: opacity 0.6s ease, visibility 0.6s; }
.landing-overlay.ativo { opacity: 1; visibility: visible; }

.landing-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; text-align: left; margin-bottom: 24px; }
.l-item { display: flex; flex-direction: column; gap: 4px; border-left: 1px solid rgba(255,255,255,0.05); padding-left: 16px; }
.l-label { font-size: 11px; color: var(--text-muted); letter-spacing: 1.5px; }
.l-value { font-size: 16px; color: var(--text-main); font-family: 'Cinzel', serif; font-weight: bold; }

.celebration-overlay { position: fixed; inset: 0; z-index: var(--z-spotlight); display: flex; align-items: center; justify-content: center; opacity: 0; visibility: hidden; transition: opacity 0.6s ease, visibility 0.6s; }
.celebration-overlay.show, .celebration-overlay.ativo { opacity: 1; visibility: visible; }

/* ==========================================================================
   6. HISTÓRICO DE VOOS (estrutura — visual em ux-modals)
   ========================================================================== */
.painel-historico { padding: 0; margin: 0; }
.titulo-historico { font-family: var(--font-display); font-size: var(--text-h2); margin: 0; letter-spacing: 1px; color: var(--text-main); }
.subtitulo-historico { color: var(--accent); font-size: 11px; text-transform: uppercase; margin-bottom: 20px; }
.tabela-historico { width: 100%; border-collapse: collapse; text-align: left; }
.tabela-historico th { font-size: 11px; color: var(--text-muted); border-bottom: 1px solid var(--border-card); padding: 10px; }
.tabela-historico td { font-size: 13px; color: var(--text-main); padding: 12px 10px; border-bottom: 1px solid var(--border-card); }

.flight-status-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 32px;
    z-index: 10;
}

.fs-item { display: flex; flex-direction: column; gap: 4px; }
.fs-divider { width: 1px; height: 24px; background: rgba(255, 255, 255, 0.08); }
.fs-status-good { color: #2ecc71; }
.fs-status-warn { color: #f1c40f; }
.fs-status-alert { color: #e74c3c; }

body.light-mode .fs-divider { background: rgba(12, 43, 91, 0.1); }

/* ==========================================================================
   7. EXTRAS DE BEHAVIORAL DESIGN (CICLO)
   IALTUM: ialtum-floating.css | Modais: ux/ux-modals.css
   ========================================================================== */
body { transition: filter 2s ease-in-out, background 0.4s ease, color 0.4s ease, font-size 0.4s ease !important; }
body.ciclo-preparacao { filter: contrast(1.08) brightness(1.05) !important; }
body.ciclo-operacao { filter: contrast(1) brightness(1) !important; }
body.ciclo-encerramento { filter: sepia(0.15) brightness(0.9) contrast(0.95) !important; }
body.ciclo-reflexao { filter: sepia(0.25) brightness(0.75) contrast(0.9) !important; }

/* Radar de Intervenção — Meu Cockpit */
.alerta-radar {
    display: flex; align-items: center; justify-content: space-between;
    background: linear-gradient(135deg, rgba(231, 76, 60, 0.08) 0%, rgba(5, 5, 5, 0.9) 100%);
    border: 1px solid rgba(231, 76, 60, 0.3); border-left: 4px solid #e74c3c;
    border-radius: 12px; padding: 24px; margin-bottom: 32px;
    box-shadow: 0 10px 30px rgba(231, 76, 60, 0.05);
}
.radar-core-box { position: relative; width: 48px; height: 48px; display: flex; justify-content: center; align-items: center; overflow: hidden; }
.radar-ponto { width: 12px; height: 12px; background: #e74c3c; border-radius: 50%; z-index: 3; box-shadow: 0 0 15px #e74c3c; pointer-events: none; }
.radar-onda {
    position: absolute; width: 100%; height: 100%; border-radius: 50%;
    border: 1px solid #e74c3c; z-index: 2; opacity: 0;
    animation: radarPulso 2s cubic-bezier(0.16, 1, 0.3, 1) infinite;
    pointer-events: none; /* decorativo — não bloquear Assumir controle / Continuar */
}
.radar-onda:nth-child(2) { animation-delay: 0.6s; }
.radar-onda:nth-child(3) { animation-delay: 1.2s; }

@keyframes radarPulso {
    0% { transform: scale(0.3); opacity: 1; border-width: 2px; }
    100% { transform: scale(2.5); opacity: 0; border-width: 0; }
}

.alerta-radar-kicker {
    color: #e74c3c;
    font-size: 11px;
    letter-spacing: 2px;
    display: inline-block;
}
.alerta-radar-title {
    font-size: 18px;
    margin: 4px 0;
    color: #fff;
}
.alerta-radar-text {
    font-size: 12px;
    color: var(--text-muted);
    margin: 0;
}
.alerta-radar-cta {
    border-color: #e74c3c !important;
    color: #e74c3c !important;
    background: rgba(231, 76, 60, 0.05) !important;
    white-space: nowrap;
    flex-shrink: 0;
}
.alerta-radar-cta:hover {
    background: #e74c3c !important;
    color: #fff !important;
}

body.light-mode .alerta-radar {
    background: linear-gradient(135deg, rgba(231, 76, 60, 0.08) 0%, rgba(255, 255, 255, 0.92) 100%);
}
body.light-mode .alerta-radar-title { color: var(--text-main); }

body.reduce-motion .radar-onda { animation: none; opacity: 0.35; }

/* Login oculto não deve interceptar cliques */
#loginScreen[style*="visibility: hidden"],
#loginScreen[style*="visibility:hidden"] {
    pointer-events: none !important;
}

@media (max-width: 720px) {
    .alerta-radar {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
        padding: 18px;
    }
    .alerta-radar-cta { width: 100%; }
}