/* =========================================================
   نظام إدارة العهد — نظام التصميم
   الألوان كلها متغيرات؛ الوضع الليلي يعيد تعريفها فقط.
   ========================================================= */
:root {
  color-scheme: light;
  --bg: #f4f4f1;
  --surface: #ffffff;
  --surface-2: #f8f8f5;
  --surface-3: #efefea;
  --ink: #0e1615;
  --muted: #3c4744;
  --faint: #66716e;
  --line: #dcdcd5;
  --line-strong: #bdbdb3;
  --th-bg: #eceee9;
  --zebra: #f7f8f5;
  --accent: #0f6b62;
  --accent-strong: #0b544d;
  --accent-ink: #ffffff;
  --accent-soft: #e2f0ed;
  --accent-softer: #f0f7f5;
  --wait: #9a5b00;  --wait-bg: #fcf1dd;
  --pay: #1d5aa6;   --pay-bg: #e6effb;
  --good: #1d7340;  --good-bg: #e2f3e8;
  --bad: #b3332c;   --bad-bg: #fce8e6;
  --off: #5d6865;   --off-bg: #ededea;
  --side-bg: #0c2c29;
  --side-ink: #d6e6e3;
  --side-muted: #86a8a3;
  --side-hover: rgba(255, 255, 255, .06);
  --side-active: rgba(94, 205, 186, .16);
  --side-active-ink: #ffffff;
  /* الرسوم البيانية */
  --viz-1: #0f7b70;
  --viz-2: #eb6834;
  --viz-grid: #ecece6;
  --viz-axis: #c9c9c1;
  --viz-warn: #d98a00;
  --viz-bad: #d04440;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 22, .05), 0 1px 1px rgba(16, 24, 22, .03);
  --shadow-lg: 0 10px 30px rgba(16, 24, 22, .12);
  --side-w: 248px;
  font-family: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #0f1312; --surface: #171c1b; --surface-2: #1c2221; --surface-3: #232a29;
    --ink: #f1f5f4; --muted: #bfcac7; --faint: #93a09c; --line: #2e3734; --line-strong: #46514d; --th-bg: #222a28; --zebra: #1a201f;
    --accent: #3fb3a3; --accent-strong: #5cc4b5; --accent-ink: #062320; --accent-soft: #163a35; --accent-softer: #13302c;
    --wait: #f0b45a; --wait-bg: #3a2a10; --pay: #79a8ea; --pay-bg: #172a45; --good: #6ccf8f; --good-bg: #133222;
    --bad: #f08a83; --bad-bg: #401b19; --off: #a3b0ad; --off-bg: #262d2c;
    --side-bg: #0b1715; --viz-1: #3fb3a3; --viz-2: #d95926; --viz-grid: #252c2b; --viz-axis: #3a4441; --viz-warn: #e0a030; --viz-bad: #e66767;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3); --shadow-lg: 0 10px 30px rgba(0, 0, 0, .45);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1312; --surface: #171c1b; --surface-2: #1c2221; --surface-3: #232a29;
  --ink: #f1f5f4; --muted: #bfcac7; --faint: #93a09c; --line: #2e3734; --line-strong: #46514d; --th-bg: #222a28; --zebra: #1a201f;
  --accent: #3fb3a3; --accent-strong: #5cc4b5; --accent-ink: #062320; --accent-soft: #163a35; --accent-softer: #13302c;
  --wait: #f0b45a; --wait-bg: #3a2a10; --pay: #79a8ea; --pay-bg: #172a45; --good: #6ccf8f; --good-bg: #133222;
  --bad: #f08a83; --bad-bg: #401b19; --off: #a3b0ad; --off-bg: #262d2c;
  --side-bg: #0b1715; --viz-1: #3fb3a3; --viz-2: #d95926; --viz-grid: #252c2b; --viz-axis: #3a4441; --viz-warn: #e0a030; --viz-bad: #e66767;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3); --shadow-lg: 0 10px 30px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
html { zoom: var(--zoom, 1); }
body { background: var(--bg); color: var(--ink); font-size: 15.5px; line-height: 1.6; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
svg { display: block; }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; display: inline-block; font-feature-settings: 'tnum' 1, 'lnum' 1; letter-spacing: .01em; }
td.num, th.num { display: table-cell; direction: rtl; }
div.num { display: block; }
.muted { color: var(--muted); }
.faint { color: var(--faint); font-size: 13.5px; }
.boot { padding: 40px; text-align: center; color: var(--muted); }
.ico { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* =================== الهيكل: قائمة جانبية + محتوى =================== */
.app { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); min-height: 100vh; }
.sidebar { background: var(--side-bg); color: var(--side-ink); position: sticky; top: 0; height: calc(100vh / var(--zoom, 1)); display: flex; flex-direction: column; padding: 18px 12px; overflow-y: auto; z-index: 40; }
.side-brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.side-logo { width: 36px; height: 36px; border-radius: 10px; background: linear-gradient(145deg, #2fa797, #0f6b62); display: grid; place-items: center; color: #fff; flex: none; }
.side-logo .ico { width: 20px; height: 20px; }
.side-brand b { display: block; font-size: 15px; color: #fff; }
.side-brand small { display: block; font-size: 11.5px; color: var(--side-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px; }
.side-section { font-size: 11px; font-weight: 600; color: var(--side-muted); padding: 14px 10px 6px; letter-spacing: .02em; }
.side-nav a { display: flex; align-items: center; gap: 10px; padding: 10px 10px; border-radius: 9px; color: var(--side-ink); font-weight: 600; font-size: 15px; margin-bottom: 2px; transition: background .15s, color .15s; }
.side-nav a:hover { background: var(--side-hover); text-decoration: none; color: #fff; }
.side-nav a.on { background: var(--side-active); color: var(--side-active-ink); box-shadow: inset -3px 0 0 #5ecdba; }
.side-nav a .ico { opacity: .85; }
.side-nav .badge { margin-inline-start: auto; }
.side-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid rgba(255, 255, 255, .08); }
.side-user { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: #1f4d47; color: #cfeee8; display: grid; place-items: center; font-weight: 700; font-size: 14px; flex: none; }
.side-user b { display: block; color: #fff; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 150px; }
.side-user small { display: block; color: var(--side-muted); font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 150px; }
.side-tools { display: flex; gap: 6px; padding: 6px 8px 0; }
.side-btn { flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px; background: rgba(255, 255, 255, .06); border: 1px solid rgba(255, 255, 255, .08); color: var(--side-ink); border-radius: 8px; padding: 7px 8px; cursor: pointer; font-size: 12.5px; }
.side-btn:hover { background: rgba(255, 255, 255, .12); color: #fff; }
.side-btn .ico { width: 16px; height: 16px; }
.side-ver { font-size: 11px; color: var(--side-muted); text-align: center; padding-top: 10px; }

.main-col { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 30; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.topbar-inner { max-width: 1240px; margin: 0 auto; padding: 10px 24px; display: flex; align-items: center; gap: 12px; min-height: 60px; }
.topbar h1 { font-size: 18px; margin: 0; }
.crumb { font-size: 12.5px; color: var(--faint); }
.topbar .spacer { flex: 1; }
.icon-btn { position: relative; width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); display: grid; place-items: center; cursor: pointer; }
.icon-btn:hover { color: var(--ink); border-color: var(--line-strong); text-decoration: none; }
.icon-btn .badge { position: absolute; top: -5px; left: -5px; }
.menu-btn { display: none; }
main { max-width: 1240px; width: 100%; margin: 0 auto; padding: 22px 24px 90px; animation: page-in .25s ease; }
@keyframes page-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.scrim { display: none; }

@media (max-width: 960px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; top: 0; bottom: 0; right: 0; width: 272px; transform: translateX(105%); transition: transform .22s ease; box-shadow: var(--shadow-lg); }
  .app.menu-open .sidebar { transform: none; }
  .app.menu-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 35; }
  .menu-btn { display: grid; }
  .topbar-inner { padding: 8px 14px; }
  main { padding: 16px 14px 90px; }
  .hide-sm { display: none !important; }
}

/* =================== عناصر عامة =================== */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
h1 { font-size: 22px; margin: 0; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 600; }
h3 { font-size: 15px; margin: 0 0 8px; font-weight: 600; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; }
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 18px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.card-sub { font-size: 12.5px; color: var(--faint); font-weight: 400; margin-top: 2px; }
.empty { padding: 32px 16px; text-align: center; color: var(--muted); }
.badge { background: var(--bad); color: #fff; border-radius: 999px; font-size: 11px; min-width: 19px; height: 19px; padding: 0 5px; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; }

/* بطاقات الأرقام */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 22px; font-weight: 700; margin-top: 2px; }
.stat .value small { font-size: 13px; font-weight: 500; color: var(--muted); }
.stat.hero { background: linear-gradient(150deg, var(--accent), var(--accent-strong)); color: var(--accent-ink); border-color: transparent; }
.stat.hero .label, .stat.hero .value small, .stat.hero .faint { color: color-mix(in srgb, var(--accent-ink) 78%, transparent); }
.stat.warn .value { color: var(--bad); }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
@media (max-width: 1100px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 520px) { .kpis { grid-template-columns: minmax(0, 1fr); } }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 6px; position: relative; overflow: hidden; transition: transform .15s, box-shadow .15s; color: inherit; }
a.kpi:hover { text-decoration: none; transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.kpi-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.kpi-label { color: var(--muted); font-size: 14px; font-weight: 600; }
.kpi-icon { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.kpi-icon.warn { background: var(--wait-bg); color: var(--wait); }
.kpi-icon.bad { background: var(--bad-bg); color: var(--bad); }
.kpi-icon.pay { background: var(--pay-bg); color: var(--pay); }
.kpi-value { font-size: 28px; font-weight: 800; letter-spacing: -.01em; line-height: 1.2; }
.kpi-value small { font-size: 13px; color: var(--muted); font-weight: 500; }
.kpi-foot { font-size: 13.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.delta { font-weight: 600; font-size: 12px; padding: 1px 7px; border-radius: 999px; }
.delta.up { color: var(--good); background: var(--good-bg); }
.delta.down { color: var(--bad); background: var(--bad-bg); }
.kpi.primary { background: linear-gradient(150deg, var(--accent), var(--accent-strong)); color: var(--accent-ink); border-color: transparent; }
.kpi.primary .kpi-label, .kpi.primary .kpi-foot, .kpi.primary .kpi-value small { color: color-mix(in srgb, var(--accent-ink) 80%, transparent); }
.kpi.primary .kpi-icon { background: rgba(255, 255, 255, .16); color: var(--accent-ink); }

.figures { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface-2); margin: 14px 0 0; }
.figures > div { background: var(--surface-2); padding: 10px 12px; border-inline-end: 1px solid var(--line); border-bottom: 1px solid var(--line); margin: 0 -1px -1px 0; }
.figures .label { font-size: 13px; color: var(--muted); font-weight: 600; }
.figures .value { font-weight: 800; font-size: 18px; }
.figures > .strong { background: var(--accent-soft); }
.figures > .bad { background: var(--bad-bg); }
.figures > .bad .value, .figures > .bad .label { color: var(--bad); }

/* شارات الحالة */
.chip { display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: 3px 11px; font-size: 13.5px; font-weight: 700; white-space: nowrap; }
.chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .85; }
.chip.wait { color: var(--wait); background: var(--wait-bg); }
.chip.pay { color: var(--pay); background: var(--pay-bg); }
.chip.good { color: var(--good); background: var(--good-bg); }
.chip.bad { color: var(--bad); background: var(--bad-bg); }
.chip.off { color: var(--off); background: var(--off-bg); }

/* القوائم */
.list { list-style: none; margin: 0; padding: 0; }
.list li { border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.row-link { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 12px 18px; color: inherit; transition: background .12s; }
.row-link:hover { background: var(--surface-2); text-decoration: none; }
.row-link .t { font-weight: 600; }
.row-link .s { color: var(--muted); font-size: 14px; }
.row-link .amt { font-weight: 700; text-align: left; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; padding: 12px 18px; border-bottom: 1px solid var(--line); background: var(--surface-2); align-items: center; }
.filters select, .filters input { min-width: 150px; width: auto; flex: 1 1 160px; max-width: 280px; }
.search { position: relative; flex: 2 1 220px; max-width: 360px; }
.search input { padding-inline-start: 34px; width: 100%; max-width: none; }
.search .ico { position: absolute; top: 50%; transform: translateY(-50%); right: 10px; color: var(--faint); width: 16px; height: 16px; }

/* الجداول */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { text-align: right; padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-weight: 700; color: var(--ink); font-size: 13.5px; background: var(--th-bg); white-space: nowrap; border-bottom: 2px solid var(--line-strong); }
tbody tr:nth-child(even) > td { background: var(--zebra); }
td.n { font-weight: 600; color: var(--ink); }
td.n .num, td .num { font-size: 1.02em; }
td.n, th.n { text-align: left; }
tfoot td { font-weight: 800; background: var(--accent-soft); border-top: 2px solid var(--accent); border-bottom: 0; font-size: 15px; }
tbody tr { transition: background .12s; }
tbody tr.over > td { background: color-mix(in srgb, var(--bad-bg) 60%, var(--surface)); }
tbody tr.over > td:first-child { box-shadow: inset -3px 0 0 var(--bad); }
tr.click { cursor: pointer; }
tr.click:hover > td { background: var(--accent-softer) !important; }
.pos { color: var(--bad); }
.neg { color: var(--good); }
.cell-main { font-weight: 700; }
.cell-sub { font-size: 13.5px; color: var(--muted); }

/* النماذج */
label { display: block; font-size: 14px; color: var(--ink); margin-bottom: 5px; font-weight: 600; }
input[type=text], input[type=number], input[type=date], input[type=password], input[type=tel], input[type=search], select, textarea {
  width: 100%; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); padding: 9px 11px; background: var(--surface); min-height: 40px; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
textarea { min-height: 72px; resize: vertical; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.grid.tight { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.field { margin-bottom: 12px; }
.check { display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: 14px; margin: 0; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.segmented { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface); }
.segmented label { margin: 0; padding: 8px 14px; cursor: pointer; color: var(--ink); font-size: 14px; transition: background .12s; }
.segmented input { display: none; }
.segmented label:has(input:checked) { background: var(--accent); color: var(--accent-ink); }

.btn { border: 1px solid var(--line-strong); background: var(--surface); border-radius: var(--radius-sm); padding: 9px 16px; cursor: pointer; font-weight: 600; font-size: 14px; display: inline-flex; align-items: center; gap: 7px; min-height: 40px; color: var(--ink); transition: background .12s, border-color .12s, transform .05s; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-strong); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 35%, transparent); }
.btn.danger:hover { background: var(--bad-bg); }
.btn.small { padding: 4px 10px; min-height: 32px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn .ico { width: 16px; height: 16px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 12px; }
.link-btn { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; font-weight: 500; }
.pills { display: inline-flex; background: var(--surface-3); border-radius: 10px; padding: 3px; gap: 2px; }
.pills button { border: 0; background: none; padding: 6px 12px; border-radius: 8px; cursor: pointer; font-size: 13px; color: var(--muted); font-weight: 500; }
.pills button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

/* محرر البنود */
.items-editor td { padding: 6px; }
.items-editor input, .items-editor select { min-height: 38px; padding: 7px 8px; }
.items-editor .x { width: 36px; text-align: center; }
.items-editor .tot { font-weight: 600; white-space: nowrap; }
.grand { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; background: var(--accent-soft); border-radius: var(--radius-sm); margin-top: 10px; font-weight: 700; font-size: 17px; }

/* لوحات الإجراء والملاحظات */
.action-panel { border: 1.5px solid var(--accent); box-shadow: 0 0 0 4px var(--accent-softer); }
.action-panel > h2 { color: var(--accent); }
.note-box { background: var(--wait-bg); color: var(--wait); border-radius: var(--radius-sm); padding: 10px 12px; margin: 10px 0; font-size: 14px; }
.note-box.bad { background: var(--bad-bg); color: var(--bad); }
.note-box.info { background: var(--pay-bg); color: var(--pay); }

/* شريط مراحل العهدة */
.progress { display: flex; gap: 0; margin: 16px 0 4px; }
.progress .st { flex: 1; position: relative; text-align: center; font-size: 12px; color: var(--faint); padding-top: 30px; min-width: 0; }
.progress .st::before { content: ""; position: absolute; top: 11px; left: 50%; width: 100%; height: 2px; background: var(--line-strong); }
.progress .st:first-child::before { display: none; }
.progress .dot { position: absolute; top: 0; left: 50%; transform: translateX(-50%); width: 24px; height: 24px; border-radius: 50%; background: var(--surface); border: 2px solid var(--line-strong); display: grid; place-items: center; z-index: 1; }
.progress .dot .ico { width: 13px; height: 13px; stroke-width: 2.6; }
.progress .st.done { color: var(--muted); }
.progress .st.done .dot { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.progress .st.done::before, .progress .st.cur::before { background: var(--accent); }
.progress .st.cur { color: var(--ink); font-weight: 600; }
.progress .st.cur .dot { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.progress .st.cur .dot::after { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1.6s infinite; }
.progress.stopped .st.cur .dot { border-color: var(--bad); box-shadow: 0 0 0 4px var(--bad-bg); }
.progress.stopped .st.cur .dot::after { background: var(--bad); animation: none; }
@keyframes pulse { 50% { transform: scale(.6); opacity: .6; } }
@media (max-width: 640px) { .progress .st span { display: none; } .progress .st.cur span { display: block; position: absolute; top: 30px; left: 50%; transform: translateX(-50%); white-space: nowrap; } .progress { margin-bottom: 18px; } }

/* بطاقات الفواتير */
.lines { display: grid; gap: 10px; }
.line { border: 1px solid var(--line); border-radius: 10px; padding: 12px; display: grid; grid-template-columns: 64px 1fr auto; gap: 12px; align-items: start; background: var(--surface); }
.line .thumb { width: 64px; height: 64px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2) center/cover no-repeat; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 12px; font-weight: 600; }
.line .meta { font-size: 14px; color: var(--muted); }
.line .meta span + span::before { content: " · "; }
.line .amount { text-align: left; font-weight: 700; }
.line .review { grid-column: 1 / -1; border-top: 1px dashed var(--line); padding-top: 10px; }
.line.rejected { background: color-mix(in srgb, var(--bad-bg) 35%, var(--surface)); }
.line.rejected .amount { text-decoration: line-through; color: var(--faint); }
.tag { font-size: 11.5px; padding: 1px 8px; border-radius: 6px; font-weight: 600; }
.tag.out { background: var(--wait-bg); color: var(--wait); }
.tag.dup { background: var(--bad-bg); color: var(--bad); }

/* السجل الزمني */
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline li { position: relative; padding: 0 22px 14px 0; }
.timeline li::before { content: ""; position: absolute; right: 5px; top: 7px; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }
.timeline li::after { content: ""; position: absolute; right: 9px; top: 18px; bottom: 0; width: 1px; background: var(--line-strong); }
.timeline li:last-child::after { display: none; }
.timeline .when { font-size: 12px; color: var(--faint); }
.timeline .what { font-weight: 500; }
.timeline .note { font-size: 13.5px; color: var(--muted); background: var(--surface-2); padding: 4px 8px; border-radius: 6px; margin-top: 2px; display: inline-block; }

.detail-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px 16px; margin-top: 12px; font-size: 14px; }
.kv > div > span:first-child { display: block; font-size: 13px; color: var(--muted); font-weight: 600; }
.two-col { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 16px; align-items: start; }
.two-col > * { min-width: 0; }
@media (max-width: 1080px) { .two-col { grid-template-columns: minmax(0, 1fr); } }

/* مسار الاعتماد */
.steps { list-style: none; margin: 0; padding: 0; counter-reset: st; }
.steps li { counter-increment: st; position: relative; padding: 0 34px 14px 0; }
.steps li::before { content: counter(st); position: absolute; right: 0; top: 0; width: 24px; height: 24px; border-radius: 50%; background: var(--off-bg); color: var(--muted); font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.steps li::after { content: ""; position: absolute; right: 11.5px; top: 26px; bottom: 2px; width: 1px; background: var(--line-strong); }
.steps li:last-child::after { display: none; }
.steps li.approved::before { background: var(--good); color: #fff; }
.steps li.cur::before { background: var(--wait); color: #fff; }
.steps li.skipped .what { color: var(--faint); text-decoration: line-through; }
.steps .what { font-weight: 600; }

/* =================== لوحة التحكم =================== */
.dash-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 16px; }
.dash-grid > .card { margin: 0; }
.span-12 { grid-column: span 12; } .span-8 { grid-column: span 8; } .span-7 { grid-column: span 7; } .span-6 { grid-column: span 6; } .span-5 { grid-column: span 5; } .span-4 { grid-column: span 4; }
@media (max-width: 1100px) { .span-8, .span-7, .span-6, .span-5, .span-4 { grid-column: span 12; } }
.dash-toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.dash-toolbar select { width: auto; min-width: 200px; }
.chart { position: relative; }
.chart svg { width: 100%; height: auto; overflow: visible; }
.chart .bar { transition: opacity .15s; cursor: default; }
.chart .hit:hover + .bar, .chart .bar:hover { opacity: .8; }
.chart text { font-family: inherit; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.hbars { display: grid; gap: 10px; }
.hbar { display: grid; grid-template-columns: minmax(90px, 230px) minmax(0, 1fr) auto; gap: 10px; align-items: center; font-size: 14.5px; }
.hbar .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink); }
.hbar .track { height: 10px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.hbar .fill { height: 100%; border-radius: 999px; background: var(--viz-1); width: 0; transition: width .7s cubic-bezier(.2, .8, .2, 1); }
.hbar .fill.other { background: var(--viz-axis); }
.hbar .vl { font-weight: 700; font-size: 14px; min-width: 84px; text-align: left; }
.pipe { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
@media (max-width: 700px) { .pipe { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.pipe a { display: block; border-radius: 10px; padding: 12px; background: var(--surface-2); border: 1px solid var(--line); color: inherit; position: relative; overflow: hidden; transition: border-color .15s, transform .15s; }
.pipe a:hover { text-decoration: none; border-color: var(--accent); transform: translateY(-1px); }
.pipe .pc { font-size: 24px; font-weight: 700; line-height: 1.1; }
.pipe .pl { font-size: 12.5px; color: var(--muted); margin-top: 2px; min-height: 2.6em; }
.pipe .pa { font-size: 12.5px; font-weight: 600; margin-top: 6px; }
.pipe .bar-b { position: absolute; bottom: 0; right: 0; height: 3px; background: var(--accent); transition: width .7s; }
.aging { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.aging .ag { border-radius: 10px; padding: 12px; background: var(--surface-2); border: 1px solid var(--line); }
.aging .ag .c { font-size: 22px; font-weight: 700; }
.aging .ag .l { font-size: 12.5px; color: var(--muted); }
.aging .ag .a { font-size: 12.5px; font-weight: 600; margin-top: 4px; }
.aging .ag.warn { border-color: color-mix(in srgb, var(--viz-warn) 45%, transparent); background: color-mix(in srgb, var(--wait-bg) 60%, var(--surface)); }
.aging .ag.bad { border-color: color-mix(in srgb, var(--viz-bad) 45%, transparent); background: color-mix(in srgb, var(--bad-bg) 60%, var(--surface)); }
.aging .ag.bad .c { color: var(--bad); }
.cycle { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.cycle div { background: var(--surface-2); border-radius: 10px; padding: 12px; text-align: center; border: 1px solid var(--line); }
.cycle b { display: block; font-size: 22px; }
.cycle span { font-size: 12.5px; color: var(--muted); }
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: grid; grid-template-columns: 30px 1fr auto; gap: 10px; align-items: start; padding: 10px 18px; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.feed li:last-child { border-bottom: 0; }
.feed .fi { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.feed .fi .ico { width: 15px; height: 15px; }
.feed .fi.bad { background: var(--bad-bg); color: var(--bad); }
.feed .fi.pay { background: var(--pay-bg); color: var(--pay); }
.feed .fi.good { background: var(--good-bg); color: var(--good); }
.feed .ft { font-size: 12px; color: var(--faint); white-space: nowrap; }
.viz-tip { position: fixed; z-index: 60; pointer-events: none; background: var(--ink); color: var(--surface); padding: 7px 10px; border-radius: 8px; font-size: 12.5px; box-shadow: var(--shadow-lg); opacity: 0; transition: opacity .1s; white-space: nowrap; }
.viz-tip b { font-weight: 700; }
.viz-tip.on { opacity: 1; }
.skeleton { background: linear-gradient(90deg, var(--surface-3), var(--surface-2), var(--surface-3)); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: var(--radius); }
@keyframes shimmer { to { background-position: -200% 0; } }
.mini-progress { height: 6px; background: var(--surface-3); border-radius: 999px; overflow: hidden; margin-top: 8px; }
.mini-progress i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }

/* =================== صفحة الدخول =================== */
.login-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; background: var(--bg); }
.login-art { background: radial-gradient(1200px 600px at 100% 0%, #1b8a7d 0%, transparent 60%), linear-gradient(160deg, #0f5c55 0%, #082a27 100%); color: #e4f3f0; padding: 48px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.login-art h2 { font-size: 30px; line-height: 1.35; margin: 0 0 12px; color: #fff; font-weight: 700; }
.login-art p { color: #b5d6d0; max-width: 420px; margin: 0; }
.login-art ul { list-style: none; padding: 0; margin: 28px 0 0; display: grid; gap: 12px; }
.login-art li { display: flex; gap: 10px; align-items: center; color: #d2ebe6; }
.login-art li .ico { color: #7fe0cf; }
.login-art .deco { position: absolute; left: -80px; bottom: -80px; width: 320px; height: 320px; border-radius: 50%; border: 1px solid rgba(255, 255, 255, .08); }
.login-art .deco.b { left: -20px; bottom: -20px; width: 200px; height: 200px; }
.login-side { display: grid; place-items: center; padding: 24px; }
.login { background: var(--surface); border-radius: 16px; padding: 30px 26px; width: 100%; max-width: 390px; box-shadow: var(--shadow-lg); border: 1px solid var(--line); }
.login h1 { font-size: 22px; margin-bottom: 4px; }
.login .sub { color: var(--muted); margin-bottom: 22px; }
.login .btn { width: 100%; justify-content: center; margin-top: 8px; }
.demo { margin-top: 18px; font-size: 12.5px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 12px; }
.demo button { background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: 3px 8px; margin: 3px 2px; cursor: pointer; font-size: 12px; }
@media (max-width: 860px) { .login-wrap { grid-template-columns: 1fr; } .login-art { display: none; } }

/* =================== تنبيه =================== */
#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(16px); opacity: 0; visibility: hidden; pointer-events: none; background: var(--ink); color: var(--surface); padding: 11px 18px; border-radius: 10px; font-size: 14px; transition: transform .2s, opacity .2s, visibility .2s; z-index: 70; max-width: calc(100% - 32px); box-shadow: var(--shadow-lg); }
#toast.show { transform: translateX(-50%) translateY(0); opacity: 1; visibility: visible; }
#toast.err { background: var(--bad); color: #fff; }

.tabs { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.tabs a { padding: 6px 14px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); color: var(--muted); font-weight: 500; }
.tabs a.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.tabs a:hover { text-decoration: none; }

dialog { border: 0; border-radius: 14px; padding: 0; width: min(520px, calc(100% - 24px)); box-shadow: var(--shadow-lg); background: var(--surface); color: var(--ink); }
dialog::backdrop { background: rgba(10, 14, 13, .5); }
dialog form { padding: 20px; }

/* =================== الإعدادات =================== */
.section-title { font-size: 15px; font-weight: 600; margin: 0 0 4px; }
.section-hint { color: var(--muted); font-size: 14px; margin: 0 0 12px; }
.pick-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px; max-height: 320px; overflow-y: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 8px; background: var(--surface-2); }
.pick-list .check { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.pick-list .check:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.pick-list .check small { display: block; color: var(--muted); font-size: 12px; }
.step-row { display: grid; grid-template-columns: 30px minmax(150px, 1fr) minmax(150px, 1fr) minmax(160px, 1fr) auto; gap: 8px; align-items: end; padding: 10px 0; border-bottom: 1px solid var(--line); }
.step-row .no { width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-weight: 700; display: flex; align-items: center; justify-content: center; margin-bottom: 7px; font-size: 13px; }
.step-row .tools { display: flex; gap: 4px; padding-bottom: 2px; }
.flow-preview { background: var(--accent-soft); border-radius: var(--radius-sm); padding: 10px 12px; margin-top: 12px; font-size: 14px; }
.sticky-save { position: sticky; bottom: 0; background: var(--bg); padding: 12px 0; border-top: 1px solid var(--line); z-index: 5; }
.team-table th.c, .team-table td.c { text-align: center; }
.big-check { width: 20px; height: 20px; accent-color: var(--accent); cursor: pointer; }
.team-sum { display: grid; gap: 4px; margin-top: 12px; background: var(--accent-soft); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 14px; }
.danger-zone { border-color: color-mix(in srgb, var(--bad) 30%, transparent); }
.danger-zone .section-title { color: var(--bad); }
.blockers { margin: 6px 0 10px; padding-inline-start: 20px; color: var(--ink); font-size: 14px; }

@media (max-width: 640px) {
  body { font-size: 14.5px; }
  h1 { font-size: 19px; }
  .stat .value, .kpi-value { font-size: 21px; }
  .items-editor thead { display: none; }
  .items-editor tr { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; border-bottom: 1px solid var(--line); padding: 8px 0; }
  .items-editor td { border: 0; padding: 0; }
  .items-editor td.c-item, .items-editor td.c-desc, .items-editor td.c-note { grid-column: 1 / -1; }
  .items-editor td.x { grid-column: 2; justify-self: end; }
  .items-editor td.tot { align-self: center; }
  .items-editor td[data-l]::before { content: attr(data-l); display: block; font-size: 12px; color: var(--muted); }
  .line { grid-template-columns: 52px 1fr; }
  .line .thumb { width: 52px; height: 52px; }
  .line .amount { grid-column: 2; text-align: right; }
  .step-row { grid-template-columns: 30px 1fr; }
  .step-row > :not(.no) { grid-column: 2; }
  .aging { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hbar { grid-template-columns: minmax(70px, 110px) minmax(0, 1fr) auto; }
  .chart { overflow-x: auto; margin: 0 -6px; padding: 0 6px; }
  .chart svg { min-width: 640px; }
  .resp-table thead { display: none; }
  .resp-table tr { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
  .resp-table td { border: 0; padding: 0; }
  .resp-table td.hide-sm { display: none; }
}

.report-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; margin-bottom: 22px; }
.report-card { min-height: 112px; }
.report-table th.sortable { cursor: pointer; user-select: none; }
.report-table th.sortable:hover { color: var(--ink); }
.report-table { font-size: 14.5px; }
.report-table th { white-space: normal; vertical-align: bottom; line-height: 1.35; min-width: 70px; font-size: 13px; }
.report-table th, .report-table td { padding: 11px 10px; }
.report-table td { white-space: nowrap; }
.report-table td.wrap { white-space: normal; min-width: 110px; max-width: 200px; line-height: 1.45; }
/* العمود الأول ثابت عند التمرير الأفقي */
.report-table th:first-child, .report-table td:first-child { position: sticky; right: 0; z-index: 1; }
.report-table th:first-child { background: var(--th-bg); }
.report-table tbody td:first-child { background: var(--surface); box-shadow: -6px 0 8px -6px rgba(0, 0, 0, .18); }
.report-table tbody tr:nth-child(even) > td:first-child { background: var(--zebra); }
.report-table tfoot td:first-child { background: var(--accent-soft); }
.report-table tfoot td { white-space: nowrap; }
.ico.flip { transform: scaleX(-1); width: 14px; height: 14px; display: inline-block; vertical-align: -2px; }
.print-only { display: none; }
.print-head { justify-content: space-between; border-bottom: 2px solid #000; padding-bottom: 8px; margin-bottom: 12px; font-size: 12px; }

@media print {
  .sidebar, .topbar, .no-print, #toast { display: none !important; }
  .print-only { display: flex !important; }
  .report-table { font-size: 10.5px; }
  .report-table th, .report-table td { padding: 4px 6px; }
  .kpi { box-shadow: none; border: 1px solid #ccc; background: #fff !important; color: #000 !important; }
  .kpi * { color: #000 !important; }
  .table-wrap { overflow: visible; }
  @page { size: A4 landscape; margin: 10mm; }
  .app { display: block; }
  body { background: #fff; }
  .card { box-shadow: none; border: 0; }
  main { padding: 0; }
}

/* حجم الخط */
.size-pick { display: flex; gap: 4px; padding: 6px 8px 0; }
.size-pick button { flex: 1; background: rgba(255, 255, 255, .06); border: 1px solid rgba(255, 255, 255, .08); color: var(--side-ink); border-radius: 8px; padding: 4px 0; cursor: pointer; font-weight: 700; line-height: 1.4; }
.size-pick button.on { background: var(--side-active); border-color: #5ecdba; color: #fff; }
.size-pick button:nth-child(1) { font-size: 12px; } .size-pick button:nth-child(2) { font-size: 14px; } .size-pick button:nth-child(3) { font-size: 16px; }
.size-label { font-size: 11px; color: var(--side-muted); padding: 10px 8px 0; }

/* الإشعارات */
.notif-wrap { position: relative; }
.notif-pop { position: absolute; top: 46px; left: 0; width: min(380px, calc(100vw - 24px)); background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-lg); z-index: 50; overflow: hidden; }
.notif-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.notif-list { max-height: 420px; overflow-y: auto; }
.notif-item { display: grid; grid-template-columns: 32px 1fr; gap: 10px; padding: 11px 14px; border-bottom: 1px solid var(--line); color: inherit; }
.notif-item:hover { background: var(--surface-2); text-decoration: none; }
.notif-item.unread { background: var(--accent-softer); }
.notif-item.unread .nt::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-inline-end: 6px; vertical-align: 1px; }
.notif-item .fi { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.notif-item .fi .ico { width: 16px; height: 16px; }
.notif-item .fi.bad { background: var(--bad-bg); color: var(--bad); } .notif-item .fi.good { background: var(--good-bg); color: var(--good); } .notif-item .fi.pay { background: var(--pay-bg); color: var(--pay); }
.notif-item .nt { font-weight: 700; font-size: 14.5px; }
.notif-item .nb { font-size: 13.5px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.notif-item .ft { font-size: 12px; color: var(--faint); margin-top: 2px; }
.notif-foot { display: block; text-align: center; padding: 10px; font-weight: 600; background: var(--surface-2); }
.notif-page .notif-item { padding: 14px 18px; }

/* كارت تقديم التصفية */
.submit-card { border: 2px solid var(--accent); background: linear-gradient(180deg, var(--accent-softer), var(--surface) 60%); }
.submit-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.btn.big { min-height: 48px; padding: 10px 22px; font-size: 16px; }

/* ---------- كلمة المرور، التنبيهات، النسخ الاحتياطي ---------- */
.login-wrap.single { grid-template-columns: 1fr; }
.pw-meter { height: 5px; background: var(--line); border-radius: 4px; margin-top: 6px; overflow: hidden; }
.pw-meter i { display: block; height: 100%; width: 0; background: var(--bad); transition: width .2s, background .2s; }
.pw-meter i[data-s="2"] { background: var(--wait); }
.pw-meter i[data-s="3"], .pw-meter i[data-s="4"] { background: var(--good); }
a.side-user { color: inherit; text-decoration: none; border-radius: 10px; }
a.side-user:hover { background: rgba(255,255,255,.06); }
.alert-bar { display: flex; align-items: center; gap: 8px; margin: 0 0 14px; font-weight: 600; }
.alert-bar .ico { flex: none; }
.alert-bar a { margin-inline-start: auto; color: inherit; white-space: nowrap; }
.restart-veil { position: fixed; inset: 0; z-index: 100; background: rgba(10,14,13,.6); display: grid; place-items: center; padding: 16px; }
.restart-veil > div { background: var(--surface); color: var(--ink); border-radius: 14px; padding: 26px; max-width: 420px; text-align: center; box-shadow: var(--shadow-lg); }
.restart-veil .spin { width: 34px; height: 34px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; margin: 0 auto 14px; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.stat-row { display: flex; flex-wrap: wrap; gap: 10px 26px; margin: 4px 0 6px; }
.stat-row > div > span { display: block; font-size: 13px; color: var(--muted); font-weight: 600; }
.plain-list { margin: 4px 0 0; padding-inline-start: 20px; line-height: 1.9; font-size: 14px; }

/* ---------- المسودات وتأكيد الإرسال ---------- */
dialog.send-dlg { width: min(640px, calc(100% - 24px)); }
.chain-list { margin: 0 0 10px; padding-inline-start: 22px; line-height: 1.9; }
.drafts-card { margin-bottom: 16px; border: 1px dashed var(--line-strong, var(--line)); }
.drafts-card .card-head h2 { display: flex; align-items: center; gap: 6px; }

.extend-box { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin: 0 0 12px; background: var(--surface-2, transparent); }
.extend-box > b { display: block; margin-bottom: 8px; }

.audit-diff { font-size: 13px; line-height: 1.7; min-width: 240px; }
