/* ===================================
   ADMIN PANEL — OPTIMISATION MOBILE
   Fichier dédié responsive mobile
   =================================== */

/* ===================================
   VARIABLES & BASE
   =================================== */
:root {
    --touch-target: 48px; /* Taille minimale zone tactile */
    --mobile-padding: 0.875rem;
    --header-height-mobile: 56px;
    --bottom-nav-height: 64px;
}

/* ===================================
   HEADER MOBILE
   =================================== */
@media (max-width: 768px) {
    .admin-header {
        height: var(--header-height-mobile);
        padding: 0 0.75rem;
        gap: 0.5rem;
    }

    .admin-layout {
        margin-top: var(--header-height-mobile);
        min-height: calc(100vh - var(--header-height-mobile));
    }

    .admin-sidebar {
        top: var(--header-height-mobile);
    }

    /* Logo + nom compacts */
    .admin-branding {
        gap: 0.5rem;
    }

    .admin-branding img {
        height: 26px !important;
    }

    .admin-branding strong {
        font-size: 0.95rem;
        line-height: 1.1;
    }

    .admin-branding span {
        display: none !important; /* Cache "Panel Admin" sur mobile */
    }

    /* Bouton toggle sidebar — plus grand pour le touch */
    .sidebar-toggle {
        min-width: var(--touch-target);
        min-height: var(--touch-target);
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.3rem;
        padding: 0;
        border-radius: 8px;
    }

    /* Header right — boutons icônes only */
    .admin-header-right {
        gap: 0.4rem;
    }

    #viewSiteBtn {
        display: none; /* Caché sur mobile, accessible via menu */
    }

    .header-btn {
        min-width: var(--touch-target);
        min-height: var(--touch-target);
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 10px;
    }

    .header-btn span {
        display: none;
    }

    /* Badge notification */
    .notification-badge {
        width: 18px;
        height: 18px;
        font-size: 0.65rem;
        top: 4px;
        right: 4px;
    }

    /* Dropdown notifications — plein écran sur mobile */
    .notifications-dropdown {
        position: fixed !important;
        top: var(--header-height-mobile) !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        min-width: unset !important;
        max-height: 70vh;
        border-radius: 0 0 16px 16px;
        overflow-y: auto;
    }

    /* Dropdown user menu — plein écran */
    .admin-user-menu.active .user-menu-dropdown {
        position: fixed !important;
        top: var(--header-height-mobile) !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        min-width: unset !important;
        border-radius: 0 0 16px 16px;
        box-shadow: 0 8px 30px rgba(0,0,0,0.15) !important;
    }

    .user-menu-item {
        padding: 1rem 1.5rem;
        font-size: 1rem;
        min-height: var(--touch-target);
    }

    .user-menu-item i {
        width: 24px;
        font-size: 1.1rem;
    }
}

/* ===================================
   SIDEBAR MOBILE — MENU BLANC PLEIN ÉCRAN
   =================================== */
@media (max-width: 1024px) {

    /* Supprime le pseudo-element gris */
    .admin-sidebar::before {
        display: none !important;
        content: none !important;
        background: none !important;
    }

    .admin-sidebar.active::before {
        display: none !important;
    }

    /* Menu blanc plein écran qui glisse depuis la droite */
    .admin-sidebar {
        position: fixed !important;
        top: 56px !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100% !important;
        height: calc(100vh - 56px) !important;
        background: #ffffff !important;
        border-right: none !important;
        box-shadow: none !important;
        z-index: 999 !important;
        overflow-y: auto !important;
        transform: translateX(100%) !important;
        transition: transform 0.3s ease !important;
    }

    .admin-sidebar.active {
        transform: translateX(0) !important;
    }

    .admin-header {
        z-index: 1000 !important;
    }

    /* Nav items larges et espacés */
    .admin-nav {
        padding: 1.5rem 1rem;
    }

    .admin-nav-item {
        min-height: 52px;
        padding: 0.875rem 1.25rem;
        font-size: 1rem;
        font-weight: 500;
        margin-bottom: 0.25rem;
        border-radius: 10px;
        display: flex;
        align-items: center;
        gap: 1rem;
    }

    .admin-nav-item i {
        font-size: 1.2rem;
        width: 26px;
        text-align: center;
    }

    .sidebar-footer {
        background: #ffffff !important;
        border-top: 1px solid #e5e7eb;
    }

    /* Aucun overlay, aucun fond gris */
    .sidebar-overlay {
        display: none !important;
    }
}

/* ===================================
   BOTTOM NAVIGATION BAR (mobile only)
   =================================== */
@media (max-width: 768px) {
    /* Barre de navigation fixe en bas */
    .admin-bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: var(--bottom-nav-height);
        background: white;
        border-top: 1px solid #e5e7eb;
        box-shadow: 0 -4px 20px rgba(0,0,0,0.08);
        z-index: 997;
        align-items: stretch;
    }

    .bottom-nav-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        background: none;
        border: none;
        cursor: pointer;
        color: #9ca3af;
        font-size: 0.65rem;
        font-weight: 500;
        font-family: 'Montserrat', sans-serif;
        padding: 0.4rem 0.2rem;
        transition: color 0.2s, background 0.2s;
        border-radius: 0;
        text-decoration: none;
        -webkit-tap-highlight-color: transparent;
    }

    .bottom-nav-item i {
        font-size: 1.25rem;
        transition: transform 0.2s;
    }

    .bottom-nav-item.active {
        color: #5B1013;
    }

    .bottom-nav-item.active i {
        transform: scale(1.1);
    }

    .bottom-nav-item:active {
        background: #f9fafb;
    }

    /* Espace pour que le contenu ne soit pas caché derrière la bottom nav */
    .admin-main {
        padding-bottom: calc(var(--bottom-nav-height) + 1rem) !important;
    }
}

/* ===================================
   CONTENU PRINCIPAL MOBILE
   =================================== */
@media (max-width: 768px) {
    .admin-main {
        padding: var(--mobile-padding);
        margin-left: 0 !important;
    }

    /* Section header */
    .section-header {
        flex-direction: column;
        gap: 0.75rem;
        margin-bottom: 1.25rem;
    }

    .section-header h1 {
        font-size: 1.4rem;
        margin-bottom: 0.2rem;
    }

    .section-header p {
        font-size: 0.85rem;
    }

    .section-actions {
        flex-wrap: wrap;
        gap: 0.5rem;
        width: 100%;
    }

    .section-actions .btn,
    .section-actions button {
        flex: 1;
        min-width: 140px;
        justify-content: center;
        min-height: var(--touch-target);
    }
}

/* ===================================
   STATS CARDS — GRILLE 2 COLONNES
   =================================== */
@media (max-width: 768px) {
    .stats-grid-admin {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
        margin-bottom: 1.25rem;
    }

    .stat-card-admin {
        padding: 1rem 0.875rem;
    }

    .stat-card-header {
        margin-bottom: 0.5rem;
    }

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

    .stat-icon {
        width: 32px;
        height: 32px;
        font-size: 0.85rem;
        border-radius: 6px;
    }

    .stat-value {
        font-size: 1.6rem;
        margin-bottom: 0.3rem;
    }

    .stat-trend {
        font-size: 0.78rem;
    }
}

@media (max-width: 380px) {
    .stats-grid-admin {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }

    .stat-value {
        font-size: 1.35rem;
    }

    .stat-card-admin {
        padding: 0.75rem;
    }
}

/* ===================================
   ACTIONS RAPIDES — 2 PAR LIGNE
   =================================== */
@media (max-width: 768px) {
    .quick-actions {
        padding: 1rem;
        margin-bottom: 1.25rem;
    }

    .quick-actions-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }

    .quick-action-btn {
        padding: 1rem 0.75rem;
        gap: 0.5rem;
        border-radius: 10px;
        min-height: 90px;
    }

    .quick-action-btn i {
        font-size: 1.6rem;
    }

    .quick-action-btn span {
        font-size: 0.8rem;
        text-align: center;
        line-height: 1.2;
    }
}

/* ===================================
   DASHBOARD GRID — 1 COLONNE
   =================================== */
@media (max-width: 768px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .dashboard-card {
        padding: 1rem;
    }

    .card-header h3 {
        font-size: 1rem;
    }

    .recent-order-item {
        flex-direction: column;
        gap: 0.5rem;
        align-items: flex-start;
    }
}

/* ===================================
   TABLEAU COMMANDES — CARDS MOBILE
   =================================== */
@media (max-width: 768px) {
    .order-filters {
        gap: 0.5rem;
        margin-bottom: 1rem;
        overflow-x: auto;
        padding-bottom: 0.4rem;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap;
        scrollbar-width: none;
    }

    .order-filters::-webkit-scrollbar {
        display: none;
    }

    .filter-chip {
        white-space: nowrap;
        flex-shrink: 0;
        min-height: 36px;
        display: flex;
        align-items: center;
        padding: 0 0.875rem !important;
        font-size: 0.82rem !important;
        border-radius: 20px;
    }

    .chip-count {
        display: none;
    }
}

@media (max-width: 640px) {
    /* Convertir table en cards */
    .data-table-container {
        overflow-x: visible !important;
        background: transparent !important;
        box-shadow: none !important;
        border-radius: 0 !important;
    }

    .data-table {
        border-collapse: separate;
        border-spacing: 0 0.75rem;
        width: 100% !important;
    }

    .data-table thead {
        display: none !important;
    }

    .data-table tbody {
        display: block;
    }

    .data-table tbody tr {
        display: grid;
        grid-template-columns: 1fr;
        background: white;
        border: 1px solid #e5e7eb;
        border-radius: 12px;
        padding: 1rem;
        margin-bottom: 0.875rem;
        box-shadow: 0 2px 8px rgba(0,0,0,0.06);
        gap: 0;
    }

    .data-table tbody tr:hover {
        background: white !important;
        box-shadow: 0 4px 16px rgba(0,0,0,0.1);
    }

    .data-table td {
        display: flex;
        flex-direction: column;
        padding: 0.6rem 0 !important;
        border-top: none !important;
        border-bottom: 1px solid #f3f4f6;
        color: #374151;
        font-size: 0.9rem;
    }

    .data-table td:last-child {
        border-bottom: none;
        padding-top: 0.75rem !important;
    }

    .data-table td::before {
        font-weight: 600;
        color: #9ca3af;
        font-size: 0.72rem;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        margin-bottom: 0.25rem;
    }

    .data-table td:nth-child(1)::before { content: "Commande"; }
    .data-table td:nth-child(2)::before { content: "Date"; }
    .data-table td:nth-child(3)::before { content: "Client"; }
    .data-table td:nth-child(4)::before { content: "Produits"; }
    .data-table td:nth-child(5)::before { content: "Total"; }
    .data-table td:nth-child(6)::before { content: "Statut"; }
    .data-table td:nth-child(7)::before { content: "Actions"; }

    /* Numéro de commande en couleur primaire */
    .data-table td:nth-child(1) {
        color: #5B1013;
        font-weight: 700;
        font-size: 0.95rem;
    }

    /* Total en gras */
    .data-table td:nth-child(5) {
        font-weight: 700;
        font-size: 1rem;
        color: #1f2937;
    }

    /* Boutons d'actions en ligne */
    .table-actions {
        display: flex;
        gap: 0.5rem;
        flex-wrap: wrap;
    }

    .table-actions .action-btn {
        flex: 1;
        min-width: 80px;
        min-height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 0.4rem;
        padding: 0.5rem 0.75rem !important;
        font-size: 0.8rem;
        background: #f9fafb !important;
        color: #5B1013 !important;
        border: 1px solid #e5e7eb !important;
        border-radius: 8px;
        font-weight: 500;
    }

    .table-actions .action-btn:hover,
    .table-actions .action-btn:active {
        background: #5B1013 !important;
        color: white !important;
        border-color: #5B1013 !important;
    }
}

/* ===================================
   SECTION HEADER COMMANDES
   =================================== */
@media (max-width: 640px) {
    #ordersSection .section-actions {
        flex-direction: column;
        gap: 0.5rem;
    }

    .search-box {
        width: 100%;
    }

    .search-box input {
        width: 100%;
        min-height: var(--touch-target);
        font-size: 1rem; /* Évite le zoom iOS */
    }

    #ordersSection .section-actions button {
        width: 100%;
        min-height: var(--touch-target);
        justify-content: center;
    }
}

/* ===================================
   PRODUITS & COLLECTIONS MOBILE
   =================================== */
@media (max-width: 768px) {
    .admin-products-grid {
        grid-template-columns: 1fr !important;
        gap: 0.75rem;
    }

    .admin-product-card {
        border-radius: 10px;
    }

    .admin-product-image {
        height: 150px;
    }

    .admin-product-info {
        padding: 0.875rem;
    }

    .admin-product-name {
        font-size: 0.85rem;
    }

    .admin-product-price {
        font-size: 1rem;
    }

    .admin-product-actions {
        flex-direction: column;
        gap: 0.4rem;
    }

    .admin-product-actions .btn {
        width: 100%;
        min-height: 38px;
        font-size: 0.8rem;
        justify-content: center;
    }
}

@media (max-width: 400px) {
    .admin-products-grid {
        grid-template-columns: 1fr !important;
    }
}

/* ===================================
   CATALOG MANAGER MOBILE
   =================================== */
@media (max-width: 768px) {
    .catalog-manager-container {
        grid-template-columns: 1fr !important;
        height: auto !important;
        max-height: none !important;
    }

    .catalog-tree-panel {
        max-height: 260px;
        border-right: none;
        border-bottom: 1px solid #e5e7eb;
    }

    .catalog-editor-panel {
        padding: 1rem;
    }

    .tree-item-header {
        min-height: 44px;
        padding: 10px 12px;
    }
}

/* ===================================
   FORMULAIRES MOBILE
   =================================== */
@media (max-width: 768px) {
    /* Tous les inputs, selects, textareas lisibles sans zoom */
    input[type="text"],
    input[type="email"],
    input[type="number"],
    input[type="password"],
    input[type="search"],
    select,
    textarea {
        font-size: 16px !important; /* Empêche le zoom auto sur iOS */
        min-height: var(--touch-target);
        border-radius: 8px;
    }

    textarea {
        min-height: 80px;
    }

    /* Boutons principaux */
    .btn,
    button[type="submit"] {
        min-height: var(--touch-target);
        font-size: 0.9rem;
        border-radius: 10px;
        padding: 0 1.25rem;
    }

    /* Option group cards dans l'éditeur produit */
    .option-group-card {
        padding: 1rem;
    }

    .option-header {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
}

/* ===================================
   MODALES MOBILE
   =================================== */
@media (max-width: 768px) {
    /* Les modales prennent tout l'écran en bas (bottom sheet) */
    .modal,
    [class*="modal"],
    [id*="Modal"] {
        align-items: flex-end !important;
    }

    .modal-content,
    [class*="modal-content"],
    [class*="modal-container"] {
        width: 100% !important;
        max-width: 100% !important;
        border-radius: 20px 20px 0 0 !important;
        max-height: 92vh !important;
        overflow-y: auto !important;
        margin: 0 !important;
        padding: 1.5rem 1rem !important;
        animation: slideUp 0.3s ease !important;
    }

    @keyframes slideUp {
        from { transform: translateY(100%); opacity: 0; }
        to { transform: translateY(0); opacity: 1; }
    }
}

/* ===================================
   NOTIFICATIONS TOAST MOBILE
   =================================== */
@media (max-width: 768px) {
    /* Notifications en bas sur mobile */
    div[style*="position: fixed"][style*="top: 20px"][style*="right: 20px"] {
        top: auto !important;
        bottom: calc(var(--bottom-nav-height) + 1rem) !important;
        left: 1rem !important;
        right: 1rem !important;
        width: auto !important;
        border-radius: 12px !important;
    }
}

/* ===================================
   SCROLLBAR MOBILE
   =================================== */
@media (max-width: 768px) {
    .notifications-list,
    .admin-sidebar,
    .catalog-tree-panel,
    #unavailableDatesListDelivery,
    #unavailableDatesListPickup {
        -webkit-overflow-scrolling: touch;
    }
}

/* ===================================
   SIDEBAR MOBILE — PANNEAU BLANC PLEINE LARGEUR
   =================================== */
@media (max-width: 1024px) {

    .admin-sidebar {
        position: fixed !important;
        top: var(--header-height-mobile, 56px) !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        bottom: auto !important;
        max-height: calc(100vh - var(--header-height-mobile, 56px));
        overflow-y: auto;
        background: #ffffff !important;
        border-right: none !important;
        border-bottom: 1px solid #e5e7eb;
        box-shadow: 0 8px 24px rgba(0,0,0,0.12) !important;
        z-index: 999 !important;
        transform: translateY(-110%) !important;
        transition: transform 0.3s ease !important;
    }

    .admin-sidebar.active {
        transform: translateY(0) !important;
    }

    .admin-nav {
        padding: 1rem;
    }

    .admin-nav-item {
        min-height: 52px;
        padding: 0.875rem 1.25rem;
        font-size: 1rem;
        margin-bottom: 0.25rem;
        border-radius: 10px;
        display: flex;
        align-items: center;
        gap: 1rem;
    }

    .admin-nav-item i {
        font-size: 1.2rem;
        width: 26px;
        text-align: center;
    }

    .sidebar-footer {
        border-top: 1px solid #e5e7eb;
        padding: 1rem;
        background: #ffffff;
    }

    .sidebar-overlay {
        display: none !important;
    }

    .admin-header {
        z-index: 1000 !important;
    }
}

/* ===================================
   ANIMATIONS RÉDUITES (accessibilité)
   =================================== */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* ===================================
   SAFE AREA IPHONE (notch / home bar)
   =================================== */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    @media (max-width: 768px) {
        .admin-bottom-nav {
            padding-bottom: env(safe-area-inset-bottom);
            height: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom));
        }

        .admin-main {
            padding-bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom) + 1rem) !important;
        }
    }
}

/* ===================================
   OPTIMISATION DATES & CALENDRIER MOBILE (VERSION PROPRE)
   =================================== */
@media (max-width: 768px) {

    /* --- 1. RESET GLOBAL --- */
    .admin-main {
        padding: 10px !important;
        width: 100% !important;
        max-width: 100vw !important;
        overflow-x: hidden !important;
        box-sizing: border-box !important;
    }

    /* --- 2. ONGLETS (Retour au design d'origine, mais adaptatif) --- */
    div:has(> .delivery-tab),
    .tabs-header,
    ul.nav-tabs {
        display: flex !important;
        width: 100% !important;
        border-bottom: 1px solid #e5e7eb !important; /* Ligne de séparation propre */
        margin-bottom: 1rem !important;
        padding: 0 !important;
    }

    .delivery-tab,
    .nav-link {
        flex: 1 1 50% !important; /* Séparation parfaite 50/50 */
        min-width: 0 !important; /* Empêche de pousser hors de l'écran */
        white-space: normal !important; /* Permet au texte de passer sur 2 lignes si besoin */
        padding: 0.75rem 0.25rem !important;
        font-size: 0.85rem !important;
        text-align: center !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        border-radius: 0 !important;
        background: transparent !important;
    }

    /* --- 3. CONTENEURS --- */
    .admin-card,
    .card {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        padding: 0.75rem !important; /* Padding léger et uniforme */
        border-radius: 12px !important;
        margin-bottom: 1rem !important;
        overflow: hidden !important;
    }

    #deliveryTabContent,
    #pickupTabContent,
    .tab-content {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        padding: 0 !important;
    }

    /* --- 4. LE CALENDRIER --- */
    /* En-tête rouge (proprement intégré dans la carte) */
    .calendar-header {
        width: 100% !important;
        box-sizing: border-box !important;
        padding: 1rem !important;
        margin: 0 0 1rem 0 !important; 
        border-radius: 8px !important; /* Bords arrondis qui matchent la carte */
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
    }

    /* L'ASTUCE : Même configuration de grille exacte pour les jours et les dates = alignement parfait */
    .calendar-weekdays,
    #calendarDaysGridDelivery,
    #calendarDaysGridPickup {
        display: grid !important;
        grid-template-columns: repeat(7, minmax(0, 1fr)) !important;
        gap: 4px !important; /* Le même espacement partout ! */
        width: 100% !important;
        box-sizing: border-box !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    .calendar-weekdays {
        margin-bottom: 0.5rem !important;
    }

    .calendar-weekday {
        text-align: center !important;
        font-size: 0.8rem !important;
        padding: 0 !important;
        color: #6b7280 !important; /* Couleur douce pour les jours */
    }

    /* Boutons des dates */
    .calendar-day,
    #calendarDaysGridDelivery button,
    #calendarDaysGridPickup button {
        width: 100% !important;
        min-width: 0 !important;
        height: 40px !important;
        padding: 0 !important;
        margin: 0 !important;
        font-size: 0.9rem !important;
        border-radius: 6px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }

    /* --- 5. ALERTES ET BOÎTES VIDES --- */
    .alert, 
    .info-box,
    .empty-state {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        white-space: normal !important;
        word-wrap: break-word !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
    }
}