/* ============================================
   🍎 MACOS MOBILE SIDEBAR - ULTRA PROFESIONAL
   Sistema de sidebar responsive para todos los dispositivos
   ============================================ */

/* === VARIABLES BASE === */
:root {
    --sidebar-width: 280px;
    --sidebar-width-tablet: 300px;
    --sidebar-transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    --sidebar-shadow: 0 0 60px rgba(0, 0, 0, 0.15), 0 0 20px rgba(0, 0, 0, 0.1);
    --overlay-bg: rgba(0, 0, 0, 0.5);
    --overlay-blur: blur(3px);
}

/* === OVERLAY MEJORADO === */
.overlay {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important; /* Dynamic viewport height para móviles */
    background: var(--overlay-bg) !important;
    backdrop-filter: var(--overlay-blur) !important;
    -webkit-backdrop-filter: var(--overlay-blur) !important;
    z-index: 99997 !important; /* Menor que sidebar */
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease !important;
    cursor: pointer;
}

.overlay:not(.tw-hidden) {
    opacity: 1 !important;
    visibility: visible !important;
    display: block !important;
}

/* === SIDEBAR BASE RESPONSIVE === */
@media screen and (max-width: 1023px) {
    /* Sidebar oculto por defecto en móvil */
    .side-bar.macos-sidebar {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        width: var(--sidebar-width) !important;
        max-width: 85vw !important;
        height: 100vh !important;
        height: 100dvh !important;
        z-index: 99999 !important; /* Mayor que el overlay */
        transform: translateX(-100%) !important;
        opacity: 0 !important;
        visibility: hidden !important;
        transition: var(--sidebar-transition) !important;
        box-shadow: none !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        -webkit-overflow-scrolling: touch !important;
        overscroll-behavior: contain !important;
        will-change: transform, opacity;
        pointer-events: none !important; /* Desactivado cuando oculto */
    }

    /* Sidebar activo/visible */
    .side-bar.macos-sidebar.small-view-side-active {
        transform: translateX(0) !important;
        opacity: 1 !important;
        visibility: visible !important;
        display: flex !important;
        flex-direction: column !important;
        box-shadow: var(--sidebar-shadow) !important;
        pointer-events: auto !important; /* ACTIVAR clicks cuando visible */
    }
    
    /* Todos los elementos hijos del sidebar deben ser clickables */
    .side-bar.macos-sidebar.small-view-side-active * {
        pointer-events: auto !important;
    }
    
    /* Links del menú específicamente */
    .side-bar.macos-sidebar.small-view-side-active a,
    .side-bar.macos-sidebar.small-view-side-active button,
    .side-bar.macos-sidebar.small-view-side-active .drop_down {
        pointer-events: auto !important;
        cursor: pointer !important;
        -webkit-tap-highlight-color: rgba(0, 122, 255, 0.2) !important;
    }

    /* Asegurar que el contenido principal no se desplace */
    body:has(.small-view-side-active) {
        overflow: hidden !important;
        position: fixed !important;
        width: 100% !important;
    }

    /* Fallback para navegadores sin :has() */
    body.sidebar-open-mobile {
        overflow: hidden !important;
        position: fixed !important;
        width: 100% !important;
    }

    /* Header móvil */
    .main-header {
        position: sticky !important;
        top: 0 !important;
        z-index: 100 !important;
    }

    /* Contenedor principal ajustado */
    #scrollable-container {
        width: 100% !important;
        margin-left: 0 !important;
    }

    /* Botón hamburguesa mejorado */
    .small-view-button {
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        width: 44px !important;
        height: 44px !important;
        border-radius: 12px !important;
        background: linear-gradient(135deg, rgba(255, 255, 255, 0.15) 0%, rgba(255, 255, 255, 0.05) 100%) !important;
        backdrop-filter: blur(10px) !important;
        -webkit-backdrop-filter: blur(10px) !important;
        border: 1px solid rgba(255, 255, 255, 0.2) !important;
        transition: all 0.2s ease !important;
        cursor: pointer !important;
        color: white !important;
        padding: 0 !important;
        margin: 0 !important;
    }

    .small-view-button:hover,
    .small-view-button:active {
        background: linear-gradient(135deg, rgba(255, 255, 255, 0.25) 0%, rgba(255, 255, 255, 0.1) 100%) !important;
        transform: scale(1.05) !important;
    }

    .small-view-button svg {
        width: 24px !important;
        height: 24px !important;
        stroke: currentColor !important;
    }
}

/* === TABLET (768px - 1023px) === */
@media screen and (min-width: 768px) and (max-width: 1023px) {
    .side-bar.macos-sidebar {
        width: var(--sidebar-width-tablet) !important;
        max-width: 75vw !important;
    }

    .side-bar.macos-sidebar.small-view-side-active {
        box-shadow: var(--sidebar-shadow) !important;
    }

    /* Más espacio para el contenido en tablets */
    .sidebar-logo-section {
        padding: 28px 20px 24px !important;
    }

    /* Menú con más espacio */
    .macos-menu-item {
        padding: 12px 18px !important;
        margin: 3px 12px !important;
    }
}

/* === MÓVIL PEQUEÑO (hasta 480px) === */
@media screen and (max-width: 480px) {
    .side-bar.macos-sidebar {
        width: 100vw !important;
        max-width: 100vw !important;
        border-radius: 0 !important;
    }

    .side-bar.macos-sidebar.small-view-side-active {
        box-shadow: none !important;
    }

    /* Logo más compacto */
    .sidebar-logo-section {
        padding: 16px 12px 14px !important;
    }

    .sidebar-logo-section img,
    .sidebar-logo-section .macos-app-icon {
        width: 40px !important;
        height: 40px !important;
    }

    .sidebar-logo-section .business-name,
    .sidebar-logo-section .macos-app-title {
        font-size: 16px !important;
    }

    /* Menú más compacto */
    .macos-menu-item {
        padding: 10px 12px !important;
        margin: 2px 8px !important;
        font-size: 14px !important;
    }

    .macos-menu-item .menu-icon {
        width: 20px !important;
        height: 20px !important;
    }

    /* Submenú compacto */
    .macos-submenu {
        padding-left: 20px !important;
    }

    .macos-submenu-item {
        padding: 8px 10px !important;
        font-size: 13px !important;
    }
}

/* === LANDSCAPE MÓVIL === */
@media screen and (max-width: 1023px) and (orientation: landscape) {
    .side-bar.macos-sidebar {
        width: 45vw !important;
        max-width: 320px !important;
    }

    /* Logo muy compacto en landscape */
    .sidebar-logo-section {
        padding: 10px 12px !important;
        flex-direction: row !important;
        gap: 12px !important;
    }

    .sidebar-logo-section img,
    .sidebar-logo-section .macos-app-icon {
        width: 32px !important;
        height: 32px !important;
    }

    /* Menú más compacto */
    .macos-menu-item {
        padding: 8px 12px !important;
        margin: 1px 8px !important;
    }
}

/* === ESTILOS INTERNOS DEL SIDEBAR MÓVIL === */
@media screen and (max-width: 1023px) {
    /* Scrollbar personalizado */
    .side-bar.macos-sidebar::-webkit-scrollbar {
        width: 4px !important;
    }

    .side-bar.macos-sidebar::-webkit-scrollbar-track {
        background: transparent !important;
    }

    .side-bar.macos-sidebar::-webkit-scrollbar-thumb {
        background: rgba(0, 0, 0, 0.15) !important;
        border-radius: 4px !important;
    }

    .side-bar.macos-sidebar::-webkit-scrollbar-thumb:hover {
        background: rgba(0, 0, 0, 0.25) !important;
    }

    /* Header del sidebar en móvil con botón cerrar */
    .side-bar.macos-sidebar .sidebar-logo-section {
        position: relative !important;
    }

    /* User info section */
    .macos-user-section {
        padding: 12px 16px !important;
        border-bottom: 1px solid rgba(0, 0, 0, 0.06) !important;
    }

    /* Footer del sidebar */
    .macos-sidebar-footer {
        margin-top: auto !important;
        padding: 16px !important;
        border-top: 1px solid rgba(0, 0, 0, 0.06) !important;
    }

    /* Animación de entrada de ítems del menú */
    .side-bar.macos-sidebar.small-view-side-active .macos-menu-section {
        animation: slideInMenu 0.3s ease-out forwards;
    }

    @keyframes slideInMenu {
        from {
            opacity: 0;
            transform: translateX(-10px);
        }
        to {
            opacity: 1;
            transform: translateX(0);
        }
    }

    /* Delays escalonados para cada sección */
    .side-bar.macos-sidebar.small-view-side-active .macos-menu-section:nth-child(1) {
        animation-delay: 0.05s;
    }
    .side-bar.macos-sidebar.small-view-side-active .macos-menu-section:nth-child(2) {
        animation-delay: 0.1s;
    }
    .side-bar.macos-sidebar.small-view-side-active .macos-menu-section:nth-child(3) {
        animation-delay: 0.15s;
    }
    .side-bar.macos-sidebar.small-view-side-active .macos-menu-section:nth-child(4) {
        animation-delay: 0.2s;
    }
}

/* === BOTÓN CERRAR SIDEBAR (MÓVIL) === */
.mobile-sidebar-close {
    display: none !important;
}

@media screen and (max-width: 1023px) {
    .mobile-sidebar-close {
        display: flex !important;
        position: absolute !important;
        top: 16px !important;
        right: 16px !important;
        width: 32px !important;
        height: 32px !important;
        align-items: center !important;
        justify-content: center !important;
        border-radius: 50% !important;
        background: rgba(0, 0, 0, 0.06) !important;
        border: none !important;
        cursor: pointer !important;
        transition: all 0.2s ease !important;
        color: #636366 !important;
        z-index: 10 !important;
    }

    .mobile-sidebar-close:hover,
    .mobile-sidebar-close:active {
        background: rgba(0, 0, 0, 0.12) !important;
        color: #1d1d1f !important;
    }

    .mobile-sidebar-close svg {
        width: 16px !important;
        height: 16px !important;
        stroke-width: 2 !important;
    }
}

/* === TOUCH IMPROVEMENTS === */
@media screen and (max-width: 1023px) {
    /* Áreas de toque más grandes */
    .macos-menu-item,
    .macos-submenu-item {
        min-height: 44px !important;
        -webkit-tap-highlight-color: transparent !important;
    }

    /* Prevenir zoom en doble tap */
    .side-bar.macos-sidebar {
        touch-action: pan-y !important;
    }

    /* Active states táctiles */
    .macos-menu-item:active,
    .macos-submenu-item:active {
        background: rgba(0, 122, 255, 0.12) !important;
        transform: scale(0.98) !important;
    }
}

/* === DARK MODE SUPPORT === */
@media (prefers-color-scheme: dark) {
    @media screen and (max-width: 1023px) {
        .overlay {
            background: rgba(0, 0, 0, 0.7) !important;
        }

        .side-bar.macos-sidebar.small-view-side-active {
            box-shadow: 0 0 60px rgba(0, 0, 0, 0.5), 0 0 20px rgba(0, 0, 0, 0.3) !important;
        }
    }
}

/* === SAFE AREA SUPPORT (NOTCH) === */
@supports (padding-top: env(safe-area-inset-top)) {
    @media screen and (max-width: 1023px) {
        .side-bar.macos-sidebar {
            padding-top: env(safe-area-inset-top) !important;
            padding-bottom: env(safe-area-inset-bottom) !important;
            padding-left: env(safe-area-inset-left) !important;
        }
    }
}

/* === REDUCED MOTION === */
@media (prefers-reduced-motion: reduce) {
    .side-bar.macos-sidebar,
    .overlay,
    .macos-menu-item,
    .small-view-button {
        transition: none !important;
        animation: none !important;
    }
}

/* === PRINT === */
@media print {
    .side-bar.macos-sidebar,
    .overlay,
    .small-view-button {
        display: none !important;
    }
}

/* === FIX PARA CONTENEDOR PRINCIPAL EN MÓVIL === */
@media screen and (max-width: 1023px) {
    /* Asegurar que el wrapper principal es full width */
    .wrapper,
    .main-container,
    .content-wrapper {
        width: 100% !important;
        max-width: 100% !important;
        margin-left: 0 !important;
        padding-left: 0 !important;
    }

    /* Fix para el layout flex principal */
    body > .tw-flex,
    #app > .tw-flex {
        flex-direction: column !important;
    }

    /* Asegurar que el header ocupe todo el ancho */
    .main-header,
    header {
        width: 100% !important;
        left: 0 !important;
    }
}