/* ============================================================================
   TENSSOR PLATFORM - MOBILE UX IMPROVEMENTS
   ============================================================================
   
   Fecha: 02 Octubre 2025
   Estrategia: C - Balanceada (archivo separado + testing)
   Target: iPhone y dispositivos móviles (< 768px)
   Principio: ZERO cambios en desktop (≥ 769px)
   
   Rollback: Comentar link en index.html o feature flag = False
   
   ============================================================================ */

/* ============================================================================
   BREAKPOINTS CONSISTENTES
   ============================================================================ */
   
/*
  - MOBILE:  max-width: 767px
  - TABLET:  768px - 1024px  
  - DESKTOP: min-width: 1025px
  
  Nota: Usamos 767px (no 768px) para evitar zona gris con iPad
*/

/* ============================================================================
   QUICK WIN #1: Clases CSS Responsive + Input Font-Size Fix
   ============================================================================
   Impacto: ⚡⚡⚡⚡⚡ CRÍTICO
   Riesgo: 🟢 BAJO
   Tiempo: ⏱️ 30 minutos
   
   Resuelve:
   - Columnas mobile-hidden no se ocultan (clase no existe)
   - Inputs causan auto-zoom en iPhone (font-size < 16px)
   - Botones muy pequeños para touch
   ============================================================================ */

@media (max-width: 767px) {
    /* Ocultar elementos marcados como mobile-hidden */
    .mobile-hidden {
        display: none !important;
    }
    
    /* FIX CRÍTICO: Auto-zoom en iPhone
       iOS Safari hace zoom automático si font-size < 16px
       Esto frustra usuarios - fix universal */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="search"],
    input[type="number"],
    input[type="date"],
    select,
    textarea {
        font-size: 16px !important;
    }
    
    /* Botones touch-friendly
       Apple Human Interface Guidelines: mínimo 44x44px
       Botones más pequeños causan clicks accidentales */
    .btn {
        min-height: 44px;
        min-width: 44px;
        padding: 12px 16px;
        font-size: 16px; /* Consistencia con inputs */
    }
    
    /* Botones pequeños aún deben ser clickeables */
    .btn-sm {
        min-height: 38px;
        min-width: 38px;
        padding: 8px 12px;
        font-size: 14px;
    }
}

@media (min-width: 768px) and (max-width: 1024px) {
    /* Ocultar elementos en tablets */
    .tablet-hidden {
        display: none !important;
    }
}

@media (min-width: 1025px) {
    /* Ocultar elementos solo en desktop */
    .desktop-hidden {
        display: none !important;
    }
}

/* ============================================================================
   QUICK WIN #2: Búsqueda Sticky en Móvil
   ============================================================================
   Impacto: ⚡⚡⚡⚡ ALTO
   Riesgo: 🟢 BAJO
   Tiempo: ⏱️ 15 minutos
   
   Resuelve:
   - Búsqueda difícil de acceder (hay que scroll arriba)
   - UX inconsistente con apps nativas (WhatsApp, Instagram)
   ============================================================================ */

@media (max-width: 767px) {
    /* Búsqueda siempre visible al hacer scroll */
    .search-section {
        position: sticky;
        top: 60px; /* Debajo del header/navbar */
        z-index: 100; /* Sobre contenido, bajo modales */
        background: white;
        padding: 12px 16px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
        margin-left: -12px;
        margin-right: -12px;
    }
    
    .search-section input {
        width: 100%;
        font-size: 16px; /* Evita zoom iOS */
        padding: 12px 16px;
        border-radius: 8px;
        border: 1px solid #dee2e6;
    }
    
    .search-section input:focus {
        border-color: #0d6efd;
        box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.1);
        outline: none;
    }
    
    /* Iconos de búsqueda más grandes */
    .search-section .fa-search {
        font-size: 18px;
    }
}

/* ============================================================================
   QUICK WIN #3: Modales Full-Screen en Móvil
   ============================================================================
   Impacto: ⚡⚡⚡⚡ ALTO
   Riesgo: 🟢 BAJO
   Tiempo: ⏱️ 20 minutos
   
   Resuelve:
   - Modales muy pequeños en móvil
   - Difícil interactuar con formularios
   - Desperdicio de espacio vertical
   ============================================================================ */

@media (max-width: 767px) {
    /* Modal ocupa toda la pantalla */
    .modal-dialog {
        margin: 0;
        max-width: 100%;
        width: 100%;
        height: 100vh;
    }
    
    .modal-content {
        height: 100vh;
        border-radius: 0;
        border: none;
    }
    
    /* Header sticky - siempre visible */
    .modal-header {
        position: sticky;
        top: 0;
        z-index: 1050;
        background: white;
        border-bottom: 1px solid #dee2e6;
        padding: 16px;
    }
    
    .modal-title {
        font-size: 18px;
        font-weight: 600;
    }
    
    /* Botón cerrar más grande */
    .btn-close {
        width: 44px;
        height: 44px;
        padding: 12px;
    }
    
    /* Body con scroll suave iOS */
    .modal-body {
        overflow-y: auto;
        padding: 16px;
        -webkit-overflow-scrolling: touch;
        flex: 1; /* Ocupa espacio disponible */
    }
    
    /* Footer sticky - acciones siempre visibles */
    .modal-footer {
        position: sticky;
        bottom: 0;
        z-index: 1050;
        background: white;
        border-top: 1px solid #dee2e6;
        padding: 12px 16px;
    }
    
    /* Botones de modal full-width */
    .modal-footer .btn {
        flex: 1;
        min-width: 0; /* Permite flex shrink */
    }
}

/* ============================================================================
   QUICK WIN #4: Stats Cards Single Column en Móvil
   ============================================================================
   Impacto: ⚡⚡⚡⚡ ALTO
   Riesgo: 🟢 BAJO
   Tiempo: ⏱️ 10 minutos
   
   Resuelve:
   - Stats cards apretadas (2-3 por fila)
   - Números difíciles de leer
   - Scroll horizontal innecesario
   ============================================================================ */

@media (max-width: 767px) {
    /* Forzar columna única para stats cards */
    .stats-cards-container,
    .row.mb-4,
    .row.g-3,
    .row.g-4 {
        display: flex;
        flex-direction: column;
        gap: 12px;
        margin: 0;
    }
    
    /* Cada card ocupa 100% width */
    .stats-cards-container > *,
    .row.mb-4 > [class*="col-"],
    .row.g-3 > [class*="col-"],
    .row.g-4 > [class*="col-"] {
        width: 100% !important;
        max-width: 100% !important;
        flex: 0 0 100% !important;
        padding-left: 0 !important;
        padding-right: 0 !important;
    }
    
    /* Cards más compactas pero legibles */
    .card {
        margin-bottom: 0; /* Gap lo maneja el contenedor */
        padding: 16px;
    }
    
    .card-body {
        padding: 12px;
    }
    
    /* Números más grandes y prominentes */
    .card .display-4,
    .card .h1 {
        font-size: 2rem;
    }
    
    .card .display-5,
    .card .h2 {
        font-size: 1.75rem;
    }
    
    .card .display-6,
    .card .h3 {
        font-size: 1.5rem;
    }
    
    /* Texto secundario más legible */
    .card small,
    .card .text-muted {
        font-size: 14px;
    }
}

/* ============================================================================
   QUICK WIN #5: Padding y Spacing Optimizado Móvil
   ============================================================================
   Impacto: ⚡⚡⚡⚡ MEDIO-ALTO
   Riesgo: 🟢 BAJO
   Tiempo: ⏱️ 15 minutos
   
   Resuelve:
   - Padding excesivo desperdicia espacio vertical
   - Tablas muy anchas causan scroll horizontal
   - Headers ocupan demasiado espacio
   ============================================================================ */

@media (max-width: 767px) {
    /* Reducir padding general para ganar espacio vertical */
    .container-fluid,
    .main-content {
        padding-left: 12px !important;
        padding-right: 12px !important;
        padding-top: 12px !important;
    }
    
    /* Tablas más compactas */
    .table {
        font-size: 14px;
    }
    
    .table td,
    .table th {
        padding: 8px 4px;
        vertical-align: middle;
    }
    
    /* Primera columna (usualmente descripción) más ancha */
    .table td:first-child,
    .table th:first-child {
        padding-left: 8px;
    }
    
    /* Última columna (usualmente acciones) más espacio */
    .table td:last-child,
    .table th:last-child {
        padding-right: 8px;
    }
    
    /* Headers de sección escalables */
    h1 {
        font-size: 1.75rem;
        margin-bottom: 12px;
    }
    
    h2 {
        font-size: 1.5rem;
        margin-bottom: 10px;
    }
    
    h3 {
        font-size: 1.25rem;
        margin-bottom: 8px;
    }
    
    h4 {
        font-size: 1.1rem;
        margin-bottom: 8px;
    }
    
    /* Reducir márgenes de secciones */
    .mb-4 {
        margin-bottom: 1rem !important;
    }
    
    .mb-3 {
        margin-bottom: 0.75rem !important;
    }
    
    /* Tabs más compactas */
    .nav-tabs {
        font-size: 14px;
    }
    
    .nav-tabs .nav-link {
        padding: 8px 12px;
    }
}

/* ============================================================================
   BONUS: Mejoras Adicionales de UX Móvil
   ============================================================================
   Tiempo adicional: ~20 minutos
   No son Quick Wins pero mejoran significativamente la experiencia
   ============================================================================ */

@media (max-width: 767px) {
    /* ========================================
       Mejora: Scroll horizontal tablas (fallback)
       ======================================== */
    
    /* Si tabla es muy ancha, scroll horizontal suave */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border-radius: 8px;
    }
    
    /* Sombra indica más contenido a la derecha */
    .table-responsive::-webkit-scrollbar {
        height: 8px;
    }
    
    .table-responsive::-webkit-scrollbar-thumb {
        background: rgba(0, 0, 0, 0.2);
        border-radius: 4px;
    }
    
    /* ========================================
       Mejora: Forms más user-friendly
       ======================================== */
    
    /* Labels más prominentes */
    label {
        font-weight: 500;
        margin-bottom: 6px;
        font-size: 14px;
    }
    
    /* Form groups con más espacio */
    .form-group,
    .mb-3 {
        margin-bottom: 16px;
    }
    
    /* Checkboxes y radios más grandes */
    .form-check-input {
        width: 20px;
        height: 20px;
        margin-top: 2px;
    }
    
    .form-check-label {
        padding-left: 8px;
        font-size: 16px; /* Evita zoom */
    }
    
    /* ========================================
       Mejora: Alerts y Toasts
       ======================================== */
    
    /* Alerts full-width */
    .alert {
        border-radius: 8px;
        padding: 12px 16px;
        margin-bottom: 12px;
        font-size: 14px;
    }
    
    /* Toasts más grandes y visibles */
    .toast {
        max-width: 100%;
        margin: 8px;
        font-size: 14px;
    }
    
    /* ========================================
       Mejora: Dropdowns touch-friendly
       ======================================== */
    
    .dropdown-menu {
        font-size: 16px; /* Evita zoom */
        min-width: 200px;
    }
    
    .dropdown-item {
        padding: 12px 16px;
        min-height: 44px;
        display: flex;
        align-items: center;
    }
    
    /* ========================================
       Mejora: Badges y Pills
       ======================================== */
    
    .badge {
        padding: 6px 12px;
        font-size: 13px;
        border-radius: 6px;
    }
    
    /* ========================================
       Mejora: Loading States
       ======================================== */
    
    /* Spinners más visibles */
    .spinner-border,
    .spinner-grow {
        width: 2rem;
        height: 2rem;
    }
    
    /* Loading overlay */
    .loading-overlay {
        background: rgba(255, 255, 255, 0.9);
        backdrop-filter: blur(2px);
    }
    
    /* ========================================
       Mejora: Navegación (Nav Pills, Tabs)
       ======================================== */
    
    .nav-pills .nav-link {
        padding: 10px 16px;
        margin-bottom: 6px;
        font-size: 16px;
    }
    
    /* ========================================
       Mejora: Pagination
       ======================================== */
    
    .pagination {
        flex-wrap: wrap;
        gap: 4px;
    }
    
    .page-link {
        padding: 8px 12px;
        font-size: 16px;
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    /* Ocultar números intermedios en móvil */
    .pagination .page-item:not(.active):not(:first-child):not(:last-child) {
        display: none;
    }
    
    /* Mostrar solo: ← 1 ... [5] ... 10 → */
    .pagination .page-item.active,
    .pagination .page-item:first-child,
    .pagination .page-item:last-child {
        display: flex;
    }
}

/* ============================================================================
   TABLET ESPECÍFICO (768px - 1024px)
   ============================================================================
   Mejoras leves para tablets - no son tan críticas como móvil
   ============================================================================ */

@media (min-width: 768px) and (max-width: 1024px) {
    /* Inputs aún evitan zoom */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="search"],
    input[type="number"],
    input[type="date"],
    select,
    textarea {
        font-size: 16px;
    }
    
    /* Botones touch-friendly (tablets también son táctiles) */
    .btn {
        min-height: 40px;
        padding: 10px 14px;
    }
    
    /* Stats cards 2 columnas en tablet */
    .stats-cards-container,
    .row.mb-4 {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }
    
    /* Modales no full-screen pero más anchos */
    .modal-dialog {
        max-width: 90%;
    }
}

/* ============================================================================
   LANDSCAPE MODE (Móvil horizontal)
   ============================================================================
   Ajustes para cuando el usuario rota el teléfono
   ============================================================================ */

@media (max-width: 767px) and (orientation: landscape) {
    /* En landscape, tenemos más ancho pero menos alto */
    
    /* Reducir padding vertical */
    .modal-header,
    .modal-footer {
        padding-top: 8px;
        padding-bottom: 8px;
    }
    
    /* Stats cards 2 columnas en landscape */
    .stats-cards-container,
    .row.mb-4 {
        grid-template-columns: repeat(2, 1fr);
    }
    
    /* Headers más compactos */
    h1 {
        font-size: 1.5rem;
    }
    
    h2 {
        font-size: 1.25rem;
    }
}

/* ============================================================================
   DARK MODE (Bonus - si ya lo soportas)
   ============================================================================
   Ajustes para dark mode en móvil
   ============================================================================ */

@media (max-width: 767px) and (prefers-color-scheme: dark) {
    .search-section {
        background: #1a1a1a;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
    }
    
    .modal-header,
    .modal-footer {
        background: #1a1a1a;
        border-color: #333;
    }
    
    .modal-content {
        background: #1a1a1a;
        color: #e0e0e0;
    }
}

/* ============================================================================
   ACCESSIBILITY (a11y) - Crítico para todos los usuarios
   ============================================================================ */

@media (max-width: 767px) {
    /* Focus states más visibles en táctil */
    *:focus-visible {
        outline: 3px solid #0d6efd;
        outline-offset: 2px;
    }
    
    /* Skip to main content link */
    .skip-to-main {
        position: absolute;
        top: -40px;
        left: 0;
        background: #0d6efd;
        color: white;
        padding: 8px 16px;
        z-index: 9999;
    }
    
    .skip-to-main:focus {
        top: 0;
    }
}

/* ============================================================================
   PERFORMANCE OPTIMIZATIONS
   ============================================================================ */

@media (max-width: 767px) {
    /* Smooth scrolling pero solo en móvil (puede causar lag en desktop) */
    html {
        scroll-behavior: smooth;
    }
    
    /* GPU acceleration para animaciones */
    .modal,
    .search-section,
    .sticky-element {
        transform: translateZ(0);
        will-change: transform;
    }
}

/* ============================================================================
   FIN DE MOBILE IMPROVEMENTS
   ============================================================================
   
   Próximos pasos (Fase 2):
   - Tablas → Cards (transformación completa)
   - Bottom navigation bar
   - Filtros colapsables con accordion
   - Pull-to-refresh
   
   ============================================================================ */

/* ============================================================================
   FASE 1.5 - ARREGLOS CRÍTICOS (02 Oct 2025)
   ============================================================================ */

@media (max-width: 767px) {
    /* MOBILE HEADER */
    .mobile-header {
        position: fixed !important;
        top: 0;
        left: 0;
        right: 0;
        height: 56px;
        background: var(--surface-color, #ffffff);
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
        z-index: 1000;
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0 16px;
    }
    
    #hamburgerBtn {
        width: 44px;
        height: 44px;
        border: none;
        background: transparent;
        font-size: 24px;
        cursor: pointer;
    }
    
    /* DRAWER */
    .drawer {
        position: fixed;
        top: 0;
        left: -280px;
        width: 280px;
        height: 100vh;
        background: var(--surface-color, #ffffff);
        box-shadow: 2px 0 8px rgba(0,0,0,0.15);
        z-index: 1001;
        transition: left 0.3s ease;
        overflow-y: auto;
    }
    
    .drawer.open {
        left: 0;
    }
    
    .drawer-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 1000;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s;
    }
    
    .drawer-overlay.visible {
        opacity: 1;
        pointer-events: auto;
    }
    
    /* BOTTOM NAVIGATION FIXED */
    .bottom-navigation {
        position: fixed !important;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 999;
        padding-bottom: env(safe-area-inset-bottom, 0px);
        background: var(--surface-color, #ffffff);
        box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
    }
    
    /* BOTTOM SHEET */
    .bottom-sheet {
        position: fixed;
        bottom: -100%;
        left: 0;
        right: 0;
        background: var(--surface-color, #ffffff);
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -4px 16px rgba(0,0,0,0.15);
        z-index: 1002;
        transition: bottom 0.3s ease;
        max-height: 70vh;
        overflow-y: auto;
    }
    
    .bottom-sheet.open {
        bottom: 0;
    }
    
    .sheet-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 1001;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s;
    }
    
    .sheet-overlay.visible {
        opacity: 1;
        pointer-events: auto;
    }
}

/* ============================================================================
   DESKTOP - OCULTAR ELEMENTOS MOBILE
   ============================================================================
   Bug fix: El drawer menu se mostraba parcialmente en desktop
   Solución: Ocultar completamente drawer, overlay y mobile-header en desktop
   ============================================================================ */

@media (min-width: 768px) {
    /* Ocultar drawer menu en desktop */
    .drawer,
    #drawerMenu {
        display: none !important;
    }
    
    /* Ocultar overlay del drawer en desktop */
    .drawer-overlay,
    #drawerOverlay {
        display: none !important;
    }
    
    /* Ocultar header mobile en desktop */
    .mobile-header {
        display: none !important;
    }
    
    /* Ocultar bottom navigation en desktop */
    .bottom-navigation {
        display: none !important;
    }
    
    /* Ocultar bottom sheet en desktop */
    .bottom-sheet,
    .sheet-overlay {
        display: none !important;
    }
}
