/**
 * WeRoad Newsletter Modal US — blog "Stories"
 *
 * Tutto scoped sotto `.wr-nl`. Nessuna utility Tailwind: il bundle del tema è compilato in
 * purge mode e non conosce le classi dei file aggiunti dopo il build, quindi le utility
 * nuove non esisterebbero (vedi docs/wordpress-blog-infra.md §10a).
 *
 * Mobile: bottom sheet ancorato in basso. Desktop (>= 768px): modale centrata.
 */

/* Il tema ha un CSS globale che non controlliamo: fissiamo il box model dentro il
   componente invece di dipendere dai default della pagina. Senza questo un <a> con
   width:100% e padding sfonda il contenitore (il <button> no, perché gli UA stylesheet
   gli danno già border-box). */
.wr-nl,
.wr-nl *,
.wr-nl *::before,
.wr-nl *::after,
.wr-nl-toast {
    box-sizing: border-box;
}

.wr-nl {
    --wr-nl-surface: #ffffff;
    --wr-nl-text: #1a1a1a;
    --wr-nl-text-toned: #55595f;
    --wr-nl-text-dimmed: #7b7f86;
    --wr-nl-border: #d7dade;
    --wr-nl-border-focus: #9aa0a6;
    --wr-nl-error: #d13438;
    --wr-nl-success: #0f9d58;
    --wr-nl-cta-bg: #1a1a1a;
    --wr-nl-cta-text: #ffffff;

    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    font-family: inherit;
}

.wr-nl[hidden] {
    display: none;
}

.wr-nl__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    opacity: 0;
    transition: opacity 0.25s ease;
}

.wr-nl.is-open .wr-nl__backdrop {
    opacity: 1;
}

.wr-nl__dialog {
    position: relative;
    width: 100%;
    max-width: 26rem;
    max-height: 92vh;
    overflow-x: hidden;
    overflow-y: auto;
    background: var(--wr-nl-surface);
    color: var(--wr-nl-text);
    border-radius: 0.875rem 0.875rem 0 0;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.18);
    transform: translateY(100%);
    transition: transform 0.25s ease;
}

.wr-nl.is-open .wr-nl__dialog {
    transform: translateY(0);
}

/* ── Testata ─────────────────────────────────────────────────────────── */

.wr-nl__head {
    display: flex;
    justify-content: flex-end;
    padding: 0.75rem 1rem 0;
}

.wr-nl__close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    padding: 0;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--wr-nl-text-toned);
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.wr-nl__close:hover {
    background: rgba(0, 0, 0, 0.06);
}

.wr-nl__close:focus-visible,
.wr-nl__input:focus-visible,
.wr-nl__cta:focus-visible,
.wr-nl__legal a:focus-visible {
    outline: 2px solid var(--wr-nl-cta-bg);
    outline-offset: 2px;
}

/* ── Contenuto ───────────────────────────────────────────────────────── */

.wr-nl__intro {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.25rem;
    padding: 0 1.25rem 0.5rem;
}

.wr-nl__illustration {
    width: 6rem;
    height: 6rem;
    display: block;
}

.wr-nl__copy {
    text-align: center;
}

/* wpautop non tocca questo markup (non è un campo ACF), ma i margini dei <p> del tema sì:
   li azzeriamo esplicitamente per non dipendere dal CSS globale. */
.wr-nl__copy p {
    margin: 0;
}

.wr-nl__title {
    margin: 0 0 0.5rem;
    font-size: 1.5rem;
    line-height: 1.25;
    font-weight: 600;
    color: var(--wr-nl-text);
}

.wr-nl__subtitle {
    margin: 0 0 0.5rem;
    font-size: 1rem;
    line-height: 1.4;
    font-weight: 500;
    color: var(--wr-nl-text);
}

.wr-nl__note {
    font-size: 0.875rem;
    line-height: 1.4;
    color: var(--wr-nl-text-toned);
}

/* ── Form ────────────────────────────────────────────────────────────── */

.wr-nl__form,
.wr-nl__existing {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 1rem 1.25rem 1.5rem;
}

.wr-nl__form[hidden],
.wr-nl__existing[hidden],
.wr-nl__alert[hidden] {
    display: none;
}

.wr-nl__input {
    width: 100%;
    height: 2.75rem;
    padding: 0 1rem;
    font-size: 1rem;
    font-family: inherit;
    color: var(--wr-nl-text);
    background: var(--wr-nl-surface);
    border: 1px solid var(--wr-nl-border);
    border-radius: 0.375rem;
    box-sizing: border-box;
}

.wr-nl__input::placeholder {
    color: var(--wr-nl-text-dimmed);
}

.wr-nl__input:focus {
    border-color: var(--wr-nl-border-focus);
    outline: none;
}

.wr-nl__input[aria-invalid='true'] {
    border-color: var(--wr-nl-error);
}

.wr-nl__cta {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 2.75rem;
    padding: 0 1rem;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 600;
    color: var(--wr-nl-cta-text);
    background: var(--wr-nl-cta-bg);
    border: 0;
    border-radius: 0.375rem;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
    transition: opacity 0.15s ease;
}

.wr-nl__cta.is-disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.wr-nl__cta.is-loading .wr-nl__cta-label {
    opacity: 0;
}

.wr-nl__spinner {
    position: absolute;
    width: 1.25rem;
    height: 1.25rem;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-top-color: var(--wr-nl-cta-text);
    border-radius: 999px;
    opacity: 0;
}

.wr-nl__cta.is-loading .wr-nl__spinner {
    opacity: 1;
    animation: wr-nl-spin 0.7s linear infinite;
}

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

.wr-nl__legal {
    margin: 0;
    font-size: 0.75rem;
    line-height: 1.45;
    text-align: center;
    color: var(--wr-nl-text-dimmed);
}

.wr-nl__legal a {
    color: inherit;
    text-decoration: underline;
}

.wr-nl__alert {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    text-align: center;
    color: var(--wr-nl-error);
    background: rgba(209, 52, 56, 0.1);
    border-radius: 0.5rem;
}

/* ── Ramo "email già registrata" ─────────────────────────────────────── */

.wr-nl__existing {
    text-align: center;
}

.wr-nl__existing p {
    margin: 0;
}

.wr-nl__existing-title {
    font-size: 1rem;
    font-weight: 600;
}

.wr-nl__existing-note {
    font-size: 0.875rem;
    color: var(--wr-nl-text-toned);
}

/* ── Toast di conferma ───────────────────────────────────────────────── */

.wr-nl-toast {
    position: fixed;
    left: 50%;
    bottom: 1.25rem;
    z-index: 10000;
    max-width: calc(100vw - 2rem);
    padding: 0.75rem 1.25rem;
    font-family: inherit;
    font-size: 0.9375rem;
    font-weight: 500;
    color: #ffffff;
    background: var(--wr-nl-success, #0f9d58);
    border-radius: 0.5rem;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    transform: translate(-50%, 1rem);
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.wr-nl-toast.is-visible {
    opacity: 1;
    transform: translate(-50%, 0);
}

/* ── Blocco dello scroll, come fa la modale del sito ─────────────────── */

html.wr-nl-scroll-lock,
html.wr-nl-scroll-lock body {
    overflow: hidden;
}

/* ── Desktop: modale centrata ────────────────────────────────────────── */

@media (min-width: 768px) {
    .wr-nl {
        align-items: center;
        padding: 1.5rem;
    }

    .wr-nl__dialog {
        border-radius: 0.875rem;
        box-shadow: 0 12px 40px rgba(0, 0, 0, 0.22);
        transform: translateY(1rem) scale(0.98);
        opacity: 0;
        transition: transform 0.2s ease, opacity 0.2s ease;
    }

    .wr-nl.is-open .wr-nl__dialog {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

/* ── Rispetto delle preferenze di movimento ──────────────────────────── */

@media (prefers-reduced-motion: reduce) {
    .wr-nl__backdrop,
    .wr-nl__dialog,
    .wr-nl-toast {
        transition: none;
    }

    .wr-nl__cta.is-loading .wr-nl__spinner {
        animation-duration: 2s;
    }
}
