/* =========================================================================
   GST Billing – design system, layout, components and print styles.
   Colours are tokens on :root; dark mode re-defines them. --brand is set
   per company at runtime (Settings → Business profile → Brand colour).
   ========================================================================= */
:root {
  color-scheme: light;
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --surface-3: #eef0f4;
  --line: #e3e6ec;
  --line-2: #d3d8e0;
  --ink: #0f172a;
  --ink-2: #445166;
  --muted: #627084;
  --brand: #3348c6;
  --brand-ink: #ffffff;
  --brand-soft: color-mix(in srgb, var(--brand) 10%, transparent);
  --brand-line: color-mix(in srgb, var(--brand) 35%, transparent);
  --brand-text: var(--brand);
  --ok: #15803d;   --ok-bg: #ecfdf3;
  --warn: #a15c07; --warn-bg: #fff8e6;
  --bad: #b91c1c;  --bad-bg: #fef2f2;
  --info: #1d4ed8; --info-bg: #eff6ff;
  --status-good: #0ca30c; --status-warning: #fab219; --status-serious: #ec835a; --status-critical: #d03b3b;
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a;
  --grid: #e7e8ec; --axis: #c3c2b7;
  --radius: 12px; --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 1px 3px rgba(15, 23, 42, .04);
  --shadow-lg: 0 18px 48px rgba(15, 23, 42, .22);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sidebar: 252px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d0f12; --surface: #16191d; --surface-2: #1b1f24; --surface-3: #232830;
    --line: #2a3038; --line-2: #39404a;
    --ink: #eef1f5; --ink-2: #bcc4ce; --muted: #929ca8;
    --brand-soft: color-mix(in srgb, var(--brand) 24%, transparent);
    --brand-line: color-mix(in srgb, var(--brand) 55%, transparent);
    --brand-text: color-mix(in srgb, var(--brand) 55%, #ffffff);
    --ok: #4ade80; --ok-bg: rgba(34, 197, 94, .13);
    --warn: #fbbf24; --warn-bg: rgba(245, 158, 11, .13);
    --bad: #f87171; --bad-bg: rgba(239, 68, 68, .13);
    --info: #93c5fd; --info-bg: rgba(59, 130, 246, .14);
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
    --grid: #2a2f36; --axis: #3c424b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-lg: 0 18px 48px rgba(0, 0, 0, .6);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d0f12; --surface: #16191d; --surface-2: #1b1f24; --surface-3: #232830;
  --line: #2a3038; --line-2: #39404a;
  --ink: #eef1f5; --ink-2: #bcc4ce; --muted: #929ca8;
  --brand-soft: color-mix(in srgb, var(--brand) 24%, transparent);
  --brand-line: color-mix(in srgb, var(--brand) 55%, transparent);
  --brand-text: color-mix(in srgb, var(--brand) 55%, #ffffff);
  --ok: #4ade80; --ok-bg: rgba(34, 197, 94, .13);
  --warn: #fbbf24; --warn-bg: rgba(245, 158, 11, .13);
  --bad: #f87171; --bad-bg: rgba(239, 68, 68, .13);
  --info: #93c5fd; --info-bg: rgba(59, 130, 246, .14);
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
  --grid: #2a2f36; --axis: #3c424b;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-lg: 0 18px 48px rgba(0, 0, 0, .6);
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 var(--font); }
a { color: var(--brand-text); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 17px; font-weight: 650; }
h3 { font-size: 15px; font-weight: 650; }
p { margin: 0 0 10px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
img { max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.sr-only { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.num, .r { text-align: right; font-variant-numeric: tabular-nums; }
.c { text-align: center; }
.nowrap { white-space: nowrap; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.pos { color: var(--ok); }
.neg { color: var(--bad); }
.hidden, [hidden] { display: none !important; }
.spacer { flex: 1; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.span-all { grid-column: 1 / -1; }
@media (max-width: 900px) { .g3, .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 560px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } .span-2 { grid-column: auto; } }

/* ---------- app shell ---------- */
.app { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; overflow-y: auto; background: var(--surface); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; }
.sb-brand { display: flex; align-items: center; gap: 10px; padding: 16px 16px 12px; border-bottom: 1px solid var(--line); }
.sb-logo { width: 38px; height: 38px; border-radius: 10px; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center;
  font-weight: 800; font-size: 15px; flex: none; overflow: hidden; }
.sb-logo img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.sb-name { font-weight: 700; font-size: 14.5px; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.sb-sub { font-size: 11.5px; color: var(--muted); }
.nav { padding: 10px 8px 16px; display: flex; flex-direction: column; gap: 1px; }
.nav-sec { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 14px 10px 6px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--ink-2); font-weight: 520; }
.nav a:hover { background: var(--surface-3); color: var(--ink); text-decoration: none; }
.nav a.active { background: var(--brand-soft); color: var(--brand-text); font-weight: 650; }
.nav svg { width: 18px; height: 18px; flex: none; }
.sb-foot { margin-top: auto; padding: 12px 16px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 30; height: 58px; display: flex; align-items: center; gap: 10px; padding: 0 22px;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: saturate(1.4) blur(10px); border-bottom: 1px solid var(--line); }
.topbar .title { font-weight: 650; font-size: 15.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 0 1 auto; }
.topbar > .btn { flex: none; }
.menu-btn { display: none; }
.content { width: 100%; max-width: 1340px; margin: 0 auto; padding: 22px; }
.banner { padding: 10px 22px; font-size: 13.5px; display: flex; gap: 10px; align-items: center; border-bottom: 1px solid var(--line); }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner.bad { background: var(--bad-bg); color: var(--bad); }
.banner.info { background: var(--info-bg); color: var(--info); }
.scrim { display: none; }
@media (max-width: 980px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; z-index: 60; left: 0; top: 0; bottom: 0; width: 280px; transform: translateX(-102%); transition: transform .22s ease; box-shadow: var(--shadow-lg); }
  .app.nav-open .sidebar { transform: none; }
  .app.nav-open .scrim { display: block; position: fixed; inset: 0; z-index: 55; background: rgba(2, 6, 23, .45); }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 0 12px; }
  .content { padding: 16px; }
  .banner { padding: 10px 16px; }
}

/* ---------- page header ---------- */
.page-head { display: flex; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head .sub { color: var(--muted); margin-top: 3px; font-size: 13px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-size: 13px; margin-bottom: 6px; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 38px; padding: 0 14px; border-radius: 9px;
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink); font-weight: 600; font-size: 13.5px; cursor: pointer;
  white-space: nowrap; text-decoration: none; transition: background .12s, border-color .12s, box-shadow .12s; }
.btn:hover { background: var(--surface-3); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 17px; height: 17px; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { background: color-mix(in srgb, var(--brand) 88%, #000); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line-2)); }
.btn.danger:hover { background: var(--bad-bg); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-3); }
.btn.sm { height: 32px; padding: 0 10px; font-size: 12.5px; border-radius: 8px; }
.btn.icon { width: 38px; padding: 0; }
.btn.sm.icon { width: 32px; }
.btn.block { width: 100%; }
.btn.busy { position: relative; color: transparent !important; pointer-events: none; }
.btn.busy::after { content: ""; position: absolute; width: 16px; height: 16px; border: 2px solid currentColor; border-radius: 50%;
  border-color: var(--muted) transparent var(--muted) transparent; animation: spin .8s linear infinite; }
.btn.primary.busy::after { border-color: var(--brand-ink) transparent var(--brand-ink) transparent; }
@keyframes spin { to { transform: rotate(360deg); } }
.link-btn { background: none; border: 0; padding: 0; color: var(--brand-text); font-weight: 600; cursor: pointer; }
.link-btn:hover { text-decoration: underline; }

/* ---------- form controls ---------- */
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label, .label { font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.field .hint { font-size: 12px; color: var(--muted); }
.field .err-msg { font-size: 12px; color: var(--bad); font-weight: 600; }
.input, .select, .textarea, .field input:not([type=checkbox]):not([type=radio]):not([type=color]), .field select, .field textarea {
  width: 100%; height: 38px; padding: 0 11px; border: 1px solid var(--line-2); border-radius: 9px; background: var(--surface); color: var(--ink);
  outline: none; transition: border-color .12s, box-shadow .12s; }
.field textarea, .textarea { height: auto; min-height: 70px; padding: 9px 11px; resize: vertical; line-height: 1.4; }
.input:focus, .select:focus, .textarea:focus, .field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.invalid, .field .invalid { border-color: var(--bad) !important; box-shadow: 0 0 0 3px var(--bad-bg) !important; }
input[type=date] { min-width: 0; }
input::placeholder, textarea::placeholder { color: color-mix(in srgb, var(--muted) 75%, transparent); }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 520; user-select: none; }
.check input { width: 16px; height: 16px; accent-color: var(--brand); margin: 0; }
.input-group { display: flex; align-items: stretch; }
.input-group > .addon { display: grid; place-items: center; padding: 0 10px; border: 1px solid var(--line-2); border-right: 0; background: var(--surface-2);
  border-radius: 9px 0 0 9px; color: var(--muted); font-weight: 600; font-size: 13px; white-space: nowrap; max-width: 55%; overflow: hidden; }
.input-group > input { border-radius: 0 9px 9px 0 !important; min-width: 0; }
.seg { display: inline-flex; padding: 3px; background: var(--surface-3); border-radius: 10px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; font-weight: 600; font-size: 13px; color: var(--ink-2); cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

/* ---------- cards, tiles ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.card-head h2, .card-head h3 { font-size: 15px; }
.card-body { padding: 16px 18px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); min-width: 0; }
.tile .t-label { font-size: 12.5px; color: var(--muted); font-weight: 600; display: flex; align-items: center; gap: 6px; }
.tile .t-value { font-size: 22px; font-weight: 700; margin-top: 4px; letter-spacing: -.01em; overflow-wrap: anywhere; }
.tile .t-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.tile.link { cursor: pointer; }
.tile.link:hover { border-color: var(--brand-line); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.t { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.t th { text-align: left; font-size: 12px; font-weight: 650; color: var(--muted); text-transform: none; padding: 10px 12px; border-bottom: 1px solid var(--line);
  background: var(--surface-2); white-space: nowrap; position: sticky; top: 0; }
table.t td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.t tbody tr:last-child td { border-bottom: 0; }
table.t tr.click { cursor: pointer; }
table.t tr.click:hover td { background: var(--surface-2); }
table.t tfoot td { font-weight: 700; background: var(--surface-2); border-top: 1px solid var(--line); border-bottom: 0; }
table.t td.r, table.t th.r { text-align: right; }
table.t .strong { font-weight: 650; }
table.t .sub { display: block; font-size: 12px; color: var(--muted); }
.cell-actions { display: flex; gap: 4px; justify-content: flex-end; }
.empty { padding: 42px 20px; text-align: center; color: var(--muted); }
.empty svg { width: 42px; height: 42px; opacity: .55; margin-bottom: 8px; }
.empty .e-title { font-weight: 650; color: var(--ink); font-size: 15px; margin-bottom: 4px; }
.more-row { padding: 12px; text-align: center; border-top: 1px solid var(--line); }

/* ---------- badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 9px; border-radius: 999px; font-size: 12px; font-weight: 650;
  background: var(--surface-3); color: var(--ink-2); white-space: nowrap; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: .9; }
.badge.plain::before { display: none; }
.badge.paid, .badge.good { background: var(--ok-bg); color: var(--ok); }
.badge.paid::before, .badge.good::before { background: var(--status-good); }
.badge.partial, .badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.partial::before, .badge.warn::before { background: var(--status-warning); }
.badge.unpaid { background: var(--surface-3); color: var(--ink-2); }
.badge.unpaid::before { background: var(--status-serious); }
.badge.overdue, .badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.overdue::before, .badge.bad::before { background: var(--status-critical); }
.badge.cancelled { background: var(--surface-3); color: var(--muted); text-decoration: line-through; }
.badge.cancelled::before { background: var(--muted); }
.badge.converted, .badge.info { background: var(--info-bg); color: var(--info); }
.badge.active::before { background: var(--status-good); }

/* ---------- filters bar & tabs ---------- */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.filters .input, .filters .select { width: auto; height: 36px; }
.filters .search { flex: 1 1 220px; max-width: 340px; }
.filters input[type=date] { width: 150px; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs a, .tabs button { padding: 10px 14px; border: 0; background: none; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent;
  margin-bottom: -1px; cursor: pointer; white-space: nowrap; display: inline-flex; gap: 6px; align-items: center; }
.tabs a:hover, .tabs button:hover { color: var(--ink); text-decoration: none; }
.tabs .on { color: var(--brand-text); border-bottom-color: var(--brand); }
.count { display: inline-grid; place-items: center; min-width: 20px; height: 18px; padding: 0 6px; border-radius: 999px; background: var(--surface-3);
  font-size: 11px; color: var(--ink-2); }

/* ---------- modal, toast, menus ---------- */
.modal-wrap { position: fixed; inset: 0; z-index: 100; background: rgba(2, 6, 23, .5); display: flex; align-items: flex-start; justify-content: center;
  padding: 5vh 16px; overflow-y: auto; animation: fade .12s ease; }
.modal { background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg); width: 100%; max-width: 560px; border: 1px solid var(--line);
  display: flex; flex-direction: column; animation: pop .14s ease; }
.modal.lg { max-width: 820px; }
.modal.xl { max-width: 1060px; }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 16.5px; }
.modal-body { padding: 18px 20px; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--line); background: var(--surface-2);
  border-radius: 0 0 16px 16px; flex-wrap: wrap; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: translateY(8px) scale(.985); opacity: 0; } }
.toasts { position: fixed; z-index: 200; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--ink); color: var(--surface); padding: 11px 14px; border-radius: 10px; box-shadow: var(--shadow-lg); font-weight: 550;
  display: flex; gap: 10px; align-items: flex-start; animation: pop .16s ease; }
.toast.error { background: #b91c1c; color: #fff; }
.toast.ok { background: #14532d; color: #fff; }
.menu { position: absolute; z-index: 90; min-width: 200px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-lg);
  padding: 6px; }
.menu button, .menu a { display: flex; width: 100%; align-items: center; gap: 9px; text-align: left; padding: 8px 10px; border: 0; background: none;
  border-radius: 8px; cursor: pointer; color: var(--ink); font-weight: 520; }
.menu button:hover, .menu a:hover { background: var(--surface-3); text-decoration: none; }
.menu .danger { color: var(--bad); }
.menu hr { margin: 5px 0; }
.menu svg { width: 16px; height: 16px; }

/* ---------- autocomplete ---------- */
.ac { position: relative; }
.ac-list { position: absolute; z-index: 80; left: 0; right: 0; top: calc(100% + 4px); background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: var(--shadow-lg); max-height: 300px; overflow-y: auto; padding: 4px; min-width: 260px; }
.ac-item { padding: 8px 10px; border-radius: 7px; cursor: pointer; display: flex; gap: 10px; align-items: center; }
.ac-item.on, .ac-item:hover { background: var(--brand-soft); }
.ac-item .ac-main { flex: 1; min-width: 0; }
.ac-item .ac-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ac-item .ac-sub { font-size: 12px; color: var(--muted); }
.ac-item .ac-side { font-size: 12.5px; color: var(--ink-2); text-align: right; white-space: nowrap; }
.ac-foot { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 4px; }
.ac-empty { padding: 10px; color: var(--muted); font-size: 13px; }

/* ---------- auth screens ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(1200px 500px at 10% -10%, var(--brand-soft), transparent 60%), var(--bg); }
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow-lg); padding: 28px; }
.auth-card.wide { max-width: 560px; }
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.auth-brand .sb-logo { width: 46px; height: 46px; font-size: 18px; border-radius: 12px; }
.auth-title { font-size: 21px; font-weight: 750; }
.auth .stack { gap: 14px; }
.auth-foot { margin-top: 18px; text-align: center; color: var(--muted); font-size: 13px; }
.alert { padding: 10px 12px; border-radius: 10px; font-size: 13.5px; font-weight: 550; }
.alert.bad { background: var(--bad-bg); color: var(--bad); }
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.alert.info { background: var(--info-bg); color: var(--info); }
.alert.ok { background: var(--ok-bg); color: var(--ok); }

/* ---------- dashboard ---------- */
.dash-grid { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); gap: 16px; }
@media (max-width: 1100px) { .dash-grid { grid-template-columns: minmax(0, 1fr); } }
.quick { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.chart-wrap { position: relative; padding: 8px 14px 6px; }
.chart-wrap svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-legend { display: flex; gap: 16px; flex-wrap: wrap; padding: 0 18px 4px; font-size: 12.5px; color: var(--ink-2); }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.chart-tip { position: absolute; pointer-events: none; z-index: 5; background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow-lg); padding: 8px 10px; font-size: 12.5px; min-width: 150px; transform: translate(-50%, -100%); }
.chart-tip .tt-title { color: var(--muted); font-weight: 600; margin-bottom: 4px; }
.chart-tip .tt-row { display: flex; align-items: center; gap: 8px; }
.chart-tip .tt-row b { font-variant-numeric: tabular-nums; }
.chart-tip .tt-key { width: 12px; height: 3px; border-radius: 2px; display: inline-block; }
.bar-hit { cursor: default; }
.bar-mark { pointer-events: none; } /* the wider transparent .bar-hit underneath receives hover/focus */
.bar-hit:focus { outline: none; }
.bar-hit:focus + .bar-mark, .bar-hit:hover + .bar-mark { filter: brightness(1.12); }
.list { display: flex; flex-direction: column; }
.list-item { display: flex; gap: 10px; align-items: center; padding: 10px 18px; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.list-item .li-main { flex: 1; min-width: 0; }
.list-item .li-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .li-sub { font-size: 12px; color: var(--muted); }
a.list-item { color: inherit; }
a.list-item:hover { background: var(--surface-2); text-decoration: none; }

/* ---------- document form ---------- */
.doc-head { padding: 18px; display: grid; gap: 14px; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.doc-head .party-col { grid-column: span 2; grid-row: span 2; }
@media (max-width: 900px) { .doc-head { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 560px) { .doc-head { grid-template-columns: 1fr; } .doc-head .party-col { grid-column: auto; grid-row: auto; } }
.party-chip { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); min-height: 18px; }
.lines-card { margin-top: 14px; container-type: inline-size; }
.ac-list svg, .back svg, .chart-legend svg { width: 16px; height: 16px; flex: none; }
.lines-tools { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 12px 18px; border-bottom: 1px solid var(--line); }
.lines-tools .scan { width: 260px; max-width: 100%; }
.lines { --cols: 28px minmax(180px, 3fr) 84px 78px 86px 100px 64px 78px 112px 34px; }
.lines.no-disc { --cols: 28px minmax(180px, 3fr) 84px 78px 86px 100px 78px 112px 34px; }
.lines.no-tax { --cols: 28px minmax(180px, 3fr) 84px 78px 86px 100px 64px 112px 34px; }
.lines.no-tax.no-disc { --cols: 28px minmax(180px, 3fr) 84px 78px 86px 100px 112px 34px; }
.lrow { display: grid; grid-template-columns: var(--cols); gap: 8px; padding: 8px 18px; align-items: start; border-bottom: 1px solid var(--line); }
.lrow.lhead { font-size: 12px; font-weight: 650; color: var(--muted); background: var(--surface-2); padding-top: 9px; padding-bottom: 9px; align-items: center; }
.lrow input, .lrow select { width: 100%; height: 36px; border: 1px solid var(--line-2); border-radius: 8px; padding: 0 8px; background: var(--surface); outline: none; }
.lrow input:focus, .lrow select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.lrow input.sub-input { height: 30px; margin-top: 4px; font-size: 12.5px; border-style: dashed; }
.lrow .c-no { padding-top: 9px; color: var(--muted); font-weight: 600; text-align: center; }
.lrow .c-amt { text-align: right; padding-top: 8px; font-variant-numeric: tabular-nums; }
.lrow .c-amt b { display: block; font-size: 14px; }
.lrow .c-amt small { color: var(--muted); font-size: 11.5px; }
.lrow .c-del button { margin-top: 2px; }
.lrow .num-in { text-align: right; }
.lrow .stock-note { font-size: 11.5px; color: var(--muted); margin-top: 3px; }
.lrow .stock-note.low { color: var(--warn); }
.lines-add { padding: 12px 18px; display: flex; gap: 10px; flex-wrap: wrap; }
/* Stack each line as a small card when the items card itself is narrow (works with or without the sidebar). */
@container (max-width: 960px) {
  .lrow.lhead { display: none; }
  .lrow { grid-template-columns: 1fr 1fr 1fr; grid-template-areas: "no item item" "hsn qty unit" "rate disc gst" "amt amt del"; gap: 8px 10px; padding: 12px 16px; }
  .lines.no-disc .lrow { grid-template-areas: "no item item" "hsn qty unit" "rate gst gst" "amt amt del"; }
  .lines.no-tax .lrow { grid-template-areas: "no item item" "hsn qty unit" "rate disc disc" "amt amt del"; }
  .lines.no-tax.no-disc .lrow { grid-template-areas: "no item item" "hsn qty unit" "rate rate rate" "amt amt del"; }
  .lrow .c-no { grid-area: no; text-align: left; } .lrow .c-item { grid-area: item; } .lrow .c-hsn { grid-area: hsn; } .lrow .c-qty { grid-area: qty; }
  .lrow .c-unit { grid-area: unit; } .lrow .c-rate { grid-area: rate; } .lrow .c-disc { grid-area: disc; } .lrow .c-gst { grid-area: gst; }
  .lrow .c-amt { grid-area: amt; text-align: left; } .lrow .c-del { grid-area: del; justify-self: end; }
  .lrow [data-label]::before { content: attr(data-label); display: block; font-size: 11px; font-weight: 650; color: var(--muted); margin-bottom: 3px; }
}
.doc-bottom { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 14px; margin-top: 14px; align-items: start; }
@media (max-width: 900px) { .doc-bottom { grid-template-columns: minmax(0, 1fr); } }
.totals { padding: 6px 18px 16px; }
.totals .tr { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; font-variant-numeric: tabular-nums; }
.totals .tr.grand { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 12px; font-size: 19px; font-weight: 750; }
.totals .tr.bal { font-weight: 700; }
.recv { border-top: 1px dashed var(--line-2); margin-top: 8px; padding-top: 12px; display: grid; gap: 8px; grid-template-columns: 1fr 110px; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 16px; }
@media (max-width: 560px) {
  .form-actions { position: sticky; bottom: 0; background: var(--bg); padding: 10px 0; border-top: 1px solid var(--line); z-index: 5; }
  .form-actions .btn { flex: 1; }
}
details.more > summary { cursor: pointer; font-weight: 600; color: var(--brand-text); list-style: none; padding: 4px 0; }
details.more > summary::-webkit-details-marker { display: none; }
details.more > summary::before { content: "+ "; }
details.more[open] > summary::before { content: "− "; }

/* ---------- document view ---------- */
.doc-view { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
@media (max-width: 1100px) { .doc-view { grid-template-columns: minmax(0, 1fr); } }
.paper-stage { background: var(--surface-3); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; overflow-x: auto; }
.paper-stage .paper { margin: 0 auto; box-shadow: 0 2px 12px rgba(15, 23, 42, .14); }
.paper-stage .paper + .paper { margin-top: 18px; }
.side-card .kv { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px dashed var(--line); font-variant-numeric: tabular-nums; }
.side-card .kv:last-child { border-bottom: 0; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }

/* =========================================================================
   Printable paper (invoice / receipt / statement). Always light.
   ========================================================================= */
.paper { --p-ink: #111827; --p-muted: #4b5563; --p-line: #d6d9df; --p-soft: #f3f4f6; --p-brand: var(--brand, #3348c6);
  color-scheme: light; background: #fff; color: var(--p-ink); font: 11.5px/1.4 var(--font); position: relative; }
.paper.a4 { width: 210mm; min-height: 297mm; padding: 12mm 12mm 10mm; }
.paper.a5 { width: 148mm; min-height: 210mm; padding: 8mm; font-size: 9.5px; }
.paper.thermal80 { width: 80mm; padding: 4mm 3.5mm; font-size: 11px; }
.paper.thermal58 { width: 58mm; padding: 3mm 2.5mm; font-size: 9.5px; }
.paper * { box-sizing: border-box; }
.paper table { width: 100%; border-collapse: collapse; }
.paper .r { text-align: right; }
.paper .c { text-align: center; }
.paper .p-muted { color: var(--p-muted); }
.p-top { height: 4px; background: var(--p-brand); margin: -12mm -12mm 8mm; }
.paper.a5 .p-top { margin: -8mm -8mm 5mm; }
.p-head { display: flex; justify-content: space-between; gap: 14px; align-items: flex-start; padding-bottom: 10px; border-bottom: 1.5px solid var(--p-ink); }
.p-brand { display: flex; gap: 12px; align-items: flex-start; min-width: 0; }
.p-logo { max-width: 34mm; max-height: 20mm; object-fit: contain; }
.p-name { font-size: 18px; font-weight: 800; letter-spacing: -.01em; color: var(--p-ink); }
.paper.a5 .p-name { font-size: 14px; }
.p-addr { white-space: pre-line; color: var(--p-muted); margin-top: 2px; }
.p-ids { margin-top: 3px; font-weight: 600; }
.p-title { text-align: right; flex: none; }
.p-doc { font-size: 17px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; color: var(--p-brand); }
.paper.a5 .p-doc { font-size: 13px; }
.p-copy { font-size: 10px; font-weight: 700; color: var(--p-muted); text-transform: uppercase; letter-spacing: .05em; margin-top: 3px; }
.p-meta { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px 14px; padding: 10px 0; border-bottom: 1px solid var(--p-line); }
.p-meta.two { grid-template-columns: 1.3fr 1fr; }
.p-label { font-size: 9.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--p-muted); margin-bottom: 3px; }
.p-pname { font-size: 13px; font-weight: 750; }
.p-info td { padding: 1.5px 0; vertical-align: top; }
.p-info td:first-child { color: var(--p-muted); padding-right: 8px; white-space: nowrap; }
.p-info td:last-child { font-weight: 600; }
.p-items { margin-top: 8px; }
.p-items th { background: var(--p-soft); font-size: 9.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--p-muted); font-weight: 700;
  padding: 6px 5px; border-top: 1px solid var(--p-line); border-bottom: 1px solid var(--p-line); text-align: left; }
.p-items td { padding: 6px 5px; border-bottom: 1px solid var(--p-line); vertical-align: top; font-variant-numeric: tabular-nums; }
.p-items td .p-desc { color: var(--p-muted); font-size: 10px; }
.p-items tfoot td { font-weight: 700; background: var(--p-soft); border-bottom: 1px solid var(--p-line); }
.p-items .p-item { font-weight: 600; }
.p-bottom { display: grid; grid-template-columns: minmax(0, 1fr) 70mm; gap: 14px; margin-top: 10px; }
.paper.a5 .p-bottom { grid-template-columns: minmax(0, 1fr) 52mm; }
.p-box { border: 1px solid var(--p-line); border-radius: 6px; padding: 7px 9px; margin-bottom: 8px; break-inside: avoid; }
.p-words { font-weight: 600; }
.p-taxsum th, .p-taxsum td { padding: 3px 4px; border-bottom: 1px solid var(--p-line); font-size: 10px; font-variant-numeric: tabular-nums; }
.p-taxsum th { color: var(--p-muted); font-weight: 700; text-align: right; }
.p-taxsum th:first-child, .p-taxsum td:first-child { text-align: left; }
.p-tot td { padding: 3.5px 0; font-variant-numeric: tabular-nums; }
.p-tot td:last-child { text-align: right; font-weight: 600; }
.p-tot .p-grand td { border-top: 1.5px solid var(--p-ink); border-bottom: 1.5px solid var(--p-ink); font-size: 14px; font-weight: 800; padding: 6px 0; }
.p-pay { display: flex; gap: 10px; align-items: flex-start; }
.p-qr { width: 26mm; height: 26mm; flex: none; }
.p-qr svg { width: 100%; height: 100%; display: block; }
.p-qr-fallback { font-weight: 600; }
.p-sign { margin-top: 12px; text-align: right; break-inside: avoid; }
.p-sign img { max-height: 16mm; max-width: 50mm; display: block; margin: 6px 0 4px auto; }
.p-sign .p-sign-space { height: 14mm; }
.p-sign .p-sign-line { border-top: 1px solid var(--p-ink); display: inline-block; padding-top: 3px; min-width: 45mm; text-align: center; font-weight: 600; }
.p-terms { white-space: pre-line; color: var(--p-muted); font-size: 10px; }
.p-foot { margin-top: 10px; padding-top: 6px; border-top: 1px solid var(--p-line); text-align: center; color: var(--p-muted); font-size: 9.5px; }
.p-stamp { position: absolute; top: 120mm; left: 50%; transform: translateX(-50%) rotate(-18deg); border: 4px solid #b91c1c; color: #b91c1c; font-size: 40px;
  font-weight: 900; padding: 4px 18px; border-radius: 10px; opacity: .28; letter-spacing: .14em; pointer-events: none; }
.p-paid { display: inline-block; margin-top: 8px; border: 2px solid #15803d; color: #15803d; font-weight: 900; letter-spacing: .12em; padding: 1px 10px;
  border-radius: 6px; transform: rotate(-4deg); font-size: 13px; }
/* thermal */
.paper.thermal80 .t-center, .paper.thermal58 .t-center { text-align: center; }
.t-name { font-size: 15px; font-weight: 800; }
.paper.thermal58 .t-name { font-size: 12.5px; }
.t-logo { max-width: 30mm; max-height: 14mm; object-fit: contain; display: block; margin: 0 auto 2mm; }
.t-rule { border-top: 1px dashed #111; margin: 2mm 0; }
.t-items td { padding: 1px 0; vertical-align: top; font-variant-numeric: tabular-nums; }
.t-items .t-iname { font-weight: 650; padding-top: 1.5mm; }
.t-tot td { padding: 0.6mm 0; }
.t-tot td:last-child { text-align: right; }
.t-grand td { font-size: 14px; font-weight: 800; border-top: 1px dashed #111; padding-top: 1.5mm; }
.paper.thermal58 .t-grand td { font-size: 12px; }
.t-qr { width: 30mm; height: 30mm; margin: 2mm auto; }
.paper.thermal58 .t-qr { width: 26mm; height: 26mm; }
.t-qr svg { width: 100%; height: 100%; display: block; }

/* ---------- printing ---------- */
#print-root { display: none; color-scheme: light; --surface: #fff; --surface-2: #f6f7f9; --surface-3: #eef0f4; --line: #d6d9df; --line-2: #c8cdd5;
  --ink: #111827; --ink-2: #374151; --muted: #4b5563; --shadow: none; }
@media print {
  html, body { background: #fff !important; }
  body.printing > *:not(#print-root) { display: none !important; }
  body.printing #print-root { display: block; }
  #print-root .paper { margin: 0; box-shadow: none; min-height: 0; }
  #print-root .paper + .paper { break-before: page; }
  #print-root .p-top { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .paper .p-items th, .paper .p-items tfoot td { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

@media (max-width: 560px) {
  .share-top { height: auto; flex-wrap: wrap; padding: 10px 12px; gap: 8px; }
  .share-top .title { flex-basis: 100%; }
  .share-top .spacer { display: none; }
  .topbar .btn.sm span { display: none; } /* icon-only "New sale" on phones */
}

/* ---------- misc ---------- */
.kbd { font-family: var(--mono); font-size: 11.5px; padding: 1px 5px; border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 5px; background: var(--surface-2); }
.color-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.swatch { width: 28px; height: 28px; border-radius: 8px; border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--line-2); cursor: pointer; padding: 0; }
.swatch.on { box-shadow: 0 0 0 2px var(--ink); }
.img-drop { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.img-prev { width: 140px; height: 76px; border: 1px dashed var(--line-2); border-radius: 10px; display: grid; place-items: center; background: #fff; overflow: hidden; color: #64748b; font-size: 12px; }
.img-prev img { max-width: 100%; max-height: 100%; object-fit: contain; }
.help { font-size: 12.5px; color: var(--muted); }
.statement-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.loading { padding: 48px; text-align: center; color: var(--muted); }
.loading::before { content: ""; display: inline-block; width: 18px; height: 18px; margin-right: 10px; vertical-align: -3px; border-radius: 50%;
  border: 2px solid var(--muted); border-right-color: transparent; animation: spin .8s linear infinite; }
.err-box { padding: 24px; text-align: center; }
.copy-box { display: flex; gap: 8px; }
.copy-box input { flex: 1; }
.pill-list { display: flex; gap: 6px; flex-wrap: wrap; }
.pill { padding: 4px 10px; border-radius: 999px; background: var(--surface-3); font-size: 12.5px; font-weight: 600; color: var(--ink-2); border: 0; cursor: pointer; }
.pill.on { background: var(--brand-soft); color: var(--brand-text); }
