/* البداية — الحسابات والخزنة */
:root {
  --navy: #011748; --navy-2: #0b2a6b; --blue: #478FDB; --blue-soft: #e8f1fb;
  --bg: #f3f5f9; --card: #ffffff; --ink: #0b1a3f; --muted: #5d6b84; --line: #dde3ee;
  --good: #137a4b; --good-bg: #e6f5ee; --bad: #b3261e; --bad-bg: #fdecea; --warn: #9a5b00; --warn-bg: #fff4e0;
  --radius: 10px; --shadow: 0 1px 2px rgba(1,23,72,.06), 0 4px 16px rgba(1,23,72,.06);
  --font: 'IBM Plex Sans Arabic', system-ui, -apple-system, 'Segoe UI', Tahoma, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { font: 15px/1.6 var(--font); color: var(--ink); background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--blue); }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.num, .money { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }

/* boot + login */
.boot { min-height: 100vh; display: grid; place-content: center; text-align: center; color: var(--muted); }
.boot img { width: 160px; margin: 0 auto 12px; }
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: linear-gradient(160deg, var(--navy) 0 45%, var(--bg) 45% 100%); }
.login-card { width: 100%; max-width: 380px; background: var(--card); border-radius: 16px; padding: 32px 28px; box-shadow: var(--shadow); }
.login-card img { display: block; width: 150px; margin: 0 auto 8px; }
.login-card h1 { text-align: center; font-size: 18px; margin: 0 0 22px; color: var(--navy); }

/* shell */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.side { background: var(--navy); color: #dbe5f7; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.side .brand { display: flex; align-items: center; gap: 10px; padding: 18px 16px; border-bottom: 1px solid rgba(255,255,255,.08); }
.side .brand img { width: 44px; height: 44px; background: #fff; border-radius: 10px; padding: 4px; object-fit: contain; }
.side .brand b { display: block; color: #fff; font-size: 15px; }
.side .brand small { color: #9fb3d9; font-size: 12px; }
.side nav { padding: 10px 8px; overflow-y: auto; flex: 1; }
.side .group { font-size: 11.5px; color: #8ea3cb; padding: 14px 10px 4px; }
.side a.nav { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: #dbe5f7; text-decoration: none; font-weight: 500; }
.side a.nav:hover { background: rgba(255,255,255,.06); }
.side a.nav.on { background: var(--blue); color: #fff; }
.side .me { padding: 12px 16px; border-top: 1px solid rgba(255,255,255,.08); font-size: 13px; }
.side .me b { color: #fff; display: block; }
.side .me button { margin-top: 8px; width: 100%; background: transparent; color: #dbe5f7; border: 1px solid rgba(255,255,255,.2); border-radius: 8px; padding: 6px; cursor: pointer; }
.topbar { display: none; }
main.content { padding: 24px 28px 64px; min-width: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { margin: 0; font-size: 22px; color: var(--navy); }
.page-head p { margin: 2px 0 0; color: var(--muted); font-size: 13.5px; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 0 0 auto; width: 260px; z-index: 40; transform: translateX(100%); transition: transform .2s; }
  .shell.open .side { transform: none; }
  .shell.open::after { content: ''; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 30; }
  .topbar { display: flex; align-items: center; gap: 10px; background: var(--navy); color: #fff; padding: 10px 14px; position: sticky; top: 0; z-index: 20; }
  .topbar button { background: transparent; border: 0; color: #fff; font-size: 22px; cursor: pointer; }
  .topbar img { width: 30px; height: 30px; background: #fff; border-radius: 7px; padding: 2px; }
  main.content { padding: 16px 14px 64px; }
}

/* cards, kpis */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card + .card { margin-top: 16px; }
.card h2 { margin: 0 0 12px; font-size: 16px; color: var(--navy); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi span { color: var(--muted); font-size: 13px; }
.kpi b { display: block; font-size: 22px; color: var(--navy); }

/* toolbar + forms */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar .grow { flex: 1; }
.input, select.input, textarea.input { height: 38px; border: 1px solid var(--line); border-radius: 8px; background: #fff; padding: 0 10px; min-width: 0; }
textarea.input { height: auto; padding: 8px 10px; }
.input:focus { border-color: var(--blue); outline: none; box-shadow: 0 0 0 3px var(--blue-soft); }
.field { display: grid; gap: 4px; margin-bottom: 12px; }
.field label { font-size: 13px; color: var(--muted); font-weight: 500; }
.field .hint { font-size: 12px; color: var(--muted); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 12px; }
@media (max-width: 600px) { .grid2, .grid3 { grid-template-columns: 1fr; } }

.btn { height: 38px; padding: 0 16px; border-radius: 8px; border: 1px solid var(--line); background: #fff; cursor: pointer; font-weight: 500; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.primary:hover { background: var(--navy-2); }
.btn.blue { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.danger { color: var(--bad); border-color: #f0c4c0; }
.btn.small { height: 30px; padding: 0 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.full { width: 100%; justify-content: center; }

/* tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th { background: #f6f8fc; color: var(--muted); font-weight: 600; font-size: 12.5px; text-align: right; padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; position: sticky; top: 0; }
table.t td { padding: 8px 10px; border-bottom: 1px solid #eef1f6; vertical-align: middle; }
table.t tr:last-child td { border-bottom: 0; }
table.t tbody tr.click { cursor: pointer; }
table.t tbody tr.click:hover td { background: #f8fafe; }
table.t tfoot td { font-weight: 700; background: #f6f8fc; border-top: 1px solid var(--line); }
td.n, th.n { text-align: left; }
.empty { padding: 32px; text-align: center; color: var(--muted); }

/* badges */
.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; background: #eef1f6; color: var(--muted); white-space: nowrap; }
.badge.good { background: var(--good-bg); color: var(--good); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.blue { background: var(--blue-soft); color: var(--navy-2); }
.pos { color: var(--good); } .neg { color: var(--bad); }

/* segmented 1 / ½ / 0 */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 4px 12px; cursor: pointer; font-weight: 600; min-width: 42px; }
.seg button + button { border-right: 1px solid var(--line); }
.seg button.on[data-v="1"] { background: var(--good); color: #fff; }
.seg button.on[data-v="0.5"] { background: var(--blue); color: #fff; }
.seg button.on[data-v="0"] { background: #8a94a6; color: #fff; }
tr.dirty td { background: #fffbea !important; }

/* month grid */
.mgrid td.d { text-align: center; padding: 0; min-width: 30px; cursor: pointer; user-select: none; font-weight: 600; }
.mgrid td.d.v1 { background: var(--good-bg); color: var(--good); }
.mgrid td.d.v05 { background: var(--blue-soft); color: var(--navy-2); }
.mgrid td.d.v0 { background: #f1f3f7; color: #8a94a6; }
.mgrid td.d.off { background: repeating-linear-gradient(45deg, #fafbfd, #fafbfd 4px, #f0f2f6 4px, #f0f2f6 8px); cursor: not-allowed; }
.mgrid td.d.chg { outline: 2px solid #f0b400; outline-offset: -2px; }
.mgrid th.d { text-align: center; padding: 6px 2px; min-width: 30px; }
.mgrid th.d.fri { color: var(--bad); }
.mgrid .sticky { position: sticky; right: 0; background: #fff; z-index: 1; }

/* modal */
.modal-back { position: fixed; inset: 0; background: rgba(1,23,72,.35); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 560px; max-height: 92vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { max-width: 860px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 16px; color: var(--navy); }
.modal-head button { border: 0; background: none; font-size: 20px; cursor: pointer; color: var(--muted); }
.modal-body { padding: 16px 18px; overflow-y: auto; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-start; }
.err { background: var(--bad-bg); color: var(--bad); padding: 8px 12px; border-radius: 8px; font-size: 13.5px; margin-bottom: 12px; }
.note { background: var(--blue-soft); color: var(--navy-2); padding: 8px 12px; border-radius: 8px; font-size: 13.5px; margin-bottom: 12px; }
.warnbox { background: var(--warn-bg); color: var(--warn); padding: 8px 12px; border-radius: 8px; font-size: 13.5px; margin-bottom: 12px; }

/* toasts */
#toasts { position: fixed; bottom: 16px; left: 16px; display: grid; gap: 8px; z-index: 60; }
.toast { background: var(--navy); color: #fff; padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); max-width: 360px; font-size: 14px; }
.toast.bad { background: var(--bad); }
.toast.good { background: var(--good); }

.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.tabs button { border: 0; background: none; padding: 8px 12px; cursor: pointer; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; }
.tabs button.on { color: var(--navy); border-bottom-color: var(--blue); }
.muted { color: var(--muted); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
