/*
 * نظام التصميم — الوضوح أولًا لكبار السن:
 * خط كبير، تباين قوي، أهداف لمس 48px فأكثر، لون أساسي واحد هادئ،
 * والحالات دائمًا نص + لون (لا تعتمد على اللون وحده).
 */
:root {
  --bg: #f5f7f6;
  --surface: #ffffff;
  --ink: #18291f;
  --muted: #4d6156;
  --line: #d9e1dc;
  --primary: #16694a;
  --primary-hover: #0f5238;
  --primary-soft: #e4f1ea;
  --danger: #b3261e;
  --danger-soft: #fdeceb;
  --warning: #855600;
  --warning-soft: #fcf2db;
  --success: #14652d;
  --success-soft: #e5f4e9;
  --info: #1d4f8f;
  --info-soft: #e8f0fb;
  --radius: 14px;
}

* { box-sizing: border-box; }
html { font-size: 17px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Cairo", "Segoe UI", Tahoma, Arial, sans-serif;
  line-height: 1.7;
}
a { color: inherit; }
h1, h2, h3 { line-height: 1.35; margin: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.icon { width: 1.35em; height: 1.35em; flex-shrink: 0; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
.ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }

/* ---------- الإطار ---------- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar-inner { max-width: 1400px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.brand { font-size: 1.3rem; font-weight: 700; color: var(--primary); text-decoration: none; }
.search { flex: 1 1 360px; display: flex; gap: 8px; max-width: 640px; }
.search input { flex: 1; min-width: 0; }
.search-btn { padding-inline: 16px; }
.userbox { display: flex; align-items: center; gap: 12px; margin-inline-start: auto; }

.shell { display: flex; max-width: 1400px; margin: 0 auto; }
.sidebar { width: 240px; flex-shrink: 0; padding: 18px 14px; border-inline-start: 1px solid var(--line); position: sticky; top: 70px; align-self: flex-start; display: flex; flex-direction: column; gap: 4px; }
.nav-link { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 10px; font-weight: 600; font-size: 1.05rem; text-decoration: none; min-height: 50px; color: var(--ink); }
.nav-link:hover { background: var(--primary-soft); }
.nav-link.active { background: var(--primary-soft); color: var(--primary); }
.content { flex: 1; min-width: 0; padding: 24px 24px 40px; }
.bare { max-width: 480px; margin: 0 auto; padding: 48px 16px; }

.bottomnav { display: none; }

@media (max-width: 900px) {
  .sidebar, .userbox { display: none; }
  .topbar-inner { padding: 10px 16px 12px; gap: 10px; }
  .search { flex-basis: 100%; max-width: none; }
  .content { padding: 18px 16px 110px; }
  .bottomnav {
    display: grid; grid-template-columns: repeat(5, 1fr);
    position: fixed; bottom: 0; inset-inline: 0; z-index: 30;
    background: var(--surface); border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .bottomnav a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 64px; font-size: 0.82rem; font-weight: 700; color: var(--muted); text-decoration: none; }
  .bottomnav a.active { color: var(--primary); }
  .bottomnav .icon { width: 1.5rem; height: 1.5rem; }
}

/* ---------- عناصر عامة ---------- */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.page-title { font-size: 1.65rem; font-weight: 700; }
.page-sub { color: var(--muted); margin-top: 2px; }
.section { margin-top: 32px; }
.section-title { font-size: 1.25rem; font-weight: 700; margin-bottom: 12px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.grid-stats { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
@media (max-width: 420px) { .grid-2 { grid-template-columns: 1fr; } .grid-stats { grid-template-columns: 1fr 1fr; } }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
a.card { display: block; text-decoration: none; transition: border-color .15s; }
a.card:hover { border-color: var(--primary); }
.card-title { font-weight: 700; font-size: 1.15rem; }
.card-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.amount { font-size: 1.45rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.narrow { max-width: 640px; }

.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; text-decoration: none; display: block; }
a.stat:hover { border-color: var(--primary); }
.stat-label { color: var(--muted); font-weight: 600; }
.stat-value { font-size: 2rem; font-weight: 700; line-height: 1.3; font-variant-numeric: tabular-nums; }
.stat-detail { color: var(--muted); }
.tone-danger { color: var(--danger); }
.tone-warning { color: var(--warning); }
.tone-success { color: var(--success); }

.empty { text-align: center; padding: 40px 20px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.empty-title { font-size: 1.2rem; font-weight: 700; margin: 0; }

.highlight { background: var(--primary-soft); border-radius: 12px; padding: 14px 16px; display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px 24px; margin: 0; }
.facts dt { color: var(--muted); font-weight: 600; font-size: 0.95rem; }
.facts dd { margin: 0; font-weight: 700; font-size: 1.1rem; }

/* ---------- الأزرار ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 50px; padding: 10px 22px; border-radius: 10px; border: 1px solid transparent;
  font: inherit; font-weight: 700; font-size: 1rem; line-height: 1.2; cursor: pointer; text-decoration: none; text-align: center;
}
.btn:focus-visible, .input:focus-visible, .nav-link:focus-visible, a:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn-secondary:hover { background: var(--primary-soft); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { min-height: 42px; padding: 6px 16px; font-size: 0.95rem; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .6; cursor: progress; }

/* ---------- النماذج ---------- */
.form { display: flex; flex-direction: column; gap: 18px; }
.field label, .label { display: block; font-weight: 700; margin-bottom: 6px; }
.input, .search input, .field input, .field select, .field textarea {
  width: 100%; min-height: 52px; padding: 10px 14px; font: inherit; font-size: 1.05rem;
  border: 1px solid #b9c6be; border-radius: 10px; background: var(--surface); color: var(--ink);
}
.field textarea { min-height: 90px; }
.search input:focus, .field input:focus, .field select:focus, .field textarea:focus { outline: 3px solid var(--primary); outline-offset: 1px; border-color: var(--primary); }
.hint { color: var(--muted); font-size: 0.92rem; margin-top: 4px; }
.fields-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 640px) { .fields-2 { grid-template-columns: 1fr; } }
fieldset { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 16px; }
legend { font-size: 1.15rem; font-weight: 700; margin-bottom: 8px; padding: 0; }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 600; cursor: pointer; }
.check input { width: 22px; height: 22px; margin-top: 4px; flex-shrink: 0; }
details > summary { cursor: pointer; font-weight: 700; min-height: 44px; display: flex; align-items: center; }

/* ---------- التنبيهات والشارات ---------- */
.alert { border-radius: 10px; padding: 12px 16px; font-weight: 600; margin: 0 0 16px; border: 1px solid; }
.alert-error { background: var(--danger-soft); color: var(--danger); border-color: #f0c2bf; }
.alert-success { background: var(--success-soft); color: var(--success); border-color: #bfe0c8; }
.alert-warning { background: var(--warning-soft); color: var(--warning); border-color: #ecd9a8; font-weight: 400; }

.badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 3px 12px; font-size: 0.9rem; font-weight: 700; white-space: nowrap; }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-neutral { background: #edf1ef; color: var(--muted); }

.tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.tab { min-height: 46px; padding: 8px 18px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); text-decoration: none; font-weight: 700; display: inline-flex; align-items: center; }
.tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ---------- الجداول: تتحول إلى بطاقات على الجوال ---------- */
.table-card { padding: 0; overflow: hidden; }
.rtable { width: 100%; border-collapse: collapse; text-align: right; }
.rtable th { padding: 12px 14px; color: var(--muted); font-size: 0.92rem; border-bottom: 2px solid var(--line); white-space: nowrap; }
.rtable td { padding: 13px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; font-variant-numeric: tabular-nums; }
.rtable tr:last-child td { border-bottom: 0; }
.rtable tr.dim td { opacity: .6; }
@media (max-width: 720px) {
  .table-card { background: transparent; border: 0; }
  .rtable thead { display: none; }
  .rtable, .rtable tbody, .rtable tr, .rtable td { display: block; width: 100%; }
  .rtable tr { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 16px; margin-bottom: 12px; }
  .rtable td { display: flex; justify-content: space-between; align-items: center; gap: 12px; border-bottom: 1px solid var(--line); padding: 10px 0; }
  .rtable td:last-child { border-bottom: 0; }
  .rtable td::before { content: attr(data-label); color: var(--muted); font-weight: 600; font-size: 0.92rem; }
  .rtable td[data-label=""]::before { content: none; }
}

/* ---------- قائمة "المزيد" ---------- */
.menu-list { display: flex; flex-direction: column; gap: 10px; }
.menu-item { display: flex; align-items: center; gap: 14px; min-height: 64px; padding: 12px 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; font-weight: 700; font-size: 1.1rem; width: 100%; font-family: inherit; color: var(--ink); cursor: pointer; }
.menu-item .icon { color: var(--primary); width: 1.6rem; height: 1.6rem; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media print { .topbar, .sidebar, .bottomnav, .btn { display: none !important; } .content { padding: 0; } }
