/* ==========================================================================
   Mobile-First & Touch Optimizations
   Styles globaux pour améliorer l'expérience mobile et tactile
   ========================================================================== */

/* ==========================================================================
   Variables CSS pour mobile
   ========================================================================== */

:root {
    /* Tailles tactiles minimales */
    --touch-target-min: 44px;
    --touch-target-comfortable: 48px;
    
    /* Espacements mobiles */
    --mobile-padding: 1rem;
    --mobile-margin: 0.75rem;
    
    /* Z-index */
    --z-drawer: 1050;
    --z-overlay: 1040;
    --z-modal: 1055;
    --z-toast: 1060;
}

/* ==========================================================================
   Touch optimizations - Zones tactiles
   ========================================================================== */

/* Boutons et éléments interactifs - Taille minimale recommandée */
@media (max-width: 768px) {
    .btn,
    button,
    a.btn,
    input[type="button"],
    input[type="submit"],
    input[type="reset"] {
        min-height: var(--touch-target-min);
        min-width: var(--touch-target-min);
        padding: 0.625rem 1rem;
    }
    
    /* Boutons larges sur mobile pour faciliter le tap */
    .btn-block-mobile {
        display: block;
        width: 100%;
    }
    
    /* Liens et boutons texte */
    a:not(.btn),
    button.link-button {
        padding: 0.5rem;
        margin: -0.5rem; /* Compensation pour agrandir la zone de tap */
    }
}

/* ==========================================================================
   Formulaires optimisés pour tactile
   ========================================================================== */

@media (max-width: 768px) {
    /* Inputs plus grands sur mobile */
    .form-control,
    .form-select,
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="tel"],
    input[type="date"],
    input[type="time"],
    textarea,
    select {
        min-height: var(--touch-target-comfortable);
        font-size: 1rem; /* Évite le zoom automatique sur iOS */
        padding: 0.75rem 1rem;
        border-radius: 0.5rem;
    }
    
    /* Labels plus espacés */
    label {
        margin-bottom: 0.625rem;
        font-weight: 600;
    }
    
    /* Groupes de formulaire */
    .form-group,
    .mb-3 {
        margin-bottom: 1.25rem;
    }
    
    /* Checkboxes et radios */
    input[type="checkbox"],
    input[type="radio"] {
        width: 1.25rem;
        height: 1.25rem;
        cursor: pointer;
    }
    
    /* Labels de checkbox/radio cliquables */
    .form-check-label {
        padding-left: 0.5rem;
        cursor: pointer;
        min-height: var(--touch-target-min);
        display: flex;
        align-items: center;
    }
}

/* ==========================================================================
   Modals optimisés pour mobile
   ========================================================================== */

@media (max-width: 768px) {
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }
    
    .modal-fullscreen-mobile {
        width: 100vw;
        max-width: 100vw;
        height: 100vh;
        margin: 0;
    }
    
    .modal-fullscreen-mobile .modal-content {
        height: 100vh;
        border: 0;
        border-radius: 0;
    }
    
    .modal-header {
        padding: 1.25rem 1.5rem;
    }
    
    .modal-body {
        padding: 1.5rem;
    }
    
    .modal-footer {
        padding: 1rem 1.5rem;
        gap: 0.75rem;
    }
    
    .modal-footer .btn {
        flex: 1;
    }
}

/* ==========================================================================
   Tables responsive - Cache sur mobile (utiliser MobileCard à la place)
   ========================================================================== */

@media (max-width: 768px) {
    .table-responsive {
        border: 0;
    }
    
    /* Cacher les tableaux si une alternative mobile existe */
    .table-responsive:has(+ .mobile-card-list) {
        display: none;
    }
    
    /* Tableaux horizontalement scrollables (si pas d'alternative) */
    .table-responsive table {
        font-size: 0.875rem;
    }
    
    .table-responsive th,
    .table-responsive td {
        padding: 0.5rem;
        white-space: nowrap;
    }
}

/* ==========================================================================
   Navigation et menus mobiles
   ========================================================================== */

@media (max-width: 768px) {
    /* Navbar mobile-friendly */
    .navbar {
        padding: 0.75rem 1rem;
    }
    
    .navbar-brand {
        font-size: 1.125rem;
    }
    
    .navbar-toggler {
        min-height: var(--touch-target-min);
        min-width: var(--touch-target-min);
        padding: 0.5rem;
        border: none;
    }
    
    /* Menu déroulant full-width sur mobile */
    .dropdown-menu {
        width: 100%;
        border: none;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    }
    
    .dropdown-item {
        padding: 0.875rem 1.5rem;
        font-size: 1rem;
    }
}

/* ==========================================================================
   Cards optimisées pour mobile
   ========================================================================== */

@media (max-width: 768px) {
    .card {
        border-radius: 0.75rem;
        margin-bottom: var(--mobile-margin);
    }
    
    .card-header {
        padding: 1rem 1.25rem;
        font-size: 1rem;
    }
    
    .card-body {
        padding: 1rem 1.25rem;
    }
    
    .card-footer {
        padding: 1rem 1.25rem;
    }
    
    /* Cards sans ombre sur mobile (plus flat) */
    .card-flat-mobile {
        box-shadow: none;
        border: 1px solid var(--bs-border-color);
    }
}

/* ==========================================================================
   Typography mobile
   ========================================================================== */

@media (max-width: 768px) {
    /* Titres plus petits sur mobile */
    h1, .h1 { font-size: 1.75rem; }
    h2, .h2 { font-size: 1.5rem; }
    h3, .h3 { font-size: 1.25rem; }
    h4, .h4 { font-size: 1.125rem; }
    h5, .h5 { font-size: 1rem; }
    h6, .h6 { font-size: 0.9375rem; }
    
    /* Corps de texte optimisé pour lecture mobile */
    body {
        font-size: 0.9375rem;
        line-height: 1.6;
    }
    
    /* Textes plus petits */
    small, .small {
        font-size: 0.8125rem;
    }
}

/* ==========================================================================
   Espacements et grilles mobiles
   ========================================================================== */

@media (max-width: 768px) {
    /* Réduire les espacements */
    .container,
    .container-fluid {
        padding-left: var(--mobile-padding);
        padding-right: var(--mobile-padding);
    }
    
    /* Marges verticales réduites */
    .mb-3, .my-3 { margin-bottom: 1rem !important; }
    .mb-4, .my-4 { margin-bottom: 1.25rem !important; }
    .mb-5, .my-5 { margin-bottom: 1.5rem !important; }
    
    .mt-3, .my-3 { margin-top: 1rem !important; }
    .mt-4, .my-4 { margin-top: 1.25rem !important; }
    .mt-5, .my-5 { margin-top: 1.5rem !important; }
    
    /* Colonnes full-width par défaut */
    [class*="col-"] {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }
}

/* ==========================================================================
   Scroll fluide et performance
   ========================================================================== */

/* Désactiver le rebond du scroll sur iOS */
body {
    overscroll-behavior-y: none;
}

/* Scroll snap pour les carousels sur mobile */
.scroll-snap-mobile {
    scroll-snap-type: x mandatory;
    scroll-behavior: smooth;
}

.scroll-snap-mobile > * {
    scroll-snap-align: start;
}

/* ==========================================================================
   Gestes et interactions tactiles
   ========================================================================== */

/* Désactiver le callout sur iOS (menu contextuel au long press) */
a, button, img {
    -webkit-touch-callout: none;
}

/* Activer le callout uniquement pour les liens avec href */
a[href] {
    -webkit-touch-callout: default;
}

/* Tap highlight transparent (évite le flash bleu sur Android) */
* {
    -webkit-tap-highlight-color: transparent;
}

/* Restaurer le tap highlight pour les liens */
a, button, input, select, textarea {
    -webkit-tap-highlight-color: rgba(13, 110, 253, 0.1);
}

/* Curseur pointer pour éléments interactifs */
@media (hover: hover) and (pointer: fine) {
    button, a, input[type="submit"], input[type="button"], .clickable {
        cursor: pointer;
    }
}

/* ==========================================================================
   Pull to refresh (iOS Safari)
   ========================================================================== */

/* Désactiver le pull-to-refresh natif si on a un custom implementation */
body.disable-pull-refresh {
    overscroll-behavior-y: contain;
}

/* ==========================================================================
   Safe areas (notch iPhone, etc.)
   ========================================================================== */

@supports (padding: env(safe-area-inset-top)) {
    body {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }
    
    /* Header fixe avec safe area */
    .header-fixed {
        padding-top: calc(0.5rem + env(safe-area-inset-top));
    }
    
    /* Footer fixe avec safe area */
    .footer-fixed {
        padding-bottom: calc(0.5rem + env(safe-area-inset-bottom));
    }
}

/* ==========================================================================
   Orientations (portrait/landscape)
   ========================================================================== */

@media (orientation: landscape) and (max-height: 500px) {
    /* Réduire les espacements en landscape mobile */
    .modal-header,
    .modal-body,
    .modal-footer {
        padding: 0.75rem 1rem;
    }
    
    .card-header,
    .card-body,
    .card-footer {
        padding: 0.75rem 1rem;
    }
}

/* ==========================================================================
   Utilitaires mobile-first
   ========================================================================== */

/* Afficher uniquement sur mobile */
@media (min-width: 769px) {
    .mobile-only {
        display: none !important;
    }
}

/* Cacher sur mobile */
@media (max-width: 768px) {
    .desktop-only {
        display: none !important;
    }
}

/* Texte tronqué sur mobile */
@media (max-width: 768px) {
    .text-truncate-mobile {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}

/* Stack vertical sur mobile */
@media (max-width: 768px) {
    .stack-mobile {
        display: flex !important;
        flex-direction: column !important;
        gap: 0.75rem !important;
    }
    
    .stack-mobile > * {
        width: 100% !important;
    }
}

/* ==========================================================================
   Performance optimizations
   ========================================================================== */

/* Hardware acceleration pour les animations */
.will-change-transform {
    will-change: transform;
}

.will-change-opacity {
    will-change: opacity;
}

/* Optimiser le rendu des images sur mobile */
@media (max-width: 768px) {
    img {
        max-width: 100%;
        height: auto;
        image-rendering: -webkit-optimize-contrast;
    }
}

/* ==========================================================================
   Accessibilité tactile
   ========================================================================== */

/* Focus visible optimisé pour navigation clavier */
:focus-visible {
    outline: 2px solid var(--bs-primary, #0d6efd);
    outline-offset: 2px;
    border-radius: 0.25rem;
}

/* Skip link pour navigation clavier */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--bs-primary);
    color: white;
    padding: 8px;
    text-decoration: none;
    z-index: 100;
}

.skip-link:focus {
    top: 0;
}

/* ==========================================================================
   Préchargement et états de chargement
   ========================================================================== */

/* Skeleton loader pour mobile */
.skeleton-mobile {
    background: linear-gradient(
        90deg,
        var(--bs-gray-200) 25%,
        var(--bs-gray-300) 50%,
        var(--bs-gray-200) 75%
    );
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
    border-radius: 0.375rem;
}

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ==========================================================================
   Mode sombre mobile - DÉSACTIVÉ
   ========================================================================== */

/* @media (prefers-color-scheme: dark) {
    :root {
        --bs-body-bg: #1a1d20;
        --bs-body-color: #f8f9fa;
        --bs-border-color: #495057;
    }
    
    @media (max-width: 768px) {
        .card {
            background: var(--bs-dark, #212529);
            border-color: var(--bs-border-color);
        }
        
        .form-control,
        .form-select {
            background: var(--bs-dark, #212529);
            border-color: var(--bs-border-color);
            color: var(--bs-light, #f8f9fa);
        }
        
        .modal-content {
            background: var(--bs-dark, #212529);
            color: var(--bs-light, #f8f9fa);
        }
    }
} */

/* ==========================================================================
   Print styles (masquer sur impression)
   ========================================================================== */

@media print {
    .mobile-drawer,
    .mobile-drawer-overlay,
    .mobile-card-actions,
    .btn,
    .navbar,
    .footer {
        display: none !important;
    }
}
