/**
 * iOS Safari Specific Styles
 * Fixes para problemas de visualización en iPhone/iPad
 */

/* ============================================
   1. VIEWPORT HEIGHT FIX
   ============================================ */
/* iOS Safari no calcula bien el 100vh debido a la barra de navegación */
body {
    /* Usar la variable CSS definida en ios-compat.js */
    min-height: 100vh;
    min-height: calc(var(--vh, 1vh) * 100);
}

.login-container {
    /* Ajustar posición en móvil */
    margin-top: 20vh;
}

@media (max-width: 768px) {
    .login-container {
        margin-top: 10vh;
        margin-left: 15px;
        margin-right: 15px;
    }
}

/* ============================================
   2. SMOOTH SCROLLING
   ============================================ */
/* iOS necesita -webkit-overflow-scrolling para scroll suave */
* {
    -webkit-overflow-scrolling: touch;
}

html {
    -webkit-text-size-adjust: 100%;
}

/* ============================================
   3. INPUT & FORM FIXES
   ============================================ */
/* iOS añade sombras y bordes raros a los inputs */
input,
textarea,
select,
button {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    border-radius: 4px;
}

/* Fix para el borde interno de los inputs en iOS */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="tel"],
textarea {
    -webkit-appearance: none;
    appearance: none;
}

/* Evitar zoom automático en inputs en iOS */
@media screen and (max-width: 768px) {
    input,
    textarea,
    select {
        font-size: 16px !important;
    }
}

/* ============================================
   4. BUTTON ACTIVE STATES
   ============================================ */
/* iOS no muestra bien el :active en touch */
.btn:active,
button:active {
    opacity: 0.7;
    transform: scale(0.98);
}

/* Eliminar highlight azul en tap de iOS */
* {
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
    -webkit-touch-callout: none;
}

/* Pero mantenerlo en links */
a {
    -webkit-tap-highlight-color: rgba(225, 6, 0, 0.2);
}

/* ============================================
   5. FIXED POSITIONING
   ============================================ */
/* iOS tiene problemas con position: fixed en scroll */
.header,
.main-nav {
    position: -webkit-sticky;
    position: sticky;
    top: 0;
    z-index: 1000;
}

/* ============================================
   6. FLEXBOX FIXES
   ============================================ */
/* iOS Safari viejo tiene bugs con flexbox */
.flex-container {
    display: -webkit-box;
    display: -webkit-flex;
    display: flex;
}

.flex-item {
    -webkit-box-flex: 1;
    -webkit-flex: 1;
    flex: 1;
}

/* ============================================
   7. MENU MÓVIL
   ============================================ */
@media (max-width: 768px) {
    /* Asegurar que el menú sea accesible en móvil */
    .main-nav {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .main-nav ul {
        display: flex;
        flex-wrap: nowrap;
        min-width: min-content;
    }
    
    .main-nav li {
        flex-shrink: 0;
        white-space: nowrap;
    }
}

/* ============================================
   8. SAFE AREA (iPhone X+)
   ============================================ */
/* Soporte para el notch de iPhone X y superiores */
body {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

.header {
    padding-top: max(20px, env(safe-area-inset-top));
}

.main-nav {
    padding-left: max(0px, env(safe-area-inset-left));
    padding-right: max(0px, env(safe-area-inset-right));
}

/* ============================================
   9. MODAL FIXES
   ============================================ */
/* iOS tiene problemas con modals y scroll */
.modal.show {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.modal-content {
    position: relative;
    margin: 50px auto;
}

/* Prevenir scroll del body cuando modal está abierto */
body.modal-open {
    position: fixed;
    width: 100%;
    overflow: hidden;
}

/* ============================================
   10. TOUCH GESTURES
   ============================================ */
/* Mejorar el área de touch en elementos pequeños */
.btn-sm,
.badge,
.remove-rider-btn {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* ============================================
   11. FONTS
   ============================================ */
/* iOS renderiza mejor con system fonts */
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 
                 Helvetica, Arial, sans-serif, 'Apple Color Emoji';
}

/* ============================================
   12. LOADING STATES
   ============================================ */
/* Feedback visual durante carga en iOS */
.loading {
    position: relative;
    pointer-events: none;
    opacity: 0.6;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid #e10600;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ============================================
   13. TABLES RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
    /* Tablas scrollables en móvil */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    table {
        min-width: 600px;
    }
}

/* ============================================
   14. IMAGES
   ============================================ */
/* Prevenir imágenes desbordadas */
img {
    max-width: 100%;
    height: auto;
}

/* iOS a veces añade un border azul raro */
img {
    border: 0;
}

/* ============================================
   15. ORIENTATION CHANGES
   ============================================ */
/* Reajustar cuando cambia la orientación */
@media (orientation: landscape) and (max-height: 500px) {
    .login-container {
        margin-top: 5vh;
        padding: 20px;
    }
    
    .login-header h1 {
        font-size: 1.8em;
    }
}

/* ============================================
   16. DARK MODE SUPPORT (iOS 13+)
   ============================================ */
@media (prefers-color-scheme: dark) {
    /* Opcional: Si quieres soporte para dark mode */
    /* 
    body {
        background-color: #1a1a1a;
        color: #f5f5f5;
    }
    */
}

/* ============================================
   17. ACCESSIBILITY
   ============================================ */
/* iOS VoiceOver support */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ============================================
   18. PERFORMANCE
   ============================================ */
/* Hardware acceleration para animaciones */
.modal,
.btn,
.card {
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

/* ============================================
   19. SPECIFIC iOS CLASS STYLES
   ============================================ */
/* Estos se activan cuando ios-compat.js añade la clase .ios al body */

.ios .form-group input,
.ios .form-group select,
.ios .form-group textarea {
    /* Mayor padding en iOS para evitar zoom */
    padding: 12px;
    font-size: 16px;
}

.ios .btn {
    /* Botones más grandes en iOS para mejor touch */
    padding: 12px 24px;
}

/* ============================================
   20. DEBUG HELPERS (REMOVER EN PRODUCCIÓN)
   ============================================ */
.debug-ios-info {
    position: fixed;
    bottom: 10px;
    right: 10px;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 10px;
    border-radius: 5px;
    font-size: 12px;
    font-family: monospace;
    z-index: 9999;
    max-width: 200px;
}

/* Ocultar por defecto */
.debug-ios-info {
    display: none;
}

/* Activar con ?debug=1 en la URL */
body.debug .debug-ios-info {
    display: block;
}
