/* =========================================================
   📱 DesignCV — Mobile & Tactile (Module 9)
   RESPONSIVE UNIQUE — Source de vérité pour le mobile.
   Tous les !important garantissent la priorité maximale.
   ========================================================= */

/* ---------- 1. SAFE AREA (iOS notch) ---------- */
@supports (padding: env(safe-area-inset-bottom)) {
    .navbar {
        padding-left: max(2rem, env(safe-area-inset-left)) !important;
        padding-right: max(2rem, env(safe-area-inset-right)) !important;
        padding-top: env(safe-area-inset-top) !important;
        height: calc(var(--nav-height) + env(safe-area-inset-top)) !important;
    }
    .form-panel,
    .preview-panel {
        padding-bottom: env(safe-area-inset-bottom) !important;
    }
}

/* ---------- 2. TOUCH-ACTION (supprime le delay 300ms) ---------- */
.btn,
.btn-icon,
.color-dot,
.theme-btn,
.opt-card,
.photo-preview,
.skill-tag,
.skill-remove,
.btn-remove,
.history-item {
    touch-action: manipulation;
}

/* ---------- 3. TABLETTE (≤1100px) — Single column ---------- */
@media (max-width: 1100px) {
    .app-grid {
        grid-template-columns: 1fr !important;
    }
    .form-panel {
        position: relative !important;
        top: 0 !important;
        max-height: none !important;
        border-right: none !important;
        border-bottom: 1px solid var(--border) !important;
        overflow-y: auto !important;
    }
    .preview-panel {
        position: relative !important;
        top: 0 !important;
        max-height: none !important;
        min-height: 70vh !important;
    }
    .cv-sheet {
        transform: scale(0.85) !important;
        margin: 1.5rem auto !important;
    }
    .preview-area {
        padding: 16px !important;
    }
}

/* ---------- 4. MOBILE (≤700px) ---------- */
@media (max-width: 700px) {
    /* Layout principal */
    .app-grid {
        grid-template-columns: 1fr !important;
    }
    .form-panel {
        border-right: none !important;
        border-bottom: 1px solid var(--border) !important;
        position: relative !important;
        top: 0 !important;
        max-height: none !important;
        padding: 1.25rem !important;
        overflow-y: auto !important;
    }
    .preview-panel {
        position: relative !important;
        top: 0 !important;
        max-height: none !important;
        min-height: 60vh !important;
        overflow-y: auto !important;
    }
    .form-panel,
    .preview-panel {
        -webkit-overflow-scrolling: touch !important;
    }

    /* Navbar */
    .navbar {
        padding: 0 0.75rem !important;
    }
    .brand {
        font-size: 1.1rem !important;
    }
    .nav-actions {
        gap: 4px !important;
    }
    .nav-actions .btn-ghost {
        padding: 6px 8px !important;
        font-size: 0.75rem !important;
    }
    .nav-actions .btn-primary {
        padding: 8px 12px !important;
        font-size: 0.8rem !important;
    }

    /* Formulaire */
    .form-header h1 {
        font-size: 1.4rem !important;
    }
    .form-row,
    .skill-row {
        grid-template-columns: 1fr !important;
    }
    .form-input,
    .form-textarea,
    .form-select {
        font-size: 16px !important;
        padding: 12px 14px !important;
    }

    /* Toolbar preview */
    .preview-toolbar {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 10px !important;
        padding: 10px !important;
    }
    .toolbar-group {
        justify-content: space-between !important;
    }

    /* CV preview */
    .cv-sheet {
        transform: scale(0.55) !important;
        margin: 0.5rem auto !important;
        width: 210mm !important;
    }
    .preview-area {
        padding: 0.5rem !important;
        overflow-x: hidden !important;
    }

    /* Boutons tactiles min 44px */
    .btn {
        min-height: 44px;
        padding: 12px 18px;
    }
    .btn-sm {
        min-height: 40px;
    }
    .btn-icon {
        min-width: 44px;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
    .color-dot {
        width: 36px;
        height: 36px;
    }
    .theme-btn {
        min-height: 40px;
        padding: 8px 16px;
    }

    /* Modale pleine largeur */
    .modal {
        max-width: 100% !important;
        max-height: 95vh !important;
        margin: 0 !important;
        border-radius: 0 !important;
    }
    .modal-header {
        padding: 14px 16px 10px !important;
    }
    .modal-body {
        padding: 12px 16px 16px !important;
    }
    .modal-footer {
        padding: 12px 16px 16px !important;
        flex-wrap: wrap !important;
    }

    /* Options grid */
    .opt-grid {
        grid-template-columns: 1fr !important;
        gap: 10px !important;
    }
    .opt-card {
        padding: 14px !important;
    }

    /* Photo */
    .photo-upload {
        flex-direction: column !important;
        align-items: flex-start !important;
    }
    .photo-preview {
        width: 80px !important;
        height: 80px !important;
    }

    /* Toast centré en bas */
    .toast {
        bottom: 16px !important;
        left: 16px !important;
        right: 16px !important;
        text-align: center !important;
    }

    /* Body — pas de scroll horizontal */
    body {
        overflow-x: hidden !important;
    }
}

/* ---------- 5. PETITS MOBILES (≤480px) ---------- */
@media (max-width: 480px) {
    .cv-sheet {
        transform: scale(0.42) !important;
        margin: 0 !important;
    }
    .preview-area {
        min-height: 350px !important;
    }
    .navbar {
        padding: 0 0.5rem !important;
    }
    .nav-actions .btn-ghost {
        font-size: 0.7rem !important;
        padding: 6px 6px !important;
    }
    .form-panel {
        padding: 1rem !important;
    }
    .form-header h1 {
        font-size: 1.2rem !important;
    }
}

/* ---------- 6. SCROLL FLUIDE TACTILE ---------- */
.form-panel,
.preview-area,
.modal {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

/* ---------- 7. SUPPRESSION DES DÉBORDEMENTS HORIZENTAUX ---------- */
body {
    overflow-x: hidden;
}
.app-grid,
.preview-toolbar,
.navbar {
    max-width: 100vw;
}

/* ---------- 8. MODE PAYSAGE MOBILE ---------- */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
    .navbar {
        height: 56px !important;
    }
    .form-panel {
        max-height: calc(100vh - 56px) !important;
    }
    .preview-panel {
        min-height: 60vh !important;
    }
}
