:root {
  --ink: #16202E;
  --ink-2: #3D4654;
  --muted: #5B6472;
  --line: #E3E6EB;
  --line-2: #EEF0F3;
  --ground: #F2F3F5;
  --surface: #FFFFFF;
  --brand: #1F3A5F;
  --brand-dark: #132840;
  --blue: #1E4FB8;
  --blue-bg: #E6EEFB;
  --warn: #9A3B06;
  --warn-strong: #C2570C;
  --warn-bg: #FFF8F2;
  --warn-line: #F2C9A8;
  --c: #00A3D7; --m: #D6247F; --y: #F2C500; --k: #16202E;
  --radius: 14px;
  --font: 'IBM Plex Sans Arabic', system-ui, sans-serif;
  --display: 'Readex Pro', 'IBM Plex Sans Arabic', sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--ground); color: var(--ink); font-family: var(--font); font-size: 15px; line-height: 1.5; -webkit-text-size-adjust: 100%; }
body.modal-open { overflow: hidden; }
a { color: var(--brand); }
a:hover { color: var(--brand-dark); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; }
.num, .money { font-variant-numeric: tabular-nums; }
.ltr { direction: ltr; unicode-bidi: isolate; }
.muted { color: var(--muted); }
.warn-text { color: var(--warn); }
.blue-text { color: var(--blue); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- layout ---------- */
.shell { min-height: 100vh; display: flex; align-items: stretch; }
.side { width: 248px; flex: 0 0 248px; background: var(--surface); border-left: 1px solid var(--line); padding: 22px 14px; display: flex; flex-direction: column; gap: 24px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; padding: 4px 8px 0; color: var(--ink); text-decoration: none; }
.brand small { font-size: 13px; color: var(--muted); font-weight: 600; }
.ahb-logo { display: block; flex: 0 0 auto; width: auto; }
.nav { display: flex; flex-direction: column; gap: 3px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-radius: 10px; color: var(--ink-2); text-decoration: none; font-weight: 500; }
.nav a:hover { background: #E8EBF0; color: var(--ink); }
.nav a.on { background: var(--brand); color: #fff; }
.nav .badge { margin-inline-start: auto; }
.me { margin-top: auto; padding: 12px 14px; border-radius: 12px; background: var(--ground); font-size: 13px; color: var(--ink-2); }
.me b { color: var(--ink); display: block; }
.main { flex: 1 1 auto; min-width: 0; padding: 26px 30px 48px; display: flex; flex-direction: column; gap: 20px; }
.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 14px; }
.page-head h1 { font-family: var(--display); font-size: 26px; font-weight: 600; }
.page-head .sub { margin-top: 4px; color: var(--muted); font-size: 14px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; }
.topbar, .tabbar { display: none; }

@media (max-width: 860px) {
  .side { display: none; }
  .main { padding: 16px 16px 96px; gap: 16px; }
  .page-head h1 { font-size: 22px; }
  .topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; background: var(--brand); color: #fff; position: sticky; top: 0; z-index: 5; }
  .topbar b { font-family: var(--display); font-size: 18px; }
  .topbar a { color: #fff; }
  .shell { flex-direction: column; }
  .tabbar { display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 6; background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
  .tabbar a { flex: 1 1 0; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px 7px; font-size: 11.5px; color: var(--muted); text-decoration: none; position: relative; }
  .tabbar a.on { color: var(--brand); font-weight: 600; }
  .tabbar .badge { position: absolute; top: 4px; right: 50%; transform: translateX(18px); }
}

/* ---------- cards & stats ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.pad { padding: 18px 20px; }
.card h2, .h2 { font-size: 17px; font-weight: 600; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.stat { padding: 16px 18px; display: flex; flex-direction: column; gap: 6px; }
.stat .label { font-size: 14px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.stat .value { font-family: var(--display); font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat .value small { font-size: 13px; color: var(--muted); font-weight: 500; }
.stat .hint { font-size: 13px; color: var(--muted); }
.stat.warn { background: var(--warn-bg); border-color: var(--warn-line); }
.stat.warn .label, .stat.warn .value { color: var(--warn); }
.dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.row2 { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-start; }
.row2 > .grow { flex: 2 1 520px; min-width: 0; }
.row2 > .side-col { flex: 1 1 300px; min-width: 0; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 16px; border-radius: 10px; border: 1px solid #D5D9E0; background: var(--surface); color: var(--ink); text-decoration: none; cursor: pointer; font-size: 14.5px; white-space: nowrap; }
.btn:hover { border-color: var(--brand); color: var(--ink); }
.btn.pri { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.btn.pri:hover { background: var(--brand-dark); color: #fff; }
.btn.danger { background: var(--warn); border-color: var(--warn); color: #fff; font-weight: 600; }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: 13.5px; border-radius: 8px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn { width: 38px; height: 38px; display: inline-grid; place-items: center; border-radius: 8px; border: 1px solid transparent; background: transparent; color: var(--muted); cursor: pointer; text-decoration: none; }
.icon-btn:hover { border-color: #D5D9E0; background: var(--ground); color: var(--ink); }
.icon-btn.del:hover { border-color: var(--warn-line); background: var(--warn-bg); color: var(--warn); }
.link-btn { border: 0; background: none; padding: 4px 0; color: var(--brand); font-weight: 600; cursor: pointer; font-size: 14px; }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .lbl { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.in { width: 100%; height: 46px; border: 1px solid #D5D9E0; border-radius: 10px; background: var(--surface); padding: 0 12px; font-size: 16px; }
textarea.in { height: auto; min-height: 80px; padding: 10px 12px; resize: vertical; }
.in:focus, .chip:focus-visible, .btn:focus-visible, .icon-btn:focus-visible, .nav a:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.in.phone { direction: ltr; text-align: right; font-variant-numeric: tabular-nums; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.grid4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; align-items: end; }
@media (max-width: 860px) { .grid3 { grid-template-columns: 1fr 1fr; } .grid4 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 420px) { .grid2.stack-sm { grid-template-columns: 1fr; } }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 40px; padding: 0 14px; border-radius: 99px; border: 1px solid #D5D9E0; background: var(--surface); color: var(--ink-2); cursor: pointer; font-size: 14px; }
.chip:hover { border-color: var(--brand); }
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip.dashed { border-style: dashed; }
.chip.dashed.on { border-style: solid; }
.chip.dark.on { background: var(--ink); border-color: var(--ink); }
.check { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; font-size: 14px; }
.check input { width: 18px; height: 18px; accent-color: var(--brand); margin: 0; }
.check.locked { background: #F6F7F9; color: var(--muted); cursor: default; }
.status { font-size: 13px; font-weight: 600; padding: 9px 12px; border-radius: 8px; }
.status.ok { background: var(--blue-bg); color: var(--blue); }
.status.new { background: #E8EBF0; color: var(--ink); }
.status.err { background: var(--warn-bg); color: var(--warn); }
.status.idle { background: none; color: var(--muted); padding: 0; font-weight: 500; }
.form-error { color: var(--warn); font-weight: 600; font-size: 14px; }
.total-box { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-radius: 10px; background: var(--ground); font-weight: 600; }
.total-box.dark { background: var(--brand); color: #fff; font-size: 16px; }
.total-box.warn { background: var(--warn-bg); border: 1px solid var(--warn-line); color: var(--warn); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; position: relative; }
.card, .field { position: relative; }
table.t { width: 100%; border-collapse: collapse; }
.t th { font-size: 13px; color: var(--muted); font-weight: 600; text-align: right; padding: 11px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; background: #FAFBFC; }
.t td { font-size: 14px; padding: 11px 14px; border-bottom: 1px solid var(--line-2); white-space: nowrap; vertical-align: middle; }
.t tr:last-child td { border-bottom: 0; }
.t tr.flash td { background: #EEF4FD; }
.t td.wrap { white-space: normal; min-width: 160px; }
.t a.row-link { color: var(--ink); text-decoration: none; font-weight: 600; }
.t a.row-link:hover { color: var(--brand); text-decoration: underline; }
/* on phones a "stack" table turns every row into a small card: label on one side, value on the other */
@media (max-width: 640px) {
  .t.stack thead { display: none; }
  .t.stack, .t.stack tbody, .t.stack tr, .t.stack td { display: block; width: 100%; }
  .t.stack tr { padding: 10px 16px; border-bottom: 1px solid var(--line); }
  .t.stack tr:last-child { border-bottom: 0; }
  .t.stack td { border: 0; padding: 3px 0; white-space: normal; display: flex; justify-content: space-between; align-items: center; gap: 12px; min-width: 0; }
  .t.stack td::before { content: attr(data-label); color: var(--muted); font-size: 13px; font-weight: 600; flex: 0 0 auto; }
  .t.stack td:not([data-label])::before, .t.stack td[data-label=""]::before { content: none; }
  .t.stack td:empty { display: none; }
  .t.stack td.cell-title { font-size: 15px; font-weight: 600; padding-bottom: 6px; }
  .t.stack td.cell-actions { justify-content: flex-start; padding-top: 6px; }
  .t.stack td.wrap { min-width: 0; }
}
.pill { display: inline-block; padding: 3px 10px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill.paid { background: var(--blue-bg); color: var(--blue); }
.pill.due { background: #FDEEE3; color: var(--warn); }
.pill.part, .pill.gray { background: var(--line-2); color: var(--ink-2); }
.pill.dark { background: var(--ink); color: #fff; }
.pill.danger { background: var(--warn); color: #fff; }
.tag { display: inline-block; margin-inline-start: 8px; padding: 1px 8px; border-radius: 99px; background: var(--line-2); color: var(--ink-2); font-size: 11px; font-weight: 600; }
.badge { min-width: 22px; height: 22px; padding: 0 6px; border-radius: 99px; background: var(--warn-strong); color: #fff; font-size: 12px; font-weight: 700; display: inline-grid; place-items: center; }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.list-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line-2); color: var(--ink); text-decoration: none; }
.list-row:last-child { border-bottom: 0; }

/* ---------- banners, toasts, modal ---------- */
.banner { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; padding: 13px 16px; border-radius: 12px; font-weight: 600; text-decoration: none; }
.banner.warn { background: var(--warn-bg); border: 1px solid var(--warn-line); color: var(--warn); }
.banner.dark { background: var(--ink); color: #fff; font-weight: 500; align-items: flex-start; justify-content: flex-start; }
.banner.info { background: var(--blue-bg); color: var(--blue); }
.toast { position: fixed; z-index: 50; bottom: 24px; left: 50%; transform: translateX(-50%); max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 12px; background: var(--ink); color: #fff; font-weight: 600; box-shadow: 0 12px 32px rgba(0,0,0,.2); cursor: pointer; }
.toast.err { background: var(--warn); }
@media (max-width: 860px) { .toast { bottom: 84px; } }
.overlay { position: fixed; inset: 0; z-index: 30; background: rgba(22, 32, 46, .5); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { width: 100%; max-width: 500px; max-height: 100%; overflow-y: auto; padding: 22px; display: flex; flex-direction: column; gap: 16px; box-shadow: 0 24px 64px rgba(0,0,0,.22); }
.modal.wide { max-width: 760px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.modal-head h2 { font-family: var(--display); font-size: 20px; font-weight: 600; }
@media (max-width: 560px) { .overlay { align-items: flex-end; padding: 0; } .modal { border-radius: 16px 16px 0 0; max-height: 92vh; } }
.loading { padding: 40px; text-align: center; color: var(--muted); }
.error-box { padding: 14px 16px; border-radius: 12px; background: var(--warn-bg); border: 1px solid var(--warn-line); color: var(--warn); font-weight: 600; display: flex; flex-wrap: wrap; align-items: center; gap: 10px; justify-content: space-between; }

/* ---------- chart ---------- */
.bars { height: 220px; display: flex; align-items: flex-end; justify-content: space-around; gap: 10px; border-bottom: 1px solid var(--line); padding: 0 6px; }
.bars .col { flex: 1 1 0; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bars .pair { display: flex; align-items: flex-end; gap: 4px; height: 180px; }
.bars .b1, .bars .b2 { width: 20px; border-radius: 4px 4px 0 0; min-height: 2px; }
.bars .b1 { background: var(--brand); } .bars .b2 { background: #7FA6E0; }
.bars-x { display: flex; justify-content: space-around; gap: 10px; padding: 0 6px; font-size: 13px; color: var(--ink-2); }
.bars-x span { flex: 1 1 0; text-align: center; }

/* ---------- login ---------- */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; background: var(--ground); }
.auth-card { width: 100%; max-width: 400px; padding: 30px 26px; display: flex; flex-direction: column; gap: 22px; }
.auth-top { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; }
.auth-top b { font-family: var(--display); font-size: 30px; letter-spacing: 1px; }
.pw-wrap { position: relative; }
.pw-wrap .in { padding-left: 74px; }
.pw-wrap button { position: absolute; left: 6px; top: 5px; height: 36px; padding: 0 10px; border: 0; border-radius: 8px; background: var(--ground); color: var(--ink-2); cursor: pointer; font-size: 13px; }

/* ---------- settings: job rows ---------- */
.job-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.job-row .job-name { flex: 2 1 200px; }
.job-row .job-unit { flex: 1 1 110px; }
.job-row .job-btns { display: inline-flex; gap: 2px; flex: 0 0 auto; }
.icon-btn:disabled { opacity: .35; cursor: default; }
@media (max-width: 560px) { .job-row { padding-bottom: 10px; border-bottom: 1px solid var(--line-2); } .job-row .job-name { flex-basis: 100%; } }

/* ---------- audit ---------- */
.audit-item { padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; border-right: 4px solid transparent; }
.audit-item.pending { border-right-color: var(--warn-strong); }
.avatar { width: 38px; height: 38px; flex: 0 0 38px; border-radius: 11px; background: var(--blue-bg); color: var(--brand); display: grid; place-items: center; font-weight: 700; }
.diff { width: 100%; border-collapse: collapse; font-size: 14px; }
.diff th { font-size: 12px; color: var(--muted); font-weight: 600; text-align: right; padding: 7px 12px; background: #F6F7F9; border-bottom: 1px solid var(--line); }
.diff td { padding: 8px 12px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
.diff tr:last-child td { border-bottom: 0; }
.old { color: var(--warn); text-decoration: line-through; }
.new { color: var(--blue); font-weight: 600; }
.meta { padding: 9px 12px; border-radius: 8px; background: #F6F7F9; font-size: 13px; color: var(--ink-2); }

/* ---------- invoice (screen + print) ---------- */
.invoice-page { background: #E9EBEF; min-height: 100vh; padding: 20px 12px 40px; }
.invoice-tools { max-width: 794px; margin: 0 auto 14px; display: flex; flex-wrap: wrap; gap: 10px; justify-content: space-between; }
.invoice { max-width: 794px; margin: 0 auto; background: #fff; color: var(--ink); padding: 48px 52px; display: flex; flex-direction: column; gap: 24px; box-shadow: 0 6px 24px rgba(0,0,0,.08); position: relative; }
.invoice .strip { display: flex; height: 6px; position: absolute; top: 0; left: 0; right: 0; }
.invoice .strip i { flex: 1 1 0; }
.inv-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; }
.inv-box { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; padding: 16px 18px; border: 1px solid #C9CED6; border-radius: 10px; }
.inv-box .k { font-size: 12px; color: #4A5361; }
.inv-box .v { font-size: 15px; font-weight: 600; margin-top: 2px; }
.inv-table { width: 100%; border-collapse: collapse; }
.inv-table th { background: var(--brand); color: #fff; font-size: 13px; font-weight: 600; text-align: right; padding: 10px 12px; }
.inv-table td { padding: 11px 12px; border-bottom: 1px solid #C9CED6; font-size: 14px; }
.inv-sum { display: flex; flex-direction: column; gap: 8px; width: 290px; flex: 0 0 auto; font-size: 14px; }
.inv-sum > div { display: flex; justify-content: space-between; }
.inv-foot { margin-top: auto; display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; padding-top: 18px; border-top: 1px solid #C9CED6; font-size: 13px; color: #4A5361; line-height: 1.8; }
@media (max-width: 640px) {
  .invoice { padding: 32px 18px; }
  .inv-box { grid-template-columns: 1fr 1fr; }
  .inv-bottom { flex-direction: column; }
  .inv-sum { width: 100%; }
}
.void-stamp { position: absolute; top: 40%; left: 50%; transform: translate(-50%, -50%) rotate(-18deg); border: 6px solid var(--warn); color: var(--warn); border-radius: 14px; padding: 6px 34px; font-family: var(--display); font-size: 72px; font-weight: 700; opacity: .35; pointer-events: none; }
@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff; }
  .invoice-page { background: #fff; padding: 0; }
  .invoice-tools, .no-print, .toast { display: none !important; }
  .invoice { box-shadow: none; max-width: none; padding: 14px 0 0; min-height: 268mm; }
  .invoice .strip { top: 0; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
