#derf-sticky-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background-color: #fcf5f6;
    border-top: 2px solid #eac271;
    box-shadow: 0 -5px 20px rgba(0,0,0,0.1);
    z-index: 9990 !important; /* Priorité haute mais laisse passer les modales/CMP (souvent > 10000) */
    transform: translateY(120%);
    transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1), opacity 0.3s ease;
    opacity: 0;
    pointer-events: none;
    /* Sécurité pour les nouveaux iPhone (encoche du bas) */
    padding-bottom: env(safe-area-inset-bottom);
}

#derf-sticky-bar.derf-sticky-visible {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
}

.derf-sticky-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 15px;
    max-width: 1200px;
    margin: 0 auto;
}

.derf-sticky-img {
    width: 45px;
    height: 45px;
    object-fit: contain;
    border-radius: 6px;
    border: 1px solid #eaddde;
    background: #fff;
    display: none;
}

.derf-sticky-info {
    flex-grow: 1;
    padding: 0 10px 0 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-width: 0;
}

.derf-sticky-title {
    font-family: 'Nunito', sans-serif;
    font-size: 0.85rem;
    font-weight: 700;
    color: #333;
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.derf-sticky-formats {
    display: none;
    gap: 8px;
    margin-top: 2px;
}

.derf-format-link {
    font-family: 'Nunito', sans-serif;
    font-size: 11px;
    font-weight: bold;
    color: #eac271;
    background-color: #333;
    padding: 2px 8px;
    border-radius: 4px;
    text-decoration: none;
}

.derf-format-link:hover {
    background-color: #7a1f28;
    color: #fff;
}

.derf-sticky-pricing {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-top: 2px;
}

.derf-sticky-price {
    font-family: 'Nunito', sans-serif;
    font-size: 1rem;
    color: #7a1f28;
    font-weight: 800;
}

/* La Pilule Dorée (Smart Buy) */
.derf-sticky-smartbuy {
    font-family: 'Caveat', cursive;
    font-size: 0.95rem;
    color: #7a1f28;
    background-color: #eac271;
    padding: 2px 12px;
    border-radius: 12px;
    white-space: nowrap;
    display: inline-block;
    margin-left: 8px;
    box-shadow: 2px 2px 5px rgba(0,0,0,0.05);
}

/* =========================================================
   ZONE D'ACTION : BOUTONS ET QUANTITÉ (Alignement strict)
   ========================================================= */

/* Le conteneur global */
.derf-input-group-custom {
    display: flex;
    align-items: stretch; /* FORCE tous les éléments à avoir la même hauteur sans traits blancs */
    border: 1px solid #1e5d52;
    border-radius: 25px;
    overflow: hidden;
    background: #fff;
    height: 38px;
    box-sizing: border-box;
}

/* Base commune pour tous les boutons du groupe */
.derf-qty-btn,
.derf-btn-terroir {
    display: flex !important;
    align-items: center !important; /* Centrage vertical absolu */
    justify-content: center !important; /* Centrage horizontal absolu */
    height: auto !important; /* On laisse le conteneur gérer la hauteur */
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    line-height: 1 !important; /* Sécurité anti-décalage iOS */
}

/* Les boutons + et - spécifiques */
.derf-qty-btn {
    background-color: #fcf5f6;
    color: #1e5d52;
    width: 32px;
    font-size: 1.2rem;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.2s;
}

.derf-qty-btn:active {
    background-color: #eaddde;
}

/* Le champ de quantité au milieu */
.derf-qty-input {
    width: 35px;
    height: auto !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none;
    border-left: 1px solid #eaeaea;
    border-right: 1px solid #eaeaea;
    text-align: center;
    font-weight: bold;
    color: #333;
    /* Sur un input, la line-height est le meilleur moyen de centrer verticalement */
    line-height: 36px !important; 
    -moz-appearance: textfield;
}

.derf-qty-input::-webkit-outer-spin-button,
.derf-qty-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* Le bouton Ajouter spécifique */
.derf-btn-terroir {
    background-color: #1e5d52 !important;
    color: #fff !important;
    padding: 0 20px !important; /* On remet l'espace horizontal */
    font-weight: 800 !important;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-radius: 0 !important;
    transition: background-color 0.2s;
}

.derf-btn-terroir:hover {
    background-color: #15453d !important;
}


/* Autres styles (Bouton Vineux, Animations) */

.derf-btn-vineux {
    background-color: #7a1f28 !important;
    color: #ffffff !important;
    border: none !important;
    border-radius: 50px !important;
    font-family: 'Nunito', sans-serif;
    font-weight: 800 !important;
    font-size: 0.9rem !important;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 12px 25px !important;
    box-shadow: 0 4px 15px rgba(122, 31, 40, 0.3) !important;
    transition: all 0.2s ease !important;
    margin: 0 !important;
    white-space: nowrap;
}

.derf-btn-vineux:active {
    transform: scale(0.95) !important;
}

/* Animation de pulsation */
@keyframes derf-pulse {
    0% { transform: scale(1); background-color: #1e5d52; }
    50% { transform: scale(0.97); background-color: #eac271; color: #7a1f28 !important; }
    100% { transform: scale(1); background-color: #1e5d52; }
}

.derf-btn-adding {
    animation: derf-pulse 0.7s infinite ease-in-out !important;
    pointer-events: none;
}


/* =========================================
   MEDIA QUERIES (Mobile et Desktop)
   ========================================= */

/* Mobile */
@media (max-width: 575px) {
    .derf-sticky-container {
        padding: 8px 10px;
    }
    
    .derf-sticky-info {
        padding-right: 5px;
    }

    .derf-sticky-title {
        font-size: 0.8rem;
        max-width: 140px; 
    }
    
    .derf-sticky-smartbuy { 
        font-size: 0.75rem; 
        padding: 1px 6px; 
        margin-left: 4px;
    }

    /* Le groupe entier s'adapte */
    .derf-input-group-custom {
        display: flex !important;
        align-items: stretch !important; /* Maintient la règle de stretch */
        justify-content: space-between !important;
    }

    /* Input ajusté */
    .derf-qty-input {
        width: 30px !important;
    }

    /* Bouton centré et compacté */
    .derf-btn-terroir { 
        padding: 0 10px !important; 
        font-size: 0.8rem !important; 
        /* Plus besoin de toucher au line-height ici, géré en haut */
    }
/* 1. Protéger le bloc d'action (Il ne doit jamais rétrécir ou se faire écraser) */
    .derf-sticky-action {
        flex-shrink: 0;
        margin-left: 10px; /* Force un espace de respiration avec le texte */
    }

    /* 2. Empiler le prix et la pilule sur mobile pour libérer l'espace horizontal */
    .derf-sticky-pricing {
        flex-direction: column;
        align-items: flex-start;
        gap: 2px;
        margin-top: 2px;
    }

    .derf-sticky-price {
        font-size: 1.05rem !important;
        line-height: 1;
    }

    /* 3. Ajuster la pilule puisqu'elle passe en dessous */
    .derf-sticky-smartbuy { 
        font-size: 0.75rem !important; 
        padding: 2px 8px !important; 
        margin-left: 0 !important; /* Annule la marge gauche desktop */
        margin-top: 2px;
    }

    /* 4. Optimisation millimétrée des boutons +/- pour les très petits écrans */
    .derf-qty-btn {
        width: 28px !important; /* On gagne 8px précieux au total */
        font-size: 1.1rem !important;
    }    
}

/* Desktop */
@media (min-width: 992px) {
    #derf-sticky-bar {
        left: 50%;
        width: 100%;
        max-width: 800px;
        border-radius: 15px 15px 0 0;
        border-left: 2px solid #eac271;
        border-right: 2px solid #eac271;
        transform: translateX(-50%) translateY(120%);
    }

    #derf-sticky-bar.derf-sticky-visible {
        transform: translateX(-50%) translateY(0);
    }

    .derf-sticky-container {
        padding: 12px 25px;
        padding-bottom: 12px;
    }

    .derf-sticky-img, .derf-sticky-formats {
        display: flex;
    }

    .derf-sticky-info {
        padding: 0 20px;
    }

    .derf-sticky-title {
        max-width: 450px;
        font-size: 1rem;
    }

    .derf-sticky-price { font-size: 1.2rem; }
    .derf-sticky-smartbuy { font-size: 1rem; }

    .derf-btn-vineux:hover {
        background-color: #eac271 !important;
        color: #7a1f28 !important;
        transform: translateY(-3px) !important;
        box-shadow: 0 8px 20px rgba(234, 194, 113, 0.4) !important;
        cursor: pointer;
    }
}