/* ============ Design tokens ============ */
:root, :root[data-theme="dark"] {
  --bg: #0B0D12; --sidebar: #10141C; --card: #171C26; --card-2: #1C2230; --input: #111722;
  --primary: #FF7900; --primary-hover: #FF922E; --primary-soft: rgba(255,121,0,.12); --on-primary: #1A0E00;
  --text: #F4F6FA; --text-2: #9BA5B4; --text-3: #6B7585; --border: #293140; --border-2: #222938;
  --success: #22C55E; --success-soft: rgba(34,197,94,.12);
  --danger: #EF4444; --danger-soft: rgba(239,68,68,.12);
  --warning: #F5B942; --warning-soft: rgba(245,185,66,.14);
  --info: #60A5FA; --info-soft: rgba(96,165,250,.12);
  --backdrop: rgba(5,7,10,.6);
  --shadow: 0 1px 2px rgba(0,0,0,.35); --shadow-lg: 0 12px 32px rgba(0,0,0,.45);
  --skeleton: #212836; --skeleton-hi: #2A3242;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #F4F5F7; --sidebar: #FFFFFF; --card: #FFFFFF; --card-2: #F8F9FB; --input: #FFFFFF;
  --primary-soft: rgba(255,121,0,.10); --on-primary: #FFFFFF;
  --text: #121826; --text-2: #5B6474; --text-3: #8A93A3; --border: #E3E6EB; --border-2: #EDEFF3;
  --success: #16A34A; --danger: #DC2626; --warning: #B7791F; --info: #2563EB;
  --backdrop: rgba(17,24,39,.4);
  --shadow: 0 1px 2px rgba(16,24,40,.06); --shadow-lg: 0 12px 32px rgba(16,24,40,.14);
  --skeleton: #ECEEF2; --skeleton-hi: #F5F6F8;
  color-scheme: light;
}
:root {
  --radius-sm: 6px; --radius: 10px; --radius-lg: 14px;
  --font: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, "Noto Sans Arabic", system-ui, sans-serif;
  --sidebar-w: 260px; --sidebar-w-collapsed: 72px; --topbar-h: 64px;
}

/* ============ Base ============ */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font); font-size: 14px; line-height: 1.6; color: var(--text); background: var(--bg);
  -webkit-font-smoothing: antialiased; overflow-x: hidden;
}
h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.35; }
p { margin: 0; }
a { color: var(--primary); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; display: inline-block; }
.muted { color: var(--text-2); }
.small { font-size: 12px; }
.hidden { display: none !important; }
.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; }
.icon.flip { transform: scaleX(-1); }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ============ Boot / auth screens ============ */
.boot { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--text-2); gap: 12px; }
.spinner { width: 22px; height: 22px; border: 2px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.auth-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 420px; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 32px 28px; box-shadow: var(--shadow-lg); }
.auth-card.wide { max-width: 640px; }
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.auth-brand img { width: 44px; height: 44px; object-fit: contain; border-radius: var(--radius-sm); background: var(--card-2); }
.brand-mark { width: 44px; height: 44px; border-radius: var(--radius); background: var(--primary); color: var(--on-primary); display: grid; place-items: center; flex: none; }
.brand-mark .icon { width: 24px; height: 24px; }
.auth-title { font-size: 20px; }
.auth-sub { color: var(--text-2); margin-top: 2px; }
.steps { display: flex; gap: 8px; margin-bottom: 24px; }
.step { flex: 1; display: flex; align-items: center; gap: 8px; color: var(--text-3); font-size: 13px; }
.step::before { content: attr(data-n); width: 26px; height: 26px; border-radius: 50%; border: 1px solid var(--border); display: grid; place-items: center; flex: none; font-variant-numeric: tabular-nums; }
.step.active { color: var(--text); }
.step.active::before { border-color: var(--primary); color: var(--primary); }
.step.done::before { background: var(--primary); border-color: var(--primary); color: var(--on-primary); content: "✓"; }

/* ============ Shell ============ */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); background: var(--sidebar); border-inline-start: 1px solid var(--border-2);
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; flex: none; transition: width .18s ease;
}
.sb-head { height: var(--topbar-h); display: flex; align-items: center; gap: 10px; padding: 0 16px; border-bottom: 1px solid var(--border-2); }
.sb-head img { width: 34px; height: 34px; object-fit: contain; border-radius: var(--radius-sm); }
.sb-head .brand-mark { width: 34px; height: 34px; border-radius: 8px; }
.sb-head .brand-mark .icon { width: 18px; height: 18px; }
.sb-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-nav { flex: 1; overflow-y: auto; padding: 12px 10px; }
.sb-group { font-size: 11px; color: var(--text-3); padding: 14px 10px 6px; letter-spacing: .02em; }
.sb-item {
  display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: var(--radius-sm);
  color: var(--text-2); cursor: pointer; white-space: nowrap; border: 0; background: none; width: 100%; text-align: start;
}
.sb-item:hover { background: var(--card); color: var(--text); }
.sb-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 500; }
.sb-item .soon { margin-inline-start: auto; font-size: 10px; color: var(--text-3); border: 1px solid var(--border); border-radius: 20px; padding: 0 6px; }
.sb-foot { border-top: 1px solid var(--border-2); padding: 10px; }
.app.sb-collapsed .sidebar { width: var(--sidebar-w-collapsed); }
.app.sb-collapsed .sb-name, .app.sb-collapsed .sb-label, .app.sb-collapsed .sb-group, .app.sb-collapsed .soon { display: none; }
.app.sb-collapsed .sb-item { justify-content: center; padding: 10px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: var(--topbar-h); display: flex; align-items: center; gap: 12px; padding: 0 24px;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border-2); position: sticky; top: 0; z-index: 20;
}
.topbar-title { font-size: 17px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-spacer { flex: 1; }
.content { padding: 24px; width: 100%; max-width: 1440px; margin: 0 auto; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { font-size: 22px; }
.page-head p { color: var(--text-2); margin-top: 2px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.sb-backdrop { display: none; }

/* ============ Buttons ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 38px; padding: 0 16px;
  border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--card); color: var(--text);
  cursor: pointer; font-weight: 500; white-space: nowrap; transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--card-2); border-color: var(--text-3); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 85%, #fff); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--card); color: var(--text); border-color: transparent; }
.btn-icon { width: 38px; padding: 0; }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; }
.btn-block { width: 100%; }
.btn .spinner { width: 16px; height: 16px; }
.icon-btn-badge { position: relative; }
.icon-btn-badge .dot { position: absolute; top: 6px; inset-inline-end: 6px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 10px; background: var(--primary); color: var(--on-primary); font-size: 10px; display: grid; place-items: center; }

/* ============ Cards & stats ============ */
.card { background: var(--card); border: 1px solid var(--border-2); border-radius: var(--radius); padding: 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.card-head h3 { font-size: 15px; }
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.stat { background: var(--card); border: 1px solid var(--border-2); border-radius: var(--radius); padding: 18px 18px 16px; display: flex; flex-direction: column; gap: 10px; min-width: 0; text-align: start; color: inherit; font: inherit; }
button.stat { cursor: pointer; transition: border-color .12s; }
button.stat:hover { border-color: var(--border); }
.stat-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.stat-label { color: var(--text-2); font-size: 13px; }
.stat-icon { width: 36px; height: 36px; border-radius: var(--radius-sm); display: grid; place-items: center; background: var(--card-2); color: var(--text-2); }
.stat-icon.tone-primary { background: var(--primary-soft); color: var(--primary); }
.stat-icon.tone-success { background: var(--success-soft); color: var(--success); }
.stat-icon.tone-danger { background: var(--danger-soft); color: var(--danger); }
.stat-icon.tone-warning { background: var(--warning-soft); color: var(--warning); }
.stat-icon.tone-info { background: var(--info-soft); color: var(--info); }
.stat-value { font-size: 24px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-value.is-empty { color: var(--text-3); }
.stat-hint { color: var(--text-3); font-size: 12px; }
.stat-lg .stat-value { font-size: 28px; }

/* ============ Forms ============ */
.form { display: flex; flex-direction: column; gap: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid .span-2 { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label { font-size: 13px; color: var(--text-2); font-weight: 500; }
.field label .req { color: var(--primary); }
.input, select.input, textarea.input {
  width: 100%; height: 42px; padding: 0 12px; background: var(--input); border: 1px solid var(--border);
  border-radius: var(--radius-sm); outline: none; transition: border-color .12s, box-shadow .12s;
}
textarea.input { height: auto; min-height: 88px; padding: 10px 12px; resize: vertical; }
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.input::placeholder { color: var(--text-3); }
.input[dir="ltr"] { text-align: left; }
.field.has-error .input { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: 12px; }
.field-hint { color: var(--text-3); font-size: 12px; }
.input-wrap { position: relative; }
.input-wrap .input { padding-inline-start: 38px; }
.input-wrap .icon { position: absolute; inset-inline-start: 12px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.check { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; padding: 6px 0; }
.check input { width: 18px; height: 18px; accent-color: var(--primary); margin: 2px 0 0; flex: none; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius-sm); border: 1px solid; font-size: 13px; }
.alert .icon { margin-top: 2px; }
.alert-danger { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 35%, transparent); color: var(--text); }
.alert-danger .icon { color: var(--danger); }
.alert-warning { background: var(--warning-soft); border-color: color-mix(in srgb, var(--warning) 35%, transparent); }
.alert-warning .icon { color: var(--warning); }
.alert-info { background: var(--info-soft); border-color: color-mix(in srgb, var(--info) 30%, transparent); }
.alert-info .icon { color: var(--info); }
.alert-success { background: var(--success-soft); border-color: color-mix(in srgb, var(--success) 35%, transparent); }
.alert-success .icon { color: var(--success); }
.logo-picker { display: flex; align-items: center; gap: 12px; }
.logo-preview { width: 56px; height: 56px; border-radius: var(--radius); border: 1px dashed var(--border); display: grid; place-items: center; color: var(--text-3); overflow: hidden; background: var(--input); flex: none; }
.logo-preview img { width: 100%; height: 100%; object-fit: contain; }
.secret-box { font-family: ui-monospace, Consolas, monospace; font-size: 18px; letter-spacing: .05em; background: var(--input); border: 1px dashed var(--border); border-radius: var(--radius-sm); padding: 12px; text-align: center; direction: ltr; user-select: all; }

/* ============ Badges ============ */
.badge { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 20px; font-size: 12px; font-weight: 500; background: var(--card-2); color: var(--text-2); white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-primary { background: var(--primary-soft); color: var(--primary); }

/* ============ Tables ============ */
.dt { background: var(--card); border: 1px solid var(--border-2); border-radius: var(--radius); overflow: hidden; }
.dt-toolbar { display: flex; gap: 12px; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--border-2); flex-wrap: wrap; }
.dt-toolbar .input-wrap { flex: 1; min-width: 200px; max-width: 360px; }
.dt-toolbar .input { height: 38px; }
.dt-filters { display: flex; gap: 8px; flex-wrap: wrap; }
.dt-filters select.input { height: 38px; width: auto; min-width: 140px; }
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; }
.table th { text-align: start; font-size: 12px; font-weight: 500; color: var(--text-2); padding: 10px 16px; background: var(--card-2); border-bottom: 1px solid var(--border-2); white-space: nowrap; }
.table th.sortable { cursor: pointer; user-select: none; }
.table th.sortable:hover { color: var(--text); }
.table th .sort-ind { opacity: .5; margin-inline-start: 4px; }
.table td { padding: 12px 16px; border-bottom: 1px solid var(--border-2); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr:hover td { background: color-mix(in srgb, var(--card-2) 60%, transparent); }
.table td.end, .table th.end { text-align: end; }
.dt-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--border-2); flex-wrap: wrap; color: var(--text-2); font-size: 13px; }
.pagination { display: flex; gap: 4px; align-items: center; }
.pagination .btn { height: 32px; min-width: 32px; padding: 0 10px; }
.pagination .btn.current { background: var(--primary-soft); border-color: transparent; color: var(--primary); }
.cell-main { font-weight: 500; }
.cell-sub { color: var(--text-3); font-size: 12px; }

/* ============ Empty / skeleton ============ */
.empty { text-align: center; padding: 48px 24px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.empty-icon { width: 56px; height: 56px; border-radius: 50%; background: var(--card-2); color: var(--text-3); display: grid; place-items: center; margin-bottom: 4px; }
.empty-icon .icon { width: 26px; height: 26px; }
.empty h3 { font-size: 16px; }
.empty p { color: var(--text-2); max-width: 420px; }
.empty .btn { margin-top: 8px; }
.skel { background: linear-gradient(90deg, var(--skeleton) 25%, var(--skeleton-hi) 50%, var(--skeleton) 75%); background-size: 200% 100%; animation: shimmer 1.4s ease infinite; border-radius: var(--radius-sm); }
@keyframes shimmer { to { background-position: -200% 0; } }
.skel-line { height: 12px; margin: 10px 0; }
.skel-stat { height: 122px; border-radius: var(--radius); }
@media (prefers-reduced-motion: reduce) { .skel, .spinner { animation: none; } }

/* ============ Overlays ============ */
.overlay { position: fixed; inset: 0; background: var(--backdrop); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 16px; animation: fade .12s ease; }
@keyframes fade { from { opacity: 0; } }
.modal { width: 100%; max-width: 520px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); }
.modal.lg { max-width: 760px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border-2); }
.modal-head h3 { font-size: 16px; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--border-2); flex-wrap: wrap; }
.overlay.drawer-overlay { justify-content: flex-start; padding: 0; align-items: stretch; }
.drawer { width: 100%; max-width: 480px; height: 100%; background: var(--card); border-inline-end: 1px solid var(--border); display: flex; flex-direction: column; animation: slideIn .16s ease; }
@keyframes slideIn { from { transform: translateX(24px); opacity: 0; } }
.toasts { position: fixed; bottom: 20px; inset-inline-start: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; max-width: calc(100vw - 40px); }
.toast { display: flex; align-items: flex-start; gap: 10px; min-width: 260px; max-width: 420px; padding: 12px 14px; background: var(--card-2); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); animation: fade .15s ease; }
.toast .icon { margin-top: 2px; }
.toast-success .icon { color: var(--success); }
.toast-danger .icon { color: var(--danger); }
.toast-warning .icon { color: var(--warning); }
.toast-info .icon { color: var(--info); }
.toast .toast-msg { flex: 1; }
.menu { position: absolute; z-index: 60; min-width: 220px; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 6px; }
.menu-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: 0; background: none; border-radius: var(--radius-sm); color: var(--text); cursor: pointer; text-align: start; }
.menu-item:hover { background: var(--card-2); }
.menu-item.danger { color: var(--danger); }
.menu-sep { height: 1px; background: var(--border-2); margin: 6px 0; }
.menu-header { padding: 8px 10px 10px; }
.menu-panel { width: 340px; max-width: calc(100vw - 32px); padding: 0; }
.menu-panel .panel-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--border-2); }
.menu-panel .panel-body { max-height: 360px; overflow-y: auto; }

/* ============ Tabs / timeline / misc ============ */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border-2); margin-bottom: 20px; overflow-x: auto; scrollbar-width: none; }
.tab { padding: 10px 14px; border: 0; background: none; color: var(--text-2); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; display: inline-flex; gap: 8px; align-items: center; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 500; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 22px 16px 0; border-inline-start: 0; }
.timeline li::before { content: ""; position: absolute; inset-inline-start: 4px; top: 7px; width: 8px; height: 8px; border-radius: 50%; background: var(--border); }
.timeline li::after { content: ""; position: absolute; inset-inline-start: 7px; top: 18px; bottom: 0; width: 1px; background: var(--border-2); }
.timeline li:last-child::after { display: none; }
.timeline .t-title { font-weight: 500; }
.timeline .t-meta { color: var(--text-3); font-size: 12px; }
.daterange { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.daterange select.input, .daterange input.input { height: 38px; width: auto; }
.perm-group { border: 1px solid var(--border-2); border-radius: var(--radius); padding: 12px 14px; }
.perm-group h4 { font-size: 13px; color: var(--text-2); margin-bottom: 6px; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 8px 16px; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; word-break: break-word; }
.json-diff { font-family: ui-monospace, Consolas, monospace; font-size: 12px; background: var(--input); border: 1px solid var(--border-2); border-radius: var(--radius-sm); padding: 10px; direction: ltr; text-align: left; white-space: pre-wrap; word-break: break-word; max-height: 240px; overflow: auto; }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 4px 6px 4px 10px; border-radius: 40px; border: 1px solid transparent; background: none; cursor: pointer; }
.user-chip:hover { background: var(--card); border-color: var(--border-2); }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-weight: 600; flex: none; }
.user-chip .u-name { font-weight: 500; font-size: 13px; line-height: 1.2; text-align: start; }
.user-chip .u-role { color: var(--text-3); font-size: 11px; line-height: 1.2; text-align: start; }
.chart-box { position: relative; height: 260px; }
.list-plain { list-style: none; margin: 0; padding: 0; }
.list-plain li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border-2); }
.list-plain li:last-child { border-bottom: 0; }

/* ============ Responsive ============ */
@media (max-width: 1279px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 767px) {
  .sidebar { position: fixed; inset-inline-start: 0; top: 0; z-index: 90; transform: translateX(100%); transition: transform .2s ease; width: min(84vw, var(--sidebar-w)) !important; box-shadow: var(--shadow-lg); }
  .app.sb-open .sidebar { transform: none; }
  .app.sb-open .sb-backdrop { display: block; position: fixed; inset: 0; background: var(--backdrop); z-index: 80; }
  .app.sb-collapsed .sb-name, .app.sb-collapsed .sb-label, .app.sb-collapsed .sb-group, .app.sb-collapsed .soon { display: revert; }
  .app.sb-collapsed .sb-item { justify-content: flex-start; padding: 9px 12px; }
  .topbar { padding: 0 12px; gap: 6px; }
  .content { padding: 16px; }
  .grid-4, .grid-3, .grid-2, .form-grid { grid-template-columns: minmax(0, 1fr); }
  .form-grid .span-2 { grid-column: auto; }
  .grid-4.keep-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-value { font-size: 20px; }
  .page-head h1 { font-size: 19px; }
  .user-chip .u-text { display: none; }
  .dt-toolbar .input-wrap { max-width: none; }
  /* tables become card lists */
  .table.responsive thead { display: none; }
  .table.responsive, .table.responsive tbody, .table.responsive tr, .table.responsive td { display: block; width: 100%; }
  .table.responsive tr { padding: 12px 16px; border-bottom: 1px solid var(--border-2); }
  .table.responsive tbody tr:last-child { border-bottom: 0; }
  .table.responsive td { border: 0; padding: 3px 0; display: flex; justify-content: space-between; gap: 12px; text-align: end; }
  .table.responsive td::before { content: attr(data-label); color: var(--text-3); font-size: 12px; text-align: start; flex: none; }
  .table.responsive td.td-title { font-size: 15px; padding-bottom: 6px; text-align: start; }
  .table.responsive td.td-title::before { display: none; }
  .table.responsive tbody tr:hover td { background: none; }
  .modal { max-height: calc(100vh - 16px); }
  .overlay { padding: 8px; align-items: flex-end; }
  .modal-foot .btn { flex: 1; }
  .toasts { inset-inline: 12px; bottom: 12px; }
  .toast { min-width: 0; max-width: none; }
  .kv { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .kv dd { margin-bottom: 8px; }
  .auth-card { padding: 24px 18px; }
  .steps .step span { display: none; }
}
/* ============ Finance pages ============ */
.back-link { display: inline-flex; align-items: center; gap: 4px; color: var(--text-2); font-size: 13px; margin-bottom: 8px; }
.back-link:hover { color: var(--text); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.doc-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.doc-head h1 { font-size: 22px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.totals { width: 100%; max-width: 360px; margin-inline-start: auto; }
.totals .t-row { display: flex; justify-content: space-between; padding: 6px 0; color: var(--text-2); }
.totals .t-row.grand { color: var(--text); font-weight: 600; font-size: 16px; border-top: 1px solid var(--border-2); margin-top: 4px; padding-top: 10px; }
.totals .t-row.due { color: var(--primary); font-weight: 600; }
.items-editor { width: 100%; border-collapse: collapse; }
.items-editor th { text-align: start; font-size: 12px; font-weight: 500; color: var(--text-2); padding: 6px 6px; }
.items-editor td { padding: 4px 6px; vertical-align: top; }
.items-editor .input { height: 38px; }
.items-editor .c-desc { width: 50%; }
.items-editor .c-qty { width: 12%; }
.items-editor .c-price { width: 18%; }
.items-editor .c-total { width: 16%; text-align: end; padding-top: 12px; white-space: nowrap; }
.layout-2 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.fund-card { display: flex; flex-direction: column; gap: 12px; }
.fund-card .fund-balance { font-size: 26px; font-weight: 600; }
.fund-card .fund-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.search-box { position: relative; width: 100%; max-width: 380px; }
.search-box .input { height: 38px; }
.search-results { position: absolute; top: 44px; inset-inline: 0; z-index: 70; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); max-height: 420px; overflow-y: auto; padding: 6px; }
.search-results .sr-group { font-size: 11px; color: var(--text-3); padding: 8px 10px 4px; }
.search-results .sr-item { display: block; width: 100%; text-align: start; padding: 8px 10px; border: 0; background: none; border-radius: var(--radius-sm); cursor: pointer; color: var(--text); }
.search-results .sr-item:hover, .search-results .sr-item:focus { background: var(--card-2); outline: none; }
.chip-row { display: flex; gap: 6px; flex-wrap: wrap; }
.progress { height: 6px; background: var(--card-2); border-radius: 6px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--primary); }
.progress.over > span { background: var(--danger); }
.report-meta { color: var(--text-3); font-size: 12px; margin-top: 12px; }
#print-root { display: none; }
.help-dot { display: inline-flex; align-items: center; justify-content: center; width: 17px; height: 17px; border-radius: 50%; font-size: 11px; font-weight: 700; line-height: 1; vertical-align: middle; cursor: help; user-select: none; color: var(--primary); background: color-mix(in srgb, var(--primary) 14%, transparent); border: 1px solid color-mix(in srgb, var(--primary) 40%, transparent); transition: background .15s, color .15s; flex-shrink: 0; }
.help-dot:hover, .help-dot:focus-visible, .help-dot[aria-expanded="true"] { background: var(--primary); color: #fff; outline: none; }
.help-pop { position: fixed; z-index: 300; display: none; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--card); color: var(--text); border: 1px solid var(--border); box-shadow: var(--shadow-lg); font-size: 13px; font-weight: 400; line-height: 1.7; white-space: pre-line; text-align: start; }
.help-pop.open { display: block; }
.pick-card { border: 1px solid var(--border-2); border-radius: var(--radius); padding: 12px; background: var(--card-2); }
.pick-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.pick-plans { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin-top: 10px; }
.pick-plan { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--card); color: var(--text); cursor: pointer; text-align: start; font: inherit; }
.pick-plan:hover, .pick-plan:focus-visible { border-color: var(--primary); outline: none; }
.pick-plan .pp-name { font-weight: 600; }
.pick-plan .pp-price { color: var(--primary); font-size: 13px; }
.items-tools { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }

@media (max-width: 1023px) {
  .layout-2 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 767px) {
  .search-box { max-width: none; }
  .topbar .search-box { display: none; }
  .items-editor thead { display: none; }
  .items-editor, .items-editor tbody, .items-editor tr, .items-editor td { display: block; width: 100% !important; }
  .items-editor tr { border: 1px solid var(--border-2); border-radius: var(--radius); padding: 8px; margin-bottom: 8px; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
  .items-editor td.c-desc { grid-column: 1 / -1; }
  .items-editor td.c-total { text-align: start; }
}

/* ============ Invoice / receipt document (A4, matches company template) ============ */
.modal.doc { max-width: 880px; }
.modal.doc .modal-body { background: #EEEBE3; padding: 20px 12px; }
.modal.doc .modal-foot { flex-wrap: wrap; }
.doc-scroller { overflow-x: auto; }
.doc-sheet {
  --ink: #1A1A1A; --soft: #414552; --hair: #E3E3E3; --pill: #F2F2F5;
  --fs: 14px; --fs-th: 12px; --row-pad: 10px; --gap: 40px;
  width: 210mm; min-height: 297mm; margin: 0 auto; background: #fff; color: var(--ink);
  box-shadow: 0 1px 3px rgba(0,0,0,.08), 0 10px 30px rgba(0,0,0,.08);
  padding: 11mm 11mm 24mm; position: relative; font-size: var(--fs); line-height: 1.5;
}
.doc-sheet.d1 { --fs: 13px; --fs-th: 11.5px; --row-pad: 6px; --gap: 26px; }
.doc-sheet.d2 { --fs: 12px; --fs-th: 11px; --row-pad: 3px; --gap: 16px; }
.doc-sheet.ar { font-family: 'IBM Plex Sans Arabic', 'Segoe UI', Tahoma, sans-serif; text-align: right; }
.doc-sheet.en { font-family: 'Inter', 'Segoe UI', Arial, sans-serif; text-align: left; }
.doc-sheet * { color: inherit; }
.doc-top { display: flex; justify-content: space-between; align-items: flex-start; }
.doc-sheet .doc-title { font-size: 30px; font-weight: 600; margin: 0; line-height: 1.2; letter-spacing: -.2px; display: flex; align-items: center; gap: 10px; }
.doc-sheet.ar .doc-title { font-weight: 700; }
.doc-logo { height: 44px; display: flex; align-items: center; }
.doc-logo img { max-height: 44px; max-width: 180px; object-fit: contain; display: block; }
.doc-meta { border-collapse: collapse; margin-top: 18px; }
.doc-meta td { padding: 0 0 1px; vertical-align: top; font-size: var(--fs); line-height: 1.55; border: 0; }
.doc-meta td.k { font-weight: 600; padding-inline-end: 12px; white-space: nowrap; }
.doc-meta td.v { font-variant-numeric: tabular-nums; }
.doc-meta td.v.strong { font-weight: 600; }
.doc-parties { display: flex; margin-top: calc(var(--gap) * .6); }
.doc-parties .from { width: 45%; padding-inline-end: 16px; }
.doc-parties .to { flex: 1; }
.doc-sheet .co-line { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.doc-sheet .co-name { font-weight: 600; }
.doc-pill { background: var(--pill); border-radius: 5px; padding: 1px 7px; color: var(--soft); font-size: calc(var(--fs) - .5px); font-weight: 400; }
.doc-pill.doc-void { background: #FDECEC; color: #B42318; font-size: 13px; }
.doc-sheet .addr { line-height: 1.55; }
.doc-sheet .bill-lbl { font-weight: 600; font-size: calc(var(--fs) - .5px); margin-bottom: 5px; }
.doc-sheet .doc-headline { font-size: 21px; font-weight: 600; margin: calc(var(--gap) * .85) 0 0; letter-spacing: -.1px; }
.doc-sheet.ar .doc-headline { font-weight: 700; }
.doc-paynote { margin-top: 12px; font-size: calc(var(--fs) - .5px); white-space: pre-wrap; }
.doc-paynote .lbl { font-weight: 600; margin-inline-end: 6px; }
.doc-items { width: 100%; border-collapse: collapse; margin-top: calc(var(--gap) * .95); }
.doc-sheet.receipt .doc-items { margin-top: calc(var(--gap) * .85); }
.doc-items thead { display: table-header-group; }
.doc-items th, .doc-hist th { font-size: var(--fs-th); font-weight: 400; text-align: start; padding: 0 0 7px; border-bottom: 1.5px solid var(--ink); background: none; }
.doc-items th.n, .doc-items td.n { text-align: end; white-space: nowrap; font-variant-numeric: tabular-nums; }
.doc-items th.q { width: 60px; } .doc-items th.u { width: 130px; } .doc-items th.a { width: 135px; }
.doc-items tbody tr { break-inside: avoid; page-break-inside: avoid; }
.doc-items td { padding: var(--row-pad) 0 0; vertical-align: top; border: 0; }
.doc-items td + td { padding-inline-start: 12px; }
.doc-items tbody tr:first-child td { padding-top: calc(var(--row-pad) + 4px); }
.doc-items .it-title { white-space: pre-wrap; }
.doc-closing { break-inside: avoid; page-break-inside: avoid; }
.doc-totals { display: flex; justify-content: flex-end; margin-top: calc(var(--gap) * .6); }
.doc-totals table { width: 50%; border-collapse: collapse; margin: 0; }
.doc-totals td { padding: 1px 0; border: 0; border-top: 1px solid var(--hair); font-variant-numeric: tabular-nums; }
.doc-totals td.v { text-align: end; white-space: nowrap; }
.doc-totals tr.last td { font-weight: 600; }
.doc-sheet .doc-hist-title { font-size: 21px; font-weight: 600; margin: calc(var(--gap) * 1.05) 0 0; }
.doc-sheet.ar .doc-hist-title { font-weight: 700; }
.doc-hist { width: 100%; border-collapse: collapse; margin-top: calc(var(--gap) * .9); }
.doc-hist td { padding: calc(var(--row-pad) + 4px) 0 0; vertical-align: top; font-variant-numeric: tabular-nums; border: 0; }
.doc-hist .c-date { width: 21%; } .doc-hist .c-amt { width: 17%; } .doc-hist .c-no { width: 16%; text-align: end; } .doc-hist .c-method { width: 46%; }
.doc-recv { margin-top: calc(var(--gap) * .9); display: flex; justify-content: flex-end; }
.doc-recv .recv-box { width: 50%; }
.doc-recv .recv-line { border-top: 1px solid var(--ink); margin-top: 34px; padding-top: 5px; font-size: var(--fs-th); display: flex; justify-content: space-between; gap: 10px; }
.doc-notes { margin-top: calc(var(--gap) * .9); font-size: calc(var(--fs) - .5px); line-height: 1.7; color: var(--soft); }
.doc-notes .lbl { font-weight: 600; color: var(--ink); margin-bottom: 3px; }
.doc-notes .body { white-space: pre-wrap; color: var(--soft); }
@page docar {
  size: A4; margin: 11mm 11mm 24mm;
  @bottom-left { content: "صفحة " counter(page) " من " counter(pages); font-family: 'IBM Plex Sans Arabic', sans-serif; font-size: 9pt; color: #1A1A1A; vertical-align: top; padding-top: 7mm; border-top: 0.5pt solid #E3E3E3; }
  @bottom-right { content: ""; border-top: 0.5pt solid #E3E3E3; }
  @bottom-center { content: ""; border-top: 0.5pt solid #E3E3E3; }
}
@page docen {
  size: A4; margin: 11mm 11mm 24mm;
  @bottom-right { content: "Page " counter(page) " of " counter(pages); font-family: Inter, Arial, sans-serif; font-size: 9pt; color: #1A1A1A; vertical-align: top; padding-top: 7mm; border-top: 0.5pt solid #E3E3E3; }
  @bottom-left { content: ""; border-top: 0.5pt solid #E3E3E3; }
  @bottom-center { content: ""; border-top: 0.5pt solid #E3E3E3; }
}

/* ============ Print (A4) ============ */
@page { size: A4; margin: 14mm; }
@media print {
  html, body { background: #fff !important; color: #111 !important; }
  body > *:not(#print-root) { display: none !important; }
  #print-root { display: block !important; font-size: 12px; color: #111; }
  #print-root .p-head { display: flex; justify-content: space-between; gap: 24px; border-bottom: 2px solid #FF7900; padding-bottom: 12px; margin-bottom: 16px; }
  #print-root .p-company { display: flex; gap: 12px; align-items: center; }
  #print-root .p-company img { width: 64px; height: 64px; object-fit: contain; }
  #print-root .p-name { font-size: 18px; font-weight: 700; }
  #print-root .p-small { color: #555; font-size: 11px; }
  #print-root .p-title { font-size: 20px; font-weight: 700; color: #FF7900; margin-bottom: 6px; }
  #print-root .kv { display: grid; grid-template-columns: auto auto; gap: 2px 12px; font-size: 11px; }
  #print-root .kv dt { color: #555; }
  #print-root .kv dd { margin: 0; }
  #print-root > :not(.doc-sheet) table { width: 100%; border-collapse: collapse; margin: 12px 0; }
  #print-root > :not(.doc-sheet) th { background: #f3f3f3; text-align: start; padding: 6px 8px; font-size: 11px; border-bottom: 1px solid #ccc; }
  #print-root > :not(.doc-sheet) td { padding: 6px 8px; border-bottom: 1px solid #eee; }
  #print-root .end { text-align: end; }
  #print-root .p-box { border: 1px solid #ddd; border-radius: 6px; padding: 10px 12px; margin: 10px 0; }
  #print-root > :not(.doc-sheet) .totals .t-row { display: flex; justify-content: space-between; padding: 3px 0; }
  #print-root > :not(.doc-sheet) .totals .t-row.grand { font-weight: 700; border-top: 1px solid #ccc; }
  #print-root .p-foot { margin-top: 24px; color: #555; font-size: 11px; white-space: pre-wrap; }
  #print-root .num { direction: ltr; }
  #print-root .doc-sheet { width: auto; min-height: 0; padding: 0; margin: 0; box-shadow: none; font-size: var(--fs); color: #1A1A1A; }
  #print-root .doc-sheet.ar { page: docar; }
  #print-root .doc-sheet.en { page: docen; }
}