/* Lead capture: quote dialog, floating call/WhatsApp/quote buttons, sticky mobile bar (inc/lead-capture.php).
   Every element is position: fixed (or display: none) until revealed, so nothing shifts the layout.
   z-index: headers 1000, nav dropdowns 1100, lightbox 3000 → float/bar 900, dialog 2500.
   Tokens follow the lab/consulting pages: navy #0f2846, green #58923d, radius 18/12/10, shadow-md. */

.saf-lead, .saf-float, .saf-bar {
    --saf-navy: #0f2846;
    --saf-navy-deep: #0a1d33;
    --saf-green: #58923d;
    --saf-green-dark: #467a30;   /* buttons: white on it 5.1:1 */
    --saf-green-darker: #3b6628; /* their hover */
    --saf-green-light: #8fd16a;
    --saf-ink: #14273d;
    --saf-muted: #5b6b7b;
    --saf-line: #d5dde6;
    --saf-soft: #f4f7fa;
    --saf-wa: #17803f;           /* WhatsApp, deepened: white on it 5.0:1 (#25d366 is 1.98) */
    --saf-error: #b42318;
    font-family: 'IBM Plex Sans Arabic', 'IBM Plex Sans', system-ui, sans-serif;
    direction: rtl;
    text-align: right;
}
.saf-lead [hidden] { display: none !important; }

/* Page CTAs that open the form are <button>s styled by the page's own button classes */
button.saf-cta-quote { border: 0; cursor: pointer; font-family: inherit; line-height: inherit; }

/* While the form is open the page behind it must not scroll (gutter kept: no layout shift) */
html.saf-lead-lock { overflow: hidden; scrollbar-gutter: stable; }

/* ---------- Dialog ---------- */
.saf-lead[hidden] { display: none; }
.saf-lead {
    position: fixed; inset: 0; z-index: 2500; display: flex; align-items: center; justify-content: center; padding: 24px;
    color: var(--saf-ink); line-height: 1.6;
}
.saf-lead__backdrop { position: absolute; inset: 0; background: rgba(17, 24, 32, .55); opacity: 0; transition: opacity .22s ease; }
.saf-lead__panel {
    position: relative; display: flex; flex-direction: column; width: 100%; max-width: 520px;
    max-height: calc(100vh - 48px); max-height: calc(100dvh - 48px);
    background: #fff; border-radius: 18px; overflow: hidden; outline: none;
    box-shadow: 0 24px 60px rgba(17, 24, 32, .22);
    opacity: 0; transform: translateY(12px); transition: opacity .22s ease, transform .22s ease;
}
.saf-lead.is-open .saf-lead__backdrop { opacity: 1; }
.saf-lead.is-open .saf-lead__panel { opacity: 1; transform: none; }

/* Header band: light, with a hairline under it */
.saf-lead__head { position: relative; flex: none; padding: 22px 26px 20px 72px; background: #f4f7fa; color: var(--saf-navy); border-bottom: 1px solid #e6ecf1; }
.saf-lead__grip { display: none; }
.saf-lead__eyebrow { margin: 0 0 4px; font-size: .82rem; font-weight: 600; color: var(--saf-green-dark); }
.saf-lead__title { margin: 0; font-size: 1.35rem; font-weight: 700; line-height: 1.45; color: var(--saf-navy); }
.saf-lead__text { margin: 6px 0 0; font-size: .92rem; line-height: 1.75; color: #4a5a6b; }
.saf-lead__close {
    position: absolute; top: 16px; left: 16px; width: 44px; height: 44px; display: grid; place-items: center;
    border: 1px solid #dde4ec; border-radius: 12px; background: #fff;
    color: var(--saf-navy); font-size: 16px; cursor: pointer; transition: background .15s ease;
}
.saf-lead__close:hover { background: #eef2f6; }
.saf-lead__close:focus-visible { outline: 2px solid var(--saf-green-dark); outline-offset: 2px; }

/* Everything under the header scrolls inside the panel; the submit row stays visible */
.saf-lead__scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.saf-lead__media img { display: block; width: 100%; height: 140px; object-fit: cover; }

/* ---------- Form ---------- */
.saf-lead__form { padding: 22px 26px 0; }
.saf-lead__fields { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 14px 16px; }
.saf-lead__field { grid-column: span 3; min-width: 0; }
.saf-lead__field--full { grid-column: 1 / -1; }
.saf-lead__field--service { grid-column: span 4; }
.saf-lead__field--city { grid-column: span 2; }
.saf-lead__field label { display: block; margin: 0 0 6px; font-size: .9rem; font-weight: 600; line-height: 1.4; color: var(--saf-navy); }
.saf-lead__opt { font-weight: 400; color: var(--saf-muted); }
.saf-lead__field input,
.saf-lead__field select,
.saf-lead__field textarea {
    display: block; width: 100%; height: 48px; margin: 0; padding: 0 14px;
    border: 1px solid var(--saf-line); border-radius: 10px; background: #fff; color: var(--saf-ink);
    font: inherit; font-size: 16px; /* 16px: iOS does not zoom on focus */ line-height: 1.4;
    box-shadow: none; -webkit-appearance: none; appearance: none;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.saf-lead__field textarea { height: auto; min-height: 80px; padding: 12px 14px; resize: vertical; }
.saf-lead__field input[dir="ltr"] { text-align: right; }
.saf-lead__field ::placeholder { color: #98a5b3; opacity: 1; }
.saf-lead__field input:hover, .saf-lead__field select:hover, .saf-lead__field textarea:hover { border-color: #b4c1cf; }
.saf-lead__field input:focus, .saf-lead__field select:focus, .saf-lead__field textarea:focus {
    outline: none; border-color: #467a30; box-shadow: 0 0 0 3px rgba(70, 122, 48, .55);
}
.saf-lead__field [aria-invalid="true"] { border-color: var(--saf-error); background: #fffbfa; }
.saf-lead__field [aria-invalid="true"]:focus { box-shadow: 0 0 0 3px rgba(180, 35, 24, .15); }
.saf-lead__select { position: relative; }
.saf-lead__select select { padding-left: 42px; cursor: pointer; text-overflow: ellipsis; }
.saf-lead__select .bi { position: absolute; top: 50%; left: 15px; transform: translateY(-50%); font-size: 14px; color: var(--saf-muted); pointer-events: none; }
.saf-lead__err { margin: 6px 0 0; font-size: .84rem; line-height: 1.5; color: var(--saf-error); }
.saf-lead__err:empty { display: none; }

/* Honeypot: off-screen, not display:none (some bots skip hidden fields) */
.saf-lead__hp { position: absolute; left: -10000px; top: auto; width: 1px; height: 1px; overflow: hidden; }

.saf-lead__foot {
    position: sticky; bottom: 0; z-index: 1; margin: 18px -26px 0; padding: 14px 26px 20px;
    background: #fff; border-top: 1px solid #edf1f5;
}
.saf-lead__alert {
    margin: 0 0 12px; padding: 10px 14px; border: 1px solid #f4c7c2; border-radius: 10px;
    background: #fdf2f1; color: #8f1d14; font-size: .9rem; line-height: 1.6;
}
.saf-lead__alert:empty { display: none; }
.saf-lead__alert a { color: inherit; font-weight: 700; }
.saf-lead__alt { margin: 12px 0 0; font-size: .85rem; line-height: 1.6; color: var(--saf-muted); text-align: center; }
.saf-lead__alt a { color: var(--saf-navy); font-weight: 600; text-underline-offset: 3px; }
.saf-lead__alt span { margin: 0 4px; }

/* ---------- Buttons ---------- */
.saf-lead__btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; margin: 0; padding: 0 20px;
    border: 1px solid transparent; border-radius: 12px; font: inherit; font-size: 1rem; font-weight: 600; line-height: 1.3;
    text-decoration: none; text-align: center; cursor: pointer; -webkit-tap-highlight-color: transparent;
    transition: background-color .15s ease, border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}
.saf-lead__btn .bi { font-size: 1.1em; line-height: 1; }
.saf-lead__btn:focus-visible { outline: 3px solid rgba(15, 40, 70, .35); outline-offset: 2px; }
.saf-lead__btn:active { transform: translateY(1px); }
.saf-lead__btn--primary { background: var(--saf-green-dark); color: #fff; box-shadow: 0 8px 20px rgba(88, 146, 61, .28); }
.saf-lead__btn--primary:hover { background: var(--saf-green-darker); color: #fff; }
.saf-lead__btn--wa { background: #fff; color: var(--saf-navy); border-color: var(--saf-line); }
.saf-lead__btn--wa .bi { color: var(--saf-wa); }
.saf-lead__btn--wa:hover { background: #f3fbf6; border-color: var(--saf-wa); color: var(--saf-navy); }
.saf-lead__btn--ghost { background: var(--saf-soft); color: var(--saf-navy); }
.saf-lead__btn--ghost:hover { background: #e9eef4; }

.saf-lead__submit { width: 100%; min-height: 52px; font-size: 1.05rem; font-weight: 700; }
.saf-lead__submit[disabled] { cursor: progress; opacity: .8; box-shadow: none; transform: none; }
.saf-lead__spinner {
    display: none; width: 18px; height: 18px; border: 2px solid rgba(255, 255, 255, .45); border-top-color: #fff;
    border-radius: 50%; animation: saf-lead-spin .7s linear infinite;
}
.saf-lead__submit.is-busy .saf-lead__spinner { display: inline-block; }
@keyframes saf-lead-spin { to { transform: rotate(360deg); } }

/* ---------- Teaser: the compact auto-popup on phones ---------- */
.saf-lead__teaser { display: none; gap: 10px; padding: 18px 22px 20px; }
.saf-lead[data-mode="teaser"] .saf-lead__teaser { display: flex; }
.saf-lead[data-mode="teaser"] .saf-lead__form,
.saf-lead[data-mode="teaser"] .saf-lead__media { display: none; }
.saf-lead__teaser .saf-lead__btn { flex: 1 1 0; white-space: nowrap; padding: 0 14px; }
.saf-lead__teaser .saf-lead__btn--primary { flex-grow: 1.6; }

/* ---------- Success ---------- */
.saf-lead__success { padding: 28px 26px 26px; text-align: center; outline: none; }
.saf-lead__check {
    display: grid; place-items: center; width: 64px; height: 64px; margin: 0 auto 14px; border-radius: 50%;
    background: rgba(88, 146, 61, .12); color: var(--saf-green); font-size: 2rem;
}
.saf-lead__success h3 { margin: 0 0 8px; font-size: 1.3rem; font-weight: 700; color: var(--saf-navy); }
.saf-lead__success p { margin: 0 0 20px; color: var(--saf-muted); line-height: 1.8; }
.saf-lead__success .saf-lead__btn { width: 100%; }
.saf-lead__success .saf-lead__btn + .saf-lead__btn { margin-top: 10px; }
.saf-lead.is-done .saf-lead__form, .saf-lead.is-done .saf-lead__teaser,
.saf-lead.is-done .saf-lead__media, .saf-lead.is-done .saf-lead__text { display: none; }

/* Short viewports (landscape, or a phone with the keyboard open: JS sets .is-compact) */
@media (max-height: 640px) {
    .saf-lead__text, .saf-lead__media { display: none; }
    .saf-lead__head { padding-top: 16px; padding-bottom: 14px; }
}
.saf-lead.is-compact .saf-lead__text, .saf-lead.is-compact .saf-lead__eyebrow,
.saf-lead.is-compact .saf-lead__alt, .saf-lead.is-compact .saf-lead__grip { display: none; }
.saf-lead.is-compact .saf-lead__head { padding-top: 12px; padding-bottom: 12px; }
.saf-lead.is-compact .saf-lead__close { top: 6px; }

/* ---------- Mobile: bottom sheet ---------- */
@media (max-width: 767.98px) {
    /* --saf-kb (JS, visualViewport) lifts the sheet above the on-screen keyboard */
    .saf-lead { align-items: flex-end; padding: 0 0 var(--saf-kb, 0px); }
    .saf-lead__panel {
        max-width: none; border-radius: 18px 18px 0 0;
        max-height: calc(100vh - 16px); max-height: calc(100dvh - 16px); max-height: calc(var(--saf-vh, 100dvh) - 16px);
        transform: translateY(100%);
    }
    .saf-lead__head { padding: 24px 20px 16px 68px; }
    .saf-lead__grip {
        display: block; position: absolute; top: 8px; left: 50%; width: 40px; height: 4px; margin-left: -20px;
        border-radius: 2px; background: #cdd6e0;
    }
    .saf-lead__title { font-size: 1.15rem; }
    .saf-lead__text { font-size: .88rem; }
    .saf-lead__close { top: 14px; left: 12px; }
    .saf-lead__media { display: none; }
    .saf-lead__form { padding: 18px 20px 0; }
    .saf-lead__fields { gap: 12px; }
    .saf-lead__field--service, .saf-lead__field--city { grid-column: 1 / -1; }
    .saf-lead__foot { margin: 16px -20px 0; padding: 12px 20px calc(14px + env(safe-area-inset-bottom)); }
    .saf-lead__alt { margin-top: 10px; }
    .saf-lead__teaser { padding: 16px 20px calc(16px + env(safe-area-inset-bottom)); }
    .saf-lead__success { padding: 24px 20px calc(22px + env(safe-area-inset-bottom)); }
    /* Teaser: no backdrop, the page stays visible and usable above it */
    .saf-lead[data-mode="teaser"] { inset: auto 0 0 0; }
    .saf-lead[data-mode="teaser"] .saf-lead__backdrop { display: none; }
    .saf-lead[data-mode="teaser"] .saf-lead__panel { box-shadow: 0 -10px 30px rgba(10, 29, 51, .25); }
}
@media (max-width: 359.98px) {
    .saf-lead__field { grid-column: 1 / -1; }
}

/* ---------- Floating quote / call / WhatsApp (desktop + tablet) ---------- */
.saf-float {
    position: fixed; left: 20px; bottom: 20px; z-index: 900; direction: ltr;
    display: grid; grid-template-columns: auto auto; align-items: end; justify-items: center; gap: 10px;
}
.saf-float__btn--call { grid-column: 1; grid-row: 1; }
.saf-float__btn--wa { grid-column: 1; grid-row: 2; }
.saf-float__quote { grid-column: 2; grid-row: 2; align-self: center; }
.saf-float__btn {
    width: 54px; height: 54px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-size: 24px; text-decoration: none;
    box-shadow: 0 6px 18px rgba(15, 40, 70, .25); transition: transform .15s ease;
}
.saf-float__btn:hover, .saf-float__btn:focus-visible { color: #fff; transform: scale(1.06); }
.saf-float__btn:focus-visible, .saf-float__quote:focus-visible { outline: 3px solid rgba(88, 146, 61, .5); outline-offset: 2px; }
.saf-float__btn--wa { background: var(--saf-wa); font-size: 28px; }
.saf-float__btn--call { background: var(--saf-navy); width: 46px; height: 46px; font-size: 18px; }
.saf-float__quote {
    direction: rtl; display: inline-flex; align-items: center; gap: 8px; height: 46px; padding: 0 20px; border: 0; border-radius: 12px;
    background: var(--saf-green-dark); color: #fff; font: inherit; font-size: .98rem; font-weight: 700; white-space: nowrap; cursor: pointer;
    box-shadow: 0 8px 20px rgba(15, 40, 70, .22); transition: background-color .15s ease, transform .15s ease;
}
.saf-float__quote:hover { background: var(--saf-green-darker); transform: translateY(-1px); }

/* ---------- Sticky mobile bar ---------- */
.saf-bar, .saf-bar-spacer { display: none; }
@media (max-width: 767.98px) {
    .saf-float { display: none; }
    .saf-bar {
        position: fixed; left: 0; right: 0; bottom: 0; z-index: 900; display: flex; align-items: center; gap: 8px;
        padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); background: #fff; box-shadow: 0 -4px 16px rgba(15, 40, 70, .12);
    }
    /* In-flow spacer at the very end of <body>: the bar never covers the footer's last line */
    .saf-bar-spacer { display: block; height: calc(64px + env(safe-area-inset-bottom)); }
    .saf-bar__quote {
        flex: 1; min-width: 0; display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 48px; margin: 0; padding: 0 12px;
        border: 0; border-radius: 12px; background: var(--saf-green-dark); color: #fff; font: inherit; font-weight: 700; font-size: 1rem; line-height: 1.2;
        white-space: nowrap; cursor: pointer; -webkit-tap-highlight-color: transparent;
    }
    .saf-bar__quote:active { background: var(--saf-green-darker); }
    .saf-bar__quote:focus-visible, .saf-bar__icon:focus-visible { outline: 3px solid rgba(15, 40, 70, .35); outline-offset: 2px; }
    .saf-bar__icon {
        flex: none; width: 56px; height: 48px; line-height: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
        border-radius: 12px; color: var(--saf-navy); background: #f1f4f8; text-decoration: none; font-size: 18px;
    }
    .saf-bar__icon span { font-size: .7rem; font-weight: 600; }
    .saf-bar__icon--wa { color: #fff; background: var(--saf-wa); }
    .saf-bar__icon:hover { color: inherit; }
    .saf-bar__icon--wa:hover { color: #fff; }
}

@media (prefers-reduced-motion: reduce) {
    .saf-lead__backdrop, .saf-lead__panel, .saf-float__btn, .saf-float__quote, .saf-lead__btn { transition: none; }
    .saf-lead__spinner { animation-duration: 1.6s; }
}
@media print {
    .saf-lead, .saf-float, .saf-bar, .saf-bar-spacer { display: none !important; }
}
