/* ============================================================
   RESPONSIVE — Optimisé pour TOUTES les tailles d'écran
   Breakpoints : mobile (<640) / tablette (640-1024) / desktop (>1024)
   ============================================================ */

/* ============ SCALE de l'aperçu A4 selon la largeur dispo ============ */
.cv-document {
    /* Mise à l'échelle responsive pour s'adapter au panneau de preview */
    transform-origin: top center;
    transition: transform 0.2s ease-out;
}

/* Desktop large : taille réelle */
@media screen and (min-width: 1280px) {
    .cv-document { transform: scale(1); }
}

/* Desktop normal : légère réduction */
@media screen and (min-width: 1024px) and (max-width: 1279px) {
    .cv-document { transform: scale(0.92); }
}

/* Tablette */
@media screen and (max-width: 1023px) and (min-width: 768px) {
    .cv-document { transform: scale(0.85); }
    #preview-panel { padding: 1rem 0.5rem; }
}

/* ============ MOBILE (<768px) ============ */
@media screen and (max-width: 767px) {

    /* Header compact */
    #app-header {
        padding: 0;
    }
    #app-header > div {
        padding: 0.6rem 0.75rem;
        gap: 0.5rem;
    }
    #app-header .w-10.h-10 {
        width: 2.25rem; height: 2.25rem;
    }
    #app-header h1 {
        font-size: 0.95rem;
    }
    #app-header h1 + p {
        display: none;
    }

    /* Boutons header en mode icônes uniquement */
    #app-header button span:not(.sr-only) {
        display: none;
    }
    #app-header button {
        padding: 0.5rem 0.65rem !important;
    }
    #btn-export {
        padding: 0.5rem 0.8rem !important;
    }
    #btn-export span {
        display: inline !important;
        font-size: 0.85rem;
    }

    /* Main : pleine hauteur, slide entre panels */
    #app-main {
        height: calc(100vh - 56px);
        position: relative;
        overflow: hidden;
    }

    #form-panel, #preview-panel {
        position: absolute;
        top: 0; left: 0;
        width: 100%; height: 100%;
        transition: transform 0.35s cubic-bezier(0.25, 0.8, 0.25, 1);
        will-change: transform;
    }

    #form-panel {
        transform: translateX(0);
        z-index: 2;
    }
    #preview-panel {
        transform: translateX(100%);
        display: block !important;
        z-index: 1;
    }

    /* Mode aperçu : on slide les deux panneaux */
    body.mobile-preview-mode #form-panel {
        transform: translateX(-100%);
        display: block !important;
    }
    body.mobile-preview-mode #preview-panel {
        transform: translateX(0);
        z-index: 2;
    }

    /* Scale de l'aperçu sur mobile */
    .cv-document {
        transform: scale(0.45);
        margin-top: -55%;
    }

    /* iPhone SE et plus petits */
    @media (max-width: 360px) {
        .cv-document { transform: scale(0.4); margin-top: -60%; }
    }

    #preview-panel {
        padding: 0.5rem;
        overflow-x: hidden;
    }
    #preview-panel > div {
        max-width: 100% !important;
    }

    /* Tabs scrollables */
    nav.sticky {
        padding: 0.5rem;
    }
    .tab-btn {
        font-size: 0.7rem;
        padding: 0.4rem 0.6rem;
    }
    .tab-btn i {
        font-size: 0.8rem;
    }

    /* Formulaires plus compacts */
    #form-panel .p-4.md\\:p-6 {
        padding: 0.75rem !important;
    }
    .section-title {
        font-size: 0.95rem;
    }

    /* Modals plein écran */
    .modal-content {
        max-height: 95vh;
        border-radius: 1rem;
    }
    .modal-body {
        padding: 1rem;
    }

    /* Galerie de templates : 2 colonnes */
    #templates-gallery {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.5rem !important;
    }
    .template-card-preview .cv-document {
        transform: scale(0.18) !important;
    }

    /* Couleurs : grille plus serrée */
    #color-palette {
        gap: 0.4rem !important;
    }
    .color-swatch {
        width: 2rem !important;
        height: 2rem !important;
    }

    /* Toast positionné mieux */
    #toast {
        bottom: 5rem;
    }

    /* Bouton bascule mobile : style FAB animé */
    #btn-toggle-mobile {
        position: fixed;
        bottom: 1rem;
        right: 1rem;
        width: 3.5rem;
        height: 3.5rem;
        border-radius: 50%;
        box-shadow: 0 8px 24px rgba(15, 23, 42, 0.3);
        z-index: 30;
        background: linear-gradient(135deg, #4f46e5, #7c3aed);
        transition: transform 0.2s ease, box-shadow 0.2s;
    }
    #btn-toggle-mobile:hover {
        transform: scale(1.05);
    }
    #btn-toggle-mobile:active {
        transform: scale(0.95);
    }
    #btn-toggle-mobile i {
        font-size: 1.1rem;
        transition: transform 0.3s;
    }
    body.mobile-preview-mode #btn-toggle-mobile i {
        transform: rotate(180deg);
    }

    /* Bouton bascule dans toolbar : caché (on utilise le FAB) */
    #app-header #btn-toggle-mobile {
        display: none !important;
    }
}

/* ============ TRÈS PETITS ÉCRANS ============ */
@media screen and (max-width: 400px) {
    .modal-header {
        padding: 0.75rem 1rem;
    }
    .modal-header h2 {
        font-size: 1rem;
    }
    .grid-cols-2 {
        gap: 0.5rem;
    }
}

/* ============ TABLETTE PORTRAIT (768-1023) ============ */
@media screen and (min-width: 768px) and (max-width: 1023px) {
    #form-panel { width: 50%; }
    #preview-panel { padding: 1.5rem 1rem; }

    .tab-btn { font-size: 0.7rem; padding: 0.4rem 0.7rem; }

    #templates-gallery {
        grid-template-columns: repeat(3, 1fr) !important;
    }
}

/* ============ DESKTOP TRÈS LARGE ============ */
@media screen and (min-width: 1536px) {
    #form-panel {
        width: 38%;
    }
}

/* ============ RÉDUIRE LE MOTION pour utilisateurs sensibles ============ */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
    }
}

/* ============ INDICATEUR FAB toggle au-dessus de tout ============ */
#btn-toggle-mobile {
    display: none;
}
@media screen and (max-width: 767px) {
    #btn-toggle-mobile {
        display: grid !important;
        place-items: center;
    }
}
