/**
 * WebMagnet Checkout Funnel — Frontend Styles
 * v1.0.0
 */

:root {
    --wmcf-color-brand: #1a1a1a;
    --wmcf-color-accent: #ff5722;
    --wmcf-color-bg: #ffffff;
    --wmcf-color-bg-soft: #f7f7f8;
    --wmcf-color-border: #e5e5e7;
    --wmcf-color-text: #1a1a1a;
    --wmcf-color-text-soft: #6b6b73;
    --wmcf-color-error: #d32f2f;
    --wmcf-color-success: #2e7d32;
    --wmcf-radius: 8px;
    --wmcf-radius-lg: 12px;
    --wmcf-shadow: 0 4px 20px rgba(0,0,0,0.08);
    --wmcf-shadow-lg: 0 12px 40px rgba(0,0,0,0.15);
    --wmcf-transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --wmcf-side-cart-width: 420px;
}

/* =========================================================
   PROGRESS BAR
   ========================================================= */
.wmcf-progress {
    /* ol semantic con reset visivo: il marker numerico verrebbe duplicato
     * con .wmcf-progress__num se non resettato. */
    list-style: none;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    margin: 0 0 32px;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}

/* screen-reader-text: classe WP standard per testo solo per AT (non visibile),
 * usata in render_progress_bar per "Step N di M" announcement. */
.screen-reader-text {
    border: 0;
    clip: rect(1px, 1px, 1px, 1px);
    -webkit-clip-path: inset(50%);
    clip-path: inset(50%);
    height: 1px;
    margin: -1px;
    overflow: hidden;
    padding: 0;
    position: absolute;
    width: 1px;
    word-wrap: normal !important;
}

.wmcf-progress__step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    transition: opacity var(--wmcf-transition);
    opacity: 0.4;
}

.wmcf-progress__step.is-active,
.wmcf-progress__step.is-complete {
    opacity: 1;
}

.wmcf-progress__num {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--wmcf-color-bg-soft);
    border: 2px solid var(--wmcf-color-border);
    color: var(--wmcf-color-text-soft);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
    transition: all var(--wmcf-transition);
}

.wmcf-progress__step.is-active .wmcf-progress__num {
    background: var(--wmcf-color-brand);
    border-color: var(--wmcf-color-brand);
    color: #fff;
}

.wmcf-progress__step.is-complete .wmcf-progress__num {
    background: var(--wmcf-color-success);
    border-color: var(--wmcf-color-success);
    color: #fff;
}

/* Step completato: il numero sparisce e appare un ✓ via ::after.
 * Il vecchio selettore `.wmcf-progress__num span` cercava uno <span> figlio
 * che non esiste (il numero "1" è text node DIRETTO dentro lo span esterno).
 * Risultato: numero e ✓ visibili insieme nel cerchio (es. "1✓").
 * Fix: nascondi il text node tramite font-size:0 + color:transparent
 * sul container, e usa font-size esplicito sul ::after per mostrare il ✓. */
.wmcf-progress__step.is-complete .wmcf-progress__num {
    font-size: 0;
    color: transparent;
}

.wmcf-progress__step.is-complete .wmcf-progress__num::after {
    content: '✓';
    font-size: 14px;
    color: #fff;
    line-height: 1;
}

.wmcf-progress__label {
    font-size: 12px;
    color: var(--wmcf-color-text-soft);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.wmcf-progress__step.is-active .wmcf-progress__label {
    color: var(--wmcf-color-brand);
}

.wmcf-progress__line {
    flex: 1;
    height: 2px;
    background: var(--wmcf-color-border);
    margin: 0 12px;
    margin-bottom: 24px;
    transition: background var(--wmcf-transition);
    min-width: 40px;
    max-width: 120px;
}

.wmcf-progress__line.is-complete {
    background: var(--wmcf-color-success);
}

/* =========================================================
   STEP EMAIL-FIRST
   ========================================================= */
.wmcf-step--email {
    max-width: 500px;
    margin: 0 auto 32px;
    padding: 32px;
    background: var(--wmcf-color-bg);
    border: 1px solid var(--wmcf-color-border);
    border-radius: var(--wmcf-radius-lg);
    box-shadow: var(--wmcf-shadow);
}

.wmcf-step.is-hidden {
    display: none;
}

.wmcf-step__header {
    text-align: center;
    margin-bottom: 24px;
}

/* Mini cart summary allo step email: l'utente vede subito quanti articoli
 * e quanto totale, anche se #order_review è nascosto. Display flex
 * justify-content space-between per layout pulito. Padding moderato
 * più border per delineare l'area come "non-form". */
.wmcf-step__cart-summary {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    margin: 0 0 20px;
    background: var(--wmcf-color-bg-soft, #f7f7f7);
    border: 1px solid var(--wmcf-color-border, #e0e0e0);
    border-radius: var(--wmcf-radius, 6px);
    font-size: 14px;
}

.wmcf-step__cart-summary-count {
    color: var(--wmcf-color-text-soft, #555);
}

.wmcf-step__cart-summary-total {
    font-weight: 700;
    color: var(--wmcf-color-text, #1a1a1a);
}

.wmcf-step__title {
    font-size: 24px;
    font-weight: 700;
    margin: 0 0 8px;
    color: var(--wmcf-color-text);
}

.wmcf-step__subtitle {
    font-size: 14px;
    color: var(--wmcf-color-text-soft);
    margin: 0;
    line-height: 1.5;
}

.wmcf-field {
    margin-bottom: 16px;
}

.wmcf-field label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--wmcf-color-text);
    margin-bottom: 6px;
}

.wmcf-field input[type="email"],
.wmcf-field input[type="text"] {
    width: 100%;
    padding: 12px 14px;
    border: 1.5px solid var(--wmcf-color-border);
    border-radius: var(--wmcf-radius);
    font-size: 16px;
    transition: border-color var(--wmcf-transition), box-shadow var(--wmcf-transition);
    background: #fff;
    box-sizing: border-box;
}

.wmcf-field input:focus {
    outline: none;
    border-color: var(--wmcf-color-brand);
    box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.08);
}

.wmcf-field input.is-error {
    border-color: var(--wmcf-color-error);
}

.wmcf-required {
    color: var(--wmcf-color-error);
    margin-left: 2px;
}

.wmcf-error {
    display: block;
    color: var(--wmcf-color-error);
    font-size: 13px;
    margin-top: 4px;
    min-height: 18px;
}

.wmcf-form-error {
    background: #fff1f0;
    border-left: 3px solid var(--wmcf-color-error);
    color: var(--wmcf-color-error);
    padding: 10px 14px;
    border-radius: var(--wmcf-radius);
    margin: 12px 0;
    font-size: 14px;
    font-weight: 500;
}

.wmcf-consent.is-error .wmcf-consent__label {
    color: var(--wmcf-color-error);
}

.wmcf-consent.is-error input[type="checkbox"] {
    outline: 2px solid var(--wmcf-color-error);
    outline-offset: 2px;
}

.wmcf-field-row {
    display: flex;
    gap: 12px;
}

.wmcf-field--half {
    flex: 1;
}

@media (max-width: 480px) {
    .wmcf-field-row {
        flex-direction: column;
        gap: 0;
    }
    .wmcf-step--email {
        padding: 20px;
    }
}

/* =========================================================
   CONSENT CHECKBOXES
   ========================================================= */
.wmcf-consents {
    margin: 16px 0;
    padding: 16px;
    background: var(--wmcf-color-bg-soft);
    border-radius: var(--wmcf-radius);
}

.wmcf-consent {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 10px;
    /* cursor:pointer rimosso dal wrapper: ora è un <div>, non più <label>.
       Il cursor:pointer è ora sul .wmcf-consent__label (l'elemento <label>)
       per non dare false affordance di click sui link interni. */
}

.wmcf-consent:last-child {
    margin-bottom: 0;
}

.wmcf-consent input[type="checkbox"] {
    margin-top: 2px;
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    accent-color: var(--wmcf-color-brand);
    cursor: pointer;
}

.wmcf-consent__label {
    font-size: 13px;
    line-height: 1.5;
    color: var(--wmcf-color-text);
    cursor: pointer;
}

/* Link DENTRO il testo del consenso: cursore link, NON pointer del label.
   Il click sul link deve navigare, non togglare il checkbox. */
.wmcf-consent__label a {
    cursor: pointer;
    text-decoration: underline;
}

/* =========================================================
   BUTTONS
   ========================================================= */
.wmcf-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 24px;
    border-radius: var(--wmcf-radius);
    font-size: 15px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    border: none;
    transition: all var(--wmcf-transition);
    line-height: 1;
    box-sizing: border-box;
}

.wmcf-btn--primary {
    background: var(--wmcf-color-brand);
    color: #fff;
}

.wmcf-btn--primary:hover {
    background: var(--wmcf-color-accent);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.wmcf-btn--ghost {
    background: transparent;
    color: var(--wmcf-color-text);
    border: 1.5px solid var(--wmcf-color-border);
}

.wmcf-btn--ghost:hover {
    border-color: var(--wmcf-color-brand);
}

.wmcf-btn--block {
    width: 100%;
}

.wmcf-btn:disabled,
.wmcf-btn.is-loading {
    opacity: 0.6;
    cursor: not-allowed;
    pointer-events: none;
}

.wmcf-btn__spinner {
    display: none;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: wmcf-spin 0.6s linear infinite;
}

.wmcf-btn.is-loading .wmcf-btn__spinner {
    display: inline-block;
}

@keyframes wmcf-spin {
    to { transform: rotate(360deg); }
}

.wmcf-step__actions {
    margin-top: 20px;
}

.wmcf-step__footer {
    text-align: center;
    margin-top: 16px;
    color: var(--wmcf-color-text-soft);
}

.wmcf-step-nav {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin: 24px 0;
    flex-wrap: wrap;
}

/* =========================================================
   MULTI-STEP: HIDE/SHOW SECTIONS
   ========================================================= */
body.wmcf-multistep-checkout.wmcf-step-email .woocommerce-checkout #customer_details,
body.wmcf-multistep-checkout.wmcf-step-email .woocommerce-checkout #order_review_heading,
body.wmcf-multistep-checkout.wmcf-step-email .woocommerce-checkout #order_review,
body.wmcf-multistep-checkout.wmcf-step-email .wmcf-step-nav--shipping,
/* Step email: nasconde solo coupon toggle e wmcf-step-nav payment.
 * IL LOGIN TOGGLE È INTENZIONALMENTE VISIBILE: utenti con account
 * esistente devono poter loggarsi PRIMA di compilare l'email guest.
 * Senza questo, scenario rotto:
 * - User apre /checkout/, vede solo email
 * - Vorrebbe loggarsi per usare card salvata, indirizzi, billing
 * - Toggle "Already a customer?" era nascosto
 * - Inserisce email come guest, prosegue
 * - Allo step 2 vede toggle login MA ormai è già nel guest flow
 * - Se logga ora, WC mergia cart ma email captured è diversa
 * Risultato: utenti registrati o si loggavano PRIMA di /checkout/
 * (richiede UX dedicata) o procedevano come guest perdendo auto-fill.
 * Tenere visibile il login toggle a step email risolve. */
body.wmcf-multistep-checkout.wmcf-step-email .wmcf-step-nav--payment,
body.wmcf-multistep-checkout.wmcf-step-email .woocommerce-form-coupon-toggle,
body.wmcf-multistep-checkout.wmcf-step-email .checkout_coupon {
    display: none !important;
}

body.wmcf-multistep-checkout.wmcf-step-shipping .wmcf-step--email {
    display: none !important;
}

body.wmcf-multistep-checkout.wmcf-step-shipping #order_review_heading,
body.wmcf-multistep-checkout.wmcf-step-shipping #order_review,
body.wmcf-multistep-checkout.wmcf-step-shipping .wmcf-step-nav--payment {
    display: none !important;
}

body.wmcf-multistep-checkout.wmcf-step-payment .wmcf-step--email,
body.wmcf-multistep-checkout.wmcf-step-payment #customer_details,
body.wmcf-multistep-checkout.wmcf-step-payment .wmcf-step-nav--shipping {
    display: none !important;
}

.wmcf-step-nav--payment {
    margin: 0 0 20px;
}

/* =========================================================
   SIDE CART
   ========================================================= */
.wmcf-side-cart {
    position: fixed;
    inset: 0;
    z-index: 99998;
    visibility: hidden;
    pointer-events: none;
}

.wmcf-side-cart.is-open {
    visibility: visible;
    pointer-events: auto;
}

.wmcf-side-cart__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    opacity: 0;
    transition: opacity var(--wmcf-transition);
}

.wmcf-side-cart.is-open .wmcf-side-cart__backdrop {
    opacity: 1;
}

.wmcf-side-cart__panel {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: var(--wmcf-side-cart-width);
    max-width: 100vw;
    background: #fff;
    box-shadow: var(--wmcf-shadow-lg);
    transform: translateX(100%);
    transition: transform var(--wmcf-transition);
    display: flex;
    flex-direction: column;
}

.wmcf-side-cart.is-open .wmcf-side-cart__panel {
    transform: translateX(0);
}

.wmcf-side-cart__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--wmcf-color-border);
    flex-shrink: 0;
}

.wmcf-side-cart__title {
    font-size: 18px;
    font-weight: 700;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.wmcf-side-cart__title .wmcf-cart-count {
    background: var(--wmcf-color-brand);
    color: #fff;
    font-size: 12px;
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: 600;
    min-width: 22px;
    text-align: center;
}

.wmcf-side-cart__close {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    display: flex;
    color: var(--wmcf-color-text);
    border-radius: var(--wmcf-radius);
    transition: background var(--wmcf-transition);
}

.wmcf-side-cart__close:hover {
    background: var(--wmcf-color-bg-soft);
}

.wmcf-side-cart__inner {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.wmcf-side-cart__items {
    flex: 1;
    overflow-y: auto;
    padding: 16px 24px;
}

.wmcf-side-cart__empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 24px;
    text-align: center;
    color: var(--wmcf-color-text-soft);
}

.wmcf-side-cart__empty p {
    margin-bottom: 16px;
}

/* CART ITEM */
.wmcf-cart-item {
    display: flex;
    gap: 12px;
    padding: 14px 0;
    border-bottom: 1px solid var(--wmcf-color-border);
    position: relative;
}

.wmcf-cart-item:last-child {
    border-bottom: none;
}

.wmcf-cart-item__thumb {
    flex-shrink: 0;
    width: 64px;
    height: 64px;
    border-radius: var(--wmcf-radius);
    overflow: hidden;
    background: var(--wmcf-color-bg-soft);
}

.wmcf-cart-item__thumb img,
.wmcf-cart-item__img {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover;
    display: block;
    margin: 0 !important;
    max-width: none !important;
}

.wmcf-cart-item__body {
    flex: 1;
    min-width: 0;
}

.wmcf-cart-item__name {
    font-size: 14px;
    font-weight: 600;
    margin: 0 0 4px;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-right: 24px;
}

.wmcf-cart-item__price {
    font-size: 14px;
    color: var(--wmcf-color-text-soft);
    margin-bottom: 6px;
}

.wmcf-cart-item__qty {
    display: inline-flex;
    align-items: center;
    border: 1px solid var(--wmcf-color-border);
    border-radius: var(--wmcf-radius);
    overflow: hidden;
}

.wmcf-qty-btn {
    background: none;
    border: none;
    width: 28px;
    height: 28px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    color: var(--wmcf-color-text);
    transition: background var(--wmcf-transition);
}

.wmcf-qty-btn:hover {
    background: var(--wmcf-color-bg-soft);
}

.wmcf-qty-input {
    width: 36px;
    height: 28px;
    border: none;
    border-left: 1px solid var(--wmcf-color-border);
    border-right: 1px solid var(--wmcf-color-border);
    text-align: center;
    font-size: 13px;
    -moz-appearance: textfield;
    appearance: textfield;
}

.wmcf-qty-input::-webkit-outer-spin-button,
.wmcf-qty-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.wmcf-cart-item__remove {
    position: absolute;
    top: 14px;
    right: 0;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--wmcf-color-text-soft);
    padding: 4px;
    transition: color var(--wmcf-transition);
}

.wmcf-cart-item__remove:hover {
    color: var(--wmcf-color-error);
}

.wmcf-side-cart__footer {
    padding: 16px 24px 24px;
    border-top: 1px solid var(--wmcf-color-border);
    background: #fff;
    flex-shrink: 0;
}

.wmcf-side-cart__subtotal {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    font-size: 16px;
}

.wmcf-side-cart__subtotal strong {
    font-size: 18px;
    color: var(--wmcf-color-brand);
}

/* =========================================================
   SIDE CART TRIGGER (floating button)
   ========================================================= */
.wmcf-side-cart-trigger {
    position: fixed;
    /* Safe-area-inset env: su iPhone X+ e Pro/Max successivi (~80% iOS attuale)
     * la home indicator riserva ~34px in basso. Su Android con gesture bar ~24px.
     * Senza safe-area, bottom:16px metteva il trigger DENTRO la home bar:
     * tappare ci sopra non apriva il cart, era interpretato come gesture home.
     * env() ritorna 0 su device senza safe-area → max() cade sul valore originale.
     * Richiede <meta name="viewport" content="... viewport-fit=cover"> per attivarsi
     * (aggiunto via wp_head filter in WMCF_Plugin se mancante). */
    bottom: max(24px, calc(24px + env(safe-area-inset-bottom)));
    right: max(24px, calc(24px + env(safe-area-inset-right)));
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--wmcf-color-brand);
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: var(--wmcf-shadow-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 99997;
    transition: transform var(--wmcf-transition);
}

.wmcf-side-cart-trigger:hover {
    transform: scale(1.05);
}

.wmcf-side-cart-trigger .wmcf-cart-count {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--wmcf-color-accent);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 12px;
    min-width: 20px;
    text-align: center;
    border: 2px solid #fff;
}

/* Hide del badge count quando 0: applicato a qualsiasi .wmcf-cart-count
 * (trigger button e header del side cart panel). Il badge "0" è rumore visivo:
 * lo nascondiamo come fa anche il WC default cart counter. */
.wmcf-cart-count[data-count="0"] {
    display: none;
}

@media (max-width: 480px) {
    .wmcf-side-cart-trigger {
        bottom: max(16px, calc(16px + env(safe-area-inset-bottom)));
        right: max(16px, calc(16px + env(safe-area-inset-right)));
    }
}

/* Posizionamento alternativo a sinistra per evitare collisione con
   chat widget (Tawk, Intercom, Crisp, Drift, Zendesk Chat, HubSpot Chat,
   ecc.) che tipicamente stanno in basso a destra. Override delle regole
   right: 24px / 16px con left: 24px / 16px e right: auto. */
body.wmcf-side-cart-position-left .wmcf-side-cart-trigger {
    right: auto;
    left: max(24px, calc(24px + env(safe-area-inset-left)));
}

@media (max-width: 480px) {
    body.wmcf-side-cart-position-left .wmcf-side-cart-trigger {
        left: max(16px, calc(16px + env(safe-area-inset-left)));
    }
}

body.wmcf-side-cart-open {
    overflow: hidden;
}

/* =========================================================
   ACCESSIBILITY (WCAG 2.1)
   ========================================================= */

/* prefers-reduced-motion: utenti con vestibolopatia, cinetosi o impostazioni
   OS che richiedono ridotto movimento. Disabilitiamo le animation più visibili
   (slide del side cart, hover transition dei bottoni). */
@media (prefers-reduced-motion: reduce) {
    .wmcf-side-cart__panel,
    .wmcf-side-cart__backdrop,
    .wmcf-progress__step,
    .wmcf-progress__line,
    .wmcf-btn,
    .wmcf-cart-item {
        transition: none !important;
        animation: none !important;
    }
}

/* :focus-visible — outline visibile SOLO su navigazione tastiera, non su click
   mouse. UX migliore di :focus che mostra outline anche su click (visivamente
   rumoroso). */
.wmcf-btn:focus-visible,
.wmcf-qty-btn:focus-visible,
.wmcf-cart-item__remove:focus-visible,
.wmcf-side-cart__close:focus-visible {
    outline: 2px solid var(--wmcf-color-brand);
    outline-offset: 2px;
}

/* =========================================================
   RECOVERY LANDING PAGE
   ========================================================= */
.wmcf-recovery-landing {
    max-width: 600px;
    margin: 60px auto;
    padding: 32px;
    text-align: center;
    color: var(--wmcf-color-text);
}

.wmcf-recovery-landing__title {
    margin-bottom: 16px;
    color: var(--wmcf-color-text);
}

.wmcf-recovery-landing__intro {
    font-size: 1.1em;
    margin-bottom: 24px;
}

.wmcf-recovery-landing__items {
    list-style: none;
    padding: 0;
    margin: 0 0 32px 0;
    text-align: left;
    border: 1px solid var(--wmcf-color-border);
    border-radius: 6px;
    overflow: hidden;
}

.wmcf-recovery-landing__item {
    padding: 12px 16px;
    border-bottom: 1px solid var(--wmcf-color-border);
}

.wmcf-recovery-landing__item:last-child {
    border-bottom: none;
}

.wmcf-recovery-landing__form {
    display: inline-block;
}

.wmcf-recovery-landing__cta {
    font-size: 1.1em;
    padding: 14px 32px;
}

.wmcf-recovery-landing__alt {
    margin-top: 24px;
    font-size: 0.9em;
    color: var(--wmcf-color-text-soft);
}

.wmcf-recovery-landing__alt a {
    color: var(--wmcf-color-text-soft);
    text-decoration: underline;
}

.wmcf-recovery-landing__alt a:hover {
    color: var(--wmcf-color-brand);
}
