/* ==========================================================================
   إيجاري (Ijari) — التنسيقات
   ========================================================================== */

:root {
    --green: #0e7a4b;
    --green-dark: #0a5c39;
    --green-light: #e8f5ee;
    --green-soft: #f1f9f5;
    --amber: #d99616;
    --amber-light: #fdf6e6;
    --red: #c0392b;
    --red-light: #fdeceb;
    --ink: #1f2937;
    --muted: #6b7280;
    --line: #e6e8eb;
    --bg: #f4f5f7;
    --card: #ffffff;
    --radius: 18px;
    --radius-sm: 12px;
    --shadow: 0 6px 24px rgba(16, 40, 30, 0.06);
    --shadow-sm: 0 2px 10px rgba(16, 40, 30, 0.05);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Tajawal', system-ui, -apple-system, 'Segoe UI', Tahoma, sans-serif;
    background: var(--bg);
    color: var(--ink);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { margin: 0 0 .4rem; font-weight: 800; }

/* -------------------- الشعار -------------------- */
.brand { display: inline-flex; align-items: center; gap: .5rem; }
.brand-mark { font-size: 1.5rem; }
.brand-name { font-weight: 800; font-size: 1.35rem; color: var(--green); }

/* -------------------- رأس التطبيق -------------------- */
.app-header {
    position: sticky; top: 0; z-index: 40;
    background: var(--card);
    border-bottom: 1px solid var(--line);
}
.app-header-inner {
    max-width: 720px; margin: 0 auto;
    padding: .8rem 1.1rem;
    display: flex; align-items: center; justify-content: space-between;
}
.header-actions { display: flex; align-items: center; gap: .6rem; }
.role-chip {
    background: var(--green-light); color: var(--green-dark);
    padding: .35rem .75rem; border-radius: 999px;
    font-size: .85rem; font-weight: 700;
}
.icon-btn {
    position: relative; width: 42px; height: 42px;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--green-soft); border-radius: 12px; font-size: 1.15rem;
    border: none; cursor: pointer;
}
.badge {
    position: absolute; top: -4px; inset-inline-start: -4px;
    background: var(--red); color: #fff;
    min-width: 18px; height: 18px; padding: 0 4px;
    border-radius: 999px; font-size: .7rem; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
}

/* -------------------- المحتوى -------------------- */
.app-main {
    max-width: 720px; margin: 0 auto;
    /* مساحة سفلية تكفي لظهور آخر زر كاملًا فوق الشريط السفلي الثابت مع فراغ بسيط فقط
       (‏6.5rem ≈ ارتفاع الشريط + فجوة صغيرة، إضافةً إلى safe-area على iPhone) */
    padding: 1.1rem 1.1rem calc(6.5rem + env(safe-area-inset-bottom));
}

/* -------------------- الرسائل الومضية -------------------- */
.flash {
    display: flex; align-items: center; gap: .6rem;
    padding: .8rem 1rem; border-radius: var(--radius-sm);
    margin-bottom: 1rem; font-weight: 500; font-size: .95rem;
    border: 1px solid transparent;
}
.flash-ico {
    width: 24px; height: 24px; flex: 0 0 24px;
    border-radius: 50%; display: flex; align-items: center; justify-content: center;
    font-weight: 800; color: #fff;
}
.flash-success { background: var(--green-light); color: var(--green-dark); border-color: #bfe3cd; }
.flash-success .flash-ico { background: var(--green); }
.flash-error { background: var(--red-light); color: #922; border-color: #f3c9c4; }
.flash-error .flash-ico { background: var(--red); }
.flash-info { background: var(--amber-light); color: #8a5a08; border-color: #f2e0b8; }
.flash-info .flash-ico { background: var(--amber); }

/* -------------------- البطاقات -------------------- */
.card {
    background: var(--card); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 1.1rem 1.2rem;
    margin-bottom: 1rem; border: 1px solid #f0f1f3;
}

.page-head {
    display: flex; align-items: center; justify-content: space-between;
    margin: .3rem 0 1.1rem; flex-wrap: wrap; gap: .8rem;
}
.page-head h1 { font-size: 1.6rem; }

/* -------------------- الأزرار -------------------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
    padding: .7rem 1.2rem; border-radius: 12px;
    font-family: inherit; font-weight: 700; font-size: .95rem;
    border: none; cursor: pointer; transition: .15s; text-align: center;
    white-space: nowrap;              /* نص الزر في سطر واحد دائمًا */
}
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:hover { background: var(--green-dark); }
.btn-outline { background: #fff; color: var(--green); border: 1.5px solid var(--green); }
.btn-outline:hover { background: var(--green-soft); }
.btn-amber { background: var(--amber); color: #fff; }
.btn-amber:hover { filter: brightness(.95); }
.btn-danger { background: #fff; color: var(--red); border: 1.5px solid #ecc4bf; }
.btn-danger:hover { background: var(--red-light); }
.btn-ghost { background: var(--green-soft); color: var(--green-dark); }
.btn-block { width: 100%; }
.btn-sm { padding: .5rem .85rem; font-size: .85rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* -------------------- الإحصائيات -------------------- */
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .7rem; margin-bottom: 1.1rem; }
.stat {
    background: var(--green-soft); border-radius: var(--radius-sm);
    padding: .95rem .6rem; text-align: center;
}
.stat.amber { background: var(--amber-light); }
.stat-ico {
    width: 42px; height: 42px; margin: 0 auto .5rem;
    border-radius: 50%; background: #fff;
    display: flex; align-items: center; justify-content: center; font-size: 1.2rem;
}
.stat-label { color: var(--muted); font-size: .82rem; }
.stat-value { font-weight: 800; font-size: 1.05rem; margin-top: .15rem; }
.stat-value.green { color: var(--green-dark); }
.stat-value.amber { color: var(--amber); }

/* -------------------- بطاقة العقد -------------------- */
.contract-card { padding: 0; overflow: hidden; }
.contract-body { padding: 1.1rem 1.2rem; }
.contract-top { display: flex; justify-content: space-between; align-items: flex-start; gap: .6rem; }
.contract-title { font-size: 1.2rem; font-weight: 800; }
.contract-sub { color: var(--muted); font-size: .9rem; display: flex; align-items: center; gap: .35rem; margin-top: .1rem; }
.status-dot {
    display: inline-flex; align-items: center; gap: .35rem;
    background: var(--green-light); color: var(--green-dark);
    padding: .3rem .7rem; border-radius: 999px; font-size: .8rem; font-weight: 700;
}
.status-dot::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--green); }
.status-dot.expired { background: #eef0f2; color: var(--muted); }
.status-dot.expired::before { background: var(--muted); }

.money-row { display: flex; align-items: center; gap: .5rem; margin-top: 1rem; }
.money-col { flex: 1 1 0; min-width: 0; }
.money-col-left { text-align: end; }
.money-col .lbl { color: var(--muted); font-size: .8rem; white-space: nowrap; }
.money-col .val { font-weight: 800; font-size: 1rem; margin-top: .15rem; white-space: nowrap; }
.val.green { color: var(--green-dark); }
.val.amber { color: var(--amber); }

/* دائرة تقدّم صغيرة داخل بطاقة العقد */
.ring.ring-sm { --size: 66px; flex: 0 0 66px; }
.ring.ring-sm::before { inset: 8px; }
.ring.ring-sm span { font-size: .82rem; }

/* --------------------------------------------------------------------------
   قوس المدة الزمنية للدفعة الحالية
   خط أخضر رقيق (3px مقابل 8px لخط الدائرة) خارج دائرة السداد وشبه ملاصق لها.
   يبدأ من نهاية الجزء الأخضر ويطول مع مضيّ مدة الدفعة فيكتمل عند موعد استحقاقها.
   يُرسَم بموضع مطلق، فلا يؤثّر على تخطيط البطاقة إطلاقًا.
   -------------------------------------------------------------------------- */
/* حلقة مقسّمة بأجزاء: كل دفعة جزء بلونها الخاص */
.ring.ring-seg { background: none; }        /* الأجزاء تُرسَم بـ SVG بدل التدرّج المخروطي */
.ring.ring-seg::before { display: none; }   /* لا حاجة للقرص الأبيض الداخلي */
.ring .ring-svg {
    position: absolute; top: -8px; left: -8px;
    width: calc(var(--size) + 16px); height: calc(var(--size) + 16px);
    transform: rotate(-90deg);              /* يبدأ من أعلى الدائرة */
    pointer-events: none; overflow: visible;
}
.ring .ring-svg circle { fill: none; stroke-linecap: butt; }
.ring .ring-svg .seg-track { stroke: #eef0f2; }
.ring .ring-svg .seg.is-paid    { stroke: var(--green); }
.ring .ring-svg .seg.is-pending { stroke: var(--amber); }
.ring .ring-svg .seg.is-overdue { stroke: var(--red); }
.ring .ring-svg .seg.is-future  { stroke: #eef0f2; }

.ring .time-arc {
    position: absolute; top: -8px; left: -8px;
    width: 82px; height: 82px;
    transform: rotate(-90deg);          /* يبدأ من أعلى الدائرة مثل الجزء الأخضر */
    pointer-events: none; overflow: visible;
}
.ring .time-arc circle {
    fill: none;
    stroke: var(--time-arc, #5ba87f);   /* أخضر أفتح من خط الدائرة ليتميّز عنه */
    stroke-width: 3;
    stroke-linecap: round;
}
.ring .time-arc.is-overdue circle { stroke: var(--red); }

/* سطر موعد الدفعة القادمة أسفل الدائرة */
.due-hint {
    margin-top: .8rem; display: flex; align-items: center; gap: .4rem; flex-wrap: wrap;
    background: var(--green-soft); border: 1px solid #d8ebe1; color: var(--green-dark);
    border-radius: 11px; padding: .45rem .8rem; font-size: .82rem; font-weight: 700;
}
.due-hint .dh-date { color: var(--muted); font-weight: 600; font-size: .78rem; }
.due-hint.is-overdue { background: var(--red-light); border-color: #f4cfcb; color: #a3271b; }
.due-hint.is-overdue .dh-date { color: #b06054; }

/* -------------------- تعديل مبلغ الدفعة القادمة بالضغط عليه -------------------- */
.pay-amount-form {
    display: inline-flex; align-items: center; gap: .25rem;
    margin: 0; white-space: nowrap;
}
.pay-amount-input {
    width: 6.6rem; padding: .32rem .45rem;
    font-family: inherit; font-weight: 800; font-size: 1rem; color: var(--ink);
    text-align: center; background: var(--green-soft);
    border: 1.5px dashed #bfe3cd; border-radius: 9px;
    /* يبدو كنصّ حتى يُضغط عليه */
    -moz-appearance: textfield;
}
.pay-amount-input::-webkit-outer-spin-button,
.pay-amount-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.pay-amount-input:hover { border-color: var(--green); }
.pay-amount-input:focus {
    outline: none; background: #fff;
    border-style: solid; border-color: var(--green);
    box-shadow: 0 0 0 3px rgba(14, 122, 75, .12);
}
.pay-amount-input.is-saving { opacity: .55; }
.pay-amount-cur { font-size: .78rem; font-weight: 700; color: var(--muted); }

/* -------------------- طلبات انضمام تنتظر الموافقة -------------------- */
.pending-requests {
    background: var(--amber-light); border: 1px solid #f2e0b8;
    border-radius: 12px; padding: .8rem .9rem;
}
.pending-requests .pr-title { margin: 0 0 .2rem; font-size: .96rem; color: #8a5a08; }
.pr-item {
    display: flex; align-items: center; justify-content: space-between; gap: .7rem; flex-wrap: wrap;
    background: var(--card); border: 1px solid #f0e3c4; border-radius: 10px;
    padding: .6rem .75rem; margin-top: .5rem;
}
.pr-info { min-width: 0; flex: 1 1 140px; }
.pr-name { font-weight: 800; font-size: .92rem; }
.pr-meta { color: var(--muted); font-size: .8rem; }
.pr-actions { display: flex; gap: .45rem; flex-wrap: wrap; }
.pr-actions form { margin: 0; }

/* -------------------- مسح QR مباشر من الكاميرا -------------------- */
.qr-live {
    position: relative; margin: .9rem auto 0; width: 100%; max-width: 320px;
    aspect-ratio: 1 / 1; border-radius: 16px; overflow: hidden;
    background: #0b0f0d; box-shadow: var(--shadow-sm);
}
.qr-video { width: 100%; height: 100%; object-fit: cover; display: block; }
/* إطار توجيه في المنتصف — نفس المربّع الذي نفكّ ترميزه */
.qr-frame {
    position: absolute; inset: 14%;
    border: 3px solid rgba(255, 255, 255, .92); border-radius: 14px;
    box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .28);
}
.scan-msg {
    margin-top: .6rem; text-align: center; font-size: .86rem; font-weight: 700;
    color: var(--muted);
}
.scan-msg.is-ok  { color: var(--green-dark); }
.scan-msg.is-err { color: var(--red); }
.scan-btns { display: flex; gap: .6rem; justify-content: center; flex-wrap: wrap; }

/* -------------------- السحب على الدفعة لإلغاء الدفع -------------------- */
.pay-swipe { position: relative; overflow: hidden; border-radius: var(--radius-sm); margin-bottom: .6rem; }
.pay-swipe .pay-item { margin-bottom: 0; }
.pay-swipe-form { display: none; }

/* لوحة الإجراء تحت الصفّ — تظهر من الجهة الخلفية حسب اتجاه اللغة */
.pay-swipe-action {
    position: absolute; inset-block: 0; inset-inline-start: 0; width: 100%;
    background: var(--red); color: #fff; border-radius: var(--radius-sm);
    display: flex; align-items: center; gap: .5rem;
    padding-inline-start: 1.1rem;
    font-weight: 800; font-size: .92rem;
}
.pay-swipe-action .psa-ico { font-size: 1.15rem; }

/* الصفّ نفسه ينزلق فوق اللوحة */
.pay-swipe .pay-item.is-swipeable {
    position: relative; z-index: 1;
    transition: transform .18s ease;
    touch-action: pan-y;                 /* يسمح بالتمرير العمودي الطبيعي */
    cursor: grab;
}
.pay-swipe.is-dragging .pay-item.is-swipeable { transition: none; }
.pay-swipe.is-armed .pay-item.is-swipeable {
    transform: translateX(var(--swipe-open, 0px));
}

/* شريط التراجع بعد إلغاء الدفع */
.undo-bar {
    display: flex; align-items: center; justify-content: space-between; gap: .8rem;
    background: var(--ink); color: #fff; border-radius: 12px;
    padding: .6rem .9rem; margin-bottom: .8rem;
    font-size: .88rem; font-weight: 700;
    transition: opacity .3s, transform .3s;
}
.undo-bar.is-gone { opacity: 0; transform: translateY(-6px); pointer-events: none; }
.undo-btn {
    background: transparent; color: #ffd479; border: 1.5px solid #ffd479;
    border-radius: 999px; padding: .3rem .8rem; font-weight: 800; font-size: .85rem;
    font-family: inherit; cursor: pointer; white-space: nowrap;
}

/* -------------------- مبدّل اللغة (أعلام) -------------------- */
.lang-switch { display: flex; gap: .5rem; justify-content: center; flex-wrap: wrap; }
.lang-btn {
    display: inline-flex; align-items: center; gap: .45rem;
    padding: .42rem .85rem; border-radius: 999px;
    border: 1.5px solid var(--line); background: var(--card);
    font-size: .86rem; font-weight: 700; color: var(--muted);
    transition: border-color .15s, color .15s, background .15s;
}
.lang-btn:hover { border-color: #cfe6d8; color: var(--green-dark); }
.lang-btn.is-active { border-color: var(--green); background: var(--green-light); color: var(--green-dark); }
.lang-btn .flag {
    display: inline-flex; width: 22px; height: 15px; flex: 0 0 22px;
    border-radius: 3px; overflow: hidden; box-shadow: 0 0 0 1px rgba(0, 0, 0, .12);
}
.lang-btn .flag svg { width: 100%; height: 100%; display: block; }
.lang-switch.on-guest { margin-bottom: 1.1rem; }
.lang-switch.in-card { justify-content: flex-start; }

.pending-banner {
    margin-top: .9rem; background: var(--amber-light); color: #8a5a08;
    border: 1px solid #f2e0b8; border-radius: 12px;
    padding: .6rem .9rem; font-weight: 700; font-size: .9rem;
    display: flex; align-items: center; gap: .5rem;
}

.card-actions {
    display: flex; align-items: stretch; gap: .6rem;
    border-top: 1px solid var(--line); padding: .8rem .9rem;
}
.ca-btn {
    flex: 1 1 0; display: inline-flex; align-items: center; justify-content: center;
    gap: .4rem; font-size: .92rem; font-weight: 700;
    padding: .7rem .6rem; border-radius: 12px; text-align: center;
    border: 1.5px solid transparent; transition: background .15s, border-color .15s;
}
.ca-primary { background: var(--green); color: #fff; }
.ca-primary:hover { background: var(--green-dark); }
.ca-outline { background: #fff; color: var(--green-dark); border-color: #cfe6d8; }
.ca-outline:hover { background: var(--green-soft); }

/* -------------------- بطاقة حذف الحساب -------------------- */
.danger-card { border: 1px solid #f3c9c4; background: #fff8f7; }
.danger-title { color: #b3261e; }
.danger-text { color: #7a2a24; font-size: .9rem; line-height: 1.7; margin: .2rem 0 1rem; }

/* -------------------- تفاصيل العقد -------------------- */
.detail-list { display: grid; gap: .1rem; }
.detail-row {
    display: flex; align-items: center; justify-content: space-between;
    padding: .7rem 0; border-bottom: 1px solid var(--line);
}
.detail-row:last-child { border-bottom: none; }
.detail-label { color: var(--muted); font-size: .9rem; display: flex; align-items: center; gap: .5rem; }
.detail-value { font-weight: 700; }

/* دائرة التقدّم */
.progress-card { display: flex; align-items: center; gap: 1.1rem; }
.ring {
    --p: 0; --size: 92px;
    width: var(--size); height: var(--size); flex: 0 0 var(--size);
    border-radius: 50%;
    background: conic-gradient(var(--green) calc(var(--p) * 1%), #eef0f2 0);
    display: flex; align-items: center; justify-content: center;
    position: relative;
}
.ring::before {
    content: ''; position: absolute; inset: 10px; background: #fff; border-radius: 50%;
}
.ring span { position: relative; font-weight: 800; color: var(--green-dark); font-size: 1.05rem; }
.progress-figures { display: flex; gap: 1.4rem; flex: 1; }
.progress-figures .fig .lbl { color: var(--muted); font-size: .82rem; }
.progress-figures .fig .val { font-weight: 800; font-size: 1.1rem; }

/* -------------------- جدول الدفعات -------------------- */
.section-title { font-size: 1.15rem; margin: 1.4rem 0 .8rem; }
.pay-item {
    display: flex; align-items: center; gap: .7rem;
    background: var(--card); border: 1px solid #f0f1f3;
    border-radius: var(--radius-sm); padding: .8rem .9rem; margin-bottom: .6rem;
    box-shadow: var(--shadow-sm);
}
.pay-index {
    width: 30px; height: 30px; flex: 0 0 30px;
    border-radius: 50%; border: 2px solid var(--line);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: .85rem; color: var(--muted);
}
.pay-item.paid .pay-index { border-color: var(--green); color: var(--green); }
.pay-item.pending .pay-index { border-color: var(--amber); color: var(--amber); }
.pay-main { flex: 1; min-width: 0; }
.pay-date { font-weight: 700; font-size: .92rem; }
.pay-method { color: var(--muted); font-size: .82rem; display: flex; align-items: center; gap: .3rem; }
.pay-amount { font-weight: 800; white-space: nowrap; }
.pay-status {
    padding: .3rem .7rem; border-radius: 999px; font-size: .78rem; font-weight: 700; white-space: nowrap;
}
.pay-status.paid { background: var(--green-light); color: var(--green-dark); }
.pay-status.pending { background: var(--amber-light); color: #8a5a08; }
.pay-status.due { background: #eef0f2; color: var(--muted); }
.pay-actions { display: flex; gap: .3rem; margin-top: .5rem; flex-wrap: wrap; }

/* -------------------- النماذج -------------------- */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-weight: 700; font-size: .9rem; margin-bottom: .4rem; }
.form-control {
    width: 100%; padding: .75rem .9rem;
    border: 1.5px solid var(--line); border-radius: 12px;
    font-family: inherit; font-size: 1rem; background: #fff; color: var(--ink);
    transition: .15s;
}
.form-control:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px var(--green-light); }
.form-hint { color: var(--muted); font-size: .82rem; margin-top: .35rem; }
.form-row { display: flex; gap: .8rem; flex-wrap: nowrap; }
.form-row .form-group { flex: 1 1 0; min-width: 0; }         /* min-width:0 يمنع تجاوز الحقول (خصوصًا التاريخ) */
.form-row .form-group.col-2of3 { flex: 2 1 0; }
.form-row .form-group.col-1of3 { flex: 1 1 0; }
.form-control { min-width: 0; max-width: 100%; }
/* حقول التاريخ داخل الصفوف لا تتجاوز عرض الشاشة على iOS */
input[type="date"].form-control { min-width: 0; width: 100%; -webkit-appearance: none; appearance: none; }
select.form-control { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%236b7280' d='M6 8 0 2l1.4-1.4L6 5.2 10.6.6 12 2z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: left 1rem center; }

/* اختيار الدور */
.role-select { display: flex; gap: .7rem; }
.role-option {
    flex: 1; border: 1.5px solid var(--line); border-radius: 14px;
    padding: .9rem; text-align: center; cursor: pointer; transition: .15s;
    font-weight: 700;
}
.role-option input { position: absolute; opacity: 0; }
.role-option .r-ico { font-size: 1.6rem; display: block; margin-bottom: .3rem; }
.role-option:has(input:checked) { border-color: var(--green); background: var(--green-soft); color: var(--green-dark); }

/* -------------------- تخطيط الضيوف (دخول/تسجيل) -------------------- */
body.is-guest { overscroll-behavior-y: none; }
.guest-wrap {
    min-height: 100vh;            /* احتياطي للمتصفحات القديمة */
    min-height: 100dvh;          /* يملأ الشاشة بثبات مع/بدون لوحة المفاتيح */
    display: flex; align-items: flex-start; justify-content: center;
    padding: max(6vh, 1.4rem) 1.2rem 1.4rem;
    background: linear-gradient(160deg, var(--green-soft), var(--bg));
    overscroll-behavior: none;
}
@media (min-width: 700px) {
    .guest-wrap { align-items: center; padding-top: 1.4rem; }
}
.guest-card {
    background: var(--card); width: 100%; max-width: 420px;
    border-radius: 22px; box-shadow: var(--shadow); padding: 1.8rem 1.6rem;
}
.guest-card .brand { justify-content: center; margin-bottom: 1.2rem; }
.guest-card h1 { text-align: center; font-size: 1.4rem; }
.guest-card .subtitle { text-align: center; color: var(--muted); margin-bottom: 1.4rem; font-size: .92rem; }
.auth-links { text-align: center; margin-top: 1.1rem; font-size: .9rem; color: var(--muted); }
.auth-links a { color: var(--green); font-weight: 700; }

/* -------------------- شريط سفلي -------------------- */
.bottom-nav {
    position: fixed; bottom: 0; inset-inline: 0; z-index: 40;
    background: var(--card); border-top: 1px solid var(--line);
    display: flex; justify-content: space-around;
    padding: .5rem .5rem calc(.5rem + env(safe-area-inset-bottom));
    max-width: 720px; margin: 0 auto;
}
.nav-item {
    display: flex; flex-direction: column; align-items: center; gap: .15rem;
    color: var(--muted); font-size: .72rem; font-weight: 600; padding: .3rem .8rem; border-radius: 12px;
}
.nav-item .nav-ico { font-size: 1.25rem; }
.nav-item.is-active { color: var(--green); }

/* -------------------- المشاركة والرمز -------------------- */
.share-box {
    background: var(--green-soft); border: 1px dashed #bfe3cd;
    border-radius: 14px; padding: 1rem; text-align: center; margin-top: 1rem;
}
.share-code {
    font-size: 1.6rem; font-weight: 800; letter-spacing: .25rem;
    color: var(--green-dark); font-family: 'Tajawal', monospace; direction: ltr;
}

/* -------------------- مسح QR في صفحة الانضمام -------------------- */
.scan-btns { display: flex; flex-direction: column; gap: .5rem; margin: .7rem 0; }
.scan-btns .btn { width: 100%; }
.scan-msg { margin-top: .7rem; padding: .6rem .85rem; border-radius: 10px; font-size: .86rem; font-weight: 600; }
.scan-msg.scan-ok { background: var(--green-light); color: var(--green-dark); }
.scan-msg.scan-err { background: var(--red-light); color: #922; }

/* -------------------- QR -------------------- */
.qr-wrap { display: flex; gap: 1rem; align-items: center; margin-top: 1rem; flex-wrap: wrap; }
.qr-box {
    width: 150px; height: 150px; flex: 0 0 150px;
    background: #fff; border: 1px solid var(--line); border-radius: 14px;
    padding: 8px; display: flex; align-items: center; justify-content: center;
}
.qr-box svg { width: 100%; height: 100%; }

/* -------------------- الرسائل (المحادثة) -------------------- */
.chat {
    display: flex; flex-direction: column; gap: .55rem;
    max-height: 55vh; overflow-y: auto; padding: .3rem;
}
.msg { max-width: 78%; padding: .6rem .85rem; border-radius: 16px; font-size: .93rem; line-height: 1.55; }
.msg .meta { font-size: .72rem; opacity: .7; margin-top: .25rem; }
.msg.mine { align-self: flex-start; background: var(--green); color: #fff; border-bottom-right-radius: 5px; }
.msg.theirs { align-self: flex-end; background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 5px; }
.chat-form { display: flex; gap: .5rem; margin-top: .8rem; }
.chat-form textarea {
    flex: 1; resize: none; border: 1.5px solid var(--line); border-radius: 14px;
    padding: .7rem .9rem; font-family: inherit; font-size: .95rem;
}
.chat-form textarea:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px var(--green-light); }

/* -------------------- روابط الإجراءات في شاشة العقد -------------------- */
.action-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(80px, 1fr)); gap: .6rem; margin: 1rem 0; }
.action-tile {
    position: relative; background: var(--card); border: 1px solid #f0f1f3; border-radius: 14px;
    padding: .85rem .4rem; text-align: center; box-shadow: var(--shadow-sm);
    display: flex; flex-direction: column; align-items: center; gap: .3rem;
    font-weight: 700; font-size: .82rem; color: var(--green-dark);
}
.action-tile .t-ico { font-size: 1.4rem; }
/* صف زرّي حفظ/حذف — يبقيان في سطر واحد على الموبايل */
.form-btn-row { display: flex; gap: .6rem; margin-top: .3rem; }
.form-btn-row .btn { flex: 1 1 0; min-width: 0; white-space: nowrap; }

/* شارة «مؤرشف» + تكديس الحالة */
.status-stack { display: flex; flex-direction: column; align-items: flex-end; gap: .35rem; }
.archived-pill {
    display: inline-flex; align-items: center; gap: .3rem;
    background: #eef0f2; color: #52606d; border: 1px solid #dfe3e8;
    padding: .28rem .6rem; border-radius: 999px; font-size: .76rem; font-weight: 800; white-space: nowrap;
}
.contract-card.is-archived { opacity: .82; }
.contract-card.is-archived .contract-title { color: #52606d; }
.archived-hint {
    background: #eef0f2; color: #52606d; border: 1px solid #dfe3e8;
    border-radius: 12px; padding: .6rem .9rem; margin-bottom: 1rem; font-size: .84rem; font-weight: 600;
}

/* مبدّل (Toggle) الإعدادات */
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; cursor: pointer; }
.toggle-title { display: block; font-weight: 700; }
.toggle-hint { display: block; color: var(--muted); font-size: .82rem; margin-top: .2rem; font-weight: 400; }
.switch { position: relative; flex: 0 0 auto; width: 52px; height: 30px; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .slider {
    position: absolute; inset: 0; background: #cbd2d9; border-radius: 999px; transition: .2s;
}
.switch .slider::before {
    content: ''; position: absolute; width: 24px; height: 24px; border-radius: 50%;
    background: #fff; top: 3px; inset-inline-start: 3px; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.switch input:checked + .slider { background: var(--green); }
.switch input:checked + .slider::before { transform: translateX(-22px); }

.viewonly-badge {
    display: flex; align-items: center; gap: .5rem;
    background: var(--green-soft); color: var(--green-dark);
    border: 1px solid #bfe3cd; border-radius: 12px;
    padding: .6rem .9rem; margin-bottom: 1rem; font-size: .86rem; font-weight: 600;
}
.action-tile.share-tile { background: var(--green); color: #fff; border-color: var(--green); }
.action-tile.share-tile .t-ico { filter: none; }
.action-tile .badge { top: 6px; inset-inline-start: 6px; }
.related-link {
    display: flex; align-items: center; justify-content: space-between;
    padding: .6rem .2rem; border-bottom: 1px solid var(--line); font-size: .9rem;
}
.related-link:last-child { border-bottom: none; }

/* -------------------- تخطيط صفحة العقد (عمود جانبي على الكمبيوتر) -------------------- */
.app-main.wide { max-width: 1060px; }

.contract-grid { display: grid; grid-template-columns: 1fr; gap: 1rem; align-items: start; }
.contract-main { min-width: 0; }

@media (min-width: 900px) {
    .contract-grid.has-aside { grid-template-columns: minmax(0, 1fr) 330px; }
    .contract-grid.has-aside .contract-main { order: 1; }
    .contract-grid.has-aside .contract-aside { order: 2; position: sticky; top: 82px; }
}

/* بطاقة المشاركة */
.share-panel { margin-bottom: 0; }
.share-head { display: flex; align-items: center; gap: .5rem; margin-bottom: .5rem; }
.share-head h3 { margin: 0; font-size: 1.05rem; }
.share-head-ico { font-size: 1.2rem; }
.share-sub { font-size: .82rem; }
.qr-center { margin: .5rem auto .9rem; }
.qr-holder { text-align: center; margin: .6rem 0 .9rem; line-height: 0; }
.qr-holder img { display: inline-block; }
.code-box {
    background: var(--green-soft); border: 1px dashed #bfe3cd; border-radius: 12px;
    padding: .8rem; text-align: center; margin-bottom: .8rem;
}
.link-field { margin-bottom: .4rem; }
.link-field .form-control { margin: .25rem 0 .5rem; }
.link-btns { display: flex; gap: .4rem; flex-wrap: wrap; }
.link-btns .btn { flex: 1; white-space: nowrap; }
.share-manage { display: flex; flex-direction: column; gap: .5rem; }
.view-only-note {
    text-align: center; color: var(--muted); font-size: .8rem; margin-top: .8rem;
    background: #f6f7f8; border-radius: 10px; padding: .4rem;
}

/* -------------------- الإشعارات -------------------- */
.notif-item {
    display: flex; gap: .7rem; align-items: flex-start;
    padding: .85rem 0; border-bottom: 1px solid var(--line);
}
.notif-item:last-child { border-bottom: none; }
.notif-ico {
    width: 38px; height: 38px; flex: 0 0 38px; border-radius: 50%;
    background: var(--green-light); display: flex; align-items: center; justify-content: center; font-size: 1.1rem;
}
.notif-item.unread .notif-ico { background: var(--amber-light); }
.notif-msg { font-size: .93rem; }
.notif-time { color: var(--muted); font-size: .78rem; margin-top: .15rem; }

/* -------------------- حالة فارغة -------------------- */
.empty {
    text-align: center; padding: 2.5rem 1rem; color: var(--muted);
}
.empty .emoji { font-size: 2.6rem; display: block; margin-bottom: .6rem; }

/* دفعة مقفلة (ترتيب إلزامي) */
.pay-locked {
    color: var(--muted); font-size: .82rem; font-weight: 600;
    background: #f4f5f7; border: 1px dashed #dfe3e8; border-radius: 10px;
    padding: .45rem .7rem; display: inline-flex; align-items: center; gap: .35rem;
}

/* الشريط الجانبي والتنقّل العلوي — مخفيان على الموبايل */
.top-nav { display: none; }
.side-nav { display: none; }

/* ============ تنسيق الكمبيوتر (Desktop) — شريط جانبي كلوحة تحكم ============ */
@media (min-width: 992px) {
    /* إخفاء عناصر الموبايل */
    .app-header, .bottom-nav, .top-nav { display: none; }

    /* الشريط الجانبي (يمين في RTL) */
    .side-nav {
        display: flex; flex-direction: column;
        position: fixed; top: 0; inset-inline-end: 0; width: 246px; height: 100vh;
        background: linear-gradient(180deg, #0e5236, #0a3b28);
        color: #eafff3; padding: 1.3rem 1rem; z-index: 60;
        box-shadow: -2px 0 14px rgba(0, 0, 0, .12);
    }
    .side-brand { display: flex; align-items: center; gap: .5rem; padding: .2rem .5rem 1.3rem; }
    .side-brand .brand-mark { font-size: 1.5rem; }
    .side-brand .brand-name { color: #fff; font-size: 1.4rem; font-weight: 800; }
    .side-links { display: flex; flex-direction: column; gap: .28rem; }
    .side-link {
        display: flex; align-items: center; gap: .7rem;
        padding: .72rem .85rem; border-radius: 12px; color: #cfeadd; font-weight: 600; font-size: .98rem;
    }
    .side-link .side-ico { font-size: 1.1rem; width: 1.4rem; text-align: center; }
    .side-link:hover { background: rgba(255, 255, 255, .08); color: #fff; }
    .side-link.is-active { background: rgba(255, 255, 255, .16); color: #fff; }
    .side-badge {
        background: var(--red); color: #fff; border-radius: 999px; font-size: .7rem; font-weight: 700;
        min-width: 18px; height: 18px; padding: 0 .35rem; display: inline-flex; align-items: center;
        justify-content: center; margin-inline-start: auto;
    }
    .side-account {
        margin-top: auto; display: flex; align-items: center; gap: .6rem;
        padding: .8rem .5rem 0; border-top: 1px solid rgba(255, 255, 255, .14);
    }
    .acct-ico {
        width: 38px; height: 38px; flex: 0 0 38px; border-radius: 50%;
        background: rgba(255, 255, 255, .16); display: flex; align-items: center; justify-content: center; font-size: 1.1rem;
    }
    .acct-name { font-weight: 700; color: #fff; font-size: .92rem; }
    .acct-role { color: #a9d6c2; font-size: .78rem; }

    /* منطقة المحتوى بجانب الشريط */
    .app-main, .app-main.wide {
        margin-inline-end: 246px; margin-inline-start: 0; max-width: 1200px;
        padding: 1.9rem 2rem 2.5rem;
    }

    /* قائمة العقود: شبكة بطاقات واسعة */
    .contracts-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1.1rem; align-items: start; }
    .stats-grid { max-width: 820px; }

    /* صفحة العقد: عمودان مريحان */
    .contract-grid.has-aside { grid-template-columns: minmax(0, 1fr) 340px; gap: 1.4rem; }
    .contract-aside { position: sticky; top: 1.4rem; }

    /* ملخّص العقد كشريط أفقي من الإحصائيات (مثل النموذج) */
    .contract-main .card:first-child .detail-list { display: flex; }
    .contract-main .card:first-child .detail-row {
        flex: 1; flex-direction: column; align-items: flex-start; gap: .25rem;
        border-bottom: none; border-inline-start: 1px solid var(--line); padding: .2rem 1.1rem;
    }
    .contract-main .card:first-child .detail-row:first-child { border-inline-start: none; padding-inline-start: 0; }

    .pay-item { padding: .95rem 1.1rem; }

    /* صفحة الرسائل: مساحة قراءة/كتابة مريحة */
    .chat { max-height: 62vh; }
    .chat-form textarea { min-height: 54px; }

    .page-head h1 { font-size: 1.75rem; }
}

/* شاشات كبيرة جدًا: عرض أوسع و3 أعمدة للعقود */
@media (min-width: 1400px) {
    .app-main, .app-main.wide { max-width: 1340px; }
    .contracts-grid { grid-template-columns: repeat(3, 1fr); }
}

.muted { color: var(--muted); }
.text-center { text-align: center; }
.mt-1 { margin-top: 1rem; } .mt-2 { margin-top: 1.5rem; }
.divider { height: 1px; background: var(--line); margin: 1.1rem 0; border: none; }

/* ==========================================================================
   حوار التأكيد الداخلي — أزراره بلغة الواجهة لا بلغة نظام الهاتف
   ========================================================================== */
.ij-dialog-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.2rem;
    background: rgba(15, 30, 24, 0.45);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
    opacity: 0;
    transition: opacity 0.16s ease;
}

.ij-dialog-overlay.is-open { opacity: 1; }

.ij-dialog {
    width: 100%;
    max-width: 360px;
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: 0 18px 50px rgba(10, 30, 22, 0.28);
    padding: 1.15rem 1.15rem 0.95rem;
    transform: translateY(10px) scale(0.98);
    transition: transform 0.16s ease;
}

.ij-dialog-overlay.is-open .ij-dialog { transform: none; }

.ij-dialog-body {
    color: var(--ink);
    font-size: 0.97rem;
    line-height: 1.65;
    max-height: 55vh;
    overflow-y: auto;
}

.ij-dialog-body p { margin: 0 0 0.35rem; }
.ij-dialog-body p:last-child { margin-bottom: 0; }
.ij-dialog-body p.is-spacer { height: 0.45rem; margin: 0; }
.ij-dialog-body p:first-child { font-weight: 700; }

.ij-dialog-actions {
    display: flex;
    gap: 0.6rem;
    margin-top: 1.05rem;
}

.ij-dialog-btn {
    flex: 1;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 700;
    padding: 0.72rem 0.6rem;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.ij-dialog-btn.is-cancel {
    background: #fff;
    border-color: var(--line);
    color: var(--muted);
}

.ij-dialog-btn.is-ok {
    background: var(--green);
    color: #fff;
}

.ij-dialog-btn.is-ok.is-danger { background: var(--red); }
.ij-dialog-btn:active { filter: brightness(0.95); }
