/* ==============================================
   HEKOO - MOBILE EXPERIENCE (mobile.css)
   Fusion chirurgicale - Restauration Page 1 
   + Correction Liste Page 3 (Zéro superposition)
   ============================================== */

/* ──────────────────────────────────────────────
   1. BOTTOM NAVIGATION
   ────────────────────────────────────────────── */
.mobile-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 64px;
    background: rgba(255, 255, 255, 0.97);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid rgba(0, 0, 0, 0.06);
    z-index: 1500;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.06);
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

.mobile-bottom-nav .nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    gap: 3px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.68rem;
    font-weight: 600;
    transition: color 0.2s ease;
    position: relative;
}

.mobile-bottom-nav .nav-item svg {
    width: 23px;
    height: 23px;
    transition: transform 0.25s ease;
    stroke: currentColor;
}

.mobile-bottom-nav .nav-item.active {
    color: var(--secondary-terracotta);
}

.mobile-bottom-nav .nav-item.active svg {
    transform: translateY(-2px) scale(1.1);
}

.mobile-bottom-nav .nav-item.active::after {
    content: '';
    display: block;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--secondary-terracotta);
    position: absolute;
    bottom: 8px;
}

/* ──────────────────────────────────────────────
   2. OVERRIDES MOBILE (max-width: 768px)
   ────────────────────────────────────────────── */
@media (max-width: 768px) {
    :root {
        --bottom-nav-h: 64px;
        --header-h-m: 56px;
    }

    body {
        overflow: hidden;
        width: 100vw;
    }

    .mobile-bottom-nav {
        display: flex;
    }

    #qr-code-btn {
        display: none !important;
    }

    /* SYSTÈME DE PAGES FADE */
    .main-content {
        height: 100dvh !important;
        transform: none !important;
        transition: none !important;
        position: relative !important;
    }

    .page {
        position: absolute !important;
        top: 0 !important;
        left: 0 !important;
        width: 100% !important;
        height: 100dvh !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        opacity: 0 !important;
        pointer-events: none !important;
        transition: opacity 0.3s ease !important;
        padding-top: calc(var(--header-h-m) + 0.5rem) !important;
        padding-bottom: calc(var(--bottom-nav-h) + 1.5rem) !important;
        box-sizing: border-box;
    }

    .page-1-active .page-1,
    .page-2-active .page-2,
    .page-3-active .page-3,
    .page-4-active .page-4 {
        opacity: 1 !important;
        pointer-events: auto !important;
    }

    header {
        height: var(--header-h-m);
        padding: 0 1.2rem;
        background: rgba(244, 241, 237, 0.97) !important;
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
        border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    }

    header>div {
        display: none !important;
    }

    .logo {
        font-size: 1.5rem;
    }

    /* ========================================
       3. PAGE 1 — ACCUEIL (RESTO VERSION)
       ======================================== */
    .page-1 {
        /* HEKOO Chirurgie N°1 : Remplacement du center par flex-start et ajout de marge en haut pour ouverture propre */
        padding: calc(var(--header-h-m) + 2rem) 1.2rem calc(var(--bottom-nav-h) + 1.5rem) !important;
        justify-content: flex-start !important;
        display: flex;
        flex-direction: column;
    }

    .hero {
        text-align: center;
        margin-bottom: 1.2rem;
    }

    .hero h1 {
        font-size: clamp(1.8rem, 7vw, 2.5rem);
        letter-spacing: -0.5px;
        margin-bottom: 0.3rem;
    }

    .hero p {
        font-size: 0.95rem;
        margin-bottom: 1.2rem;
    }

    .btn-primary {
        width: 100%;
        max-width: 320px;
        margin: 0 auto;
        padding: 1rem 2rem;
        font-size: 1.05rem;
    }

    .features {
        flex-direction: column;
        gap: 0.8rem;
        margin-top: 1.5rem;
    }

    .feature-pill {
        width: 100%;
        padding: 0.8rem 1rem;
        background: var(--white-card);
        border: 1px solid rgba(0, 0, 0, 0.05);
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
    }

    /* ========================================
       4. PAGE 2 — FORMULAIRE & TAGS
       ======================================== */
    .page-2 {
        padding: calc(var(--header-h-m) + 0.5rem) 1rem calc(var(--bottom-nav-h) + 1rem) !important;
    }

    /* HEKOO Chirurgie N°2 : Titre alternatif sur mobile "Quel est ton projet ?" */
    .page-2-container h2 {
        font-size: 0 !important;
        /* Masque le texte long d'origine sans casser le JS */
        margin-bottom: 0.5rem;
    }

    .page-2-container h2::before {
        content: "Quel est ton projet ?";
        font-size: clamp(1.8rem, 7vw, 2.5rem) !important;
        display: block;
        color: var(--text-main);
        line-height: 1.2;
    }

    .tags-wrapper {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        scroll-snap-type: x mandatory !important;
        scrollbar-width: none !important;
        padding: 10px 1rem 20px 1rem !important;
        margin: 0 -1rem 1rem -1rem !important;
        gap: 1rem !important;
    }

    .tags-wrapper::-webkit-scrollbar {
        display: none !important;
    }

    .tags-row {
        display: contents !important;
    }

    .prompt-tag {
        flex: 0 0 82% !important;
        scroll-snap-align: center !important;
        background: #fff !important;
        border-radius: 16px !important;
        padding: 1.2rem 1rem !important;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05) !important;
        white-space: normal !important;
    }

    /* ========================================
       5. PAGE 3 — DASHBOARD (CHIRURGIE LISTE)
       ======================================== */
    .page-3 {
        padding: calc(var(--header-h-m) + 0.5rem) 0.8rem calc(var(--bottom-nav-h) + 1rem) !important;
    }

    /* Conteneur de carte sécurisé */
    .dash-card {
        padding: 1rem;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
        overflow: hidden;
    }

    .dash-card .flex-between {
        display: flex !important;
        align-items: center;
        gap: 10px;
        margin-bottom: 1rem;
    }

    .btn-export {
        padding: 8px 12px !important;
        font-size: 0.8rem !important;
        white-space: nowrap;
    }

    /* 🛡️ REFONTE TOTALE DE LA TABLE EN LISTE MOBILE 🛡️ */
    /* HEKOO Chirurgie N°3 : Rendre la liste de courses aussi large que les autres encarts */
    .page-3 .logistics-table {
        display: block !important;
        width: 100% !important;
        border-collapse: collapse;
    }

    /* On annule le padding de la carte uniquement pour la table pour gagner de la place */
    .page-3 .dash-card:has(.logistics-table) {
        padding-left: 0 !important;
        padding-right: 0 !important;
        background: transparent !important;
        box-shadow: none !important;
        border: none !important;
    }

    .page-3 .logistics-table thead {
        display: none !important;
    }

    .page-3 .logistics-table tbody {
        display: block !important;
        width: 100% !important;
    }

    .page-3 .logistics-table tr {
        display: flex !important;
        flex-wrap: wrap !important;
        align-items: flex-start !important;
        padding: 14px 12px !important;
        margin-bottom: 10px !important;
        background: #fff !important;
        border: 1px solid #E2DDD5 !important;
        border-radius: 12px !important;
        width: 100% !important;
        box-sizing: border-box !important;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.03) !important;
    }

    /* Cellules de base */
    .page-3 .logistics-table td {
        display: block !important;
        padding: 0 !important;
        background: transparent !important;
        border: none !important;
    }

    /* 1. Checkbox : SUPPRIMÉE sur mobile */
    .page-3 .logistics-table td:nth-child(1) {
        display: none !important;
    }

    /* 3. Article (Titre) : FLEX 1 - PREND TOUT L'ESPACE RESTANT */
    .page-3 .logistics-table td:nth-child(3) {
        flex: 1 !important;
        order: 1;
        /* Remonte en première position */
        font-weight: 700;
        font-size: 0.95rem;
        /* Légèrement grossi pour meilleure lisibilité */
        color: var(--text-main);
        line-height: 1.4;
        padding-right: 8px !important;
        word-wrap: break-word;
        overflow-wrap: break-word;
        min-width: 0;
    }

    /* 6. Prix : Largeur fixe, aligné droite */
    .page-3 .logistics-table td:nth-child(6) {
        flex: 0 0 65px !important;
        order: 2;
        /* Passe en deuxième */
        font-weight: 700;
        font-size: 0.95rem;
        text-align: right !important;
        color: var(--text-main);
    }

    /* 7. Poubelle : Largeur fixe */
    .page-3 .logistics-table td:nth-child(7) {
        flex: 0 0 30px !important;
        order: 3;
        /* En troisième */
        display: flex;
        justify-content: flex-end;
    }

    /* --- DÉTAILS (Niveau 2) --- */
    .page-3 .logistics-table td:nth-child(2),
    .page-3 .logistics-table td:nth-child(4),
    .page-3 .logistics-table td:nth-child(5) {
        display: none !important;
        /* Masqués par défaut */
        width: 100% !important;
        flex: 0 0 100% !important;
        order: 4;
        /* Passe en dessous du reste */
        font-size: 0.85rem;
        color: var(--text-secondary);
        padding-left: 0 !important;
        /* Retrait de l'alignement de l'ancienne checkbox */
        margin-top: 6px;
    }

    /* Affichage au clic/tap sur le TR */
    .page-3 .logistics-table tr:active td:nth-child(2),
    .page-3 .logistics-table tr:active td:nth-child(4),
    .page-3 .logistics-table tr:active td:nth-child(5),
    .page-3 .logistics-table tr:hover td:nth-child(2),
    .page-3 .logistics-table tr:hover td:nth-child(4),
    .page-3 .logistics-table tr:hover td:nth-child(5) {
        display: block !important;
    }

    /* État Coché (Maintenu si coché depuis web, mais sans checkbox mobile) */
    .page-3 .logistics-table tr.item-checked {
        opacity: 0.5;
    }

    .page-3 .logistics-table tr.item-checked td:nth-child(3),
    .page-3 .logistics-table tr.item-checked td:nth-child(6) {
        text-decoration: line-through;
    }

    /* ========================================
       6. PAGE 4 — PROFIL & MODALES
       ======================================== */
    .page-4 {
        padding: calc(var(--header-h-m) + 0.5rem) 0.8rem 80px !important;
    }

    .modal-overlay {
        align-items: flex-end !important;
    }

    .modal-content {
        width: 100% !important;
        border-radius: 24px 24px 0 0 !important;
        max-height: 90dvh;
    }

    /* LOADER IA */
    #iaOrganicCanvas {
        width: 220px !important;
        height: 220px !important;
    }
}
