:root {
  --primary: #1F3A5F;
  --accent: #C8A24A;
  --bg: #F6F4EF;
  --surface: #FFFFFF;
  --ink: #1B1E24;
  --muted: #6B7280;
  --line: #E6E2D8;
  --ok: #1E7F4F;
  --warn: #B7791F;
  --bad: #B42318;
  --info: #2F5D8C;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 24, 31, .06), 0 4px 16px rgba(20, 24, 31, .04);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: 'IBM Plex Sans Arabic', system-ui, sans-serif;
  background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.6;
}
.boot { padding: 48px; text-align: center; color: var(--muted); }
a { color: var(--primary); }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }

/* ---------- الهيكل ---------- */
.shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.side {
  background: var(--primary); color: #fff; padding: 20px 14px; position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 4px; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; border-bottom: 1px solid rgba(255,255,255,.12); margin-bottom: 10px; }
.brand img { width: 38px; height: 38px; border-radius: 9px; background: #fff; object-fit: contain; }
.brand b { display: block; font-size: 16px; }
.brand small { opacity: .7; font-size: 12px; }
.side a {
  color: rgba(255,255,255,.82); text-decoration: none; padding: 9px 12px; border-radius: 9px; font-weight: 500;
}
.side a:hover { background: rgba(255,255,255,.08); color: #fff; }
.side a.on { background: rgba(255,255,255,.14); color: #fff; box-shadow: inset -3px 0 0 var(--accent); }
.side .grow { flex: 1; }
.side .who { font-size: 13px; opacity: .8; padding: 10px 12px; border-top: 1px solid rgba(255,255,255,.12); }
.side .who button { margin-top: 6px; }
main { padding: 28px 32px 60px; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
h1 { font-size: 24px; margin: 0; }
h2 { font-size: 17px; margin: 0 0 12px; }
.menu-btn { display: none; }

/* ---------- عناصر ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.grid { display: grid; gap: 16px; }
.kpis { grid-template-columns: repeat(3, 1fr); margin-bottom: 18px; }
.kpi .label { color: var(--muted); font-size: 13px; }
.kpi .value { font-size: 26px; font-weight: 700; margin-top: 4px; }
.kpi .sub { font-size: 12px; color: var(--muted); }
.kpi.accent { border-top: 3px solid var(--accent); }
.two { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }

.btn {
  font: inherit; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 8px 14px; border-radius: 9px; cursor: pointer; font-weight: 500; white-space: nowrap;
}
.btn:hover { border-color: var(--primary); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.danger { color: var(--bad); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.ghost { background: transparent; border-color: rgba(255,255,255,.3); color: #fff; }
.btn:disabled { opacity: .5; cursor: default; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th, td { white-space: nowrap; padding: 10px 14px; text-align: right; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12.5px; color: var(--muted); font-weight: 600; background: #FBFAF7; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #FCFBF8; }
td.empty { text-align: center; color: var(--muted); padding: 28px; }
tr.click { cursor: pointer; }

.pill { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.pill.paid, .pill.done, .pill.active { background: #E5F3EC; color: var(--ok); }
.pill.partial, .pill.in_progress, .pill.due { background: #FBF1DE; color: var(--warn); }
.pill.overdue, .pill.urgent, .pill.terminated { background: #FDE8E6; color: var(--bad); }
.pill.upcoming, .pill.open, .pill.high { background: #E7EEF6; color: var(--info); }
.pill.void, .pill.ended, .pill.low, .pill.normal { background: #EFEEEA; color: var(--muted); }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
input, select, textarea {
  font: inherit; width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--primary) 30%, transparent); border-color: var(--primary); }
.filters select, .filters input { width: auto; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.form-grid .full { grid-column: 1 / -1; }
.hint { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.muted { color: var(--muted); }
dl.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px 18px; margin: 0; }
dl.facts dt { font-size: 12.5px; color: var(--muted); }
dl.facts dd { margin: 0; font-weight: 600; }

dialog { border: 0; border-radius: 14px; padding: 0; width: min(620px, 94vw); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(15, 20, 30, .45); }
dialog form { padding: 22px; }
dialog h2 { margin-bottom: 16px; }
dialog .foot { display: flex; gap: 8px; justify-content: flex-start; margin-top: 18px; }
.err { color: var(--bad); font-size: 13.5px; margin-top: 10px; min-height: 1em; }

#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px); opacity: 0;
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 10px; transition: .25s; pointer-events: none; z-index: 50;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- الدخول ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(circle at 20% 0%, color-mix(in srgb, var(--accent) 18%, transparent), transparent 40%), var(--bg); }
.auth .card { width: min(400px, 100%); padding: 28px; }
.auth .brand { color: var(--ink); border-color: var(--line); }
.auth .brand img { border: 1px solid var(--line); }
.auth .brand small { color: var(--muted); }
.auth form > div { margin-bottom: 12px; }
.auth .btn { width: 100%; padding: 10px; margin-top: 6px; }

/* ---------- الموبايل ---------- */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 0 0 auto; width: 260px; transform: translateX(100%); transition: transform .2s; z-index: 40; }
  .shell.nav-open .side { transform: none; }
  .menu-btn { display: inline-block; }
  main { padding: 18px 16px 60px; }
  .form-grid { grid-template-columns: 1fr; }
  .kpi .value { font-size: 22px; }
  .kpis { grid-template-columns: 1fr 1fr; }
  th, td { padding: 9px 10px; }
}
