/* =====================================================================
   GST Billing — "Khata" design system
   Slate-teal navigation, white workspace, money-green primary, ledger-red
   accent reserved for negatives / overdue. Figures use tabular numerals and
   amount columns carry the thin double red rule of a paper account book.
   ===================================================================== */
:root {
  --ink: #1B2B28; --ink-2: #51615D; --ink-3: #82918D;
  --line: #DCE3E0; --line-2: #EBF0EE;
  --bg: #F4F6F5; --surface: #FFFFFF; --surface-2: #F8FAF9;
  --nav: #16322D; --nav-2: #1D3F39; --nav-ink: #C9D8D4; --nav-ink-2: #86A39D;
  --primary: #1F6F54; --primary-600: #185A44; --primary-50: #E7F2ED;
  --ledger: #B3261E; --ledger-50: #FBECEA;
  --amber: #9A6100; --amber-50: #FFF4DE;
  --blue: #1E5A8A; --blue-50: #E8F1F8;
  --radius: 10px; --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(22,50,45,.06), 0 4px 16px rgba(22,50,45,.06);
  --shadow-lg: 0 12px 40px rgba(22,50,45,.18);
  --font: "Public Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --sidebar-w: 248px; --topbar-h: 60px;
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 14px/1.5 var(--font); color: var(--ink); background: var(--bg); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
button, input, select, textarea { font: inherit; color: inherit; }
.icon { flex: none; vertical-align: middle; }
.num, .amount, td.num, th.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.neg { color: var(--ledger); }
.muted { color: var(--ink-3); }
.pad { padding: 14px 16px; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.content { padding: 24px 28px 48px; max-width: 1480px; width: 100%; }

/* ---------- Sidebar ---------- */
.sidebar { width: var(--sidebar-w); background: var(--nav); color: var(--nav-ink); position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; flex: none; z-index: 40; }
.sidebar-brand { height: var(--topbar-h); display: flex; align-items: center; gap: 10px; padding: 0 18px; border-bottom: 1px solid rgba(255,255,255,.06); }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--primary); color: #fff; display: grid; place-items: center; font-weight: 700; }
.brand-text { font-weight: 700; color: #fff; letter-spacing: .01em; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-close { display: none; color: var(--nav-ink); }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 10px 10px 20px; scrollbar-width: thin; scrollbar-color: var(--nav-2) transparent; }
.nav-root, .nav-sub { list-style: none; margin: 0; padding: 0; }
.nav-group-link, .nav-group-toggle { display: flex; align-items: center; gap: 11px; width: 100%; padding: 9px 10px; border: 0; background: none;
  color: var(--nav-ink); border-radius: var(--radius-sm); cursor: pointer; text-align: left; font-weight: 500; }
.nav-group-link:hover, .nav-group-toggle:hover { background: var(--nav-2); color: #fff; text-decoration: none; }
.nav-group-link.is-active { background: var(--primary); color: #fff; }
.nav-group-toggle .chev { margin-left: auto; transition: transform .15s; opacity: .7; }
.nav-group.is-open > .nav-group-toggle .chev { transform: rotate(180deg); }
.nav-group.is-open > .nav-group-toggle { color: #fff; }
.nav-sub { display: none; padding: 2px 0 6px 20px; margin-left: 9px; border-left: 1px solid rgba(255,255,255,.08); }
.nav-group.is-open > .nav-sub { display: block; }
.nav-link { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 6px; color: var(--nav-ink-2); font-size: 13.5px; }
.nav-link:hover { color: #fff; background: rgba(255,255,255,.05); text-decoration: none; }
.nav-link.is-active { color: #fff; background: rgba(31,111,84,.55); font-weight: 600; }
.nav-link.is-pending { opacity: .45; cursor: default; }
.nav-link.is-pending:hover { background: none; color: var(--nav-ink-2); }
.phase-badge { margin-left: auto; font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 99px; border: 1px solid rgba(255,255,255,.25); }
.sidebar-foot { padding: 10px 18px; font-size: 11px; color: var(--nav-ink-2); border-top: 1px solid rgba(255,255,255,.06); }
.sidebar-backdrop { display: none; }

/* ---------- Topbar ---------- */
.topbar { height: var(--topbar-h); background: var(--surface); border-bottom: 1px solid var(--line); display: flex; align-items: center;
  gap: 16px; padding: 0 20px; position: sticky; top: 0; z-index: 30; }
.menu-toggle { display: none; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.global-search { position: relative; flex: 1; max-width: 460px; display: flex; align-items: center; gap: 8px; background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 8px; padding: 0 10px; color: var(--ink-3); }
.global-search:focus-within { border-color: var(--primary); background: #fff; }
.global-search input { border: 0; background: none; outline: none; flex: 1; height: 36px; color: var(--ink); min-width: 0; }
.global-search kbd { font: 11px var(--font); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; color: var(--ink-3); }
.search-results { position: absolute; top: 42px; left: 0; right: 0; background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); max-height: 420px; overflow-y: auto; color: var(--ink); }
.search-group { padding: 8px 12px 4px; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); }
.search-item { display: flex; justify-content: space-between; gap: 12px; padding: 8px 12px; color: var(--ink); }
.search-item:hover, .search-item.is-focus { background: var(--primary-50); text-decoration: none; }
.search-item small { color: var(--ink-3); }
.branch-switch, .branch-static { display: flex; align-items: center; gap: 6px; color: var(--ink-2); font-size: 13px; }
.branch-switch select { border: 1px solid var(--line); border-radius: 8px; height: 36px; padding: 0 8px; background: #fff; max-width: 240px; }
.icon-btn { position: relative; display: inline-grid; place-items: center; width: 36px; height: 36px; border: 0; border-radius: 8px; background: none;
  color: var(--ink-2); cursor: pointer; }
.icon-btn:hover { background: var(--bg); color: var(--ink); }
.icon-btn .dot { position: absolute; top: 8px; right: 9px; width: 8px; height: 8px; border-radius: 50%; background: var(--ledger); border: 2px solid #fff; }
.user-chip { display: flex; align-items: center; gap: 10px; border: 0; background: none; cursor: pointer; padding: 4px 6px; border-radius: 8px; }
.user-chip:hover { background: var(--bg); }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--primary-50); color: var(--primary); display: grid; place-items: center; font-weight: 700; }
.user-meta { display: flex; flex-direction: column; text-align: left; line-height: 1.2; }
.user-meta small { color: var(--ink-3); font-size: 12px; }

/* ---------- Dropdowns ---------- */
.dropdown { position: relative; }
.dropdown-menu { position: absolute; right: 0; top: calc(100% + 6px); min-width: 200px; background: #fff; border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 6px; display: none; z-index: 50; }
.dropdown.is-open > .dropdown-menu { display: block; }
.dropdown-wide { width: 360px; padding: 0; }
.dropdown-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; font-weight: 600; border-bottom: 1px solid var(--line-2); }
.dropdown-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; background: none; border-radius: 6px;
  color: var(--ink); cursor: pointer; text-align: left; }
.dropdown-item:hover { background: var(--bg); text-decoration: none; }
.notif-list { max-height: 380px; overflow-y: auto; }
.notif { display: block; padding: 10px 14px; border-bottom: 1px solid var(--line-2); color: var(--ink); }
.notif.unread { background: var(--primary-50); }
.notif small { display: block; color: var(--ink-3); }
.link-btn { border: 0; background: none; color: var(--primary); cursor: pointer; font-size: 12px; font-weight: 600; padding: 0; }

/* ---------- Page header ---------- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 38px; padding: 0 16px; border-radius: 8px;
  border: 1px solid var(--line); background: #fff; color: var(--ink); font-weight: 600; cursor: pointer; white-space: nowrap; text-decoration: none; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-600); }
.btn-danger { background: var(--ledger); border-color: var(--ledger); color: #fff; }
.btn-danger:hover { background: #962019; }
.btn-ghost { border-color: transparent; background: none; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn-icon { width: 30px; height: 30px; padding: 0; border-color: transparent; background: none; color: var(--ink-2); }
.btn-icon:hover { background: var(--bg); color: var(--ink); }
.btn-icon.danger:hover { color: var(--ledger); background: var(--ledger-50); }
.btn[disabled], .btn.is-loading { opacity: .6; pointer-events: none; }
.btn.is-loading::after { content: ""; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line-2); }
.card-head h2, .card-head h3 { font-size: 15px; font-weight: 700; }
.card-body { padding: 18px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }

/* Stat tiles: figure sits on a ledger rule */
.stat { padding: 16px 18px; position: relative; }
.stat-label { color: var(--ink-2); font-size: 12.5px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.stat-value { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 6px; letter-spacing: -.01em; }
.stat-sub { font-size: 12px; color: var(--ink-3); margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat::after { content: ""; position: absolute; left: 18px; right: 18px; bottom: 10px; height: 3px;
  border-top: 1px solid rgba(179,38,30,.18); border-bottom: 1px solid rgba(179,38,30,.18); }
.stat { padding-bottom: 22px; }
.stat.is-alert .stat-value { color: var(--ledger); }
.stat a.stat-link { position: absolute; inset: 0; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.form-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
.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 .req { color: var(--ledger); }
.input, .select, .textarea, .field input:not([type=checkbox]):not([type=radio]):not([type=file]), .field select, .field textarea {
  width: 100%; height: 38px; padding: 0 11px; border: 1px solid var(--line); border-radius: 8px; background: #fff; outline: none; }
.field textarea, .textarea { height: auto; min-height: 76px; padding: 9px 11px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus, .input:focus, .select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-50); }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--ledger); }
.field-error { color: var(--ledger); font-size: 12px; }
.hint { color: var(--ink-3); font-size: 12px; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 500; }
.check input { width: 16px; height: 16px; accent-color: var(--primary); }
.form-section { font-size: 12px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--ink-3); grid-column: 1 / -1;
  padding-top: 8px; border-top: 1px dashed var(--line); margin-top: 4px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; padding-top: 6px; }
.img-preview { width: 140px; height: 80px; border: 1px dashed var(--line); border-radius: 8px; display: grid; place-items: center; overflow: hidden; background: var(--surface-2); }
.img-preview img { max-width: 100%; max-height: 100%; }

/* ---------- Toolbar + tables ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line-2); }
.toolbar .search { position: relative; flex: 1; min-width: 200px; max-width: 320px; }
.toolbar .search .icon { position: absolute; left: 10px; top: 11px; color: var(--ink-3); }
.toolbar .search input { padding-left: 32px; }
.toolbar .spacer { flex: 1; }
.toolbar select, .toolbar input { height: 36px; border: 1px solid var(--line); border-radius: 8px; padding: 0 10px; background: #fff; }
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; }
.table th { position: sticky; top: 0; background: var(--surface-2); text-align: left; font-size: 12px; font-weight: 700; letter-spacing: .03em;
  text-transform: uppercase; color: var(--ink-2); padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table th.sortable { cursor: pointer; user-select: none; }
.table th.sortable::after { content: " ↕"; opacity: .35; }
.table th.sort-asc::after { content: " ↑"; opacity: 1; }
.table th.sort-desc::after { content: " ↓"; opacity: 1; }
.table td { padding: 10px 14px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.table tbody tr:hover { background: #FAFCFB; }
/* the account-book double rule to the left of money columns */
.table td.num, .table th.num { border-left: 3px double rgba(179,38,30,.22); }
.table .actions { text-align: right; white-space: nowrap; width: 1%; }
.table tfoot td { font-weight: 700; background: var(--surface-2); border-top: 2px solid var(--line); }
.table-empty { padding: 48px 16px; text-align: center; color: var(--ink-3); }
.table-empty .icon { color: var(--line); margin-bottom: 6px; }
.table-loading td { color: var(--ink-3); text-align: center; padding: 32px; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; flex-wrap: wrap; color: var(--ink-2); font-size: 13px; }
.pager-pages { display: flex; gap: 4px; }
.pager button { min-width: 32px; height: 32px; border: 1px solid var(--line); background: #fff; border-radius: 6px; cursor: pointer; }
.pager button.is-current { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 700; }
.pager button[disabled] { opacity: .4; cursor: default; }
.pager select { height: 32px; border: 1px solid var(--line); border-radius: 6px; }

/* ---------- Badges / alerts ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--line-2); color: var(--ink-2); }
.badge-green { background: var(--primary-50); color: var(--primary); }
.badge-red { background: var(--ledger-50); color: var(--ledger); }
.badge-amber { background: var(--amber-50); color: var(--amber); }
.badge-blue { background: var(--blue-50); color: var(--blue); }
.alert { display: flex; align-items: flex-start; gap: 10px; padding: 11px 14px; border-radius: 8px; margin-bottom: 16px; border: 1px solid; }
.alert-success { background: var(--primary-50); border-color: #BFDCCF; color: var(--primary-600); }
.alert-danger { background: var(--ledger-50); border-color: #F1C5C1; color: var(--ledger); }
.alert-info { background: var(--blue-50); border-color: #C7DBEB; color: var(--blue); }
.alert-warning { background: #FFF6E0; border-color: #F0D58C; color: #7A5200; }
.alert-warn { background: var(--amber-50); border-color: #EFD9A8; color: var(--amber); }

/* ---------- Modal ---------- */
dialog.modal { border: 0; padding: 0; border-radius: 14px; width: min(640px, calc(100vw - 24px)); max-height: calc(100vh - 40px); box-shadow: var(--shadow-lg); color: var(--ink); }
dialog.modal.modal-lg { width: min(960px, calc(100vw - 24px)); }
dialog.modal.modal-sm { width: min(420px, calc(100vw - 24px)); }
dialog.modal::backdrop { background: rgba(16,32,29,.45); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line-2); position: sticky; top: 0; background: #fff; z-index: 1; }
.modal-head h2 { font-size: 17px; }
.modal-body { padding: 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line-2); background: var(--surface-2);
  position: sticky; bottom: 0; }

/* ---------- Toasts ---------- */
.toast-stack { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 1000; }
.toast { display: flex; gap: 10px; align-items: flex-start; min-width: 260px; max-width: 400px; background: var(--ink); color: #fff; padding: 12px 14px;
  border-radius: 10px; box-shadow: var(--shadow-lg); animation: toastIn .18s ease-out; }
.toast.toast-error { background: var(--ledger); }
.toast.toast-success { background: var(--primary-600); }
@keyframes toastIn { from { transform: translateY(8px); opacity: 0; } }

/* ---------- Permission matrix ---------- */
.perm-matrix th, .perm-matrix td { text-align: center; }
.perm-matrix td:first-child, .perm-matrix th:first-child { text-align: left; }
.perm-matrix .group-row td { background: var(--surface-2); font-weight: 700; font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); text-align: left; }
.perm-matrix input { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }

/* ---------- Charts ---------- */
.chart-box { position: relative; height: 280px; }
.chart-box canvas { width: 100%; height: 100%; display: block; }
.chart-tip { position: absolute; pointer-events: none; background: var(--ink); color: #fff; font-size: 12px; padding: 6px 9px; border-radius: 6px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--ink-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.list-rows { list-style: none; margin: 0; padding: 0; }
.list-rows li { display: flex; justify-content: space-between; gap: 12px; padding: 9px 18px; border-bottom: 1px solid var(--line-2); }
.list-rows li:last-child { border-bottom: 0; }

/* ---------- Auth pages ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.05fr 1fr; background: #fff; }
.auth-aside { background: var(--nav); color: var(--nav-ink); padding: 48px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.auth-aside h2 { color: #fff; font-size: 30px; line-height: 1.2; max-width: 420px; letter-spacing: -.01em; }
.auth-aside p { max-width: 420px; color: var(--nav-ink-2); }
.auth-ledger { position: absolute; inset: 0; opacity: .08; pointer-events: none;
  background-image: repeating-linear-gradient(to bottom, transparent 0 31px, #fff 31px 32px); }
.auth-ledger::before { content: ""; position: absolute; top: 0; bottom: 0; left: 72%; width: 6px; border-left: 1px solid #ff6b60; border-right: 1px solid #ff6b60; opacity: 3; }
.auth-main { display: grid; place-items: center; padding: 32px; }
.auth-card { width: 100%; max-width: 380px; }
.auth-card h1 { font-size: 24px; margin-bottom: 6px; }
.auth-card .sub { color: var(--ink-2); margin-bottom: 24px; }
.auth-card form { display: grid; gap: 14px; }
.auth-card .btn { height: 42px; }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 960px) {
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s; }
  .app.sidebar-open .sidebar { transform: none; }
  .app.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 35; }
  .sidebar-close, .menu-toggle { display: inline-grid; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .user-meta, .global-search kbd { display: none; }
  .auth { grid-template-columns: 1fr; }
  .auth-aside { display: none; }
}
@media (max-width: 640px) {
  .content { padding: 16px 14px 40px; }
  .grid-4, .form-grid, .form-grid.cols-3 { grid-template-columns: 1fr; }
  .branch-switch select { max-width: 130px; }
  .topbar { gap: 8px; padding: 0 10px; }
  .dropdown-wide { width: calc(100vw - 24px); right: -60px; }
}
@media print {
  .sidebar, .topbar, .page-actions, .toolbar, .pager, .actions { display: none !important; }
  .content { padding: 0; } .card { box-shadow: none; border: 0; } body { background: #fff; }
}

/* ---------- Picker / document editor ---------- */
.picker-results { position: absolute; left: 0; right: 0; top: calc(100% + 2px); background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow-lg); max-height: 300px; overflow-y: auto; z-index: 60; min-width: 280px; }
.picker-item { padding: 8px 10px; cursor: pointer; border-bottom: 1px solid var(--line-2); font-size: 13px; }
.picker-item:hover, .picker-item.is-focus { background: var(--primary-50); }
.picker-item small { color: var(--ink-3); }
.picker-empty { padding: 10px; color: var(--ink-3); }
.doc-editor .items-table td { padding: 6px 8px; vertical-align: top; }
.doc-editor .items-table input, .doc-editor .items-table select { width: 100%; height: 34px; border: 1px solid var(--line); border-radius: 6px; padding: 0 8px; background: #fff; }
.doc-editor .items-table input.num { text-align: right; font-variant-numeric: tabular-nums; }
.doc-editor .items-table .prod-cell { min-width: 240px; }
.doc-editor .items-table .muted-line { font-size: 12px; color: var(--ink-3); margin-top: 3px; }
.totals-box { width: 100%; max-width: 380px; margin-left: auto; }
.totals-box div { display: flex; justify-content: space-between; padding: 5px 0; font-variant-numeric: tabular-nums; }
.totals-box .grand { font-size: 20px; font-weight: 700; border-top: 3px double rgba(179,38,30,.35); margin-top: 6px; padding-top: 10px; }
.party-card { background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; font-size: 13px; }
.doc-view dl { display: grid; grid-template-columns: 150px 1fr; gap: 4px 12px; margin: 0; font-size: 13px; }
.doc-view dt { color: var(--ink-3); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.kbd-hint { font-size: 12px; color: var(--ink-3); }
.text-danger { color: var(--danger, #b3261e); }
tr.row-error td { background: #fdecea; }
.report-head { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 12px; }
.report-head .field { margin: 0; }
.report-table td.num, .report-table th.num { white-space: nowrap; }
.report-table tr.group-row td { background: var(--surface-2); font-weight: 600; }
.report-table tr.total-row td { font-weight: 700; border-top: 2px solid var(--line); }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat-row .stat { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.stat-row .stat span { display: block; font-size: 12px; color: var(--ink-3); }
.stat-row .stat strong { font-size: 18px; font-variant-numeric: tabular-nums; }
.lines-table input, .lines-table select { width: 100%; height: 34px; border: 1px solid var(--line); border-radius: 6px; padding: 0 8px; background: #fff; }
@media (max-width: 900px) { #docEditor .grid-2 { grid-template-columns: 1fr !important; } }
.fy-badge { font-size: 12px; font-weight: 600; padding: 4px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); white-space: nowrap; color: var(--ink-2, #444); }

/* =====================================================================
   Phones and small tablets — full mobile layout
   ===================================================================== */
.search-toggle, .bottom-nav { display: none; }
@media (max-width: 640px) {
  :root { --topbar-h: 56px; }
  body { padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px)); -webkit-text-size-adjust: 100%; }
  input, select, textarea { font-size: 16px !important; } /* stops iOS zooming into fields */
  .btn, .icon-btn { min-height: 40px; }

  /* Top bar: menu · search icon · branch · bell · avatar */
  .topbar { height: var(--topbar-h); padding: 0 8px; gap: 4px; }
  .search-toggle { display: inline-grid; }
  .global-search { display: none; }
  .topbar.search-open .global-search { display: flex; position: absolute; left: 8px; right: 8px; top: 8px; max-width: none; z-index: 45; background: #fff; box-shadow: var(--shadow-lg); }
  .topbar.search-open .search-results { left: 0; right: 0; width: auto; max-height: 70vh; }
  .fy-badge, .branch-switch > svg, .branch-static > svg, .user-chip > .icon { display: none; }
  .topbar-right { gap: 4px; min-width: 0; }
  .branch-switch select { max-width: 132px; height: 36px; font-size: 14px !important; padding: 0 4px; }
  .branch-static { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
  .dropdown-menu { right: 0; max-width: calc(100vw - 16px); }
  .dropdown-wide { width: calc(100vw - 16px); right: -48px; }

  /* Page */
  .content { padding: 12px 10px 24px; }
  .page-head { margin-bottom: 12px; gap: 10px; }
  .page-head h1 { font-size: 19px; }
  .page-actions { width: 100%; }
  .page-actions > .btn, .page-actions > a.btn { flex: 1 1 auto; justify-content: center; }
  .alert { font-size: 13px; }
  .card { border-radius: 10px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .stat-row { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat-row .stat strong { font-size: 15px; }

  /* Filters and toolbars stack */
  .toolbar { padding: 10px; gap: 8px; }
  .toolbar .search { flex: 1 1 100%; }
  .toolbar-filters, .toolbar-filters select { width: 100%; }
  .toolbar .spacer { display: none; }
  #docFilters, #opsFilters, #masterFilters { display: grid !important; grid-template-columns: 1fr 1fr; gap: 8px !important; margin-bottom: 10px; }
  #docFilters > *, #opsFilters > *, #masterFilters > * { width: 100%; min-width: 0; }
  .report-head { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .report-head .field { min-width: 0 !important; }
  .report-head .field select, .report-head .field input { width: 100%; }
  .pager { justify-content: center; padding: 10px; }
  .pager > :first-child { width: 100%; text-align: center; }

  /* Lists become cards: each row is a card, each cell shows its column name */
  .data-table thead { display: none; }
  .data-table, .data-table tbody, .data-table tfoot { display: block; }
  .data-table tr { display: block; padding: 10px 12px; border-bottom: 1px solid var(--line); }
  .data-table td { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 3px 0 !important; border: 0 !important; text-align: right; min-height: 0; }
  .data-table td::before { content: attr(data-label); color: var(--ink-3); font-size: 12px; text-align: left; flex: 0 0 auto; }
  .data-table td:first-child { font-size: 15px; }
  .data-table td:first-child::before { display: none; }
  .data-table td:first-child { justify-content: flex-start; text-align: left; }
  .data-table td { width: auto !important; white-space: normal; }
  .data-table td.actions { justify-content: flex-end; gap: 6px; padding-top: 6px !important; }
  .data-table td.line-no { display: none; }
  .data-table td.actions::before, .data-table td[colspan]::before, .data-table td:empty { display: none; }
  .data-table td[colspan] { display: block; text-align: center; }
  .data-table tfoot tr { background: var(--surface-2); }
  .data-table tfoot td:not(:empty) { justify-content: space-between; }

  /* Dialogs use the whole screen with the buttons always visible */
  dialog.modal, dialog.modal.modal-lg, dialog.modal.modal-sm { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border-radius: 0; }
  dialog.modal[open] { display: flex; flex-direction: column; }
  dialog.modal > form { display: flex; flex-direction: column; min-height: 100%; }
  .modal-head { padding: 12px 14px; }
  .modal-body { padding: 14px; flex: 1; overflow-y: auto; }
  .modal-foot { position: sticky; bottom: 0; padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px)); flex-wrap: wrap; gap: 6px; }
  .modal-foot .btn, .modal-foot select, .modal-foot a.btn { flex: 1 1 calc(50% - 6px); justify-content: center; }
  .doc-view dl { grid-template-columns: 110px 1fr; }
  .doc-view > div[style*="grid-template-columns"] { grid-template-columns: 1fr !important; }

  /* Document editor: each item line is a compact card */
  .doc-editor .items-table thead { display: none; }
  .doc-editor .items-table, .doc-editor .items-table tbody, .doc-editor .items-table tfoot, .doc-editor .items-table tfoot tr { display: block; }
  .doc-editor .items-table tbody tr { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; padding: 12px 44px 12px 12px; border-bottom: 1px solid var(--line); position: relative; }
  .doc-editor .items-table td { display: block; padding: 0 !important; border: 0 !important; min-width: 0 !important; width: auto !important; }
  .doc-editor .items-table td[data-label]::before { content: attr(data-label); display: block; font-size: 11px; color: var(--ink-3); margin-bottom: 2px; text-align: left; }
  .doc-editor .items-table td.line-no { display: none; }
  .doc-editor .items-table td.prod-cell { grid-column: 1 / -1; }
  .doc-editor .items-table td.line-total { font-weight: 700; }
  .doc-editor .items-table td.line-remove { position: absolute; top: 8px; right: 6px; }
  .doc-editor .items-table td.table-empty, .doc-editor .items-table td[colspan] { grid-column: 1 / -1; }
  .doc-editor .items-table tfoot td { display: block; padding: 12px !important; }
  .doc-editor .items-table tfoot td:first-child { display: none; }
  .doc-editor .grid-2 { grid-template-columns: 1fr !important; }
  .totals-box { max-width: none; }
  .doc-editor .card-body .btn-row:last-of-type { position: sticky; bottom: calc(64px + env(safe-area-inset-bottom, 0px)); background: #fff; padding: 10px 0; z-index: 5; }
  .doc-editor .btn-row .btn { flex: 1 1 auto; justify-content: center; }
  .lines-table { min-width: 560px; }
  #opsLines, #opsLines + * { overflow-x: auto; }

  /* Bottom navigation */
  .bottom-nav { display: flex; position: fixed; left: 0; right: 0; bottom: 0; height: calc(60px + env(safe-area-inset-bottom, 0px)); padding-bottom: env(safe-area-inset-bottom, 0px);
    background: #fff; border-top: 1px solid var(--line); z-index: 32; box-shadow: 0 -4px 16px rgba(16,32,29,.06); }
  .bottom-nav a, .bottom-nav button { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font: 600 11px var(--font);
    color: var(--ink-3); background: none; border: 0; text-decoration: none; min-width: 0; }
  .bottom-nav .is-active { color: var(--primary); }
  .bottom-nav .bn-primary { color: var(--primary); }
  .bottom-nav .bn-primary .icon { width: 42px; height: 42px; padding: 10px; margin-top: -18px; border-radius: 50%; background: var(--primary); color: #fff; box-shadow: 0 4px 12px rgba(0,0,0,.2); }
  .toast-stack { left: 10px; right: 10px; bottom: calc(72px + env(safe-area-inset-bottom, 0px)); }
  .sidebar { z-index: 50; width: min(300px, 86vw); }
  .app.sidebar-open .sidebar-backdrop { z-index: 45; }
  .picker-results { min-width: 0; max-height: 50vh; }
}
@media print { .bottom-nav, .search-toggle { display: none !important; } }
.grid > *, .grid-2 > *, .grid-3 > *, .grid-4 > * { min-width: 0; }
@media (max-width: 640px) {
  .report-table th:first-child, .report-table td:first-child { position: sticky; left: 0; background: #fff; z-index: 1; box-shadow: 1px 0 0 var(--line); }
  .report-table tr.group-row td:first-child { background: var(--surface-2); }
}
/* Tablets and small laptops: keep the top bar on one line */
.global-search { min-width: 0; }
.topbar-right { flex-shrink: 0; }
@media (max-width: 1200px) {
  .user-meta, .fy-badge { display: none; }
  .branch-switch select { max-width: 170px; }
}
.party-input { display: flex; gap: 6px; align-items: stretch; }
.party-input > input { flex: 1; min-width: 0; }
.party-add { flex: 0 0 auto; border: 1px solid var(--primary); color: var(--primary); background: var(--primary-50, #eef6f3); }
.picker-create { color: var(--primary); font-weight: 600; border-top: 1px dashed var(--line); }
.price-history { font-size: 12px; margin-top: 4px; color: var(--ink-2, #444); }
.price-history table { width: 100%; border-collapse: collapse; margin-top: 4px; }
.price-history td, .price-history th { padding: 2px 6px; border-bottom: 1px solid var(--line-2, #eee); text-align: left; font-weight: 400; }
.price-history th { color: var(--ink-3); font-size: 11px; }
.price-history .num { text-align: right; }
.trend-up { color: var(--danger, #b3261e); font-weight: 600; }
.trend-down { color: var(--primary, #1f6f56); font-weight: 600; }
.ph-toggle { background: none; border: 0; padding: 0; color: var(--primary); cursor: pointer; font: inherit; text-decoration: underline; }
.ph-table { overflow-x: auto; max-width: 100%; }
.price-history table { white-space: nowrap; font-size: 11px; }
.price-history td, .price-history th { border-left: 0 !important; border-right: 0 !important; }

/* ---- Back buttons, simplified editor, multi-select (Oct 2026 update) ---- */
.modal-head { gap: 10px; }
.modal-head .modal-back { flex: none; height: 30px; padding: 0 10px; gap: 4px; font-size: 13px; }
.modal-head h2 { flex: 1; min-width: 0; }
.editor-bar { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.editor-title { margin: 0; font-size: 17px; }
.btn-back { gap: 6px; }
.more-details { margin-top: 12px; border-top: 1px dashed var(--line); padding-top: 10px; }
.more-details > summary { cursor: pointer; font-weight: 600; color: var(--primary); list-style: revert; }
.more-details > summary .kbd-hint { font-weight: 400; margin-left: 6px; }
.select-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; background: var(--primary-50); border: 1px solid var(--primary);
  border-radius: 8px; padding: 8px 12px; margin: 0 0 10px; }
.select-bar[hidden] { display: none; }
.row-pick { width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer; }
.mode-switch { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.mode-switch label { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; cursor: pointer; font-weight: 600; }
.mode-switch label:has(input:checked) { border-color: var(--primary); background: var(--primary-50); }
.mode-switch small { display: block; font-weight: 400; color: var(--ink-3); }
.picker-results { z-index: 1000; }
.modal-foot .view-back { margin-right: auto; gap: 6px; }
.price-history { margin-top: 6px; padding: 6px 8px; background: var(--surface-2); border: 1px solid var(--line-2); border-radius: 6px; font-size: 12px; line-height: 1.5; color: var(--ink-2); }
.price-history:empty { display: none; }
.price-history .ph-label { display: inline-block; min-width: 92px; font-weight: 600; color: var(--ink); }
.price-history .trend-up { color: #b3261e; font-weight: 600; }
.price-history .trend-down { color: var(--primary); font-weight: 600; }
@media (max-width: 640px) { .doc-editor .items-table td.prod-cell { grid-column: 1 / -1; } .price-history .ph-label { display: block; min-width: 0; } }
.btn-whatsapp { background: #1fa855; border-color: #1fa855; color: #fff; gap: 6px; }
.btn-whatsapp:hover { background: #178a45; }
.gstr-sec { margin-top: 12px; }
.gstr-sec > summary { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 16px; cursor: pointer; font-weight: 700; }
.gstr-sec[open] > summary { border-bottom: 1px solid var(--line-2); }

/* Add-item box: its own colour so it is easy to find (sales, purchase, challans, adjustments) */
.doc-editor .items-table tfoot td { background: #eef6ff; }
#productSearch, #lineProduct {
  height: 46px !important; font-size: 15px; font-weight: 600; color: #0b3b75;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%231d64c4' stroke-width='2.2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E") no-repeat 14px center;
  padding-left: 44px !important; border: 2px solid #3b82f6 !important; border-radius: 10px !important;
  box-shadow: 0 0 0 4px rgba(59, 130, 246, .12);
}
#productSearch::placeholder, #lineProduct::placeholder { color: #3d6aa8; font-weight: 500; }
#productSearch:focus, #lineProduct:focus { outline: none; border-color: #1d4ed8 !important; box-shadow: 0 0 0 5px rgba(37, 99, 235, .28); background-color: #f8fbff; }
