/* Design tokens: light enterprise theme. Components use tokens only, never raw hex. */
:root {
  --bg: #f4f6fa; --surface: #fff; --surface-2: #f8fafc;
  --border: #e2e8f0; --border-strong: #cbd5e1;
  --text: #0f172a; --muted: #5b6b80;
  --primary: #1d4ed8; --primary-hover: #1e40af; --primary-soft: #eff4ff; --on-primary: #fff;
  --ok: #15803d; --ok-soft: #ecfdf3; --warn: #b45309; --warn-soft: #fff7e6;
  --danger: #b91c1c; --danger-soft: #fef2f2;
  --side: #0f172a; --side-text: #cbd5e1; --side-hover: #1e293b; --side-active: #1d4ed8;
  --ring: #2563eb; --radius: 10px;
  --shadow: 0 1px 2px rgb(15 23 42 / .06), 0 1px 3px rgb(15 23 42 / .08);
  --font: "Fira Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Fira Code", ui-monospace, Menlo, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 400 15px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
.link { color: var(--primary); text-decoration: underline; text-underline-offset: 2px; cursor: pointer; }
.link:hover { color: var(--primary-hover); }
.mono { font-family: var(--mono); font-size: .92em; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.muted { color: var(--muted); }
:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 14px; border-radius: 6px; z-index: 100; }
.skip:focus { left: 8px; }

/* ---------- shell ---------- */
.app { display: block; min-height: 100vh; }
.side { position: fixed; inset: 0 auto 0 0; width: 256px; background: var(--side); color: var(--side-text); display: flex; flex-direction: column; padding: 16px 12px; z-index: 40; transform: translateX(-100%); transition: transform .2s ease; overflow-y: auto; }
.side.open { transform: none; }
.scrim { position: fixed; inset: 0; background: rgb(15 23 42 / .5); z-index: 30; display: none; }
.scrim.open { display: block; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 600; font-size: 16px; padding: 4px 10px 18px; }
.brand-mark { width: 32px; height: 32px; border-radius: 8px; background: var(--primary); display: grid; place-items: center; }
.nav-label { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: #94a3b8; padding: 16px 12px 6px; }
.nav a { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 12px; border-radius: 8px; color: var(--side-text); text-decoration: none; cursor: pointer; transition: background-color .15s, color .15s; }
.nav a:hover { background: var(--side-hover); color: #fff; }
.nav a[aria-current="page"] { background: var(--side-active); color: #fff; }
.content { min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; height: 56px; padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.topbar .crumb { font-weight: 600; }
main { padding: 16px; max-width: 1240px; margin: 0 auto; }
@media (min-width: 1024px) {
  .side { transform: none; }
  .content { margin-left: 256px; }
  .topbar .menu-btn, .scrim { display: none !important; }
  main { padding: 28px 32px; }
}

/* ---------- components ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.pad { padding: 20px; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; margin-bottom: 20px; }
.page-head h1 { font-size: 22px; font-weight: 600; }
.page-head p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.grow { flex: 1; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 0 16px; border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font: 500 14px var(--font); cursor: pointer; text-decoration: none; transition: background-color .15s, border-color .15s, opacity .15s; }
.btn:hover { background: var(--surface-2); border-color: var(--muted); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-sm { min-height: 32px; padding: 0 10px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.icon-btn { width: 40px; padding: 0; }
.stepper { width: 32px; min-height: 32px; padding: 0; font-weight: 700; }
.svg { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.lbl { display: block; font-size: 13px; font-weight: 500; color: var(--muted); }
.fld { display: block; width: 100%; min-height: 40px; margin-top: 4px; padding: 8px 12px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface); color: var(--text); font: 400 15px var(--font); transition: border-color .15s, box-shadow .15s; }
.fld:hover { border-color: var(--muted); }
.fld:focus { outline: none; border-color: var(--ring); box-shadow: 0 0 0 3px rgb(37 99 235 / .2); }
.fld[readonly] { background: var(--surface-2); }
textarea.fld { resize: vertical; line-height: 1.5; }
.err { color: var(--danger); font-size: 13px; min-height: 1.2em; }
.grid2 { display: grid; gap: 16px; }
.grid3 { display: grid; gap: 16px; }
.grid4 { display: grid; gap: 16px; }
@media (min-width: 700px) { .grid2 { grid-template-columns: 1fr 1fr; } .grid3 { grid-template-columns: repeat(3, 1fr); } .grid4 { grid-template-columns: repeat(4, 1fr); } }
.section-title { font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: 10px; }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 500; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.bad { background: var(--danger-soft); color: var(--danger); border-color: transparent; }

.kpis { display: grid; gap: 12px; grid-template-columns: repeat(2, 1fr); margin-bottom: 20px; }
@media (min-width: 900px) { .kpis { grid-template-columns: repeat(4, 1fr); } }
.kpi { padding: 16px 18px; }
.kpi .k { font-size: 13px; color: var(--muted); }
.kpi .v { font-size: 24px; font-weight: 600; margin-top: 4px; font-variant-numeric: tabular-nums; }

/* data tables */
.tbl-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); background: var(--surface-2); padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.tbl td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl-scroll { max-height: calc(100vh - 300px); overflow: auto; }
.tbl-scroll .tbl th { position: sticky; top: 0; z-index: 2; }
.tbl tfoot td { font-weight: 600; background: var(--surface-2); border-top: 2px solid var(--border-strong); }
.tbl .cell { display: block; width: 100%; min-width: 96px; min-height: 34px; padding: 4px 8px; border: 1px solid transparent; border-radius: 6px; background: transparent; font: inherit; color: inherit; }
.tbl .cell:hover { border-color: var(--border-strong); background: var(--surface); }
.tbl .cell:focus { outline: none; border-color: var(--ring); background: var(--surface); box-shadow: 0 0 0 3px rgb(37 99 235 / .2); }
.tbl .cell.r { text-align: right; }
.tbl .dim { color: var(--muted); opacity: .55; }
.tbl th input.cell { font-weight: 600; text-transform: uppercase; font-size: 12px; letter-spacing: .04em; color: var(--muted); }
.neg { color: var(--danger); } .pos { color: var(--warn); } .zero { color: var(--ok); }
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl.nowrap td { white-space: nowrap; }
.tbl .r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl tr.sub > td { background: var(--surface-2); padding: 0; }
.tbl tr.sub:hover { background: var(--surface-2); }
.subtbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.subtbl th, .subtbl td { padding: 9px 14px; border-bottom: 1px solid var(--border); text-align: left; }
.subtbl th { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.subtbl .r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.empty { padding: 48px 16px; text-align: center; color: var(--muted); }
.bar { height: 6px; background: var(--border); border-radius: 99px; overflow: hidden; min-width: 80px; }
.bar > i { display: block; height: 100%; background: var(--primary); }
.chev { transition: transform .15s; }
[aria-expanded="true"] .chev { transform: rotate(180deg); }
.search { max-width: 320px; }

/* toasts */
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 90; }
.toast { background: var(--text); color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); font-size: 14px; max-width: 360px; }
.toast.bad { background: var(--danger); }

dialog.modal { border: 0; border-radius: 12px; padding: 28px; width: min(520px, calc(100vw - 32px)); box-shadow: 0 20px 50px rgb(15 23 42 / .3); color: var(--text); }
.modal h2 { margin-bottom: 18px; }
.modal .err { margin: 12px 0 0; }
.modal .actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
dialog.modal::backdrop { background: rgb(15 23 42 / .5); }

/* ---------- paper (Release Order / Tax Invoice document) ---------- */
.sheet { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; }
.doc-title { text-align: center; font-size: 26px; font-weight: 700; letter-spacing: .12em; margin-bottom: 20px; }
.party { border: 1px solid var(--border-strong); border-radius: 8px; padding: 12px 14px; font-size: 14px; }
.party h3 { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.party .nm { font-weight: 600; }
.kv { display: flex; gap: 8px; font-size: 13px; }
.kv span:first-child { color: var(--muted); min-width: 44px; }
.totals { margin-left: auto; width: 100%; max-width: 360px; font-size: 14px; }
.totals td { padding: 5px 0; }
.totals tr.final td { border-top: 2px solid var(--text); padding-top: 8px; font-weight: 700; font-size: 17px; }
.words { margin-top: 12px; font-weight: 500; }

/* editable bill table */
.grid-tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.grid-tbl th, .grid-tbl td { border: 1px solid var(--border-strong); }
.grid-tbl thead th { background: var(--surface-2); }
.grid-tbl .letters th { font-size: 11px; color: var(--muted); font-weight: 500; padding: 2px; }
.grid-tbl input { display: block; width: 100%; min-height: 36px; padding: 6px 8px; border: 0; background: transparent; text-align: center; font: inherit; color: inherit; }
.grid-tbl input:focus { outline: 2px solid var(--ring); outline-offset: -2px; background: var(--primary-soft); }
.grid-tbl input.desc { text-align: left; }
.grid-tbl thead input { font-weight: 600; }
.grid-tbl .tot { text-align: right; padding: 0 10px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.grid-tbl .idx { text-align: center; color: var(--muted); width: 40px; }
.formula { font-family: var(--mono); text-transform: uppercase; }

.bank-tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.bank-tbl th, .bank-tbl td { border: 1px solid var(--border-strong); }
.bank-tbl th { background: var(--surface-2); font-size: 12px; padding: 6px 8px; text-align: center; }
.bank-tbl input { display: block; width: 100%; min-height: 38px; padding: 6px 8px; border: 0; background: transparent; text-align: center; font: inherit; color: inherit; }
.bank-tbl input:focus { outline: 2px solid var(--ring); outline-offset: -2px; background: var(--primary-soft); }

.banner { display: flex; flex-wrap: wrap; gap: 8px 24px; align-items: center; padding: 12px 16px; border-radius: var(--radius); background: var(--primary-soft); border: 1px solid var(--border); margin-bottom: 16px; font-size: 14px; }
.banner.warn { background: var(--warn-soft); }
.banner b { font-variant-numeric: tabular-nums; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---------- print: A4 portrait, only the document ---------- */
@page { size: A4 portrait; margin: 12mm; }
@media print {
  body { background: #fff; font-size: 12px; }
  .side, .scrim, .topbar, .no-print, .toasts, .skip { display: none !important; }
  .content { margin: 0 !important; }
  main { padding: 0; max-width: none; }
  .sheet { border: 0; box-shadow: none; padding: 0; }
  .fld, .grid-tbl input, .bank-tbl input, select, textarea { border: 0 !important; box-shadow: none !important; background: transparent !important; padding: 0 !important; -webkit-appearance: none; appearance: none; min-height: 0 !important; }
  textarea { resize: none; overflow: visible; }
  .grid-tbl, .bank-tbl, .party, .totals, .terms { break-inside: avoid; }
  .grid-tbl input { padding: 4px 6px !important; }
}

/* page tabs and compliance chips */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tabs a { padding: 8px 14px; border-radius: 8px 8px 0 0; color: var(--muted); font-weight: 500; text-decoration: none; }
.tabs a[aria-current] { color: var(--text); border-bottom: 2px solid var(--primary, #2563eb); }
.chk { display: grid; gap: 4px; padding: 12px 16px; border-top: 1px solid var(--border); }
.chk ul { margin: 4px 0 0 18px; padding: 0; font-size: 13px; }
.mini { font-size: 12px; color: var(--muted); }

/* credited / cancelled bills */
.row-cancel td { background: var(--danger-soft); }
.row-cancel .amt, .row-cancel .strike { text-decoration: line-through; opacity: .75; }
.row-part td { background: var(--warn-soft); }

/* universal table filter bar (tablefilter.js) */
tr[hidden] { display: none !important; }
.tf-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.tf-bar .fld { margin: 0; width: auto; min-width: 0; padding: 6px 10px; font-size: 13px; }
.tf-bar .tf-q { min-width: 200px; flex: 1 1 200px; max-width: 320px; }
.tf-bar .tf-sel { max-width: 230px; }
.tf-bar .tf-min, .tf-bar .tf-max { width: 110px; }
.tf-bar .tf-lbl { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.tf-bar .tf-chips { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.tf-bar .tf-count { margin-left: auto; font-size: 12px; color: var(--muted); }
.tf-bar [aria-pressed="true"] { background: var(--primary-soft); border-color: var(--primary); }
.tf-row th { padding: 4px 6px; background: var(--surface-2); }
.tf-row .fld { width: 100%; min-width: 70px; padding: 4px 6px; font-size: 12px; margin: 0; }
.tbl thead th.tf-sort-asc::after { content: " ▲"; font-size: 10px; }
.tbl thead th.tf-sort-desc::after { content: " ▼"; font-size: 10px; }
.tf-filtered tfoot { display: none; }

/* ---------- Neeraj Communication letterhead: header, footer and corporate bill styling (all printed documents) ---------- */
.sheet {
  --text: #231f20; --muted: #6a6e75; --border: #e4e6ea; --border-strong: #c8ccd2; --surface: #fff; --surface-2: #f5f6f8; --primary-soft: #fff4e6;
  --c-cyan: #12a8dc; --c-yellow: #fbbf12; --c-orange: #f7931e; --c-red: #e61f27; --c-green: #3fa535; --ink: #231f20;
  --brand: linear-gradient(90deg, var(--c-cyan) 0 20%, var(--c-yellow) 20% 40%, var(--c-orange) 40% 60%, var(--c-red) 60% 80%, var(--c-green) 80% 100%);
  background: #fff; color: var(--ink); padding: 0; overflow: hidden; position: relative; font-family: "Poppins", var(--font);
}
.sheet > :not(.lh-head):not(.lh-foot) { margin-left: 32px; margin-right: 32px; }
.lh-head { position: relative; display: flex; justify-content: space-between; align-items: flex-start; min-height: 150px; margin-bottom: 18px; }
.lh-head .splash { position: absolute; left: 0; top: 0; width: min(66%, 520px); height: auto; pointer-events: none; user-select: none; }
.lh-mark { position: relative; align-self: flex-end; padding: 0 0 6px 32px; margin-top: 82px; }
.lh-mark b { display: block; font: 700 clamp(18px, 3.4vw, 27px)/1.05 "Montserrat", "Poppins", var(--font); letter-spacing: .02em; color: var(--ink); white-space: nowrap; }
.lh-mark span { display: block; margin-top: 6px; font: 500 10.5px/1 var(--font); letter-spacing: .26em; text-transform: uppercase; color: var(--muted); }
.lh-contact { position: relative; font-size: 11.5px; line-height: 1.55; color: var(--ink); padding: 14px 32px 0 12px; text-align: left; max-width: 230px; }
.lh-contact i { display: block; height: 7px; }
.lh-contact a { color: inherit; text-decoration: none; }
.lh-rule { height: 3px; background: var(--brand); margin: 0 0 20px !important; border-radius: 2px; }
.doc-title { text-align: left !important; font: 800 22px/1.1 "Montserrat", "Poppins", var(--font) !important; letter-spacing: .16em !important; color: var(--ink); margin: 0 32px 18px !important; display: flex; align-items: center; gap: 14px; }
.doc-title::after { content: ""; flex: 1; height: 2px; background: linear-gradient(90deg, var(--c-orange), transparent); opacity: .55; }
.lh-gstline { display: flex; flex-wrap: wrap; gap: 4px 22px; font-size: 11.5px; color: var(--muted); margin: -8px 32px 18px !important; }
.lh-gstline b { color: var(--ink); font-weight: 600; }
.party { border: 0 !important; border-top: 3px solid var(--c-cyan) !important; background: var(--surface-2); border-radius: 0 0 8px 8px !important; }
#parties .party:nth-child(2), .grid3 .party:nth-child(2) { border-top-color: var(--c-orange) !important; }
#parties .party:nth-child(3), .grid3 .party:nth-child(3) { border-top-color: var(--c-green) !important; }
.party h3 { color: var(--ink) !important; font-weight: 700; }
.sheet .grid-tbl { border-collapse: separate; border-spacing: 0; border: 1px solid var(--border-strong); border-radius: 8px; overflow: hidden; }
.sheet .grid-tbl th, .sheet .grid-tbl td { border-color: var(--border); }
.sheet .grid-tbl thead th { background: var(--ink); color: #fff; border-color: #3a3536; }
.sheet .grid-tbl thead input { color: #fff; font-weight: 600; letter-spacing: .02em; }
.sheet .grid-tbl .letters th { background: var(--surface-2) !important; color: var(--muted) !important; }
.sheet .grid-tbl tbody tr:nth-child(even) td { background: #fafafb; }
.sheet .totals tr.final td { border-top: 0; background: var(--ink); color: #fff; padding: 9px 12px; font-size: 16px; }
.sheet .totals tr.final td:first-child { border-radius: 8px 0 0 8px; } .sheet .totals tr.final td:last-child { border-radius: 0 8px 8px 0; }
.sheet .section-title { font: 700 12px/1 "Montserrat", var(--font); letter-spacing: .14em; text-transform: uppercase; display: flex; align-items: center; gap: 8px; }
.sheet .section-title::before { content: ""; width: 9px; height: 9px; border-radius: 3px; background: var(--c-orange); }
.sheet .bank-tbl { border-collapse: separate; border-spacing: 0; border: 1px solid var(--border-strong); border-radius: 8px; overflow: hidden; }
.sheet .bank-tbl th { background: var(--surface-2); color: var(--ink); font-weight: 600; letter-spacing: .04em; }
.sheet .words { font-style: italic; color: var(--ink); }
.lh-foot { position: relative; margin-top: 34px; padding: 14px 32px 0; min-height: 96px; break-inside: avoid; }
.lh-foot .splash { position: absolute; right: 0; bottom: 0; width: min(34%, 260px); height: auto; pointer-events: none; user-select: none; }
.lh-foot .thanks { font: 600 12px/1 "Montserrat", var(--font); letter-spacing: .14em; text-transform: uppercase; color: var(--ink); margin-bottom: 10px; }
.lh-foot .regd { font-size: 10.5px; color: var(--muted); margin-bottom: 12px; max-width: 62%; }
.lh-svc { position: relative; display: grid; grid-template-columns: repeat(4, auto); justify-content: start; gap: 2px 26px; font-size: 10.5px; line-height: 1.5; color: var(--ink); max-width: 66%; padding-bottom: 14px; }
@media (max-width: 760px) { .lh-head { min-height: 120px; } .lh-contact { display: none; } .lh-svc { grid-template-columns: repeat(2, auto); } .sheet > :not(.lh-head):not(.lh-foot) { margin-left: 16px; margin-right: 16px; } }
@page { size: A4 portrait; margin: 0; }
@media print {
  body { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .sheet { overflow: visible; }
  .sheet > :not(.lh-head):not(.lh-foot) { margin-left: 14mm; margin-right: 14mm; }
  .lh-head { min-height: 38mm; margin-bottom: 6mm; } .lh-mark { margin-top: 20mm; padding-left: 14mm; } .lh-contact { padding-right: 12mm; }
  .lh-gstline { margin-left: 14mm !important; margin-right: 14mm !important; }
  .lh-foot { padding-left: 14mm; padding-bottom: 0; margin-top: 8mm; }
  .sheet .grid-tbl thead th, .sheet .totals tr.final td { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .sheet .grid-tbl thead input { color: #fff !important; }
}
.lh-svc div { white-space: nowrap; }
.lh-svc { max-width: none; }
.lh-foot .splash { width: min(26%, 200px); }
.sheet .section-title { white-space: nowrap; }
@media (max-width: 760px) { .lh-foot .splash { opacity: .35; } }

/* ---------- v2: paper-width sheet, meta block in the header, table that fits A4 ---------- */
.sheet { max-width: 210mm; margin: 0 auto; min-height: 297mm; display: flex; flex-direction: column; font-size: 12px; line-height: 1.4; }
.sheet > :not(.lh-head):not(.lh-foot) { margin-left: 28px; margin-right: 28px; }
.lh-head { min-height: 0; height: auto; align-items: stretch; margin-bottom: 14px; flex: none; }
.lh-head .splash { width: min(52%, 400px); }
.lh-mark { align-self: flex-end; margin-top: 0; padding: 0 0 6px 28px; position: relative; z-index: 1; }
.lh-mark { margin-top: 74px; }
.lh-mark b { font-size: clamp(16px, 2.6vw, 22px); }
.lh-meta { position: relative; z-index: 1; width: 285px; padding: 14px 28px 0 0; display: flex; flex-direction: column; gap: 6px; }
.lh-meta .doc-title { margin: 0 !important; font-size: 20px !important; letter-spacing: .14em !important; justify-content: flex-end; text-align: right !important; }
.lh-meta .doc-title::after { display: none; }
.lh-ids { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 2px 14px; font-size: 10.5px; color: var(--muted); }
.lh-ids b { color: var(--ink); font-weight: 600; }
.lh-fields { display: block !important; margin: 4px 0 0 !important; padding: 8px 10px; background: var(--surface-2); border-top: 3px solid var(--c-orange); border-radius: 0 0 8px 8px; }
.lh-fields > * { display: flex !important; justify-content: space-between; align-items: center; gap: 8px; margin: 0 0 3px; font-size: 10.5px; color: var(--muted); }
.lh-fields .fld, .lh-fields input, .lh-fields select { width: 150px !important; margin: 0 !important; padding: 3px 6px; font-size: 11.5px; min-height: 0; text-align: right; color: var(--ink); background: transparent; border: 1px solid var(--border); }
.lh-fields .fld { border-radius: 6px; width: 150px; }
.lh-fields .muted { font-size: 10px; }
.lh-fields .fld[style] { width: auto !important; max-width: 165px; text-align: right; }
.lh-rule { margin: 0 0 14px !important; flex: none; }
.lh-gstline { display: none; }
.lh-foot { margin-top: auto !important; padding: 16px 28px 0; min-height: 70px; flex: none; }
.lh-foot .splash { width: min(26%, 190px); }
.lh-svc { max-width: none; padding-bottom: 4px; gap: 1px 22px; font-size: 10px; }
.lh-foot .regd { font-size: 9.5px; max-width: 72%; margin: 4px 0 10px; }
.sheet .tbl-wrap { overflow: visible; }
.sheet .grid-tbl { table-layout: fixed; width: 100%; font-size: 11.5px; }
.sheet .grid-tbl th, .sheet .grid-tbl td { padding: 0; vertical-align: top; }
.sheet .grid-tbl thead th { vertical-align: middle; }
.sheet .grid-tbl textarea { display: block; width: 100%; min-height: 28px; padding: 6px 8px; border: 0; background: transparent; font: inherit; color: inherit; resize: none; overflow: hidden; text-align: left; line-height: 1.35; }
.sheet .grid-tbl textarea:focus, .sheet .grid-tbl input:focus { outline: 2px solid var(--ring); outline-offset: -2px; background: var(--primary-soft); color: var(--ink); }
.sheet .grid-tbl thead textarea { color: #fff; font-weight: 600; text-align: center; }
.sheet .grid-tbl thead textarea:focus { color: var(--ink); }
.sheet .grid-tbl textarea.txt { text-align: center; }
.sheet .grid-tbl input { min-height: 28px; padding: 6px 4px; text-align: right; white-space: nowrap; min-width: 0; font-variant-numeric: tabular-nums; }
.sheet .grid-tbl td.tot, .sheet .grid-tbl th.tot { padding: 6px 8px; white-space: nowrap; }
.sheet .grid-tbl .idx { width: auto; padding: 6px 2px; font-size: 10.5px; }
.sheet .bank-tbl { font-size: 11.5px; }
.sheet .bank-tbl input { min-height: 28px; padding: 4px 6px; }
.sheet .terms textarea { font-size: 11px; line-height: 1.4; }
@media (max-width: 760px) { .sheet { min-height: 0; } .lh-head { flex-wrap: wrap; } .lh-meta { width: 100%; padding: 8px 16px 0; } .lh-mark { margin-top: 70px; padding-left: 16px; } .lh-fields > * { font-size: 11px; } }
@media print {
  .sheet { max-width: none; margin: 0; width: 210mm; min-height: 297mm; font-size: 11px; }
  .sheet > :not(.lh-head):not(.lh-foot) { margin-left: 11mm; margin-right: 11mm; }
  .lh-head { margin-bottom: 4mm; } .lh-mark { margin-top: 20mm; padding-left: 11mm; } .lh-meta { padding-right: 11mm; padding-top: 6mm; }
  .lh-foot { padding: 4mm 11mm 0; } .lh-rule { margin-bottom: 4mm !important; }
  .sheet > [style*="margin-bottom"], .sheet > .grid2, .sheet > .grid3 { margin-bottom: 4mm !important; }
  .sheet > [style*="margin-top"] { margin-top: 5mm !important; }
  .sheet .grid-tbl, .sheet .bank-tbl, .sheet .party, .sheet .totals, .sheet .terms { break-inside: avoid; }
  .sheet .grid-tbl tr { break-inside: avoid; }
  .sheet .grid-tbl textarea, .sheet .grid-tbl input { padding: 3px 5px !important; min-height: 0 !important; overflow: visible; }
  .sheet .grid-tbl thead textarea { color: #fff !important; }
  .lh-fields .fld, .lh-fields input { border: 0 !important; padding: 0 !important; }
  .lh-fields { background: #f5f6f8 !important; }
  [style*="height:56px"] { height: 30px !important; }
  .sheet .totals { font-size: 12px; }
}
.lh-fields > label, .lh-fields > .lbl { white-space: nowrap; }
.lh-fields > .lbl > .fld { white-space: normal; }
.lh-mark .wm { display: block; width: clamp(200px, 40vw, 300px); height: auto; margin-bottom: 8px; }
@media print { .lh-mark .wm { width: 78mm; } }

/* ---------- v3: title + PAN/GSTIN top-right, details strip full width (no wasted space), orange table header ---------- */
.lh-meta { width: auto; padding-top: 10px; gap: 3px; align-items: flex-end; }
.lh-meta .doc-title { align-self: flex-end; }
.lh-ids { flex-direction: column; align-items: flex-end; gap: 1px; }
.lh-head { margin-bottom: 8px; }
.lh-fields { display: grid !important; grid-template-columns: repeat(3, 1fr); gap: 4px 18px; margin-top: 0 !important; margin-bottom: 14px !important; padding: 8px 12px; }
.lh-fields > * { margin: 0; }
.lh-fields .fld[style] { max-width: none; }
.sheet .grid-tbl thead th { background: #b8500f; border-color: #d9702a; }
@media (max-width: 760px) { .lh-fields { grid-template-columns: 1fr; } }
@media print { .lh-meta { padding-top: 5mm; } .sheet .grid-tbl thead th { background: #b8500f !important; } }

/* editable party fields on documents: look like text, show an outline on hover/focus, print as plain text */
.party .pf { background: transparent; border: 1px solid transparent; border-radius: 4px; font: inherit; color: inherit; padding: 1px 4px; margin-left: -4px; min-width: 0; width: 100%; }
.party .pf:hover { border-color: var(--border-strong); }
.party .pf:focus { outline: 2px solid var(--ring); background: var(--primary-soft); }
.party .kv .pf { text-align: right; flex: 1; margin-left: 0; }
.party .nm.pf { font-weight: 600; font-size: 14px; }
@media print { .party .pf { border: 0 !important; padding: 0; } }

/* ---------- v4: selected row/column, wrapping text areas, nothing cut off on screen or in print ---------- */
.grid-tbl tr.sel-row td { background: var(--primary-soft) !important; }
.grid-tbl th.cl { cursor: pointer; } .grid-tbl th.cl.sel-col { background: var(--primary-soft); color: var(--text); }
.grid-tbl td.idx { cursor: pointer; }
.grid-tbl textarea.numc { text-align: right !important; min-width: 0; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; white-space: pre-wrap; }
textarea.ta-auto { resize: none; overflow: hidden; white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; line-height: 1.4; font-family: inherit; min-height: 0; display: block; }
.lh-fields textarea.fld { text-align: right; }
.sheet textarea, .qsheet textarea, .grid-tbl td, .bank-tbl td, .party { overflow-wrap: anywhere; word-break: break-word; }
.l-sub, .q-sub, .w-sub { text-align: left !important; }
@media print {
  textarea, input { overflow: visible !important; white-space: pre-wrap !important; overflow-wrap: anywhere; text-overflow: clip !important; }
  .grid-tbl td, .grid-tbl th, .bank-tbl td, .party, .terms { overflow: visible !important; }
  textarea.ta-auto, .grid-tbl textarea { height: auto; }
}

.party .pf { display: block; resize: none; overflow: hidden; }
.party .kv { align-items: flex-start; gap: 8px; }
.party .kv .pf { text-align: left; width: auto; }
.lh-fields div.fld { white-space: normal !important; overflow: visible !important; height: auto !important; max-width: 100% !important; width: 100% !important; overflow-wrap: anywhere; line-height: 1.35; }
.lh-fields > .lbl { align-items: flex-start; }
.lh-fields textarea.fld { width: 150px; }

/* ---------- covering letter + invoice: the letter pages print first, the invoice follows on plain paper ---------- */
.cover-mount { margin-bottom: 18px; }
.sheet.after-letter { margin-top: 18px; }
@media print { .sheet.after-letter { break-before: page; page-break-before: always; margin-top: 0; } .cover-mount { margin: 0; } .cover-mount .pg:last-child { break-after: page; page-break-after: always; } }
body.plain-inv .lh-head .splash, body.plain-inv .lh-head .lh-mark, body.plain-inv .lh-foot { display: none !important; }
body.plain-inv .lh-head { min-height: 0; }
body.plain-inv .lh-meta { padding-top: 14px; }
[hidden] { display: none !important; }
body.plain-inv .lh-meta { margin-left: auto; }
.lh-fields > .lbl:nth-child(3) { grid-column: 1 / -1; }
.lh-fields > .lbl:nth-child(3) div.fld { text-align: right; }

/* ---------- v5: details box as wide as "Billed by" and aligned with it; orange Final Total; one font in bank details ---------- */
.sheet > .lh-fields { margin-left: 28px !important; margin-right: 28px !important; display: block !important; width: calc((100% - 56px - 16px) / 2); box-sizing: border-box; }
.lh-fields > * { display: flex !important; justify-content: space-between; align-items: center; gap: 12px; }
.lh-fields > .lbl:nth-child(3) { grid-column: auto; }
.lh-fields .fld, .lh-fields textarea, .lh-fields input { text-align: right; width: auto !important; flex: 1; min-width: 0; }
.lh-fields > .lbl:nth-child(3) div.fld { text-align: right; flex: 1; width: auto !important; }
@media print { .sheet > .lh-fields { margin-left: 11mm !important; margin-right: 11mm !important; width: calc((100% - 22mm - 16px) / 2); } }
@media (max-width: 760px) { .sheet > .lh-fields { margin-left: 16px !important; margin-right: 16px !important; width: auto; } }
.sheet .totals tr.final td { background: #b8500f !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.sheet .bank-tbl, .sheet .bank-tbl th, .sheet .bank-tbl td, .sheet .bank-tbl textarea, .sheet .bank-tbl input { font: 500 11.5px/1.4 "Poppins", var(--font) !important; letter-spacing: 0; }
.sheet .bank-tbl th { font-weight: 600 !important; text-align: center; vertical-align: middle; padding: 7px 8px; }
.sheet .bank-tbl td { vertical-align: middle; padding: 0; text-align: center; }
.sheet .bank-tbl textarea, .sheet .bank-tbl input { text-align: center !important; padding: 8px 8px !important; min-height: 0 !important; display: block; width: 100%; box-sizing: border-box; }
.sheet .bank-tbl td, .sheet .bank-tbl th { width: 25%; }

/* ---------- v6: black text on the bill, bigger header fields, print = preview ---------- */
.sheet { --muted: #000; --text: #000; --ink: #000; color: #000; }
.sheet .muted, .sheet .kv span, .sheet .lh-ids, .sheet .totals .muted { color: #000 !important; }
.lh-fields > * { font-size: 11.5px !important; }
.lh-fields .fld, .lh-fields textarea, .lh-fields input { font-size: 12.5px !important; }
.lh-fields .muted { font-size: 11px !important; }
.party .nm.pf { font-weight: 600; font-size: 14px; }
.party .addr.pf { font-size: 12px; line-height: 1.4; }
.party select#toPick { width: 100%; margin: 4px 0 6px; font-size: 12px; }
.party .nm.pf, .party .addr.pf { display: block; width: 100%; box-sizing: border-box; }
@media print {
  .party .addr.pf:placeholder-shown { display: none !important; }
  .party select#toPick { display: none !important; }
  .sheet .lh-fields > * { display: flex !important; justify-content: space-between !important; align-items: flex-start !important; }
  .sheet .lh-fields textarea, .sheet .lh-fields input, .sheet .lh-fields div.fld { text-align: right !important; flex: 1 1 auto !important; width: auto !important; min-width: 0; direction: ltr; }
  .sheet .lh-fields .lbl, .sheet .lh-fields > * { text-align: left; }
  .sheet .lh-fields { font-size: inherit; }
}

/* letterhead on/off switch above the sheet */
.lh-switch { max-width: 210mm; margin: 0 auto 10px; display: flex; gap: 16px; align-items: center; flex-wrap: wrap; background: var(--surface, #fff); border: 1px solid var(--border, #ddd); border-radius: 8px; padding: 8px 12px; }

/* company with no letterhead artwork: its name is a plain heading */
.lh-head .lh-name { font: 700 26px/1.1 "Montserrat", "Fira Sans", sans-serif; letter-spacing: .04em; color: #000; padding: 14px 0 4px; }
body.plain-inv .lh-head .lh-name { display: none; }
.lh-head:has(.lh-name) { min-height: 0; }
