/* Phase 29 - one font, one form-control look, no number spinners.
   Loaded LAST on every admin / company / auth page so it wins. */
:root { --ui-font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif; --ui-blue: #2563EB; --ui-border: #CBD5E1; }
html, body, input, select, textarea, button, table, .btn { font-family: var(--ui-font); }
/* monospace columns use the same family (tabular figures keep digits aligned) */
.td-mono, .json-preview.ui-same, .hs-suggest .hs-opt strong, .fbr-verify-irn, .br-chip, .br-color-in input[type=text] { font-family: var(--ui-font); font-variant-numeric: tabular-nums; }

/* number inputs: no up/down arrows, no wheel changes (wheel handled in ui-unified.js) */
input[type=number] { -moz-appearance: textfield; appearance: textfield; }
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; display: none; }

/* one dropdown look */
select {
  -webkit-appearance: none; -moz-appearance: none; appearance: none;
  background-color: #fff;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%2364748B' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 11px 7px;
  padding-right: 32px !important;
  border: 1.5px solid var(--ui-border); border-radius: 8px; color: #1F2937; cursor: pointer;
  text-overflow: ellipsis;
}
select:hover:not(:disabled) { border-color: #94A3B8; }
select:focus { border-color: var(--ui-blue); box-shadow: 0 0 0 3px rgba(37,99,235,.15); outline: none; }
select:disabled { background-color: #F1F5F9; cursor: not-allowed; opacity: .75; }
select[multiple], select[size]:not([size="1"]) { background-image: none; padding-right: 10px !important; }
select option { font-family: var(--ui-font); }

/* searchable pick-from-list (UOM etc.) */
.ui-combo { position: relative; display: block; width: 100%; }
.ui-combo > input { width: 100%; padding-right: 32px !important; cursor: pointer;
  border: 1.5px solid var(--ui-border); border-radius: 8px; background-color: #fff;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%2364748B' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 11px 7px; }
.ui-combo > input:focus { border-color: var(--ui-blue); box-shadow: 0 0 0 3px rgba(37,99,235,.15); outline: none; cursor: text; }
.ui-combo-pop { position: fixed; z-index: 100000; background: #fff; border: 1px solid var(--ui-border); border-radius: 10px;
  box-shadow: 0 12px 32px rgba(15,23,42,.18); max-height: 260px; overflow-y: auto; padding: 4px; font-size: 13px; }
.ui-combo-pop .o { padding: 7px 10px; border-radius: 6px; cursor: pointer; line-height: 1.3; }
.ui-combo-pop .o.on, .ui-combo-pop .o:hover { background: #EFF6FF; color: #1E40AF; }
.ui-combo-pop .o.sel { font-weight: 600; }
.ui-combo-pop .none { padding: 9px 10px; color: #64748B; }

/* tidy HS-code picker rows */
.xf-float-pop .opt:has(.hs-row) { padding: 0; }
.xf-float-pop .opt .hs-row { flex: 1; min-width: 0; }
.xf-float-pop .hs-row { display: grid; grid-template-columns: 92px 1fr; gap: 10px; align-items: center; padding: 7px 10px; min-height: 34px; }
.xf-float-pop .hs-row .c { font-weight: 700; color: #1E40AF; font-variant-numeric: tabular-nums; }
.xf-float-pop .hs-row .d { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #334155; }
.xf-float-pop .hs-row mark { background: #FEF08A; color: inherit; border-radius: 2px; padding: 0 1px; }
.xf-float-pop .opt.active .hs-row, .xf-float-pop .opt:hover .hs-row { background: #EFF6FF; }
.f-rate{min-width:64px}

/* bulk selection bar (Digital + Local lists; same look as CRM) */
.bulk-bar-wrap{position:sticky;top:64px;z-index:30;display:flex;align-items:center;justify-content:space-between;gap:12px;flex-wrap:wrap;background:#fff;border:1px solid var(--primary,#2563EB);border-left-width:5px;border-radius:10px;padding:10px 14px;margin-bottom:12px;box-shadow:var(--shadow-md);font-size:13px}
.bulk-bar-wrap[hidden]{display:none}
.bulk-sel{display:flex;align-items:center;gap:8px;flex-wrap:wrap}
.bulk-sel strong{color:var(--primary,#2563EB);font-size:15px}
.bulk-actions{display:flex;gap:6px;flex-wrap:wrap}
.bulk-sep{width:1px;background:var(--border);margin:2px 4px}
.sel-col{width:36px;text-align:center}
tr.is-selected td{background:#EFF6FF}

/* ===== Approved theme-blue accents (colour only - no layout change) ===== */
/* Digital: Tax Configuration + Tax Summary (totals) */
.xf-section:has(#tax_sale_type), .xf-section:has(#t_subtotal), .xf-section:has(#t_gross),
.xf-totals { background: linear-gradient(180deg,#EFF6FF,#fff 70%); border: 1px solid #BFD6FB; box-shadow: inset 4px 0 0 #2563EB; }
.xf-section:has(#tax_sale_type), .xf-section:has(#t_subtotal), .xf-section:has(#t_gross) { border-top: 1px solid #BFD6FB; }
.xf-section:has(#tax_sale_type) .xf-head h3, .xf-section:has(#t_subtotal) .xf-head h3, .xf-section:has(#t_gross) .xf-head h3 { color: #1E40AF; }
.xf-section:has(#tax_sale_type) .xf-head h3 i, .xf-section:has(#t_subtotal) .xf-head h3 i, .xf-section:has(#t_gross) .xf-head h3 i { color: #2563EB; }
.xf-section:has(#tax_sale_type) .xf-head, .xf-section:has(#t_subtotal) .xf-head, .xf-section:has(#t_gross) .xf-head { border-bottom-color: #DCE8FB; }
.xf-section:has(#tax_sale_type) .xf-note { color: #1E40AF; }
.xf-totals { border-radius: 10px; padding: 12px 16px; }
.xf-totals .xf-trow { border-bottom: 1px dashed #DCE8FB; }
.xf-totals .xf-trow.grand, .xf-totals .xf-trow.sep { border-bottom: 0; }
.xf-totals .xf-trow.grand b, .xf-section:has(#t_subtotal) .xf-trow.grand b, .xf-section:has(#t_gross) .xf-trow.grand b { color: #1E40AF; }
.xf-section:has(#t_subtotal) .xf-trow, .xf-section:has(#t_gross) .xf-trow { border-bottom: 1px dashed #DCE8FB; }
/* CRM / Local: 3rd-schedule chip, Tax % header and selects */
.xf-3s { background: #EFF6FF; border: 1px solid #BFD6FB; color: #1E40AF; border-radius: 999px; padding: 3px 10px; }
th.c-tax { color: #1E40AF; background: #EFF6FF; }
.f-sales_tax_rate, .f-tax { border-color: #BFD6FB !important; background-color: #F5F9FF !important; color: #1E40AF; font-weight: 600; }
/* compact selects inside item tables: smaller arrow gutter so values like "18%" are never cut */
td select, .item-table select { padding-right: 22px !important; background-position: right 7px center; }
.f-sales_tax_rate, .f-tax { min-width: 84px; }
th.c-tax { min-width: 90px; }

/* Digital Invoice review page: compact at 100%, Total column always visible */
.fbr-err-under { margin-top: 8px; display: flex; gap: 8px; align-items: flex-start; background: #FEF2F2; border: 1px solid #FECACA; color: #991B1B; border-radius: 8px; padding: 8px 12px; font-size: 13px; max-width: 760px; }
.invoice-view { font-size: 13.5px; }
.invoice-view h1 { font-size: 20px; }
.invoice-view .review-table { min-width: 0; width: 100%; font-size: 12.5px; table-layout: auto; }
.invoice-view .review-table th, .invoice-view .review-table td { padding: 7px 8px; }
.invoice-view .review-table .col-desc { width: 28%; }
.invoice-view .item-table-wrap { overflow-x: auto; }
.invoice-view .totals-box { max-width: 380px; margin-left: auto; font-size: 13px; }

/* New / Edit Digital Invoice pop-up: no empty gap, fits the viewport at 100% */
body.embedded .main-content, body.embedded main { padding-top: 0 !important; }
body.embedded .page-container { padding: 8px 12px 72px !important; }
body.embedded { zoom: .92; }
body.embedded .xf-section { margin-bottom: 10px; }
body.embedded .xf-head { padding-top: 8px; padding-bottom: 8px; }
body.embedded .xf-body { padding-top: 10px; padding-bottom: 10px; }
body.embedded .xf-grid { row-gap: 8px; }
body.embedded .xf-field input, body.embedded .xf-field select { height: 34px; }

/* ===== Phase 31 - fill the screen, fit every device ===== */
/* content uses the full width beside the sidebar (no dead margins on big screens) */
.page-container, body.page-form .page-container { max-width: none; margin: 0; padding: 20px 24px; box-sizing: border-box; width: 100%; }
.main-content { min-width: 0; }
.stats-row { justify-content: stretch; }
.stats-row .stat-card { max-width: none; }
/* nothing may push the page sideways */
html, body { max-width: 100%; overflow-x: hidden; }
img, svg, video, canvas { max-width: 100%; height: auto; }
input, select, textarea { max-width: 100%; box-sizing: border-box; }
.page-header > *, .card, .xf-section, .xf-grid > *, .form-row > * { min-width: 0; }
/* wide tables scroll inside their own box instead of the page */
.tbl-scroll { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tbl-scroll > .data-table { min-width: 640px; }
.xf-head-right, .page-header-actions, .filter-row, .toolbar { flex-wrap: wrap; }
.xf-head { flex-wrap: wrap; }
.im-drop, .im-drop > * { max-width: 100%; box-sizing: border-box; }
.im-drop span { overflow-wrap: anywhere; }

/* laptops / small desktops: slimmer sidebar to give the content room */
@media (min-width: 769px) and (max-width: 1180px) {
  .sidebar { width: 208px; }
  .main-content { margin-left: 208px; }
  .topbar { left: 208px; }
  .sidebar-title { font-size: 16px; white-space: nowrap; }
  .sidebar-brand { gap: 8px; }
  .xf-actionbar { left: 208px; }
  .xf-ab-info { display: none !important; }
  .page-container, body.page-form .page-container { padding: 16px 16px; }
}
/* tablets and phones */
@media (max-width: 768px) {
  .page-container, body.page-form .page-container { padding: 12px 10px; }
  .page-header { gap: 8px; margin-bottom: 14px; }
  .page-header h1 { font-size: 20px; }
  .xf-grid, .xf-grid.c4, .xf-grid.c3, .xf-grid.c2, .xf-grid.c5 { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  .card { padding-left: 12px; padding-right: 12px; }
  .bulk-bar-wrap { top: 56px; }
}
@media (max-width: 480px) {
  .xf-grid, .xf-grid.c4, .xf-grid.c3, .xf-grid.c2, .xf-grid.c5 { grid-template-columns: minmax(0, 1fr) !important; }
  .xf-grid .span-2, .xf-grid .span-all { grid-column: 1 / -1 !important; }
  .page-header { flex-direction: column; align-items: stretch; }
  .page-header .btn, .page-header-actions .btn { width: 100%; text-align: center; justify-content: center; }
  .stats-row .stat-card { min-height: 0; }
}
.im-grid { grid-template-columns: minmax(0, 1fr); }
@media (min-width: 1001px) { .im-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); } }
.im-grid > * { min-width: 0; }
/* summary cards: 4 across on desktop, 2 on tablet/phone (compact on phones) */
@media (max-width: 1100px) { .di-cards, .dash-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 560px) {
  .di-cards, .dash-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .di-card { padding: 10px 10px 10px 10px; min-height: 0; }
  .di-ic { display: none; }
  .di-l { font-size: 10.5px; }
  .di-v { font-size: 18px; }
}
.im-guide { display: block; max-width: 100%; overflow-x: auto; }
/* phones: slim action bar so forms keep the screen */
@media (max-width: 600px) {
  .xf-ab-info { display: none !important; }
  .xf-actionbar { padding: 8px 10px; gap: 6px; flex-wrap: wrap; justify-content: stretch; }
  .xf-actionbar .xf-btn, .xf-actionbar button, .xf-actionbar a { flex: 1 1 calc(33% - 6px); min-width: 0; padding-left: 6px; padding-right: 6px; font-size: 12.5px; text-align: center; justify-content: center; }
}
/* inline "span N" cells must never create extra columns on narrow screens */
@media (max-width: 768px) { .xf-grid > [style*="grid-column"] { grid-column: 1 / -1 !important; } }

/* ===== Phase 32: Digital invoice items table fits the screen (no inner sideways scroll) ===== */
.xf-items.xf-di { table-layout: fixed; width: 100%; }
.xf-items.xf-di thead th { padding: 8px 4px; font-size: 10.5px; white-space: normal; line-height: 1.2; vertical-align: bottom; }
.xf-items.xf-di tbody td { padding: 5px 3px; }
.xf-items.xf-di input, .xf-items.xf-di select { padding: 0 4px; font-size: 12px; min-width: 0; }
.xf-items.xf-di thead th { min-width: 0 !important; }
.xf-items.xf-di th:nth-child(1), .xf-items.xf-di td:nth-child(1) { width: 26px; }
.xf-items.xf-di th:nth-child(2) { width: 10%; }
.xf-items.xf-di th:nth-child(3) { width: auto; }
.xf-items.xf-di th:nth-child(4) { width: 8%; }
.xf-items.xf-di th:nth-child(5) { width: 5.8%; }
.xf-items.xf-di th:nth-child(6) { width: 7%; }
.xf-items.xf-di th:nth-child(7) { width: 6%; }
.xf-items.xf-di th:nth-child(8) { width: 6%; }
.xf-items.xf-di th:nth-child(9) { width: 6%; }
.xf-items.xf-di th:nth-child(10) { width: 6%; }
.xf-items.xf-di th:nth-child(11) { width: 6%; }
.xf-items.xf-di th:nth-child(12) { width: 5.4%; }
.xf-items.xf-di th:nth-child(13) { width: 5.4%; }
.xf-items.xf-di th:nth-child(14) { width: 8%; }
.xf-items.xf-di th:nth-child(15), .xf-items.xf-di td:nth-child(15) { width: 34px; }
.xf-items.xf-di input[type=number] { -moz-appearance: textfield; appearance: textfield; }
.xf-items.xf-di input[type=number]::-webkit-outer-spin-button, .xf-items.xf-di input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.xf-items-wrap:has(> .xf-di) { overflow-x: visible; }
.xf-items.xf-di .cell-total { font-size: 12.5px; }

/* Tablet and phone: each item becomes a compact card, every field kept */
@media (max-width: 1180px) {
  .xf-items.xf-di, .xf-items.xf-di tbody { display: block; }
  .xf-items.xf-di thead { display: none; }
  .xf-items.xf-di tbody tr { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px 10px; padding: 12px 14px 12px; border-bottom: 8px solid #F1F5F9; position: relative; }
  .xf-items.xf-di tbody td { display: block; padding: 0; border: 0; width: auto !important; min-width: 0; }
  .xf-items.xf-di tbody td::before { content: attr(data-l); display: block; font-size: 10.5px; font-weight: 600; color: var(--text-secondary, #475569); margin-bottom: 3px; }
  .xf-items.xf-di td.cell-idx { grid-column: 1 / 2; align-self: center; text-align: left; padding: 0; font-size: 13px; }
  .xf-items.xf-di td.cell-idx::before { display: none; }
  .xf-items.xf-di td:nth-child(2) { grid-column: 2 / 4; }
  .xf-items.xf-di td:nth-child(3) { grid-column: 4 / 7; }
  .xf-items.xf-di td:nth-child(4) { grid-column: 1 / 4; }
  .xf-items.xf-di td:nth-child(5) { grid-column: 4 / 5; }
  .xf-items.xf-di td:nth-child(6) { grid-column: 5 / 7; }
  .xf-items.xf-di td:nth-child(7), .xf-items.xf-di td:nth-child(8) { grid-column: span 3; }
  .xf-items.xf-di td:nth-child(9), .xf-items.xf-di td:nth-child(10), .xf-items.xf-di td:nth-child(11), .xf-items.xf-di td:nth-child(12), .xf-items.xf-di td:nth-child(13) { grid-column: span 1; }
  .xf-items.xf-di td:nth-child(9) { grid-column: 1 / 2; }
  .xf-items.xf-di td.cell-total { grid-column: 1 / 5; text-align: left; padding: 0; align-self: end; font-size: 14px; }
  .xf-items.xf-di td:nth-child(15) { grid-column: 6 / 7; justify-self: end; align-self: end; }
  .xf-items.xf-di td:nth-child(15)::before { display: none; }
}
@media (max-width: 600px) {
  .xf-items.xf-di tbody tr { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .xf-items.xf-di td.cell-idx { grid-column: 1 / 2; }
  .xf-items.xf-di td:nth-child(2) { grid-column: 2 / 5; }
  .xf-items.xf-di td:nth-child(3) { grid-column: 1 / 5; }
  .xf-items.xf-di td:nth-child(4) { grid-column: 1 / 3; }
  .xf-items.xf-di td:nth-child(5) { grid-column: 3 / 5; }
  .xf-items.xf-di td:nth-child(6), .xf-items.xf-di td:nth-child(7), .xf-items.xf-di td:nth-child(8) { grid-column: span 2; }
  .xf-items.xf-di td:nth-child(9) { grid-column: span 1; }
  .xf-items.xf-di td:nth-child(10), .xf-items.xf-di td:nth-child(11), .xf-items.xf-di td:nth-child(12), .xf-items.xf-di td:nth-child(13) { grid-column: span 1; }
  .xf-items.xf-di td.cell-total { grid-column: 1 / 4; }
  .xf-items.xf-di td:nth-child(15) { grid-column: 4 / 5; }
  body.page-wide .page-container, .page-container { padding-bottom: 140px; }
}
/* pop-up editor: keep the last section clear of the fixed action bar */
body.embedded .page-container, body.embedded .content-area { padding-bottom: 104px !important; }
html body.embedded main.main-content .page-container, html body.embedded .main-content > .page-container { padding-bottom: 104px !important; }
html body.embedded { overflow-x: hidden; }

/* ===== Phase 33: laptops with Windows display scaling (125% / 150%) =====
   The browser says "100%" but the screen only has ~1280 CSS px, so everything looks too large.
   Scale the whole app down a little on those screens so it fits like it does on a normal monitor.
   Phones and small tablets are not affected (min-width). */
@media (min-resolution: 1.4dppx) and (min-width: 1100px) and (max-width: 1700px) { html { zoom: 0.74; } }
@media (min-resolution: 1.2dppx) and (max-resolution: 1.39dppx) and (min-width: 1100px) and (max-width: 1700px) { html { zoom: 0.84; } }
/* CRM items table: keep the Qty / Discount boxes readable (the table scrolls inside its own box on narrow screens) */
.xf-items:has(th.c-tax) { min-width: 1100px; }

/* ===== Phase 34: invoice creation pages (Digital, CRM, Local) fit the screen - the PAGE never scrolls =====
   Only the list of item rows scrolls inside its own box when there are many items. */
@media (min-width: 1181px) and (min-height: 600px) {
  html:has(#invoiceForm, #crmForm, #liForm), body:has(#invoiceForm, #crmForm, #liForm) { overflow: hidden !important; height: 100%; }
  body:has(#invoiceForm, #crmForm, #liForm) .page-container {
    position: fixed; top: 56px; left: 240px; right: 0; bottom: 0; width: auto; max-width: none;
    padding: 8px 14px 6px !important; overflow: hidden; display: flex; flex-direction: column; min-height: 0;
  }
  body:has(#invoiceForm) .page-container { bottom: 57px; }
  body.embedded:has(#invoiceForm, #crmForm, #liForm) .page-container { top: 0; left: 0; }
  body:has(#invoiceForm, #crmForm, #liForm) .page-container > form { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
  /* compact sections */
  body:has(#invoiceForm, #crmForm, #liForm) .xf-section { margin-bottom: 0; }
  body:has(#invoiceForm, #crmForm, #liForm) .xf-head { padding: 6px 12px; min-height: 0; }
  body:has(#invoiceForm, #crmForm, #liForm) .xf-head h3 { font-size: 13px; }
  body:has(#invoiceForm, #crmForm, #liForm) .xf-body { padding: 8px 12px 10px; }
  body:has(#invoiceForm, #crmForm, #liForm) .xf-grid { gap: 6px 10px; }
  body:has(#invoiceForm, #crmForm, #liForm) .xf-field > label { font-size: 11px; margin-bottom: 2px; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  body:has(#invoiceForm, #crmForm, #liForm) .xf-field input:not([type=checkbox]):not([type=radio]),
  body:has(#invoiceForm, #crmForm, #liForm) .xf-field select { height: 30px; font-size: 12.5px; }
  /* the items list is the only part that scrolls */
  body:has(#invoiceForm, #crmForm, #liForm) .xf-section > .xf-head, body:has(#invoiceForm, #crmForm, #liForm) .xf-search { flex: 0 0 auto; }
  body:has(#invoiceForm, #crmForm, #liForm) .xf-items-wrap { flex: 1 1 auto; min-height: 56px; overflow-y: auto; }
  body:has(#invoiceForm, #crmForm, #liForm) .xf-items thead th { position: sticky; top: 0; z-index: 2; }

  /* ---- Digital ---- */
  #invoiceForm > fieldset#formFields { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; gap: 8px; }
  #invoiceForm .xf-section { flex: 0 0 auto; }
  #invoiceForm .xf-section:last-child { flex: 1 1 0; min-height: 120px; display: flex; flex-direction: column; }
  #invoiceForm .xf-section.accent-blue .xf-grid.c4 { grid-template-columns: repeat(8, minmax(0, 1fr)); }
  #invoiceForm .xf-section.accent-blue .xf-grid .span-2 { grid-column: span 2; }
  #invoiceForm .xf-field .hint { display: none; }
  #invoiceForm .xf-two { gap: 8px; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); flex: 0 0 auto; }
  #invoiceForm .xf-two > .xf-section { margin-bottom: 0; }
  #invoiceForm .xf-two > .xf-section:first-child .xf-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  #invoiceForm .xf-two > .xf-section:first-child .xf-grid > :nth-child(4) { order: 3; }
  #invoiceForm .xf-two > .xf-section:first-child .xf-grid > :nth-child(3) { order: 4; }
  #invoiceForm .xf-two > .xf-section:first-child .xf-grid > :nth-child(5) { order: 5; grid-column: span 2; }
  #invoiceForm .xf-two > .xf-section:last-child .xf-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  #invoiceForm .xf-two > .xf-section:last-child .xf-grid > :nth-child(1) { grid-column: span 2; }
  #invoiceForm .xf-two > .xf-section:last-child .xf-grid > :nth-child(3) { grid-column: span 2; }
  #invoiceForm .xf-two > .xf-section:last-child .xf-grid > :nth-child(7) { grid-column: span 2; }
  #invoiceForm .xf-section.accent-amber .xf-body { padding-bottom: 10px; }
  #invoiceForm .xf-foot { padding: 6px 12px 8px; display: block; flex: 0 0 auto; }
  #invoiceForm .xf-totals { width: 100%; display: grid; grid-template-columns: repeat(auto-fit, minmax(105px, 1fr)); gap: 2px 14px; padding: 6px 12px; }
  #invoiceForm .xf-totals .xf-trow { flex-direction: column; align-items: flex-start; padding: 0; border: 0; margin: 0; font-size: 11.5px; line-height: 1.3; }
  #invoiceForm .xf-totals .xf-trow b { font-size: 13.5px; }
  #invoiceForm .xf-totals .xf-trow.sep, #invoiceForm .xf-totals .xf-trow.grand { margin: 0; padding: 0; border: 0; }
  #invoiceForm .xf-totals .xf-trow.grand b { font-size: 16px; }

  /* ---- CRM and Local: main column + summary column fill the height ---- */
  .xf-layout.xf-layout-fill { flex: 1 1 auto; min-height: 0; grid-template-columns: minmax(0, 1fr) 232px; grid-template-rows: minmax(0, 1fr); gap: 10px; }
  .xf-layout.xf-layout-fill > div:first-child { min-height: 0; display: flex; flex-direction: column; gap: 8px; }
  .xf-layout.xf-layout-fill > div:first-child > .xf-section { flex: 0 0 auto; }
  .xf-layout.xf-layout-fill > div:first-child > .xf-section:has(.xf-items-wrap) { flex: 1 1 0; min-height: 150px; display: flex; flex-direction: column; }
  .xf-layout.xf-layout-fill > .xf-side { min-height: 0; overflow-y: auto; }
  .xf-side-fill .xf-trow { padding: 4px 0; }
  .xf-side-actions { padding: 10px 14px 12px; gap: 6px; }
  .xf-side-actions .xf-btn.block { height: 34px; }
  .xf-search { margin: 6px 12px; }
  .xf-search input { height: 34px; }

  /* CRM and Local item tables fit the main column without sideways scroll */
  .xf-items.crm-row1 { min-width: 0 !important; table-layout: auto; }
  .xf-items.crm-row1 thead th { padding: 6px 3px; font-size: 10.5px; }
  .xf-items.crm-row1 tbody td { padding: 4px 2px; }
  .xf-items.crm-row1 th.c-prod { min-width: 120px !important; width: 28%; }
  .xf-items.crm-row1 th.c-colour { min-width: 60px !important; width: 8%; }
  .xf-items.crm-row1 th.c-vendor { min-width: 66px !important; width: 9%; }
  .xf-items.crm-row1 th.c-po { min-width: 60px !important; width: 8%; }
  .xf-items.crm-row1 th.c-price { min-width: 70px !important; }
  .xf-items.crm-row1 th.c-qty { min-width: 92px !important; }
  .xf-items.crm-row1 th.c-disc { min-width: 56px !important; }
  .xf-items.crm-row1 th.c-tax { min-width: 62px !important; }
  .xf-items.crm-row1 th.c-amt { min-width: 76px !important; }
  .xf-items.crm-row1 input, .xf-items.crm-row1 select { font-size: 12px; }
  .xf-items.crm-row1 .xf-qty button { width: 20px; flex: 0 0 20px; }
  .xf-items.crm-row1 .xf-qty input { min-width: 40px; }

  /* ---- Local compaction ---- */
  #liForm .xf-section.accent-blue .xf-grid.c4 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  #liForm .xf-section.accent-blue .xf-grid.c4 > .xf-field { grid-column: span 1; }
  #liForm .xf-section.accent-blue .xf-grid.c4 > .xf-field[style*="span 2"] { grid-column: span 2; }
  #liForm .xf-section:nth-of-type(2) .xf-grid.c4 { grid-template-columns: repeat(8, minmax(0, 1fr)); }
  #liForm .li-switches { margin-bottom: 6px; }
  #liForm .li-terms .xf-body { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 10px; align-items: start; }
  #liForm .li-terms textarea { height: 56px; min-height: 0; resize: none; }
  #liForm .li-terms .xf-field { margin-top: 0 !important; }
}
@media (min-width: 1181px) and (min-height: 600px) and (max-height: 900px) {
  #liForm .li-hint, #crmForm .hint:not(.warn), .xf-side-actions p { display: none; }
}

/* Phase 34b: short unscaled laptop screens (e.g. 1366x768 -> ~625px of page height): shrink the invoice pages a little so they still fit without scrolling */
@media (min-width: 1181px) and (max-height: 690px) and (max-resolution: 1.19dppx) {
  html:has(#invoiceForm, #crmForm, #liForm) { zoom: 0.84; }
}

/* Phase 35: vh units shrink when html{zoom} is used -> white band under the login page / short pages. Compensate by the zoom factor. */
@media (min-resolution: 1.4dppx) and (min-width: 1100px) and (max-width: 1700px) {
  html body .auth-shell { height: calc(100vh / .74) !important; height: calc(100dvh / .74) !important; min-height: 0 !important; }
  html body .auth-main { min-height: calc(100vh / .74) !important; }
  html body .main-content, html body .login-body { min-height: calc(100vh / .74) !important; }
  html body .chat-layout, html body .ai-chat-layout { height: calc(100vh / .74 - 56px) !important; }
}
@media (min-resolution: 1.2dppx) and (max-resolution: 1.39dppx) and (min-width: 1100px) and (max-width: 1700px) {
  html body .auth-shell { height: calc(100vh / .84) !important; height: calc(100dvh / .84) !important; min-height: 0 !important; }
  html body .auth-main { min-height: calc(100vh / .84) !important; }
  html body .main-content, html body .login-body { min-height: calc(100vh / .84) !important; }
  html body .chat-layout, html body .ai-chat-layout { height: calc(100vh / .84 - 56px) !important; }
}
@media (min-width: 1181px) and (max-height: 690px) and (max-resolution: 1.19dppx) {
  html:has(#invoiceForm, #crmForm, #liForm) body .main-content { min-height: calc(100vh / .84) !important; }
}

/* Phase 36: cancelled invoices - print/download switched off; dashboard selection column */
.btn.is-off, .btn.ic.is-off { opacity: .5; cursor: not-allowed; pointer-events: none; }
.data-table tr.is-cancelled td { color: var(--text-muted); }
.data-table tr.is-cancelled .td-primary { text-decoration: line-through; }
.data-table .sel-col { width: 34px; text-align: center; }
.data-table tr.is-selected td { background: #F1F6FF; }

/* Phase 37: Digital invoice printout fits A4 width (columns were cut off at the right edge) */
@media print {
  .invoice-view { font-size: 11px; }
  .invoice-view .item-table-wrap { overflow: visible !important; }
  .invoice-view .review-table { table-layout: fixed; width: 100%; font-size: 9.5px; }
  .invoice-view .review-table th, .invoice-view .review-table td { padding: 4px 4px; word-break: break-word; overflow-wrap: anywhere; white-space: normal; }
  .invoice-view .review-table th:nth-child(1) { width: 12%; }
  .invoice-view .review-table th.col-desc { width: 24%; }
  .invoice-view .review-table th:nth-child(3) { width: 7%; }
  .invoice-view .review-table th:nth-child(4) { width: 8%; }
  .invoice-view .review-table th.col-num { width: 12.25%; }
  .invoice-view .review-table thead { display: table-header-group; }
  .invoice-view .review-table tr { break-inside: avoid; page-break-inside: avoid; }
  .invoice-view .totals-box { max-width: 300px; break-inside: avoid; }
}

/* Phase 38: very light blue gradient on the left bar (same soft blue-to-white look as Tax Configuration).
   Background only - every text, icon and link colour stays exactly as before. */
.sidebar:not(.sidebar-dark) { background: linear-gradient(180deg, #E8F1FF 0%, #F3F8FF 42%, #FFFFFF 100%); border-right-color: #DCE8FA; }
.sidebar:not(.sidebar-dark) .sidebar-brand { border-bottom-color: rgba(37,99,235,.10); }
.sidebar:not(.sidebar-dark) .sidebar-divider { background: rgba(37,99,235,.10); }
.sidebar:not(.sidebar-dark) .sidebar-link:hover { background: rgba(255,255,255,.75); }
.sidebar:not(.sidebar-dark) .sidebar-link.active { background: #FFFFFF; box-shadow: 0 1px 3px rgba(37,99,235,.14); }

/* Phase 39: product picker — the "Enter manually" option is a fixed footer row */
.xf-float-pop .opt.manual{border-top:1px solid #E5E7EB;margin-top:4px;padding-top:8px;display:flex;justify-content:space-between;gap:10px}
.xf-float-pop .opt.manual small{color:#6B7280;font-weight:400}
.xf-combo>i.bi-chevron-down{pointer-events:auto;cursor:pointer;padding:6px 4px;top:3px}
.xf-items.crm-row1 .xf-combo>i.bi-chevron-down{top:50%}
