/* ==========================================================================
   Sanadex.wanis.online — editorial "paper ledger" design system
   Warm paper, ink rail, clay accent, hairline rules, tabular numerals.
   No gradients, no glassmorphism.
   ========================================================================== */

/* ---------------------------------------------------------------- tokens */
:root {
  --paper: #f4f1ea;
  --surface: #ffffff;
  --surface-2: #faf8f3;
  --surface-3: #f0ece2;
  --ink: #191713;
  --ink-2: #4a453c;
  --muted: #7a7364;
  --line: #e3ddcf;
  --line-strong: #cfc7b4;
  --accent: #b4441f;
  --accent-ink: #8c3316;
  --accent-soft: #f7e8e0;
  --ok: #2e6b4f;
  --ok-soft: #e4f0e8;
  --warn: #90620f;
  --warn-soft: #f8ecd4;
  --danger: #a32828;
  --danger-soft: #f8e2df;
  --info: #2a5c82;
  --info-soft: #e4edf4;
  --rail: #191713;
  --rail-2: #221f19;
  --rail-text: #d8d2c4;
  --rail-muted: #8c8574;
  --rail-line: #2e2a22;
  --shadow-1: 0 1px 2px rgba(25, 23, 19, .05);
  --shadow-2: 0 10px 30px -12px rgba(25, 23, 19, .28);
  --r-xs: 3px;
  --r-sm: 5px;
  --r-md: 8px;
  --r-lg: 12px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, "Liberation Mono", monospace;
  --sans: "Dubai", "Cairo", "Segoe UI", system-ui, -apple-system, Tahoma, sans-serif;
  --rail-w: 264px;
  --rail-w-min: 78px;
  --topbar-h: 62px;
}

[data-accent="ink"] { --accent: #2b3a4a; --accent-ink: #1d2937; --accent-soft: #e6eaef; }
[data-accent="moss"] { --accent: #476b3f; --accent-ink: #365430; --accent-soft: #e8efe4; }
[data-accent="plum"] { --accent: #6d3350; --accent-ink: #55263d; --accent-soft: #f0e4eb; }

[data-theme="dark"] {
  --paper: #12110e;
  --surface: #1b1915;
  --surface-2: #211e19;
  --surface-3: #2a261f;
  --ink: #f1ece0;
  --ink-2: #cbc4b3;
  --muted: #968e7e;
  --line: #302c24;
  --line-strong: #453f33;
  --accent: #e07a4f;
  --accent-ink: #eda184;
  --accent-soft: #37241b;
  --ok: #6fae8b;
  --ok-soft: #1e2f26;
  --warn: #d7a44b;
  --warn-soft: #322817;
  --danger: #e07a72;
  --danger-soft: #341d1b;
  --info: #7aa9cf;
  --info-soft: #1b2933;
  --rail: #0e0d0b;
  --rail-2: #16140f;
  --rail-text: #cfc8b7;
  --rail-muted: #7c7565;
  --rail-line: #262219;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-2: 0 16px 40px -14px rgba(0, 0, 0, .7);
}

/* ---------------------------------------------------------------- reset */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  background-color: var(--paper);
  background-image: radial-gradient(rgba(25, 23, 19, .035) 1px, transparent 1px);
  background-size: 4px 4px;
}
[data-theme="dark"] body {
  background-image: radial-gradient(rgba(255, 255, 255, .022) 1px, transparent 1px);
}
h1, h2, h3, h4, h5 { margin: 0; font-weight: 700; line-height: 1.25; letter-spacing: -.01em; }
p { margin: 0 0 .6em; }
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
img { max-width: 100%; }
svg.ic { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7;
  stroke-linecap: round; stroke-linejoin: round; flex: none; }
button, input, select, textarea { font: inherit; color: inherit; }
table { border-collapse: collapse; width: 100%; }
[hidden] { display: none !important; }
::selection { background: var(--accent); color: #fff; }

/* scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 10px; border: 3px solid transparent;
  background-clip: content-box; }

/* ---------------------------------------------------------------- layout */
.app { display: flex; min-height: 100vh; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.sidebar {
  position: sticky; top: 0; height: 100vh; width: var(--rail-w); flex: 0 0 var(--rail-w);
  background: var(--rail); color: var(--rail-text);
  display: flex; flex-direction: column; z-index: 40;
  border-inline-end: 1px solid var(--rail-line);
  transition: width .18s ease, flex-basis .18s ease;
}
.sb-head { display: flex; align-items: center; gap: 10px; padding: 18px 16px 14px; }
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; color: inherit; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 36px; height: 36px; flex: none; display: grid; place-items: center;
  background: var(--accent); color: #fff; border-radius: 4px;
  font-family: var(--mono); font-weight: 700; font-size: 19px; letter-spacing: -.05em;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.12; min-width: 0; }
.brand-text strong { font-size: 15.5px; font-weight: 800; letter-spacing: .01em; color: #fff; }
.brand-text em { font-style: normal; font-family: var(--mono); font-size: 10.5px; color: var(--accent);
  letter-spacing: .04em; }
.sb-toggle {
  margin-inline-start: auto; width: 28px; height: 28px; display: grid; place-items: center;
  background: transparent; border: 1px solid var(--rail-line); color: var(--rail-muted);
  border-radius: var(--r-xs); cursor: pointer;
}
.sb-toggle:hover { color: #fff; border-color: var(--rail-muted); }

.sb-nav { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 4px 10px 18px; }
.nav-group { margin-top: 14px; }
.nav-group:first-child { margin-top: 2px; }
.nav-group-label {
  display: flex; align-items: center; gap: 8px; padding: 0 8px 6px;
  font-size: 10px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase;
  color: var(--rail-muted); white-space: nowrap;
}
.nav-group-label::after { content: ""; flex: 1; height: 1px; background: var(--rail-line); }
.nav-link {
  display: flex; align-items: center; gap: 11px; padding: 8px 10px; margin-bottom: 1px;
  color: var(--rail-text); border-radius: var(--r-sm); font-size: 13.6px; font-weight: 500;
  position: relative; white-space: nowrap;
}
.nav-link:hover { background: var(--rail-2); color: #fff; text-decoration: none; }
.nav-link.active { background: rgba(224, 122, 79, .16); color: #fff; font-weight: 700; }
.nav-link.active::before {
  content: ""; position: absolute; inset-inline-start: -10px; top: 6px; bottom: 6px;
  width: 3px; background: var(--accent); border-radius: 0 2px 2px 0;
}
[dir="rtl"] .nav-link.active::before { border-radius: 2px 0 0 2px; }
.nav-link .ic { color: var(--rail-muted); width: 17px; height: 17px; }
.nav-link:hover .ic, .nav-link.active .ic { color: var(--accent); }
.nav-text { overflow: hidden; text-overflow: ellipsis; }
.nav-count { margin-inline-start: auto; font-family: var(--mono); font-size: 11px; color: var(--rail-muted); }

.sb-foot { border-top: 1px solid var(--rail-line); padding: 12px 10px 14px; }
.sb-user { display: flex; align-items: center; gap: 9px; padding: 6px 8px; border-radius: var(--r-sm); }
.sb-user:hover { background: var(--rail-2); text-decoration: none; }
.avatar {
  width: 30px; height: 30px; flex: none; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 12.5px; font-family: var(--mono);
}
.avatar.lg { width: 42px; height: 42px; font-size: 15px; }
.sb-user-meta { min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.sb-user-meta b { font-size: 12.8px; color: #fff; font-weight: 600; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.sb-user-meta span { font-size: 10.5px; color: var(--rail-muted); }
.sb-links { display: flex; gap: 6px; margin-top: 8px; }
.sb-links a, .sb-links button {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 5px; height: 30px;
  border: 1px solid var(--rail-line); border-radius: var(--r-xs); color: var(--rail-muted);
  background: transparent; font-size: 11.5px; cursor: pointer;
}
.sb-links a:hover, .sb-links button:hover { color: #fff; border-color: var(--rail-muted);
  text-decoration: none; }

/* collapsed rail */
body.sb-collapsed .sidebar { width: var(--rail-w-min); flex-basis: var(--rail-w-min); }
body.sb-collapsed .brand-text,
body.sb-collapsed .nav-text,
body.sb-collapsed .nav-group-label span,
body.sb-collapsed .sb-user-meta,
body.sb-collapsed .sb-links span { display: none; }
body.sb-collapsed .sb-head { justify-content: center; padding-inline: 8px; flex-wrap: wrap; gap: 6px; }
body.sb-collapsed .sidebar .sb-toggle { margin: 0 auto; }
body.sb-collapsed .nav-link { justify-content: center; padding: 9px 0; }
body.sb-collapsed .nav-group-label { justify-content: center; padding: 0 0 6px; }
body.sb-collapsed .nav-group-label::after { display: none; }
body.sb-collapsed .sb-user { justify-content: center; }
body.sb-collapsed .sb-links a, body.sb-collapsed .sb-links button { flex: 1; }

/* topbar */
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--topbar-h); flex: none;
  display: flex; align-items: center; gap: 12px; padding: 0 22px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
}
.tb-menu, .tb-collapse {
  width: 34px; height: 34px; display: none; place-items: center; background: transparent;
  border: 1px solid var(--line); border-radius: var(--r-sm); color: var(--ink-2); cursor: pointer;
}
.tb-collapse { display: grid; }
.tb-menu:hover, .tb-collapse:hover { border-color: var(--line-strong); color: var(--ink); }
.tb-crumb { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted);
  min-width: 0; }
.tb-crumb b { color: var(--ink); font-weight: 600; font-size: 13.5px; }
.tb-crumb .sep { color: var(--line-strong); }
.tb-crumb span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb-actions { margin-inline-start: auto; display: flex; align-items: center; gap: 7px; }
.search-trigger {
  display: flex; align-items: center; gap: 8px; height: 34px; padding: 0 10px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-sm);
  color: var(--muted); font-size: 12.5px; cursor: pointer; min-width: 200px;
}
.search-trigger:hover { border-color: var(--line-strong); color: var(--ink-2); }
.search-trigger .ic { width: 15px; height: 15px; }
.kbd {
  font-family: var(--mono); font-size: 10px; padding: 2px 5px; border-radius: 3px;
  border: 1px solid var(--line-strong); color: var(--muted); margin-inline-start: auto;
  background: var(--surface);
}
.lang-switch, .theme-btn {
  height: 34px; min-width: 34px; display: inline-flex; align-items: center; justify-content: center;
  gap: 5px; padding: 0 9px; border: 1px solid var(--line); border-radius: var(--r-sm);
  color: var(--ink-2); font-size: 12px; font-weight: 600; background: var(--surface);
}
.lang-switch:hover, .theme-btn:hover { border-color: var(--line-strong); text-decoration: none; color: var(--ink); }
.tb-user { display: flex; align-items: center; gap: 8px; padding-inline-start: 8px;
  border-inline-start: 1px solid var(--line); }
.tb-user span { font-size: 12.5px; font-weight: 600; }
@media (max-width: 1180px) { .tb-user span { display: none; } }
@media (max-width: 760px) { .search-trigger { min-width: 0; } .search-trigger span { display: none; } }

/* content */
.content { flex: 1; width: 100%; max-width: 1560px; margin: 0 auto; padding: 22px 26px 40px; }
.page-head { display: flex; align-items: flex-end; gap: 18px; flex-wrap: wrap; margin-bottom: 18px; }
.page-title { font-size: 25px; font-weight: 800; letter-spacing: -.02em; }
.page-sub { color: var(--muted); font-size: 13px; margin-top: 3px; max-width: 70ch; }
.page-actions { margin-inline-start: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.foot {
  border-top: 1px solid var(--line); padding: 14px 26px; color: var(--muted); font-size: 11.5px;
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
}
.foot .dot { width: 3px; height: 3px; border-radius: 50%; background: var(--line-strong); }
@media (max-width: 640px) { .content { padding: 16px 14px 32px; } .page-title { font-size: 21px; } }

/* mobile drawer */
.scrim { position: fixed; inset: 0; background: rgba(12, 11, 9, .55); z-index: 39; display: none; }
@media (max-width: 1000px) {
  .sidebar {
    position: fixed; inset-block: 0; inset-inline-start: 0; height: 100vh;
    width: var(--rail-w); flex-basis: var(--rail-w); transform: translateX(-100%);
    transition: transform .2s ease; box-shadow: var(--shadow-2);
  }
  [dir="rtl"] .sidebar { transform: translateX(100%); }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open .scrim { display: block; }
  body.sb-collapsed .sidebar { width: var(--rail-w); flex-basis: var(--rail-w); }
  body.sb-collapsed .brand-text, body.sb-collapsed .nav-text,
  body.sb-collapsed .nav-group-label span, body.sb-collapsed .sb-user-meta,
  body.sb-collapsed .sb-links span { display: initial; }
  body.sb-collapsed .sb-head { justify-content: flex-start; }
  body.sb-collapsed .nav-link { justify-content: flex-start; padding: 8px 10px; }
  body.sb-collapsed .nav-group-label { justify-content: flex-start; }
  .tb-menu { display: grid; }
  .tb-collapse { display: none; }
}
@media (min-width: 1001px) { body.nav-open .scrim { display: none; } }

/* ---------------------------------------------------------------- surfaces */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
  box-shadow: var(--shadow-1); overflow: hidden;
}
.card + .card { margin-top: 16px; }
.card-head {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px;
  border-bottom: 1px solid var(--line); background: var(--surface-2);
}
.card-title { font-size: 11.5px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase;
  color: var(--ink-2); }
.card-actions { margin-inline-start: auto; display: flex; gap: 6px; align-items: center; }
.card-body { padding: 16px; }
.card-body.tight { padding: 10px 12px; }
.card-body.flush { padding: 0; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-side { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-side, .grid-3 { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 720px) { .grid-2, .grid-4 { grid-template-columns: minmax(0, 1fr); } }

.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.end { justify-content: flex-end; }
.gap-sm { gap: 6px; }
.spacer { flex: 1; }

/* ---------------------------------------------------------------- text utils */
.muted { color: var(--muted); }
.tiny { font-size: 11.5px; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; text-align: end; }
.txt-end { text-align: end; }
.txt-center { text-align: center; }
.strong { font-weight: 700; }
.section-label { font-size: 10.5px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 8px; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------------------------------------------------------------- buttons */
.btn {
  --btn-bg: var(--surface);
  --btn-fg: var(--ink);
  --btn-bd: var(--line-strong);
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 36px; padding: 0 14px; border-radius: var(--r-sm); border: 1px solid var(--btn-bd);
  background: var(--btn-bg); color: var(--btn-fg); font-size: 13px; font-weight: 600;
  cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s, color .12s;
}
.btn:hover { text-decoration: none; border-color: var(--ink-2); }
.btn:active { transform: translateY(1px); }
.btn .ic { width: 16px; height: 16px; }
.btn-primary { --btn-bg: var(--accent); --btn-fg: #fff; --btn-bd: var(--accent); }
.btn-primary:hover { --btn-bg: var(--accent-ink); --btn-bd: var(--accent-ink); }
.btn-ink { --btn-bg: var(--ink); --btn-fg: var(--surface); --btn-bd: var(--ink); }
.btn-ghost { --btn-bg: transparent; --btn-bd: transparent; color: var(--ink-2); }
.btn-ghost:hover { --btn-bg: var(--surface-3); --btn-bd: transparent; }
.btn-danger { --btn-bg: transparent; --btn-fg: var(--danger); --btn-bd: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn-danger:hover { --btn-bg: var(--danger); --btn-fg: #fff; --btn-bd: var(--danger); }
.btn-ok { --btn-bg: transparent; --btn-fg: var(--ok); --btn-bd: color-mix(in srgb, var(--ok) 44%, transparent); }
.btn-ok:hover { --btn-bg: var(--ok); --btn-fg: #fff; --btn-bd: var(--ok); }
.btn-sm { height: 29px; padding: 0 10px; font-size: 12px; border-radius: var(--r-xs); }
.btn-sm .ic { width: 14px; height: 14px; }
.btn-lg { height: 42px; padding: 0 20px; font-size: 14px; }
.btn-icon { width: 34px; height: 34px; padding: 0; }
.btn-sm.btn-icon { width: 28px; height: 28px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn-group { display: inline-flex; gap: 4px; }

/* ---------------------------------------------------------------- badges & chips */
.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 700; letter-spacing: .02em; white-space: nowrap;
  border: 1px solid transparent;
}
.b-neutral { background: var(--surface-3); color: var(--ink-2); border-color: var(--line); }
.b-ok { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 24%, transparent); }
.b-warn { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 26%, transparent); }
.b-danger { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 26%, transparent); }
.b-info { background: var(--info-soft); color: var(--info); border-color: color-mix(in srgb, var(--info) 24%, transparent); }
.b-accent { background: var(--accent-soft); color: var(--accent-ink); border-color: color-mix(in srgb, var(--accent) 26%, transparent); }

.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 11px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface);
  color: var(--ink-2); font-size: 12.5px; font-weight: 600;
}
.chip:hover { border-color: var(--line-strong); text-decoration: none; color: var(--ink); }
.chip.is-on { background: var(--ink); border-color: var(--ink); color: var(--surface); }
.chip .ic { width: 14px; height: 14px; }
.chip-row { display: flex; gap: 7px; flex-wrap: wrap; }

/* ---------------------------------------------------------------- table */
.table-wrap { overflow: auto; border-radius: 0; }
table.table { font-size: 13.5px; }
.table thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--surface-2); color: var(--muted); text-align: start;
  font-size: 10.5px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase;
  padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.table tbody td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:hover td { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table td.num, .table th.num { text-align: end; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.table .act { text-align: end; white-space: nowrap; }
.table .act .btn { margin-inline-start: 4px; }
.table tfoot td { padding: 10px 12px; border-top: 2px solid var(--line-strong); font-weight: 700;
  background: var(--surface-2); }
.table .subtle { color: var(--muted); font-size: 12px; }
.table-sm tbody td { padding: 6px 8px; }
.table-fixed { table-layout: fixed; }
[dir="rtl"] .select { text-align: right; }
.table-fixed .input, .table-fixed .select { min-width: 0; }
.table-zebra tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }

/* ---------------------------------------------------------------- forms */
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; text-align: start; }
.label { font-size: 12px; font-weight: 700; color: var(--ink-2); display: flex; gap: 6px;
  align-items: baseline; text-align: start; }
.label .req { color: var(--danger); font-weight: 700; }
.input, .select, .textarea {
  width: 100%; min-height: 38px; padding: 8px 10px; border: 1px solid var(--line-strong);
  border-radius: var(--r-sm); background: var(--surface); color: var(--ink); font-size: 13.5px;
  text-align: start; transition: border-color .12s, box-shadow .12s;
}
.input[dir="ltr"], .textarea[dir="ltr"] { font-family: var(--mono); font-size: 12px; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--muted); }
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
}
.textarea { min-height: 84px; resize: vertical; }
.select {
  padding-inline-end: 8px;
}
.help { font-size: 11.5px; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 14px; }
.span-2 { grid-column: span 2; } .span-3 { grid-column: span 3; } .span-4 { grid-column: span 4; }
.span-5 { grid-column: span 5; } .span-6 { grid-column: span 6; } .span-7 { grid-column: span 7; }
.span-8 { grid-column: span 8; } .span-9 { grid-column: span 9; } .span-12 { grid-column: span 12; }
@media (max-width: 900px) {
  .span-2, .span-3, .span-4, .span-5, .span-6, .span-7, .span-8, .span-9 { grid-column: span 12; }
}
.check { display: flex; align-items: center; gap: 9px; min-height: 38px; }
.check input[type="checkbox"], .check input[type="radio"] {
  appearance: none; width: 18px; height: 18px; border: 1.5px solid var(--line-strong);
  border-radius: 3px; background: var(--surface); cursor: pointer; flex: none; position: relative;
}
.check input:checked { background: var(--accent); border-color: var(--accent); }
.check input:checked::after {
  content: ""; position: absolute; inset: 0; background: no-repeat center/12px 12px
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E");
}
.check span { font-size: 13px; color: var(--ink-2); }
.toolbar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 12px 14px;
  border-bottom: 1px solid var(--line); background: var(--surface-2);
}
.toolbar .input, .toolbar .select { min-height: 34px; padding-block: 5px; font-size: 13px; }
.toolbar form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; width: 100%; }
.search-box { position: relative; flex: 1; min-width: 180px; max-width: 340px; }
.search-box .ic { position: absolute; inset-inline-start: 10px; top: 9px; width: 15px; height: 15px;
  color: var(--muted); }
.search-box .input { padding-inline-start: 32px; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px;
  overflow-x: auto; }
.tab { padding: 9px 14px; font-size: 13px; font-weight: 600; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab:hover { color: var(--ink); text-decoration: none; }
.tab.is-on { color: var(--ink); border-bottom-color: var(--accent); }

/* ---------------------------------------------------------------- flash */
.flashes { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.flash {
  display: flex; align-items: flex-start; gap: 10px; padding: 11px 13px; border-radius: var(--r-sm);
  border: 1px solid var(--line); border-inline-start: 3px solid var(--muted);
  background: var(--surface); font-size: 13.5px; box-shadow: var(--shadow-1);
}
.flash.success { border-inline-start-color: var(--ok); background: var(--ok-soft); }
.flash.danger { border-inline-start-color: var(--danger); background: var(--danger-soft); }
.flash.warning { border-inline-start-color: var(--warn); background: var(--warn-soft); }
.flash.info { border-inline-start-color: var(--info); background: var(--info-soft); }
.flash .ic { margin-top: 2px; }
.flash .close { margin-inline-start: auto; background: none; border: 0; cursor: pointer;
  color: inherit; opacity: .6; padding: 0 2px; font-size: 16px; line-height: 1; }
.flash .close:hover { opacity: 1; }

/* ---------------------------------------------------------------- kpi */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 1280px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 980px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 560px) { .kpis { grid-template-columns: minmax(0, 1fr); } }
.kpi {
  position: relative; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: 14px 15px 13px; box-shadow: var(--shadow-1);
  display: flex; flex-direction: column; gap: 4px; min-width: 0;
}
.kpi:hover { border-color: var(--line-strong); text-decoration: none; }
.kpi::before {
  content: ""; position: absolute; inset-inline-start: 0; top: 12px; bottom: 12px; width: 2px;
  background: var(--accent); opacity: .55;
}
.kpi-label { font-size: 10.5px; font-weight: 800; letter-spacing: .09em; text-transform: uppercase;
  color: var(--muted); }
.kpi-value { font-family: var(--mono); font-size: 23px; font-weight: 700; letter-spacing: -.03em;
  line-height: 1.15; font-variant-numeric: tabular-nums; }
.kpi-value small { font-size: 12px; font-weight: 600; color: var(--muted);
  margin-inline-start: 5px; letter-spacing: 0; }
.kpi-foot { font-size: 11.5px; color: var(--muted); display: flex; align-items: center; gap: 5px; }
.kpi-foot .ic { width: 13px; height: 13px; }
[dir="rtl"] .kpi-foot .ic { transform: scaleX(-1); }

/* ---------------------------------------------------------------- bars & progress */
.bars { display: flex; align-items: flex-end; gap: 8px; height: 132px; padding-top: 8px; }
.bar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center;
  gap: 6px; min-width: 0; height: 100%; }
.bar-fill { width: 100%; max-width: 42px; background: var(--accent); border-radius: 2px 2px 0 0;
  min-height: 2px; opacity: .85; transition: height .3s; }
.bar:hover .bar-fill { opacity: 1; }
.bar-label { font-family: var(--mono); font-size: 9.5px; color: var(--muted); white-space: nowrap; }
.bar-value { font-family: var(--mono); font-size: 10.5px; color: var(--ink-2); }
.progress { height: 6px; background: var(--surface-3); border-radius: 99px; overflow: hidden; }
.progress-bar { height: 100%; background: var(--accent); border-radius: 99px; }
.bullet { display: flex; flex-direction: column; gap: 5px; }
.bullet-top { display: flex; justify-content: space-between; gap: 10px; font-size: 12.5px; }
.bullet-top b { font-weight: 600; }
.bullet-top span { font-family: var(--mono); color: var(--muted); }

/* ---------------------------------------------------------------- alerts list */
.feed { display: flex; flex-direction: column; }
.feed-item {
  display: flex; align-items: flex-start; gap: 11px; padding: 11px 14px;
  border-bottom: 1px solid var(--line); font-size: 13px; color: var(--ink-2);
}
.feed-item:last-child { border-bottom: 0; }
.feed-item:hover { background: var(--surface-2); text-decoration: none; color: var(--ink); }
.feed-icon { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  flex: none; background: var(--surface-3); color: var(--ink-2); }
.feed-item.warn .feed-icon { background: var(--warn-soft); color: var(--warn); }
.feed-item.danger .feed-icon { background: var(--danger-soft); color: var(--danger); }
.feed-item.info .feed-icon { background: var(--info-soft); color: var(--info); }
.feed-icon .ic { width: 15px; height: 15px; }

/* ---------------------------------------------------------------- empty state */
.empty {
  display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center;
  padding: 44px 20px; color: var(--muted); border: 1px dashed var(--line-strong);
  border-radius: var(--r-md); margin: 14px; background: var(--surface-2);
}
.empty .ic { width: 26px; height: 26px; color: var(--line-strong); }
.empty b { color: var(--ink-2); font-size: 14px; }
.empty p { font-size: 12.5px; margin: 0; max-width: 46ch; }

/* ---------------------------------------------------------------- pager */
.pager { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--line);
  background: var(--surface-2); font-size: 12px; color: var(--muted); }
.pager .spacer { flex: 1; }
.pager a, .pager span.pg {
  min-width: 30px; height: 30px; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); border-radius: var(--r-xs); background: var(--surface);
  color: var(--ink-2); padding: 0 9px; font-family: var(--mono); font-size: 12px;
}
.pager a:hover { border-color: var(--ink-2); text-decoration: none; }

/* ---------------------------------------------------------------- command palette */
.cmd { position: fixed; inset: 0; z-index: 90; display: grid; place-items: start center;
  padding-top: 12vh; }
.cmd-backdrop { position: absolute; inset: 0; background: rgba(12, 11, 9, .5);
  backdrop-filter: blur(3px); }
.cmd-panel {
  position: relative; width: min(620px, calc(100vw - 32px)); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--r-lg); box-shadow: var(--shadow-2);
  overflow: hidden;
}
.cmd-input { width: 100%; border: 0; border-bottom: 1px solid var(--line); padding: 15px 18px;
  font-size: 15px; background: var(--surface); color: var(--ink); }
.cmd-input:focus { outline: none; }
.cmd-results { max-height: 54vh; overflow-y: auto; padding: 6px; }
.cmd-group { font-size: 10px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase;
  color: var(--muted); padding: 10px 12px 4px; }
.cmd-item { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: var(--r-sm);
  color: var(--ink); font-size: 13.5px; }
.cmd-item:hover, .cmd-item.is-sel { background: var(--surface-3); text-decoration: none; }
.cmd-item .ic { color: var(--muted); width: 16px; height: 16px; }
.cmd-item small { margin-inline-start: auto; color: var(--muted); font-size: 11px; }
.cmd-hint { border-top: 1px solid var(--line); padding: 8px 14px; font-size: 11px; color: var(--muted);
  display: flex; gap: 12px; background: var(--surface-2); }

/* ---------------------------------------------------------------- print documents */
.sheet { background: #fff; color: #191713; width: 100%; margin: 0 auto; }
.sheet.a4 { max-width: 210mm; padding: 12mm 14mm; min-height: 280mm; }
.sheet.a5 { max-width: 148mm; padding: 8mm 10mm; }
.sheet.thermal { width: 74mm; padding: 4mm 3mm; font-size: 11px; }
.sheet-head { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start;
  border-bottom: 2px solid #191713; padding-bottom: 12px; margin-bottom: 14px; }
.sheet-logo { max-height: 54px; margin-bottom: 6px; }
.sheet-company h2 { font-size: 18px; margin-bottom: 2px; }
.sheet-company p { margin: 0; font-size: 11.5px; color: #4a453c; }
.doc-title { text-align: end; }
.doc-title h3 { font-size: 16px; text-transform: uppercase; letter-spacing: .06em; }
.doc-title .doc-no { font-family: var(--mono); font-size: 13px; margin-top: 3px; }
.doc-title .doc-meta { font-size: 11.5px; color: #4a453c; margin-top: 4px; }
.party-bar { display: flex; justify-content: space-between; gap: 20px; border: 1px solid #d8d2c4;
  border-radius: 4px; padding: 9px 11px; margin-bottom: 12px; font-size: 12px; }
.party-bar .k { font-size: 10px; text-transform: uppercase; letter-spacing: .1em; color: #7a7364; }
.items-table { width: 100%; font-size: 12px; margin-bottom: 10px; }
.items-table th { background: #f0ece2; border: 1px solid #d8d2c4; padding: 6px 7px; text-align: start;
  font-size: 10px; text-transform: uppercase; letter-spacing: .06em; }
.items-table td { border: 1px solid #e3ddcf; padding: 6px 7px; }
.items-table td.num { text-align: end; font-family: var(--mono); }
.items-table tfoot td { font-weight: 700; background: #faf8f3; }
.totals { margin-inline-start: auto; width: min(320px, 100%); font-size: 12.5px; margin-top: 8px; }
.totals-row { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px dotted #d8d2c4; }
.totals-row.grand { border-bottom: 2px solid #191713; border-top: 2px solid #191713; margin-top: 2px;
  padding: 6px 0; font-weight: 700; font-size: 14px; }
.totals-row span:last-child { font-family: var(--mono); }
.terms { margin-top: 16px; font-size: 10.5px; color: #4a453c; border-top: 1px solid #e3ddcf;
  padding-top: 8px; }
.signatures { display: flex; justify-content: space-between; gap: 20px; margin-top: 26px; font-size: 11px; }
.signatures div { flex: 1; text-align: center; }
.signatures .line { border-top: 1px solid #191713; margin-top: 30px; padding-top: 4px; }
.print-toolbar { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; padding: 14px; }
.status-stamp { display: inline-block; border: 2px solid #a32828; color: #a32828; padding: 3px 10px;
  border-radius: 3px; font-weight: 800; font-size: 12px; letter-spacing: .08em; transform: rotate(-4deg);
  margin-top: 6px; }
.status-stamp.paid { border-color: #2e6b4f; color: #2e6b4f; }
.status-stamp.credit { border-color: #90620f; color: #90620f; }
.qr-note { font-size: 9px; color: #7a7364; }

/* barcode labels (kept namespaced: .bc-* so they never clash with form .label) */
.labels { display: flex; flex-wrap: wrap; gap: 3mm; padding: 4mm; }
.bc-label {
  border: 1px solid #b9b3a3; border-radius: 3px; text-align: center; padding: 2mm;
  page-break-inside: avoid; break-inside: avoid; background: #fff; color: #000;
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
}
.bc-label.small { width: 50mm; height: 25mm; }
.bc-label.large { width: 70mm; height: 40mm; }
.bc-name { font-size: 9px; font-weight: 700; width: 100%; overflow: hidden; white-space: nowrap;
  text-overflow: ellipsis; }
.bc-price { font-size: 11px; font-weight: 800; font-family: var(--mono); }
.bc-label .bc { max-width: 100%; height: auto; }
.bc-label.large .bc-name { font-size: 11px; }
.bc-label.large .bc-price { font-size: 13px; }

/* ---------------------------------------------------------------- login */
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(420px, 1fr); }
.auth-side {
  background: var(--rail); color: var(--rail-text); padding: 42px 46px;
  display: flex; flex-direction: column; justify-content: space-between; position: relative;
  overflow: hidden;
}
.auth-side::after {
  content: ""; position: absolute; inset-inline-end: -120px; bottom: -120px; width: 340px;
  height: 340px; border: 1px solid var(--rail-line); border-radius: 50%;
}
.auth-brand { display: flex; align-items: center; gap: 12px; }
.auth-brand .brand-mark { width: 42px; height: 42px; font-size: 22px; }
.auth-brand strong { font-size: 18px; color: #fff; display: block; }
.auth-brand em { font-style: normal; font-family: var(--mono); font-size: 11px; color: var(--accent); }
.auth-copy h1 { font-size: clamp(26px, 3vw, 38px); line-height: 1.15; color: #fff; margin-bottom: 12px;
  letter-spacing: -.02em; }
.auth-copy p { color: var(--rail-muted); max-width: 44ch; font-size: 14px; }
.auth-points { list-style: none; padding: 0; margin: 24px 0 0; display: grid; gap: 10px; }
.auth-points li { display: flex; gap: 10px; align-items: center; font-size: 13px; color: var(--rail-text); }
.auth-points .ic { color: var(--accent); width: 16px; height: 16px; }
.auth-foot { font-size: 11px; color: var(--rail-muted); position: relative; z-index: 1; }
.auth-main { display: grid; place-items: center; padding: 34px 22px; background: var(--paper);
  text-align: start; }
[dir="rtl"] .auth-side { order: 2; }
.auth-card { width: min(400px, 100%); }
.auth-card .card-body { padding: 26px; }
.auth-card h2 { font-size: 21px; margin-bottom: 4px; }
.auth-card .sub { color: var(--muted); font-size: 13px; margin-bottom: 20px; }
.auth-lang { display: flex; gap: 6px; margin-bottom: 14px; }
@media (max-width: 900px) {
  .auth { grid-template-columns: minmax(0, 1fr); }
  .auth-side { display: none; }
}

/* ---------------------------------------------------------------- licence strip */
.license-strip {
  display: flex; align-items: center; gap: 10px; margin-bottom: 14px; padding: 9px 12px;
  border: 1px solid color-mix(in srgb, var(--warn) 32%, var(--line));
  background: var(--warn-soft); color: var(--warn); border-radius: var(--r-sm);
  font-size: 12.5px; font-weight: 600;
}
.license-strip .ic { width: 16px; height: 16px; }
.license-strip span { flex: 1; }
.license-strip.is-danger { border-color: color-mix(in srgb, var(--danger) 34%, var(--line));
  background: var(--danger-soft); color: var(--danger); }
.license-strip .btn { --btn-bg: transparent; --btn-fg: currentColor;
  --btn-bd: color-mix(in srgb, currentColor 40%, transparent); height: 27px; font-size: 11.5px; }

/* ---------------------------------------------------------------- arabic typography
   Letter-spacing and uppercase break connected Arabic script, so neutralise them
   for Arabic while keeping the micro-label look in English. */
[lang="ar"] .card-title,
[lang="ar"] .section-label,
[lang="ar"] .kpi-label,
[lang="ar"] .nav-group-label,
[lang="ar"] .table thead th,
[lang="ar"] .doc-title h3,
[lang="ar"] .label {
  letter-spacing: 0;
  text-transform: none;
  font-weight: 700;
}
[lang="ar"] .card-title { font-size: 12.5px; }
[lang="ar"] .section-label, [lang="ar"] .kpi-label { font-size: 11.5px; }
[lang="ar"] .table thead th { font-size: 11.5px; letter-spacing: 0; }
[lang="ar"] .nav-group-label { font-size: 10.5px; letter-spacing: 0; }
[lang="ar"] .page-title { letter-spacing: 0; }

/* ---------------------------------------------------------------- print pages */
.print-body { background: var(--paper); padding: 18px 14px 40px; }
.print-body .sheet {
  background: #fff; color: #191713; border: 1px solid var(--line);
  box-shadow: var(--shadow-2); border-radius: 2px;
}
.print-body .sheet.a4 { padding: 12mm 14mm; }
.print-body .sheet.a5 { padding: 8mm 10mm; }
.print-body .sheet.thermal { padding: 4mm 3mm; }
.print-body .sheet .totals-row { border-bottom-color: #d8d2c4; }
.print-body .sheet .items-table { color: #191713; }

/* ---------------------------------------------------------------- misc */
.hr { height: 1px; background: var(--line); margin: 14px 0; border: 0; }
.dot-sep { color: var(--line-strong); }
.list-plain { list-style: none; margin: 0; padding: 0; }
.list-plain li { display: flex; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--line);
  font-size: 13px; }
.list-plain li:last-child { border-bottom: 0; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; }
.stat-strip { display: flex; gap: 22px; flex-wrap: wrap; }
.stat-strip div { display: flex; flex-direction: column; }
.stat-strip b { font-family: var(--mono); font-size: 18px; }
.stat-strip span { font-size: 11px; color: var(--muted); }
.inline-form { display: inline; }
.mono-sm { font-family: var(--mono); font-size: 12px; }
.flag { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; color: var(--muted); }
.warn-row td { background: var(--danger-soft) !important; }
.clickable { cursor: pointer; }

/* ---------------------------------------------------------------- print */
@media print {
  @page { margin: 8mm; }
  html, body { background: #fff !important; }
  body { font-size: 11px; background-image: none !important; }
  .sidebar, .topbar, .foot, .scrim, .cmd, .print-toolbar, .no-print, .flashes,
  .page-head .page-actions, .toolbar, .pager { display: none !important; }
  .app { display: block; }
  .content { padding: 0 !important; max-width: none !important; }
  .page-head { margin: 0 0 8px !important; }
  .card { border: 0 !important; box-shadow: none !important; }
  .card-head { background: #fff !important; border-bottom: 1px solid #191713 !important; }
  .table thead th { background: #fff !important; }
  .sheet { width: auto !important; padding: 0 !important; max-width: none !important; }
  .label { page-break-inside: avoid; }
  a { color: #191713 !important; text-decoration: none !important; }
  .sheet.a4 { min-height: auto; }
}

/* ---------------------------------------------------------------- line editor */
.lines-wrap { overflow-x: auto; }
.lines { min-width: 760px; }
.lines-head, .line-row {
  display: grid; gap: 8px; align-items: center;
  grid-template-columns: minmax(180px, 2.4fr) 112px 78px 108px 74px 132px 96px 34px;
  padding: 8px 14px;
}
.lines-head { background: var(--surface-2); border-bottom: 1px solid var(--line);
  font-size: 11px; font-weight: 700; color: var(--muted); }
.lines-head span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.line-row { border-bottom: 1px solid var(--line); }
.line-row:last-child { border-bottom: 0; }
.line-row .line-total { text-align: end; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.line-row .input, .line-row .select { min-height: 34px; padding-block: 5px; font-size: 12.5px; }
.line-row .check { min-height: 34px; }
.line-row .check span { display: none; }
@media (max-width: 700px) {
  .lines { min-width: 0; }
  .lines-head { display: none; }
  .line-row { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .line-row > :nth-child(1), .line-row > :nth-child(2) { grid-column: span 2; }
}

/* dark-mode contrast for solid accent buttons */
[data-theme="dark"] .btn-primary { --btn-fg: #17140f; font-weight: 700; }
[data-theme="dark"] .kpi::before { opacity: .8; }

/* two KPI columns on small screens, one only on very narrow phones */
@media (max-width: 560px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 11px 12px; }
  .kpi-value { font-size: 19px; }
  .kpi-label { font-size: 10.5px; }
}
@media (max-width: 420px) {
  .kpis { grid-template-columns: minmax(0, 1fr); }
}

/* password reveal */
.input-group { position: relative; }
.input-group .input { padding-inline-end: 46px; }
.input-group .btn { position: absolute; inset-inline-end: 5px; top: 5px; height: 28px; width: 30px;
  border-color: transparent; background: transparent; color: var(--muted); }
.input-group .btn:hover { color: var(--ink); background: var(--surface-3); }
