/* ==================================================================
   WA Leads — فورم جمع بيانات العميل قبل واتساب
   عربي RTL، متجاوب، ورقة سفلية على الموبايل ونافذة في الوسط على الشاشات الكبيرة
   ================================================================== */

.wal-modal {
    --wal-brand:      #25D366;
    --wal-brand-dark: #128C7E;
    --wal-ink:        #0f172a;
    --wal-muted:      #64748b;
    --wal-line:       #e2e8f0;
    --wal-bg:         #ffffff;
    --wal-field:      #f8fafc;
    --wal-danger:     #dc2626;
    --wal-radius:     20px;

    position: fixed;
    inset: 0;
    z-index: 2147483000;
    display: none;
    direction: rtl;
    font-family: "Cairo", "Tajawal", "Segoe UI", Tahoma, system-ui, -apple-system, sans-serif;
    -webkit-font-smoothing: antialiased;
}

.wal-modal.is-open { display: block; }

/* لا نسمح لأنماط القالب بكسر المقاسات داخل الفورم */
.wal-modal *,
.wal-modal *::before,
.wal-modal *::after { box-sizing: border-box; }

html.wal-locked,
html.wal-locked body { overflow: hidden; }

/* ---- الخلفية ---- */

.wal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, .55);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    animation: wal-fade .2s ease both;
}

@keyframes wal-fade { from { opacity: 0; } to { opacity: 1; } }

/* ---- البطاقة ---- */

.wal-modal .wal-sheet {
    position: absolute;
    right: 50%;
    bottom: 0;
    transform: translateX(50%);
    width: min(420px, 100%);
    box-sizing: border-box;
    background: var(--wal-bg);
    color: var(--wal-ink);
    border-radius: var(--wal-radius) var(--wal-radius) 0 0;
    padding: 26px 22px calc(22px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -8px 40px rgba(15, 23, 42, .28);
    animation: wal-rise .28s cubic-bezier(.2, .8, .3, 1) both;
    max-height: 92vh;
    overflow-y: auto;
    /* لا سكرول أفقي مهما طال نص أي عنصر داخل البطاقة */
    overflow-x: hidden;
}

@keyframes wal-rise {
    from { opacity: 0; transform: translateX(50%) translateY(28px); }
    to   { opacity: 1; transform: translateX(50%) translateY(0); }
}

@media (min-width: 560px) {
    .wal-modal .wal-sheet {
        top: 50%;
        bottom: auto;
        transform: translate(50%, -50%);
        border-radius: var(--wal-radius);
        padding: 30px 28px 24px;
        box-shadow: 0 24px 60px rgba(15, 23, 42, .32);
    }
    @keyframes wal-rise {
        from { opacity: 0; transform: translate(50%, -46%) scale(.97); }
        to   { opacity: 1; transform: translate(50%, -50%) scale(1); }
    }
}

@media (prefers-reduced-motion: reduce) {
    .wal-modal .wal-sheet,
    .wal-modal .wal-backdrop { animation: none; }
}

/*
 * هواتف قصيرة: نضغط المسافات قليلاً حتى يبقى زر الإرسال ظاهراً
 * بلا تمرير، فالتمرير قبل الشراء يُفقد عملاء.
 */
@media (max-height: 730px) {
    .wal-modal .wal-sheet  { padding-top: 20px; }
    .wal-modal .wal-head   { margin-bottom: 14px; }
    .wal-modal .wal-badge  { width: 40px; height: 40px; border-radius: 12px; }
    .wal-modal .wal-title  { font-size: 17px; }
    .wal-modal .wal-sub    { font-size: 12.5px; }
    .wal-modal .wal-field  { margin-bottom: 10px; }
    .wal-modal .wal-label  { margin-bottom: 4px; font-size: 12.5px; }
    .wal-modal .wal-input  { height: 46px; }
    .wal-modal .wal-submit { height: 50px; margin-top: 4px; }
    .wal-modal .wal-note   { margin-top: 10px; }
}

/* ---- زر الإغلاق ---- */

.wal-modal .wal-x {
    position: absolute;
    top: 14px;
    left: 14px;
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--wal-field);
    color: var(--wal-muted);
    cursor: pointer;
    transition: background .15s, color .15s;
}

.wal-modal .wal-x:hover { background: #eef2f7; color: var(--wal-ink); }

/* ---- الترويسة ---- */

.wal-modal .wal-head {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin: 0 0 20px;
}

.wal-modal .wal-badge {
    flex: 0 0 auto;
    width: 46px;
    height: 46px;
    display: grid;
    place-items: center;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--wal-brand), var(--wal-brand-dark));
    color: #fff;
    box-shadow: 0 6px 16px rgba(37, 211, 102, .35);
}

.wal-modal .wal-title {
    margin: 2px 0 4px;
    font-size: 19px;
    line-height: 1.4;
    font-weight: 800;
    color: var(--wal-ink);
}

.wal-modal .wal-sub {
    margin: 0;
    font-size: 13.5px;
    line-height: 1.6;
    color: var(--wal-muted);
}

/* ---- الحقول ---- */

.wal-modal .wal-form { margin: 0; }

.wal-modal .wal-field {
    display: block;
    margin: 0 0 14px;
}

.wal-modal .wal-label {
    display: block;
    margin: 0 0 6px;
    font-size: 13px;
    font-weight: 700;
    color: var(--wal-ink);
}

.wal-modal .wal-input {
    display: block;
    width: 100%;
    box-sizing: border-box;
    height: 52px;
    max-width: none;
    min-width: 0;
    margin: 0;
    padding: 0 16px;
    font-family: inherit;
    font-size: 16px; /* 16px يمنع تكبير الصفحة تلقائياً على iOS */
    color: var(--wal-ink);
    background: var(--wal-field);
    border: 1.5px solid var(--wal-line);
    border-radius: 14px;
    outline: none;
    transition: border-color .15s, background .15s, box-shadow .15s;
}

.wal-modal .wal-input::placeholder { color: #94a3b8; }

.wal-modal .wal-input:focus {
    background: #fff;
    border-color: var(--wal-brand);
    box-shadow: 0 0 0 4px rgba(37, 211, 102, .16);
}

.wal-modal .wal-input--tel {
    direction: ltr;
    text-align: right;
    letter-spacing: .4px;
}

/* ---- قائمة المحافظات ---- */

.wal-modal .wal-select-wrap {
    position: relative;
    display: block;
}

.wal-modal .wal-select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    padding-inline-end: 42px;
    cursor: pointer;
    background-image: none;
}

/* لون باهت ما دام لم يُختر شيء، ليبدو كنص إرشادي */
.wal-modal .wal-select.is-empty { color: #94a3b8; }
.wal-modal .wal-select option   { color: var(--wal-ink); }

.wal-modal .wal-select-arrow {
    position: absolute;
    inset-inline-end: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--wal-muted);
    pointer-events: none;
}

.wal-modal .wal-optional {
    margin-inline-start: 4px;
    font-size: 11.5px;
    font-weight: 600;
    color: #94a3b8;
}

.wal-modal .wal-input.has-error {
    border-color: var(--wal-danger);
    background: #fef2f2;
}

/*
 * لا نحجز مساحة للخطأ ما لم يوجد خطأ فعلاً.
 * مع أربعة حقول كان الحجز يدفع زر الإرسال خارج الشاشة في الهواتف القصيرة.
 */
.wal-modal .wal-err {
    display: block;
    margin: 0;
    font-size: 12.5px;
    font-style: normal;
    font-weight: 600;
    line-height: 1.5;
    color: var(--wal-danger);
}

.wal-modal .wal-err:not(:empty) { margin: 6px 2px 0; }

/* ---- مصيدة البوتات ---- */

/*
 * لا نُخفيها بـ left:-9999px.
 * في اتجاه RTL تكون تلك المساحة قابلة للتمرير فعلاً، فيظهر سكرول أفقي
 * غريب أسفل الفورم. نستخدم بدلها الإخفاء بالقص داخل حدود البطاقة.
 */
.wal-modal .wal-hp {
    position: absolute !important;
    top: 0;
    inset-inline-start: 0;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    border: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    clip-path: inset(50%);
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
}

/* ---- زر الإرسال ---- */

.wal-modal .wal-submit {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    /* قوالب كثيرة تفرض max-width أو أحرف كبيرة على كل زر — نتجاوزها */
    max-width: none;
    min-width: 0;
    height: 54px;
    margin: 6px 0 0;
    padding: 0 18px;
    font-family: inherit;
    font-size: 16px;
    font-weight: 800;
    line-height: 1.2;
    letter-spacing: normal;
    text-transform: none;
    text-decoration: none;
    color: #fff;
    background: linear-gradient(135deg, var(--wal-brand), var(--wal-brand-dark));
    border: 0;
    border-radius: 14px;
    cursor: pointer;
    box-shadow: 0 8px 20px rgba(37, 211, 102, .32);
    transition: transform .12s, box-shadow .15s, opacity .15s;
}

.wal-modal .wal-submit:hover  { box-shadow: 0 10px 26px rgba(37, 211, 102, .42); }
.wal-modal .wal-submit:active { transform: translateY(1px); }

.wal-modal .wal-submit:disabled {
    opacity: .75;
    cursor: default;
    transform: none;
}

.wal-modal .wal-spinner { display: none; }

.wal-modal .wal-submit.is-busy .wal-spinner {
    display: block;
    width: 18px;
    height: 18px;
    border: 2.5px solid rgba(255, 255, 255, .4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: wal-spin .7s linear infinite;
}

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

/* ---- ملاحظة الخصوصية ---- */

/*
 * flex هنا كان يمنع النص من الالتفاف فيتجاوز عرض البطاقة ويظهر سكرول أفقي.
 * الأيقونة صارت داخل السطر نفسه، والنص يلتف طبيعياً.
 */
.wal-modal .wal-note {
    display: block;
    margin: 14px 0 0;
    font-size: 12px;
    line-height: 1.7;
    color: var(--wal-muted);
    text-align: center;
    overflow-wrap: break-word;
    word-wrap: break-word;
}

.wal-modal .wal-note svg {
    display: inline-block;
    vertical-align: -2px;
    margin-inline-end: 4px;
    color: var(--wal-brand-dark);
}

/* رابط صفحة الشروط — عريض وتحته خط ليُفهم أنه قابل للضغط */
.wal-modal .wal-note-link {
    font-weight: 800;
    color: var(--wal-brand-dark);
    text-decoration: underline;
    text-underline-offset: 3px;
    text-decoration-thickness: 1.5px;
    transition: color .15s;
}

.wal-modal .wal-note-link:hover,
.wal-modal .wal-note-link:focus {
    color: var(--wal-brand);
    text-decoration-thickness: 2px;
}

/* ---- الوضع الليلي ---- */

@media (prefers-color-scheme: dark) {
    .wal-modal {
        --wal-ink:   #f1f5f9;
        --wal-muted: #94a3b8;
        --wal-line:  #334155;
        --wal-bg:    #1e293b;
        --wal-field: #0f172a;
    }
    .wal-modal .wal-x:hover { background: #334155; color: #f1f5f9; }
    .wal-modal .wal-input:focus { background: #0f172a; }
    .wal-modal .wal-input.has-error { background: #2a1416; }
    .wal-modal .wal-note svg { color: var(--wal-brand); }
    .wal-modal .wal-note-link { color: #4ade80; }
    .wal-modal .wal-note-link:hover,
    .wal-modal .wal-note-link:focus { color: #86efac; }
}
