/* ALJOURNI — واجهة عربية RTL */

:root {
  --bg: #f2f5fa;
  --surface: #ffffff;
  --surface-2: #f6f8fc;
  --line: #dfe5ef;
  --line-strong: #c3cddd;
  --ink: #16213a;
  --ink-2: #45526b;
  --ink-3: #6b7790;
  --brand: #1d5fd1;
  --brand-ink: #15449a;
  --brand-soft: #e5eefc;
  --side: #0f2a5c;
  --side-ink: #d5e0f5;
  --side-active: #1b3f80;

  --ok: #1d7044;
  --ok-soft: #e2f2e8;
  --gold: #8a5d00;
  --gold-soft: #fbf0d4;
  --bad: #b02a20;
  --bad-soft: #fbe5e2;
  --info: #285b9e;
  --info-soft: #e5edf8;

  --accent: #f5821f;
  --accent-ink: #b85400;
  --accent-soft: #fff0e2;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(15, 30, 60, .06), 0 4px 16px rgba(15, 30, 60, .05);
  --shadow-lg: 0 12px 40px rgba(15, 30, 60, .22);
  --font: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, "Noto Sans Arabic", sans-serif;
  --side-w: 248px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
:focus-visible { outline: 3px solid #7fa6ea; outline-offset: 2px; }
.num, td.num, .money { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }
.muted { color: var(--ink-3); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------------------------------------------------------------- تحميل */
.boot { min-height: 100vh; display: grid; place-content: center; justify-items: center; gap: 12px; color: var(--ink-3); }
.spinner { width: 32px; height: 32px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- الدخول */
.auth {
  min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(1200px 600px at 100% 0, #dce7fb 0, transparent 60%), var(--bg);
}
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 32px 28px; }
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.logo { width: 44px; height: 44px; border-radius: 12px; background: var(--side); color: #fff; display: grid; place-items: center; font-weight: 700; letter-spacing: .5px; font-size: 15px; }
.auth-brand h1 { margin: 0; font-size: 20px; letter-spacing: .5px; }
.auth-brand p { margin: 0; color: var(--ink-3); font-size: 13px; }
.auth h2 { font-size: 18px; margin: 0 0 4px; }
.auth .lead { color: var(--ink-2); margin: 0 0 20px; font-size: 14px; }
.auth .note { margin-top: 18px; font-size: 13px; color: var(--ink-3); border-top: 1px solid var(--line); padding-top: 14px; }

/* ---------------------------------------------------------------- الهيكل */
.shell { display: grid; grid-template-columns: var(--side-w) 1fr; min-height: 100vh; }
.side {
  background: var(--side); color: var(--side-ink); position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; padding: 18px 12px; overflow-y: auto;
}
.side .brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; color: #fff; }
.side .brand .logo { background: var(--accent); color: var(--side); width: 38px; height: 38px; font-size: 13px; }
.side .brand strong { display: block; letter-spacing: .5px; }
.side .brand small { display: block; color: #9fb4dc; font-size: 12px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label { font-size: 12px; color: #93a9d4; padding: 14px 10px 6px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px;
  color: var(--side-ink); text-decoration: none; font-size: 14.5px;
}
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a[aria-current="page"] { background: var(--side-active); color: #fff; font-weight: 600; box-shadow: inset -3px 0 0 var(--accent); }
.side .side-foot { margin-top: auto; padding: 14px 8px 0; font-size: 12px; color: #93a9d4; }

.main { min-width: 0; display: flex; flex-direction: column; }
.top {
  position: sticky; top: 0; z-index: 20; background: rgba(242,245,250,.92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; padding: 10px 28px; min-height: 60px;
}
.top .menu-btn { display: none; }
.top .crumb { font-weight: 600; }
.top .spacer { flex: 1; }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 4px 4px 4px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); }
.user-chip .avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--brand-soft); color: var(--brand-ink); display: grid; place-items: center; font-weight: 700; }
.user-chip .who { line-height: 1.25; }
.user-chip .who b { display: block; font-size: 14px; }
.user-chip .who small { color: var(--ink-3); font-size: 12px; }
.session-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); display: inline-block; margin-inline-start: 4px; }

.content { padding: 24px 28px 48px; max-width: 1320px; width: 100%; }
.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: 24px; line-height: 1.3; }
.page-head p { margin: 4px 0 0; color: var(--ink-2); font-size: 14px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------------------------------------------------------------- الأزرار */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink); border-radius: var(--radius-sm); padding: 8px 14px; cursor: pointer;
  font-weight: 500; font-size: 14px; min-height: 40px; white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--surface-2); border-color: #a9b6cc; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-ink); }
.btn.danger { color: var(--bad); border-color: #e7b9b4; }
.btn.danger:hover { background: var(--bad-soft); }
.btn.danger.solid { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: rgba(0,0,0,.05); }
.btn.sm { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.btn.icon-only { padding: 0; width: 36px; min-height: 36px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn .icon { width: 17px; height: 17px; }

/* ---------------------------------------------------------------- المؤشرات */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin-bottom: 20px; }
.kpi {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px;
  box-shadow: var(--shadow); text-align: start; display: flex; flex-direction: column; gap: 6px; position: relative;
}
button.kpi { cursor: pointer; width: 100%; }
button.kpi:hover { border-color: var(--line-strong); }
.kpi .k-label { display: flex; align-items: center; gap: 8px; color: var(--ink-2); font-size: 14px; font-weight: 500; }
.kpi .k-label .icon { color: var(--brand); }
.kpi .k-value { font-size: 26px; font-weight: 700; line-height: 1.2; letter-spacing: -.3px; }
.kpi .k-value .cur { font-size: 14px; font-weight: 500; color: var(--ink-3); margin-inline-start: 4px; }
.kpi .k-sub { font-size: 12.5px; color: var(--ink-3); display: flex; align-items: center; gap: 4px; }
.kpi.neg .k-value { color: var(--bad); }
.kpi.ok .k-label .icon { color: var(--ok); }
.kpi.gold .k-label .icon { color: var(--gold); }
.kpi.bad .k-label .icon { color: var(--bad); }
.kpi.active { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand-soft), var(--shadow); }
.kpi.compact .k-value { font-size: 22px; }

/* ---------------------------------------------------------------- اللوحات */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 18px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.panel-head h2 { margin: 0; font-size: 16px; }
.panel-head .hint { color: var(--ink-3); font-size: 13px; }
.panel-body { padding: 16px 18px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tabs a {
  padding: 10px 14px; text-decoration: none; color: var(--ink-2); border-bottom: 2px solid transparent; margin-bottom: -1px;
  white-space: nowrap; font-weight: 500; display: flex; align-items: center; gap: 6px;
}
.tabs a[aria-selected="true"] { color: var(--brand-ink); border-bottom-color: var(--brand); font-weight: 600; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.tile {
  display: flex; align-items: center; gap: 12px; padding: 14px; border-radius: var(--radius); background: var(--surface);
  border: 1px solid var(--line); text-decoration: none; color: var(--ink); box-shadow: var(--shadow);
}
.tile:hover { border-color: var(--brand); }
.tile .t-ico { width: 40px; height: 40px; border-radius: 10px; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; }
.tile b { display: block; font-size: 14.5px; }
.tile small { color: var(--ink-3); font-size: 12.5px; }

/* ---------------------------------------------------------------- الجداول */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 12px 18px; border-bottom: 1px solid var(--line); }
.search { position: relative; flex: 1 1 260px; max-width: 420px; }
.search .icon { position: absolute; inset-inline-start: 11px; top: 50%; transform: translateY(-50%); color: var(--ink-3); }
.search input { width: 100%; padding-inline-start: 38px !important; }
.toolbar .count { color: var(--ink-3); font-size: 13px; margin-inline-start: auto; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line-strong); background: var(--surface); border-radius: 999px; padding: 4px 12px; font-size: 13px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.chip[aria-pressed="true"] { background: var(--brand); color: #fff; border-color: var(--brand); }

.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td { padding: 10px 14px; text-align: start; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data th { background: var(--surface-2); color: var(--ink-2); font-weight: 600; font-size: 13px; white-space: nowrap; position: sticky; top: 0; }
table.data th.sortable { cursor: pointer; user-select: none; }
table.data th.sortable:hover { color: var(--ink); }
table.data th .sort { opacity: .35; font-size: 11px; margin-inline-start: 4px; }
table.data th[aria-sort] .sort { opacity: 1; color: var(--brand); }
table.data td.num, table.data th.num { text-align: end; }
table.data tbody tr:hover { background: #f7f9fd; }
table.data tbody tr.clickable { cursor: pointer; }
table.data tfoot td { font-weight: 700; background: var(--surface-2); }
table.data .row-actions { display: flex; gap: 4px; justify-content: flex-end; }
.cell-main { font-weight: 600; }
.cell-sub { color: var(--ink-3); font-size: 12.5px; }
.empty { padding: 40px 18px; text-align: center; color: var(--ink-3); }
.empty .icon { width: 36px; height: 36px; color: var(--line-strong); margin-bottom: 6px; }
.empty b { display: block; color: var(--ink-2); margin-bottom: 2px; }

.pos { color: var(--ok); }
.neg { color: var(--bad); }

/* ---------------------------------------------------------------- الحالات */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 10px 2px 9px; border-radius: 999px; font-size: 12.5px; font-weight: 600; white-space: nowrap; border: 1px solid transparent; }
.badge .icon { width: 14px; height: 14px; stroke-width: 2.4; }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: #bfe0cb; }
.badge.gold { background: var(--gold-soft); color: var(--gold); border-color: #efd99a; }
.badge.bad { background: var(--bad-soft); color: var(--bad); border-color: #f0c2bc; }
.badge.info { background: var(--info-soft); color: var(--info); border-color: #c7d6ee; }
.badge.neutral { background: #eceff5; color: var(--ink-2); border-color: var(--line); }

/* ---------------------------------------------------------------- النماذج */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.form-grid .full { grid-column: 1 / -1; }
fieldset.group { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px 16px; margin: 0 0 14px; }
fieldset.group legend { padding: 0 6px; font-weight: 600; font-size: 14px; color: var(--brand-ink); }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field label { font-size: 13.5px; font-weight: 500; color: var(--ink-2); }
.field label .req { color: var(--bad); margin-inline-start: 2px; }
.field .hint { font-size: 12px; color: var(--ink-3); }
.field .err { font-size: 12.5px; color: var(--bad); display: none; align-items: center; gap: 4px; }
.field.invalid .err { display: flex; }
.field.invalid input, .field.invalid select, .field.invalid textarea { border-color: var(--bad); background: #fffafa; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=search], input[type=month], select, textarea {
  width: 100%; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: #fff; padding: 8px 11px; min-height: 40px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
input.ltr { direction: ltr; text-align: right; }
textarea { min-height: 76px; resize: vertical; }
.input-affix { position: relative; }
.input-affix input { padding-inline-end: 48px; }
.input-affix .affix { position: absolute; inset-inline-end: 10px; top: 50%; transform: translateY(-50%); color: var(--ink-3); font-size: 13px; pointer-events: none; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); overflow: hidden; }
.seg label { padding: 7px 14px; cursor: pointer; font-size: 14px; display: flex; align-items: center; gap: 6px; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label:has(input:checked) { background: var(--brand); color: #fff; }
.seg label:has(input:focus-visible) { outline: 3px solid #7fa6ea; outline-offset: -3px; }
.form-error { display: none; background: var(--bad-soft); color: var(--bad); border: 1px solid #f0c2bc; border-radius: var(--radius-sm); padding: 9px 12px; margin-bottom: 14px; font-size: 14px; align-items: center; gap: 8px; }
.form-error.show { display: flex; }
.stack > * + * { margin-top: 14px; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--brand); }

.lookup { border: 1px dashed var(--line-strong); border-radius: var(--radius-sm); padding: 10px 12px; background: var(--surface-2); font-size: 14px; }
.lookup.found { border-style: solid; border-color: #bfe0cb; background: #f6fbf8; }
.lookup.missing { border-style: solid; border-color: #f0c2bc; background: #fffafa; color: var(--bad); }
.lookup .l-row { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }

.calc { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 14px; }
.calc .row { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; font-size: 14px; }
.calc .row + .row { border-top: 1px dashed var(--line); }
.calc .row.total { font-weight: 700; font-size: 15px; border-top: 1px solid var(--line-strong); }

/* ---------------------------------------------------------------- تفاصيل */
dl.details { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 20px; margin: 0; }
dl.details > div { padding: 9px 0; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 12px; min-width: 0; }
dl.details dt { color: var(--ink-3); font-size: 13.5px; }
dl.details dd { margin: 0; font-weight: 600; text-align: end; overflow-wrap: anywhere; }
.breakdown { list-style: none; margin: 0; padding: 0; }
.breakdown li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.breakdown .sign { width: 24px; height: 24px; border-radius: 6px; display: grid; place-items: center; font-weight: 700; flex: none; }
.breakdown .sign.plus { background: var(--ok-soft); color: var(--ok); }
.breakdown .sign.minus { background: var(--bad-soft); color: var(--bad); }
.breakdown .lbl { flex: 1; }
.breakdown li.total { border-bottom: 0; border-top: 2px solid var(--ink); font-weight: 700; font-size: 16px; }
.formula { background: var(--brand-soft); color: var(--brand-ink); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 13.5px; margin-bottom: 12px; }

.period { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.period .field { width: 170px; }
.quick-ranges { display: flex; gap: 6px; flex-wrap: wrap; }

.statement-head { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin-bottom: 16px; }
.stat { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; background: var(--surface-2); }
.stat > span { display: block; font-size: 12.5px; color: var(--ink-3); }
.stat b { font-size: 17px; }

/* ---------------------------------------------------------------- النوافذ */
.modal-backdrop { position: fixed; inset: 0; background: rgba(10, 20, 45, .45); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 5vh 16px; overflow-y: auto; animation: fade .15s ease; }
.modal { background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg); width: 100%; max-width: 640px; display: flex; flex-direction: column; animation: rise .18s ease; }
.modal.wide { max-width: 860px; }
.modal.narrow { max-width: 440px; }
.modal-head { display: flex; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 18px; flex: 1; }
.modal-body { padding: 18px 20px; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-start; padding: 14px 20px; border-top: 1px solid var(--line); background: var(--surface-2); border-radius: 0 0 16px 16px; flex-wrap: wrap; }
.modal-foot .grow { flex: 1; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } }
.confirm-ico { width: 44px; height: 44px; border-radius: 50%; background: var(--bad-soft); color: var(--bad); display: grid; place-items: center; margin-bottom: 10px; }

/* ---------------------------------------------------------------- الإشعارات */
#toast-root { position: fixed; bottom: 20px; inset-inline-end: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; max-width: calc(100vw - 40px); }
.toast { background: #14254a; color: #fff; padding: 11px 16px; border-radius: 10px; box-shadow: var(--shadow-lg); display: flex; align-items: center; gap: 10px; animation: rise .2s ease; font-size: 14px; min-width: 240px; }
.toast.ok .icon { color: #7ed6a3; }
.toast.bad { background: var(--bad); }
.toast.leave { opacity: 0; transition: opacity .3s; }

/* ---------------------------------------------------------------- الهاتف */
.scrim { display: none; }
@media (max-width: 960px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset-block: 0; inset-inline-start: 0; width: 280px; z-index: 60; transform: translateX(100%); transition: transform .2s ease; }
  .shell.nav-open .side { transform: none; box-shadow: var(--shadow-lg); }
  .shell.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 55; }
  .top { padding: 8px 16px; }
  .top .menu-btn { display: inline-flex; }
  .content { padding: 18px 16px 90px; }
  .user-chip .who { display: none; }
  .user-chip { padding: 4px; }
  .hide-sm { display: none; }
}
@media (max-width: 720px) {
  .page-head h1 { font-size: 21px; }
  .page-head .actions { width: 100%; }
  .page-head .actions .btn { flex: 1 1 auto; }
  .kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi { padding: 12px 14px; }
  .kpi .k-value { font-size: 19px; }
  .kpi .k-label { font-size: 13px; }
  .form-grid, dl.details { grid-template-columns: 1fr; }
  .toolbar { padding: 10px 12px; }
  .search { max-width: none; }
  .panel-head, .panel-body { padding-inline: 14px; }
  .period .field { width: calc(50% - 5px); }

  /* تحويل الجداول إلى بطاقات سجلات */
  table.data.responsive thead { display: none; }
  table.data.responsive, table.data.responsive tbody, table.data.responsive tr, table.data.responsive td { display: block; width: 100%; }
  table.data.responsive tr { padding: 10px 14px; border-bottom: 1px solid var(--line); }
  table.data.responsive td { border: 0; padding: 3px 0; display: flex; justify-content: space-between; gap: 12px; text-align: end; }
  table.data.responsive td::before { content: attr(data-label); color: var(--ink-3); font-size: 13px; font-weight: 500; text-align: start; flex: none; }
  table.data.responsive td.primary { font-size: 15px; padding-bottom: 6px; }
  table.data.responsive td.primary::before { display: none; }
  table.data.responsive td.primary > * { text-align: start; }
  table.data.responsive td > .cv { min-width: 0; overflow-wrap: anywhere; }
  table.data.responsive td.primary > .cv { width: 100%; }
  table.data.responsive td.num { text-align: end; }
  table.data.responsive td.actions-cell { justify-content: flex-start; padding-top: 8px; }
  table.data.responsive td.actions-cell::before { display: none; }
  table.data.responsive tfoot { display: block; }
  table.data.responsive tfoot tr { display: flex; flex-wrap: wrap; gap: 4px 16px; padding: 10px 14px; background: var(--surface-2); }
  table.data.responsive tfoot td { display: block; width: auto; border: 0; padding: 0; }
  table.data.responsive tfoot td:empty { display: none; }

  .fab { position: fixed; bottom: 18px; inset-inline-end: 16px; z-index: 30; border-radius: 999px; min-height: 52px; padding: 0 20px; box-shadow: var(--shadow-lg); }
  .modal-backdrop { padding: 0; align-items: flex-end; }
  .modal { border-radius: 16px 16px 0 0; max-height: 94vh; }
  .modal-body { overflow-y: auto; }
  .modal-foot { border-radius: 0; }
  #toast-root { inset-inline: 16px; bottom: 80px; }
}
@media (min-width: 721px) { .fab-only { display: none; } }

/* ---------------------------------------------------------------- الطباعة */
#print-root { display: none; }
@media print {
  @page { size: A4; margin: 14mm 12mm; }
  body { background: #fff; font-size: 11.5pt; }
  body.printing > *:not(#print-root) { display: none !important; }
  body.printing #print-root { display: block; }
  .print-head { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 2px solid #000; padding-bottom: 8px; margin-bottom: 12px; }
  .print-head h1 { margin: 0; font-size: 17pt; }
  .print-head .meta { text-align: left; font-size: 9.5pt; color: #333; }
  .print-head .org { font-weight: 700; letter-spacing: .5px; }
  .print-period { font-size: 10.5pt; margin: 0 0 10px; }
  #print-root table { width: 100%; border-collapse: collapse; font-size: 9.5pt; }
  #print-root th, #print-root td { border: 1px solid #999; padding: 4px 6px; text-align: start; }
  #print-root th { background: #eee !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  #print-root td.num, #print-root th.num { text-align: left; }
  #print-root tfoot td { font-weight: 700; }
  #print-root tr { break-inside: avoid; }
  #print-root .summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 12px; }
  #print-root .summary div { border: 1px solid #999; padding: 5px 8px; }
  #print-root .summary span { display: block; font-size: 9pt; color: #444; }
  #print-root .summary b { font-size: 11.5pt; }
  #print-root dl { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; margin: 0; }
  #print-root dl div { display: flex; justify-content: space-between; border-bottom: 1px solid #ccc; padding: 5px 0; }
  #print-root dt { color: #444; }
  #print-root dd { margin: 0; font-weight: 700; }
  .print-foot { margin-top: 18px; font-size: 9pt; color: #555; display: flex; justify-content: space-between; }
}

/* محاذاة الأرقام داخل نص عربي */
.cell-sub.num, .cell-main.num { text-align: right; display: block; }
.field > .seg { align-self: flex-start; }
@media (max-width: 720px) { .statement-head { grid-template-columns: 1fr 1fr; } .stat b { font-size: 15px; } }

/* لمسات برتقالية */
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.accent:hover { background: var(--accent-ink); border-color: var(--accent-ink); }
.side .brand .logo { color: #fff; }
.logo { background: var(--side); }
.auth-brand .logo { background: linear-gradient(135deg, var(--brand) 0%, var(--side) 100%); box-shadow: inset 0 -3px 0 var(--accent); }
.page-head h1 { position: relative; padding-bottom: 6px; }
.page-head h1::after { content: ""; position: absolute; inset-inline-start: 0; bottom: 0; width: 44px; height: 3px; border-radius: 3px; background: var(--accent); }
.tabs a[aria-selected="true"] { border-bottom-color: var(--accent); }
.kpi.accent .k-label .icon { color: var(--accent); }
.tile .t-ico { background: var(--accent-soft); color: var(--accent-ink); }
.chip[aria-pressed="true"] { background: var(--side); border-color: var(--side); }

/* ---------------------------------------------------------------- توافق الهاتف */
.shell, .auth, .boot { min-height: 100dvh; }
.side { height: 100dvh; }
.sort-select { display: none; }
.top .crumb { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { -webkit-tap-highlight-color: rgba(29, 95, 209, .12); }
@media (max-width: 960px) {
  .side { padding-top: calc(18px + env(safe-area-inset-top)); padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
  .top { padding-top: calc(8px + env(safe-area-inset-top)); }
  .content { padding-bottom: calc(100px + env(safe-area-inset-bottom)); }
}
@media (max-width: 720px) {
  /* منع تكبير iOS التلقائي عند لمس الحقول */
  input[type=text], input[type=password], input[type=number], input[type=date], input[type=search], input[type=month], select, textarea { font-size: 16px; min-height: 46px; }
  input[type=date] { -webkit-appearance: none; appearance: none; text-align: right; }
  /* أهداف لمس مريحة */
  .btn { min-height: 44px; }
  .btn.sm { min-height: 40px; padding: 6px 12px; }
  .btn.icon-only, .btn.sm.icon-only { width: 42px; min-height: 42px; }
  .chip { padding: 8px 14px; font-size: 14px; }
  .check input, table.data input[type=checkbox] { width: 22px; height: 22px; }
  .seg { display: flex; width: 100%; }
  .seg label { flex: 1; justify-content: center; padding: 10px 8px; }
  /* التبويبات تملأ العرض */
  .tabs a { flex: 1 1 0; justify-content: center; padding: 10px 6px; font-size: 14px; text-align: center; }
  .tabs a .icon { display: none; }
  /* زر الإضافة العائم بدل زر الرأس */
  .has-fab .page-head .btn.accent { display: none; }
  .fab { bottom: calc(18px + env(safe-area-inset-bottom)); }
  /* الترتيب على الهاتف */
  .sort-select { display: block; flex: 1 1 100%; }
  .sort-select select { min-height: 42px; font-size: 16px; }
  .toolbar .count { margin-inline-start: 0; }
  /* النوافذ كورقة سفلية */
  .modal { max-height: 92dvh; }
  .modal-head { position: sticky; top: 0; z-index: 2; background: var(--surface); border-radius: 16px 16px 0 0; }
  .modal-foot { padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
  .modal-foot .btn { flex: 1 1 auto; }
  .modal-foot .grow { display: none; }
  .modal-body { padding: 16px; }
  fieldset.group { padding: 12px; }
  .period .field { width: calc(50% - 5px) !important; }
  .period > .btn { width: 100%; }
  .quick-ranges { width: 100%; }
  .quick-ranges .chip { flex: 1 1 auto; justify-content: center; }
  .panel-head h2 { font-size: 15px; }
  table.data.responsive td { font-size: 14.5px; }
  table.data.responsive td.actions-cell .row-actions { justify-content: flex-start; flex-wrap: wrap; width: 100%; }
  #toast-root { bottom: calc(84px + env(safe-area-inset-bottom)); }
}
@media (max-width: 370px) {
  .kpis, .statement-head { grid-template-columns: 1fr; }
  .period .field { width: 100% !important; }
}
