/**
 * @fileoverview Núcleo Estético Inmutable, Control de Design Tokens e Infraestructura Móvil Dvh
 * Integra clases de control para transiciones de enrutador y el spinner corporativo de carga.
 * @version 5.1.0
 * @author Mixteco Studio - Senior Software Engineer
 */

/* ==========================================================================
   1. IMPORTACIONES DE INFRAESTRUCTURA Y COMPONENTES FIJOS
   ========================================================================== */
@import "../components/sidebar/sidebar.css";
@import "../components/mobile-header/mobile-header.css";
@import url("https://unpkg.com/lucide-static@latest/font/lucide.css");
    
/* ==========================================================================
   2. DESIGN TOKENS & SYSTEM VARIABLES (Gobernadas por Data-Driven Engine)
   ========================================================================== */
:root {
    /* --- PALETA CROMÁTICA SEMÁNTICA (Valores inyectados por ThemeEngine) --- */
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-surface: #e2e8f0;
    --bg-overlay: rgba(15, 23, 42, 0.3);
    
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    
    --accent-primary: #2563eb;
    --accent-secondary: #7c3aed;
    --accent-primary-alpha: rgba(37, 99, 235, 0.1);
    
    /* Variables de canales RGB para sombras y efectos dinámicos */
    --accent-primary-rgb: 37, 99, 235;
    --accent-secondary-rgb: 124, 58, 237;
    --bg-secondary-rgb: 248, 250, 252;
    
    /* --- COMPOSICIÓN ARMÓNICA --- */
    --hero-gradient: linear-gradient(135deg, var(--bg-surface) 0%, var(--bg-primary) 100%);
    
    /* Semántica de Capa Comercial (Inmutables) */
    --color-success: #10b981;
    --color-free: #22c55e;
    
    /* Estructura y Layout (Geometría Inmutable) */
    --sidebar-width: 288px;
    --header-mobile-height: 64px;
    --font-global: 'Inter', system-ui, -apple-system, sans-serif;
    
    --radius-xl: 32px;
    --radius-lg: 24px;
    --radius-md: 16px;
    --radius-sm: 8px;
    
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.05), 0 2px 4px -1px rgba(0,0,0,0.03);
    --shadow-xl: 0 20px 25px -5px rgba(15, 23, 42, 0.05), 0 10px 10px -5px rgba(15, 23, 42, 0.03);
    --shadow-2xl: 0 25px 50px -12px rgba(15, 23, 42, 0.25);
    
    --transition-speed: 0.3s;
    --transition-curve: cubic-bezier(0.4, 0, 0.2, 1);
    --transition-smooth: all var(--transition-speed) var(--transition-curve);
}

/* ==========================================================================
   3. MODERN CSS RESET & NORMALIZATION (MÓVIL PÍXEL PERFECT)
   ========================================================================== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-family: var(--font-global);
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
    
    /* ✅ FIJADO ELÁSTICO: Sincroniza el lienzo neto con el Viewport Dinámico del Smartphone */
    height: 100dvh;
    width: 100vw;
}

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
    transition: background-color var(--transition-speed) var(--transition-curve),
                color var(--transition-speed) var(--transition-curve);

    /* ✅ CONTROL BIOMÉTRICO TÁCTIL: Cancela los rebotes elásticos de iOS que traban los modales de la SPA */
    height: 100dvh;
    width: 100vw;
    overscroll-behavior-y: none;
}

img, svg, picture, video {
    display: block;
    max-width: 100%;
    height: auto;
}

button, input, select, textarea {
    font: inherit;
    color: inherit;
    background: none;
    border: none;
    outline: none;
}

button {
    cursor: pointer;
    user-select: none;
}

a {
    text-decoration: none;
    color: inherit;
}

/* ==========================================================================
   4. STRUCTURAL LAYOUT SHELL (BEM Architecture for SPA Viewports)
   ========================================================================== */
.site-wrapper {
    display: flex;
    flex-direction: column;
    height: 100dvh;
}

.app-container {
    display: flex;
    flex-direction: column;
    width: 100vw;
    height: 100dvh;
    position: relative;
}

.layout-shell {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100dvh;
}

/* Eje de Contenidos Central: Adaptado de forma unificada */
.layout-shell__main {
    flex: 1;
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100dvh;
    position: relative;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch; /* Suavizado inercial nativo para dispositivos Apple */
    
    /* Empuja el contenido hacia abajo el tamaño justo del MobileHeader */
    padding-top: var(--header-mobile-height); 
    box-sizing: border-box;
    transition: padding var(--transition-speed) var(--transition-curve),
                opacity var(--transition-speed) var(--transition-curve);
    opacity: 0; /* Por defecto inicia oculto y se controla mediante estados */
}

/* --- ESTADOS DE CONTROL DE FLUJO DEL ENRUTADOR --- */
.layout-shell__main--loading,
.layout-shell__main--loaded,
.layout-shell__main--error {
    opacity: 1;
}

.layout-shell__main--transitioning {
    opacity: 0;
}

.no-scrollbar {
    scrollbar-width: none; 
    -ms-overflow-style: none; 
}

.no-scrollbar::-webkit-scrollbar {
    display: none; 
    width: 0 !important;
    height: 0 !important;
}

/* --- Personalización Limpia del Scrollbar --- */
.inicio-view {
    scrollbar-width: thin;
    scrollbar-color: var(--bg-surface) transparent;
}

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background-color: var(--bg-surface);
    border-radius: var(--radius-xl);
}

::-webkit-scrollbar-thumb:hover {
    background-color: var(--text-muted);
}

/* ==========================================================================
   RESPONSIVE LAYOUT (Evolución Estructural Desktop Sincronizada)
   ========================================================================== */
@media (min-width: 1024px) {
    html, body, .site-wrapper, .app-container, .layout-shell {
        height: 100vh; /* Restaurar comportamiento tradicional en Desktop */
    }

    .layout-shell {
        flex-direction: row;
    }

    .layout-shell__main {
        padding-top: 0;
        height: 100vh;
        margin-left: var(--sidebar-width);
        width: calc(100% - var(--sidebar-width));
    }
}

/* ==========================================================================
   5. GLOBAL ANIMATION TOKENS & UI FALLBACKS
   ========================================================================== */
.fade-in-engine {
    animation: spaViewEnter var(--transition-speed) var(--transition-curve) forwards;
    will-change: transform, opacity;
}

@keyframes spaViewEnter {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ==========================================================================
   COMPONENTE: STUDIO LOADER SPINNER CRÍTICO (Diseño Profesional)
   ========================================================================== */
.studio-loader-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    width: 100%;
    height: 100%;
    min-height: 300px;
    gap: 1.25rem;
    background-color: var(--bg-primary);
}

.studio-loader-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--bg-surface);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: studioSpin 0.8s linear infinite;
}

.studio-loader-text {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-secondary);
    letter-spacing: -0.01em;
    animation: studioPulse 1.5s ease-in-out infinite;
}

@keyframes studioSpin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes studioPulse {
    0%, 100% {
        opacity: 0.6;
    }
    50% {
        opacity: 1;
    }
}

/* ==========================================================================
   UI FALLBACKS: ERROR BOUNDARY & ACCESIBILIDAD
   ========================================================================== */
.critical-fallback-wrapper {
    padding: 4rem 2rem;
    font-family: var(--font-global);
    text-align: center;
    max-width: 32rem;
    margin: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.critical-fallback-wrapper__title {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--color-success);
    letter-spacing: -0.02em;
}

.critical-fallback-wrapper__description {
    color: var(--text-secondary);
    font-size: 0.95rem;
    line-height: 1.6;
}

.screen-reader-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

/* ==========================================================================
   6. UTILITIES: CONGELAMIENTO DE CAPAS BASE (MODAL FREEZE ENGINE)
   ========================================================================== */

/* ✅ CLASE DE INFRAESTRUCTURA MÓVIL CRÍTICA:
   Inyectada dinámicamente por ProjDataSheet y Venta para congelar el scroll de fondo 
   impidiendo desbordamientos y parpadeos en navegadores táctiles */
.u-overflow-hidden {
    overflow: hidden !important;
    height: 100dvh !important;
}