/* ==========================================================================
   Cart Drawer Modale - MiDifendo
   Side-drawer slide-in da destra (desktop), full-screen su mobile.
   Si apre automaticamente dopo "Aggiungi al carrello".
   ========================================================================== */

#md-cart-drawer-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 99998;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0s linear 0.25s;
}
#md-cart-drawer-overlay.is-open {
    opacity: 1;
    visibility: visible;
    transition: opacity 0.25s ease, visibility 0s linear 0s;
}

#md-cart-drawer {
    position: fixed;
    top: 0; right: 0;
    bottom: 0;
    width: 440px;
    max-width: 100%;
    background: #ffffff;
    z-index: 99999;
    box-shadow: -2px 0 20px rgba(0, 0, 0, 0.15);
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    font-family: 'proxima_nova_rgregular', Arial, sans-serif;
}
#md-cart-drawer.is-open {
    transform: translateX(0);
}

/* Header */
.md-cart-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 22px;
    border-bottom: 1px solid #ececec;
    flex-shrink: 0;
}
.md-cart-drawer-header h3 {
    margin: 0;
    font-size: 22px;
    font-weight: 700;
    color: #223E52;
    line-height: 1.2;
}
.md-cart-drawer-close {
    background: none;
    border: 1px solid #cccccc;
    width: 36px; height: 36px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, border-color 0.15s ease;
    padding: 0;
}
.md-cart-drawer-close:hover { background: #f5f5f5; border-color: #999; }
.md-cart-drawer-close svg { width: 18px; height: 18px; }

/* USP banner */
.md-cart-drawer-usps {
    padding: 12px 22px;
    border-bottom: 1px solid #ececec;
    flex-shrink: 0;
}
.md-cart-drawer-usp {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: #444;
    line-height: 1.4;
    padding: 4px 0;
}
.md-cart-drawer-usp svg { flex-shrink: 0; color: #FF8800; width: 18px; height: 18px; }
.md-cart-drawer-usp strong { color: #223E52; font-weight: 600; }

/* Free shipping progress */
.md-shipping-progress {
    padding: 10px 22px 14px;
    background: #FFF8F0;
    border-bottom: 1px solid #ececec;
    flex-shrink: 0;
}
.md-shipping-progress-text {
    font-size: 13px;
    color: #555;
    margin-bottom: 6px;
}
.md-shipping-progress-text strong { color: #FF8800; }
.md-shipping-progress-bar {
    height: 6px;
    background: #ececec;
    border-radius: 3px;
    overflow: hidden;
}
.md-shipping-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #FF8800, #FFA84A);
    transition: width 0.4s ease;
}

/* Body scrollable */
.md-cart-drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px 22px;
}

/* Empty state */
.md-cart-empty {
    text-align: center;
    padding: 40px 20px;
    color: #888;
}
.md-cart-empty svg { width: 64px; height: 64px; opacity: 0.3; margin-bottom: 16px; }

/* Cart item */
.md-cart-item {
    display: flex;
    gap: 14px;
    padding: 14px 0;
    border-bottom: 1px solid #f0f0f0;
}
.md-cart-item:last-child { border-bottom: 0; }
.md-cart-item-thumb {
    width: 80px; height: 80px;
    flex-shrink: 0;
    background: #f8f8f8;
    border-radius: 4px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}
.md-cart-item-thumb img { width: 100%; height: 100%; object-fit: cover; }
.md-cart-item-info { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: space-between; }
.md-cart-item-titolo {
    font-size: 14px;
    font-weight: 600;
    color: #223E52;
    line-height: 1.3;
    margin: 0 0 4px;
    text-decoration: none;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.md-cart-item-titolo:hover { color: #FF8800; text-decoration: none; }
.md-cart-item-variante {
    font-size: 12px;
    color: #666;
    margin: 0 0 6px;
}
.md-cart-item-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.md-cart-item-qty {
    display: flex;
    align-items: center;
    border: 1px solid #ddd;
    border-radius: 4px;
    overflow: hidden;
}
.md-cart-item-qty button {
    background: #fafafa;
    border: 0;
    width: 26px; height: 26px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    color: #444;
    padding: 0;
}
.md-cart-item-qty button:hover { background: #ececec; }
.md-cart-item-qty span {
    padding: 0 10px;
    font-size: 13px;
    min-width: 28px;
    text-align: center;
}
.md-cart-item-prezzo {
    font-size: 14px;
    font-weight: 700;
    color: #223E52;
}
.md-cart-item-remove {
    background: none;
    border: 0;
    cursor: pointer;
    color: #999;
    padding: 4px;
    margin-left: 8px;
    border-radius: 3px;
}
.md-cart-item-remove:hover { color: #d33; background: #fff0f0; }
.md-cart-item-remove svg { width: 16px; height: 16px; }

.md-cart-item.md-cart-item-virtual {
    background: #FFF8E1;
    margin: 8px -22px;
    padding: 10px 22px;
    border-radius: 0;
}
.md-cart-item.md-cart-item-virtual .md-cart-item-thumb { display: none; }
.md-cart-item.md-cart-item-virtual .md-cart-item-titolo { color: #FF8800; }
.md-cart-item.md-cart-item-virtual .md-cart-item-prezzo { color: #d35400; }

/* Cross-sell */
.md-cross-sell {
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid #ececec;
}
.md-cross-sell h4 {
    font-size: 16px;
    font-weight: 700;
    color: #223E52;
    margin: 0 0 14px;
}
.md-cross-sell-grid {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding-bottom: 6px;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
}
.md-cross-sell-grid::-webkit-scrollbar { height: 6px; }
.md-cross-sell-grid::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }
.md-cross-sell-card {
    flex: 0 0 140px;
    border: 1px solid #ececec;
    border-radius: 6px;
    padding: 10px;
    text-decoration: none !important;
    color: #223E52;
    transition: border-color 0.15s ease, transform 0.15s ease;
    scroll-snap-align: start;
    background: #fff;
}
.md-cross-sell-card:hover {
    border-color: #FF8800;
    transform: translateY(-2px);
    color: #223E52;
}
.md-cross-sell-card img {
    width: 100%;
    height: 110px;
    object-fit: cover;
    border-radius: 4px;
    margin-bottom: 8px;
}
.md-cross-sell-titolo {
    font-size: 12px;
    font-weight: 600;
    line-height: 1.3;
    margin: 0 0 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: 30px;
}
.md-cross-sell-prezzo {
    font-size: 14px;
    font-weight: 700;
    color: #FF8800;
}

/* Footer (sticky bottom con CTA) */
.md-cart-drawer-footer {
    padding: 18px 22px;
    border-top: 1px solid #ececec;
    background: #fafafa;
    flex-shrink: 0;
}
.md-cart-totale {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 12px;
}
.md-cart-totale-label {
    font-size: 14px;
    color: #666;
}
.md-cart-totale-valore {
    font-size: 22px;
    font-weight: 800;
    color: #223E52;
}
.md-cart-cta-row {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.md-cart-cta-primary, .md-cart-cta-secondary {
    display: block;
    width: 100%;
    padding: 14px 18px;
    text-align: center;
    text-decoration: none;
    font-weight: 700;
    font-size: 15px;
    border-radius: 4px;
    border: 0;
    cursor: pointer;
    line-height: 1.2;
    font-family: inherit;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    transition: background 0.15s ease;
}
.md-cart-cta-primary {
    background: #FF8800;
    color: #ffffff !important;
}
.md-cart-cta-primary:hover { background: #e57b00; color: #ffffff !important; text-decoration: none; }
.md-cart-cta-secondary {
    background: #ffffff;
    color: #223E52 !important;
    border: 2px solid #223E52;
}
.md-cart-cta-secondary:hover { background: #223E52; color: #ffffff !important; text-decoration: none; }

/* Responsive: full-screen su mobile */
@media (max-width: 600px) {
    #md-cart-drawer {
        width: 100%;
        height: 100%;
        max-width: 100%;
    }
    .md-cart-drawer-header h3 { font-size: 19px; }
    .md-cart-item-thumb { width: 64px; height: 64px; }
    .md-cross-sell-card { flex-basis: 130px; }
    .md-cart-drawer-footer { padding: 14px 16px; }
    .md-cart-drawer-body { padding: 12px 16px; }
    .md-cart-drawer-header { padding: 14px 16px; }
    .md-cart-drawer-usps { padding: 10px 16px; }
}

/* Loading state */
.md-cart-drawer-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    color: #888;
}
.md-cart-drawer-loading svg {
    width: 32px; height: 32px;
    animation: md-spin 1s linear infinite;
}
@keyframes md-spin { to { transform: rotate(360deg); } }

/* Hide body scroll when drawer open */
body.md-cart-drawer-open { overflow: hidden; }

/* ==========================================================================
   WhatsApp Floating Button — Bottone flottante in basso a destra su tutte le pagine
   Si nasconde quando il menu mobile e' aperto (body.md-mobile-menu-open)
   o quando il drawer e' aperto.
   ========================================================================== */

#md-whatsapp-fab {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 9990;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #25D366;
    box-shadow: 0 4px 14px rgba(37, 211, 102, 0.5), 0 2px 6px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}
#md-whatsapp-fab:hover {
    transform: scale(1.06);
    box-shadow: 0 6px 18px rgba(37, 211, 102, 0.6), 0 3px 8px rgba(0, 0, 0, 0.2);
}
#md-whatsapp-fab svg { width: 30px; height: 30px; fill: #ffffff; }

/* Tooltip su desktop al hover */
#md-whatsapp-fab::before {
    content: 'Scrivici su WhatsApp';
    position: absolute;
    right: calc(100% + 12px);
    top: 50%;
    transform: translateY(-50%);
    background: #223E52;
    color: #fff;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    font-family: Arial, sans-serif;
}
#md-whatsapp-fab:hover::before { opacity: 1; }

/* Hide WhatsApp button + altri widget flottanti quando menu mobile o drawer e' aperto */
body.md-mobile-menu-open #md-whatsapp-fab,
body.md-cart-drawer-open #md-whatsapp-fab {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

/* Nascondi widget mobile della scheda prodotto e altre barre sticky quando menu mobile aperto.
   .acquista-mobile e' la classe del widget MiDifendo (riga prodotto + bottone acquista in basso). */
body.md-mobile-menu-open .acquista-mobile,
body.md-mobile-menu-open .product-fixed-action,
body.md-mobile-menu-open .product-action-fixed,
body.md-mobile-menu-open .product-mobile-add,
body.md-mobile-menu-open .product-fixed-cart,
body.md-mobile-menu-open .add-to-cart-fixed,
body.md-mobile-menu-open .sticky-toolbox,
body.md-mobile-menu-open .pdp-sticky-bar,
body.md-mobile-menu-open .scopri-orange.sticky-mobile {
    display: none !important;
}

/* Su mobile il bottone WhatsApp leggermente piu' piccolo per non occupare troppo */
@media (max-width: 600px) {
    #md-whatsapp-fab { right: 14px; bottom: 14px; width: 50px; height: 50px; }
    #md-whatsapp-fab svg { width: 26px; height: 26px; }
    #md-whatsapp-fab::before { display: none; }
}

/* Quando la pagina ha il widget acquista-mobile (scheda prodotto su mobile),
   sposta il bottone WhatsApp piu' in alto per non sovrastarlo. */
@media (max-width: 767px) {
    body.md-has-acquista-mobile #md-whatsapp-fab {
        bottom: 110px;
    }
}
