/* ============================================================
   دفاتر | Dafater — micro-ERP + XBRL engine · design system
   Arabic-first RTL · navy ink base · teal accent · dark + light
   ============================================================ */

:root, [data-theme="dark"] {
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans Arabic",
          "Noto Kufi Arabic", Tahoma, Arial, sans-serif;

  --bg: #0a1020;
  --bg-deep: #060b17;
  --bg-grad: radial-gradient(900px 500px at 85% -10%, rgba(45, 212, 191, 0.07), transparent 60%),
             radial-gradient(700px 420px at -10% 110%, rgba(94, 120, 255, 0.06), transparent 55%);
  --surface: #101830;
  --surface-2: #16203c;
  --surface-3: #1d294b;
  --border: rgba(158, 180, 235, 0.11);
  --border-strong: rgba(158, 180, 235, 0.24);
  --text: #e8eefb;
  --text-2: #9fb0d0;
  --text-3: #64748f;
  --accent: #2dd4bf;
  --accent-dim: rgba(45, 212, 191, 0.12);
  --accent-ink: #04211c;
  --amber: #e8b45a;
  --amber-dim: rgba(232, 180, 90, 0.13);
  --red: #f07a68;
  --red-dim: rgba(240, 122, 104, 0.13);
  --green: #4ade80;
  --green-dim: rgba(74, 222, 128, 0.12);
  --blue: #7ba6f0;
  --blue-dim: rgba(123, 166, 240, 0.12);
  --shadow: 0 12px 36px rgba(2, 6, 16, 0.5);
  --shadow-sm: 0 3px 12px rgba(2, 6, 16, 0.35);
  --ring: 0 0 0 3px rgba(45, 212, 191, 0.28);

  --r-sm: 8px; --r-md: 12px; --r-lg: 18px;
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px; --sp-6: 32px; --sp-7: 48px;
  --ease: cubic-bezier(0.32, 0.72, 0.24, 1);
}

[data-theme="light"] {
  --bg: #f4f6fa;
  --bg-deep: #e9edf4;
  --bg-grad: radial-gradient(900px 500px at 85% -10%, rgba(13, 148, 136, 0.06), transparent 60%),
             radial-gradient(700px 420px at -10% 110%, rgba(80, 100, 220, 0.05), transparent 55%);
  --surface: #ffffff;
  --surface-2: #f6f8fc;
  --surface-3: #eceff7;
  --border: rgba(18, 32, 68, 0.10);
  --border-strong: rgba(18, 32, 68, 0.22);
  --text: #101a30;
  --text-2: #4a5a7a;
  --text-3: #8794ad;
  --accent: #0d9488;
  --accent-dim: rgba(13, 148, 136, 0.10);
  --accent-ink: #ffffff;
  --amber: #9a6d10;
  --amber-dim: rgba(154, 109, 16, 0.11);
  --red: #c2422f;
  --red-dim: rgba(194, 66, 47, 0.10);
  --green: #15803d;
  --green-dim: rgba(21, 128, 61, 0.10);
  --blue: #2d5fa8;
  --blue-dim: rgba(45, 95, 168, 0.10);
  --shadow: 0 12px 34px rgba(18, 32, 68, 0.12);
  --shadow-sm: 0 3px 10px rgba(18, 32, 68, 0.07);
  --ring: 0 0 0 3px rgba(13, 148, 136, 0.22);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--font);
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  color: var(--text);
  font-size: 15px;
  line-height: 1.75;
  min-height: 100vh;
  transition: background 0.3s var(--ease), color 0.3s var(--ease);
}
::selection { background: var(--accent-dim); }
button { font-family: inherit; cursor: pointer; color: inherit; }
input, select, textarea { font-family: inherit; color: inherit; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
  outline: none; box-shadow: var(--ring); border-radius: var(--r-sm);
}
.hidden { display: none !important; }

/* figures always LTR + tabular */
.num, .money {
  font-variant-numeric: tabular-nums;
  direction: ltr; unicode-bidi: isolate;
  white-space: nowrap;
}
.money.neg { color: var(--red); }

/* ============================================================ login */
.login {
  min-height: 100vh; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: var(--sp-5); gap: var(--sp-5); text-align: center;
}
.login-brand { display: flex; flex-direction: column; align-items: center; gap: var(--sp-3); }
.login-mark {
  width: 66px; height: 66px; border-radius: 20px;
  background: linear-gradient(140deg, var(--accent), #0e9384);
  display: grid; place-items: center; color: var(--accent-ink);
  font-size: 1.7rem; font-weight: 800;
  box-shadow: 0 8px 30px rgba(45, 212, 191, 0.35);
}
.login h1 { font-size: 2.2rem; font-weight: 800; letter-spacing: -0.02em; line-height: 1.2; }
.login .tagline { max-width: 560px; color: var(--text-2); font-size: 0.95rem; line-height: 2; }
.login .tagline b { color: var(--text); }
.persona-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: var(--sp-4); width: 100%; max-width: 820px;
}
.persona {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: var(--sp-5); text-align: center; display: flex; flex-direction: column;
  align-items: center; gap: var(--sp-2);
  transition: transform 0.22s var(--ease), border-color 0.22s var(--ease), box-shadow 0.22s var(--ease);
}
.persona:hover { transform: translateY(-4px); border-color: var(--accent); box-shadow: var(--shadow-sm); }
.persona:disabled { opacity: 0.6; cursor: wait; transform: none; }
.persona .avatar {
  width: 56px; height: 56px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 800; font-size: 1.15rem;
  background: var(--accent-dim); color: var(--accent);
  border: 1px solid var(--border-strong);
}
.persona.t2 .avatar { background: var(--blue-dim); color: var(--blue); }
.persona .p-name { font-weight: 700; font-size: 1.02rem; }
.persona .p-role { font-size: 0.76rem; color: var(--accent); font-weight: 600; }
.persona.t2 .p-role { color: var(--blue); }
.persona .p-tenant { font-size: 0.74rem; color: var(--text-3); line-height: 1.6; }
.login-foot { max-width: 640px; display: flex; flex-direction: column; gap: var(--sp-2); }
.login-note { font-size: 0.74rem; color: var(--text-3); }
.login-err {
  background: var(--red-dim); border: 1px solid var(--red); color: var(--red);
  border-radius: var(--r-md); padding: var(--sp-2) var(--sp-4); font-size: 0.82rem;
}

/* ============================================================ shell */
.shell { display: grid; grid-template-columns: 256px 1fr; min-height: 100vh; }

.sidebar {
  background: color-mix(in srgb, var(--bg-deep) 88%, transparent);
  backdrop-filter: blur(14px);
  border-inline-end: 1px solid var(--border);
  padding: var(--sp-5) var(--sp-4);
  display: flex; flex-direction: column; gap: var(--sp-5);
  position: sticky; top: 0; height: 100vh; overflow-y: auto; z-index: 40;
}
.brand { display: flex; align-items: center; gap: var(--sp-3); padding-inline: var(--sp-2); }
.brand-mark {
  width: 42px; height: 42px; border-radius: 13px; flex-shrink: 0;
  background: linear-gradient(140deg, var(--accent), #0e9384);
  display: grid; place-items: center; color: var(--accent-ink);
  font-weight: 800; font-size: 1.1rem;
  box-shadow: 0 4px 14px rgba(45, 212, 191, 0.3);
}
.brand-name { font-weight: 800; font-size: 1.3rem; line-height: 1.25; letter-spacing: -0.01em; }
.brand-sub { font-size: 0.66rem; color: var(--text-3); letter-spacing: 0.05em; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label { font-size: 0.66rem; color: var(--text-3); letter-spacing: 0.12em; padding: var(--sp-2) var(--sp-3) var(--sp-1); }
.nav-item {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: 8px var(--sp-3); border-radius: var(--r-md);
  color: var(--text-2); text-decoration: none; font-size: 0.89rem; font-weight: 500;
  border: none; background: transparent; width: 100%; text-align: start;
  transition: background 0.18s var(--ease), color 0.18s var(--ease);
}
.nav-item .ic { flex-shrink: 0; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-dim); color: var(--accent); font-weight: 700; }
.nav-item .count {
  margin-inline-start: auto; font-size: 0.68rem; background: var(--surface-3);
  border-radius: 20px; padding: 0 8px; color: var(--text-2); font-variant-numeric: tabular-nums;
}
.nav-item .count.warn { background: var(--amber-dim); color: var(--amber); }

.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: var(--sp-3); }
.tax-disclaimer {
  font-size: 0.68rem; color: var(--text-3); line-height: 1.7;
  border: 1px dashed var(--border-strong); border-radius: var(--r-md);
  padding: var(--sp-2) var(--sp-3);
}
.user-chip { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-2); }
.user-chip .avatar {
  width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0;
  background: var(--accent-dim); border: 1px solid var(--border-strong);
  display: grid; place-items: center; font-size: 0.78rem; font-weight: 700; color: var(--accent);
}
.user-chip .name { font-size: 0.82rem; font-weight: 600; line-height: 1.4; }
.user-chip .role { font-size: 0.68rem; color: var(--text-3); }

/* ============================================================ main + topbar */
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-5); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 30;
  background: color-mix(in srgb, var(--bg) 84%, transparent);
  backdrop-filter: blur(14px);
}
.page-title { font-weight: 800; font-size: 1.08rem; letter-spacing: -0.01em; }
.tenant-pill {
  font-size: 0.72rem; font-weight: 600; color: var(--text-2);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 30px; padding: 3px 12px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; max-width: 260px;
}
.topbar-actions { margin-inline-start: auto; display: flex; align-items: center; gap: var(--sp-2); }
.icon-btn {
  width: 37px; height: 37px; border-radius: var(--r-md); border: 1px solid var(--border);
  background: var(--surface); color: var(--text-2);
  display: grid; place-items: center; flex-shrink: 0;
  transition: color 0.18s var(--ease), border-color 0.18s var(--ease), transform 0.18s var(--ease);
}
.icon-btn:hover { color: var(--accent); border-color: var(--border-strong); transform: translateY(-1px); }
#menuBtn { display: none; }
[data-theme="light"] .ic-moon, [data-theme="dark"] .ic-sun { display: none; }

.content { padding: var(--sp-5) var(--sp-5) var(--sp-7); max-width: 1180px; width: 100%; margin: 0 auto; }
.view { animation: viewIn 0.35s var(--ease) both; }
@keyframes viewIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.page-head { display: flex; flex-wrap: wrap; align-items: flex-start; gap: var(--sp-3); margin-bottom: var(--sp-5); }
.page-head .eyebrow { font-size: 0.72rem; color: var(--accent); font-weight: 700; letter-spacing: 0.04em; }
.page-head h1 { font-size: 1.45rem; font-weight: 800; letter-spacing: -0.02em; line-height: 1.4; }
.page-head p { font-size: 0.84rem; color: var(--text-2); max-width: 620px; line-height: 1.9; }
.page-head .actions { margin-inline-start: auto; display: flex; gap: var(--sp-2); flex-wrap: wrap; }

/* ============================================================ buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text); border-radius: var(--r-md);
  padding: 8px 18px; font-size: 0.86rem; font-weight: 600;
  transition: transform 0.18s var(--ease), box-shadow 0.18s var(--ease),
              border-color 0.18s var(--ease), background 0.18s var(--ease), opacity 0.18s;
}
.btn:hover { transform: translateY(-1px); border-color: var(--accent); box-shadow: var(--shadow-sm); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-primary {
  background: linear-gradient(140deg, var(--accent), #0e9384);
  color: var(--accent-ink); border-color: transparent; font-weight: 700;
  box-shadow: 0 5px 18px rgba(45, 212, 191, 0.28);
}
.btn-primary:hover { box-shadow: 0 8px 24px rgba(45, 212, 191, 0.38); border-color: transparent; }
.btn-danger { color: var(--red); border-color: color-mix(in srgb, var(--red) 40%, transparent); }
.btn-danger:hover { border-color: var(--red); background: var(--red-dim); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-ghost:hover { color: var(--text); border-color: var(--border); box-shadow: none; }
.btn-sm { padding: 4px 12px; font-size: 0.76rem; border-radius: var(--r-sm); }

/* ============================================================ cards / KPI */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: var(--sp-5);
  transition: border-color 0.25s var(--ease);
}
.card + .card { margin-top: var(--sp-4); }
.card-head { display: flex; align-items: baseline; flex-wrap: wrap; gap: var(--sp-3); margin-bottom: var(--sp-4); }
.card-title { font-weight: 700; font-size: 1rem; display: flex; align-items: center; gap: var(--sp-2); }
.card-sub { font-size: 0.76rem; color: var(--text-3); }
.card-head .end { margin-inline-start: auto; display: flex; gap: var(--sp-2); align-items: center; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: var(--sp-4); margin-bottom: var(--sp-5); }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: var(--sp-4) var(--sp-5); position: relative; overflow: hidden;
  transition: transform 0.22s var(--ease), box-shadow 0.22s var(--ease), border-color 0.22s var(--ease);
}
.kpi:hover { transform: translateY(-3px); box-shadow: var(--shadow-sm); border-color: var(--border-strong); }
.kpi::after {
  content: ''; position: absolute; inset-inline-start: 0; top: 0; bottom: 0; width: 3px;
  background: var(--kpi-accent, var(--accent)); opacity: 0.9;
}
.kpi.warn { --kpi-accent: var(--amber); }
.kpi.bad { --kpi-accent: var(--red); }
.kpi.ok { --kpi-accent: var(--green); }
.kpi.calm { --kpi-accent: var(--blue); }
.kpi .label { font-size: 0.74rem; color: var(--text-2); font-weight: 600; }
.kpi .value { font-size: 1.55rem; font-weight: 800; line-height: 1.45; margin-top: 2px; letter-spacing: -0.01em; }
.kpi .value .unit { font-size: 0.8rem; color: var(--text-2); font-weight: 600; }
.kpi .hint { font-size: 0.7rem; color: var(--text-3); }

/* ============================================================ badges + chips */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 0.7rem; font-weight: 700; border-radius: 30px; padding: 2px 10px; white-space: nowrap;
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { background: var(--green-dim); color: var(--green); }
.badge.warn { background: var(--amber-dim); color: var(--amber); }
.badge.bad { background: var(--red-dim); color: var(--red); }
.badge.info { background: var(--blue-dim); color: var(--blue); }
.badge.accent { background: var(--accent-dim); color: var(--accent); }
.badge.mute { background: var(--surface-3); color: var(--text-3); }
.code-tag {
  font-size: 0.72rem; font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate;
  background: var(--surface-3); border: 1px solid var(--border);
  border-radius: 6px; padding: 0 7px; color: var(--text-2);
}

/* ============================================================ tables */
.tbl-wrap { overflow-x: auto; border-radius: var(--r-md); border: 1px solid var(--border); }
.card > .tbl-wrap { border: none; }
.tbl { width: 100%; border-collapse: collapse; font-size: 0.84rem; min-width: 560px; }
.tbl th {
  text-align: start; font-size: 0.7rem; color: var(--text-3); font-weight: 700;
  letter-spacing: 0.05em; padding: var(--sp-2) var(--sp-3);
  border-bottom: 1px solid var(--border-strong); white-space: nowrap;
}
.tbl td { padding: 9px var(--sp-3); border-bottom: 1px solid var(--border); vertical-align: top; }
.tbl tbody tr { transition: background 0.15s var(--ease); }
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl tbody tr:last-child td { border-bottom: none; }
.tbl td.end, .tbl th.end { text-align: end; }
.tbl .strong { font-weight: 700; }
.tbl .muted { color: var(--text-3); }
.tbl tr.total-row td { border-top: 2px solid var(--border-strong); font-weight: 800; background: var(--surface-2); }
.tbl tr.clickable { cursor: pointer; }
.tbl tr.detail-row td { background: var(--bg-deep); padding: var(--sp-3) var(--sp-5); }

/* ============================================================ COA tree */
.tree { display: flex; flex-direction: column; }
.tree-row {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: 7px var(--sp-3); border-radius: var(--r-md); min-height: 40px;
  transition: background 0.15s var(--ease);
}
.tree-row:hover { background: var(--surface-2); }
.tree-row .twisty {
  width: 22px; height: 22px; border: none; background: transparent; color: var(--text-3);
  display: grid; place-items: center; border-radius: 6px; flex-shrink: 0;
  transition: transform 0.2s var(--ease), color 0.15s;
}
.tree-row .twisty:hover { color: var(--accent); }
.tree-node.open > .tree-row .twisty { transform: rotate(-90deg); }
.tree-row .a-name { font-size: 0.87rem; font-weight: 500; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-node[data-depth="0"] > .tree-row .a-name { font-weight: 800; font-size: 0.92rem; }
.tree-node[data-depth="1"] > .tree-row .a-name { font-weight: 700; }
.tree-row .a-bal { margin-inline-start: auto; font-size: 0.83rem; font-weight: 600; }
.tree-kids { border-inline-start: 1px solid var(--border); margin-inline-start: 21px; padding-inline-start: var(--sp-2); display: none; }
.tree-node.open > .tree-kids { display: block; animation: viewIn 0.25s var(--ease) both; }
.map-badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 0.68rem; font-weight: 700; border-radius: 6px; padding: 1px 8px;
  border: none; white-space: nowrap; flex-shrink: 0;
  direction: ltr; unicode-bidi: isolate;
  background: var(--green-dim); color: var(--green); cursor: default;
}
.map-badge.unmapped {
  background: var(--amber-dim); color: var(--amber); cursor: pointer;
  border: 1px dashed var(--amber);
  animation: pulseWarn 2.2s var(--ease) infinite;
  direction: rtl;
}
.map-badge.unmapped:hover { background: var(--amber); color: #241503; animation: none; }
@keyframes pulseWarn { 0%, 100% { box-shadow: 0 0 0 0 rgba(232, 180, 90, 0); } 50% { box-shadow: 0 0 0 4px rgba(232, 180, 90, 0.15); } }

/* ============================================================ journal form */
.jline-grid { display: flex; flex-direction: column; gap: var(--sp-2); }
.jline {
  display: grid; grid-template-columns: minmax(150px, 2fr) 110px 110px 34px;
  gap: var(--sp-2); align-items: center;
}
.jline-head { font-size: 0.68rem; color: var(--text-3); font-weight: 700; letter-spacing: 0.04em; }
.balance-bar {
  display: flex; align-items: center; gap: var(--sp-4); flex-wrap: wrap;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: var(--sp-3) var(--sp-4); margin-top: var(--sp-3);
  transition: border-color 0.25s var(--ease), background 0.25s var(--ease);
}
.balance-bar.balanced { border-color: var(--green); background: var(--green-dim); }
.balance-bar.unbalanced { border-color: var(--red); background: var(--red-dim); }
.balance-bar .cell { font-size: 0.78rem; color: var(--text-2); }
.balance-bar .cell b { display: block; font-size: 0.95rem; color: var(--text); }
.balance-bar .verdict { margin-inline-start: auto; font-weight: 800; font-size: 0.85rem; }
.balance-bar.balanced .verdict { color: var(--green); }
.balance-bar.unbalanced .verdict { color: var(--red); }
.lock-note {
  display: flex; align-items: center; gap: var(--sp-2);
  font-size: 0.74rem; color: var(--text-3); line-height: 1.7;
}
.lock-note .ic { color: var(--amber); flex-shrink: 0; }

/* ============================================================ forms */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: var(--sp-3); }
.field label { font-size: 0.74rem; font-weight: 700; color: var(--text-2); }
.input {
  background: var(--bg-deep); border: 1px solid var(--border-strong); border-radius: var(--r-md);
  padding: 8px var(--sp-3); font-size: 0.87rem; color: var(--text); width: 100%;
  transition: border-color 0.18s var(--ease), box-shadow 0.18s var(--ease);
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
.input::placeholder { color: var(--text-3); }
input.num-in { direction: ltr; text-align: end; font-variant-numeric: tabular-nums; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); }

/* ============================================================ XBRL stages */
.stage {
  position: relative;
  border-inline-start: 3px solid var(--border-strong);
  padding-inline-start: var(--sp-5); padding-bottom: var(--sp-5); margin-inline-start: var(--sp-3);
}
.stage:last-child { padding-bottom: 0; }
.stage::before {
  content: attr(data-n); position: absolute; inset-inline-start: -16px; top: 0;
  width: 29px; height: 29px; border-radius: 50%;
  background: var(--surface-3); border: 1px solid var(--border-strong); color: var(--text-2);
  display: grid; place-items: center; font-size: 0.78rem; font-weight: 800;
}
.stage.on { border-inline-start-color: var(--accent); }
.stage.on::before { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.stage.done::before { background: var(--green); color: #06210f; border-color: transparent; content: '✓'; }
.stage.blocked::before { background: var(--red); color: #fff; border-color: transparent; content: '✕'; }
.stage h3 { font-size: 1rem; font-weight: 800; margin-bottom: 3px; }
.stage .s-sub { font-size: 0.79rem; color: var(--text-2); margin-bottom: var(--sp-3); max-width: 600px; }

.finding {
  display: flex; gap: var(--sp-3); align-items: flex-start;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md);
  border-inline-start: 3px solid var(--red);
  padding: var(--sp-3) var(--sp-4); margin-bottom: var(--sp-2);
  animation: viewIn 0.3s var(--ease) both; animation-delay: calc(var(--i, 0) * 50ms);
}
.finding.warning { border-inline-start-color: var(--amber); }
.finding .f-ic { flex-shrink: 0; margin-top: 3px; color: var(--red); }
.finding.warning .f-ic { color: var(--amber); }
.finding .f-title { font-weight: 700; font-size: 0.87rem; }
.finding .f-title .code-tag { margin-inline-start: 6px; }
.finding .f-detail { font-size: 0.79rem; color: var(--text-2); line-height: 1.8; }
.finding .f-fix { font-size: 0.78rem; color: var(--accent); font-weight: 600; margin-top: 2px; }
.finding .f-act { margin-inline-start: auto; flex-shrink: 0; align-self: center; }

.gen-blocked {
  display: flex; gap: var(--sp-3); align-items: center;
  background: var(--red-dim); border: 1px solid var(--red); border-radius: var(--r-md);
  padding: var(--sp-3) var(--sp-4); color: var(--red); font-size: 0.85rem; font-weight: 600; line-height: 1.8;
}
.gen-ok {
  display: flex; gap: var(--sp-3); align-items: center;
  background: var(--green-dim); border: 1px solid var(--green); border-radius: var(--r-md);
  padding: var(--sp-3) var(--sp-4); color: var(--green); font-size: 0.85rem; font-weight: 600; line-height: 1.8;
}

/* viewer */
.viewer-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(280px, 1fr); gap: var(--sp-4); align-items: start; }
.ix-frame-wrap { border: 1px solid var(--border-strong); border-radius: var(--r-md); overflow: hidden; background: #fff; }
.ix-frame-wrap iframe { display: block; width: 100%; height: 620px; border: none; background: #fff; }
.facts-panel { max-height: 620px; overflow-y: auto; display: flex; flex-direction: column; gap: var(--sp-2); padding-inline-end: 2px; }
.facts-panel::-webkit-scrollbar { width: 5px; }
.facts-panel::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 4px; }
.fact {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: var(--sp-2) var(--sp-3); cursor: pointer;
  transition: border-color 0.15s var(--ease), background 0.15s var(--ease);
}
.fact:hover, .fact.hl { border-color: var(--accent); background: var(--accent-dim); }
.fact .f-label { font-size: 0.8rem; font-weight: 700; display: flex; justify-content: space-between; gap: var(--sp-2); }
.fact .f-el { font-size: 0.7rem; color: var(--accent); direction: ltr; unicode-bidi: isolate; text-align: end; word-break: break-all; display: block; }
.fact .f-meta { font-size: 0.66rem; color: var(--text-3); direction: ltr; unicode-bidi: isolate; text-align: end; display: block; }

/* ============================================================ mapping picker + drawer */
#scrim {
  position: fixed; inset: 0; background: rgba(4, 8, 18, 0.55); backdrop-filter: blur(2px);
  opacity: 0; pointer-events: none; transition: opacity 0.3s var(--ease); z-index: 60;
}
#scrim.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; bottom: 0; inset-inline-start: 0; width: min(480px, 100vw);
  background: var(--surface); border-inline-end: 1px solid var(--border-strong);
  box-shadow: var(--shadow); z-index: 70; display: flex; flex-direction: column;
  /* anchored at the RTL start edge (right) — off-canvas means pushing further right */
  transform: translateX(105%); transition: transform 0.35s var(--ease);
}
.drawer.open { transform: none !important; }
.drawer-head {
  display: flex; align-items: flex-start; gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--border);
}
.drawer-head h2 { font-size: 1.05rem; font-weight: 800; line-height: 1.5; }
.drawer-head .sub { font-size: 0.76rem; color: var(--text-3); }
.drawer-head .icon-btn { margin-inline-start: auto; }
.drawer-body { flex: 1; overflow-y: auto; padding: var(--sp-4) var(--sp-5); }
.drawer-foot { display: flex; gap: var(--sp-2); align-items: center; padding: var(--sp-3) var(--sp-5); border-top: 1px solid var(--border); }

.el-item {
  width: 100%; text-align: start; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: var(--sp-2) var(--sp-3); margin-bottom: var(--sp-2);
  transition: border-color 0.15s var(--ease), background 0.15s var(--ease);
}
.el-item:hover { border-color: var(--accent); background: var(--accent-dim); }
.el-item .e-ar { font-size: 0.85rem; font-weight: 700; }
.el-item .e-name { font-size: 0.7rem; color: var(--accent); direction: ltr; unicode-bidi: isolate; display: block; text-align: end; word-break: break-all; }
.el-item .e-meta { font-size: 0.66rem; color: var(--text-3); }

/* ============================================================ empty / error / skeleton */
.empty {
  text-align: center; padding: var(--sp-7) var(--sp-5); color: var(--text-3);
  border: 1.5px dashed var(--border-strong); border-radius: var(--r-lg);
  display: flex; flex-direction: column; align-items: center; gap: var(--sp-2);
}
.empty .e-ic {
  width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface-2); color: var(--text-3); font-size: 1.2rem; font-weight: 800;
}
.empty h3 { color: var(--text-2); font-size: 0.95rem; }
.empty p { font-size: 0.8rem; max-width: 420px; line-height: 1.9; }
.empty.error { border-color: color-mix(in srgb, var(--red) 45%, transparent); }
.empty.error .e-ic { background: var(--red-dim); color: var(--red); }

.sk {
  border-radius: var(--r-sm); height: 14px; margin: 8px 0;
  background: linear-gradient(100deg, var(--surface-2) 40%, var(--surface-3) 50%, var(--surface-2) 60%);
  background-size: 200% 100%; animation: shimmer 1.4s infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }
.sk.w40 { width: 40%; } .sk.w60 { width: 60%; } .sk.w80 { width: 80%; } .sk.tall { height: 26px; }

/* ============================================================ toast */
#toasts { position: fixed; bottom: var(--sp-4); inset-inline-start: 50%; transform: translateX(50%); z-index: 90; display: flex; flex-direction: column; gap: var(--sp-2); align-items: center; width: min(480px, calc(100vw - 32px)); }
.toast {
  display: flex; gap: var(--sp-2); align-items: flex-start; width: 100%;
  background: var(--surface-3); border: 1px solid var(--border-strong); color: var(--text);
  padding: var(--sp-2) var(--sp-4); border-radius: var(--r-md); font-size: 0.83rem;
  box-shadow: var(--shadow); animation: toastIn 0.3s var(--ease) both;
}
@keyframes toastIn { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
.toast.out { opacity: 0; transform: translateY(10px); transition: 0.25s var(--ease); }
.toast .t-ic { flex-shrink: 0; margin-top: 4px; color: var(--green); }
.toast.bad .t-ic { color: var(--red); }
.toast.info .t-ic { color: var(--blue); }
.toast .t-msg { font-weight: 700; }
.toast .t-sub { font-size: 0.74rem; color: var(--text-2); }

/* ============================================================ tour */




.tour-card .t-nav { display: flex; gap: var(--sp-2); margin-top: var(--sp-3); align-items: center; }
.tour-card .t-nav .spacer { flex: 1; }

/* ============================================================ docs */
.route-card { border: 1px solid var(--border); border-radius: var(--r-md); margin-bottom: var(--sp-3); overflow: hidden; }
.route-head {
  display: flex; align-items: center; gap: var(--sp-3); width: 100%;
  background: var(--surface); border: none; padding: var(--sp-3) var(--sp-4); text-align: start;
  transition: background 0.15s;
}
.route-head:hover { background: var(--surface-2); }
.method {
  font-size: 0.68rem; font-weight: 800; letter-spacing: 0.05em; border-radius: 6px;
  padding: 2px 9px; min-width: 52px; text-align: center; direction: ltr;
}
.method.get { background: var(--green-dim); color: var(--green); }
.method.post { background: var(--blue-dim); color: var(--blue); }
.method.put { background: var(--amber-dim); color: var(--amber); }
.route-path { font-size: 0.85rem; font-weight: 600; direction: ltr; unicode-bidi: isolate; font-variant-numeric: tabular-nums; }
.route-sum { font-size: 0.74rem; color: var(--text-3); margin-inline-start: auto; text-align: end; }
.route-body { padding: var(--sp-3) var(--sp-4); border-top: 1px solid var(--border); background: var(--bg-deep); display: none; }
.route-card.open .route-body { display: block; animation: viewIn 0.25s var(--ease); }
.route-body h5 { font-size: 0.72rem; color: var(--text-2); font-weight: 800; margin: var(--sp-2) 0 4px; }
pre.code {
  direction: ltr; text-align: left; font-size: 0.74rem; line-height: 1.7;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: var(--sp-3); overflow-x: auto; color: var(--text-2); white-space: pre;
}

/* ============================================================ misc */
.note-strip {
  display: flex; gap: var(--sp-2); align-items: flex-start;
  font-size: 0.76rem; color: var(--text-2); line-height: 1.8;
  background: var(--blue-dim); border: 1px solid color-mix(in srgb, var(--blue) 35%, transparent);
  border-radius: var(--r-md); padding: var(--sp-2) var(--sp-4); margin-bottom: var(--sp-4);
}
.note-strip .ic { color: var(--blue); flex-shrink: 0; margin-top: 4px; }
.note-strip.amber { background: var(--amber-dim); border-color: color-mix(in srgb, var(--amber) 35%, transparent); }
.note-strip.amber .ic { color: var(--amber); }
.tabs { display: flex; gap: var(--sp-2); flex-wrap: wrap; margin-bottom: var(--sp-4); }
.tab-btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2);
  border-radius: 30px; padding: 5px 16px; font-size: 0.8rem; font-weight: 600;
  transition: 0.18s var(--ease);
}
.tab-btn:hover { border-color: var(--border-strong); color: var(--text); }
.tab-btn.active { background: var(--accent-dim); border-color: transparent; color: var(--accent); font-weight: 700; }
.ic { display: inline-flex; flex-shrink: 0; }
.ic svg { display: block; }

/* ============================================================ print */
@media print {
  .sidebar, .topbar, #toasts, #scrim, .drawer, .tour-card, .no-print, .tabs, .page-head .actions { display: none !important; }
  body { background: #fff !important; background-image: none !important; color: #000 !important; }
  .shell { display: block; }
  .content { padding: 0; max-width: none; }
  .card { border: none; box-shadow: none; padding: 0; break-inside: avoid; }
  .tbl th, .tbl td { border-color: #ccc !important; color: #000 !important; }
  .kpi, .tbl tbody tr:hover { background: #fff !important; }
}

/* ============================================================ responsive */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset-inline-start: 0; top: 0; bottom: 0; width: min(290px, 84vw);
    transform: translateX(105%); transition: transform 0.32s var(--ease); height: 100vh;
  }
  .sidebar.open { transform: none; box-shadow: var(--shadow); }
  #menuBtn { display: grid; }
  .content { padding: var(--sp-4) var(--sp-3) var(--sp-7); }
  .viewer-grid { grid-template-columns: 1fr; }
  .ix-frame-wrap iframe { height: 440px; }
  .facts-panel { max-height: 380px; }
  .tenant-pill { max-width: 130px; }
}
@media (max-width: 480px) {
  body { font-size: 14px; }
  .page-head h1 { font-size: 1.2rem; }
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: var(--sp-2); }
  .kpi { padding: var(--sp-3) var(--sp-4); }
  .kpi .value { font-size: 1.15rem; }
  .row2 { grid-template-columns: 1fr; }
  .jline { grid-template-columns: minmax(110px, 2fr) 82px 82px 30px; gap: 6px; }
  .persona-grid { grid-template-columns: 1fr; }
  .login h1 { font-size: 1.7rem; }
  .route-sum { display: none; }
  .tree-row { flex-wrap: wrap; row-gap: 2px; }
  .tree-row .a-bal { flex-basis: 100%; text-align: start; padding-inline-start: 30px; }
  .content { padding-inline: var(--sp-2); }
  .drawer { width: 100vw; }
}

/* ============ statutory appropriations panel (التوزيعات النظامية) ============ */
.stat-na td { opacity: 0.55; }
.stat-na td:first-child { text-decoration: line-through; text-decoration-thickness: 1px; }
.stat-na-why td { padding-top: 0; border-top: none; font-size: 0.78rem; color: var(--text-2); opacity: 0.85; }
.rsv-wrap { padding: 14px 16px 4px; }
.rsv-label { font-size: 0.8rem; color: var(--text-2); margin-bottom: 8px; }
.rsv-bar { height: 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border-strong); overflow: hidden; }
.rsv-fill { height: 100%; border-radius: inherit; background: var(--green); min-width: 3px; transition: width 0.6s ease; }
.rsv-bar.capped .rsv-fill { background: var(--amber); }
.stat-foot { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: var(--sp-4); padding: 14px 16px; }
.stat-notes { padding: 0 16px 14px; font-size: 0.76rem; color: var(--text-3); line-height: 1.9; }


/* ============================ guided tour: cut-out spotlight, one lit thing ============ */
:root, [data-theme="dark"] { --tour-dim: rgba(4, 9, 20, 0.76); }
[data-theme="light"] { --tour-dim: rgba(16, 26, 48, 0.5); }
/* no overflow:hidden here — it would block scrollIntoView for below-the-fold targets;
   the spot re-places itself on scroll instead */

/* The spot's giant spread shadow IS the dim: a transparent hole over the target,
   so the element beneath stays bright and clickable (box-shadow never catches clicks). */
.tour-spot {
  position: fixed; z-index: 901; border-radius: 12px; pointer-events: none;
  border: 2px solid var(--accent);
  background: transparent;
  box-shadow: 0 0 0 9999px var(--tour-dim);
  transition: top .28s var(--ease), left .28s var(--ease),
              width .28s var(--ease), height .28s var(--ease);
}
.tour-spot::after { /* glow ring pulses on its own layer; the dim shadow stays static */
  content: ''; position: absolute; inset: -2px; border-radius: inherit;
  box-shadow: 0 0 0 4px var(--accent-dim), 0 0 26px 5px color-mix(in srgb, var(--accent) 45%, transparent);
  animation: tourPulse 1.9s ease-in-out infinite;
}
.tour-spot.void { border-color: transparent; }
.tour-spot.void::after { animation: none; box-shadow: none; }
@keyframes tourPulse {
  0%, 100% { box-shadow: 0 0 0 4px var(--accent-dim), 0 0 22px 4px color-mix(in srgb, var(--accent) 38%, transparent); }
  50%      { box-shadow: 0 0 0 7px var(--accent-dim), 0 0 38px 9px color-mix(in srgb, var(--accent) 60%, transparent); }
}

/* Step interactions open the drawer (قيد جديد، اربط الحساب): lift it above the dim. */
body.tour-on #scrim { z-index: 940; }
body.tour-on .drawer { z-index: 950; }
body.tour-on #toasts { z-index: 960; }

.tour-card {
  position: fixed; z-index: 902;
  width: min(460px, calc(100vw - 24px));
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  padding: 20px 22px;
  box-shadow: var(--shadow), 0 0 0 1px var(--accent-dim);
  opacity: 1;
  transition: top .28s var(--ease), left .28s var(--ease), opacity .2s ease-out;
}
/* The card must NEVER be invisible: if the spotlight can't find its target, the text still shows. */
.tour-card.placing { opacity: 1; }
.tour-card.centered { top: 50% !important; left: 50% !important; transform: translate(-50%, -50%); }

.tour-card .t-step {
  font-size: 0.72rem; color: var(--accent); font-weight: 800;
  letter-spacing: .04em; margin-bottom: 6px;
}
.tour-card h4 { font-size: 1.24rem; font-weight: 800; margin: 0 0 8px; line-height: 1.4; }
.tour-card .t-why {
  display: inline-block; font-size: .72rem; font-weight: 800; color: var(--accent);
  background: rgba(45,212,191,.12); border: 1px solid rgba(45,212,191,.35);
  padding: 3px 10px; border-radius: 999px; margin-bottom: 10px;
}
.tour-card p { font-size: 0.97rem; color: var(--text); line-height: 2.05; margin: 0; }
.tour-card .t-nav { display: flex; gap: 10px; margin-top: 18px; align-items: center; }
.tour-card .t-nav .spacer { flex: 1; }
.tour-card .t-nav .btn-primary { padding: 10px 22px; font-size: .95rem; font-weight: 800; }

@media (max-width: 640px) {
  .tour-card { width: calc(100vw - 20px); padding: 18px; left: 10px !important; }
  .tour-card.centered { transform: translateY(-50%); } /* left is pinned; only vertical centering */
  .tour-card h4 { font-size: 1.1rem; }
  .tour-card p { font-size: .93rem; line-height: 1.95; }
}


/* The spotlight rides the element itself: lifted above the dim, ringed and glowing. */
.tour-target {
  position: relative; z-index: 901 !important;
  border-radius: 10px;
  outline: 2px solid var(--accent);
  outline-offset: 4px;
  box-shadow: 0 0 0 6px rgba(45,212,191,.18), 0 0 34px 8px rgba(45,212,191,.55);
  animation: tourPulse 1.9s ease-in-out infinite;
}
/* Kill the measured ring — the class-based highlight replaces it. */
.tour-spot { display: none !important; }

/* Dim everything except the .tour-target (which is lifted to z-index 901) and the card (902). */
body.tour-on #tour::before {
  content: ''; position: fixed; inset: 0; z-index: 900;
  background: rgba(3, 7, 16, 0.74);
  animation: tourFade .18s ease-out;
  pointer-events: none;
}

/* The highlighted element must read as LIT, not just ringed: brighten it and lay a
   glowing halo behind it so it visibly pops out of the dimmed page. */
.tour-target {
  filter: brightness(1.35) saturate(1.2);
  box-shadow:
    0 0 0 6px rgba(45, 212, 191, 0.26),
    0 0 40px 12px rgba(45, 212, 191, 0.60),
    0 0 110px 34px rgba(45, 212, 191, 0.30) !important;
}
.tour-target::after {
  content: ''; position: absolute; inset: -14px; z-index: -1;
  border-radius: 16px; pointer-events: none;
  background: radial-gradient(ellipse at center, rgba(45,212,191,.30), rgba(45,212,191,.10) 55%, transparent 75%);
}

/* Fill the target with the accent so it reads as switched-on, not merely outlined. */
.tour-target,
.tour-target * {
  color: #04211c !important;   /* dark ink on the lit accent fill */
  border-color: var(--accent) !important;
}
.tour-target {
  background-color: var(--accent) !important;
  background-image: none !important;
}
