:root {
  --bg: #f4f5f3;
  --surface: #ffffff;
  --surface-2: #f8f9f7;
  --border: #e2e5e0;
  --border-strong: #cdd2cb;
  --text: #1d2420;
  --text-2: #56605a;
  --text-3: #8a938d;
  --accent: #0f5f56;
  --accent-2: #0c4d46;
  --accent-soft: #e4f0ee;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;
  --warn: #9a6200;
  --warn-soft: #fdf3e0;
  --ok: #1e7a3c;
  --ok-soft: #e6f4ea;
  --side: #13201c;
  --side-text: #c9d3ce;
  --side-active: #1f332d;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 20, .06), 0 4px 16px rgba(16, 24, 20, .06);
  --font: 'IBM Plex Sans Arabic', system-ui, -apple-system, 'Segoe UI', Tahoma, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.num, td.num, th.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: plaintext; }
[dir=rtl] .num, [dir=rtl] td.num, [dir=rtl] th.num { text-align: left; }
[dir=ltr] .num, [dir=ltr] td.num, [dir=ltr] th.num { text-align: right; }
.muted { color: var(--text-2); }
.small { font-size: 12px; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--text-2); }
.hidden { display: none !important; }

/* ---------- Layout ---------- */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.side {
  background: var(--side); color: var(--side-text);
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column;
}
.brand { padding: 18px 18px 14px; display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 15px; }
.brand .logo { width: 30px; height: 30px; border-radius: 7px; background: var(--accent); display: grid; place-items: center; font-size: 15px; flex-shrink: 0; }
.nav { padding: 6px 10px 20px; flex: 1; }
.nav-group { margin-top: 14px; }
.nav-title { font-size: 11px; font-weight: 600; letter-spacing: .02em; color: #7f8e87; padding: 0 10px 6px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 6px; color: var(--side-text); font-size: 13.5px;
}
.nav a:hover { background: var(--side-active); text-decoration: none; color: #fff; }
.nav a.active { background: var(--side-active); color: #fff; box-shadow: inset -3px 0 0 #3fb3a3; }
[dir=ltr] .nav a.active { box-shadow: inset 3px 0 0 #3fb3a3; }
.nav a svg { width: 17px; height: 17px; flex-shrink: 0; opacity: .8; }
/* module accordion */
.nav-home { margin: 6px 0 8px; }
.mod { margin-bottom: 2px; }
.mod-head {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 8px 10px; border-radius: 6px; border: 0; background: none; cursor: pointer;
  color: var(--side-text); font: inherit; font-size: 13.5px; font-weight: 600; text-align: start;
}
.mod-head:hover { background: var(--side-active); color: #fff; }
.mod-head svg { width: 17px; height: 17px; flex-shrink: 0; opacity: .8; }
.mod-head .chev { width: 15px; height: 15px; margin-inline-start: auto; opacity: .6; transition: transform .15s; transform: rotate(-90deg); }
[dir=rtl] .mod-head .chev { transform: rotate(90deg); }
.mod.open > .mod-head .chev { transform: none; }
.mod.has-active > .mod-head { color: #fff; }
.mod-items { display: none; padding: 2px 0 8px; }
.mod.open > .mod-items { display: block; }
.nav .mod-items a { padding: 7px 10px; padding-inline-start: 37px; font-size: 13px; }
.side-foot { padding: 14px 18px; border-top: 1px solid #22332d; font-size: 12.5px; }
.side-foot .who { color: #fff; font-weight: 600; }
.side-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.side-foot button { margin-top: 8px; background: none; border: 1px solid #33473f; color: var(--side-text); padding: 5px 10px; border-radius: 6px; cursor: pointer; }
.side-foot button:hover { background: var(--side-active); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: none; align-items: center; gap: 10px; padding: 10px 16px;
  background: var(--side); color: #fff; position: sticky; top: 0; z-index: 20;
}
.topbar button { background: none; border: 0; color: #fff; padding: 6px; margin: -6px 0; cursor: pointer; display: inline-flex; min-width: 40px; min-height: 40px; align-items: center; justify-content: center; }
.topbar button svg { width: 24px; height: 24px; flex-shrink: 0; display: block; }
.content { padding: 24px 28px 48px; max-width: 1400px; width: 100%; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { font-size: 20px; margin: 0; font-weight: 700; }
.page-head .sub { color: var(--text-2); font-size: 13px; margin-top: 2px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- Cards / panels ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px; }
.card h2 { font-size: 15px; margin: 0 0 12px; font-weight: 600; }
.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)); }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { padding: 14px 16px; }
.kpi .label { color: var(--text-2); font-size: 12.5px; }
.kpi .value { font-size: 21px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; direction: ltr; }
[dir=rtl] .kpi .value { text-align: right; }
[dir=ltr] .kpi .value { text-align: left; }
.kpi .value.neg { color: var(--danger); }
.kpi a { color: inherit; }

/* ---------- Forms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 14px; border-radius: 6px; border: 1px solid var(--border-strong);
  background: var(--surface); cursor: pointer; font-weight: 500; font-size: 13.5px; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-2); }
.btn-danger { color: var(--danger); border-color: #e6b8b4; }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { padding: 4px 10px; font-size: 12.5px; }
.btn-icon { padding: 5px 8px; }

.form-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px 14px; }
.form-grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.span-all { grid-column: 1 / -1; }
.field label { display: block; font-size: 12.5px; color: var(--text-2); margin-bottom: 4px; font-weight: 500; }
.field .req { color: var(--danger); }
.input, select.input, textarea.input {
  width: 100%; padding: 7px 10px; border: 1px solid var(--border-strong); border-radius: 6px;
  background: var(--surface); min-height: 36px;
}
.input:focus { outline: 2px solid color-mix(in srgb, var(--accent) 35%, transparent); border-color: var(--accent); }
.input[readonly], .input:disabled { background: var(--surface-2); color: var(--text-2); }
[dir=rtl] input.input.num { text-align: left; }
[dir=ltr] input.input.num { text-align: right; }
textarea.input { min-height: 64px; resize: vertical; }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; font-size: 13.5px; }

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.filters .field { min-width: 140px; }
.filters .grow { flex: 1; min-width: 180px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th {
  text-align: start; font-weight: 600; color: var(--text-2); font-size: 12.5px;
  background: var(--surface-2); padding: 9px 12px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.tbl td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tbody tr:hover td { background: #fafbf9; }
.tbl tr.clickable { cursor: pointer; }
.tbl tfoot td { font-weight: 700; background: var(--surface-2); border-top: 1px solid var(--border-strong); }
.tbl .empty { text-align: center; color: var(--text-3); padding: 28px; }
.tbl tr.warn td { background: var(--warn-soft); }

.lines td { padding: 5px 6px; }
.lines .input { min-height: 32px; padding: 5px 8px; }
.lines .c-no { width: 36px; text-align: center; color: var(--text-3); }
.lines .c-item { min-width: 260px; }
.lines .c-n { width: 110px; }
.lines .c-sm { width: 80px; }
.lines .c-tot { width: 130px; }
.lines .c-x { width: 40px; }
.stock-hint { font-size: 11.5px; color: var(--text-3); margin-top: 2px; }
.stock-hint.low { color: var(--danger); }

.totals { margin-inline-start: auto; width: 320px; max-width: 100%; }
.totals .row { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; gap: 10px; }
.totals .row.grand { border-top: 2px solid var(--text); margin-top: 6px; padding-top: 10px; font-size: 17px; font-weight: 700; }
.totals .input { width: 120px; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.b-draft { background: var(--warn-soft); color: var(--warn); }
.b-posted { background: var(--ok-soft); color: var(--ok); }
.b-cancelled { background: var(--danger-soft); color: var(--danger); }
.b-neutral { background: #eef0ed; color: var(--text-2); }

/* ---------- Chart ---------- */
.bars { display: flex; align-items: flex-end; gap: 10px; height: 180px; padding-top: 10px; }
.bar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 6px; min-width: 0; }
.bar .col { width: 100%; max-width: 46px; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; }
.bar .col.neg { background: var(--danger); }
.bar .v { font-size: 11px; color: var(--text-2); font-variant-numeric: tabular-nums; direction: ltr; }
.bar .m { font-size: 11.5px; color: var(--text-2); direction: ltr; }

/* ---------- Auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, #13201c 0%, #1b3a33 100%); }
.auth .card { width: 100%; max-width: 400px; padding: 28px; }
.auth h1 { font-size: 20px; margin: 0 0 4px; }
.auth-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.lang-btn { background: none; border: 1px solid #33473f; color: var(--side-text); padding: 5px 10px; border-radius: 6px; cursor: pointer; font-size: 12.5px; }
.lang-btn.light { border-color: var(--border-strong); color: var(--text); background: var(--surface); flex-shrink: 0; }
.lang-btn.light:hover { background: var(--surface-2); }
.auth .tabs { display: flex; gap: 4px; background: var(--surface-2); border-radius: 7px; padding: 4px; margin: 18px 0; }
.auth .tabs button { flex: 1; border: 0; background: none; padding: 7px; border-radius: 5px; cursor: pointer; font-weight: 500; }
.auth .tabs button.on { background: var(--surface); box-shadow: var(--shadow); }
.auth .field { margin-bottom: 12px; }
.auth .btn { width: 100%; margin-top: 6px; padding: 9px; }
.auth .lang-btn { width: auto; }
.auth .link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; margin-top: 12px; font-size: 13px; }

/* ---------- Modal / toast ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(15, 22, 19, .45); display: grid; place-items: center; z-index: 100; padding: 16px; }
.modal { background: var(--surface); border-radius: 10px; width: 100%; max-width: 640px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.sm { max-width: 420px; }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--border); font-weight: 700; font-size: 16px; display: flex; justify-content: space-between; align-items: center; }
.modal-head button { background: none; border: 0; font-size: 22px; line-height: 1; cursor: pointer; color: var(--text-2); }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-start; }

#toast-root { position: fixed; bottom: 20px; inset-inline-end: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--text); color: #fff; padding: 10px 16px; border-radius: 7px; box-shadow: var(--shadow); max-width: 420px; font-size: 13.5px; animation: tin .18s ease-out; }
.toast.err { background: var(--danger); }
.toast.ok { background: var(--ok); }
@keyframes tin { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

.notice { padding: 10px 14px; border-radius: 7px; background: var(--accent-soft); color: var(--accent-2); font-size: 13.5px; margin-bottom: 14px; }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.err { background: var(--danger-soft); color: var(--danger); }

.doc-meta { display: flex; gap: 22px; flex-wrap: wrap; font-size: 13px; color: var(--text-2); }
.doc-meta b { color: var(--text); font-weight: 600; }

/* ---------- Print ---------- */
#print-root { display: none; }
@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff; font-size: 12px; }
  #app, #modal-root, #toast-root { display: none !important; }
  #print-root { display: block; }
}
.pr { color: #000; font-family: var(--font); }
.pr-head { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 2px solid #000; padding-bottom: 10px; margin-bottom: 14px; gap: 20px; }
.pr-head .co { font-size: 18px; font-weight: 700; }
.pr-head .co-sub { font-size: 11.5px; color: #333; margin-top: 2px; }
.pr-title { text-align: center; font-size: 17px; font-weight: 700; margin: 0 0 12px; }
.pr-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 24px; margin-bottom: 14px; font-size: 12.5px; }
.pr-meta div span { color: #444; }
.pr-sub { font-size: 10.5px; color: #555; margin-top: 2px; }
.pr table { width: 100%; border-collapse: collapse; font-size: 12px; }
.pr th, .pr td { border: 1px solid #555; padding: 5px 7px; text-align: start; }
.pr th { background: #eee; font-weight: 700; }
[dir=rtl] .pr td.num, [dir=rtl] .pr th.num { text-align: left; }
[dir=ltr] .pr td.num, [dir=ltr] .pr th.num { text-align: right; }
.pr-date { text-align: end; }
.pr-totals { width: 280px; margin-inline-start: auto; margin-top: 10px; font-size: 12.5px; }
.pr-totals div { display: flex; justify-content: space-between; padding: 3px 0; }
.pr-totals .g { border-top: 2px solid #000; font-weight: 700; font-size: 14px; padding-top: 6px; }
.pr-sign { display: flex; justify-content: space-between; margin-top: 50px; font-size: 12.5px; }
.pr-sign div { border-top: 1px solid #000; padding-top: 6px; width: 180px; text-align: center; }
.pr-foot { margin-top: 24px; font-size: 11px; color: #444; text-align: center; }
.pr-stamp { display: inline-block; border: 2px solid #b00; color: #b00; padding: 2px 12px; font-weight: 700; margin-inline-start: 10px; font-size: 13px; }

/* ---------- Printed invoice (minimal layout) ---------- */
.pi { --pi-ink: #1b1b1b; --pi-soft: #555; --pi-rule: #9d9d9d;
  --pi-display: 'Italiana', 'Didot', 'Bodoni 72', 'Playfair Display', 'Liberation Serif', Georgia, serif;
  --pi-body: 'Lato', 'Helvetica Neue', Arial, 'Liberation Sans', sans-serif;
  color: var(--pi-ink); font-family: var(--pi-body); font-size: 11.5px; line-height: 1.55;
  min-height: calc(297mm - 24mm - 2px); display: flex; flex-direction: column; padding: 6mm 5mm 0; box-sizing: border-box; }
.pi.pi-ar { --pi-display: var(--font); --pi-body: var(--font); font-size: 12px; }
.pi-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 26px; gap: 20px; }
.pi-logo { width: 82px; height: 82px; display: flex; align-items: center; justify-content: center; }
.pi-logo img { max-width: 100%; max-height: 100%; object-fit: contain; }
.pi-mono { width: 74px; height: 74px; border-radius: 50%; background: #000; color: #fff; display: flex; align-items: center; justify-content: center;
  font-family: var(--pi-display); font-size: 34px; line-height: 1; }
.pi-title { font-family: var(--pi-display); font-size: 50px; line-height: 1; letter-spacing: .02em; font-weight: 400; display: flex; align-items: center; gap: 14px; }
.pi-ar .pi-title { font-weight: 300; font-size: 44px; letter-spacing: 0; }
.pi-stamp { font-family: var(--pi-body); font-size: 12px; font-weight: 700; letter-spacing: .08em; color: #b00; border: 2px solid #b00; padding: 3px 10px; transform: rotate(-6deg); }
.pi-info { display: flex; justify-content: space-between; gap: 30px; margin-bottom: 30px; }
.pi-lbl { font-weight: 700; font-size: 10.5px; letter-spacing: .04em; text-transform: uppercase; margin-bottom: 3px; }
.pi-ar .pi-lbl { font-size: 11.5px; letter-spacing: 0; }
.pi-party { font-weight: 700; font-size: 12.5px; }
.pi-sub { color: var(--pi-soft); font-size: 10px; }
.pi-ltr { text-align: start; unicode-bidi: plaintext; }
.pi-doc { text-align: end; }
.pi-doc span { color: var(--pi-soft); }
.pi-no { font-size: 14px; margin-bottom: 2px; }
.pi-no b { font-weight: 400; }
.pi table.pi-tbl { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 11.5px; }
.pi .pi-tbl th, .pi .pi-tbl td { border: 0; border-bottom: 1px solid var(--pi-rule); padding: 9px 6px; background: none; vertical-align: middle; }
.pi .pi-tbl thead th { border-top: 1px solid var(--pi-ink); border-bottom: 1px solid var(--pi-ink); font-weight: 700; font-size: 11px; }
.pi .pi-tbl .pi-n { text-align: center; color: var(--pi-soft); }
.pi .pi-tbl .pi-it { text-align: start; overflow-wrap: anywhere; }
.pi .pi-tbl .pi-c { text-align: center; white-space: nowrap; }
.pi .pi-tbl .pi-b { font-weight: 700; }
.pi .pi-tbl tbody tr { break-inside: avoid; }
.pi-sum { display: flex; justify-content: space-between; align-items: flex-start; gap: 28px; margin-top: 4px; break-inside: avoid; }
.pi-left { flex: 1; padding-top: 12px; min-width: 0; }
.pi-words { font-style: italic; margin-bottom: 16px; }
.pi-ar .pi-words { font-style: normal; }
.pi-bal-row { display: flex; border: 1px solid var(--pi-rule); }
.pi-bal-row > div { flex: 1; padding: 6px 10px; display: flex; flex-direction: column; gap: 1px; }
.pi-bal-row > div + div { border-inline-start: 1px solid var(--pi-rule); }
.pi-bal-row span { color: var(--pi-soft); font-size: 10px; }
.pi-bal-row b { font-size: 12.5px; white-space: nowrap; }
.pi-bal-new { background: #f1f1ee; }
.pi-totals { width: 36%; min-width: 230px; }
.pi-totals > div { display: flex; justify-content: space-between; padding: 8px 6px; border-bottom: 1px solid var(--pi-rule); }
.pi-totals > div span { font-weight: 700; font-size: 11px; }
.pi-totals > div b { font-weight: 400; white-space: nowrap; }
.pi-totals .pi-grand { border-bottom: 0; border-top: 1px solid var(--pi-ink); margin-top: -1px; padding-top: 14px; align-items: center; }
.pi-totals .pi-grand span { font-size: 17px; }
.pi-totals .pi-grand b { font-size: 21px; }
.pi-notes { margin-top: 18px; font-size: 11px; }
.pi-totals b, .pi-bal-row b, .pi .pi-tbl td.pi-c { direction: ltr; unicode-bidi: isolate; }
.pi-totals .pi-grand { gap: 12px; }
.pi-ar .pi-totals .pi-grand span { font-size: 15px; }
.pi-ar .pi-totals { width: 40%; }
.pi-foot { margin-top: auto; padding-top: 34px; break-inside: avoid; }
.pi-thanks { font-size: 17px; margin-bottom: 26px; }
.pi-bottom { display: flex; justify-content: space-between; align-items: flex-end; gap: 30px; padding-bottom: 2mm; }
.pi-pay { font-size: 10.5px; }
.pi-co { text-align: end; font-size: 10px; color: #333; }
.pi-coname { font-family: var(--pi-display); font-size: 22px; color: var(--pi-ink); line-height: 1.2; margin-bottom: 2px; }
.pi-ar .pi-coname { font-weight: 600; font-size: 19px; }

/* settings: logo preview */
.logo-edit { display: flex; gap: 16px; align-items: center; }
.logo-prev { width: 96px; height: 96px; border: 1px dashed var(--border); border-radius: 10px; display: flex; align-items: center; justify-content: center; padding: 6px; text-align: center; }
.logo-prev img { max-width: 100%; max-height: 100%; object-fit: contain; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .content { min-width: 0; }
  .side { position: fixed; inset: 0 0 0 auto; width: 260px; z-index: 50; transform: translateX(100%); transition: transform .2s; }
  [dir=ltr] .side { inset: 0 auto 0 0; transform: translateX(-100%); }
  [dir=ltr] .shell.nav-open .side { transform: none; }
  .shell.nav-open .side { transform: none; }
  .shell.nav-open::after { content: ''; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 40; }
  .topbar { display: flex; }
  .content { padding: 16px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .form-grid, .form-grid.cols-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 520px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi .label { overflow-wrap: anywhere; }
  .kpi .value { font-size: 17px; }
  .form-grid, .form-grid.cols-2, .form-grid.cols-3 { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .totals { width: 100%; }
}

/* ---------- Tasks & KPIs ---------- */
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-ok:hover { background: #17622f; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 7px; padding: 3px; align-self: flex-end; flex-wrap: wrap; max-width: 100%; }
.seg button { border: 0; background: none; padding: 6px 14px; border-radius: 5px; cursor: pointer; font-weight: 500; color: var(--text-2); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.pr-low { background: #eef0ed; color: var(--text-2); }
.pr-normal { background: #e8eef7; color: #2d5a8c; }
.pr-high { background: var(--warn-soft); color: var(--warn); }
.pr-urgent { background: var(--danger-soft); color: var(--danger); }
.ts-todo { background: #eef0ed; color: var(--text-2); }
.ts-in_progress { background: var(--accent-soft); color: var(--accent-2); }
.ts-paused { background: var(--warn-soft); color: var(--warn); }
.ts-done { background: var(--ok-soft); color: var(--ok); }
.ts-cancelled { background: var(--danger-soft); color: var(--danger); }
.band-ex { background: var(--ok-soft); color: var(--ok); }
.band-good { background: var(--accent-soft); color: var(--accent-2); }
.band-fair { background: var(--warn-soft); color: var(--warn); }
.band-poor { background: var(--danger-soft); color: var(--danger); }
.neg { color: var(--danger); }
.tbl tr.row-live td { background: #f1f8f6; }
.live { color: var(--accent); font-variant-numeric: tabular-nums; }
.stars { color: #d99a00; letter-spacing: 1px; white-space: nowrap; }
.stars .off { color: #d9ddd7; }
.stars-input { display: inline-flex; gap: 2px; }
.stars-input button { border: 0; background: none; font-size: 26px; line-height: 1; color: #d9ddd7; cursor: pointer; padding: 0 2px; }
.stars-input button.on { color: #d99a00; }

.now-card { display: flex; align-items: center; gap: 16px; padding: 14px 18px; margin-bottom: 14px; border-radius: var(--radius);
  background: linear-gradient(135deg, #0f5f56, #13423c); color: #fff; box-shadow: var(--shadow); flex-wrap: wrap; }
.now-card .muted { color: #b9d6d0; }
.now-dot { width: 10px; height: 10px; border-radius: 50%; background: #5fe0b5; box-shadow: 0 0 0 0 rgba(95,224,181,.7); animation: pulse 1.6s infinite; flex-shrink: 0; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(95,224,181,.6); } 70% { box-shadow: 0 0 0 10px rgba(95,224,181,0); } 100% { box-shadow: 0 0 0 0 rgba(95,224,181,0); } }
.now-body { flex: 1; min-width: 160px; }
.now-title { font-weight: 700; font-size: 16px; }
.now-time { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; direction: ltr; }
.now-card .btn { background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.25); color: #fff; }
.now-card .btn-ok { background: #fff; color: var(--accent-2); border-color: #fff; }

.meta-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 18px; font-size: 13.5px; }
.detail-block { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.pre { white-space: pre-wrap; margin-top: 4px; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 6px 0 6px 0; padding-inline-start: 16px; border-inline-start: 2px solid var(--border); position: relative; font-size: 13.5px; }
.timeline li::before { content: ''; position: absolute; inset-inline-start: -5px; top: 11px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }

.kbar { height: 8px; background: #eceee9; border-radius: 99px; overflow: hidden; margin-bottom: 3px; }
.kbar span { display: block; height: 100%; border-radius: 99px; }
.kbar .ok { background: var(--ok); }
.kbar .mid { background: #d99a00; }
.kbar .low { background: var(--danger); }
.score-head { display: flex; gap: 22px; align-items: center; flex-wrap: wrap; }
.score-ring { width: 120px; height: 120px; border-radius: 50%; display: grid; place-content: center; text-align: center; flex-shrink: 0; border: 8px solid currentColor; }
.score-ring.b-neutral { color: #cdd2cb; }
.score-ring .v { font-size: 24px; font-weight: 700; color: var(--text); direction: ltr; }
.score-ring .l { font-size: 11.5px; color: var(--text-2); }
.score-ring.band-ex, .score-ring.band-good, .score-ring.band-fair, .score-ring.band-poor { background: none; }
.score-info { flex: 1; min-width: 220px; }
.score-info .who { font-size: 18px; font-weight: 700; }
.mini-stats { display: flex; gap: 18px; flex-wrap: wrap; margin-top: 12px; }
.mini-stats div, .m-stats div { display: flex; flex-direction: column; }
.mini-stats b, .m-stats b { font-size: 17px; font-variant-numeric: tabular-nums; }
.mini-stats span, .m-stats span { font-size: 11.5px; color: var(--text-2); }

.team-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.member { padding: 16px; display: flex; flex-direction: column; gap: 12px; border-top: 3px solid #cdd2cb; }
.member.working { border-top-color: var(--accent); }
.m-head { display: flex; align-items: center; gap: 10px; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-2); display: grid; place-items: center; font-weight: 700; flex-shrink: 0; }
.m-name { flex: 1; min-width: 0; }
.state { font-size: 11.5px; font-weight: 600; padding: 2px 9px; border-radius: 99px; background: #eef0ed; color: var(--text-2); white-space: nowrap; }
.state.on { background: var(--accent-soft); color: var(--accent-2); }
.m-now { background: var(--surface-2); border-radius: 7px; padding: 10px 12px; min-height: 64px; }
.m-task { font-weight: 600; display: block; margin-top: 2px; }
.m-clock { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--accent); direction: ltr; text-align: start; }
[dir=rtl] .m-clock { text-align: right; }
.m-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.m-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; }
.m-actions { display: flex; gap: 6px; }
@media (max-width: 520px) { .meta-grid { grid-template-columns: 1fr; } .m-stats { grid-template-columns: repeat(2, 1fr); } }
.m-stats b, .mini-stats b { white-space: nowrap; }
.m-stats b { font-size: 15px; }
.tbl td.num { white-space: nowrap; }
.now-card { flex-direction: column; align-items: stretch; gap: 10px; }
.now-head { display: flex; align-items: center; gap: 10px; }
.now-item { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; padding-top: 10px; border-top: 1px solid rgba(255,255,255,.15); }
.now-step { font-size: 13px; color: #d9ece8; margin-top: 2px; }
.step-line { font-size: 12.5px; color: var(--text-2); margin-top: 3px; }
.m-cur { padding: 6px 0; border-bottom: 1px dashed var(--border); }
.m-cur:last-child { border-bottom: 0; }
.m-cur-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.m-cur .m-clock { font-size: 15px; flex-shrink: 0; }
.m-step { font-size: 12.5px; color: var(--text-2); margin-top: 2px; }
.m-cur-right { display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0; }
.m-cur-right .btn-icon { padding: 2px 7px; font-size: 11px; }

/* ---------- CRM ---------- */
.cs-new { background: #eef0ed; color: var(--text-2); }
.cs-contacted { background: #e8eef7; color: #2d5a8c; }
.cs-interested { background: var(--accent-soft); color: var(--accent-2); }
.cs-quote { background: var(--warn-soft); color: var(--warn); }
.cs-won { background: var(--ok-soft); color: var(--ok); }
.cs-lost { background: var(--danger-soft); color: var(--danger); }
.due-over { background: var(--danger-soft); color: var(--danger); }
.due-today { background: var(--warn-soft); color: var(--warn); }
.due-later { background: #eef0ed; color: var(--text-2); }
.ak { background: #eef0ed; color: var(--text-2); font-weight: 600; }
.ak-call, .ak-whatsapp { background: var(--ok-soft); color: var(--ok); }
.ak-visit, .ak-meeting { background: var(--accent-soft); color: var(--accent-2); }
.ak-message, .ak-email { background: #e8eef7; color: #2d5a8c; }
.ak-stage { background: var(--warn-soft); color: var(--warn); }
.board { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; align-items: start; }
.board-col { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; min-height: 120px; }
.board-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.board-empty { text-align: center; padding: 16px 0; }
.lead-card { padding: 10px 12px; margin-bottom: 8px; box-shadow: none; }
.lead-title { font-weight: 600; color: var(--text); display: block; }
.lead-title:hover { color: var(--accent); }
.lead-foot { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.lead-move { margin-inline-start: auto; display: inline-flex; gap: 4px; }
.lead-move .btn-icon { padding: 2px 9px; font-size: 15px; line-height: 1.1; }
.stepper { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.stepper .step { border: 1px solid var(--border-strong); background: var(--surface); border-radius: 999px; padding: 6px 14px; font: inherit; font-size: 13px; cursor: pointer; color: var(--text-2); }
.stepper .step:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.stepper .step.done { background: var(--accent-soft); border-color: transparent; color: var(--accent-2); }
.stepper .step.cur { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.stepper .step:disabled { cursor: default; }
.info-rows > div { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 7px 0; border-bottom: 1px dashed var(--border); font-size: 13.5px; }
.info-rows > div:last-child { border-bottom: 0; }
.info-rows span { color: var(--text-2); }
.linkbtn { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font: inherit; font-size: 12px; }
.crm-tl li { padding-bottom: 10px; }
.tl-next { margin-top: 3px; color: var(--text-2); }
.tl-stage { color: var(--text-2); }
@media (max-width: 1100px) { .board { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 520px) { .board { grid-template-columns: 1fr; } }

/* ---------- Online store ---------- */
.badge.b-online { background: #e6f0ec; color: #1f6b4f; }
.notice.shop-notice { border-inline-start: 3px solid #1f6b4f; }
.pi-cat { display: inline-block; font-size: 9.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  border: 1px solid var(--pi-ink); padding: 1px 7px; margin: 1px 0 4px; }
.pi-ar .pi-cat { font-size: 10.5px; letter-spacing: 0; }
.btn.btn-wa { background: #1f8f4e; border-color: #1f8f4e; color: #fff; }
.btn.btn-wa:hover { background: #197a42; }
.tbl.tbl-compact { font-size: 12.5px; }
.tbl.tbl-compact th, .tbl.tbl-compact td { padding-inline: 8px; white-space: nowrap; }

/* batches & expiry */
.batch-row { display: flex; gap: 6px; margin-top: 4px; }
.batch-row .input-sm, .input-sm { height: 30px; padding: 4px 8px; font-size: 12.5px; }
.batch-row input[data-f=batch_no] { flex: 1 1 55%; min-width: 0; }
.batch-row input[type=date] { flex: 1 1 45%; min-width: 0; }
.batch-row select { flex: 1; min-width: 0; }
.line-batch { font-size: 11.5px; color: var(--text-3); margin-top: 2px; }
.badge.exp-over { background: #fde8e8; color: #b42318; }
.badge.exp-soon { background: #fff1e0; color: #b54708; }
.badge.exp-mid { background: #fef9e0; color: #8a6d00; }
.badge.exp-ok { background: #e8f5ec; color: #1f7a3d; }
.pi-batch { font-size: 10.5px; color: #666; margin-top: 2px; }
/* reorder planning */
.badge.ro-out { background: #fde8e8; color: #b42318; }
.badge.ro-order_now { background: #fff1e0; color: #b54708; }
.badge.ro-soon { background: #fef9e0; color: #8a6d00; }
.badge.ro-ok { background: #e8f5ec; color: #1f7a3d; }
.badge.ro-no_sales { background: var(--surface-2); color: var(--text-3); }
.trend { font-size: 12px; white-space: nowrap; color: var(--text-2); }
.trend.up { color: #1f7a3d; }
.trend.down { color: #b42318; }
/* price lists */
.price-grid td .input-sm { width: 96px; text-align: end; }
.input.dirty { border-color: var(--accent); background: var(--accent-soft); }
/* aging */
.age-0 { color: var(--text-2); }
.age-3, .age-4 { color: var(--danger); font-weight: 600; }
.pl-tbl td.lbl { white-space: nowrap; }
.pl-tbl tr.pl-sum td { font-weight: 700; border-top: 2px solid var(--border); }
.pl-tbl tr.pl-net td { font-weight: 700; font-size: 15px; background: var(--surface-2); }
.pl-tbl tr.pl-sub td.lbl { padding-inline-start: 28px; color: var(--text-2); }
.pl-tbl td.neg { color: var(--danger); }
.neg-amt { color: var(--ok); }
.exp-bars { display: grid; gap: 8px; max-width: 720px; }
.exp-bar { display: grid; grid-template-columns: minmax(120px, 190px) 1fr 110px 40px; gap: 10px; align-items: center; font-size: 13px; }
.exp-bar .track { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.exp-bar .track span { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
@media (max-width: 640px) { .exp-bar { grid-template-columns: 1fr 90px; } .exp-bar .track, .exp-bar .small { display: none; } }
.nowrap { white-space: nowrap; }
.row-actions { display: flex; flex-direction: column; gap: 4px; align-items: stretch; }
.row-actions .btn { justify-content: center; white-space: nowrap; }
/* import */
.imp-drop { margin-top: 16px; border: 2px dashed var(--border); border-radius: 10px; padding: 26px 16px; text-align: center; display: grid; gap: 6px; justify-items: center; background: var(--surface-2); }
.imp-drop.over { border-color: var(--accent); background: var(--accent-soft); }
.imp-drop .btn { margin-top: 6px; }
.imp-cols { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 6px; }
.badge.b-pack { background: #eef0ff; color: #3b3fa8; }
.tbl tr.clickable:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
