/**
 * MOAMOA - CORRECTIONS RESPONSIVE MOBILE GLOBALES
 * Normes 2025 - Touch-Friendly, iOS-Safe, WCAG 2.1
 * Version: 1.0.0
 * Date: 30 Octobre 2025
 *
 * UTILISATION:
 * À inclure dans header.php APRÈS tous les autres CSS
 * <link rel="stylesheet" href="/css/mobile-responsive-fix.css">
 */

/* ============================================
   1. RESET & FONDATIONS
   ============================================ */

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

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

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

/* ============================================
   2. TYPOGRAPHY RESPONSIVE
   ============================================ */

@media (max-width: 768px) {
    body {
        font-size: 16px; /* iOS-safe - évite zoom automatique */
    }

    h1 {
        font-size: clamp(1.5rem, 5vw, 2rem);
        line-height: 1.2;
    }

    h2 {
        font-size: clamp(1.25rem, 4vw, 1.75rem);
        line-height: 1.3;
    }

    h3 {
        font-size: clamp(1.125rem, 3.5vw, 1.5rem);
        line-height: 1.4;
    }

    h4 {
        font-size: clamp(1rem, 3vw, 1.25rem);
        line-height: 1.4;
    }

    p, span, div, li {
        font-size: clamp(0.875rem, 3vw, 1rem);
        line-height: 1.6;
    }
}

@media (max-width: 425px) {
    h1 {
        font-size: 1.5rem;
    }

    h2 {
        font-size: 1.25rem;
    }
}

/* ============================================
   3. INPUTS & FORMS (iOS-SAFE)
   ============================================ */

@media (max-width: 768px) {
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="tel"],
    input[type="url"],
    input[type="search"],
    input[type="date"],
    input[type="time"],
    input[type="datetime-local"],
    select,
    textarea {
        font-size: 16px !important; /* CRITIQUE: Évite zoom iOS */
        padding: 14px 16px;
        min-height: 48px;
        border-radius: 8px;
        width: 100%;
        -webkit-appearance: none;
        -moz-appearance: none;
        appearance: none;
        box-sizing: border-box;
    }

    select {
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23333' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: right 12px center;
        padding-right: 40px;
    }

    textarea {
        min-height: 120px;
        resize: vertical;
    }

    .form-control {
        font-size: 16px !important;
    }
}

/* Labels visibles */
@media (max-width: 768px) {
    label,
    .form-label {
        display: block;
        margin-bottom: 0.5rem;
        font-weight: 500;
        font-size: 0.875rem;
    }
}

/* ============================================
   4. BUTTONS TOUCH-FRIENDLY (44x44px minimum)
   ============================================ */

@media (max-width: 768px) {
    button,
    .btn,
    .action-btn,
    a.button,
    input[type="submit"],
    input[type="button"],
    .btn-primary,
    .btn-secondary,
    .btn-success,
    .btn-danger,
    .btn-warning {
        min-height: 44px;
        min-width: 44px;
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
        border-radius: 8px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 0.5rem;
        text-align: center;
        cursor: pointer;
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
        box-sizing: border-box;
    }

    /* Boutons full-width sur mobile pour formulaires */
    .btn-primary,
    .btn-submit,
    button[type="submit"],
    form .btn {
        width: 100%;
    }

    /* Groupes de boutons */
    .action-buttons,
    .button-group,
    .btn-group {
        flex-direction: column;
        gap: 0.75rem;
    }

    .action-buttons button,
    .button-group button,
    .btn-group button {
        width: 100%;
    }
}

/* ============================================
   5. CONTAINERS & LAYOUT
   ============================================ */

@media (max-width: 768px) {
    .dashboard-container,
    .container,
    .main-content {
        padding-left: 1rem;
        padding-right: 1rem;
        margin-left: auto;
        margin-right: auto;
        max-width: 100%;
        overflow-x: hidden;
    }

    .customer-dashboard,
    .customer-orders,
    .customer-account {
        padding-left: 1rem;
        padding-right: 1rem;
        max-width: 100%;
    }

    /* Headers avec décorations */
    .welcome-header,
    .page-header {
        padding: 1.5rem 1rem !important;
        overflow: hidden;
        position: relative;
    }

    /* Cache pseudo-éléments décoratifs qui débordent */
    .welcome-header::before,
    .welcome-header::after,
    .page-header::before,
    .page-header::after {
        display: none !important;
    }

    /* Welcome Content flex */
    .welcome-content {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .welcome-text h1 {
        font-size: 1.75rem;
    }

    .welcome-text p {
        font-size: 0.95rem;
    }
}

@media (max-width: 425px) {
    .dashboard-container,
    .container,
    .main-content {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }

    .welcome-header,
    .page-header {
        padding: 1.25rem 0.75rem !important;
    }

    .welcome-text h1 {
        font-size: 1.5rem;
    }
}

/* ============================================
   6. GRIDS RESPONSIVE
   ============================================ */

@media (max-width: 768px) {
    .dashboard-grid,
    .stats-grid,
    .products-grid,
    .quick-actions,
    .tools-grid,
    .grid,
    [class*="-grid"] {
        grid-template-columns: 1fr !important;
        gap: 1rem;
    }

    /* Stats en 2 colonnes possible */
    .stats-grid.two-col {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

@media (max-width: 425px) {
    .dashboard-grid,
    .stats-grid,
    .products-grid,
    .grid,
    [class*="-grid"] {
        gap: 0.75rem;
    }

    /* Forcer 1 colonne sur très petit mobile */
    .stats-grid.two-col {
        grid-template-columns: 1fr !important;
    }
}

/* Dashboard sections */
@media (max-width: 768px) {
    .dashboard-section {
        padding: 1.25rem;
        margin-bottom: 1rem;
    }
}

/* ============================================
   7. TABLES RESPONSIVE
   ============================================ */

@media (max-width: 768px) {
    .table-container,
    .table-responsive,
    [class*="table-container"] {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -1rem;
        padding: 0 1rem;
        max-width: 100vw;
    }

    table,
    .products-table,
    .orders-table,
    .clients-table,
    .factures-table {
        min-width: 600px;
        font-size: 0.875rem;
        width: 100%;
    }

    th, td {
        padding: 0.75rem 0.5rem !important;
        white-space: nowrap;
        font-size: 0.875rem !important;
    }

    th {
        font-weight: 600;
        background: #f8f9fa;
    }

    /* Boutons dans tables */
    table button,
    table .btn {
        min-height: 44px;
        padding: 0.5rem 0.75rem;
        font-size: 0.85rem;
    }
}

/* ============================================
   8. MODALS RESPONSIVE
   ============================================ */

@media (max-width: 768px) {
    .modal-overlay {
        padding: 0;
    }

    .modal-content,
    .modal {
        width: 95vw !important;
        max-width: 95vw !important;
        max-height: 90vh !important;
        margin: 5vh auto !important;
        padding: 1.25rem !important;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        border-radius: 12px;
        box-sizing: border-box;
    }

    .modal-header {
        margin-bottom: 1rem;
        padding-bottom: 0.75rem;
    }

    .modal-header h3 {
        font-size: 1.25rem;
    }

    .modal-body {
        max-height: 60vh;
        overflow-y: auto;
    }

    .modal-footer {
        margin-top: 1rem;
        padding-top: 0.75rem;
        border-top: 1px solid #e5e5e5;
    }

    .modal-footer button {
        width: 100%;
        margin: 0.25rem 0;
    }
}

@media (max-width: 425px) {
    .modal-content,
    .modal {
        width: 100vw !important;
        max-width: 100vw !important;
        height: 100vh !important;
        max-height: 100vh !important;
        margin: 0 !important;
        border-radius: 0 !important;
    }
}

/* ============================================
   9. CARDS RESPONSIVE
   ============================================ */

@media (max-width: 768px) {
    .card,
    .dashboard-section,
    .section,
    .order-card,
    .product-card,
    .action-card,
    [class*="-card"] {
        padding: 1.25rem 1rem;
        margin-bottom: 1rem;
        border-radius: 12px;
    }

    /* Card Headers */
    .card-header,
    .order-header,
    .section-header {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.75rem;
    }

    /* Card Footers */
    .card-footer,
    .order-footer {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }
}

@media (max-width: 425px) {
    .card,
    .dashboard-section,
    .section,
    [class*="-card"] {
        padding: 1rem 0.875rem;
    }
}

/* ============================================
   10. BACK LINKS & NAVIGATION
   ============================================ */

@media (max-width: 768px) {
    .back-link,
    .back-button,
    .btn-back,
    [class*="back-"] {
        position: static !important;
        display: block;
        margin-bottom: 1rem;
        text-align: center;
        padding: 0.75rem 1rem;
        min-height: 44px;
    }

    /* Back link en absolute dans header */
    .page-header .back-link,
    .welcome-section .back-link {
        position: static !important;
        margin-bottom: 1rem;
    }
}

/* ============================================
   11. IMAGES RESPONSIVE
   ============================================ */

@media (max-width: 768px) {
    img {
        max-width: 100%;
        height: auto;
        display: block;
    }

    .image-preview,
    .product-image,
    .boutique-logo,
    .boutique-header-photo {
        border-radius: 8px;
        object-fit: cover;
        max-width: 100%;
    }

    /* Grids d'images */
    .images-grid,
    .boutique-photos-grid,
    .image-preview-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }
}

/* ============================================
   12. FILTERS & SEARCH
   ============================================ */

@media (max-width: 768px) {
    .filters,
    .filters-section,
    .search-section {
        padding: 1rem;
        margin-bottom: 1rem;
    }

    .filters form,
    .filter-form {
        flex-direction: column;
        gap: 0.875rem;
    }

    .filter-group,
    .search-group {
        width: 100%;
        min-width: 100%;
    }

    .filter-buttons {
        flex-direction: column;
        gap: 0.5rem;
    }

    .filter-btn,
    .search-btn {
        width: 100%;
        text-align: center;
        min-height: 44px;
    }

    /* Actions Bar */
    .actions-bar {
        flex-direction: column;
        gap: 1rem;
    }

    .filters-group {
        flex-direction: column;
        width: 100%;
        gap: 0.75rem;
    }

    .search-box,
    .filter-box {
        width: 100%;
        max-width: 100%;
    }

    .search-box input,
    .filter-box select {
        width: 100%;
        font-size: 16px;
    }
}

/* ============================================
   13. PAGINATION
   ============================================ */

@media (max-width: 768px) {
    .pagination-container {
        flex-direction: column;
        gap: 1rem;
        padding: 1rem;
        text-align: center;
    }

    .pagination {
        flex-wrap: wrap;
        justify-content: center;
        gap: 0.35rem;
    }

    .pagination-btn,
    .pagination-number,
    .pagination a,
    .pagination span {
        padding: 0.5rem 0.65rem;
        font-size: 0.85rem;
        min-width: 44px;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
}

/* ============================================
   14. STATS & NUMBERS
   ============================================ */

@media (max-width: 768px) {
    .stat-card {
        padding: 0.875rem;
        text-align: left;
        display: flex;
        align-items: center;
        gap: 1rem;
    }

    .stat-icon {
        width: 40px;
        height: 40px;
        min-width: 40px;
        margin: 0;
    }

    .stat-value,
    .stat-number {
        font-size: clamp(1.5rem, 5vw, 2rem);
    }

    .stat-label {
        font-size: 0.875rem;
    }
}

@media (max-width: 425px) {
    .stat-value,
    .stat-number {
        font-size: 1.5rem;
    }
}

/* ============================================
   15. TABS RESPONSIVE
   ============================================ */

@media (max-width: 768px) {
    .tabs {
        flex-direction: column;
        gap: 0.5rem;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .tab {
        width: 100%;
        justify-content: center;
        padding: 0.875rem 1rem;
        min-height: 44px;
    }
}

/* ============================================
   16. ALERTS & MESSAGES
   ============================================ */

@media (max-width: 768px) {
    .alert,
    .message,
    .notification {
        padding: 1rem 0.875rem;
        font-size: 0.9rem;
        border-radius: 8px;
        margin-bottom: 1rem;
    }

    .alert i,
    .message i {
        font-size: 1.25rem;
    }
}

/* ============================================
   17. CHAT & MESSAGING
   ============================================ */

@media (max-width: 968px) {
    .chat-container {
        position: relative;
        height: 500px;
        max-height: 60vh;
    }

    .content-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .chat-container {
        height: 400px;
        max-height: 50vh;
    }

    .chat-textarea {
        min-height: 44px;
        font-size: 16px;
        padding: 0.75rem 1rem;
    }

    .chat-send-btn {
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
    }

    .message {
        max-width: 85%;
    }
}

/* ============================================
   18. UTILITIES MOBILE
   ============================================ */

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

    /* Show mobile only */
    .mobile-only,
    .show-mobile {
        display: block !important;
    }

    /* Full width on mobile */
    .mobile-full-width {
        width: 100% !important;
        max-width: 100% !important;
    }

    /* Stack vertical */
    .mobile-stack {
        flex-direction: column !important;
    }

    /* No margin on mobile */
    .mobile-no-margin {
        margin: 0 !important;
    }

    /* No padding on mobile */
    .mobile-no-padding {
        padding: 0 !important;
    }
}

/* ============================================
   19. ACCESSIBILITY & TOUCH
   ============================================ */

@media (max-width: 768px) {
    /* Focus visible pour keyboard navigation */
    *:focus-visible {
        outline: 2px solid #667eea;
        outline-offset: 2px;
        border-radius: 4px;
    }

    /* Touch feedback */
    button:active,
    .btn:active,
    a:active {
        transform: scale(0.98);
        opacity: 0.9;
        transition: all 0.1s ease;
    }

    /* Smooth scroll */
    html {
        scroll-behavior: smooth;
    }

    /* Espacement minimal entre éléments cliquables */
    button + button,
    .btn + .btn,
    a.btn + a.btn {
        margin-top: 0.5rem;
    }
}

/* ============================================
   20. ANIMATIONS PERFORMANTES (GPU)
   ============================================ */

@media (max-width: 768px) {
    /* N'animer que transform et opacity pour performance */
    .animated,
    [class*="animate-"] {
        transition-property: transform, opacity;
        transition-duration: 0.2s;
        transition-timing-function: ease-out;
    }

    /* Hardware acceleration */
    .animated,
    .modal,
    .sidebar {
        will-change: transform;
        transform: translateZ(0);
        -webkit-transform: translateZ(0);
    }
}

/* Désactiver animations si préférence réduite */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ============================================
   21. FORMULAIRES LONGS (Scroll indicators)
   ============================================ */

@media (max-width: 768px) {
    .section h2,
    .card h2,
    .dashboard-section h2 {
        position: sticky;
        top: 60px;
        background: white;
        z-index: 10;
        margin: -1.25rem -1rem 1rem;
        padding: 1rem 1rem 0.75rem;
        border-bottom: 2px solid #f0f0f0;
    }

    /* Form rows */
    .form-row {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .form-group {
        margin-bottom: 1.25rem;
    }
}

/* ============================================
   22. COLOR PICKERS & FILE UPLOADS
   ============================================ */

@media (max-width: 768px) {
    input[type="color"] {
        width: 100%;
        height: 48px;
        min-height: 48px;
        padding: 4px;
        border-radius: 8px;
        cursor: pointer;
    }

    input[type="file"] {
        font-size: 14px;
        padding: 0.75rem 0.5rem;
        width: 100%;
    }

    .file-upload-label {
        display: block;
        width: 100%;
        padding: 1rem;
        text-align: center;
        background: #f8f9fa;
        border: 2px dashed #dee2e6;
        border-radius: 8px;
        cursor: pointer;
        min-height: 48px;
    }
}

/* ============================================
   23. SIDEBAR MOBILE (Admin)
   ============================================ */

@media (max-width: 1024px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        z-index: 1000;
        position: fixed;
        width: 280px;
    }

    .sidebar.mobile-open {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0 !important;
        padding-top: 80px;
        width: 100%;
        max-width: 100%;
    }
}

/* ============================================
   24. PRINT STYLES
   ============================================ */

@media print {
    .header,
    .sidebar,
    .mobile-menu-toggle,
    .back-link,
    .nav,
    button,
    .btn,
    .action-btn {
        display: none !important;
    }

    body {
        font-size: 12pt;
        color: black;
    }

    .main-content,
    .container {
        margin: 0;
        padding: 0;
        max-width: 100%;
    }

    .page-header,
    .welcome-header {
        background: none !important;
        color: black !important;
        border-bottom: 2px solid black;
    }
}

/* ============================================
   25. FIXES SPÉCIFIQUES iOS
   ============================================ */

/* Fix bounce scroll iOS */
@media (max-width: 768px) {
    body {
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-y: contain;
    }

    /* Fix inputs dans iOS Safari */
    input,
    textarea,
    select {
        -webkit-appearance: none;
        border-radius: 8px;
    }

    /* Fix position fixed dans iOS */
    .modal-overlay,
    .sidebar {
        position: fixed;
        -webkit-overflow-scrolling: touch;
    }
}

/* ============================================
   26. CORRECTIONS SPÉCIFIQUES PAR PAGE
   ============================================ */

/* Dashboard Vendeur - Stats Grid */
@media (max-width: 768px) {
    .products-stats {
        flex-direction: column;
        padding: 1rem;
        gap: 1rem;
        align-items: stretch;
    }
}

/* Mes Produits - Actions */
@media (max-width: 768px) {
    .btn-action {
        min-width: 44px;
        min-height: 44px;
        padding: 0.65rem;
        font-size: 0.9rem;
    }

    .actions-group {
        gap: 0.35rem;
        flex-wrap: wrap;
    }
}

/* Order Details - Items */
@media (max-width: 768px) {
    .item {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .item-price {
        align-self: flex-end;
    }
}

/* Shipping Categories */
@media (max-width: 768px) {
    .shipping-categories-grid {
        grid-template-columns: 1fr;
        gap: 0.875rem;
    }

    .shipping-card {
        padding: 1rem;
    }

    .zones-grid {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }

    .price-input-group {
        flex-direction: column;
        gap: 0.5rem;
    }
}

/* Plans & Subscriptions */
@media (max-width: 768px) {
    .plans-grid {
        grid-template-columns: 1fr;
        gap: 1.25rem;
    }

    .plan-card {
        padding: 1.5rem;
    }

    .plan-cta {
        width: 100%;
        padding: 1rem;
        font-size: 1rem;
        min-height: 48px;
    }
}

/* Bulk Actions */
@media (max-width: 768px) {
    .bulk-actions {
        flex-direction: column;
        align-items: stretch;
        padding: 0.875rem;
    }

    .bulk-selection-info {
        margin-bottom: 0.75rem;
    }

    .btn-bulk-delete,
    .btn-bulk-shipping {
        width: 100%;
        justify-content: center;
    }
}

/* ============================================
   FIN DU FICHIER
   ============================================ */
