/* =====================================================================
   Design Tokens — مستخرجة حرفيًا من bundle تطبيق React Native الأصلي
   (الألوان/الخطوط/الأنصاف أقطار/التباعد). مرجع كامل: docs/08-frontend-views.md §13
   ===================================================================== */
:root {
  /* الهوية */
  --brand: #4A7065;
  --brand-dark: #334F46;
  --brand-secondary: #E1E8E6;
  --brand-tertiary: #F0F4F2;
  /* الحالات الدلالية (هادئة — ليست ألوان Bootstrap الزاهية) */
  --success: #3A6F54;
  --warning: #B58548;   /* كهرماني/ذهبي داكن — ليس برتقالي */
  --warning-bg: #FBEFDF;
  --error: #A84A42;     /* أحمر طوبي مكسور — ليس أحمر صريح */
  --error-bg: #F7E4E2;
  --info: #4A5854;      /* رمادي-أخضر داكن — ليس أزرق */
  --muted: #6B7876;
  --border: #E1E8E6;
  --surface: #FFFFFF;
  --surface-secondary: #F4F6F5;
  /* الأنصاف أقطار */
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-pill: 999px;
  /* التباعد */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-lg: 16px;
  --space-xl: 24px;
}
body { font-family: 'Tajawal', sans-serif; background: var(--surface-secondary); }
* { font-family: inherit; }
b, strong, .fw-bold, .fw-bolder { font-weight: 700; }
.app-topbar { background: var(--brand); }
.app-topbar .navbar-brand { min-width: 0; flex: 1 1 auto; }
html, body { max-width: 100%; overflow-x: hidden; }
.app-sidebar { width: 240px; background: #fff; border-left: 1px solid #E1E8E6; min-height: calc(100vh - 56px); }
/* min-width:0 ضروري: العنصر flex-grow داخل صف flex — بدونه يتمدّد لعرض أوسع محتوى
   (مثل شبكة الأسنان 387px) فيتجاوز الشاشة ويُقصّ الجانب. مع min-width:0 يلتزم بعرض
   الحاوية، وتتكفّل الحاويات ذات overflow-x:auto (شبكة الأسنان/الجداول) بالتمرير الداخلي. */
.app-content { min-height: calc(100vh - 56px); min-width: 0; max-width: 100%; }
.app-content > .container-fluid { max-width: 100%; }
.nav-link { color: #384541; padding: .6rem 1.2rem; border-radius: 0; }
.nav-link.active, .nav-link:hover { background: #E9F1EE; color: var(--brand-dark); font-weight: 600; }
.card { border: none; box-shadow: 0 1px 3px rgba(0,0,0,.06); border-radius: var(--radius-md); }
.app-sidebar { border-color: var(--border); }
.stat-card { border-radius: 1rem; color: #fff; }
.stat-card .num { font-size: 1.9rem; font-weight: 700; }
.btn-brand { background: var(--brand); color: #fff; }
.btn-brand:hover { background: var(--brand-dark); color: #fff; }
.tooth-grid-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px; }
.nav-tabs-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.nav-tabs-scroll .nav-tabs { border-bottom: 1px solid #dee2e6; }
.tooth-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; max-width: 480px; }
.tooth-btn { aspect-ratio: 1; border-radius: 6px; border: 1px solid #ccc; background: #fff; font-size: .7rem; cursor: pointer; touch-action: manipulation; }
/* ---- رأس صفحة "فواتير [مريض]" ---- */
.pinv-head { display: flex; align-items: center; gap: .5rem; }
.pinv-head .pinv-title { flex: 1 1 auto; text-align: center; font-weight: 700; font-size: 1.05rem; min-width: 0; }
.pinv-head .pinv-add, .circle-add {
  flex-shrink: 0; width: 40px; height: 40px; border-radius: var(--radius-pill); border: none;
  background: var(--brand); color: #fff; font-size: 1.4rem; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
.pinv-head .pinv-add:active, .circle-add:active { transform: scale(.94); }
.pinv-head .pinv-back {
  flex-shrink: 0; width: 40px; height: 40px; border-radius: var(--radius-pill);
  display: flex; align-items: center; justify-content: center;
  color: var(--brand); background: var(--brand-tertiary); text-decoration: none;
}
/* سطر في بطاقة الحالة المالية */
.fin-line { display: flex; justify-content: space-between; align-items: center; padding: .2rem 0; }
.fin-line .lbl { font-size: .85rem; color: var(--c-muted); }
.fin-line .val { font-weight: 700; }
/* حالة فارغة موحّدة (أيقونة + نص) */
.empty-hint { text-align: center; color: var(--c-muted); padding: 1.5rem .5rem; }
.empty-hint i { font-size: 1.6rem; opacity: .5; display: block; margin-bottom: .4rem; }

/* عنوان بطاقة قسم (صفحة تفاصيل المريض — بنية scroll متواصل) */
.card-sec { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; font-weight: 700; font-size: .95rem; margin-bottom: .9rem; color: #1A211E; }
.card-sec i { color: var(--brand); font-size: .9rem; }
/* سن محدَّد في مخطط الأسنان (قبل الحفظ) */
.tooth-btn.selected { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand) inset; font-weight: 700; }
/* chips اختيار الحالة في مخطط الأسنان */
.cond-chip {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .3rem .7rem; border-radius: var(--radius-pill); font-size: .78rem; font-weight: 700;
  border: 1px solid var(--chip, #9AA7A3); background: #fff; color: #1A211E; cursor: pointer;
}
.cond-chip::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--chip, #9AA7A3); }
.cond-chip.active { background: var(--chip, #9AA7A3); color: #fff; }
.table-clickable tbody tr { cursor: pointer; }
.table-clickable tbody tr:hover { background: #F0F5F3; }
/* شاشات الجوال: عمود ثابت 44px لكل سن (بدل التقلّص دون الحد الأدنى للمس) + تمرير أفقي عند الحاجة */
@media (max-width: 575.98px) {
  .tooth-grid { grid-template-columns: repeat(8, 44px); gap: 5px; max-width: none; width: max-content; }
  .tooth-btn { font-size: .75rem; min-width: 44px; min-height: 44px; }
}
@media (min-width: 992px) {
  .app-sidebar { position: sticky; top: 56px; height: calc(100vh - 56px); }
}

/* أهداف لمس مريحة (~44px) لكل الحقول وأزرار الإجراء الرئيسية، دون تكبير الأزرار الصغيرة داخل الجداول */
.form-control, .form-select, .btn:not(.btn-sm):not(.btn-link) { min-height: 2.75rem; }
textarea.form-control { min-height: 4.5rem; }
.form-check-input { width: 1.25em; height: 1.25em; }
img { max-width: 100%; height: auto; }
.list-group-item.d-flex { flex-wrap: wrap; gap: .25rem .75rem; word-break: break-word; }

@media (max-width: 575.98px) {
  .app-content > .container-fluid { padding: 1rem !important; }
}

/* =====================================================================
   Mobile UX layer — يقارب إحساس تطبيق native ضمن حدود Bootstrap 5 RTL
   (انظر docs/04-migration-decisions.md القرار 14، docs/08 §10)
   ===================================================================== */
:root {
  --c-success: var(--success);  --c-success-bg: #E4EEE9;
  --c-warning: var(--warning);  --c-warning-bg: var(--warning-bg);
  --c-danger:  var(--error);    --c-danger-bg:  var(--error-bg);
  --c-info:    var(--info);      --c-info-bg:    #E6EAE9;
  --c-brand-bg: var(--brand-tertiary);
  --c-muted:   var(--muted);     --c-muted-bg:   #EEF1F0;
  --c-orange:  var(--warning);   --c-orange-bg:  var(--warning-bg);   /* كهرماني للمصروفات/المشتريات (يطابق الأصلي) */
  --c-dark:    var(--brand-dark);
}
.tone-orange .ic { background: var(--c-orange-bg); color: var(--c-orange); }

/* =====================================================================
   البند 3 — الوضع الداكن. Bootstrap 5.3 يتكفّل بـ .table/.modal/.form-control/
   .dropdown-menu/.nav-pills عبر data-bs-theme="dark". هنا نعيد فقط تعريف
   الـ Design Tokens + الأسطح/النصوص المثبّتة يدويًا (#fff / #1A211E ...).
   ألوان الهوية والحالات (brand/warning/error/info) تبقى كما هي — مقروءة على
   خلفية داكنة لأنها متوسطة الإشراق؛ خلفياتها الشفّافة تُعتّم فقط. ===================================================================== */
:root[data-bs-theme="dark"] {
  --brand-tertiary: #22302B;
  --brand-secondary: #2A3A35;
  --border: #33403C;
  --muted: #9AA7A3;
  --surface: #1B211F;
  --surface-secondary: #121614;
  --c-text: #E8ECEA;
  /* الحالات: نُفتّح النص/الحد في الداكن لضمان تباين كافٍ فوق الخلفيات الداكنة
     المُعتَّمة (النسخ الأصلية متوسطة الإشراق تفقد التباين على تِنت داكن). */
  --success: #7FB89C;
  --warning: #E0A45C;
  --error:   #E38A7F;
  --info:    #9FB2AC;
  --success-bg: #1E2D26;
  --warning-bg: #33291B;
  --error-bg:   #3A2622;
  --c-success: var(--success);
  --c-warning: var(--warning);
  --c-danger:  var(--error);
  --c-info:    var(--info);
  --c-success-bg: #1E2D26;
  --c-warning-bg: #33291B;
  --c-danger-bg:  #3A2622;
  --c-info-bg:    #212B29;
  --c-brand-bg:   #22302B;
  --c-muted-bg:   #232B29;
  --c-orange:     var(--warning);
  --c-orange-bg:  #33291B;
}
:root { --c-text: #1A211E; }

[data-bs-theme="dark"] .app-sidebar,
[data-bs-theme="dark"] .welcome-card,
[data-bs-theme="dark"] .currency-bar,
[data-bs-theme="dark"] .fin-item,
[data-bs-theme="dark"] .net-card,
[data-bs-theme="dark"] .today-tile,
[data-bs-theme="dark"] .bottom-nav,
[data-bs-theme="dark"] .stat-tile,
[data-bs-theme="dark"] .quick-tile,
[data-bs-theme="dark"] .appt-card,
[data-bs-theme="dark"] .cond-chip,
[data-bs-theme="dark"] .tooth-btn,
[data-bs-theme="dark"] .modal.modal-sheet .modal-footer { background: var(--surface); }

[data-bs-theme="dark"] .card-sec,
[data-bs-theme="dark"] .welcome-card .wc-title,
[data-bs-theme="dark"] .fin-item .val,
[data-bs-theme="dark"] .today-tile .n,
[data-bs-theme="dark"] .stat-tile .n,
[data-bs-theme="dark"] .quick-tile,
[data-bs-theme="dark"] .cond-chip,
[data-bs-theme="dark"] .appt-card .appt-time { color: var(--c-text); }

[data-bs-theme="dark"] .nav-link { color: var(--c-text); }
[data-bs-theme="dark"] .nav-link.active,
[data-bs-theme="dark"] .nav-link:hover { background: #24332E; color: #CFE0DA; }
[data-bs-theme="dark"] .currency-bar,
[data-bs-theme="dark"] .bottom-nav,
[data-bs-theme="dark"] .app-sidebar { border-color: var(--border); }
[data-bs-theme="dark"] .table-clickable tbody tr:hover { background: #202B28; }
[data-bs-theme="dark"] .stat-grid-3 .stat-tile .ic {
  background: color-mix(in srgb, var(--_tone, var(--brand)) 22%, var(--surface));
}
/* صفوف الدفعات في قائمة الفواتير: خلفية فاتحة في الفاتح، وسطح داكن مع نص مقروء في الداكن
   (كان table-light ثابتًا فيُخفي اسم المريض الرمادي الفاتح فوق الأبيض) */
.table > tbody > tr.pay-row > * { --bs-table-bg: #F4F7F6; --bs-table-color: var(--c-text); }
[data-bs-theme="dark"] .table > tbody > tr.pay-row > * { --bs-table-bg: var(--surface-secondary); --bs-table-color: var(--c-text); }
[data-bs-theme="dark"] .table > tbody > tr.pay-row .text-muted { color: var(--muted) !important; }
/* زرّ تبديل السمة في الشريط العلوي */
.theme-toggle { background: transparent; border: 0; color: #fff; font-size: 1rem; line-height: 1; padding: .25rem .4rem; cursor: pointer; }

/* ---- بطاقة الترحيب الشخصية (أعلى لوحة التحكم — يطابق القديم) ---- */
.welcome-card {
  display: flex; align-items: center; gap: .8rem;
  background: #fff; border-radius: 1rem; padding: .85rem 1rem; margin-bottom: .9rem;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.welcome-card .wc-avatar {
  width: 46px; height: 46px; flex-shrink: 0; border-radius: 50%;
  background: var(--c-brand-bg); color: var(--brand);
  display: flex; align-items: center; justify-content: center; font-size: 1.25rem;
}
.welcome-card .wc-title { font-weight: 700; font-size: 1rem; color: #1A211E; }
.welcome-card .wc-sub { font-size: .8rem; color: var(--c-muted); }

/* ---- شريط اختيار العملة ---- */
.currency-bar {
  width: 100%; text-align: start; background: #fff; border: 1px solid #E1E8E6;
  border-radius: .75rem; padding: .6rem .9rem; font-weight: 600; color: #384541;
  display: flex; align-items: center; justify-content: space-between;
}
.currency-bar i.fa-dollar-sign { color: var(--c-success); }

/* ---- عناوين أقسام لوحة التحكم ---- */
.dash-h { display: flex; align-items: center; gap: .45rem; font-size: .95rem; font-weight: 700; margin: 1.1rem 0 .5rem; }
.dash-h i { color: var(--brand); font-size: .85rem; }

/* ---- الملخّص المالي (2×2 + صافي الربح) ---- */
.fin-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .6rem; }
.fin-item {
  background: #fff; border-radius: .9rem; padding: .7rem .8rem;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
  display: grid; grid-template-columns: auto 1fr; align-items: center;
  column-gap: .45rem; row-gap: .2rem;
}
.fin-item .dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.fin-item .lbl { font-size: .8rem; color: var(--c-muted); }
.fin-item .val { grid-column: 1 / -1; font-weight: 700; font-size: 1rem; color: #1A211E; }
.net-card {
  margin-top: .6rem; background: #fff; border-radius: .9rem; padding: .8rem 1rem;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
  display: flex; align-items: center; justify-content: space-between;
}
.net-card .val { font-weight: 800; font-size: 1.15rem; }
.net-card .val.pos { color: var(--c-success); }
.net-card .val.neg { color: var(--c-danger); }

/* ---- بطاقات "ملخّص اليوم" ---- */
.today-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; }
.today-tile {
  background: #fff; border-radius: .9rem; padding: .8rem .5rem; text-align: center;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.today-tile i { font-size: 1rem; }
.today-tile .n { font-size: 1.05rem; font-weight: 700; color: #1A211E; margin-top: .2rem; }
.today-tile .l { font-size: .68rem; color: var(--c-muted); }

/* ---- 1. شريط تنقل سفلي (جوال فقط) ---- */
.bottom-nav {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 1030;
  display: flex; background: #fff; border-top: 1px solid #E1E8E6;
  padding-bottom: env(safe-area-inset-bottom, 0);
  box-shadow: 0 -2px 10px rgba(0,0,0,.05);
}
.bottom-nav a {
  flex: 1 1 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; padding: 8px 2px 6px; min-height: 56px;
  color: var(--c-muted); text-decoration: none; font-size: .68rem; font-weight: 600;
}
.bottom-nav a i { font-size: 1.15rem; }
.bottom-nav a.active { color: var(--brand); }
.bottom-nav a.active i { transform: translateY(-1px); }
.bottom-nav a span { max-width: 100%; overflow: visible; }
@media (min-width: 992px) { .bottom-nav { display: none; } }
@media (max-width: 991.98px) {
  .app-content { padding-bottom: 72px; }   /* مساحة للشريط السفلي */
  /* أيقونة شريط تصحيح CodeIgniter (🔥) — أداة تطوير غير مقصودة في الواجهة
     وتغطّي أول عنصر في شريط التنقل السفلي ("الرئيسية"). نُخفيها على عرض الجوال
     (تبقى على الديسكتوب حيث لا يوجد شريط سفلي، وتختفي أصلًا في بيئة production). */
  #debug-icon { display: none !important; }
}

/* ---- 2. بطاقات إحصائية (Stat tiles) ----
   الجوال: عمودان (2×2 نظيف لأربع بطاقات = إحساس native)؛ 3 من sm، 4 من md.
   القرار موثّق في docs/04 القرار 15. */
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .6rem; }
@media (min-width: 576px) { .stat-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 768px) { .stat-grid { grid-template-columns: repeat(4, 1fr); gap: 1rem; } }
/* ترتيب صريح يمين→يسار لكل شبكات لوحة التحكم (لا نعتمد على وراثة dir فقط —
   بعض المتصفحات/الإضافات قد تعيد ضبط الاتجاه). أول عنصر في DOM = العمود الأيمن. */
.stat-grid, .stat-grid-3, .quick-grid, .today-grid, .fin-grid { direction: rtl; }
/* صف الإحصائيات الثلاثي في لوحة التحكم: 3 أعمدة دائمًا (يطابق الأصلي) */
.stat-grid-3 { grid-template-columns: repeat(3, 1fr) !important; }
.stat-grid-3 .stat-tile { padding: .8rem .35rem; border-radius: var(--radius-md); border-top: 3px solid var(--_tone, var(--brand)); }
.stat-grid-3 .stat-tile .n { font-size: 1.3rem; }
/* صندوق الأيقونة: مربع مدوّر 32×32 (ليس دائرة) + خلفية = اللون بشفافية ~13% */
.stat-grid-3 .stat-tile .ic {
  width: 32px; height: 32px; border-radius: 10px; margin-bottom: .4rem;
  background: color-mix(in srgb, var(--_tone, var(--brand)) 13%, #fff);
  color: var(--_tone, var(--brand));
}
.stat-grid-3 .tone-orange   { --_tone: var(--warning); }
.stat-grid-3 .tone-warning  { --_tone: var(--warning); }
.stat-grid-3 .tone-info     { --_tone: var(--info); }
.stat-grid-3 .tone-success  { --_tone: var(--success); }
.stat-grid-3 .tone-brand    { --_tone: var(--brand); }
.stat-grid-3 .tone-danger   { --_tone: var(--error); }
.min-w-0 { min-width: 0; }
.stat-tile {
  background: #fff; border-radius: 1rem; padding: .9rem .6rem; text-align: center;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.stat-tile .ic {
  width: 42px; height: 42px; border-radius: 50%; margin: 0 auto .5rem;
  display: flex; align-items: center; justify-content: center; font-size: 1.05rem;
}
.stat-tile .n { font-size: 1.5rem; font-weight: 700; line-height: 1.1; color: #1A211E; }
.stat-tile .l { font-size: .72rem; color: var(--c-muted); margin-top: 2px; }
.tone-success .ic { background: var(--c-success-bg); color: var(--c-success); }
.tone-warning .ic { background: var(--c-warning-bg); color: var(--c-warning); }
.tone-danger  .ic { background: var(--c-danger-bg);  color: var(--c-danger); }
.tone-info    .ic { background: var(--c-info-bg);    color: var(--c-info); }
.tone-brand   .ic { background: var(--c-brand-bg);   color: var(--brand); }

/* ---- 3. شبكة اختصارات سريعة ---- */
.quick-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .6rem; }
@media (min-width: 768px) { .quick-grid { grid-template-columns: repeat(3, 1fr); } }
.quick-tile {
  background: #fff; border-radius: 1rem; padding: 1rem .75rem; text-align: center;
  box-shadow: 0 1px 3px rgba(0,0,0,.06); color: #1A211E; text-decoration: none;
  display: flex; flex-direction: column; align-items: center; gap: .5rem; font-weight: 600; font-size: .82rem;
}
.quick-tile { border-radius: var(--radius-md); }
.quick-tile:active { transform: scale(.97); }
.quick-tile i {
  width: 40px; height: 40px; border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem; color: var(--brand); background: var(--brand-tertiary);
}

/* ---- 4. تبويبات Pills ممتلئة ---- */
.nav-pills { gap: .4rem; }
.nav-pills .nav-link {
  border-radius: var(--radius-pill); padding: .4rem 1rem; font-size: .85rem; font-weight: 600;
  color: var(--c-muted); background: var(--c-muted-bg);
}
.nav-pills .nav-link.active { background: var(--brand); color: #fff; }

/* ---- 5. Status chips موحّدة ---- */
.chip {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .15rem .6rem; border-radius: var(--radius-pill); font-size: .74rem; font-weight: 700;
  border: 1px solid transparent; white-space: nowrap;
}
.chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.chip-success   { color: var(--c-success); background: var(--c-success-bg); border-color: var(--c-success); }
.chip-warning   { color: var(--c-warning); background: var(--c-warning-bg); border-color: var(--c-warning); }
.chip-danger    { color: var(--c-danger);  background: var(--c-danger-bg);  border-color: var(--c-danger); }
.chip-info      { color: var(--c-info);    background: var(--c-info-bg);    border-color: var(--c-info); }
.chip-secondary { color: var(--c-muted);   background: var(--c-muted-bg);   border-color: #B7C2BF; }
.chip-brand     { color: var(--brand-dark); background: var(--brand-tertiary); border-color: var(--brand); }

/* ---- المواعيد: قائمة مجمّعة حسب اليوم ---- */
.day-h { font-weight: 700; font-size: .9rem; color: var(--c-muted); margin: 1rem 0 .5rem; }
.appt-card {
  background: #fff; border-radius: var(--radius-md); box-shadow: 0 1px 3px rgba(0,0,0,.06);
  padding: .7rem .8rem; margin-bottom: .5rem;
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: .7rem; direction: rtl;
}
.appt-card .appt-time { font-weight: 700; font-size: .95rem; color: #1A211E; white-space: nowrap; }
.appt-card .appt-side { display: flex; flex-direction: column; align-items: flex-end; gap: .35rem; }

/* ---- 6. Avatars دائرية بحرف أول ---- */
.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .85rem; line-height: 1;
}
.avatar-row { display: flex; align-items: center; gap: .55rem; }
.avatar-lg { width: 60px; height: 60px; font-size: 1.5rem; background: var(--c-brand-bg); color: var(--brand); }

/* ---- 7. Bottom sheet (تحويل النوافذ المنبثقة على الجوال) ---- */
@media (max-width: 575.98px) {
  .modal.modal-sheet { padding: 0 !important; }
  .modal.modal-sheet .modal-dialog {
    position: fixed; inset-inline: 0; bottom: 0; margin: 0; max-width: 100%; width: 100%;
  }
  /* إصلاح: النماذج الطويلة (مثال: نافذة الفاتورة بحقول العملة الكثيرة) كانت تُقصّ
     بلا تمرير — max-height كانت على .modal-content فقط، بينما <form> الحاوي لـ
     .modal-body/.modal-footer ليس flex فينمو بلا حدود متجاهلاً overflow-y:auto على
     .modal-body (لا سياق ارتفاع محدود يُفعّلها). الحل: .modal-content flex column +
     overflow:hidden، و<form> الابن المباشر يصير flex column أيضًا بنفس الحدود،
     فتُصبح .modal-body وحدها القابلة للتمرير بين رأس وذيل ثابتين. */
  .modal.modal-sheet .modal-content {
    border-radius: 1.1rem 1.1rem 0 0; max-height: 88vh; overflow: hidden;
    display: flex; flex-direction: column;
  }
  .modal.modal-sheet .modal-content > form {
    display: flex; flex-direction: column; min-height: 0; overflow: hidden;
  }
  .modal.modal-sheet .modal-body { overflow-y: auto; min-height: 0; flex: 1 1 auto; -webkit-overflow-scrolling: touch; }
  .modal.modal-sheet .modal-footer {
    position: sticky; bottom: 0; z-index: 2; flex-shrink: 0; background: var(--bs-modal-bg, var(--surface));
  }
  .modal.modal-sheet .modal-header {
    position: sticky; top: 0; z-index: 2; flex-shrink: 0; background: var(--bs-modal-bg, var(--surface));
  }
  .modal.modal-sheet .modal-header::before {
    content: ""; position: absolute; top: 7px; inset-inline: 0; margin: 0 auto;
    width: 38px; height: 4px; border-radius: 999px; background: #D3DAD8;
  }
  .modal.modal-sheet.fade .modal-dialog { transform: translateY(100%); transition: transform .25s ease-out; }
  .modal.modal-sheet.show .modal-dialog { transform: none; }
}

/* ---- دفعات الفواتير (patients/invoices) ---- */
.pay-list { border-top: 1px dashed var(--c-muted-bg, #EEF1F0); padding-top: .25rem; }
.pay-row { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .5rem 0; border-bottom: 1px solid var(--c-muted-bg, #EEF1F0); }
.pay-row:last-child { border-bottom: 0; }
.pay-no { font-weight: 600; font-size: .9rem; }
.pay-badge { font-weight: 500; font-size: .7rem; }
.pay-actions { display: flex; gap: .35rem; flex-shrink: 0; }
.pay-actions .btn { min-width: 40px; min-height: 40px; }
.pay-sub { font-weight: 600; }
.pay-remaining { color: var(--c-muted); }
#payModal input[name=amount] { min-height: 52px; font-size: 1.25rem; }
#invList .btn-sm.btn-brand, #invList .payToggle { min-height: 42px; }

/* ===================== مخطط الأسنان التفاعلي (FDI) — patients/_tooth_picker.php ===================== */
.tp-wrap { max-width: 440px; margin: 0 auto; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); padding: 4px; }
.tp-svg { display: block; width: 100%; height: auto; }
.tp-mid { stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 5 5; opacity: .7; }
.tp-center { fill: var(--muted); font-size: 12px; }
.tp-count { font-weight: 700; fill: var(--brand); font-size: 13px; }
.tp-tooth { cursor: pointer; outline: none; -webkit-tap-highlight-color: transparent; }
.tp-hit { fill: transparent; }
.tp-shape { fill: var(--surface-secondary); stroke: var(--c-text); stroke-width: 1.6; transition: fill .12s; }
.tp-mark { stroke: var(--c-text); stroke-width: 1.4; stroke-linecap: round; }
.tp-num { fill: var(--muted); font-size: 11px; }
.tp-tooth:hover .tp-shape { fill: var(--brand-secondary); }
.tp-tooth:focus-visible .tp-shape { stroke: var(--brand); stroke-width: 3; }
.tp-tooth.on .tp-shape { fill: var(--brand); stroke: var(--brand-dark); stroke-width: 2.4; }
.tp-tooth.on .tp-mark { stroke: #fff; }
.tp-tooth.on .tp-num { fill: var(--brand); font-weight: 700; }
.tp-hint { min-height: 20px; margin-top: 6px; text-align: center; }
.tp-chips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 6px; }
.tp-chip { display: inline-flex; align-items: center; gap: 4px; background: var(--brand-tertiary); border: 1px solid var(--brand); color: var(--brand-dark); border-radius: var(--radius-pill); padding: 2px 4px 2px 10px; font-size: 13px; }
:root[data-bs-theme="dark"] .tp-chip { color: var(--c-text); }
.tp-chip-x { border: 0; background: transparent; color: inherit; min-width: 24px; min-height: 24px; line-height: 1; border-radius: 50%; }
.tp-chip-btn { border: 0; background: transparent; color: inherit; min-height: 28px; padding: 0 2px; font: inherit; cursor: pointer; }
.tp-chip-btn:focus-visible { outline: 2px solid var(--brand-dark); border-radius: 6px; }
/* قائمة أسطح السن (fixed داخل .modal-content أو body) */
.tp-menu { position: fixed; z-index: 2000; width: 260px; max-width: calc(100vw - 16px); max-height: min(70vh, 420px); overflow-y: auto; background: var(--surface); color: var(--c-text); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: 0 8px 24px rgba(0,0,0,.2); padding: 6px; }
.tp-menu-head { padding: 4px 8px 6px; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.tp-menu-head b { color: var(--brand); }
.tp-mi { display: flex; align-items: center; gap: 2px; }
.tp-mi-pick { flex: 1; text-align: start; border: 0; background: transparent; color: inherit; min-height: 44px; padding: 6px 10px; border-radius: 8px; font-size: 15px; }
.tp-mi-pick:hover, .tp-mi-pick:focus-visible { background: var(--brand-tertiary); outline: none; }
.tp-mi-pick.is-cur { background: var(--brand); color: #fff; font-weight: 600; }
.tp-mi-pick.is-pre:not(.is-cur) { box-shadow: inset 0 0 0 2px var(--brand); }
.tp-mi-ico { border: 0; background: transparent; color: var(--muted); min-width: 40px; min-height: 44px; border-radius: 8px; }
.tp-mi-ico:hover:not(:disabled) { background: var(--brand-tertiary); color: var(--c-text); }
.tp-mi-ico.on { color: #e0a100; }
.tp-mi-ico:disabled { opacity: 1; cursor: default; }
.tp-mi-input { flex: 1; min-width: 0; min-height: 40px; }
.tp-mi-add { border-top: 1px solid var(--border); margin-top: 4px; padding-top: 6px; }
.tp-menu-err { padding: 4px 8px; }
:root[data-bs-theme="dark"] .tp-menu { box-shadow: 0 8px 24px rgba(0,0,0,.6); }
:root[data-bs-theme="dark"] .tp-mi-pick.is-cur { color: #fff; }
.teeth-more { cursor: pointer; text-decoration: underline dotted; }
/* مبدّل دائمة/مؤقتة (segmented) + مؤشر التحديدات في المخطط غير الظاهر */
.tp-tabs { display: flex; gap: 0; max-width: 440px; margin: 0 auto 8px; border: 1px solid var(--brand); border-radius: var(--radius-pill); overflow: hidden; }
.tp-tab { flex: 1; position: relative; border: 0; background: var(--surface); color: var(--c-text); min-height: 44px; padding: 6px 10px; font-size: 14px; }
.tp-tab + .tp-tab { border-inline-start: 1px solid var(--brand); }
.tp-tab.active { background: var(--brand); color: #fff; font-weight: 600; }
.tp-tab:focus-visible { outline: 3px solid var(--brand-dark); outline-offset: -3px; }
.tp-dot { display: inline-block; min-width: 20px; height: 20px; line-height: 20px; padding: 0 5px; border-radius: 10px; background: var(--brand); color: #fff; font-size: 12px; font-weight: 700; margin-inline-start: 4px; }
.tp-chip-prim { border-style: dashed; }

/* ب2 — صورة البروفايل */
.welcome-card .wc-avatar { overflow: hidden; text-decoration: none; }
.wc-avatar img, .avatar-pick img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar-pick {
  width: 96px; height: 96px; border-radius: 50%; overflow: hidden; flex-shrink: 0;
  background: var(--c-brand-bg); color: var(--brand); font-size: 2.2rem;
  display: flex; align-items: center; justify-content: center; border: 2px solid var(--border);
}

/* ب3 — الدعم الفني: زر مصمت بتباين عالٍ في الوضعين (على الشريط الأخضر وعلى الخلفية الداكنة) */
.support-btn { background: #fff; color: #1A211E; border-color: #B7C4BF; font-weight: 600; }
.support-btn:hover, .support-btn:focus, .support-btn.show { background: #E8F0ED; color: #1A211E; border-color: #E8F0ED; }
.support-menu .dropdown-item { display: flex; align-items: center; gap: .5rem; }
.support-wa { color: #25D366; font-size: 1.25rem; }
.support-tg { color: #229ED9; font-size: 1.25rem; }

/* ب6 — بطاقة المستحقات بعرض الصف كاملًا، وتبقى قابلة للنقر */
.fin-item.fin-dues { grid-column: 1 / -1; text-decoration: none; color: inherit; }
.fin-item.fin-dues:hover { box-shadow: 0 2px 8px rgba(0,0,0,.12); }

/* ب3 — الدعم الفني المدمج (صفحة الدخول): أيقونتان دائريتان بحدّ واضح في الوضعين */
.support-ico {
  width: 40px; height: 40px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  background: #fff; border: 1px solid #B7C4BF; font-size: 1.4rem; text-decoration: none; flex-shrink: 0;
}
.support-ico:hover, .support-ico:focus { background: #E8F0ED; }

/* ---- نوافذ طويلة: تمرير داخلي لكل النوافذ (ملاحظات العميل 2026-10-20: زيارة/طبيب/موظف/طلب مخبر) ----
   <form> الذي يلفّ .modal-body/.modal-footer كان يمنع تمرير .modal-body (حتى مع modal-dialog-scrollable)،
   فيتجاوز المحتوى الشاشة. الحل عام: .modal-content عمود flex بحد أقصى للارتفاع، و<form> الابن المباشر
   عمود flex أيضًا، فيصير .modal-body وحده القابل للتمرير بين رأس وذيل ثابتين. */
.modal-content {
  max-height: calc(100vh - 3.5rem); display: flex; flex-direction: column; overflow: hidden;
}
.modal-content > form {
  display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; overflow: hidden;
}
.modal-content .modal-body { overflow-y: auto; min-height: 0; flex: 1 1 auto; -webkit-overflow-scrolling: touch; }
.modal-content .modal-header, .modal-content .modal-footer { flex-shrink: 0; }

/* ===================== اللغات من اليسار إلى اليمين (الإنكليزية/الفرنسية/التركية): html[dir=ltr] ===================== */
[dir="ltr"] .app-sidebar { border-left: 0; border-right: 1px solid #E1E8E6; }
[data-bs-theme="dark"][dir="ltr"] .app-sidebar, [dir="ltr"] [data-bs-theme="dark"] .app-sidebar { border-right-color: #2A3A35; }
/* أسهم الاتجاه المرسومة لليمين-إلى-اليسار تُعكس في الاتجاه الآخر */
[dir="ltr"] .fa-arrow-right, [dir="ltr"] .fa-arrow-left, [dir="ltr"] .fa-chevron-right, [dir="ltr"] .fa-chevron-left,
[dir="ltr"] .fa-angle-right, [dir="ltr"] .fa-angle-left, [dir="ltr"] .fa-angles-right, [dir="ltr"] .fa-angles-left,
[dir="ltr"] .fa-caret-right, [dir="ltr"] .fa-caret-left, [dir="ltr"] .fa-right-from-bracket, [dir="ltr"] .fa-right-to-bracket { transform: scaleX(-1); }
html.i18n-pending body { visibility: hidden; }
/* مواضع كان فيها direction: rtl صريحًا (شبكات لوحة التحكم وبطاقات المواعيد) */
[dir="ltr"] .stat-grid, [dir="ltr"] .stat-grid-3, [dir="ltr"] .quick-grid, [dir="ltr"] .today-grid, [dir="ltr"] .fin-grid, [dir="ltr"] .appt-card { direction: ltr; }
[dir="ltr"] .appt-card .appt-side { align-items: flex-start; }

/* ===================== محدّد اللغة ===================== */
/* صفحة الدخول: أربعة أزرار ظاهرة، الحالية مميّزة */
.lang-pills { display: flex; flex-wrap: wrap; gap: .4rem; justify-content: center; }
.lang-pill { display: inline-block; padding: .4rem .95rem; border-radius: 2rem; border: 1px solid rgba(255,255,255,.55); color: #fff; text-decoration: none; font-size: .9rem; font-weight: 500; background: rgba(255,255,255,.08); }
.lang-pill:hover { background: rgba(255,255,255,.22); color: #fff; }
.lang-pill.active { background: #fff; color: #334F46; border-color: #fff; font-weight: 700; }
/* الشريط العلوي: عناصر القائمة المنسدلة بنص داكن على خلفية بيضاء (كان النص أبيض فيضيع) */
.lang-switch { color-scheme: light; }
.lang-switch option { background: #fff; color: #212529; }
[data-bs-theme="dark"] .lang-switch { color-scheme: dark; }
[data-bs-theme="dark"] .lang-switch option { background: #22302B; color: #fff; }
/* ===================== منتقي الوقت (ساعة | دقيقة | ص/م) لحقول الوقت — assets/js/app.js ===================== */
.t24-input { cursor: pointer; min-width: 6.2rem; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%236c757d' stroke-width='1.4'%3E%3Ccircle cx='8' cy='8' r='6.2'/%3E%3Cpath d='M8 4.5V8l2.3 1.6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right .4rem center; background-size: 1rem; padding-right: 1.9rem; }
.t24-pop { position: fixed; z-index: 2100; width: 260px; padding: .6rem; border-radius: .8rem; background: var(--bs-body-bg, #fff); color: var(--bs-body-color, #212529); border: 1px solid var(--bs-border-color, #dee2e6); box-shadow: 0 .6rem 1.6rem rgba(0,0,0,.28); }
.t24-cols { display: flex; gap: .4rem; }
.t24-col { flex: 1 1 0; max-height: 236px; overflow-y: auto; border: 1px solid var(--bs-border-color, #dee2e6); border-radius: .55rem; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.t24-ap { flex: 0 0 62px; align-self: flex-start; }
.t24-it { display: block; width: 100%; min-height: 44px; border: 0; background: transparent; color: inherit; font-size: 1.1rem; text-align: center; padding: .3rem 0; }
.t24-it:hover { background: var(--bs-tertiary-bg, #f1f3f2); }
.t24-it.on { background: var(--brand, #4A7065); color: #fff; font-weight: 700; }
.t24-foot { display: flex; justify-content: space-between; gap: .5rem; margin-top: .55rem; }
/* الهاتف: شريط سفلي بعرض الشاشة وصفوف كبيرة */
.t24-pop.t24-sheet { left: 8px; right: 8px; bottom: 8px; top: auto; width: auto; padding: .75rem; }
.t24-sheet .t24-col { max-height: 42vh; }
.t24-sheet .t24-it { min-height: 48px; font-size: 1.2rem; }
