@font-face { font-family: "IBM Plex Sans Arabic"; font-weight: 400; font-display: swap; src: url("fonts/plex-arabic-400.woff2") format("woff2"); unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFF; }
@font-face { font-family: "IBM Plex Sans Arabic"; font-weight: 400; font-display: swap; src: url("fonts/plex-latin-400.woff2") format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+20AC; }
@font-face { font-family: "IBM Plex Sans Arabic"; font-weight: 500; font-display: swap; src: url("fonts/plex-arabic-500.woff2") format("woff2"); unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFF; }
@font-face { font-family: "IBM Plex Sans Arabic"; font-weight: 500; font-display: swap; src: url("fonts/plex-latin-500.woff2") format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+20AC; }
@font-face { font-family: "IBM Plex Sans Arabic"; font-weight: 600; font-display: swap; src: url("fonts/plex-arabic-600.woff2") format("woff2"); unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFF; }
@font-face { font-family: "IBM Plex Sans Arabic"; font-weight: 600; font-display: swap; src: url("fonts/plex-latin-600.woff2") format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+20AC; }
@font-face { font-family: "IBM Plex Sans Arabic"; font-weight: 700; font-display: swap; src: url("fonts/plex-arabic-700.woff2") format("woff2"); unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFF; }
@font-face { font-family: "IBM Plex Sans Arabic"; font-weight: 700; font-display: swap; src: url("fonts/plex-latin-700.woff2") format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+20AC; }

:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface-1: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e4e6eb;
  --text-primary: #111827;
  --text-secondary: #4b5563;
  --text-muted: #6b7280;
  --brand: #0f2a4a;
  --brand-ink: #ffffff;
  --accent: #2a78d6;
  --series-1: #2a78d6;  /* الشهر الحالي */
  --series-2: #eb6834;  /* الشهر السابق */
  --grid: #eceef2;
  --good: #0a7a3d;  --good-bg: #e7f5ec;
  --bad: #c0362c;   --bad-bg: #fbeceb;
  --warn-bg: #fff6e0; --warn-border: #f0c96a;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16,24,40,.04), 0 1px 3px rgba(16,24,40,.06);
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #111111;
    --surface-1: #1a1a19;
    --surface-2: #222220;
    --border: #2f2f2c;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #9a998f;
    --brand: #0f2a4a;
    --accent: #3987e5;
    --series-1: #3987e5;
    --series-2: #d95926;
    --grid: #2a2a28;
    --good: #4cc27c;  --good-bg: #16301f;
    --bad: #ef7a72;   --bad-bg: #3a1c1a;
    --warn-bg: #2d2614; --warn-border: #6b5a22;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
.num, .kpi-value, .tbl td.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-muted); }
.small { font-size: 12px; }

/* ===== الشريط العلوي ===== */
.topbar { background: var(--brand); color: var(--brand-ink); position: sticky; top: 0; z-index: 10; }
.topbar-inner { max-width: 1320px; margin: 0 auto; padding: 14px 24px; display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 38px; height: 38px; border-radius: 10px; background: rgba(255,255,255,.12); display: grid; place-items: center; color: #fff; }
.brand-title { font-weight: 700; font-size: 16px; }
.brand-sub { font-size: 12px; opacity: .75; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.updated { font-size: 12px; opacity: .8; margin-inline-end: 6px; }
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  font: inherit; font-size: 13px; font-weight: 600;
  background: #fff; color: var(--brand); border: 0; border-radius: 9px;
  padding: 8px 14px; cursor: pointer; text-decoration: none;
}
.btn:hover { filter: brightness(.95); }
.btn[disabled] { opacity: .6; cursor: progress; }
.btn-ghost { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.3); }
.btn-ghost:hover { background: rgba(255,255,255,.08); }

/* ===== الهيكل ===== */
.wrap { max-width: 1320px; margin: 0 auto; padding: 22px 24px 40px; }
.section { margin-bottom: 26px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 0 0 12px; flex-wrap: wrap; }
.section-head h2 { font-size: 17px; margin: 0; font-weight: 700; padding-inline-start: 10px; border-inline-start: 3px solid var(--accent); }
.section-note { color: var(--text-secondary); font-size: 13px; }
.section-note strong { color: var(--text-primary); font-size: 15px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.align-start { align-items: start; }

.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.card-head h3 { margin: 0; font-size: 14px; font-weight: 600; }

/* ===== بطاقات المؤشرات ===== */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.kpis-3 { grid-template-columns: 1fr; margin: 0; }
.kpi { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; min-height: 118px; }
.kpi-accent { border-top: 3px solid var(--accent); }
.kpi-label { color: var(--text-secondary); font-size: 13px; font-weight: 500; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.kpi-value { font-size: 26px; font-weight: 700; margin: 6px 0 4px; letter-spacing: -.3px; }
.kpi-value .cur { font-size: 13px; font-weight: 500; color: var(--text-muted); margin-inline-start: 4px; }
.kpi-meta { color: var(--text-muted); font-size: 12px; display: grid; gap: 2px; }
.kpi-meta b { color: var(--text-secondary); font-weight: 600; }
.tag { background: var(--surface-2); border: 1px solid var(--border); color: var(--text-secondary); border-radius: 999px; padding: 0 8px; font-size: 11px; }
.kpi-compare { display: grid; gap: 10px; margin-top: 8px; }
.cmp-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 12px; color: var(--text-secondary); }

.delta { display: inline-flex; align-items: center; gap: 4px; font-weight: 700; font-size: 12px; border-radius: 999px; padding: 2px 8px; white-space: nowrap; }
.delta.up { color: var(--good); background: var(--good-bg); }
.delta.down { color: var(--bad); background: var(--bad-bg); }
.delta.flat { color: var(--text-muted); background: var(--surface-2); }
.kpi-delta .delta { font-size: 20px; padding: 2px 12px; }

/* ===== المخططات ===== */
.chart-box { position: relative; height: 260px; }
.chart-tall { height: 320px; }

/* ===== السيولة ===== */
.bal-card .bal-total { font-size: 22px; font-weight: 700; margin: 4px 0 10px; }
.bal-card .bal-total .cur { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.bal-head { display: flex; justify-content: space-between; align-items: center; }
.bal-icon { width: 34px; height: 34px; border-radius: 9px; background: var(--surface-2); display: grid; place-items: center; color: var(--accent); border: 1px solid var(--border); }
.bal-share { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-bottom: 10px; }
.bal-share span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }

/* ===== الجداول ===== */
.table-wrap { overflow-x: auto; margin-top: 12px; position: relative; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: start; font-weight: 600; color: var(--text-secondary); background: var(--surface-2); padding: 9px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.tbl td { padding: 9px 10px; border-bottom: 1px solid var(--border); }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .num { text-align: left; direction: ltr; white-space: nowrap; }
.tbl th.num { text-align: left; }
.tbl tfoot td { font-weight: 700; background: var(--surface-2); }
.tbl tbody tr:hover td { background: var(--surface-2); }
.empty { color: var(--text-muted); text-align: center; padding: 18px; }

/* ===== تنبيهات ===== */
.banner { border-radius: 12px; padding: 12px 16px; margin-bottom: 16px; font-size: 13px; }
.banner ul { margin: 6px 0 0; padding-inline-start: 18px; }
.banner-demo { background: #fdecc8; color: #5a3d00; border: 1px solid #f0c96a; }
.banner-warn { background: var(--warn-bg); border: 1px solid var(--warn-border); color: var(--text-primary); }
.banner-error { background: var(--bad-bg); color: var(--bad); border: 1px solid currentColor; }

.foot { text-align: center; margin-top: 30px; }

/* ===== صفحة الدخول ===== */
.login-page { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(160deg, #0f2a4a 0%, #163b66 100%); }
.login-card { width: min(380px, 92vw); background: var(--surface-1); border-radius: 18px; padding: 30px; box-shadow: 0 20px 50px rgba(0,0,0,.25); display: grid; gap: 10px; }
.login-card .brand-mark { background: var(--brand); }
.login-card h1 { font-size: 18px; margin: 6px 0 0; }
.login-card label { font-size: 13px; font-weight: 600; margin-top: 8px; }
.login-card input { font: inherit; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-1); color: var(--text-primary); }
.login-card input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.login-card button { font: inherit; font-weight: 700; background: var(--brand); color: #fff; border: 0; padding: 11px; border-radius: 10px; cursor: pointer; margin-top: 6px; }
.form-error { color: var(--bad); font-size: 13px; }

/* ===== تجاوب ===== */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 760px) {
  .kpis, .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .wrap { padding: 16px; }
  .topbar-inner { padding: 12px 16px; }
  .kpi-value { font-size: 22px; }
}

/* ===== طباعة ===== */
@media print {
  .topbar { position: static; }
  .topbar-actions { display: none; }
  body { background: #fff; }
  .card, .kpi { box-shadow: none; break-inside: avoid; }
}
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.grid-2 > *, .grid-3 > *, .kpis > * { min-width: 0; }
