/**
 * Get a quote modal.
 *
 * Loaded on every page but only rendered by layouts.partials.quote-modal.
 * Every rule is namespaced under `.qm` so nothing here can restyle an
 * existing component, and the shell stays `visibility: hidden` until opened.
 */

/* ------------------------------------------------------------------- Shell */

.qm {
    position: fixed;
    inset: 0;
    /* Above the mobile drawer (300) so a quote can be raised from it. */
    z-index: 350;
    display: grid;
    place-items: center;
    padding: clamp(0.75rem, 3vw, 2rem);
    visibility: hidden;
    pointer-events: none;
}

.qm.is-open {
    visibility: visible;
    pointer-events: auto;
}

.qm__scrim {
    position: absolute;
    inset: 0;
    background: rgba(4, 26, 47, 0.6);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
    opacity: 0;
    transition: opacity var(--t-base) var(--ease);
}

.qm.is-open .qm__scrim {
    opacity: 1;
}

.qm__dialog {
    position: relative;
    display: grid;
    /* Head and foot stay pinned; only the body scrolls. */
    grid-template-rows: auto minmax(0, 1fr) auto;
    width: min(48rem, 100%);
    max-height: min(92vh, 58rem);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--r-xl);
    box-shadow:
        0 44px 100px -34px rgba(4, 26, 47, 0.6),
        0 2px 6px -2px rgba(4, 26, 47, 0.18);
    overflow: hidden;
    opacity: 0;
    transform: translateY(22px) scale(0.985);
    transition: opacity var(--t-base) var(--ease), transform var(--t-slow) var(--ease);
}

.qm.is-open .qm__dialog {
    opacity: 1;
    transform: none;
}

/* -------------------------------------------------------------------- Head */

.qm__head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    padding: clamp(1.1rem, 2.4vw, 1.6rem) clamp(1.15rem, 2.6vw, 2rem);
    border-bottom: 1px solid var(--border);
    background: linear-gradient(180deg, var(--bg-tint), var(--bg));
    transition: box-shadow var(--t-base) var(--ease);
}

/* Set by the script once the body has scrolled, so the head reads as pinned. */
.qm__head.is-stuck {
    box-shadow: 0 12px 24px -18px rgba(4, 26, 47, 0.55);
}

.qm__headtext {
    display: grid;
    gap: 0.4rem;
    min-width: 0;
}

.qm__eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    justify-self: start;
    padding: 0.28rem 0.7rem;
    border-radius: var(--r-pill);
    background: var(--brand-100);
    color: var(--brand-700);
    font-size: 0.7rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.qm__eyebrow i {
    font-size: 0.9rem;
}

.qm__title {
    margin: 0;
    font-size: var(--fs-h3);
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.qm__sub {
    margin: 0;
    max-width: 44ch;
    font-size: 0.9rem;
    line-height: 1.55;
    color: var(--text-soft);
}

.qm__close {
    flex: none;
    width: 2.5rem;
    height: 2.5rem;
}

/* -------------------------------------------------------------------- Body */

.qm__body {
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: clamp(1.15rem, 2.6vw, 1.75rem);
}

.qm__view[hidden] {
    display: none;
}

/* Reassurance strip, so the visitor knows what happens after submitting. */
.qm__trust {
    display: grid;
    gap: 0.6rem;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 12.5rem), 1fr));
    margin: 0;
    padding: 0.9rem 1rem;
    list-style: none;
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    background: var(--bg-soft);
}

.qm__trust li {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-soft);
}

.qm__trust i {
    flex: none;
    font-size: 1.1rem;
    color: var(--brand-600);
}

/* ------------------------------------------------------------------ Alerts */

.qm__alert {
    display: flex;
    align-items: flex-start;
    gap: 0.65rem;
    padding: 0.85rem 1rem;
    border: 1px solid;
    border-radius: var(--r-sm);
    font-size: 0.87rem;
    line-height: 1.5;
}

.qm__alert[hidden] {
    display: none;
}

.qm__alert i {
    flex: none;
    margin-top: 0.1rem;
    font-size: 1.1rem;
}

.qm__alert--error {
    background: rgba(244, 63, 94, 0.06);
    border-color: rgba(244, 63, 94, 0.3);
    color: #9F1239;
}

.qm__alert--info {
    background: var(--brand-100);
    border-color: rgba(13, 59, 102, 0.18);
    color: var(--brand-700);
}

/* ------------------------------------------------------------------- Form */

.qm__legend {
    padding: 0;
    font-size: 0.86rem;
    font-weight: 700;
}

.qm__legend span {
    color: var(--accent-600);
}

.qm__legend-row {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.5rem 0.75rem;
}

.qm__count {
    font-size: 0.74rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--text-muted);
}

.qm__count.is-warn {
    color: var(--accent-600);
}

/* The textarea sits inside .qm, so scope the shared min-height down a little. */
.qm textarea.field__control {
    min-height: 7rem;
}

/* --------------------------------------------------------------- Done view */

.qm__done {
    display: grid;
    gap: 1.1rem;
    justify-items: center;
    text-align: center;
    padding: clamp(1.5rem, 4vw, 2.5rem) 0.5rem;
}

.qm__done-badge {
    display: grid;
    place-items: center;
    width: 4.25rem;
    height: 4.25rem;
    border-radius: 50%;
    background: rgba(16, 185, 129, 0.12);
    border: 1px solid rgba(16, 185, 129, 0.32);
    color: var(--mint-500);
    font-size: 2rem;
    animation: qmPop var(--t-slow) var(--ease) both;
}

@keyframes qmPop {
    from {
        opacity: 0;
        transform: scale(0.7);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

.qm__done-title {
    margin: 0;
    font-size: var(--fs-h3);
    font-weight: 800;
    letter-spacing: -0.02em;
}

.qm__done-text {
    margin: 0;
    max-width: 42ch;
    font-size: 0.93rem;
    line-height: 1.6;
    color: var(--text-soft);
}

.qm__steps {
    display: grid;
    gap: 0.55rem;
    width: 100%;
    max-width: 30rem;
    margin: 0.25rem 0 0;
    padding: 1rem 1.1rem;
    list-style: none;
    text-align: left;
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    background: var(--bg-soft);
}

.qm__steps li {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--text-soft);
}

.qm__steps i {
    flex: none;
    margin-top: 0.1rem;
    color: var(--brand-600);
}

.qm__done-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.65rem;
}

/* -------------------------------------------------------------------- Foot */

.qm__foot {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.9rem 1.25rem;
    padding: 0.95rem clamp(1.15rem, 2.6vw, 2rem);
    border-top: 1px solid var(--border);
    background: var(--bg-soft);
}

.qm__note {
    display: flex;
    align-items: flex-start;
    gap: 0.4rem;
    max-width: 30rem;
    margin: 0;
    font-size: 0.76rem;
    line-height: 1.5;
    color: var(--text-muted);
}

.qm__note i {
    flex: none;
    margin-top: 0.1rem;
}

.qm__actions {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.qm__busy {
    display: none;
    width: 1rem;
    height: 1rem;
    border-radius: 50%;
    border: 2px solid currentColor;
    border-top-color: transparent;
    animation: qmSpin 0.7s linear infinite;
}

@keyframes qmSpin {
    to {
        transform: rotate(360deg);
    }
}

.qm__submit[data-busy='true'] {
    pointer-events: none;
    opacity: 0.75;
}

.qm__submit[data-busy='true'] .qm__busy {
    display: inline-block;
}

/* ----------------------------------------------------------------- Mobile */

/* Below the tablet breakpoint the dialog becomes a full height sheet. */
@media (max-width: 47.99rem) {
    .qm {
        padding: 0;
        place-items: stretch;
    }

    .qm__dialog {
        width: 100%;
        height: 100%;
        max-height: 100%;
        border: 0;
        border-radius: 0;
        transform: translateY(3%);
    }

    .qm.is-open .qm__dialog {
        transform: none;
    }

    .qm__foot {
        align-items: stretch;
    }

    .qm__actions {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
    }

    .qm__actions .btn {
        width: 100%;
    }
}

/* Very small phones: keep the submit row side by side with the WhatsApp link. */
@media (max-width: 26rem) {
    .qm__actions {
        grid-template-columns: minmax(0, 1fr);
    }

    .qm__done-actions {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
    }

    .qm__done-actions .btn {
        width: 100%;
    }
}
