:root {
  --bg: #f4f6f9; --panel: #ffffff; --ink: #1c2534; --muted: #667085; --line: #e3e7ee; --line2: #eef1f5;
  --brand: #1f3a5f; --brand2: #2b5283; --gold: #c8962e; --gold-soft: #fbf3e2;
  --ok: #18794e; --ok-soft: #e7f6ee; --warn: #b54708; --warn-soft: #fef4e6; --bad: #b42318; --bad-soft: #fdecea; --info-soft: #eaf1fb;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --font: 'Cairo';
  font-family: var(--font), 'Segoe UI', Tahoma, sans-serif; font-size: 14px; color: var(--ink);
}
* { box-sizing: border-box; }
html, body { overflow-x: hidden; }
body { margin: 0; background: var(--bg); }
a { color: var(--brand2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 16px 0 8px; color: var(--brand); }
.num, td.n, th.n { font-variant-numeric: tabular-nums; direction: ltr; text-align: left; white-space: nowrap; }

/* التخطيط */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.side { background: var(--brand); color: #dfe7f2; position: sticky; top: 0; height: 100vh; overflow-y: auto; padding-bottom: 24px; }
.side .logo { display: flex; align-items: center; gap: 10px; padding: 18px 16px 14px; border-bottom: 1px solid rgba(255,255,255,.08); }
.side .logo b { width: 34px; height: 34px; border-radius: 8px; background: var(--gold); color: var(--brand); display: grid; place-items: center; font-size: 18px; }
.side .logo span { font-weight: 700; color: #fff; font-size: 15px; line-height: 1.2; }
.side .logo small { display: block; font-weight: 400; color: #9fb3cc; font-size: 11px; }
.side .grp { padding: 14px 16px 4px; font-size: 11px; color: #8ea4c0; letter-spacing: .3px; }
.side a { display: flex; align-items: center; gap: 10px; color: #dfe7f2; padding: 6px 10px; margin: 2px 8px; border-radius: 9px; font-size: 13.5px; }
.side a:hover { background: rgba(255,255,255,.07); text-decoration: none; }
.side a.on { background: rgba(232,182,76,.16); color: #fff; box-shadow: inset -3px 0 0 var(--gold); }
.side a .badge { margin-inline-start: auto; background: var(--gold); color: var(--brand); border-radius: 10px; font-size: 11px; padding: 0 7px; font-weight: 700; }
.main { min-width: 0; }
.top { display: flex; align-items: center; gap: 12px; padding: 12px 24px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.top .sp { flex: 1; }
.top .who { font-size: 13px; color: var(--muted); }
.top .rate { font-size: 12px; background: var(--gold-soft); color: #7a5512; padding: 4px 10px; border-radius: 20px; }
.burger { display: none; background: none; border: 0; font-size: 22px; cursor: pointer; color: var(--brand); }
.page { padding: 20px 24px 40px; max-width: 1500px; }
.ph { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.ph .sp { flex: 1; }
.ph .sub { color: var(--muted); font-size: 13px; }

/* البطاقات */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.card.tight { padding: 0; overflow: hidden; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .l { color: var(--muted); font-size: 12px; }
.kpi .v { font-size: 22px; font-weight: 700; margin-top: 4px; direction: ltr; text-align: right; font-variant-numeric: tabular-nums; }
.kpi .s { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi.alert { border-color: #f5c2bd; background: var(--bad-soft); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }

/* الجداول */
.tw { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: 13px; }
table.t th { background: #f8fafc; color: #475467; font-weight: 600; text-align: right; padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; position: sticky; top: 0; cursor: pointer; user-select: none; }
table.t td { padding: 8px 10px; border-bottom: 1px solid var(--line2); vertical-align: top; white-space: nowrap; }
table.t td.wrap { white-space: normal; min-width: 220px; }
table.t tbody tr:hover td { background: #fafbfd; }
table.t tr.click { cursor: pointer; }
table.t tfoot td { font-weight: 700; background: #f8fafc; border-top: 1px solid var(--line); }
table.t td.neg { color: var(--bad); }
.empty { padding: 32px; text-align: center; color: var(--muted); }

/* الحالات */
.tag { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 500; white-space: nowrap; background: #eef1f5; color: #475467; }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.bad { background: var(--bad-soft); color: var(--bad); }
.tag.info { background: var(--info-soft); color: var(--brand2); }
.tag.gold { background: var(--gold-soft); color: #7a5512; }

/* النماذج */
.form { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px 14px; }
.form .wide { grid-column: 1 / -1; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: #344054; font-weight: 500; }
input, select, textarea { font: inherit; padding: 7px 10px; border: 1px solid #d0d5dd; border-radius: 7px; background: #fff; color: var(--ink); min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(43,82,131,.25); border-color: var(--brand2); }
input[type=number] { direction: ltr; text-align: left; }
input[readonly] { background: #f8fafc; }
textarea { min-height: 64px; resize: vertical; }
.chk { flex-direction: row; align-items: center; gap: 8px; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 14px; }
.filters label.f { min-width: 150px; }

.btn { font: inherit; border: 1px solid #d0d5dd; background: #fff; color: #344054; padding: 7px 14px; border-radius: 7px; cursor: pointer; font-weight: 500; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { background: #f9fafb; }
.btn.p { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn.p:hover { background: var(--brand2); }
.btn.g { background: var(--gold); border-color: var(--gold); color: #fff; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.bad { color: var(--bad); border-color: #f5c2bd; }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* محرر الأسطر */
table.lines { width: 100%; border-collapse: collapse; }
table.lines th { font-size: 12px; color: var(--muted); text-align: right; padding: 6px; font-weight: 600; border-bottom: 1px solid var(--line); }
table.lines td { padding: 4px; border-bottom: 1px solid var(--line2); }
table.lines input, table.lines select { width: 100%; }
table.lines .x { color: var(--bad); cursor: pointer; border: 0; background: none; font-size: 18px; }
.totals { display: flex; gap: 24px; justify-content: flex-end; flex-wrap: wrap; padding: 12px 4px 0; font-size: 13px; }
.totals b { font-size: 16px; }
.hint { font-size: 12px; color: var(--muted); }
.note { background: var(--warn-soft); border: 1px solid #f9dbaf; color: #7a3a07; padding: 10px 12px; border-radius: 8px; margin-bottom: 12px; font-size: 13px; }
.note.info { background: var(--info-soft); border-color: #cddcf1; color: var(--brand); }
.note.bad { background: var(--bad-soft); border-color: #f5c2bd; color: var(--bad); }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px 20px; }
.kv div { font-size: 13px; } .kv span { color: var(--muted); display: block; font-size: 12px; }

/* النوافذ */
.modal-bg { position: fixed; inset: 0; background: rgba(16,24,40,.45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: #fff; border-radius: 12px; width: min(760px, 100%); max-height: 90vh; overflow-y: auto; padding: 20px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal .mh { display: flex; align-items: center; margin-bottom: 14px; } .modal .mh h2 { margin: 0; flex: 1; }
#toast { position: fixed; top: 70px; left: 50%; transform: translateX(-50%); z-index: 300; align-items: center; display: flex; flex-direction: column; gap: 8px; }
#toast div { background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); max-width: 90vw; font-size: 15px; font-weight: 600; padding: 12px 22px; box-shadow: 0 10px 30px rgba(0,0,0,.25); }
#toast div.err { background: var(--bad); }

/* الدخول */
.login { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(160deg, #1f3a5f, #142640); padding: 16px; }
.login .box { background: #fff; padding: 32px; border-radius: 14px; width: min(380px, 100%); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.login .box h1 { color: var(--brand); margin-bottom: 4px; } .login .box p { color: var(--muted); margin: 0 0 20px; font-size: 13px; }
.login form { display: grid; gap: 12px; }

/* الرسم البياني */
.bars { display: flex; align-items: flex-end; gap: 10px; height: 170px; padding-top: 10px; }
.bars .b { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.bars .col { width: 100%; max-width: 46px; display: flex; gap: 3px; align-items: flex-end; height: 100%; }
.bars .col i { flex: 1; background: var(--brand2); border-radius: 4px 4px 0 0; min-height: 2px; }
.bars .col i.p { background: var(--gold); }
.bars small { font-size: 11px; color: var(--muted); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); } .legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-inline-end: 4px; vertical-align: middle; }

.tree td:first-child { white-space: nowrap; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.tabs a { padding: 8px 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.on { color: var(--brand); border-color: var(--gold); font-weight: 600; text-decoration: none; }
.rep-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.rep-list a { display: block; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; color: var(--ink); box-shadow: var(--shadow); }
.rep-list a:hover { border-color: var(--brand2); text-decoration: none; }
.rep-list a b { display: block; margin-bottom: 4px; color: var(--brand); } .rep-list a span { color: var(--muted); font-size: 12.5px; }

/* الطباعة */
.print-only { display: none; }
@media print {
  .side, .top, .no-print, .filters, .actions, .ph .btn { display: none !important; }
  .shell { display: block; } .page { padding: 0; max-width: none; } .card { box-shadow: none; border: 0; padding: 0; }
  .print-only { display: block; } body { background: #fff; } table.t th { position: static; }
}

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 0 0 auto; width: 260px; transform: translateX(100%); transition: transform .2s, visibility .2s; z-index: 40; visibility: hidden; }
  .side.open { transform: none; visibility: visible; }
  .top .who { display: none; }
  .kpis { grid-template-columns: 1fr 1fr; } .kpi .v { font-size: 18px; }
  .burger { display: block; }
  .page { padding: 16px; } .top { padding: 10px 16px; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .top .rate { display: none; }
  .pos-grid { grid-template-columns: 1fr !important; }
}

/* الأيقونات */
body, button, input, select, textarea { font-family: var(--font), 'Segoe UI', Tahoma, sans-serif; }
.svgi { display: inline-grid; place-items: center; flex: none; }
.svgi svg { width: 16px; height: 16px; display: block; }
.svgi.tile { width: 28px; height: 28px; border-radius: 8px; color: #fff; box-shadow: inset 0 -2px 0 rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.18); }
.side a .mt { flex: 1; min-width: 0; }
.side a.on .svgi.tile { box-shadow: 0 0 0 2px rgba(232,182,76,.7); }
.rep-h { display: flex; align-items: center; gap: 8px; }
.rep-h .svgi.tile { width: 26px; height: 26px; }
.rep-list a { display: flex !important; gap: 12px; align-items: flex-start; }
.rep-list a .svgi.tile { width: 38px; height: 38px; border-radius: 10px; }
.rep-list a .svgi.tile svg { width: 20px; height: 20px; }
.font-list { display: grid; gap: 10px; min-width: min(460px, 80vw); }
.font-opt { text-align: right; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; cursor: pointer; display: flex; flex-direction: column; gap: 4px; }
.font-opt b { font-size: 16px; color: var(--brand); } .font-opt span { color: var(--muted); font-size: 14px; }
.font-opt:hover { border-color: var(--brand2); } .font-opt.on { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold-soft); }

/* قائمة البحث */
.ss { position: relative; display: block; min-width: 0; }
.ss > input { width: 100%; }
.ss-list { display: none; position: fixed; background: #fff; border: 1px solid #d0d5dd; border-radius: 8px; box-shadow: 0 8px 24px rgba(16,24,40,.14); max-height: 260px; overflow-y: auto; z-index: 200; }
.ss-list.open { display: block; }
.ss-o { padding: 7px 12px; cursor: pointer; font-size: 13.5px; border-bottom: 1px solid var(--line2); }
.ss-o.hi, .ss-o:hover { background: var(--info-soft); }
.ss-new { color: var(--ok); font-weight: 600; background: var(--ok-soft); }
.ss-empty { padding: 8px 12px; color: var(--muted); font-size: 13px; }

/* المرحلة 3 */
.meter { position: relative; min-width: 110px; height: 18px; background: var(--line2); border-radius: 9px; overflow: hidden; }
.meter i { position: absolute; inset-block: 0; right: 0; border-radius: 9px; opacity: .85; }
.meter span { position: relative; display: block; text-align: center; font-size: 11.5px; line-height: 18px; font-weight: 600; color: var(--ink); }
.note b { margin-inline-end: 4px; }

/* البحث الشامل */
.gs { position: relative; flex: 1; max-width: 460px; min-width: 0; }
.gs-ic { position: absolute; inset-inline-start: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; display: flex; }
.gs-in { width: 100%; padding: 8px 36px 8px 12px; border-radius: 20px; background: var(--bg); border: 1px solid var(--line); }
.gs-in:focus { background: #fff; border-color: var(--brand2); outline: none; box-shadow: 0 0 0 3px var(--info-soft); }
.gs-list { display: none; position: absolute; top: calc(100% + 6px); inset-inline: 0; min-width: 320px; max-height: 70vh; overflow-y: auto; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 12px 32px rgba(16,24,40,.18); z-index: 100; padding: 6px 0; }
.gs-list.open { display: block; }
.gs-h { display: flex; align-items: center; gap: 6px; padding: 8px 14px 4px; font-size: 11.5px; color: var(--muted); font-weight: 600; }
.gs-h .svgi svg { width: 14px; height: 14px; }
.gs-o { display: block; padding: 7px 14px; color: var(--ink); text-decoration: none !important; border-inline-start: 3px solid transparent; }
.gs-o.hi, .gs-o:hover { background: var(--info-soft); border-inline-start-color: var(--brand2); }
.gs-t { font-size: 13.5px; font-weight: 500; } .gs-t .tag { font-size: 10.5px; padding: 0 6px; }
.gs-s { font-size: 12px; color: var(--muted); margin-top: 1px; }
.gs-empty { padding: 14px; color: var(--muted); font-size: 13px; text-align: center; }
.tsearch-bar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line2); color: var(--muted); }
.tsearch { flex: 1; max-width: 320px; padding: 6px 10px; border-radius: 16px; }
@media (max-width: 900px) { .gs { max-width: none; } .gs-list { position: fixed; top: 56px; inset-inline: 8px; min-width: 0; } }
@media (max-width: 900px) { .top { gap: 6px; } .top .btn .bt { display: none; } .top .btn.sm { padding: 6px 8px; } }
