/* مكوّنات مشتركة لنماذج الويب. الموبايل أولاً؛ من 900px تتحوّل القائمة السفلية إلى قائمة جانبية. */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg-canvas);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

a { color: var(--text-link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, p { margin: 0; }
img { max-width: 100%; }

:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* أرقام وهواتف بين نص عربي: عزل الاتجاه حتى لا ينقلب ترتيبها */
.num, .phone { unicode-bidi: isolate; direction: ltr; display: inline-block; }

/* ===== الهيكل ===== */
.shell { min-height: 100vh; padding-bottom: 76px; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  min-height: 56px; padding: 8px var(--page-pad);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
}
.topbar .brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.brand-mark {
  width: 32px; height: 32px; flex: none;
  border-radius: var(--radius-md);
  background: var(--accent-fill); color: var(--text-on-accent);
  display: grid; place-items: center; font-weight: 700; font-size: 15px;
}
.brand-name { font-weight: 700; font-size: var(--fs-title-m); white-space: nowrap; }
.role-tag {
  font-size: var(--fs-caption); color: var(--text-tertiary);
  white-space: nowrap;
}
.topbar .icon-btn { flex: none; }

.page { padding: var(--page-pad); max-width: 760px; margin: 0 auto; }
.page-head { margin: 4px 0 16px; }
.page-head h1 { font-size: var(--fs-headline); line-height: var(--lh-headline); font-weight: 700; }
.page-head p { color: var(--text-secondary); margin-top: 4px; }
.back-link { display: inline-flex; align-items: center; gap: 6px; min-height: var(--control-sm); margin-bottom: 4px; font-weight: 600; }

/* ===== التنقّل: سفلي على الموبايل ===== */
.nav {
  position: fixed; inset: auto 0 0 0; z-index: 30;
  display: flex; justify-content: space-around;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
}
.nav a {
  flex: 1 1 0; min-width: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 56px; padding: 4px 2px;
  color: var(--text-tertiary); font-size: var(--fs-caption); line-height: 16px; font-weight: 600;
  border-radius: var(--radius-md); text-align: center;
}
.nav a:hover { text-decoration: none; background: var(--bg-hover); }
.nav a .ico { font-size: 20px; line-height: 24px; }
.nav a[aria-current="page"] { color: var(--accent-on-subtle); background: var(--accent-subtle); }
.nav .nav-title { display: none; }
.nav .badge-dot {
  position: relative;
}
.nav .badge-dot::after {
  content: ""; position: absolute; top: 2px; inset-inline-end: -4px;
  width: 8px; height: 8px; border-radius: 50%; background: var(--danger-icon);
}

/* ===== سطح المكتب: قائمة جانبية على اليمين ===== */
@media (min-width: 900px) {
  .shell {
    display: grid; grid-template-columns: 232px 1fr;
    grid-template-rows: auto 1fr; padding-bottom: 0;
  }
  .topbar { grid-column: 1 / -1; }
  .nav {
    position: sticky; top: 56px; align-self: start;
    height: calc(100vh - 56px);
    flex-direction: column; justify-content: flex-start; gap: 2px;
    border-top: 0; border-inline-end: 1px solid var(--border-subtle);
    padding: 16px 12px;
  }
  .nav .nav-title { display: block; color: var(--text-tertiary); font-size: var(--fs-caption); padding: 0 12px 6px; }
  .nav a {
    flex: none; flex-direction: row; justify-content: flex-start; gap: 10px;
    min-height: var(--control); padding: 0 12px;
    font-size: var(--fs-body); text-align: start;
  }
  .page { padding: 24px 32px; max-width: 880px; margin: 0; }
}

/* ===== الأزرار ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--control); padding: 0 18px;
  border-radius: var(--radius-md); border: 1px solid transparent;
  font: inherit; font-weight: 700; cursor: pointer; text-align: center;
  white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--accent-fill); color: var(--text-on-accent); }
.btn-primary:hover { background: var(--accent-fill-hover); }
.btn-primary:active { background: var(--accent-fill-pressed); }
.btn-secondary { background: var(--bg-surface); color: var(--text-primary); border-color: var(--border-interactive); }
.btn-secondary:hover { background: var(--bg-hover); }
.btn-quiet { background: transparent; color: var(--text-link); }
.btn-quiet:hover { background: var(--accent-subtle); }
.btn-danger { background: var(--bg-surface); color: var(--danger-text); border-color: var(--danger-icon); }
.btn-danger:hover { background: var(--danger-bg); }
.btn-success { background: var(--success-icon); color: #fff; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.icon-btn {
  width: var(--control); height: var(--control);
  display: inline-grid; place-items: center;
  border-radius: var(--radius-full); border: 0; background: transparent;
  font-size: 20px; color: var(--text-secondary); cursor: pointer; position: relative;
}
.icon-btn:hover { background: var(--bg-hover); text-decoration: none; }
.icon-btn .count {
  position: absolute; top: 4px; inset-inline-start: 4px;
  min-width: 18px; height: 18px; padding: 0 4px; border-radius: 9px;
  background: var(--danger-fill); color: #fff; font-size: 11px; line-height: 18px; font-weight: 700;
}

.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.actions .btn { flex: 1 1 140px; }

/* ===== البطاقات ===== */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--card-pad);
}
.card + .card, .stack > * + * { margin-top: var(--gap); }
.card h2 { font-size: var(--fs-title-m); line-height: var(--lh-title-m); font-weight: 700; }
.card-link { display: block; color: inherit; }
.card-link:hover { text-decoration: none; border-color: var(--border-interactive); }

.section-title {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  font-size: var(--fs-title-m); font-weight: 700; margin: 24px 0 10px;
}
.section-title small { font-size: var(--fs-body-s); color: var(--text-tertiary); font-weight: 400; }

.meta { color: var(--text-secondary); font-size: var(--fs-body-s); line-height: var(--lh-body-s); }
.muted { color: var(--text-tertiary); }

/* قائمة «تسمية: قيمة» — كل سطر مستقل حتى لا يختلط العربي باللاتيني */
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0; }
.kv dt { color: var(--text-tertiary); font-size: var(--fs-body-s); }
.kv dd { margin: 0; font-weight: 600; }

/* ===== بطاقة الجلسة: ورقة التقويم هي العنصر المميّز ===== */
.session {
  display: grid; grid-template-columns: 64px 1fr; gap: 14px; align-items: start;
}
.cal {
  width: 64px; border-radius: var(--radius-md); overflow: hidden;
  border: 1px solid var(--border-subtle); text-align: center;
  background: var(--bg-surface);
}
.cal .cal-month {
  background: var(--accent-fill); color: var(--text-on-accent);
  font-size: 12px; line-height: 20px; font-weight: 700;
}
.cal .cal-day { font-size: 26px; line-height: 32px; font-weight: 800; padding-top: 4px; }
.cal .cal-week { font-size: 12px; line-height: 18px; color: var(--text-tertiary); padding-bottom: 6px; }
.cal.today .cal-month { background: var(--danger-fill); }
.session h3 { font-size: var(--fs-title-m); line-height: var(--lh-title-m); font-weight: 700; }
.session .when { font-weight: 700; color: var(--accent-on-subtle); }
.session .rows { margin-top: 6px; display: grid; gap: 2px; }
.session .rows div { display: flex; gap: 6px; color: var(--text-secondary); font-size: var(--fs-body-s); }
.session .rows .k { color: var(--text-tertiary); flex: none; }
.fee-line {
  margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--border-subtle);
  display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; align-items: center;
}
.fee { font-weight: 800; font-size: var(--fs-title-m); }

/* ===== الشارات (الحالات) ===== */
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  min-height: var(--badge); padding: 0 10px; border-radius: var(--radius-full);
  font-size: var(--fs-caption); font-weight: 700; white-space: nowrap;
  background: var(--neutral-bg); color: var(--neutral-on-bg);
}
.chip-success { background: var(--success-bg); color: var(--success-on-bg); }
.chip-warning { background: var(--warning-bg); color: var(--warning-on-bg); }
.chip-danger  { background: var(--danger-bg);  color: var(--danger-on-bg); }
.chip-info    { background: var(--info-bg);    color: var(--info-on-bg); }
.chip-accent  { background: var(--accent-subtle); color: var(--accent-on-subtle); }

/* ===== التبويبات / الفلاتر ===== */
.tabs {
  display: flex; gap: 6px; padding: 4px;
  background: var(--bg-subtle); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 1 0 auto; min-height: 40px; padding: 0 14px;
  border: 0; border-radius: var(--radius-md); background: transparent;
  font: inherit; font-weight: 700; color: var(--text-secondary); cursor: pointer; white-space: nowrap;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.tab[aria-selected="true"] { background: var(--bg-surface); color: var(--accent-on-subtle); box-shadow: var(--shadow-e1); }
.tab .n {
  min-width: 22px; height: 20px; padding: 0 6px; border-radius: 10px;
  background: var(--neutral-bg); color: var(--text-secondary); font-size: 12px; line-height: 20px;
}
.tab[aria-selected="true"] .n { background: var(--accent-subtle); color: var(--accent-on-subtle); }
.panel[hidden] { display: none; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.filter {
  min-height: var(--control-sm); padding: 0 14px; border-radius: var(--radius-full);
  border: 1px solid var(--border-subtle); background: var(--bg-surface);
  font: inherit; font-size: var(--fs-body-s); font-weight: 700; color: var(--text-secondary); cursor: pointer;
}
.filter[aria-pressed="true"] { background: var(--accent-subtle); border-color: transparent; color: var(--accent-on-subtle); }

/* ===== النماذج ===== */
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label, .field .label { font-weight: 700; font-size: var(--fs-body-s); }
.field .hint { color: var(--text-tertiary); font-size: var(--fs-caption); line-height: var(--lh-caption); }
.input, .select, .textarea {
  width: 100%; min-height: var(--control);
  padding: 10px 12px; border-radius: var(--radius-md);
  border: 1px solid var(--border-interactive); background: var(--bg-surface);
  color: var(--text-primary); font: inherit;
}
.textarea { min-height: 88px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { outline: 2px solid var(--border-focus); outline-offset: 0; border-color: transparent; }
.input.ltr { direction: ltr; text-align: right; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.money-input { position: relative; }
.money-input .input { padding-inline-end: 48px; }
.money-input .unit { position: absolute; inset-inline-end: 12px; top: 50%; transform: translateY(-50%); color: var(--text-tertiary); font-size: var(--fs-body-s); pointer-events: none; }

.choice-group { display: grid; gap: 8px; }
.choice {
  display: flex; align-items: center; gap: 10px; min-height: var(--control);
  padding: 10px 12px; border: 1px solid var(--border-subtle); border-radius: var(--radius-md);
  background: var(--bg-surface); cursor: pointer;
}
.choice input { width: 20px; height: 20px; accent-color: var(--accent-fill); flex: none; }
.choice:has(input:checked) { border-color: var(--accent-fill); background: var(--accent-subtle); }

/* ===== القوائم ===== */
.list { background: var(--bg-surface); border: 1px solid var(--border-subtle); border-radius: var(--radius-lg); overflow: hidden; }
.list-item {
  display: flex; align-items: center; gap: 12px;
  min-height: 60px; padding: 12px var(--card-pad);
  border-top: 1px solid var(--border-subtle); color: inherit;
}
.list-item:first-child { border-top: 0; }
a.list-item:hover { background: var(--bg-hover); text-decoration: none; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 700; }
.list-item .end { text-align: start; flex: none; display: grid; justify-items: end; gap: 4px; }
.list-item.unread { background: var(--accent-subtle); }
.avatar {
  width: 40px; height: 40px; flex: none; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700;
  background: var(--accent-subtle); color: var(--accent-on-subtle);
}
.amount { font-weight: 800; white-space: nowrap; }
.amount.in { color: var(--success-text); }
.amount.out { color: var(--danger-text); }

/* ===== أرقام اللوحة ===== */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 640px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat {
  background: var(--bg-surface); border: 1px solid var(--border-subtle); border-radius: var(--radius-lg);
  padding: 14px; display: grid; gap: 2px; color: inherit;
}
a.stat:hover { text-decoration: none; border-color: var(--border-interactive); }
.stat .v { font-size: var(--fs-data-m); line-height: 28px; font-weight: 800; }
.stat .l { color: var(--text-secondary); font-size: var(--fs-body-s); }
.stat.attention { border-color: var(--warning-graphic); background: var(--warning-bg); }
.stat.attention .l { color: var(--warning-on-bg); }

/* ===== تنبيه داخل الصفحة ===== */
.notice {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; border-radius: var(--radius-md);
  background: var(--info-bg); color: var(--info-on-bg); font-size: var(--fs-body-s); line-height: var(--lh-body-s);
}
.notice.warning { background: var(--warning-bg); color: var(--warning-on-bg); }
.notice.danger { background: var(--danger-bg); color: var(--danger-on-bg); }
.notice.success { background: var(--success-bg); color: var(--success-on-bg); }
.notice strong { display: block; font-size: var(--fs-body); }

/* ===== الحالة الفارغة ===== */
.empty {
  text-align: center; padding: 32px 16px;
  border: 1px dashed var(--border-interactive); border-radius: var(--radius-lg);
  background: var(--bg-sunken);
}
.empty .ico { font-size: 34px; }
.empty h3 { font-size: var(--fs-title-m); margin-top: 8px; }
.empty p { color: var(--text-secondary); margin: 4px auto 14px; max-width: 36ch; }

/* ===== «قريباً» للأقسام غير المنقولة ===== */
.soon {
  display: flex; align-items: center; gap: 12px;
  padding: 14px; border-radius: var(--radius-lg);
  border: 1px dashed var(--border-subtle); background: var(--bg-sunken);
  color: var(--text-tertiary);
}
.soon .ico { font-size: 22px; filter: grayscale(1); opacity: .7; }
.soon .title { color: var(--text-secondary); font-weight: 700; }
.soon .chip { margin-inline-start: auto; }

/* ===== النافذة السفلية (sheet) ===== */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(14, 17, 22, .45);
  display: none; align-items: flex-end; justify-content: center;
}
.sheet-backdrop.open { display: flex; }
.sheet {
  width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  background: var(--bg-surface); border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  padding: 8px var(--card-pad) calc(16px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow-e3);
}
.sheet .grip { width: 40px; height: 4px; border-radius: 2px; background: var(--border-subtle); margin: 4px auto 12px; }
.sheet h2 { font-size: var(--fs-title-l); margin-bottom: 4px; }
@media (min-width: 900px) {
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: var(--radius-xl); }
}

/* ===== الإشعار المؤقت (toast) ===== */
.toast {
  position: fixed; z-index: 60; inset-inline: 16px; bottom: 88px;
  max-width: 420px; margin: 0 auto;
  display: flex; gap: 10px; align-items: center;
  padding: 12px 16px; border-radius: var(--radius-md);
  background: var(--text-primary); color: var(--bg-surface); font-weight: 600;
  box-shadow: var(--shadow-e2);
  opacity: 0; transform: translateY(8px); pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}
.toast.show { opacity: 1; transform: none; }
@media (min-width: 900px) { .toast { bottom: 24px; } }

/* ===== الجدول البسيط (لسطح المكتب) — يتحوّل لبطاقات على الموبايل ===== */
.table { width: 100%; border-collapse: collapse; background: var(--bg-surface); }
.table th, .table td { padding: 10px 12px; text-align: start; border-top: 1px solid var(--border-subtle); vertical-align: top; }
.table th { background: var(--bg-sunken); font-size: var(--fs-body-s); color: var(--text-secondary); border-top: 0; }
.table-wrap { border: 1px solid var(--border-subtle); border-radius: var(--radius-lg); overflow: hidden; }

/* شريط تناسبي لتفصيل الكلفة */
.bar { height: 8px; border-radius: 4px; background: var(--bg-subtle); overflow: hidden; margin-top: 6px; }
.bar > span { display: block; height: 100%; background: var(--accent-fill); border-radius: 4px; }

/* خط زمني لسجل الملف */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 28px 18px 0; }
.timeline li::before {
  content: ""; position: absolute; right: 7px; top: 8px; bottom: -8px;
  width: 2px; background: var(--border-subtle);
}
.timeline li:last-child::before { display: none; }
.timeline li::after {
  content: ""; position: absolute; right: 2px; top: 6px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--bg-surface); border: 2px solid var(--border-interactive);
}
.timeline li.current::after { background: var(--accent-fill); border-color: var(--accent-fill); }

.spacer { height: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* تبويبات تلتفّ لسطرين بدل التمرير (طوابير المراحل الخمس) */
.tabs.wrap { flex-wrap: wrap; overflow: visible; }
.tabs.wrap .tab { flex: 1 1 auto; }
