/**
 * ========================================
 * MOBILE MENU SYSTEM v4.0
 * ========================================
 * Sistema completo de menú hamburguesa para dispositivos móviles
 * Incluye: botón toggle, overlay, backdrop, animaciones
 */

/* ========================================
   BOTÓN HAMBURGUESA (Toggle)
   ======================================== */

.mobile-menu-toggle {
    display: none; /* Oculto por defecto en desktop */
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 1001;
    width: 48px;
    height: 48px;
    background: var(--surface-secondary, #2a2a2a);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    color: var(--text-primary, #ffffff);
    font-size: 1.25rem;
    cursor: pointer;
    transition: all var(--transition-base, 250ms);
    box-shadow: var(--shadow-lg, 0 8px 16px rgba(0, 0, 0, 0.4));
    align-items: center;
    justify-content: center;
}

.mobile-menu-toggle:hover {
    background: var(--surface-primary, #1e1e1e);
    border-color: var(--accent-primary, #00d4ff);
    color: var(--accent-primary, #00d4ff);
    transform: scale(1.05);
    box-shadow: var(--shadow-xl, 0 16px 32px rgba(0, 0, 0, 0.6));
}

.mobile-menu-toggle:active {
    transform: scale(0.95);
}

.mobile-menu-toggle i {
    display: block;
}

/* ========================================
   BOTÓN CERRAR (X)
   ======================================== */

.mobile-menu-close {
    display: none; /* Solo visible en móvil cuando el menú está abierto */
    position: absolute;
    top: 1rem;
    right: 1rem;
    z-index: 1002;
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: var(--text-secondary, #b0b0b0);
    font-size: 1.125rem;
    cursor: pointer;
    transition: all var(--transition-base, 250ms);
    align-items: center;
    justify-content: center;
}

.mobile-menu-close:hover {
    background: rgba(255, 71, 87, 0.1);
    border-color: var(--accent-danger, #ff4757);
    color: var(--accent-danger, #ff4757);
    transform: rotate(90deg);
}

.mobile-menu-close:active {
    transform: rotate(90deg) scale(0.9);
}

/* ========================================
   BACKDROP (Fondo Oscuro)
   ======================================== */

.mobile-menu-backdrop {
    display: none; /* Oculto por defecto */
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    z-index: 999;
    opacity: 0;
    transition: opacity var(--transition-base, 250ms);
}

.mobile-menu-backdrop.active {
    display: block;
    opacity: 1;
}

/* ========================================
   RESPONSIVE - MÓVIL (<768px)
   ======================================== */

@media (max-width: 767px) {
    
    /* Mostrar botón hamburguesa en móvil */
    .mobile-menu-toggle {
        display: flex;
    }
    
    /* Sidebar oculto por defecto en móvil */
    .dashboard-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 280px;
        max-width: 85vw;
        z-index: 1000;
        transform: translateX(-100%);
        transition: transform var(--transition-base, 250ms) cubic-bezier(0.4, 0.0, 0.2, 1);
        box-shadow: var(--shadow-xl, 0 16px 32px rgba(0, 0, 0, 0.6));
        overflow-y: auto;
    }
    
    /* Estado: Menú Abierto */
    body.mobile-menu-open .dashboard-sidebar,
    .mobile-menu-open .dashboard-sidebar {
        transform: translateX(0);
    }
    
    /* Mostrar botón cerrar cuando el menú está abierto */
    body.mobile-menu-open .mobile-menu-close,
    .mobile-menu-open .mobile-menu-close {
        display: flex;
    }
    
    /* Ocultar botón hamburguesa cuando el menú está abierto */
    body.mobile-menu-open .mobile-menu-toggle,
    .mobile-menu-open .mobile-menu-toggle {
        opacity: 0;
        pointer-events: none;
    }
    
    /* Activar backdrop cuando el menú está abierto */
    body.mobile-menu-open .mobile-menu-backdrop,
    .mobile-menu-open .mobile-menu-backdrop {
        display: block;
        opacity: 1;
    }
    
    /* Prevenir scroll del body cuando el menú está abierto */
    body.mobile-menu-open {
        overflow: hidden;
    }
    
    /* Ajustar el contenido principal para el botón hamburguesa */
    .dashboard-main {
        padding-top: 5rem; /* Espacio para el botón hamburguesa */
    }
    
    .dashboard-header {
        padding-top: 0;
    }
}

/* ========================================
   ANIMACIONES
   ======================================== */

@keyframes slideInFromLeft {
    from {
        transform: translateX(-100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Animación suave al abrir */
body.mobile-menu-open .dashboard-sidebar,
.mobile-menu-open .dashboard-sidebar {
    animation: slideInFromLeft 300ms cubic-bezier(0.4, 0.0, 0.2, 1);
}

body.mobile-menu-open .mobile-menu-backdrop,
.mobile-menu-open .mobile-menu-backdrop {
    animation: fadeIn 250ms ease-out;
}

/* ========================================
   ACCESIBILIDAD
   ======================================== */

/* Focus visible para navegación por teclado */
.mobile-menu-toggle:focus-visible,
.mobile-menu-close:focus-visible {
    outline: 2px solid var(--accent-primary, #00d4ff);
    outline-offset: 2px;
}

/* Reducir animaciones si el usuario lo prefiere */
@media (prefers-reduced-motion: reduce) {
    .mobile-menu-toggle,
    .mobile-menu-close,
    .mobile-menu-backdrop,
    .dashboard-sidebar {
        transition: none;
        animation: none;
    }
}

/* ========================================
   TABLET (768px - 1024px)
   ======================================== */

@media (min-width: 768px) and (max-width: 1024px) {
    /* En tablet, mantener el botón hamburguesa pero ajustar tamaños */
    .mobile-menu-toggle {
        display: flex;
        top: 1.5rem;
        left: 1.5rem;
    }
    
    .dashboard-sidebar {
        width: 300px;
    }
}

/* ========================================
   DESKTOP (>1024px)
   ======================================== */

@media (min-width: 1025px) {
    /* En desktop, ocultar completamente el sistema móvil */
    .mobile-menu-toggle,
    .mobile-menu-close,
    .mobile-menu-backdrop {
        display: none !important;
    }
    
    .dashboard-sidebar {
        position: static;
        transform: none;
    }
}

/* ========================================
   MEJORAS VISUALES
   ======================================== */

/* Efecto de pulso sutil en el botón hamburguesa */
@keyframes pulse {
    0%, 100% {
        box-shadow: 0 8px 16px rgba(0, 0, 0, 0.4);
    }
    50% {
        box-shadow: 0 8px 16px rgba(0, 212, 255, 0.3);
    }
}

.mobile-menu-toggle:hover {
    animation: pulse 2s infinite;
}

/* Efecto de rotación al cerrar */
.mobile-menu-close i {
    transition: transform var(--transition-base, 250ms);
}

.mobile-menu-close:hover i {
    transform: rotate(90deg);
}

/* ========================================
   SAFE AREA (iPhone X, notch)
   ======================================== */

@supports (padding: max(0px)) {
    @media (max-width: 767px) {
        .mobile-menu-toggle {
            top: max(1rem, env(safe-area-inset-top));
            left: max(1rem, env(safe-area-inset-left));
        }
        
        .dashboard-sidebar {
            padding-top: max(1rem, env(safe-area-inset-top));
            padding-left: max(1rem, env(safe-area-inset-left));
            padding-right: max(1rem, env(safe-area-inset-right));
        }
    }
}

/* ========================================
   DEBUG (Opcional - Comentar en producción)
   ======================================== */

/* 
.mobile-menu-toggle::before {
    content: '🍔';
    position: absolute;
    top: -1.5rem;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.75rem;
    background: var(--accent-primary);
    color: var(--background-primary);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    pointer-events: none;
}
*/
