/* ─── Custom Properties ─────────────────────────────────────────── */
:root {
    --primary:      #2563eb;
    --primary-dark: #1d4ed8;
    --cta-color:    #2563eb;    /* overridable via ?cta_color= */
    --text:         #374151;
    --text-muted:   #6b7280;
    --border:       #d1d5db;
    --border-focus: #2563eb;
    --bg:           #f3f4f6;
    --white:        #ffffff;
    --error:        #ef4444;
    --success:      #10b981;
    --radius:       8px;       /* overridable via ?radius= */
}

/* ─── Reset ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
html, body {
    height: 100%;
}
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
    background: transparent;
    color: var(--text);
    min-height: 100%;
    display: flex;
    align-items: stretch;
    justify-content: center;
    padding: 0;
}
a { color: var(--primary); }

/* ─── Widget Container ──────────────────────────────────────────── */
.widget-container {
    background: transparent;
    border-radius: 0;
    padding: 24px 32px;
    width: 100%;
    max-width: 100%;
    box-shadow: none;
    border: none;
    margin-bottom: 15px;
}

/* Logo */
.widget-logo {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 1rem;
    font-weight: 700;
    color: #111827;
    margin-bottom: 22px;
}
.widget-logo svg { width: 22px; height: 22px; color: var(--primary); }

/* Heading */
.widget-title {
    font-size: 1.35rem;
    font-weight: 800;
    color: #111827;
    letter-spacing: -.025em;
    margin-bottom: 4px;
}
.widget-subtitle {
    font-size: .85rem;
    color: var(--text-muted);
    margin-bottom: 26px;
    line-height: 1.5;
}

/* ─── Form Layout ───────────────────────────────────────────────── */
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.form-group { margin-bottom: 14px; }

.form-label {
    display: block;
    font-size: .78rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 5px;
    letter-spacing: .01em;
}
.form-label .required { color: var(--error); margin-left: 1px; }

.form-input {
    width: 100%;
    padding: 10px 13px;
    font-size: .875rem;
    font-family: inherit;
    color: var(--text);
    background: var(--white);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    outline: none;
    transition: border-color .15s, box-shadow .15s;
    -webkit-appearance: none;
}
.form-input::placeholder { color: #9ca3af; }
.form-input:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.form-input.error {
    border-color: var(--error);
    box-shadow: 0 0 0 3px rgba(239,68,68,.1);
}

/* ─── Field-level Error ─────────────────────────────────────────── */
.field-error {
    display: none;
    font-size: .72rem;
    color: var(--error);
    margin-top: 4px;
    line-height: 1.4;
}
.field-error.show { display: block; }

/* ─── Phone Field ───────────────────────────────────────────────── */
.phone-wrapper {
    display: flex;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: border-color .15s, box-shadow .15s;
    background: var(--white);
}
.phone-wrapper:focus-within {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.phone-wrapper.error {
    border-color: var(--error);
    box-shadow: 0 0 0 3px rgba(239,68,68,.1);
}

.phone-prefix {
    flex-shrink: 0;
    background: #f8f9fa;
    border: none;
    border-right: 1.5px solid var(--border);
    padding: 10px 26px 10px 10px;
    font-size: .8rem;
    font-family: inherit;
    color: var(--text);
    cursor: pointer;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    /* Chevron arrow */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='none'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%236b7280' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    max-width: 195px;
}

.phone-number {
    flex: 1;
    min-width: 0;
    border: none;
    padding: 10px 13px;
    font-size: .875rem;
    font-family: inherit;
    color: var(--text);
    background: transparent;
    outline: none;
}
.phone-number::placeholder { color: #9ca3af; }

/* ─── Privacy Checkbox ──────────────────────────────────────────── */
.privacy-group { margin-bottom: 18px; }

.checkbox-label {
    display: flex;
    align-items: flex-start;
    gap: 9px;
    cursor: pointer;
    font-size: .78rem;
    color: var(--text-muted);
    line-height: 1.55;
}
.checkbox-label input[type="checkbox"] {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
    margin-top: 2px;
    accent-color: var(--primary);
    cursor: pointer;
}

/* ─── Submit Button ─────────────────────────────────────────────── */
.btn-submit {
    width: 100%;
    padding: 12px;
    background: var(--cta-color);
    color: var(--white);
    font-size: .9rem;
    font-weight: 600;
    font-family: inherit;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: filter .15s, transform .1s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    letter-spacing: .01em;
}
.btn-submit:hover   { filter: brightness(.88); }
.btn-submit:active  { transform: scale(.99); }
.btn-submit:disabled { opacity: .65; cursor: not-allowed; filter: none; }

/* ─── Global Alert ──────────────────────────────────────────────── */
.alert {
    padding: 11px 14px;
    border-radius: var(--radius);
    font-size: .82rem;
    margin-bottom: 14px;
    display: none;
    line-height: 1.5;
}
.alert.show { display: block; }

.alert-error {
    background: #fef2f2;
    color: #dc2626;
    border: 1px solid #fecaca;
}

/* ─── Loading Spinner ───────────────────────────────────────────── */
.spinner {
    display: none;
    width: 17px;
    height: 17px;
    border: 2px solid rgba(255,255,255,.35);
    border-top-color: var(--white);
    border-radius: 50%;
    animation: spin .65s linear infinite;
    flex-shrink: 0;
}
.btn-submit.loading .spinner  { display: block; }
.btn-submit.loading .btn-text { display: none; }

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

/* ─── Shake animation (invalid submit attempt) ──────────────────── */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%       { transform: translateX(-6px); }
    40%       { transform: translateX(6px); }
    60%       { transform: translateX(-4px); }
    80%       { transform: translateX(4px); }
}
.shake { animation: shake .35s ease; }

/* ─── Success Screen ────────────────────────────────────────────── */
.success-screen {
    display: none;
    text-align: center;
    padding: 20px 0 8px;
}
.success-screen.show { display: block; }

.success-icon {
    width: 66px;
    height: 66px;
    background: #f0fdf4;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 18px;
}
.success-icon svg { width: 32px; height: 32px; color: var(--success); }

.success-screen h3 {
    font-size: 1.2rem;
    font-weight: 700;
    color: #111827;
    letter-spacing: -.02em;
    margin-bottom: 8px;
}
.success-screen p {
    font-size: .85rem;
    color: var(--text-muted);
    line-height: 1.6;
}

/* ─── Full-page loader overlay ──────────────────────────────────── */
.page-loader {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(255, 255, 255, 0.75);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    align-items: center;
    justify-content: center;
}
.page-loader.show {
    display: flex;
}
.page-loader-spinner {
    width: 48px;
    height: 48px;
    border: 3px solid rgba(37, 99, 235, 0.15);
    border-top-color: var(--cta-color);
    border-radius: 50%;
    animation: spin .75s linear infinite;
}

/* ─── Responsive ─────────────────────────────────────────────────── */
@media (max-width: 480px) {
    .widget-container { padding: 20px 16px; }
    .form-row { grid-template-columns: 1fr; }
    .phone-prefix { max-width: 160px; }
    .form-row .form-group:nth-child(n+2){margin-top: -14px}
}

/* ─── RTL (Arabic) ───────────────────────────────────────────────── */
[dir="rtl"] body {
    font-family: 'Cairo', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
}
[dir="rtl"] .form-label .required {
    margin-left: 0;
    margin-right: 1px;
}
[dir="rtl"] .phone-prefix {
    border-right: none;
    border-left: 1.5px solid var(--border);
    background-position: left 8px center;
    padding: 10px 10px 10px 26px;
}
[dir="rtl"] .phone-number {
    text-align: right;
}
[dir="rtl"] .form-input {
    text-align: right;
}
[dir="rtl"] .checkbox-label {
    flex-direction: row-reverse;
}
