/**
 * Styles Mobile Responsive - Application Native Look
 * Design Mobile-First avec navigation hybride
 * 
 * @package UMOA
 * @version 1.0
 */

/* ============================================================================
   VARIABLES MOBILE
   ============================================================================ */

:root {
    /* Hauteurs de navigation mobile */
    --mobile-top-height: 60px; /* Hauteur du header mobile fixe */
    --mobile-bottom-height: 64px;
    --mobile-safe-area-top: env(safe-area-inset-top, 0px);
    --mobile-safe-area-bottom: env(safe-area-inset-bottom, 0px);
    
    /* Border radius mobile (plus prononcés) */
    --radius-mobile-sm: 12px;
    --radius-mobile-md: 16px;
    --radius-mobile-lg: 20px;
    --radius-mobile-xl: 24px;
    
    /* Transitions fluides 60fps */
    --transition-mobile: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1),
                          opacity 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ============================================================================
   BASE MOBILE - Prévenir zoom auto sur inputs
   ============================================================================ */

@media (max-width: 768px) {
    /* Prévenir le zoom automatique sur les inputs iOS */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="tel"],
    input[type="search"],
    input[type="url"],
    textarea,
    select {
        font-size: 16px !important; /* iOS ne zoom pas si font-size >= 16px */
    }
    
    /* Améliorer le touch target (minimum 44x44px pour accessibilité) */
    button,
    a,
    input[type="button"],
    input[type="submit"],
    .btn {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Supprimer les effets hover sur mobile (éviter les bugs tactiles) */
    *:hover {
        /* Désactiver les transformations hover sur mobile */
    }
    
    /* Utiliser :active à la place de :hover pour le feedback tactile */
    button:active,
    a:active,
    .btn:active,
    .card:active,
    .nav-link:active {
        transform: scale(0.95);
        opacity: 0.85;
        transition: var(--transition-mobile);
    }
    
    /* Feedback tactile avec ripple effect */
    button,
    .btn,
    .card.clickable,
    .nav-link {
        position: relative;
        overflow: hidden;
    }
    
    /* Ripple effect au touch */
    button::after,
    .btn::after,
    .card.clickable::after {
        content: '';
        position: absolute;
        top: 50%;
        left: 50%;
        width: 0;
        height: 0;
        border-radius: 50%;
        background: rgba(255, 255, 255, 0.5);
        transform: translate(-50%, -50%);
        transition: width 0.3s, height 0.3s;
        pointer-events: none;
    }
    
    button:active::after,
    .btn:active::after,
    .card.clickable:active::after {
        width: 300px;
        height: 300px;
        transition: width 0.3s, height 0.3s;
    }
    
    /* Vibration légère sur certains éléments (si supporté) */
    button:active,
    .btn:active {
        -webkit-tap-highlight-color: rgba(74, 144, 226, 0.3);
    }
    
    /* Feedback visuel pour les inputs */
    input:focus,
    textarea:focus,
    select:focus {
        transform: scale(1.01);
        transition: transform 0.2s ease;
    }
    
    input:active,
    textarea:active,
    select:active {
        transform: scale(0.99);
    }
}

/* ============================================================================
   NAVIGATION DESKTOP - Masquer sur mobile
   ============================================================================ */

@media (max-width: 768px) {
    .navbar-desktop {
        display: none !important;
    }
}

@media (min-width: 769px) {
    .navbar-mobile-top,
    .navbar-mobile-bottom,
    .mobile-menu-overlay {
        display: none !important;
    }
}

/* ============================================================================
   NAVIGATION MOBILE - TOP BAR (Header Fixe Professionnel)
   ============================================================================ */

.navbar-mobile-top {
    width: 100%;
    max-width: 100vw;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    background: #ffffff;
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    overflow-x: hidden;
    /* Support Safe Area pour éviter la caméra frontale (notch) */
    padding-top: env(safe-area-inset-top, 0px);
    min-height: calc(60px + env(safe-area-inset-top, 0px));
    height: auto; /* Hauteur automatique pour s'adapter à la Safe Area */
}

@media (max-width: 768px) {
    .navbar-mobile-top {
        display: flex; /* Garder flex pour maintenir la structure du header */
    }

    .header-search-mobile {
        display: flex;
        margin: 0 12px 10px;
        max-width: none;
        border: 1px solid #e6e6e6;
        background: #f7f7f8;
    }
}

.mobile-top-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 60px; /* Hauteur fixe du contenu (sans la safe area) */
    padding: 0 15px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box; /* Inclure le padding dans la largeur */
    margin: 0;
}

/* Bouton Hamburger */
.mobile-menu-toggle {
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 40px;
    height: 40px;
    min-width: 40px;
    max-width: 40px;
    z-index: 1001;
    transition: var(--transition-mobile);
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1); /* Feedback visuel sur mobile */
    touch-action: manipulation; /* Optimiser les interactions tactiles */
    user-select: none; /* Empêcher la sélection de texte */
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    flex-shrink: 0;
    box-sizing: border-box;
    /* Limiter la zone de touch à la taille du bouton */
    position: relative;
    overflow: visible;
    margin: 0;
    /* S'assurer que le bouton ne déborde pas */
    contain: layout style;
}

.mobile-menu-toggle span {
    width: 24px;
    height: 2px;
    background-color: #1F2937; /* Couleur sombre pour le fond blanc */
    border-radius: 2px;
    transition: var(--transition-mobile);
    transform-origin: center;
    pointer-events: none; /* Empêcher les spans d'intercepter les clics */
    -webkit-tap-highlight-color: transparent; /* Supprimer le highlight sur mobile */
    /* Espacement entre les lignes du hamburger */
    margin: 3px 0;
    display: block;
    flex-shrink: 0;
}

.mobile-menu-toggle.active span:nth-child(1) {
    transform: rotate(45deg) translate(6px, 6px);
}

.mobile-menu-toggle.active span:nth-child(2) {
    opacity: 0;
}

.mobile-menu-toggle.active span:nth-child(3) {
    transform: rotate(-45deg) translate(6px, -6px);
}

.mobile-menu-toggle:active {
    transform: scale(0.95);
}

/* Logo mobile */
.mobile-logo {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    min-width: 0; /* Permet au logo de se réduire si nécessaire */
    padding: 0 10px;
}

.mobile-logo-img {
    height: 40px;
    width: 40px;
    max-width: 40px;
    object-fit: contain;
}

/* Actions top (chat, panier, notifications) */
.mobile-top-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.mobile-icon-link {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    min-width: 40px;
    color: #1F2937; /* Couleur sombre pour le fond blanc */
    text-decoration: none;
    border-radius: var(--radius-mobile-sm);
    transition: var(--transition-mobile);
    flex-shrink: 0;
    box-sizing: border-box;
}

.mobile-icon-link:active {
    background-color: rgba(255, 255, 255, 0.1);
    transform: scale(0.95);
}

.mobile-icon-link svg {
    width: 22px;
    height: 22px;
}

.mobile-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    background: #FF6B35;
    color: white;
    border-radius: 10px;
    min-width: 18px;
    height: 18px;
    font-size: 10px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    border: 2px solid #ffffff; /* Bordure blanche pour fond blanc */
}

/* ============================================================================
   MENU HAMBURGER OVERLAY
   ============================================================================ */

.mobile-menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                visibility 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(4px);
}

.mobile-menu-overlay.active {
    opacity: 1;
    visibility: visible;
}

.mobile-menu-content {
    position: fixed;
    top: 0;
    left: 0;
    width: 85%;
    max-width: 320px;
    height: 100%;
    background-color: #FFFFFF;
    box-shadow: 2px 0 16px rgba(0, 0, 0, 0.2);
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.mobile-menu-overlay.active .mobile-menu-content {
    transform: translateX(0);
}

.mobile-menu-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    background: var(--gradient-primary);
    color: white;
}

.mobile-menu-header h3 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
}

.mobile-menu-close {
    background: none;
    border: none;
    color: white;
    padding: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-mobile-sm);
    transition: var(--transition-mobile);
}

.mobile-menu-close:active {
    background-color: rgba(255, 255, 255, 0.1);
    transform: scale(0.95);
}

.mobile-menu-nav {
    padding: 16px 0;
}

.mobile-menu-link {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 20px;
    color: var(--text-color);
    text-decoration: none;
    font-weight: 500;
    font-size: 1rem;
    transition: var(--transition-mobile);
    border-left: 3px solid transparent;
}

.mobile-menu-link:active {
    background-color: var(--gray-100);
    border-left-color: var(--blue-medium);
    transform: translateX(4px);
}

.mobile-menu-link svg {
    width: 20px;
    height: 20px;
    color: var(--blue-medium);
    flex-shrink: 0;
}

.mobile-menu-link span:not(.mobile-favorites-count):not(.mobile-notifications-count):not(.mobile-chat-count):not(.nav-badge):not(.chat-badge):not(.cart-badge):not(.notification-badge):not(.favorites-badge) {
    flex: 1;
}

.mobile-menu-link-primary {
    background: var(--gradient-primary);
    color: white;
    margin: 8px 20px;
    border-radius: var(--radius-mobile-md);
    border-left: none;
}

.mobile-menu-link-primary svg {
    color: white;
}

.mobile-menu-link-primary:active {
    background: var(--gradient-secondary);
    transform: scale(0.98);
}

.mobile-menu-link-danger {
    color: var(--danger-color);
}

.mobile-menu-link-danger svg {
    color: var(--danger-color);
}

.mobile-menu-link-danger:active {
    background-color: rgba(239, 68, 68, 0.1);
}

/* ============================================================================
   NAVIGATION MOBILE - BOTTOM BAR
   ============================================================================ */

.navbar-mobile-bottom {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--mobile-bottom-height) + var(--mobile-safe-area-bottom));
    background-color: #FFFFFF;
    border-top: 1px solid var(--border-color);
    z-index: 999;
    display: none;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.05);
    padding-bottom: var(--mobile-safe-area-bottom);
}

@media (max-width: 768px) {
    .navbar-mobile-bottom {
        display: flex;
        justify-content: space-around;
        align-items: flex-start;
    }
}

.mobile-bottom-link {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px 4px;
    color: var(--gray-600);
    text-decoration: none;
    font-size: 0.75rem;
    font-weight: 500;
    transition: var(--transition-mobile);
    position: relative;
    min-height: 56px;
    gap: 4px;
}

/* Wrapper pour les icônes avec badges */
.mobile-bottom-link .icon-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mobile-bottom-link:active {
    color: var(--blue-medium);
    transform: scale(0.95);
}

.mobile-bottom-link.active {
    color: var(--blue-medium);
}

.mobile-bottom-link svg {
    width: 24px;
    height: 24px;
    stroke-width: 2;
}

.mobile-bottom-link span:not(.mobile-bottom-badge) {
    font-size: 0.6875rem;
    line-height: 1.2;
}

.mobile-bottom-badge {
    position: absolute;
    top: 4px;
    right: calc(50% - 20px);
    background: #FF6B35;
    color: white;
    border-radius: 10px;
    min-width: 18px;
    height: 18px;
    font-size: 10px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    border: 2px solid #FFFFFF;
}

/* Badges dynamiques pour la bottom nav - Style iOS/Android standard */
.nav-badge {
    position: absolute;
    top: -5px;
    right: -8px;
    background-color: #ff3b30; /* Rouge iOS/Android standard */
    color: white;
    font-size: 10px;
    font-weight: bold;
    min-width: 16px;
    height: 16px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2px;
    border: 2px solid white; /* Pour qu'elle ressorte sur l'icône */
    z-index: 10;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* Animation "pop" quand le badge change */
.badge-bump {
    animation: pulse-badge 0.3s ease-out;
}

@keyframes pulse-badge {
    0% { transform: scale(1); }
    50% { transform: scale(1.4); }
    100% { transform: scale(1); }
}

/* ============================================================================
   CONTENU PRINCIPAL - Ajustements pour mobile
   ============================================================================ */

@media (max-width: 768px) {
    body {
        padding-top: 0; /* Pas de padding-top car header est sticky */
        padding-bottom: calc(var(--mobile-bottom-height) + var(--mobile-safe-area-bottom));
    }
    
    .main-content {
        padding: 16px 12px;
        padding-top: calc(60px + 16px); /* Hauteur du header sticky (60px) + padding */
        min-height: calc(100vh - 60px - var(--mobile-bottom-height));
        width: 100%;
        max-width: 100vw;
        box-sizing: border-box;
        overflow-x: hidden;
    }
    
    .container {
        padding: 0 12px;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }
    
    /* Grilles responsive - Stack vertical sur mobile */
    .grid,
    .grid-2,
    .grid-3,
    .grid-4 {
        grid-template-columns: 1fr !important;
        gap: 16px;
    }
    
    /* Flexbox containers - Stack vertical */
    .flex-row {
        flex-direction: column !important;
    }
    
    .flex-container {
        flex-wrap: wrap;
    }
    
    /* Formulaires - Full width sur mobile */
    form {
        width: 100%;
    }
    
    .form-row {
        flex-direction: column;
    }
    
    .form-row .form-group {
        width: 100%;
        margin-right: 0;
        margin-bottom: 16px;
    }
    
    /* Cartes avec border-radius plus prononcés */
    .card {
        border-radius: var(--radius-mobile-lg);
        margin-bottom: 16px;
    }
    
    .card:hover {
        transform: none; /* Pas de hover sur mobile */
    }
    
    .card:active {
        transform: scale(0.98);
        transition: var(--transition-mobile);
    }
    
    /* Boutons avec border-radius plus prononcés */
    .btn {
        border-radius: var(--radius-mobile-md);
        padding: 14px 24px;
        font-size: 1rem;
    }
    
    .btn:active {
        transform: scale(0.97);
    }
    
    /* Formulaires */
    .form-control {
        border-radius: var(--radius-mobile-md);
        padding: 14px 16px;
        font-size: 16px; /* Prévenir zoom iOS */
    }
    
    /* Barre de progression pour longs formulaires */
    .form-progress {
        height: 4px;
        background: var(--gray-200);
        border-radius: var(--radius-full);
        margin-bottom: 1.5rem;
        overflow: hidden;
    }
    
    .form-progress-bar {
        height: 100%;
        background: var(--gradient-primary);
        border-radius: var(--radius-full);
        transition: width 0.3s ease;
        width: 0%;
    }
    
    .long-form {
        position: relative;
    }
    
    /* Tables responsive - Converties en Cards */
    table.table-converted {
        display: none !important;
    }
    
    .table-cards-container {
        display: flex;
        flex-direction: column;
        gap: 16px;
    }
    
    .table-card {
        background: white;
        border: 1px solid var(--border-color);
        border-radius: var(--radius-mobile-lg);
        padding: 16px;
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
        transition: var(--transition-mobile);
    }
    
    .table-card:active {
        transform: scale(0.98);
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    }
    
    .table-card-item {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        padding: 12px 0;
        border-bottom: 1px solid var(--border-color);
    }
    
    .table-card-item:last-child {
        border-bottom: none;
        padding-bottom: 0;
    }
    
    .table-card-item:first-child {
        padding-top: 0;
    }
    
    .table-card-label {
        font-weight: 600;
        color: var(--text-muted);
        font-size: 0.875rem;
        flex: 0 0 40%;
        margin-right: 12px;
    }
    
    .table-card-value {
        flex: 1;
        text-align: right;
        color: var(--text-color);
        font-size: 0.9375rem;
        word-break: break-word;
    }
    
    /* Tables classiques (fallback si pas de conversion JS) */
    table:not(.table-converted) {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        width: 100%;
    }
    
    table:not(.table-converted) thead {
        display: none;
    }
    
    table:not(.table-converted) tbody {
        display: block;
    }
    
    table:not(.table-converted) tr {
        display: block;
        margin-bottom: 16px;
        border: 1px solid var(--border-color);
        border-radius: var(--radius-mobile-md);
        padding: 12px;
        background: white;
    }
    
    table:not(.table-converted) td {
        display: block;
        text-align: right;
        padding: 8px 0;
        border: none;
    }
    
    table:not(.table-converted) td::before {
        content: attr(data-label);
        float: left;
        font-weight: 600;
        color: var(--text-muted);
    }
    
    /* Listes - Full width */
    ul, ol {
        padding-left: 20px;
    }
    
    /* Images responsive */
    img {
        max-width: 100%;
        height: auto;
        border-radius: var(--radius-mobile-md);
    }
    
    /* Modals - Full screen sur mobile */
    .modal-content {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        border-radius: var(--radius-mobile-lg) var(--radius-mobile-lg) 0 0 !important;
        max-height: 90vh;
    }
    
    /* Input groups - Stack vertical */
    .input-group {
        flex-direction: column;
    }
    
    .input-group .form-control {
        border-radius: var(--radius-mobile-md);
        margin-bottom: 8px;
    }
    
    .input-group .btn {
        border-radius: var(--radius-mobile-md);
        width: 100%;
    }
}

/* ============================================================================
   TRANSITIONS FLUIDES ENTRE PAGES
   ============================================================================ */

@media (max-width: 768px) {
    /* Transition de page */
    body {
        transition: opacity 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    }
    
    body.page-transitioning {
        opacity: 0.7;
    }
    
    /* Animation d'apparition du contenu */
    .main-content > * {
        animation: fadeInUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }
    
    @keyframes fadeInUp {
        from {
            opacity: 0;
            transform: translateY(20px);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }
}

/* ============================================================================
   UTILITAIRES MOBILE
   ============================================================================ */

@media (max-width: 768px) {
    /* Masquer certains éléments sur mobile */
    .desktop-only {
        display: none !important;
    }
    
    /* Afficher uniquement sur mobile */
    .mobile-only {
        display: block !important;
    }
    
    /* Espacement mobile */
    .mobile-spacing-sm {
        margin-bottom: 12px;
    }
    
    .mobile-spacing-md {
        margin-bottom: 16px;
    }
    
    .mobile-spacing-lg {
        margin-bottom: 24px;
    }
}

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

/* ============================================================================
   PULL-TO-REFRESH
   ============================================================================ */

.pull-to-refresh-indicator {
    position: fixed;
    top: -60px;
    left: 50%;
    transform: translateX(-50%) translateY(-60px);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    opacity: 0;
    transition: opacity 0.2s ease, transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
}

.pull-to-refresh-icon {
    width: 32px;
    height: 32px;
    color: var(--blue-medium);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease;
}

.pull-to-refresh-text {
    font-size: 0.875rem;
    color: var(--text-muted);
    font-weight: 500;
}

.pull-to-refresh-indicator.ready .pull-to-refresh-text {
    color: var(--blue-medium);
}

.pull-to-refresh-indicator.refreshing .pull-to-refresh-icon {
    animation: spin 1s linear infinite;
}

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

/* ============================================================================
   OPTIMISATIONS PERFORMANCE 60FPS
   ============================================================================ */

@media (max-width: 768px) {
    /* Utiliser transform et opacity pour les animations (GPU accelerated) */
    .mobile-menu-content,
    .mobile-menu-overlay,
    .mobile-bottom-link,
    .mobile-menu-link {
        will-change: transform, opacity;
    }
    
    /* Forcer l'accélération GPU */
    .mobile-menu-content {
        transform: translateZ(0);
        -webkit-transform: translateZ(0);
    }
    
    /* Optimiser les transitions */
    * {
        -webkit-tap-highlight-color: transparent;
    }
}

