/* ===== ERP MOBILE RESPONSIVE GLOBAL FIX ===== */
/* Incluir en TODOS los headers del ERP para garantizar */
/* comportamiento tipo app móvil nativa en todos los módulos */

/* Reset box-sizing global */
*, *::before, *::after {
    box-sizing: border-box;
}

/* Prevenir desbordamiento horizontal en todo el sitio */
html {
    overflow-x: hidden;
    max-width: 100vw;
    -webkit-text-size-adjust: 100%;
}

body {
    overflow-x: hidden;
    max-width: 100vw;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ===== Tablas Responsivas ===== */
/* Todas las tablas deben poder scrollear horizontalmente */
.table-responsive,
.overflow-x-auto {
    -webkit-overflow-scrolling: touch;
    overflow-x: auto;
    max-width: 100%;
}

table {
    min-width: 100%;
}

/* ===== Formularios Responsivos ===== */
input, select, textarea, button {
    max-width: 100%;
    font-size: 16px !important; /* Prevenir zoom en iOS */
}

@media (min-width: 768px) {
    input, select, textarea, button {
        font-size: inherit !important;
    }
}

/* ===== Grids Responsivos ===== */
@media (max-width: 640px) {
    .grid-cols-2, .grid-cols-3, .grid-cols-4,
    .sm\:grid-cols-2, .sm\:grid-cols-3, .sm\:grid-cols-4 {
        grid-template-columns: 1fr !important;
    }
    
    /* Stat cards en grid de 2 columnas en móvil */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    
    /* Padding reducido en móvil */
    .p-6 { padding: 12px !important; }
    .p-8 { padding: 16px !important; }
    .px-6 { padding-left: 12px !important; padding-right: 12px !important; }
    .px-8 { padding-left: 16px !important; padding-right: 16px !important; }
    
    /* Texto más pequeño en móvil para encabezados largos */
    h1 { font-size: 1.25rem !important; }
    h2 { font-size: 1.1rem !important; }
    
    /* Botones apilados en móvil */
    .flex-wrap { flex-wrap: wrap !important; }
    
    /* Ocultar elementos que no son esenciales en móvil */
    .hidden-mobile { display: none !important; }
    
    /* Imágenes responsivas */
    img { max-width: 100%; height: auto; }
}

/* ===== Navegación Top-Bar (SST, Contabilidad) ===== */
@media (max-width: 767px) {
    /* Menú hamburguesa para navs horizontales */
    header nav.hidden.md\:flex {
        display: none !important;
    }
    
    /* Header compacto */
    header .h-16 {
        height: 3.5rem;
    }
    
    /* Botones del header más pequeños */
    header .gap-3 {
        gap: 0.375rem;
    }
    header .gap-4 {
        gap: 0.5rem;
    }
    
    /* Logo más pequeño en header */
    header .w-10.h-10 {
        width: 2rem;
        height: 2rem;
        font-size: 0.875rem;
    }
    header .text-lg {
        font-size: 0.8125rem;
    }
    header .text-\[10px\] {
        display: none;
    }
    
    /* Select de empresa compacto */
    header select {
        max-width: 120px;
        font-size: 10px !important;
        padding: 4px 8px;
    }
}

/* ===== Menú Hamburguesa Móvil (para headers tipo top-bar) ===== */
.mobile-menu-btn {
    display: none;
    padding: 8px;
    background: transparent;
    border: none;
    color: white;
    font-size: 1.25rem;
    cursor: pointer;
}
@media (max-width: 767px) {
    .mobile-menu-btn {
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

/* Mobile dropdown menu */
.mobile-nav-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #1e293b;
    border-top: 1px solid rgba(255,255,255,0.1);
    z-index: 100;
    padding: 8px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}
.mobile-nav-dropdown.show {
    display: block;
}
.mobile-nav-dropdown a {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    color: #cbd5e1;
    text-decoration: none;
    transition: background 0.2s;
}
.mobile-nav-dropdown a:hover,
.mobile-nav-dropdown a.active-link {
    background: rgba(255,255,255,0.1);
    color: white;
}

/* ===== Modales Responsivos ===== */
@media (max-width: 640px) {
    /* Los modales tipo fixed deben ocupar toda la pantalla en móvil */
    .fixed.inset-0 > div[class*="max-w-"],
    .fixed.inset-0 > div[class*="rounded-"] {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        border-radius: 0 !important;
        max-height: 100vh !important;
        height: 100vh !important;
        overflow-y: auto;
    }
}

/* ===== Cards y contenedores ===== */
@media (max-width: 640px) {
    .rounded-3xl { border-radius: 1rem !important; }
    .rounded-2xl { border-radius: 0.75rem !important; }
    .shadow-2xl { box-shadow: 0 4px 12px rgba(0,0,0,0.1) !important; }
    
    /* Cards no se mueven al hover en móvil */
    .light-card:hover,
    [class*="hover:translate"],
    [class*="hover:scale"] {
        transform: none !important;
    }
}

/* ===== Safe areas para PWA (notch de iPhone) ===== */
@supports (padding-top: env(safe-area-inset-top)) {
    header {
        padding-top: env(safe-area-inset-top);
    }
    .content-area-scroll {
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* ===== Scrollbar fino universal ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ===== Animaciones suaves ===== */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* ===== Print ===== */
@media print {
    header, .sidebar, .mobile-menu-btn, #pwaInstallContainer, .sidebar-overlay {
        display: none !important;
    }
    body { overflow: visible !important; position: static !important; height: auto !important; }
    main { overflow: visible !important; height: auto !important; }
}
