/* ==========================================================================
   Design System : Studio M3 Premium, Papier Quadrillé & Animations
   ========================================================================== */
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL,GRAD@24,400,1,0');

:root {
    --md-bg: #F3F1F6;
    /* Augmentation de l'opacité à 0.15 pour rendre les petits carreaux bien visibles */
    --grid-color: rgba(103, 80, 164, 0.15); 
    --md-surface: rgba(255, 255, 255, 0.82);
    --md-surface-card: #FFFFFF;
    --md-on-surface: #1C1A22;
    --md-on-surface-variant: #49454F;
    --md-outline-variant: rgba(202, 196, 208, 0.8);
    --md-primary: #6750A4;
    --md-on-primary: #FFFFFF;
    --md-primary-container: #EADDFF;
    --md-on-primary-container: #21005D;
    --md-sub-grised: rgba(0, 0, 0, 0.05);
    --md-error: #B3261E;

    --dot-cat: #0284c7;
    --dot-gom: #d97706;
}

[data-theme="dark"] {
    --md-bg: #110F14;
    --grid-color: rgba(208, 188, 255, 0.12);
    --md-surface: rgba(34, 32, 38, 0.82);
    --md-surface-card: #1C1A20;
    --md-on-surface: #E6E1E9;
    --md-on-surface-variant: #CAC4D0;
    --md-outline-variant: rgba(73, 69, 79, 0.8);
    --md-primary: #D0BCFF;
    --md-on-primary: #381E72;
    --md-primary-container: #4F378B;
    --md-on-primary-container: #EADDFF;
    --md-sub-grised: rgba(255, 255, 255, 0.08);
    --md-error: #F2B8B5;

    --dot-cat: #38bdf8;
    --dot-gom: #fbbf24;
}

html, body {
    margin: 0; padding: 0;
    background-color: var(--md-bg);
    /* Rendu petits carreaux infaillible appliqué sur la racine */
    background-image: 
        linear-gradient(to right, var(--grid-color) 1px, transparent 1px),
        linear-gradient(to bottom, var(--grid-color) 1px, transparent 1px);
    background-size: 22px 22px;
    background-attachment: fixed;
    font-family: 'Roboto', sans-serif;
    height: 100vh; overflow: hidden;
}

.app-layout {
    display: grid;
    grid-template-columns: 330px 1fr;
    height: 100vh; box-sizing: border-box;
    padding: 16px; gap: 20px;
}

.icon {
    font-family: 'Material Symbols Rounded';
    font-weight: normal; font-size: 22px;
    display: inline-block; vertical-align: middle;
}

.surface {
    background-color: var(--md-surface);
    backdrop-filter: blur(24px) saturate(140%);
    -webkit-backdrop-filter: blur(24px) saturate(140%);
    border: 1px solid var(--md-outline-variant);
    border-radius: 28px; padding: 24px;
    display: flex; flex-direction: column;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.02);
    transition: background-color 0.3s;
}

/* ==========================================================================
   Sidebar
   ========================================================================== */
.sidebar { padding: 24px 12px 90px; position: relative; }
.sidebar-header { display: flex; align-items: center; justify-content: space-between; padding: 0 8px; margin-bottom: 12px; }
.sidebar h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.5px; }
.sidebar h2 { font-size: 11px; font-weight: 700; color: var(--md-primary); margin: 24px 0 12px 8px; text-transform: uppercase; letter-spacing: 1px; }
.sidebar-bottom-actions { position: absolute; left: 24px; right: 24px; bottom: 24px; display: flex; gap: 10px; align-items: center; }

.filter-scroll-area { overflow-y: auto; flex: 1; padding-right: 2px; }

.search-box {
    width: 100%; padding: 14px 16px;
    border: 1px solid var(--md-outline-variant); border-radius: 16px;
    font-size: 15px; background: var(--md-surface-card); color: var(--md-on-surface);
    box-sizing: border-box; margin: 16px 0 12px 0;
}
.search-box:focus { outline: none; border-color: var(--md-primary); }

.filter-group { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 20px; }
.layout-inline-flow { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

.chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 14px; border: 1px solid var(--md-outline-variant);
    border-radius: 100px; font-size: 13px;
    color: var(--md-on-surface-variant); background: var(--md-surface-card);
    cursor: pointer; transition: all 0.2s ease;
}
.chip:hover { background: var(--md-primary-container); color: var(--md-on-primary-container); }
.chip.active { background: var(--md-primary); color: var(--md-on-primary); border-color: transparent; font-weight: 500; }
.chip.active-global { background: var(--md-primary); color: var(--md-on-primary); border-color: transparent; font-weight: 500;}

.chip.sidebar-sub-pills {
    background: var(--md-sub-grised);
    border-style: dashed;
    font-size: 12px;
    padding: 6px 12px;
    animation: fadeInInline 0.2s ease-out forwards;
}

.chip .dot { width: 6px; height: 6px; border-radius: 50%; }
.dot.cat { background-color: var(--dot-cat); }
.dot.gom { background-color: var(--dot-gom); }
.dot.all { background-color: var(--md-on-primary); }

/* ==========================================================================
   Zone Principale (Grille Lookbook)
   ========================================================================== */
.main-content { 
    background-color: transparent; border: none; box-shadow: none; padding: 8px 0 0 0; 
    min-height: 0; /* Empêche le bug du scroll bloqué */
}
/* Colonne centrale transparente pour laisser voir le quadrillage */
.app-layout > .surface:nth-child(2) {
    background-color: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    border: none;
    box-shadow: none;
    padding: 8px 0 0 0;
}
.main-header { display: flex; align-items: center; justify-content: space-between; margin: 0 16px 20px 16px; }
.main-content h2 { font-size: 24px; font-weight: 500; letter-spacing: -0.5px; }
.count-badge { font-size: 13px; font-weight: 500; background: var(--md-surface-card); padding: 6px 14px; border-radius: 100px; border: 1px solid var(--md-outline-variant); }

/* Titres : utiliser la couleur de surface active (s'adapte au thème clair/sombre) */
.sidebar h1,
.main-content h2,
.section-title-modal,
.section-title,
.carte-vetement .nom {
    color: var(--md-on-surface);
}

.list-scroll { 
    overflow-y: auto; 
    flex: 1; 
    padding: 0 8px 32px 8px;
}
.products-large-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 24px;
}

.carte-vetement {
    background-color: var(--md-surface-card); border: 1px solid var(--md-outline-variant);
    border-radius: 28px; overflow: hidden; display: flex; flex-direction: column;
    position: relative; transition: transform 0.2s, box-shadow 0.2s ease;
}
.carte-vetement:hover { transform: translateY(-4px); box-shadow: 0 16px 32px rgba(103,80,164,0.1); }
.carte-vetement.add-card:hover { transform: none; box-shadow: none; }

.carte-vetement.add-card {
    border: 6px dashed var(--md-outline-variant);
    background: transparent;
    min-height: 400px;
    justify-content: center;
    cursor: pointer;
    transition: border-color 0.2s ease, background-color 0.2s ease;
}
.carte-vetement.add-card:hover {
    background-color: rgba(103, 80, 164, 0.06);
    border-color: var(--md-primary);
}
.carte-vetement.add-card .add-card-body {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 28px;
    padding: 0;
}
.carte-vetement.add-card .add-card-body .icon {
    font-size: 72px;
    color: var(--md-primary);
}

.img-container { width: 100%; height: 400px; position: relative; }
.carte-vetement img { width: 100%; height: 100%; object-fit: cover; }

.action-overlay { position: absolute; top: 14px; right: 14px; display: flex; gap: 6px; }
.btn-action {
    background: rgba(255, 255, 255, 0.95); border: 1px solid var(--md-outline-variant);
    color: #1c1b1f; width: 40px; height: 40px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center; cursor: pointer; transition: all 0.2s;
}
.btn-action:hover { background: var(--md-primary-container); color: var(--md-on-primary-container); transform: scale(1.08); }
.btn-action.delete:hover { background: #FFEDD5; color: var(--md-error); }

.product-info { padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.carte-vetement .nom { font-size: 16px; font-weight: 500; color: var(--md-on-surface); margin: 0; }
.badge-row { display: flex; flex-wrap: wrap; gap: 4px; }
.badge-row .chip { padding: 3px 10px; font-size: 11px; border-radius: 8px; cursor: default; background: rgba(0,0,0,0.01); }

/* ==========================================================================
   Modale Stepper
   ========================================================================== */
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.step-badge { font-size: 12px; font-weight: 700; background: var(--md-primary-container); color: var(--md-on-primary-container); padding: 4px 12px; border-radius: 100px; }

.form-step { display: none; animation: fadeInStep 0.2s ease-out forwards; }
.form-step.active { display: block; }

.section-title-modal { font-size: 16px; font-weight: 500; color: var(--md-on-surface); display: block; margin-bottom: 16px; }
.section-title { font-size: 13px; font-weight: 700; color: var(--md-primary); margin-top: 20px; display: block; text-transform: uppercase; letter-spacing: 0.5px;}

/* Titre de la modale (ex: "Nouvelle Pièce") */
#modal-title {
    color: var(--md-on-surface);
}

.giant-icon-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.btn-giant-choice {
    background: var(--md-surface-card); border: 1px solid var(--md-outline-variant);
    border-radius: 20px; padding: 20px; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 12px; cursor: pointer;
    transition: all 0.2s; color: var(--md-on-surface);
}
.btn-giant-choice:hover { border-color: var(--md-primary); background: var(--md-primary-container); color: var(--md-on-primary-container); }
.btn-giant-choice.selected { background: var(--md-primary); color: var(--md-on-primary); border-color: transparent; }
.btn-giant-choice .text-icon { font-size: 32px; }
.btn-giant-choice .label { font-size: 14px; font-weight: 500; }

.subcat-icon-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 10px; max-height: 290px; overflow-y: auto; padding: 4px;
}
.subcat-square-label {
    background: var(--md-surface-card); border: 1px solid var(--md-outline-variant);
    border-radius: 16px; padding: 14px; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 8px; cursor: pointer;
    text-align: center; font-size: 12px; font-weight: 500; transition: all 0.2s ease;
}
.subcat-square-label input { display: none; }
.subcat-square-label .icon { font-size: 22px; color: var(--md-primary); }

/* Assurer que le texte et l'icône des sous-catégories suivent le thème du modal */
.subcat-square-label,
.subcat-square-label .icon,
.subcat-square-label .label {
    color: var(--md-on-surface);
}

.subcat-square-label:has(input:checked) {
    background-color: var(--md-primary-container); color: var(--md-on-primary-container); border-color: var(--md-primary);
}
.subcat-square-label:has(input:checked) .icon { color: var(--md-on-primary-container); }

.form-chip-group { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.form-chip-label { display: inline-flex; align-items: center; padding: 12px 16px; border: 1px solid var(--md-outline-variant); border-radius: 100px; font-size: 13px; color: var(--md-on-surface-variant); cursor: pointer; background: var(--md-surface-card); transition: all 0.2s; justify-content: center; }
.form-chip-label input { display: none; }
.form-chip-label:has(input:checked) { background-color: var(--md-primary-container); color: var(--md-on-primary-container); border-color: var(--md-primary); font-weight: 500; }

.file-input-wrapper { display: flex; align-items: center; gap: 12px; padding: 16px; border: 2px dashed var(--md-outline-variant); border-radius: 16px; cursor: pointer; color: var(--md-on-surface-variant); font-size: 14px; justify-content: center; margin-top: 12px;}

.btn-theme { background: transparent; border: none; color: var(--md-on-surface); cursor: pointer; padding: 8px; border-radius: 50%; display: flex; }
.btn-theme:hover { background: rgba(121, 116, 126, 0.1); }

.fab-btn { position: fixed; bottom: 32px; right: 32px; width: 64px; height: 64px; background-color: var(--md-primary-container); color: var(--md-on-primary-container); border: none; border-radius: 24px; box-shadow: 0 6px 16px rgba(0,0,0,0.12); cursor: pointer; display: flex; align-items: center; justify-content: center; z-index: 10; transition: transform 0.2s; }
.fab-btn:hover { transform: scale(1.05); }

.mobile-sidebar-toggle {
    position: fixed;
    top: 16px;
    left: 16px;
    transform: none;
    width: 52px;
    height: 52px;
    border: none;
    border-radius: 18px;
    background: var(--md-primary-container);
    color: var(--md-on-primary-container);
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 95;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.12);
}

.mobile-sidebar-toggle .icon {
    font-size: 26px;
}

.mobile-sidebar-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 14px;
    background: var(--md-sub-grised);
    color: var(--md-on-surface);
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.mobile-sidebar-close .icon {
    font-size: 24px;
}

.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 12, 22, 0.32);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 88;
}

body.sidebar-open .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
}

.modal-overlay { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: rgba(15, 12, 22, 0.3); display: none; align-items: center; justify-content: center; z-index: 100; backdrop-filter: blur(8px); }
.modal-box { width: 100%; max-width: 480px; min-height: 400px; margin: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 24px; }

.btn-text { background: transparent; border: none; color: var(--md-primary); padding: 10px 20px; border-radius: 100px; font-weight: 500; cursor: pointer; }
.btn-filled { background: var(--md-primary); color: var(--md-on-primary); border: none; padding: 12px 28px; border-radius: 100px; font-weight: 500; cursor: pointer; }

.status-text { text-align: center; color: var(--md-on-surface-variant); font-style: italic; margin-top: 40px; grid-column: 1 / -1; }

@keyframes fadeInInline { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fadeInStep { from { opacity: 0; transform: scale(0.97); } to { opacity: 1; transform: scale(1); } }

/* ==========================================================================
   Scrollbars Invisibles / Tactiles épurées
   ========================================================================== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(103, 80, 164, 0.15); border-radius: 100px; }
::-webkit-scrollbar-thumb:hover { background: var(--md-primary); }
* { scrollbar-width: thin; scrollbar-color: rgba(103, 80, 164, 0.2) transparent; }

/* ==========================================================================
   Responsive mobile : Sidebar épurée, Profil haut & Actions fixes à gauche
   ========================================================================== */
@media (max-width: 900px) {
    html, body {
        height: auto;
        min-height: 100vh;
        overflow-x: hidden;
        overflow-y: auto;
    }

    .app-layout {
        grid-template-columns: 1fr;
        gap: 12px;
        padding: 12px;
        min-height: 100vh;
        height: auto;
        padding-bottom: 16px;
    }

    /* 1. Sidebar mobile : Centrage absolu et marges parfaitement égales */
    .sidebar {
        position: fixed;
        top: 12px;
        bottom: 12px;
        width: calc(100vw - 24px) !important; 
        max-width: 380px !important; 
        left: -120%; 
        z-index: 90;
        
        /* Padding forcé symétrique à 16px à gauche et à droite */
        padding: 86px 16px 90px 16px !important; 
        border-radius: 24px;
        height: calc(100vh - 24px);
        max-height: none;
        overflow: hidden;
        box-shadow: 0 18px 48px rgba(0, 0, 0, 0.2);
        backdrop-filter: blur(26px) saturate(150%);
        -webkit-backdrop-filter: blur(26px) saturate(150%);
        
        transform: translateX(0); 
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1), transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-sizing: border-box !important;
    }

    body.sidebar-open .sidebar {
        left: 50%;
        transform: translateX(-50%);
    }

    /* 2. NETTOYAGE ABSOLU DU HEADER */
    .sidebar-header {
        display: block !important; 
        width: 100% !important;
        padding: 0 !important; 
        margin: 0 !important;
        box-sizing: border-box !important;
    }

    .sidebar h1 {
        display: none !important;
    }

    /* 3. GESTION DU BOUTON UNIQUE (Croix) */
    .mobile-sidebar-toggle {
        display: inline-flex;
        position: fixed;
        top: 16px;
        left: 16px;
        z-index: 85; 
        transition: transform 0.2s, background-color 0.3s, left 0.3s, top 0.3s;
    }

    body.sidebar-open .mobile-sidebar-toggle {
        position: fixed; 
        z-index: 99; 
        top: 28px;
        left: 50%;
        transform: translateX(-50%) !important; 
        
        background: rgba(255, 255, 255, 0.15) !important;
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
        color: var(--md-on-surface);
        border: 1px solid rgba(255, 255, 255, 0.15) !important;
        
        width: 64px !important;
        height: 42px !important;
        border-radius: 20px !important; 
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    }

    body.sidebar-open .mobile-sidebar-toggle span {
        font-size: 22px !important;
    }

    /* 4. ZONE DE PROFIL : Largeur à 100% stricte, l'affichage est géré par JS */
    #auth-zone {
        display: block !important;
        width: 100% !important;
        padding: 0 !important;
        margin: 0 0 20px 0 !important; 
        box-sizing: border-box !important;
    }

    #auth-zone > button {
        width: 100% !important;
        padding: 14px 20px !important;
        font-size: 16px;
        border-radius: 14px;
        box-sizing: border-box !important;
        /* display retiré pour laisser le JS faire son travail */
        justify-content: center !important;
        margin: 0 !important;
    }

    #user-profile {
        /* display retiré pour laisser le JS faire son travail */
        width: 100% !important; 
        box-sizing: border-box !important;
        padding: 12px 16px !important; 
        margin: 0 !important; 
        justify-content: space-between !important;
        align-items: center !important;
    }

    #user-photo {
        width: 44px !important;
        height: 44px !important;
        border-radius: 50%;
        flex-shrink: 0; 
    }

    #user-name {
        font-size: 16px !important;
        font-weight: 600;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    #btn-logout {
        margin: 0 !important;
        padding: 8px !important;
        flex-shrink: 0;
    }

    /* 5. Ajustement de la grille et des entrées */
    .search-box {
        margin: 12px 0 !important;
        width: 100% !important;
        box-sizing: border-box !important; 
    }

    .filter-scroll-area {
        overflow-y: auto;
        padding-right: 4px;
        width: 100% !important;
        max-height: calc(100vh - 290px);
        box-sizing: border-box !important;
    }

    /* 6. REPOSITIONNEMENT DES BOUTONS THÈME & TÉLÉCHARGEMENT */
    .sidebar-bottom-actions {
        position: absolute !important;
        left: 16px !important;
        bottom: 16px !important;
        z-index: 95;
        margin: 0 !important;
        display: flex !important;
        gap: 12px !important;
        flex-direction: row !important;
        background: transparent !important;
        padding: 0 !important;
        border: none !important;
        box-shadow: none !important;
    }

    .sidebar-bottom-actions .btn-theme,
    .sidebar-bottom-actions #install-btn {
        background: var(--md-surface-card) !important;
        color: var(--md-on-surface) !important;
        width: 50px !important;
        height: 50px !important;
        border: 1px solid var(--md-outline-variant) !important;
        border-radius: 16px !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        box-shadow: 0 6px 16px rgba(0, 0, 0, 0.08) !important;
        transition: transform 0.2s, background-color 0.3s;
        cursor: pointer;
        margin: 0 !important;
        padding: 0 !important;
    }

    .sidebar-bottom-actions .btn-theme span,
    .sidebar-bottom-actions #install-btn span {
        font-size: 24px !important;
        margin: 0 !important;
    }

    .sidebar-bottom-actions .btn-theme:hover,
    .sidebar-bottom-actions #install-btn:hover {
        transform: scale(1.05);
    }

    /* 7. Contenu principal (Lookbook) */
    .main-content {
        padding: 64px 0 0 !important;
        min-height: 100vh;
    }

    .app-layout > .surface:nth-child(2) {
        padding: 64px 0 0 !important;
    }

    .main-header {
        margin: 0 8px 16px !important;
        gap: 12px;
    }

    .main-content h2 {
        font-size: 20px;
    }

    .products-large-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
        gap: 14px;
    }

    .img-container,
    .carte-vetement.add-card {
        height: 220px;
        min-height: 220px;
    }

    .product-info {
        padding: 14px;
        gap: 10px;
    }

    /* 8. Désactivation complète du FAB '+' sur mobile */
    .fab-btn {
        display: none !important;
    }

    body.sidebar-open {
        overflow: hidden;
    }

    .modal-box {
        max-width: none;
        width: calc(100% - 24px);
        margin: 12px;
        min-height: auto;
    }
}

/* ==========================================================================
   Vues Globales
   ========================================================================== */
.view-section { display: none; flex-direction: column; height: 100%; flex: 1; }
.view-section.active { display: flex; }

/* ==========================================================================
   Créateur de Tenues (Canevas Unique & Tiroirs Flottants)
   ========================================================================== */
.outfit-workspace {
    display: flex;
    flex: 1;
    overflow: hidden;
    padding: 0 16px 16px;
    min-height: 0;
    position: relative;
}

/* Styles pour les onglets de tenues (désormais dans la sidebar) */
.outfit-list-v2 { display: flex; flex-direction: column; gap: 8px; overflow-y: auto; flex: 1; }
.outfit-tab {
    display: flex; align-items: center; gap: 10px; padding: 12px 14px;
    background: var(--md-sub-grised); border: 1px solid transparent;
    border-radius: 14px; color: var(--md-on-surface); cursor: pointer;
    text-align: left; font-size: 14px; font-weight: 500; transition: all 0.2s ease;
}
.outfit-tab:hover { background: rgba(103, 80, 164, 0.08); }
.outfit-tab.active { background: var(--md-primary-container); color: var(--md-on-primary-container); border-color: var(--md-primary); }

/* --- Le Canevas (prend toute la place centrale) --- */
.canvas-container {
    flex: 1; background: var(--md-surface-card);
    border: 2px dashed var(--md-outline-variant); border-radius: 24px;
    position: relative; overflow: hidden;
    display: flex; align-items: center; justify-content: center;
    /* Marge droite pour que la silhouette reste centrée visuellement à côté des poignées fermées */
    padding-right: 80px; 
    touch-action: none;
}

.silhouette {
    width: 100%; 
    height: 80%; /* Prend beaucoup plus de place sur le canevas */
    max-height: 500px;
    
    /* Remplacement par l'icône "boy" officielle de Material Symbols */
    background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" fill="%23cac4d0"><path d="M440-120v-360H320v-160q0-33 23.5-56.5T400-720h160q33 0 56.5 23.5T640-640v160H520v360h-80Zm40-640q-33 0-56.5-23.5T400-840q0-33 23.5-56.5T480-920q33 0 56.5 23.5T560-840q0 33-23.5 56.5T480-760Z"/></svg>') no-repeat center center;
    
    background-size: contain; 
    opacity: 0.15; /* Un peu plus discret en fond */
    pointer-events: none; 
}


.canvas-hint {
    position: absolute; bottom: 24px; color: var(--md-on-surface-variant);
    font-size: 14px; background: var(--md-surface); padding: 8px 16px;
    border-radius: 100px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); pointer-events: none;
}

/* Visual feedback lors du survol de Drag */
.canvas-container.drag-over {
    border-color: var(--md-primary); background: rgba(103, 80, 164, 0.04); box-shadow: inset 0 0 20px rgba(103, 80, 164, 0.1);
}

/* --- Les Tiroirs Flottants (Collés au bord absolu de l'écran) --- */
.outfit-drawers-right {
    position: fixed; /* Sort du flux normal pour s'accrocher à l'écran */
    top: 120px;      /* Laisse respirer le haut de l'application */
    bottom: 60px;    /* Laisse respirer le bas */
    right: 0;        /* 100% collé au bord droit du navigateur */
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 12px;
    align-items: flex-end; 
    z-index: 9999; /* Par-dessus absolument toute l'interface */
    pointer-events: none; /* Permet de cliquer à travers les espaces vides */
}

/* Structure d'un tiroir individuel */
.horizontal-drawer {
    pointer-events: auto; /* Réactive le clic sur le tiroir lui-même */
    display: flex;
    height: 22%; /* Répartition automatique sur la hauteur disponible */
    min-height: 120px;
    border: 1px solid var(--md-outline-variant);
    /* Bords carrés à droite (contre l'écran), arrondis à gauche */
    border-radius: 24px 0 0 24px; 
    border-right: none;
    overflow: hidden;
    transition: width 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
    flex-shrink: 0;
    box-shadow: -8px 8px 24px rgba(0,0,0,0.12); /* Ombre portée vers la gauche */
}

/* État fermé : seule la poignée dépasse de l'écran */
.horizontal-drawer.collapsed {
    width: 64px;
    background: var(--md-sub-grised);
    box-shadow: -4px 4px 12px rgba(0,0,0,0.05);
}

/* État ouvert : le tiroir se déploie vers la gauche par-dessus le canevas */
.horizontal-drawer:not(.collapsed) {
    width: 400px;
    border-color: var(--md-primary);
    background: var(--md-surface-card);
}

/* La poignée du tiroir (placée à gauche) */
.drawer-handle {
    width: 64px; height: 100%; background: transparent; border: none;
    color: var(--md-on-surface-variant); display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 8px; cursor: pointer;
    border-right: 1px solid transparent; flex-shrink: 0; user-select: none; padding: 8px 0;
}
.horizontal-drawer:not(.collapsed) .drawer-handle {
    border-right: 1px solid var(--md-outline-variant); background: var(--md-sub-grised); color: var(--md-primary);
}

.handle-label {
    font-size: 10px; font-weight: 700; text-transform: uppercase;
    writing-mode: vertical-lr; transform: rotate(180deg); letter-spacing: 0.5px;
}

.drawer-handle .arrow { font-size: 16px; transition: transform 0.3s ease; }
.horizontal-drawer:not(.collapsed) .drawer-handle .arrow { transform: rotate(180deg); }

/* Corps intérieur du tiroir */
.drawer-body {
    flex: 1; display: flex; flex-direction: column; padding: 14px;
    overflow: hidden; min-width: 330px; 
}
.drawer-body h4 { margin: 0 0 8px 0; font-size: 13px; color: var(--md-primary); text-transform: uppercase; }
.horizontal-drawer .outfit-items-list {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; overflow-y: auto; flex: 1; padding-right: 4px;
}

/* Nouvelles miniatures de sélection (Image + Nom discret) */
.outfit-item-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    border-radius: 12px;
    overflow: hidden;
    cursor: grab;
    border: 1px solid var(--md-outline-variant);
    transition: transform 0.2s, border-color 0.2s;
    background: var(--md-sub-grised);
}
.outfit-item-wrapper:hover {
    transform: scale(1.05);
    border-color: var(--md-primary);
    z-index: 2;
}
.outfit-item-wrapper:active { cursor: grabbing; }

.outfit-item-source {
    width: 100%;
    height: 100%;
    object-fit: cover;
    pointer-events: none; /* Laisse le parent gérer le glisser-déposer */
}
/* Le petit label dans les tiroirs (Masqué par défaut, visible au Hover) */
.outfit-item-name {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    background: rgba(255, 255, 255, 0.9);
    color: var(--md-on-surface);
    font-size: 11px;
    font-weight: 600;
    text-align: center;
    padding: 6px 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    
    /* Animation de masque par défaut */
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.2s ease;
    pointer-events: none;
}
[data-theme="dark"] .outfit-item-name {
    background: rgba(28, 26, 32, 0.9);
    color: #E6E1E9;
}

/* Apparition du nom dans le tiroir au survol */
.outfit-item-wrapper:hover .outfit-item-name {
    opacity: 0;
    transform: translateY(0);
}

/* Étiquette du nom sur le canevas (Verticale, collée à la ligne, alignée en bas) */
.canvas-item-name {
    position: absolute;
    left: -14px; /* Presque collé à la ligne pointillée */
    bottom: 2px; /* Aligné sur le bas de la box */
    transform: rotate(180deg); /* Garde la lecture de bas en haut */
    writing-mode: vertical-lr;
    
    color: var(--md-primary); 
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    white-space: nowrap;
    
    background: transparent;
    border: none;
    box-shadow: none;
    
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 100; 
}

/* Afficher l'étiquette UNIQUEMENT quand l'élément est actif (au clic) */
.canvas-item.active-item .canvas-item-name {
    opacity: 1;
}

/* Afficher l'étiquette sur le canevas quand l'élément est survolé ou actif */

.canvas-item.active-item .canvas-item-name {
    opacity: 1;
}

/* Le vêtement une fois sur le canevas */
.canvas-item { position: absolute; cursor: grab; user-select: none; touch-action: none; box-sizing: border-box; z-index: 1; }

.canvas-item img { 
    width: 100%; 
    height: 100%; 
    pointer-events: none; 
    border-radius: 8px; 
    object-fit: contain; /* NOUVEAU : Empêche toute déformation de l'image */
}

.canvas-item.active-item { outline: 2px dashed var(--md-primary); }
/* Poignées d'interaction sur les items du canevas */
.delete-handle, .resize-handle, .rotate-handle {
    position: absolute; width: 28px; height: 28px; border-radius: 50%;
    display: none; align-items: center; justify-content: center;
    color: white; box-shadow: 0 2px 8px rgba(0,0,0,0.3); z-index: 10;
}
.canvas-item.active-item .delete-handle, .canvas-item.active-item .resize-handle, .canvas-item.active-item .rotate-handle { display: flex; }
.delete-handle { top: -14px; right: -14px; background: var(--md-error); cursor: pointer; }
.delete-handle .icon { font-size: 18px; }
.resize-handle { bottom: -14px; right: -14px; background: var(--md-primary); cursor: nwse-resize; }
.resize-handle .icon { font-size: 16px; }
.rotate-handle { top: -35px; left: 50%; transform: translateX(-50%); background: var(--md-primary); cursor: grab; }
.rotate-handle .icon { font-size: 18px; }
.rotate-handle { touch-action: none; }
.canvas-item.active-item::before { content: ''; position: absolute; top: -11px; left: 50%; width: 2px; height: 11px; background: var(--md-primary); transform: translateX(-50%); }

/* Animation de pulsation pour le bouton save non sauvegardé */
@keyframes saveButtonPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(179, 38, 30, 0.7); }
    50% { box-shadow: 0 0 0 8px rgba(179, 38, 30, 0); }
}

#btn-save-outfit.unsaved {
    background: #B3261E !important;
    color: #FFFFFF !important;
    animation: saveButtonPulse 2s infinite;
}

/* NOUVEAU : Input de nom de tenue stylisé */
.outfit-name-input {
    background: transparent;
    border: none;
    font-size: 24px;
    font-weight: 500;
    color: var(--md-on-surface);
    outline: none;
    border-bottom: 2px dashed transparent;
    transition: border-color 0.2s, background-color 0.2s;
    padding: 6px 12px;
    margin-left: -12px;
    border-radius: 12px;
    width: 100%;
    max-width: 400px;
}
.outfit-name-input:focus, .outfit-name-input:hover {
    border-bottom-color: var(--md-outline-variant);
    background: var(--md-sub-grised);
}

/* Responsivité Mobile (Reste en barre horizontale défilante en bas) */
@media (max-width: 900px) {
    .outfit-workspace { padding: 0 12px 12px; flex-direction: column; }
    .canvas-container { padding-right: 0; min-height: 400px; flex: none; height: 400px; }
    
    .outfit-drawers-right {
        position: relative; top: auto; right: auto; bottom: auto;
        width: 100%; height: 180px; flex-direction: row; align-items: flex-start; z-index: 10; pointer-events: auto;
    }
    .horizontal-drawer { height: 100% !important; flex-direction: column; border-radius: 20px; border-right: 1px solid var(--md-outline-variant); }
    .horizontal-drawer.collapsed { width: 72px; height: 100% !important; }
    .horizontal-drawer:not(.collapsed) { width: 260px; height: 100% !important; }
    .drawer-handle { width: 100%; height: 48px; flex-direction: row; border-right: none !important; border-bottom: 1px solid transparent; }
    .horizontal-drawer:not(.collapsed) .drawer-handle { border-bottom: 1px solid var(--md-outline-variant); }
    .handle-label { writing-mode: horizontal-tb; transform: none; }
    .drawer-handle .arrow { transform: rotate(-90deg); }
    .horizontal-drawer:not(.collapsed) .drawer-handle .arrow { transform: rotate(90deg); }
    .drawer-body { min-width: 0; }
    .horizontal-drawer .outfit-items-list { grid-template-columns: repeat(2, 1fr); }
}