/* ==========================================================================
   اينار — نظام التصميم
   كل الألوان تأتي من متغيرات CSS تُولَّد من لون الهوية المحفوظ في الإعدادات
   ========================================================================== */
:root {
  /* الهوية (تُستبدل من الإعدادات عبر brand.js) */
  --primary: #E6AE1C;
  --primary-deep: #B98A0E;
  --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-accent: #E6AE1C;

  /* ثوابت */
  --bg: #FAF7F0;
  --surface: #FFFFFF;
  --ink: #1F1D18;
  --ink-2: #6B665A;
  --ink-3: #9A9484;
  --line: #E9E2D0;
  --line-2: #F2EDDF;
  --head: #F6F1E4;

  --ok: #2E9E6B;       --ok-soft: #E3F4EB;
  --bad: #D64545;      --bad-soft: #FBE7E7;
  --info: #3B7DD8;     --info-soft: #E5EFFB;
  --warn: #C9780B;     --warn-soft: #FCEEDA;
  --idle: #7D786A;     --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;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.65;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}
h1, h2, h3, h4, p { margin: 0; }
a { color: var(--primary-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; color: inherit; cursor: pointer; }
img { max-width: 100%; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--primary-deep); outline-offset: 2px; border-radius: 6px; }
.ltr { direction: ltr; text-align: right; unicode-bidi: plaintext; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--ink-2); }
.faint { color: var(--ink-3); }
.small { font-size: 13px; }
.xs { font-size: 12px; }
.strong { font-weight: 700; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.stack-sm { display: flex; flex-direction: column; gap: 6px; }
.sp { height: 18px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.txt-ok { color: var(--ok); } .txt-bad { color: var(--bad); } .txt-warn { color: var(--warn); }

/* ===== الهيكل ===== */
.app { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-ink);
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column;
  padding: 22px 14px 14px;
  z-index: 40;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 20px; border-bottom: 1px solid var(--sidebar-line); margin-bottom: 14px; }
.brand img { width: 52px; height: 52px; object-fit: contain; flex: none; }
.brand b { font-size: 20px; font-weight: 800; line-height: 1.2; display: block; }
.brand span { font-size: 12.5px; color: var(--sidebar-muted); }
.nav { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; flex: 1; padding-block: 4px; }
.nav-sep { height: 1px; background: var(--sidebar-line); margin: 10px 8px; }
.nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 10px;
  color: var(--sidebar-ink); text-decoration: none; font-weight: 600; font-size: 14.5px;
  position: relative; transition: background .15s;
}
.nav a svg { flex: none; opacity: .8; }
.nav a:hover { background: var(--sidebar-hover); text-decoration: none; }
.nav a.active { background: var(--sidebar-active); color: var(--sidebar-accent); }
.nav a.active svg { opacity: 1; }
.nav a.active::before {
  content: ''; position: absolute; inset-inline-start: -14px; top: 9px; bottom: 9px;
  width: 4px; border-radius: 0 4px 4px 0; background: var(--primary);
}
[dir="rtl"] .nav a.active::before { border-radius: 4px 0 0 4px; }
.nav .pill { margin-inline-start: auto; background: var(--primary); color: var(--on-primary); font-size: 12px; font-weight: 800; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px; display: grid; place-items: center; }
.me { display: flex; align-items: center; gap: 10px; padding: 12px 8px 4px; border-top: 1px solid var(--sidebar-line); margin-top: 8px; }
.me .av { background: var(--primary); color: var(--on-primary); }
.me b { font-size: 14px; display: block; line-height: 1.3; }
.me small { color: var(--sidebar-muted); font-size: 12px; }
.me button { margin-inline-start: auto; background: none; border: 0; color: var(--sidebar-muted); padding: 8px; border-radius: 8px; display: grid; }
.me button:hover { background: var(--sidebar-hover); color: var(--sidebar-ink); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: none; }
.content { padding: 30px 36px 60px; max-width: 1400px; width: 100%; margin-inline: auto; }
.scrim { display: none; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { font-size: 28px; font-weight: 800; line-height: 1.25; letter-spacing: -.2px; }
.page-head p { color: var(--ink-2); margin-top: 2px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.crumb { font-size: 13px; color: var(--ink-2); margin-bottom: 6px; display: flex; gap: 6px; align-items: center; }
.crumb a { color: var(--ink-2); }

/* ===== البطاقات ===== */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-1); }
.card-pad { padding: 20px 22px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 22px; border-bottom: 1px solid var(--line-2); }
.card-head h2, .card-head h3 { font-size: 16.5px; font-weight: 800; }
.card-body { padding: 18px 22px; }
.grid { display: grid; gap: 18px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-main { grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr); align-items: start; }
.g-side { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }

/* ===== الأزرار ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font-weight: 700; font-size: 14.5px; white-space: nowrap; text-decoration: none;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--head); text-decoration: none; }
.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); }
.btn-primary:hover { background: var(--primary-deep); border-color: var(--primary-deep); color: var(--on-primary); }
.btn-dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn-dark:hover { background: #3a362b; }
.btn-danger { color: var(--bad); border-color: #F0C8C8; background: #fff; }
.btn-danger:hover { background: var(--bad-soft); }
.btn-danger.solid { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn-danger.solid:hover { background: #b93636; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--head); }
.btn-sm { height: 32px; padding: 0 11px; font-size: 13px; border-radius: 8px; gap: 6px; }
.btn-icon { width: 36px; padding: 0; }
.btn-icon.btn-sm { width: 32px; }
.btn-wa { color: #1b8a4b; border-color: #BFE3CE; background: #F2FBF6; }
.btn-wa:hover { background: #E3F6EB; }
.btn .spin { width: 16px; height: 16px; border-radius: 50%; border: 2px solid currentColor; border-top-color: transparent; animation: rot .7s linear infinite; }
@keyframes rot { to { transform: rotate(360deg); } }

/* ===== الحقول ===== */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .lbl { font-size: 13.5px; font-weight: 700; color: var(--ink); }
.field .req { color: var(--bad); margin-inline-start: 3px; }
.field .hint { font-size: 12.5px; color: var(--ink-2); line-height: 1.5; }
.input, .select, .textarea {
  width: 100%; height: 42px; padding: 0 12px;
  border: 1px solid #DAD2BC; border-radius: 10px; background: #fff; color: var(--ink);
  font: inherit; font-size: 15px; transition: border-color .15s, box-shadow .15s;
}
.textarea { height: auto; min-height: 90px; padding: 10px 12px; resize: vertical; line-height: 1.6; }
.select { appearance: none; padding-inline-end: 34px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%236B665A' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: left 12px center; }
.input:hover, .select:hover, .textarea:hover { border-color: #C9BF9F; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--primary-deep); box-shadow: 0 0 0 3px var(--primary-soft); }
.input:disabled, .select:disabled, .textarea:disabled { background: var(--head); color: var(--ink-2); }
.input.sm, .select.sm { height: 36px; font-size: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid .full { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: 9px; font-weight: 600; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--primary-deep); }
.color-row { display: flex; gap: 10px; align-items: center; }
.color-row input[type="color"] { width: 46px; height: 42px; padding: 3px; border: 1px solid #DAD2BC; border-radius: 10px; background: #fff; cursor: pointer; }
.switch { position: relative; width: 42px; height: 24px; flex: none; }
.switch input { position: absolute; opacity: 0; inset: 0; cursor: pointer; z-index: 2; margin: 0; }
.switch i { position: absolute; inset: 0; background: #CFC7B0; border-radius: 12px; transition: background .15s; }
.switch i::after { content: ''; position: absolute; top: 3px; inset-inline-start: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.switch input:checked + i { background: var(--ok); }
.switch input:checked + i::after { transform: translateX(-18px); }
[dir="ltr"] .switch input:checked + i::after { transform: translateX(18px); }
.switch input:focus-visible + i { outline: 2px solid var(--primary-deep); outline-offset: 2px; }

/* القائمة المنسدلة القابلة للبحث */
.combo { position: relative; }
.combo-list { position: absolute; z-index: 60; inset-inline: 0; top: calc(100% + 4px); background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-pop); max-height: 280px; overflow: auto; padding: 5px; }
.combo-item { display: flex; flex-direction: column; padding: 8px 10px; border-radius: 8px; cursor: pointer; line-height: 1.4; }
.combo-item small { color: var(--ink-2); font-size: 12.5px; }
.combo-item:hover, .combo-item.on { background: var(--primary-soft); }
.combo-empty { padding: 12px; color: var(--ink-2); font-size: 14px; }

/* ===== الجداول ===== */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14.5px; }
table.data th { text-align: start; font-size: 13px; font-weight: 700; color: var(--ink-2); background: var(--head); padding: 11px 16px; white-space: nowrap; border-bottom: 1px solid var(--line); }
table.data td { padding: 13px 16px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr.click { cursor: pointer; }
table.data tbody tr.click:hover td { background: #FCFAF4; }
table.data .end { text-align: end; }
table.data tfoot td { background: var(--head); font-weight: 800; border-top: 1px solid var(--line); border-bottom: 0; }
.cell-title { font-weight: 700; line-height: 1.35; }
.cell-sub { font-size: 12.5px; color: var(--ink-2); line-height: 1.4; }
.avatar, .av {
  width: 38px; height: 38px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-weight: 800; font-size: 14px;
  background: var(--primary-soft); color: var(--primary-ink);
}
.av { width: 34px; height: 34px; font-size: 13px; }
.avatar.lg { width: 64px; height: 64px; font-size: 24px; }

/* ===== الشارات ===== */
.badge { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 12px; font-size: 12.5px; font-weight: 700; white-space: nowrap; }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.plain::before { display: none; }
.b-ok { background: var(--ok-soft); color: #1E7A4F; }
.b-bad { background: var(--bad-soft); color: #B03232; }
.b-info { background: var(--info-soft); color: #2A62AD; }
.b-warn { background: var(--warn-soft); color: #9A5C06; }
.b-idle { background: var(--idle-soft); color: #5F5B4E; }
.b-gold { background: var(--primary-soft); color: var(--primary-ink); }

/* ===== مؤشرات وإحصاءات ===== */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.kpi { padding: 18px 20px; }
.kpi .k-label { font-size: 13.5px; color: var(--ink-2); font-weight: 600; }
.kpi .k-val { font-size: 29px; font-weight: 800; line-height: 1.25; margin-top: 4px; letter-spacing: -.3px; }
.kpi .k-val small { font-size: 14px; font-weight: 700; color: var(--ink-2); margin-inline-start: 4px; }
.kpi .k-sub { font-size: 13px; color: var(--ink-2); margin-top: 2px; }
.kpi.hero { background: var(--sidebar); color: var(--sidebar-ink); border-color: var(--sidebar); }
.kpi.hero .k-label, .kpi.hero .k-sub, .kpi.hero .k-val small { color: var(--sidebar-muted); }
.kpi.hero .k-val { color: var(--sidebar-accent); }
.attn { display: grid; gap: 10px; }
.attn-item { display: flex; align-items: center; gap: 14px; padding: 13px 16px; border-radius: 14px; border: 1px solid var(--primary-line); background: var(--primary-soft); }
.attn-item.bad { border-color: #F0C8C8; background: var(--bad-soft); }
.attn-item .ic { width: 38px; height: 38px; border-radius: 10px; background: rgba(255,255,255,.7); display: grid; place-items: center; color: var(--primary-ink); flex: none; }
.attn-item.bad .ic { color: var(--bad); }
.attn-item b { display: block; line-height: 1.35; }
.attn-item span { font-size: 13.5px; color: var(--ink-2); }
.stat-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); overflow: hidden; }
.stat-row > div { padding: 14px 18px; border-inline-start: 1px solid var(--line-2); }
.stat-row > div:first-child { border-inline-start: 0; }
.stat-row small { display: block; color: var(--ink-2); font-size: 13px; font-weight: 600; }
.stat-row b { font-size: 21px; font-weight: 800; }

/* مخطط الأعمدة */
.chart { width: 100%; height: 240px; display: block; }
.chart text { font-family: var(--font); fill: var(--ink-2); font-size: 12px; }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--ink-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-inline-end: 6px; vertical-align: -1px; }

/* ===== أدوات التصفية والتبويب ===== */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.search { position: relative; flex: 1 1 240px; max-width: 380px; }
.search svg { position: absolute; inset-inline-start: 12px; top: 50%; transform: translateY(-50%); color: var(--ink-3); pointer-events: none; }
.search .input { padding-inline-start: 38px; }
.chips { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.chip { height: 36px; padding: 0 14px; border-radius: 18px; border: 1px solid var(--line); background: var(--surface); font-weight: 700; font-size: 13.5px; color: var(--ink-2); }
.chip:hover { background: var(--head); }
.chip.on { background: var(--ink); border-color: var(--ink); color: #fff; }
.chip .n { opacity: .7; margin-inline-start: 6px; font-weight: 600; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tab { padding: 11px 16px; font-weight: 700; color: var(--ink-2); background: none; border: 0; border-bottom: 3px solid transparent; white-space: nowrap; margin-bottom: -1px; }
.tab:hover { color: var(--ink); }
.tab.on { color: var(--ink); border-bottom-color: var(--primary); }
.subtabs { display: flex; flex-direction: column; gap: 2px; position: sticky; top: 20px; }
.subtabs a { padding: 10px 14px; border-radius: 10px; color: var(--ink-2); font-weight: 700; display: flex; gap: 10px; align-items: center; text-decoration: none; }
.subtabs a:hover { background: var(--head); }
.subtabs a.on { background: var(--surface); color: var(--ink); border: 1px solid var(--line); box-shadow: var(--shadow-1); }
.set-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 26px; align-items: start; }

/* ===== مراحل المشروع ===== */
.steps { display: flex; align-items: flex-start; gap: 0; overflow-x: auto; padding: 4px 0 2px; }
.step { flex: 1 1 0; min-width: 92px; text-align: center; position: relative; padding: 0 4px; background: none; border: 0; }
.step .dot { width: 30px; height: 30px; border-radius: 50%; margin: 0 auto 8px; display: grid; place-items: center; background: var(--surface); border: 2px solid #D5CCB2; color: var(--ink-3); font-weight: 800; font-size: 13px; position: relative; z-index: 1; transition: all .15s; }
.step::before { content: ''; position: absolute; top: 15px; inset-inline: -50% 50%; height: 2px; background: #D5CCB2; }
.step:first-child::before { display: none; }
.step.done .dot { background: var(--ok); border-color: var(--ok); color: #fff; }
.step.done::before { background: var(--ok); }
.step.cur .dot { background: var(--primary); border-color: var(--primary); color: var(--on-primary); box-shadow: 0 0 0 5px var(--primary-soft); }
.step.cur::before { background: var(--primary); }
.step span { font-size: 13px; font-weight: 700; color: var(--ink-2); display: block; line-height: 1.3; }
.step.cur span { color: var(--ink); }
button.step:hover .dot { border-color: var(--primary-deep); }
.mini-steps { display: flex; gap: 3px; }
.mini-steps i { width: 18px; height: 6px; border-radius: 3px; background: #DDD5BE; }
.mini-steps i.on { background: var(--primary); }
.mini-steps i.done { background: var(--ok); }
.progress { height: 8px; background: var(--idle-soft); border-radius: 4px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--primary); border-radius: 4px; }

/* ===== معلومات وقوائم ===== */
.kv { display: grid; grid-template-columns: 130px minmax(0, 1fr); gap: 10px 14px; font-size: 14.5px; }
.kv dt { color: var(--ink-2); font-weight: 600; }
.kv dd { margin: 0; font-weight: 600; word-break: break-word; }
.list { display: flex; flex-direction: column; }
.list-item { display: flex; align-items: center; gap: 14px; padding: 13px 22px; border-bottom: 1px solid var(--line-2); }
.list-item:last-child { border-bottom: 0; }
a.list-item { color: inherit; text-decoration: none; }
a.list-item:hover { background: #FCFAF4; }
.empty { text-align: center; padding: 46px 24px; color: var(--ink-2); }
.empty .ic { width: 58px; height: 58px; border-radius: 50%; background: var(--primary-soft); color: var(--primary-ink); display: grid; place-items: center; margin: 0 auto 14px; }
.empty h3 { color: var(--ink); font-size: 17px; margin-bottom: 4px; }
.empty .btn { margin-top: 16px; }
.notice { padding: 12px 16px; border-radius: 12px; font-size: 14px; display: flex; gap: 10px; align-items: flex-start; background: var(--info-soft); color: #234F8C; line-height: 1.6; }
.notice.warn { background: var(--warn-soft); color: #7A4905; }
.notice.bad { background: var(--bad-soft); color: #8E2A2A; }
.notice.ok { background: var(--ok-soft); color: #176843; }
.notice svg { flex: none; margin-top: 3px; }
.skeleton { display: grid; gap: 14px; }
.sk { height: 18px; border-radius: 8px; background: linear-gradient(90deg, #EFE9D8 25%, #F8F4E8 50%, #EFE9D8 75%); background-size: 200% 100%; animation: sk 1.3s infinite linear; }
.sk.big { height: 110px; border-radius: 16px; }
@keyframes sk { to { background-position: -200% 0; } }

/* ===== النوافذ والإشعارات ===== */
.backdrop { position: fixed; inset: 0; background: rgba(31, 29, 24, .55); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 5vh 16px; overflow-y: auto; animation: fade .15s ease-out; }
.modal { background: var(--surface); border-radius: 18px; box-shadow: var(--shadow-pop); width: 100%; max-width: 560px; animation: pop .18s ease-out; margin-block: auto; }
.modal.wide { max-width: 760px; }
.modal.xwide { max-width: 980px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 18px 24px; border-bottom: 1px solid var(--line-2); }
.modal-head h2 { font-size: 18px; font-weight: 800; }
.modal-body { padding: 22px 24px; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-start; padding: 16px 24px; border-top: 1px solid var(--line-2); background: #FDFBF6; border-radius: 0 0 18px 18px; }
.form-error { background: var(--bad-soft); color: #8E2A2A; padding: 10px 14px; border-radius: 10px; font-size: 14px; margin-bottom: 14px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.98); } }
.toasts { position: fixed; inset-inline-end: 22px; bottom: 22px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast { min-width: 260px; max-width: 420px; background: var(--ink); color: #fff; padding: 13px 16px; border-radius: 12px; display: flex; gap: 10px; align-items: flex-start; box-shadow: var(--shadow-pop); animation: pop .2s ease-out; font-weight: 600; line-height: 1.5; }
.toast.bad { background: #8E2A2A; }
.toast svg { flex: none; margin-top: 3px; color: var(--primary); }
.toast.bad svg { color: #fff; }

/* ===== الدخول ===== */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; background:
  radial-gradient(900px 500px at 85% -10%, var(--primary-soft), transparent 60%),
  radial-gradient(700px 400px at -10% 110%, var(--primary-soft), transparent 55%), var(--bg); }
.auth-card { width: 100%; max-width: 410px; background: var(--surface); border: 1px solid var(--line); border-radius: 22px; padding: 34px 32px 28px; box-shadow: 0 30px 70px -30px rgba(60, 45, 10, .35); }
.auth-card .logo { width: 96px; height: 96px; display: block; margin: 0 auto 14px; object-fit: contain; }
.auth-card h1 { text-align: center; font-size: 23px; font-weight: 800; }
.auth-card .sub { text-align: center; color: var(--ink-2); margin: 4px 0 24px; }
.auth-card .btn-primary { width: 100%; height: 46px; font-size: 16px; }
.auth-foot { text-align: center; margin-top: 16px; font-size: 14px; }
.auth-foot button { background: none; border: 0; color: var(--primary-ink); font-weight: 700; padding: 4px; }

/* ===== الفاتورة (ورقة A4) ===== */
.paper-wrap { background: #EDE7D6; border-radius: var(--r-lg); padding: 26px; overflow-x: auto; }
.paper {
  --accent: var(--primary);
  width: 794px; max-width: 100%; min-height: 1000px; margin: 0 auto; background: #fff; color: #1F1D18;
  padding: 0 46px 40px; position: relative; box-shadow: 0 10px 40px -18px rgba(60, 45, 10, .5);
  font-size: 14px; line-height: 1.6; display: flex; flex-direction: column;
}
.paper::before { content: ''; display: block; height: 10px; background: var(--accent); margin: 0 -46px 34px; }
.paper .p-head { display: flex; justify-content: space-between; gap: 24px; align-items: flex-start; }
.paper .p-co { display: flex; gap: 16px; align-items: center; }
.paper .p-co img { width: 84px; height: 84px; object-fit: contain; }
.paper .p-co h2 { font-size: 22px; font-weight: 800; line-height: 1.25; }
.paper .p-co p { font-size: 12.5px; color: #6B665A; line-height: 1.6; }
.paper .p-title { text-align: end; }
.paper .p-title h1 { font-size: 40px; font-weight: 800; line-height: 1; color: #1F1D18; }
.paper .p-title .no { font-size: 17px; font-weight: 800; margin-top: 8px; display: block; direction: ltr; }
.paper .p-meta { display: grid; grid-template-columns: 1.3fr 1fr; gap: 20px; margin: 30px 0 22px; }
.paper .box { border: 1px solid #E9E2D0; border-radius: 12px; padding: 14px 16px; }
.paper .box small { color: #8A8473; font-weight: 700; display: block; margin-bottom: 4px; font-size: 12.5px; }
.paper .box b { font-size: 16.5px; font-weight: 800; display: block; line-height: 1.4; }
.paper .box p { font-size: 13px; color: #55503F; }
.paper .dates { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.paper .dates div small { margin: 0; }
.paper .dates div b { font-size: 14.5px; direction: ltr; text-align: end; }
.paper table { width: 100%; border-collapse: collapse; margin-top: 4px; }
.paper th { background: #1F1D18; color: #fff; font-size: 12.5px; font-weight: 700; padding: 9px 12px; text-align: start; }
.paper th:first-child { border-radius: 0 10px 10px 0; } .paper th:last-child { border-radius: 10px 0 0 10px; }
.paper td { padding: 11px 12px; border-bottom: 1px solid #EFE9D8; vertical-align: top; }
.paper td.n, .paper th.n { text-align: end; white-space: nowrap; }
.paper .p-sum { display: flex; justify-content: space-between; gap: 30px; margin-top: 20px; align-items: flex-start; }
.paper .p-pay { flex: 1; font-size: 13px; color: #55503F; white-space: pre-line; }
.paper .p-pay b { color: #1F1D18; display: block; margin-bottom: 4px; font-size: 13.5px; }
.paper .totals { width: 300px; flex: none; }
.paper .totals div { display: flex; justify-content: space-between; padding: 6px 0; font-size: 14px; }
.paper .totals div.grand { background: var(--accent); color: var(--paper-on, #1F1D18); border-radius: 12px; padding: 12px 16px; margin-top: 8px; font-size: 18px; font-weight: 800; }
.paper .totals div.due { font-weight: 800; color: #B03232; }
.paper .p-notes { margin-top: 24px; font-size: 13px; color: #55503F; white-space: pre-line; }
.paper .p-notes b { color: #1F1D18; display: block; margin-bottom: 2px; }
.paper .p-foot { margin-top: auto; padding-top: 26px; text-align: center; font-size: 12.5px; color: #8A8473; border-top: 1px dashed #E0D8C0; }
.paper .stamp { position: absolute; top: 120px; inset-inline-start: 48px; transform: rotate(-12deg); border: 4px solid; border-radius: 12px; padding: 4px 20px; font-size: 32px; font-weight: 800; opacity: .8; letter-spacing: 1px; pointer-events: none; }
.paper .stamp.paid { color: #2E9E6B; } .paper .stamp.draft { color: #9A9484; } .paper .stamp.cancelled { color: #D64545; }
.paper .pay-list { margin-top: 18px; font-size: 13px; }
.paper .pay-list h4 { font-size: 13.5px; margin-bottom: 4px; }
.paper .pay-list div { display: flex; justify-content: space-between; padding: 3px 0; border-bottom: 1px dotted #E0D8C0; }
.invoice-page { background: var(--bg); min-height: 100vh; padding: 24px 12px 60px; }
.invoice-bar { max-width: 794px; margin: 0 auto 16px; display: flex; gap: 10px; justify-content: space-between; align-items: center; flex-wrap: wrap; }

/* ===== الاستجابة ===== */
@media (max-width: 1180px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g-main, .g-side { grid-template-columns: minmax(0, 1fr); }
  .content { padding: 26px 24px 60px; }
}
@media (max-width: 920px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; inset-block: 0; inset-inline-start: 0; width: min(300px, 86vw); transform: translateX(100%); transition: transform .22s ease; box-shadow: var(--shadow-pop); }
  [dir="ltr"] .sidebar { transform: translateX(-100%); }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(31, 29, 24, .5); z-index: 30; }
  .topbar { display: flex; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 20; background: var(--sidebar); color: var(--sidebar-ink); padding: 9px 14px; }
  .topbar img { width: 34px; height: 34px; object-fit: contain; }
  .topbar b { font-size: 18px; font-weight: 800; }
  .topbar button { margin-inline-start: auto; background: none; border: 0; color: inherit; padding: 6px; border-radius: 8px; display: grid; }
  .content { padding: 20px 16px 60px; }
  .page-head h1 { font-size: 23px; }
  .set-layout { grid-template-columns: minmax(0, 1fr); }
  .subtabs { position: static; flex-direction: row; overflow-x: auto; gap: 6px; padding-bottom: 6px; }
  .subtabs a { white-space: nowrap; }
}
@media (max-width: 680px) {
  .g2, .g3, .form-grid { grid-template-columns: minmax(0, 1fr); }
  .kpis { gap: 10px; }
  .kpi { padding: 14px; } .kpi .k-val { font-size: 23px; }
  .stat-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-row > div:nth-child(3) { border-inline-start: 0; }
  .stat-row > div:nth-child(n+3) { border-top: 1px solid var(--line-2); }
  .kv { grid-template-columns: 100px minmax(0, 1fr); }
  .card-head, .list-item { padding-inline: 16px; } .card-body, .card-pad { padding-inline: 16px; }
  .modal-body { padding: 18px 16px; } .modal-head, .modal-foot { padding-inline: 16px; }
  .backdrop { padding: 0; align-items: flex-end; }
  .modal { border-radius: 20px 20px 0 0; max-width: none; margin: 0; }
  .toasts { inset-inline: 12px; bottom: 12px; } .toast { max-width: none; }
  /* جداول القوائم تتحول إلى بطاقات على الجوال */
  table.stack-m, table.stack-m tbody, table.stack-m tr, table.stack-m td { display: block; width: 100%; }
  table.stack-m thead { display: none; }
  table.stack-m tr { padding: 12px 16px; border-bottom: 1px solid var(--line-2); }
  table.stack-m td { border: 0; padding: 3px 0; display: flex; justify-content: space-between; gap: 12px; align-items: center; }
  table.stack-m td[data-l]::before { content: attr(data-l); color: var(--ink-2); font-size: 13px; font-weight: 600; flex: none; }
  table.stack-m td.first { font-size: 16px; padding-bottom: 6px; }
  table.stack-m td.first::before { display: none; }
  table.stack-m td.end { text-align: start; }
  table.stack-m tfoot { display: block; } table.stack-m tfoot tr { display: flex; justify-content: space-between; } table.stack-m tfoot td { width: auto; }
  .paper-wrap { padding: 8px; }
}

/* ===== الطباعة ===== */
@page { size: A4; margin: 10mm; }
@media print {
  body { background: #fff !important; }
  .sidebar, .topbar, .scrim, .toasts, .page-head, .no-print, .tabs, .toolbar, .invoice-bar, .backdrop { display: none !important; }
  .app { display: block; }
  .content { padding: 0; max-width: none; }
  .paper-wrap { background: none; padding: 0; overflow: visible; }
  .paper { box-shadow: none; width: 100%; min-height: 0; padding: 0 6mm 6mm; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .paper::before { margin: 0 -6mm 8mm; }
  .grid, .g-side { display: block; }
  .card { border: 0; box-shadow: none; }
  .print-only { display: block !important; }
  table.data th { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  body.print-statement .content > *:not(#statement) { display: none !important; }
}
.print-only { display: none; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* بنود الفاتورة في شاشة التحرير */
@media (max-width: 680px) {
  .item-row { grid-template-columns: minmax(0, 1fr) 1fr 36px !important; padding-bottom: 12px; border-bottom: 1px dashed var(--line); }
  .item-row input[data-f="description"] { grid-column: 1 / -1; }
  .item-row .lt { display: none; }
}
@media (max-width: 680px) { .toasts { inset-inline: 12px; bottom: 14px; } .toast { min-width: 0; max-width: none; } }
@media (max-width: 680px) { .item-head { display: none !important; } }
@media print { .paper { zoom: 1 !important; } }
