/* ════════════════════════════════════════════════════════════════════
   HFH T-Shirt Editor — Styles frontend
   ════════════════════════════════════════════════════════════════════ */

/* ── Reset dans la zone de l'éditeur ──────────────────────────────── */
.hfh-editor-wrap *,
.hfh-editor-wrap *::before,
.hfh-editor-wrap *::after {
    box-sizing: border-box;
}

/* ── Container principal ──────────────────────────────────────────── */
.hfh-editor-wrap {
    --hfh-primary:   #197f8d;
    --hfh-primary-d: #145f6a;
    --hfh-accent:    #e2c696;
    --hfh-danger:    #c0392b;
    --hfh-border:    #e0e0e0;
    --hfh-bg:        #f7f8fa;
    --hfh-card:      #ffffff;
    --hfh-radius:    10px;
    --hfh-shadow:    0 2px 12px rgba(0,0,0,.08);

    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: #2c3e50 !important; /* Force la couleur de base */
    max-width: 1100px;
    margin: 0 auto;
}

/* ── En-tête ──────────────────────────────────────────────────────── */
.hfh-editor-header {
    text-align: center;
    padding: 32px 16px 16px;
}
.hfh-editor-header h2 {
    font-size: clamp(1.4rem, 3vw, 2rem);
    margin: 0 0 8px;
    color: var(--hfh-primary) !important;
}
.hfh-editor-header p {
    color: #444 !important;
    margin: 0;
}

/* ── Corps (outils + aperçu) ──────────────────────────────────────── */
.hfh-editor-body {
    display: flex;
    gap: 20px;
    padding: 0 16px 16px;
    align-items: flex-start;
}

/* ── Panneau outils gauche ────────────────────────────────────────── */
.hfh-tools-panel {
    width: 340px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 2px;
}

.hfh-tool-section {
    background: var(--hfh-card);
    border: 1px solid var(--hfh-border);
    border-radius: var(--hfh-radius);
    padding: 10px 12px;
    box-shadow: var(--hfh-shadow);
}
.hfh-tool-section h3 {
    font-size: 1.2rem;
    margin: 0 0 8px !important;
    text-align: center;
    border-bottom: 1px solid #eee;
    padding-bottom: 5px;
    opacity: 0.7;
    color: #333 !important;
}

/* Mode étapes : Sections verrouillées */
.hfh-tool-section.hfh-locked {
    opacity: 0.35;
    pointer-events: none;
    filter: grayscale(0.8);
    position: relative;
}
.hfh-tool-section.hfh-locked::after {
    content: "🔒";
    position: absolute;
    top: 8px; right: 10px;
    font-size: 0.9rem;
}

.hfh-icon { font-size: 1rem; }

/* ── Swatches couleur ─────────────────────────────────────────────── */
.hfh-color-swatches {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}
.hfh-color-swatch {
    width: 100%;
    aspect-ratio: 1 / 1;
    border-radius: 50%;
    border: 2px solid #ddd;
    cursor: pointer;
    transition: all .2s ease;
    padding: 0;
    position: relative;
}
.hfh-color-swatch:hover  { transform: scale(1.15); }
.hfh-color-swatch.active {
    border-color: var(--hfh-primary);
    transform: scale(1.1);
    box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--hfh-primary);
}
/* ── Swatches couleur texte ───────────────────────────────────────── */
.hfh-text-color-swatches {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}
.hfh-text-color-swatch {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 1px solid #ddd;
    cursor: pointer;
    transition: transform .15s;
    padding: 0;
}
.hfh-text-color-swatch:hover { transform: scale(1.2); }
.hfh-text-color-swatch.active { border: 2px solid var(--hfh-primary); box-shadow: 0 0 0 1px #fff, 0 0 0 2px var(--hfh-primary); }

.hfh-custom-color-section {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-top: 15px;
    border-top: 1px solid var(--hfh-border);
}

/* ── Sélecteur taille ─────────────────────────────────────────────── */
.hfh-size-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.hfh-size-btn {
    padding: 6px 12px;
    border: 2px solid var(--hfh-border);
    border-radius: 6px;
    background: var(--hfh-bg);
    cursor: pointer;
    font-weight: 600;
    font-size: .85rem;
    color: #333 !important; /* Force la visibilité du texte des tailles */
    transition: all .15s;
}
.hfh-size-btn:hover  { border-color: var(--hfh-primary); color: var(--hfh-primary); }
.hfh-size-btn.active { background: var(--hfh-primary); border-color: var(--hfh-primary); color: #fff; }

/* ── Groupes de paramètres ────────────────────────────────────────── */
.hfh-control-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 10px;
}
.hfh-control-full {
    grid-column: span 2;
}

/* ── Layout des contrôles ────────────────────────────────────────── */
.hfh-control-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 8px;
}

/* ── Inputs ───────────────────────────────────────────────────────── */
.hfh-label {
    display: block;
    font-size: .78rem;
    font-weight: 600;
    color: #333 !important;
    margin: 5px 0 2px;
}
.hfh-label span {
    float: right;
    color: var(--hfh-primary);
}
.hfh-input,
.hfh-select,
.hfh-textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--hfh-border);
    border-radius: 6px;
    font-size: .9rem;
    color: #000000 !important;
    background-color: #ffffff !important;
    transition: border-color .15s;
}

/* Force la visibilité des options dans la liste déroulante */
.hfh-select option {
    color: #000000 !important;
    background-color: #ffffff !important;
}

.hfh-input:focus,
.hfh-select:focus,
.hfh-textarea:focus { outline: none; border-color: var(--hfh-primary); }

.hfh-input::placeholder {
    color: #aaa !important;
    opacity: 1 !important;
}

.hfh-custom-color {
    width: 100%;
    height: 36px;
    border: 1px solid var(--hfh-border);
    border-radius: 6px;
    padding: 2px;
    cursor: pointer;
    background: #fff;
}

.hfh-range {
    width: 100%;
    accent-color: var(--hfh-primary);
}
.hfh-range-out {
    font-size: .8rem;
    color: #666;
    display: block;
    text-align: right;
}

/* Barre d'outils Design */
.hfh-design-toolbar {
    display: flex;
    gap: 2px;
    background: #eee;
    padding: 2px;
    border-radius: 6px;
    margin-bottom: 8px;
    justify-content: space-between;
}
.hfh-style-btn {
    flex: 1;
    padding: 6px;
    border: none;
    border-radius: 6px;
    background: #fff;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: bold;
    color: #333 !important; /* Force la visibilité des lettres G, I, S */
    transition: 0.2s;
}
.hfh-style-btn:hover { background: #e0e0e0; }
.hfh-style-btn.active { background: var(--hfh-primary); color: #fff; }

/* Sélecteur de genre compact */
.hfh-gender-selector {
    background: #f0f0f0;
    padding: 4px;
    border-radius: 8px;
    display: flex;
    gap: 4px;
}

/* Upload image */
.hfh-file-label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border: 2px dashed var(--hfh-border);
    border-radius: 6px;
    cursor: pointer;
    font-size: .85rem;
    color: var(--hfh-primary);
    font-weight: 600;
    transition: border-color .15s, background .15s;
}
.hfh-file-label:hover { border-color: var(--hfh-primary); background: #f0f9fb; }
.hfh-file-input { display: none; }
.hfh-hint { font-size: .75rem; color: #999; margin: 6px 0 0; }

/* ── Boutons ──────────────────────────────────────────────────────── */
.hfh-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: .85rem;
    font-weight: 600;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all .15s;
    text-decoration: none;
}
.hfh-btn-primary {
    background: var(--hfh-primary);
    color: #fff;
    border-color: var(--hfh-primary);
    width: 100%;
    margin-top: 8px;
}
.hfh-btn-primary:hover { background: var(--hfh-primary-d); border-color: var(--hfh-primary-d); }

.hfh-btn-ghost {
    background: transparent;
    border-color: var(--hfh-border);
    color: #555;
}
.hfh-btn-ghost:hover { border-color: #999; color: #222; }

.hfh-btn-danger { background: transparent; border-color: var(--hfh-danger); color: var(--hfh-danger); }
.hfh-btn-danger:hover { background: var(--hfh-danger); color: #fff; }

/* ── Mode Unicolore ─────────────────────────────────────────────── */
.hfh-unicolor-wrap {
    background: #f9f9f9;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid var(--hfh-border);
    margin-top: 10px;
}
.hfh-unicolor-wrap label {
    cursor: pointer;
}

/* ── Liste des éléments (Calques) ────────────────────────────────── */
.hfh-elements-list {
    margin-top: 15px;
    border-top: 1px solid var(--hfh-border);
    padding-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 250px;
    overflow-y: auto;
}
.hfh-element-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    background: #f9f9f9;
    border: 1px solid #eee;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}
.hfh-element-item:hover { background: #f0f0f0; }
.hfh-element-item.active { border-color: var(--hfh-primary); background: #f0f9fb; box-shadow: 0 2px 5px rgba(25,127,141,0.1); }

.hfh-element-icon { font-size: 1.1rem; flex-shrink: 0; }
.hfh-element-info { flex: 1; font-size: 0.8rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #444; }

.hfh-element-actions { display: flex; gap: 4px; }
.hfh-el-action {
    padding: 4px;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    line-height: 1;
}
.hfh-el-action:hover { background: var(--hfh-primary); color: #fff; border-color: var(--hfh-primary); }

.hfh-btn-sm { font-size: .78rem; padding: 5px 10px; width: calc(50% - 3px); margin-top: 4px; }
.hfh-tool-section .hfh-btn-sm { display: inline-flex; }

.hfh-btn-submit {
    font-size: 1rem;
    padding: 14px 28px;
    width: 100%;
    margin-top: 16px;
    border-radius: 8px;
}

/* ── Zone aperçu ──────────────────────────────────────────────────── */
.hfh-preview-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

/* Toggle recto/verso */
.hfh-view-toggle {
    display: flex;
    gap: 0;
    border: 2px solid var(--hfh-primary);
    border-radius: 8px;
    overflow: hidden;
}
.hfh-toggle-btn {
    padding: 8px 20px;
    border: none;
    background: #fff;
    cursor: pointer;
    font-weight: 600;
    font-size: .88rem;
    color: var(--hfh-primary);
    transition: all .15s;
}
.hfh-toggle-btn.active { background: var(--hfh-primary); color: #fff; }
.hfh-toggle-btn:hover:not(.active) { background: #f0f9fb; }

/* Wrapper t-shirt + canvas */
.hfh-tshirt-wrapper {
    position: relative;
    width: 100%;
    max-width: 650px;
    aspect-ratio: 5 / 6;
    cursor: crosshair;
    background: #fff;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.05);
    overflow: hidden;
}

.hfh-real-tshirt-container {
    width: 100%;
    height: 100%;
    position: relative;
    transition: transform 0.2s ease-in-out;
    backface-visibility: hidden; /* Améliore la fluidité des rotations */
}

/* Couche 1: Le Mannequin */
.hfh-model-layer {
    position: absolute;
    inset: 0;
    background-image: url('../../images/model-homme.png'); /* Remontée au dossier racine */
    background-size: cover;
    background-repeat: no-repeat;
    background-position: center;
    z-index: 1;
}

.hfh-color-layer {
    position: absolute;
    inset: 0;
    z-index: 2;
    mix-blend-mode: multiply;
    opacity: 0.82; /* Réduit pour laisser respirer les plis de l'image source sur les couleurs sombres */
    
    /* Force l'utilisation de la luminosité pour les masques Noir & Blanc (Blanc=Couleur, Noir=Transparent) */
    mask-type: luminance; 
    -webkit-mask-source-type: luminance;
    mask-mode: luminance;

    /* Masquage : définit la zone où la couleur s'affiche */
    -webkit-mask-size: 100% 100%;
    mask-size: 100% 100%;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-position: center;
    mask-position: center;
    
    /* Masque par défaut (homme) */
    -webkit-mask-image: url('../../images/mask-homme.png');
    mask-image: url('../../images/mask-homme.png');
}

/* Overlay pour le réalisme (ombres et plis) */
.hfh-texture-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 3;
    display: none; /* Désactivation de la couche de texture car le fichier est manquant */
}

/* On applique le masque au conteneur Fabric pour couper le texte qui dépasse du t-shirt */
.canvas-container {
    -webkit-mask-size: cover;
    mask-size: cover;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-position: center;
    mask-position: center;
    -webkit-mask-source-type: luminance;
    mask-mode: luminance;
    overflow: hidden;
    pointer-events: auto; /* Rétablit la détection des clics sur la zone de design */
    position: absolute !important; /* Positionnement absolu pour couvrir le wrapper */
    top: 0;
    left: 0;
    z-index: 10; /* Place le design au dessus du t-shirt */
}

.canvas-container canvas {
    pointer-events: all;
}

.hfh-preview-actions {
    display: flex;
    gap: 8px;
}

.hfh-main-price-display {
    margin-top: 10px;
    background: var(--hfh-primary);
    color: #fff;
    padding: 12px 25px;
    border-radius: 50px;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 4px 15px rgba(25, 127, 141, 0.3);
}
.hfh-price-label { font-size: 0.9rem; opacity: 0.9; font-weight: 500; }
.hfh-price-val { font-size: 1.4rem; font-weight: 800; }

/* Sécurité supplémentaire : forcer le noir sur tous les textes informatifs */
.hfh-editor-wrap span, 
.hfh-editor-wrap b, 
.hfh-editor-wrap i,
.hfh-editor-wrap u,
.hfh-editor-wrap label,
.hfh-editor-wrap button,
.hfh-editor-wrap p {
    color: #2c3e50 !important;
}

/* ── Section commande ─────────────────────────────────────────────── */
.hfh-order-section {
    background: var(--hfh-card);
    border: 1px solid var(--hfh-border);
    border-radius: var(--hfh-radius);
    padding: 24px;
    margin: 0 16px 24px;
    box-shadow: var(--hfh-shadow);
}
.hfh-order-section h3 {
    font-size: 1.15rem;
    color: var(--hfh-primary);
    margin: 0 0 20px;
}

.hfh-form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 14px;
    margin-bottom: 14px;
}
.hfh-form-group { display: flex; flex-direction: column; gap: 4px; }
.hfh-form-group label { font-size: .85rem; font-weight: 600; color: #555; }

.hfh-textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--hfh-border);
    border-radius: 6px;
    font-size: .9rem;
    resize: vertical;
}

/* Récapitulatif */
.hfh-recap {
    background: var(--hfh-bg);
    border: 1px solid var(--hfh-border);
    border-radius: 8px;
    padding: 14px 18px;
    margin: 16px 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.hfh-recap-item {
    display: flex;
    justify-content: space-between;
    font-size: .9rem;
    align-items: center;
}
.hfh-recap-total { font-size: 1rem; color: var(--hfh-primary); }
.hfh-recap-color { display: flex; align-items: center; gap: 8px; }
.hfh-recap-swatch {
    display: inline-block;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 1px solid #ccc;
    background: #fff;
}

/* Notifications */
.hfh-notice {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: .9rem;
}
.hfh-notice.success { background: #e8f5e9; border: 1px solid #81c784; color: #2e7d32; }
.hfh-notice.error   { background: #ffebee; border: 1px solid #ef9a9a; color: #c62828; }

/* ── Sélecteur genre ──────────────────────────────────────────────── */
.hfh-gender-selector {
    display: flex;
    gap: 8px;
}

.hfh-gender-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 12px 10px;
    border: 2px solid var(--hfh-border);
    border-radius: 8px;
    background: var(--hfh-bg);
    cursor: pointer;
    font-size: .9rem;
    font-weight: 600;
    color: #555;
    transition: all .15s;
    line-height: 1;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}
.hfh-gender-btn svg { width: 32px; height: 32px; color: #888; transition: color .15s; }
.hfh-gender-btn:hover { border-color: var(--hfh-primary); color: var(--hfh-primary); transform: translateY(-2px); }
.hfh-gender-btn:hover svg { color: var(--hfh-primary); }
.hfh-gender-btn.active {
    border-color: var(--hfh-primary);
    background: var(--hfh-primary);
    color: #fff;
    box-shadow: 0 4px 10px rgba(25, 127, 141, 0.3);
}
.hfh-gender-btn.active svg { color: #fff; }

.hfh-gender-btn span { margin-top: 4px; }

/* ── Responsive ───────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .hfh-editor-body {
        flex-direction: column;
        padding: 0 8px 8px;
    }
    .hfh-tools-panel { width: 100%; }
    .hfh-tshirt-wrapper { max-width: 300px; }
    .hfh-order-section { margin: 0 8px 16px; }
}
