/* نظام الشروق — أحمر العُرف، دهبي المنقار، وحبر أسود */
:root {
  --red: #E6370B; --red-d: #B4260A; --red-soft: #FDEBE5;
  --gold: #C99419; --gold-soft: #F8EED6;
  --bg: #F7F4EF; --panel: #FFFFFF; --ink: #1C1A17; --muted: #6E675E; --line: #E7E1D8;
  --ok: #1E8E4E; --bad: #D0342C; --warn: #B7791F; --wa: #1FA855;
  --r: 14px; --shadow: 0 1px 2px rgba(28,26,23,.06), 0 4px 18px rgba(28,26,23,.05);
  --font: "IBM Plex Sans Arabic", -apple-system, "SF Arabic", "Segoe UI", Tahoma, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --red: #FF6A3D; --red-d: #FF8A66; --red-soft: #3A1F17; --gold: #E5B54A; --gold-soft: #3A3020;
    --bg: #141311; --panel: #1E1C19; --ink: #F2EEE8; --muted: #A69F95; --line: #322F2A;
    --ok: #4CC27F; --bad: #FF6B5E; --warn: #E5B54A; --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 15px; -webkit-text-size-adjust: 100%; }
body { direction: rtl; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.3; }
.muted { color: var(--muted); } .sm { font-size: 12.5px; } .b, .bold td { font-weight: 700; }
.up { color: var(--ok); } .down { color: var(--bad); } .warn-t { color: var(--warn); }
.num, td.n, .n { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }
.grow { flex: 1; }
.center { display: flex; justify-content: center; align-items: center; padding: 40px; }
.center.full { min-height: 100vh; }
.spin { width: 32px; height: 32px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--red); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.row-gap { display: flex; gap: 8px; align-items: center; }
.row-gap.wrap { flex-wrap: wrap; margin: 4px 0 14px; }

/* ---------- الهيكل ---------- */
.shell { display: flex; min-height: 100vh; }
.side { display: none; }
.main { flex: 1; min-width: 0; padding: max(14px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 96px max(14px, env(safe-area-inset-left)); }
.tabbar { position: fixed; inset: auto 0 0 0; z-index: 20; display: grid; grid-template-columns: repeat(5, 1fr); align-items: end;
  background: var(--panel); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
.tabbar a, .tabbar > button { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--muted); background: none; border: 0; padding: 4px 0; position: relative; cursor: pointer; }
.tabbar span { font-size: 20px; line-height: 1; }
.tabbar .on { color: var(--red); font-weight: 700; }
.tabbar .fab { width: 54px; height: 54px; margin: -22px auto 0; border-radius: 50%; background: var(--red); color: #fff; font-size: 30px; line-height: 1; justify-content: center;
  box-shadow: 0 6px 18px rgba(230,55,11,.4); }
.dot { position: absolute; top: 0; left: 50%; margin-left: 4px; min-width: 18px; height: 18px; border-radius: 9px; background: var(--red); color: #fff; font-size: 10px; font-style: normal; display: grid; place-items: center; padding: 0 4px; }
@media (min-width: 900px) {
  .tabbar { display: none; }
  .side { display: flex; flex-direction: column; gap: 4px; width: 250px; flex: none; position: sticky; top: 0; height: 100vh; overflow: auto;
    background: var(--panel); border-left: 1px solid var(--line); padding: 16px 12px; }
  .main { padding: 24px 28px 40px; max-width: 1200px; }
}
.brand-mini { display: flex; gap: 10px; align-items: center; padding: 4px 8px 14px; border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.brand-mini img { width: 44px; height: 44px; border-radius: 10px; background: #fff; }
.brand-mini b { display: block; font-size: 18px; color: var(--red); } .brand-mini small { color: var(--muted); }
.nav-i { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px; color: var(--ink); position: relative; background: none; border: 0; cursor: pointer; text-align: right; width: 100%; }
.nav-i:hover { background: var(--red-soft); }
.nav-i.on { background: var(--red); color: #fff; font-weight: 700; }
.nav-i .dot { position: static; margin: 0 auto 0 0; }
.nav-i.out { margin-top: auto; color: var(--muted); }
.side-new { display: flex; flex-wrap: wrap; gap: 6px; padding: 12px 8px; border-top: 1px solid var(--line); margin-top: 8px; }
.side-new .muted { width: 100%; }
.chip { font-size: 12.5px; padding: 5px 10px; border-radius: 999px; background: var(--gold-soft); border: 1px solid transparent; }
.chip:hover { border-color: var(--gold); }

/* ---------- صفحات وكروت ---------- */
.page { display: flex; flex-direction: column; gap: 14px; }
.page-head { display: flex; align-items: center; gap: 10px; min-height: 40px; }
.page-head h1 { font-size: 22px; font-weight: 800; }
.icon-btn { width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel); cursor: pointer; font-size: 18px; flex: none; display: grid; place-items: center; }
.icon-btn.sm { width: 30px; height: 30px; font-size: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.card-head h2 { font-size: 16px; font-weight: 700; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); gap: 14px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(46%, 180px), 1fr)); gap: 10px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; position: relative; overflow: hidden; }
.stat::before { content: ""; position: absolute; right: 0; top: 0; bottom: 0; width: 4px; background: var(--gold); }
.stat.main::before { background: var(--red); } .stat.warn::before { background: var(--bad); }
.stat.click { cursor: pointer; } .stat.click:hover { border-color: var(--red); }
.stat-l { font-size: 12.5px; color: var(--muted); }
.stat-v { font-size: clamp(18px, 4.6vw, 24px); font-weight: 700; font-variant-numeric: tabular-nums; margin: 2px 0; overflow-wrap: anywhere; }
.stat-s { font-size: 12px; color: var(--muted); }
.quick { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(46%, 150px), 1fr)); gap: 8px; }
.quick-btn { background: var(--red); color: #fff; font-weight: 700; padding: 13px 10px; border-radius: 12px; text-align: center; }
.quick-btn:nth-child(n+2) { background: var(--panel); color: var(--ink); border: 1px solid var(--line); }
.quick-btn:hover { filter: brightness(1.05); border-color: var(--red); }
.seg { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; align-items: center; }
.seg::-webkit-scrollbar { display: none; }
.seg button { flex: none; border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 6px 13px; font-size: 13px; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--gold-soft); border-color: var(--gold); color: var(--ink); font-weight: 700; }
.empty { color: var(--muted); text-align: center; padding: 22px 10px; }
.err-box { background: var(--red-soft); color: var(--bad); border-radius: 12px; padding: 12px 14px; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.note-box { background: var(--gold-soft); border-radius: 12px; padding: 10px 14px; }
.err-line { color: var(--bad); font-size: 13px; margin-top: 4px; }
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--line); color: var(--ink); white-space: nowrap; }
.badge.bad { background: var(--bad); color: #fff; } .badge.warn { background: var(--red-soft); color: var(--red-d); } .badge.gold { background: var(--gold-soft); } .badge.muted { color: var(--muted); }
.legend { font-size: 12px; color: var(--muted); } .sw { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin: 0 8px 0 4px; } .sw.red { background: var(--red); } .sw.gold { background: var(--gold); }

/* ---------- قوائم ---------- */
.list { display: flex; flex-direction: column; gap: 8px; }
.row-card { display: flex; align-items: center; gap: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 11px 13px; min-width: 0; }
a.row-card:hover, .row-card.click:hover { border-color: var(--red); cursor: pointer; }
.row-card.sel { border-color: var(--red); box-shadow: 0 0 0 2px var(--red-soft); }
.row-card.voided { opacity: .55; } .row-card.unread { border-right: 4px solid var(--red); }
.rc-ico { font-size: 22px; }
.rc-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.rc-main b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rc-main .muted { font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rc-end { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; flex: none; }
.search { font-size: 16px; }

/* ---------- جداول ---------- */
.tw { overflow: auto; border: 1px solid var(--line); border-radius: 12px; max-height: 70vh; -webkit-overflow-scrolling: touch; }
.tw.tall { max-height: 80vh; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { position: sticky; top: 0; background: var(--panel); text-align: right; color: var(--muted); font-weight: 700; padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; z-index: 1; }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th.n, td.n { text-align: left; }
tr.click { cursor: pointer; } tr.click:hover td { background: var(--red-soft); }
tr.bold td { background: var(--gold-soft); }

/* ---------- نماذج ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr)); gap: 12px; }
.form-grid .span2 { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.lbl { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.hint { font-size: 12px; color: var(--muted); }
.inp { font: inherit; font-size: 16px; width: 100%; min-width: 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--ink); }
.inp:focus { outline: none; border-color: var(--red); box-shadow: 0 0 0 3px var(--red-soft); background: var(--panel); }
.inp.sm { padding: 6px 9px; font-size: 14px; width: auto; }
.inp.num { direction: ltr; text-align: left; font-variant-numeric: tabular-nums; }
.inp.big { font-size: 26px; font-weight: 700; }
.inp.plain { border-color: transparent; background: transparent; padding: 4px 6px; font-weight: 600; }
.inp.plain:focus { border-color: var(--line); }
.check { display: flex; gap: 8px; align-items: center; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--red); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 9px 15px; cursor: pointer; font-weight: 600; white-space: nowrap; }
.btn:hover { border-color: var(--red); }
.btn.sm { padding: 6px 11px; font-size: 13px; }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary:hover { background: var(--red-d); }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn.ghost { background: transparent; }
.btn.wa { background: var(--wa); border-color: var(--wa); color: #fff; }
.btn.big { width: 100%; padding: 14px; font-size: 17px; border-radius: 12px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.btn:focus-visible, .inp:focus-visible, a:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }
.sticky-save { position: sticky; bottom: 76px; z-index: 5; padding-top: 4px; }
@media (min-width: 900px) { .sticky-save { bottom: 12px; } }

/* بحث واختيار */
.picker { position: relative; flex: 1; min-width: 0; }
.picker-val { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; border: 1px solid var(--gold); background: var(--gold-soft); border-radius: 10px; cursor: pointer; font-weight: 700; }
.picker-val .x { border: 0; background: none; font-size: 18px; cursor: pointer; color: var(--muted); }
.picker-list { position: absolute; z-index: 30; top: calc(100% + 4px); right: 0; left: 0; max-height: 320px; overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.15); }
.picker-item { padding: 10px 12px; cursor: pointer; border-bottom: 1px solid var(--line); }
.picker-item.hi, .picker-item:hover { background: var(--red-soft); }
.picker-msg { padding: 12px; color: var(--muted); }
.pi { display: flex; flex-direction: column; gap: 2px; } .pi .muted { font-size: 12.5px; }

/* أصناف الفاتورة */
.lines { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.line { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; background: var(--bg); }
.line.bad { border-color: var(--bad); }
.line-h { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.line-h b { flex: 1 1 60%; }
.line-f { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(46%, 120px), 1fr)); gap: 8px; align-items: end; }
.line-t { font-weight: 700; font-size: 17px; text-align: left; font-variant-numeric: tabular-nums; padding-bottom: 10px; }
.totals { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.totals > div { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.totals b { font-variant-numeric: tabular-nums; }
.totals .big { font-size: 20px; border-top: 1px dashed var(--line); padding-top: 8px; } .totals .big b { color: var(--red); }

/* رسوم */
.bars { position: relative; width: 100%; }
.bars svg { display: block; overflow: visible; }
.bars .grid { stroke: var(--line); } .bars .tick { fill: var(--muted); font-size: 10.5px; font-family: var(--font); }
.bars .tip { position: absolute; top: 0; width: 160px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; font-size: 12.5px; box-shadow: 0 6px 20px rgba(0,0,0,.12); pointer-events: none; }
.hbars { display: flex; flex-direction: column; gap: 4px; }
.hb { display: grid; grid-template-columns: minmax(0, 9.5rem) minmax(0, 1fr) 4.6rem; gap: 8px; align-items: center; font-size: 13px; padding: 4px 6px; border-radius: 8px; }
.hb.click { cursor: pointer; } .hb.click:hover { background: var(--red-soft); }
.hb-l { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .hb-t { height: 12px; } .hb-b { height: 100%; border-radius: 4px; min-width: 2px; }
.hb-v { direction: ltr; text-align: left; color: var(--muted); font-size: 12px; }

/* نوافذ */
.modal-bg, .sheet-bg { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.4); display: flex; align-items: flex-end; justify-content: center; }
@media (min-width: 700px) { .modal-bg { align-items: center; } }
.modal { background: var(--panel); width: min(100%, 560px); max-height: 92vh; display: flex; flex-direction: column; border-radius: 18px 18px 0 0; padding-bottom: env(safe-area-inset-bottom); }
@media (min-width: 700px) { .modal { border-radius: 18px; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 18px; }
.modal-body { padding: 16px; overflow: auto; display: flex; flex-direction: column; gap: 12px; }
.modal-foot { padding: 12px 16px; border-top: 1px solid var(--line); display: flex; justify-content: flex-start; gap: 8px; }
.sheet { background: var(--panel); width: 100%; border-radius: 20px 20px 0 0; padding: 16px 16px calc(20px + env(safe-area-inset-bottom)); max-height: 80vh; overflow: auto; }
.sheet h2 { font-size: 17px; margin-bottom: 12px; }
.sheet-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.sheet-btn { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 14px 6px; text-align: center; font-weight: 700; font-size: 13.5px; }
.sheet-btn:first-child { background: var(--red); color: #fff; border-color: var(--red); }
.sheet-list { display: flex; flex-direction: column; }
.sheet-row { display: flex; gap: 12px; align-items: center; padding: 13px 6px; border: 0; border-bottom: 1px solid var(--line); background: none; text-align: right; position: relative; cursor: pointer; }
.sheet-row .dot { position: static; margin: 0 auto 0 0; }
.toasts { position: fixed; z-index: 60; left: 50%; transform: translateX(-50%); bottom: calc(90px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 8px; width: min(92vw, 420px); }
.toast { background: var(--ink); color: var(--bg); padding: 12px 16px; border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.25); font-weight: 600; }
.toast.err { background: var(--bad); color: #fff; }
.log { background: var(--bg); border-radius: 10px; padding: 10px; white-space: pre-wrap; font-family: inherit; }

/* تسجيل الدخول */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(circle at 50% 0%, var(--red-soft), var(--bg) 60%); }
.login-box { background: var(--panel); border: 1px solid var(--line); border-top: 5px solid var(--red); border-radius: 18px; padding: 26px 22px; width: min(100%, 380px); display: flex; flex-direction: column; gap: 14px; text-align: center; box-shadow: var(--shadow); }
.login-logo { width: 130px; height: 130px; margin: 0 auto; background: #fff; border-radius: 22px; padding: 8px; box-shadow: 0 0 0 1px var(--line); }
.login-logo img { width: 100%; height: 100%; object-fit: contain; }
.login-box h1 { font-size: 22px; } .login-box .field { text-align: right; }

/* الفاتورة */
.invoice { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.inv-head { display: flex; gap: 12px; align-items: center; border-bottom: 3px solid var(--red); padding-bottom: 12px; flex-wrap: wrap; }
.inv-head img { width: 64px; height: 64px; background: #fff; border-radius: 10px; }
.inv-head h2 { font-size: 18px; color: var(--red); }
.inv-no { margin-right: auto; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.inv-no b { font-size: 18px; }
.inv-meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 8px 16px; }
.inv-meta div { display: flex; flex-direction: column; } .inv-meta span { font-size: 12px; color: var(--muted); }
.inv-tot { display: flex; flex-direction: column; gap: 6px; margin-right: auto; min-width: min(100%, 300px); }
.inv-tot div { display: flex; justify-content: space-between; gap: 16px; } .inv-tot b { font-variant-numeric: tabular-nums; }
.inv-tot .big { font-size: 20px; border-top: 2px solid var(--ink); padding-top: 6px; } .inv-tot .big b { color: var(--red); }
@media print {
  @page { margin: 10mm; }
  body { background: #fff; color: #000; }
  .side, .tabbar, .no-print, .page-head .icon-btn, .toasts { display: none !important; }
  .main { padding: 0 !important; }
  .page-head { display: none; }
  .invoice { border: 0; padding: 0; }
  .tw { max-height: none; overflow: visible; border: 0; }
  :root { --panel: #fff; --bg: #fff; --ink: #000; --line: #ccc; }
}

table.wrap td:not(.n) { white-space: normal; min-width: 9rem; }
.perm-group { display: flex; flex-direction: column; gap: 6px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; }
.perm-group b { color: var(--red); margin-bottom: 2px; }

/* ---------- التحقق بخطوتين ---------- */
.mfa { display: flex; flex-direction: column; gap: 10px; text-align: right; }
.login-box form { display: flex; flex-direction: column; gap: 12px; }
.mfa-steps { padding-inline-start: 20px; margin: 0; display: flex; flex-direction: column; gap: 6px; line-height: 1.7; }
.mfa-qr { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.mfa-qr img { width: 200px; height: 200px; background: #fff; padding: 8px; border-radius: 12px; border: 1px solid var(--line); }
.mfa-key { font-size: 13px; letter-spacing: 1px; word-break: break-all; background: var(--bg, #f6f3ef); padding: 6px 10px; border-radius: 8px; user-select: all; }
.code-inp { font-size: 28px; letter-spacing: 10px; text-align: center; font-variant-numeric: tabular-nums; }
.card h3 { font-size: 15px; font-weight: 700; margin-bottom: 8px; }
