/**
 * Optimisations Mobile Avancées
 * ENT L'Escale - Décembre 2025
 */

/* ============= PERFORMANCE & UX MOBILE ============= */

/* Désactiver les effets hover sur tactile */
@media (hover: none) and (pointer: coarse) {
    *:hover {
        /* Pas d'effet hover sur mobile tactile */
    }
}

/* Smooth scroll sur mobile */
html {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

/* Touch-friendly tap targets (min 44x44px) */
button, a, input[type="button"], input[type="submit"], .btn {
    min-height: 44px;
    min-width: 44px;
    touch-action: manipulation; /* Disable double-tap zoom */
}

/* Éviter le zoom involontaire sur focus d'input */
input, select, textarea {
    font-size: 16px !important; /* iOS ne zoom pas si >= 16px */
}

/* ============= LAYOUT RESPONSIVE ============= */

/* Containers full-width sur mobile */
@media (max-width: 768px) {
    .container, .container-fluid {
        padding-left: 1rem;
        padding-right: 1rem;
    }
    
    /* Sections avec moins de padding */
    section {
        padding: 1.5rem 0;
    }
    
    /* Headers compacts */
    h1 { font-size: 1.75rem; }
    h2 { font-size: 1.5rem; }
    h3 { font-size: 1.25rem; }
    h4 { font-size: 1.1rem; }
    h5 { font-size: 1rem; }
    h6 { font-size: 0.9rem; }
}

/* ============= FORMULAIRES MOBILE-FRIENDLY ============= */

@media (max-width: 768px) {
    /* Inputs pleine largeur */
    .form-control, .form-select {
        width: 100%;
        font-size: 16px;
        padding: 0.75rem;
        border-radius: 8px;
    }
    
    /* Labels au-dessus des inputs */
    .form-group label {
        display: block;
        margin-bottom: 0.5rem;
        font-weight: 600;
    }
    
    /* Checkboxes et radios plus grands */
    input[type="checkbox"],
    input[type="radio"] {
        width: 22px;
        height: 22px;
        margin-right: 0.5rem;
    }
    
    /* Boutons pleine largeur sauf inline */
    .btn:not(.btn-sm):not(.btn-inline) {
        width: 100%;
        padding: 0.875rem;
        font-size: 1rem;
        margin-bottom: 0.5rem;
    }
    
    .btn-group {
        display: flex;
        flex-wrap: wrap;
    }
    
    .btn-group .btn {
        flex: 1;
        min-width: auto;
    }
}

/* ============= TABLES MOBILE ============= */

@media (max-width: 768px) {
    /* Table responsive avec scroll */
    .table-responsive {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border: 1px solid #dee2e6;
        border-radius: 8px;
    }
    
    table {
        font-size: 0.875rem;
        margin-bottom: 0;
    }
    
    .table th,
    .table td {
        padding: 0.5rem;
        white-space: nowrap;
        vertical-align: middle;
    }
    
    /* Première colonne sticky */
    .table-sticky-first thead th:first-child,
    .table-sticky-first tbody td:first-child {
        position: sticky;
        left: 0;
        background: white;
        z-index: 10;
        box-shadow: 2px 0 5px rgba(0,0,0,0.05);
    }
}

/* ============= CARDS MOBILE ============= */

@media (max-width: 768px) {
    .card {
        margin-bottom: 1rem;
        border-radius: 12px;
        box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    }
    
    .card-header {
        padding: 1rem;
        font-size: 1rem;
        font-weight: 600;
    }
    
    .card-body {
        padding: 1rem;
    }
    
    .card-footer {
        padding: 0.75rem 1rem;
    }
    
    /* Cards horizontales deviennent verticales */
    .card.flex-row {
        flex-direction: column !important;
    }
}

/* ============= MODALS MOBILE ============= */

@media (max-width: 768px) {
    .modal {
        padding: 0 !important;
    }
    
    .modal-dialog {
        margin: 0;
        max-width: 100%;
        height: 100%;
    }
    
    .modal-content {
        height: 100%;
        border: none;
        border-radius: 0;
    }
    
    .modal-header {
        padding: 1rem;
        border-bottom: 1px solid #dee2e6;
    }
    
    .modal-body {
        padding: 1rem;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .modal-footer {
        padding: 1rem;
        border-top: 1px solid #dee2e6;
    }
    
    .modal-footer .btn {
        width: 100%;
    }
}

/* ============= NAVIGATION MOBILE ============= */

@media (max-width: 768px) {
    /* Navbar sticky top */
    nav.navbar-header {
        position: sticky;
        top: 0;
        z-index: 1000;
        background: white;
        box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    }
    
    /* Dropdown menus full-width */
    .dropdown-menu {
        width: 100%;
        max-width: 100%;
        border-radius: 8px;
        box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    }
    
    .dropdown-item {
        padding: 0.75rem 1rem;
        font-size: 1rem;
    }
}

/* ============= GRIDS RESPONSIVE ============= */

@media (max-width: 768px) {
    /* Colonnes empilées sur mobile */
    .row > [class*='col-'] {
        margin-bottom: 1rem;
    }
    
    /* Grid avec gap réduit */
    .row {
        margin-left: -0.5rem;
        margin-right: -0.5rem;
    }
    
    .row > * {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }
}

/* ============= IMAGES & MEDIA RESPONSIVE ============= */

@media (max-width: 768px) {
    img, video, iframe {
        max-width: 100%;
        height: auto;
    }
    
    /* Avatar circles plus petits */
    .avatar {
        width: 40px;
        height: 40px;
    }
    
    .avatar-lg {
        width: 60px;
        height: 60px;
    }
}

/* ============= BADGES & LABELS ============= */

@media (max-width: 768px) {
    .badge {
        font-size: 0.75rem;
        padding: 0.35em 0.65em;
    }
    
    .badge-lg {
        font-size: 0.85rem;
        padding: 0.5em 0.85em;
    }
}

/* ============= ALERTS MOBILE ============= */

@media (max-width: 768px) {
    .alert {
        font-size: 0.9rem;
        padding: 0.75rem 1rem;
        border-radius: 8px;
    }
}

/* ============= PAGINATION MOBILE ============= */

@media (max-width: 768px) {
    .pagination {
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .page-item {
        margin: 0.25rem;
    }
    
    .page-link {
        padding: 0.5rem 0.75rem;
        font-size: 0.9rem;
    }
}

/* ============= UTILITIES MOBILE ============= */

/* Hide on mobile */
.d-mobile-none {
    display: none !important;
}

@media (min-width: 769px) {
    .d-mobile-none {
        display: block !important;
    }
    
    .d-desktop-none {
        display: none !important;
    }
}

/* Text truncate sur mobile */
.text-mobile-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

/* Stack flex items sur mobile */
@media (max-width: 768px) {
    .flex-mobile-column {
        flex-direction: column !important;
    }
    
    .flex-mobile-column > * {
        width: 100% !important;
        margin-bottom: 0.5rem;
    }
}

/* ============= PERFORMANCE ============= */

/* GPU acceleration pour animations fluides */
.sidebar-wrapper,
.modal,
.dropdown-menu {
    transform: translateZ(0);
    will-change: transform;
}

/* Disable animations sur connexion lente */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
