/* INAR 14 — نظام التصميم
   الألوان الأساسية تأتي من الإعدادات (--primary و--sidebar) وتُطبَّق عند فتح البرنامج.
   كل المسافات والاتجاهات منطقية (start/end) لتعمل مع الاتجاه من اليمين إلى اليسار. */

:root {
  --primary: #E6AE1C;
  --primary-ink: #8A6508;          /* لون ذهبي داكن للنصوص على الأبيض (تباين كافٍ) */
  --primary-soft: #FBF1D3;
  --primary-line: #F0D78A;
  --on-primary: #1F1D18;
  --sidebar: #1F1D18;
  --sidebar-ink: #F2ECDC;
  --sidebar-muted: #A59E8C;
  --sidebar-line: rgba(255, 255, 255, .09);
  --sidebar-hover: rgba(255, 255, 255, .06);
  --sidebar-active: rgba(230, 174, 28, .16);
  --sidebar-active-ink: var(--primary);

  --bg: #FAF7F0;
  --surface: #FFFFFF;
  --surface-2: #FFFDF8;
  --ink: #1F1D18;
  --ink-2: #6B665A;
  --ink-3: #8C8676;
  --line: #E9E2D0;
  --line-2: #F2EDDF;
  --head: #F6F1E4;

  --ok: #2E9E6B;   --ok-ink: #1E6B48;   --ok-soft: #E3F4EB;
  --bad: #D64545;  --bad-ink: #9E2F2F;  --bad-soft: #FBE7E7;
  --info: #3B7DD8; --info-ink: #2A62B0; --info-soft: #E5EFFB;
  --warn: #C9780B; --warn-ink: #93570A; --warn-soft: #FCEEDA;
  --idle: #7D786A; --idle-ink: #5A5548; --idle-soft: #EEEADF;

  --r-lg: 16px; --r-md: 12px; --r-sm: 9px;
  --shadow-1: 0 1px 2px rgba(60, 45, 10, .05);
  --shadow-pop: 0 18px 50px -12px rgba(40, 28, 0, .35);
  --font: 'Cairo', 'Segoe UI', Tahoma, 'Noto Naskh Arabic', system-ui, sans-serif;
  --side-w: 262px;
  --top-h: 70px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.65; }
img { max-width: 100%; }
a { color: var(--primary-ink); }
a:hover { color: #5E4505; }
h1, h2, h3, h4 { margin: 0; line-height: 1.35; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.sr-only { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.ltr { direction: ltr; unicode-bidi: plaintext; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.top { align-items: flex-start; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.stack.tight { gap: 6px; }
.hidden { display: none !important; }

/* ===== الهيكل العام ===== */
.app { display: flex; min-height: 100vh; min-height: 100dvh; }
.sidebar { width: var(--side-w); flex: none; background: var(--sidebar); color: var(--sidebar-ink); display: flex; flex-direction: column; gap: 16px; padding: 20px 14px; position: sticky; top: 0; height: 100vh; height: 100dvh; overflow-y: auto; z-index: 30; }
.brand, .brand:hover { display: flex; align-items: center; gap: 12px; padding: 0 8px; text-decoration: none; color: inherit; }
.brand img { width: 44px; height: 44px; border-radius: 50%; background: #fff; object-fit: contain; flex: none; }
.brand img.logo-custom { width: auto; max-width: 150px; border-radius: 0; background: none; }
.brand-name { font-size: 18px; font-weight: 800; letter-spacing: .4px; display: block; }
.brand-sub { font-size: 12px; color: var(--sidebar-muted); display: block; }
.nav { display: flex; flex-direction: column; gap: 14px; }
.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-label { font-size: 12px; font-weight: 700; color: var(--sidebar-muted); padding: 0 12px 4px; }
.nav-link { display: flex; align-items: center; gap: 12px; min-height: 42px; padding: 0 12px; border-radius: 10px; color: var(--sidebar-ink); text-decoration: none; font-size: 14px; }
.nav-link:hover { background: var(--sidebar-hover); color: var(--sidebar-ink); }
.nav-link[aria-current="page"] { background: var(--sidebar-active); color: var(--sidebar-active-ink); font-weight: 700; }
.nav-link svg { flex: none; }
.side-foot { margin-top: auto; border-top: 1px solid var(--sidebar-line); padding-top: 12px; display: flex; flex-direction: column; gap: 2px; }
.side-ver { font-size: 12px; color: var(--sidebar-muted); padding: 6px 12px 0; }

.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px; min-height: var(--top-h); padding: 12px 28px; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid transparent; }
.topbar.scrolled { border-bottom-color: var(--line); }
.topbar .page-title { font-size: 18px; font-weight: 800; }
.top-actions { display: flex; align-items: center; gap: 8px; margin-inline-start: auto; }
.content { padding: 8px 28px 48px; display: flex; flex-direction: column; gap: 20px; max-width: 1400px; width: 100%; }
.page { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.btn.menu-btn { display: none; }
.bottom-nav { display: none; }
.scrim { display: none; }

/* ===== الأزرار ===== */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 16px; border-radius: var(--r-md); border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-size: 14px; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; transition: background .15s, border-color .15s, transform .05s; }
.btn:hover { background: var(--head); color: var(--ink); }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); font-weight: 700; }
.btn-primary:hover { background: color-mix(in srgb, var(--primary) 88%, #000); color: var(--on-primary); }
.btn-dark { background: var(--ink); border-color: var(--ink); color: #F2ECDC; }
.btn-dark:hover { background: #000; color: #fff; }
.btn-danger { background: var(--bad-soft); border-color: #F2C6C6; color: var(--bad-ink); }
.btn-danger:hover { background: #F7D5D5; color: var(--bad-ink); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--head); }
.btn-link { background: none; border: 0; padding: 0 4px; min-height: 36px; color: var(--primary-ink); font-weight: 600; }
.btn-link:hover { background: none; text-decoration: underline; }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: 13px; border-radius: 10px; }
.btn-lg { min-height: 52px; padding: 0 24px; font-size: 16px; border-radius: 14px; }
.btn-icon { width: 44px; padding: 0; }
.btn-icon.btn-sm { width: 36px; }
.btn-block { width: 100%; }
.badge-dot { position: absolute; top: 6px; inset-inline-start: 6px; min-width: 18px; height: 18px; border-radius: 9px; background: var(--bad); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; padding: 0 4px; }

/* زر الشرح «؟» */
.tip-btn { width: 26px; height: 26px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--ink-2); font-size: 13px; font-weight: 700; cursor: pointer; display: inline-grid; place-items: center; flex: none; padding: 0; line-height: 1; }
.tip-btn:hover { background: var(--primary-soft); color: var(--primary-ink); border-color: var(--primary-line); }
.tip-pop { position: fixed; z-index: 90; max-width: min(320px, calc(100vw - 32px)); background: var(--ink); color: #F2ECDC; font-size: 13px; line-height: 1.8; padding: 10px 14px; border-radius: 12px; box-shadow: var(--shadow-pop); }

/* ===== البطاقات ===== */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-1); min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 16px 20px; border-bottom: 1px solid var(--line-2); }
.card-head h2 { font-size: 17px; font-weight: 700; }
.card-head .sub { font-size: 13px; color: var(--ink-2); }
.card-body { padding: 18px 20px; }
.card-body.flush { padding: 0; }
.section-title { display: flex; align-items: center; gap: 8px; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 14px; }
.page-head h1 { font-size: 26px; font-weight: 800; }
.page-head p { color: var(--ink-2); font-size: 14px; max-width: 760px; }
.hero { display: flex; flex-wrap: wrap; gap: 16px; align-items: stretch; }
.hero-text { flex: 2 1 380px; display: flex; flex-direction: column; justify-content: center; gap: 4px; }
.hero-text h1 { font-size: 27px; font-weight: 800; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 18px; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.stat-label { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 14px; color: var(--ink-2); font-weight: 600; }
.stat-value { font-size: 28px; font-weight: 800; line-height: 1.2; }
.stat-note { font-size: 13px; font-weight: 600; color: var(--ink-2); }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.tile { display: flex; gap: 14px; align-items: flex-start; padding: 16px; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); text-decoration: none; color: var(--ink); transition: border-color .15s, box-shadow .15s; }
.tile:hover { border-color: var(--primary-line); box-shadow: 0 6px 20px -12px rgba(60, 45, 10, .35); color: var(--ink); }
.tile-ic { width: 44px; height: 44px; border-radius: 12px; background: var(--primary-soft); color: var(--primary-ink); display: grid; place-items: center; flex: none; }
.tile b { display: block; font-size: 15px; }
.tile span { display: block; font-size: 13px; color: var(--ink-2); }

/* ===== النماذج ===== */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .field-label { font-size: 14px; font-weight: 700; display: flex; align-items: center; gap: 6px; }
.field .req { color: var(--bad-ink); }
.hint { font-size: 13px; color: var(--ink-2); line-height: 1.7; }
.input, .select, .textarea { width: 100%; min-height: 46px; border: 1px solid var(--line); border-radius: var(--r-md); padding: 0 14px; font-size: 15px; background: var(--surface); color: var(--ink); }
.textarea { padding: 10px 14px; min-height: 96px; resize: vertical; }
.select { padding-inline-end: 34px; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236B665A' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: left 12px center; }
.input:focus, .select:focus, .textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: var(--primary); }
.input[readonly] { background: var(--bg); color: var(--ink-2); }
.field.error .input, .field.error .select { border-color: var(--bad); }
.field-error { font-size: 13px; color: var(--bad-ink); font-weight: 600; }
.check { display: flex; align-items: flex-start; gap: 10px; min-height: 44px; padding: 8px 0; cursor: pointer; font-size: 14px; }
.check input { width: 20px; height: 20px; margin: 2px 0 0; accent-color: #B98A0E; flex: none; }
.pw-wrap { position: relative; }
.pw-wrap .input { padding-inline-end: 48px; }
.pw-wrap .pw-eye { position: absolute; inset-inline-end: 4px; top: 50%; transform: translateY(-50%); }
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; }

[data-sw][aria-pressed="true"] { outline: 3px solid var(--ink); outline-offset: 2px; }

/* مفتاح تشغيل/إيقاف */
.switch { width: 48px; height: 28px; border-radius: 14px; border: 0; cursor: pointer; padding: 3px; display: flex; justify-content: flex-end; background: #D6D0C0; flex: none; transition: background .15s; }
.switch::after { content: ''; width: 22px; height: 22px; border-radius: 50%; background: #fff; display: block; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch[aria-checked="true"] { background: var(--ok); justify-content: flex-start; }
.switch[disabled] { opacity: .5; cursor: not-allowed; }

/* ===== الجداول والقوائم ===== */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { background: var(--head); color: var(--ink-2); font-weight: 600; text-align: start; padding: 10px 14px; white-space: nowrap; }
.table td { padding: 12px 14px; border-top: 1px solid var(--line-2); vertical-align: middle; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: var(--surface-2); }
.table th:first-child, .table td:first-child { padding-inline-start: 20px; }
.table th:last-child, .table td:last-child { padding-inline-end: 20px; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 12px 20px; border-top: 1px solid var(--line-2); }
.list-row:first-child { border-top: 0; }
.cell-title { font-weight: 700; overflow-wrap: anywhere; }
.cell-sub { font-size: 13px; color: var(--ink-2); overflow-wrap: anywhere; }
.user-cell { display: flex; align-items: center; gap: 12px; min-width: 0; }

.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--primary-soft); color: var(--primary-ink); display: grid; place-items: center; font-weight: 800; flex: none; font-size: 15px; overflow: hidden; }
.avatar.lg { width: 64px; height: 64px; font-size: 24px; }
.avatar.sm { width: 32px; height: 32px; font-size: 13px; }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 20px; font-size: 12px; font-weight: 700; white-space: nowrap; background: var(--idle-soft); color: var(--idle-ink); }
.badge.ok { background: var(--ok-soft); color: var(--ok-ink); }
.badge.bad { background: var(--bad-soft); color: var(--bad-ink); }
.badge.info { background: var(--info-soft); color: var(--info-ink); }
.badge.warn { background: var(--warn-soft); color: var(--warn-ink); }
.badge.gold { background: var(--primary-soft); color: #5E4505; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; display: inline-block; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.search { position: relative; flex: 1 1 260px; max-width: 420px; }
.search svg { position: absolute; inset-inline-start: 12px; top: 50%; transform: translateY(-50%); color: var(--ink-2); pointer-events: none; }
.search .input { padding-inline-start: 40px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab { min-height: 44px; padding: 0 16px; border: 0; background: none; cursor: pointer; font-weight: 600; color: var(--ink-2); border-bottom: 3px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--primary); }

.side-tabs { display: flex; flex-direction: column; gap: 2px; padding: 10px; }
.side-tab { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 44px; padding: 0 14px; border-radius: 10px; border: 0; background: none; cursor: pointer; text-align: start; font-size: 14px; color: var(--ink); }
.side-tab:hover { background: var(--bg); }
.side-tab[aria-selected="true"] { background: var(--primary-soft); color: #5E4505; font-weight: 700; }
.side-tab[disabled] { color: var(--ink-3); cursor: default; background: none; }
.split { display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start; }
.split > .split-nav { flex: 1 1 230px; max-width: 280px; }
.split > .split-main { flex: 999 1 520px; min-width: 0; display: flex; flex-direction: column; gap: 20px; }

.empty { text-align: center; padding: 36px 20px; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.empty-ic { width: 56px; height: 56px; border-radius: 16px; background: var(--primary-soft); color: var(--primary-ink); display: grid; place-items: center; }
.empty h3 { font-size: 17px; }
.empty p { color: var(--ink-2); font-size: 14px; max-width: 420px; }

.note { display: flex; gap: 10px; align-items: flex-start; padding: 12px 16px; border-radius: var(--r-md); background: var(--info-soft); color: #1F4C8A; font-size: 14px; line-height: 1.8; }
.note.warn { background: var(--warn-soft); color: #6E4207; }
.note.bad { background: var(--bad-soft); color: var(--bad-ink); }
.note.ok { background: var(--ok-soft); color: var(--ok-ink); }
.note svg { flex: none; margin-top: 3px; }

.kv { display: grid; grid-template-columns: minmax(120px, 180px) 1fr; gap: 10px 16px; font-size: 14px; }
.kv dt { color: var(--ink-2); }
.kv dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }

/* مصفوفة الصلاحيات */
.perm-sec { border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; }
.perm-sec + .perm-sec { margin-top: 12px; }
.perm-sec-head { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--head); }
.perm-sec-head b { font-size: 15px; }
.perm-row { display: flex; align-items: flex-start; gap: 12px; padding: 10px 16px; border-top: 1px solid var(--line-2); }
.perm-row .grow b { display: block; font-size: 14px; }
.perm-row .grow span { display: block; font-size: 13px; color: var(--ink-2); line-height: 1.7; }
.tri { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; flex: none; }
.tri button { min-height: 36px; padding: 0 10px; border: 0; background: var(--surface); cursor: pointer; font-size: 12px; font-weight: 700; color: var(--ink-2); }
.tri button + button { border-inline-start: 1px solid var(--line); }
.tri button[aria-pressed="true"].t-role { background: var(--idle-soft); color: var(--idle-ink); }
.tri button[aria-pressed="true"].t-grant { background: var(--ok-soft); color: var(--ok-ink); }
.tri button[aria-pressed="true"].t-deny { background: var(--bad-soft); color: var(--bad-ink); }
.tri button[disabled] { cursor: not-allowed; opacity: .6; }

/* ===== النوافذ والتنبيهات ===== */
.modal-back { position: fixed; inset: 0; background: rgba(20, 16, 8, .45); z-index: 80; display: flex; align-items: center; justify-content: center; padding: 16px; animation: fade .15s ease-out; }
.modal { background: var(--surface); border-radius: 18px; box-shadow: var(--shadow-pop); width: min(560px, 100%); max-height: calc(100dvh - 32px); display: flex; flex-direction: column; animation: pop .18s ease-out; }
.modal.wide { width: min(760px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 18px 22px 10px; }
.modal-head h2 { font-size: 19px; font-weight: 800; }
.modal-body { padding: 8px 22px 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; padding: 14px 22px 18px; border-top: 1px solid var(--line-2); }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }

.toasts { position: fixed; bottom: 20px; inset-inline-start: 50%; transform: translateX(50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: min(460px, calc(100vw - 32px)); }
[dir="rtl"] .toasts { transform: translateX(50%); }
.toast { pointer-events: auto; background: var(--ink); color: #F2ECDC; padding: 12px 18px; border-radius: 12px; box-shadow: var(--shadow-pop); font-size: 14px; font-weight: 600; display: flex; gap: 10px; align-items: center; animation: pop .18s ease-out; width: 100%; }
.toast.bad { background: #8E2A2A; color: #fff; }
.toast.ok { background: #1E6B48; color: #fff; }

.secret-box { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border: 2px dashed var(--primary-line); border-radius: 12px; background: var(--primary-soft); }
.secret-box code { font-size: 22px; font-weight: 800; letter-spacing: 2px; direction: ltr; flex: 1; text-align: center; font-family: ui-monospace, Menlo, Consolas, monospace; }

.help-panel { position: fixed; top: 0; bottom: 0; inset-inline-end: 0; width: min(420px, 100vw); background: var(--surface); z-index: 85; box-shadow: var(--shadow-pop); display: flex; flex-direction: column; animation: slide .2s ease-out; }
@keyframes slide { from { transform: translateX(-30px); opacity: 0; } }
.help-panel .help-body { padding: 4px 22px 24px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; font-size: 14px; line-height: 1.9; }
.help-panel h3 { font-size: 15px; margin-top: 6px; }
.help-panel ul { margin: 0; padding-inline-start: 20px; }

.user-menu { position: relative; }
.user-btn { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 2px 6px 2px 10px; border-radius: 12px; border: 1px solid transparent; background: none; cursor: pointer; text-align: start; }
.user-btn:hover { background: var(--surface); border-color: var(--line); }
.user-btn .who { display: flex; flex-direction: column; line-height: 1.3; }
.user-btn .who b { font-size: 14px; }
.user-btn .who span { font-size: 12px; color: var(--ink-2); }
.dropdown { position: absolute; top: calc(100% + 6px); inset-inline-end: 0; min-width: 220px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow-pop); padding: 6px; z-index: 50; }
.dropdown a, .dropdown button { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 42px; padding: 0 12px; border-radius: 10px; border: 0; background: none; cursor: pointer; text-decoration: none; color: var(--ink); font-size: 14px; text-align: start; }
.dropdown a:hover, .dropdown button:hover { background: var(--bg); color: var(--ink); }
.dropdown hr { border: 0; border-top: 1px solid var(--line-2); margin: 4px 0; }

/* ===== شاشة الدخول ===== */
.auth { min-height: 100vh; min-height: 100dvh; display: flex; }
.auth-brand { flex: 1 1 50%; background: var(--sidebar); color: var(--sidebar-ink); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: 40px; text-align: center; }
.auth-brand img { width: 120px; height: 120px; border-radius: 50%; background: #fff; object-fit: contain; }
.auth-brand img.logo-custom { width: auto; max-width: min(280px, 80%); border-radius: 0; background: none; }
.about-logo { width: 64px; height: 64px; border-radius: 50%; background: #fff; border: 1px solid var(--line); object-fit: contain; }
.about-logo.logo-custom { width: auto; max-width: 180px; border-radius: 0; background: none; border: 0; }
/* معاينة الشعار في الإعدادات: على لون القائمة (حيث يظهر فعلًا) وعلى خلفية فاتحة */
.logo-previews { display: flex; gap: 10px; flex-wrap: wrap; }
.logo-prev { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.logo-prev .tile { width: 170px; height: 96px; border-radius: 14px; border: 1px solid var(--line); display: flex; align-items: center; justify-content: center; padding: 10px; }
.logo-prev .tile.dark { background: var(--sidebar); }
.logo-prev .tile.light { background: var(--bg); }
.logo-prev img { max-width: 100%; max-height: 100%; object-fit: contain; }
.logo-prev img.on-circle { width: 70px; height: 70px; border-radius: 50%; background: #fff; }
.logo-prev .cap { font-size: 12px; color: var(--ink-2); }
.auth-brand .name { font-size: 34px; font-weight: 800; letter-spacing: 1px; }
.auth-brand .sub { color: var(--sidebar-muted); font-size: 16px; }
.auth-form { flex: 1 1 50%; display: flex; align-items: center; justify-content: center; padding: 32px 20px; }
.auth-card { width: min(420px, 100%); display: flex; flex-direction: column; gap: 16px; }
.auth-card h1 { font-size: 24px; font-weight: 800; }
.auth-foot { font-size: 13px; color: var(--ink-2); text-align: center; line-height: 1.8; }
.boot { min-height: 100vh; display: grid; place-items: center; color: var(--ink-2); }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--primary); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { background: linear-gradient(90deg, var(--line-2), #F8F4EA, var(--line-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 10px; min-height: 18px; }
@keyframes shimmer { to { background-position: -200% 0; } }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 20px; border-top: 1px solid var(--line-2); flex-wrap: wrap; }

/* ===== الشاشات المتوسطة: القائمة تصبح درجًا ===== */
@media (max-width: 1024px) {
  /* الدرج فوق شريط الهاتف السفلي، ومسافة لشريط الإيماءات والنتوء في الهواتف (خاصة عند تثبيت التطبيق) */
  .sidebar { position: fixed; inset-block: 0; inset-inline-start: 0; transform: translateX(110%); transition: transform .22s ease-out; box-shadow: var(--shadow-pop); z-index: 60;
    padding-top: calc(20px + env(safe-area-inset-top)); padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
  .app.nav-open .sidebar { transform: none; }
  .app.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(20, 16, 8, .45); z-index: 55; }
  .btn.menu-btn { display: inline-flex; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar, .content { padding-inline: 20px; }
}

/* ===== الهاتف ===== */
@media (max-width: 720px) {
  body { font-size: 15px; }
  .topbar { padding: calc(10px + env(safe-area-inset-top)) 16px 10px; min-height: 60px; }
  .content { padding: 4px 16px 96px; gap: 16px; }
  .page-head h1 { font-size: 22px; }
  .hero-text h1 { font-size: 22px; }
  .form-grid { grid-template-columns: 1fr; }
  .stats { gap: 12px; }
  .stat { padding: 14px; }
  .stat-value { font-size: 22px; }
  .user-btn .who { display: none; }
  .hide-sm { display: none !important; }
  .bottom-nav { display: grid; grid-template-columns: repeat(var(--cols, 4), minmax(0, 1fr)); position: fixed; inset-inline: 0; bottom: 0; z-index: 40; background: var(--surface); border-top: 1px solid var(--line); padding: 6px 6px calc(8px + env(safe-area-inset-bottom)); }
  .bottom-nav a, .bottom-nav button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 52px; text-decoration: none; color: var(--ink-2); font-size: 12px; background: none; border: 0; cursor: pointer; }
  .bottom-nav [aria-current="page"] { color: #5E4505; font-weight: 700; }
  .auth { flex-direction: column; }
  .auth-brand { flex: none; padding: 48px 24px 32px; border-radius: 0 0 28px 28px; gap: 10px; }
  .auth-brand img { width: 88px; height: 88px; }
  .auth-brand .name { font-size: 26px; }
  .auth-form { align-items: flex-start; padding-top: 24px; }
  .kv { grid-template-columns: 1fr; gap: 2px 0; }
  .kv dd { margin-bottom: 8px; }
  .modal-back { align-items: flex-end; padding: 0; }
  .modal { width: 100%; border-radius: 20px 20px 0 0; max-height: 92dvh; }
  .table.cards thead { display: none; }
  .table.cards, .table.cards tbody, .table.cards tr, .table.cards td { display: block; width: 100%; }
  .table.cards tr { border-top: 1px solid var(--line-2); padding: 10px 16px; }
  .table.cards td { border: 0; padding: 3px 0 !important; }
  .table.cards td[data-label]::before { content: attr(data-label) ': '; color: var(--ink-2); font-size: 13px; }
  .split > .split-nav { max-width: none; flex-basis: 100%; }
  .split-nav .side-tabs { flex-direction: row; overflow-x: auto; gap: 6px; padding: 8px; scrollbar-width: thin; }
  .split-nav .side-tab { flex: none; white-space: nowrap; }
  .split-nav .side-tab[disabled] { display: none; }
  .toolbar > * { flex: 1 1 100%; max-width: none; }
  .toolbar .select { width: 100%; }
  .page { gap: 16px; }
  .toasts { bottom: 84px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

@media print {
  .sidebar, .topbar, .bottom-nav, .toasts { display: none !important; }
  .content { padding: 0; }
}

/* آخر الأخطاء في معلومات النظام */
.err-item { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; gap: 4px; }
.err-msg { font-family: ui-monospace, Consolas, monospace; font-size: 13px; text-align: left; word-break: break-word; }
.err-where { font-family: ui-monospace, Consolas, monospace; font-size: 12px; color: var(--ink-2); text-align: left; word-break: break-all; }
