/*!
 * LMPOS component layer (assets/css/style.css)
 * ---------------------------------------------------------------------------
 * Loaded AFTER assets/css/admin.css (php-admin "AdminCN": compiled Tailwind v4 +
 * shadcn tokens). This file gives every LMPOS semantic class (the HTML that
 * assets/js/script.js renders as strings) the shadcn look, using ONLY the
 * php-admin design tokens, so light and dark mode both work.
 *
 * Layering
 *   1. Unlayered custom properties (top of this file): status colours
 *      --success / --warning / --info / --danger on :root with .dark overrides
 *      (admin.css puts .dark on <html>), plus a print-only reset of the theme
 *      tokens to the light palette. They are unlayered on purpose: admin.css
 *      defines its own tokens unlayered, and layered declarations would lose.
 *   2. Everything else sits in @layer components. admin.css already declares
 *      the order  properties, theme, base, components, utilities  so:
 *        - these rules beat the Tailwind preflight (base layer);
 *        - any Tailwind utility on the same element (utilities layer) beats
 *          these rules. That is why JS can show/hide with the `hidden` utility
 *          on elements that get display:flex/grid here. `.hidden` is NOT
 *          redefined in this file.
 *      Two deliberate `!important`s (an !important in an earlier layer beats
 *      normal utilities): `#toolbar:empty` (hide an empty toolbar even when the
 *      shell gives it a display utility) and `.btn.block:not(.hidden)` (the
 *      Tailwind `.block` utility would otherwise turn the button into
 *      display:block). Both still yield to `.hidden` / [hidden].
 *   3. Element-level rules (h1-h4, p, a, b, small, label, input, select,
 *      textarea, table, th, td, canvas, hr) are scoped to `:where(.lm)`
 *      descendants. The shell puts class="lm" on #view, #toolbar, #modal,
 *      #banner and the login form, so php-admin markup elsewhere (sidebar,
 *      navbar, dropdowns) is never touched. :where() keeps their specificity
 *      at zero, so any LMPOS class (.qty-in, .badge, ...) overrides them.
 *
 * Recipes are copied from php-admin app/Helpers/ui.php (btn_class, input_class,
 * label_class, card_class, badge_class), users/index.php (table, status badges),
 * partials/dialog-open.php (dialog) and dashboard/index.php (stat cards).
 * Radii: md = radius*.8, lg = radius, xl = radius*1.4, 4xl = radius*2.6.
 * shadow-xs = 0 1px 2px 0 rgb(0 0 0/.05); ring-1 foreground/10 = box-shadow.
 * Tints = color-mix(in oklab, <colour> N%, transparent) (Tailwind `/N`).
 */

/* ======================= 1. Status colour tokens ======================== */
:root {
  --success: oklch(0.627 0.194 149.214);  /* green-600 */
  --warning: oklch(0.666 0.179 58.318);   /* amber-600 */
  --info: oklch(0.588 0.158 241.966);     /* sky-600 */
  --danger: var(--destructive);
}
.dark {
  --success: oklch(0.792 0.209 151.711);  /* green-400 */
  --warning: oklch(0.828 0.189 84.429);   /* amber-400 */
  --info: oklch(0.746 0.16 232.661);      /* sky-400 */
  --danger: var(--destructive);
}

/* Print always uses the light palette (same values as admin.css :root). */
@media print {
  :root, .dark {
    color-scheme: light;
    --background: oklch(100% 0 0); --foreground: oklch(14.5% 0 0);
    --card: oklch(100% 0 0); --card-foreground: oklch(14.5% 0 0);
    --popover: oklch(100% 0 0); --popover-foreground: oklch(14.5% 0 0);
    --primary: oklch(20.5% 0 0); --primary-foreground: oklch(98.5% 0 0);
    --secondary: oklch(97% 0 0); --secondary-foreground: oklch(20.5% 0 0);
    --muted: oklch(97% 0 0); --muted-foreground: oklch(55.6% 0 0);
    --accent: oklch(97% 0 0); --accent-foreground: oklch(20.5% 0 0);
    --destructive: oklch(57.7% .245 27.325);
    --border: oklch(92.2% 0 0); --input: oklch(92.2% 0 0); --ring: oklch(70.8% 0 0);
    --success: oklch(0.627 0.194 149.214);
    --warning: oklch(0.666 0.179 58.318);
    --info: oklch(0.588 0.158 241.966);
    --danger: oklch(57.7% .245 27.325);
  }
}

/* ======================= 2. Component layer ============================= */
@layer components {

  /* ---------- Element defaults inside LMPOS content (.lm) ---------- */
  :where(.lm) :where(h1) { margin: 0; font-size: 1.5rem; line-height: 2rem; font-weight: 600; letter-spacing: -.025em; }
  :where(.lm) :where(h2) { margin: 0 0 .75rem; font-size: 1.25rem; line-height: 1.75rem; font-weight: 600; letter-spacing: -.025em; }
  :where(.lm) :where(h3) { margin: 0 0 .75rem; font-size: 1rem; line-height: 1.375; font-weight: 600; }
  :where(.lm) :where(h4) { margin: 0 0 .25rem; font-size: .875rem; line-height: 1.25rem; font-weight: 600; }
  :where(.lm) :where(p) { margin: 0 0 .75rem; }
  :where(.lm) :where(b, strong) { font-weight: 600; }
  :where(.lm) :where(small) { font-size: .75rem; line-height: 1rem; }
  :where(.lm) :where(hr) { margin: 1rem 0; border: 0; border-top: 1px solid var(--border); }
  :where(.lm) :where(canvas) { max-width: 100%; }

  /* Link variant: <a>, .link (clickable ids in tables), .linkbtn (button reset) */
  .link, .linkbtn, :where(.lm) :where(a:not(.btn)) {
    color: var(--primary);
    font-weight: 500;
    text-decoration-line: none;
    text-underline-offset: 4px;
    cursor: pointer;
  }
  .link:hover, .linkbtn:hover, :where(.lm) :where(a:not(.btn)):hover, tr.click:hover .link { text-decoration-line: underline; }
  .linkbtn { padding: 0; border: 0; background: none; font: inherit; font-weight: 500; text-align: left; }
  .linkbtn:focus-visible,
  :where(.lm) :where(a, .link, tr.click, summary, [tabindex]):focus-visible {
    outline: 2px solid color-mix(in oklab, var(--ring) 50%, transparent);
    outline-offset: 2px;
  }

  /* ---------- Form controls (shadcn Input / native select / textarea) ---------- */
  :where(.lm) :where(input:not([type=checkbox], [type=radio], [type=range], [type=color], [type=hidden], [type=button], [type=submit], [type=reset], [type=image]), select, textarea),
  :where(#accSel) {
    width: 100%;
    min-width: 0;
    height: 2.25rem;
    padding: .25rem .625rem;
    border: 1px solid var(--input);
    border-radius: calc(var(--radius) * .8);
    background-color: transparent;
    color: inherit;
    font-size: .875rem;
    line-height: 1.25rem;
    vertical-align: middle;
    box-shadow: 0 1px 2px 0 rgb(0 0 0 / .05);
    outline: none;
    color-scheme: light;
    transition: color .15s cubic-bezier(.4, 0, .2, 1), border-color .15s cubic-bezier(.4, 0, .2, 1), box-shadow .15s cubic-bezier(.4, 0, .2, 1);
  }
  :where(.dark) :where(.lm) :where(input:not([type=checkbox], [type=radio], [type=range], [type=color], [type=hidden], [type=button], [type=submit], [type=reset], [type=image]), select, textarea),
  :where(.dark) :where(#accSel) {
    background-color: color-mix(in oklab, var(--input) 30%, transparent);
    color-scheme: dark;
  }
  :where(.lm) :where(input, textarea)::placeholder { color: var(--muted-foreground); }
  :where(.lm) :where(input, select, textarea):focus-visible,
  :where(#accSel):focus-visible {
    border-color: var(--ring);
    box-shadow: 0 0 0 3px color-mix(in oklab, var(--ring) 50%, transparent), 0 1px 2px 0 rgb(0 0 0 / .05);
  }
  :where(.lm) :where(input, select, textarea)[aria-invalid=true] {
    border-color: var(--destructive);
    box-shadow: 0 0 0 3px color-mix(in oklab, var(--destructive) 20%, transparent);
  }
  :where(.dark) :where(.lm) :where(input, select, textarea)[aria-invalid=true] {
    border-color: color-mix(in oklab, var(--destructive) 50%, transparent);
    box-shadow: 0 0 0 3px color-mix(in oklab, var(--destructive) 40%, transparent);
  }
  :where(.lm) :where(input, select, textarea):disabled,
  :where(#accSel):disabled { cursor: not-allowed; opacity: .5; }
  :where(.lm) :where(input[readonly], textarea[readonly]) { background-color: color-mix(in oklab, var(--muted) 50%, transparent); }
  :where(.lm) :where(input[type=number]) { font-variant-numeric: tabular-nums; }
  :where(.lm) :where(input)::-webkit-calendar-picker-indicator { cursor: pointer; opacity: .6; }
  :where(.lm) :where(input[type=file]) { padding-top: .1875rem; padding-bottom: .1875rem; }
  :where(.lm) :where(input[type=file])::file-selector-button {
    height: 1.75rem; margin-inline-end: .5rem; padding: 0 .25rem; border: 0;
    background: transparent; color: var(--foreground); font-size: .875rem; font-weight: 500;
  }
  :where(.lm) :where(textarea) { height: auto; min-height: 4rem; padding-top: .5rem; padding-bottom: .5rem; resize: vertical; }

  /* Native select: chevron-down (lucide) as a background. A data URI cannot use
     currentColor, so light/dark get the matching muted-foreground grey. */
  :where(.lm) :where(select:not([multiple], [size]:not([size="1"]))),
  :where(#accSel) {
    -webkit-appearance: none;
    appearance: none;
    padding-right: 2rem;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%23737373' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right .5rem center;
    background-size: 1rem 1rem;
    cursor: pointer;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  :where(.dark) :where(.lm) :where(select:not([multiple], [size]:not([size="1"]))),
  :where(.dark) :where(#accSel) {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%23a1a1a1' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  }
  :where(.dark) :where(.lm) :where(select:not([multiple], [size]:not([size="1"]))):hover,
  :where(.dark) :where(#accSel):hover { background-color: color-mix(in oklab, var(--input) 50%, transparent); }
  :where(.lm) :where(select[multiple], select[size]:not([size="1"])) { height: auto; padding: .25rem; }
  :where(.lm) :where(option), :where(#accSel) :where(option) { background-color: var(--popover); color: var(--popover-foreground); }
  /* Account switcher in the navbar (outside .lm): compact native select */
  :where(#accSel) { width: 14rem; max-width: 100%; }

  /* Checkbox / radio */
  :where(.lm) :where(input[type=checkbox], input[type=radio]) {
    width: 1rem; height: 1rem; min-height: 0; margin: 0; flex-shrink: 0;
    vertical-align: middle; accent-color: var(--primary); cursor: pointer;
  }
  :where(.lm) :where(input[type=checkbox], input[type=radio]):focus-visible {
    outline: 2px solid color-mix(in oklab, var(--ring) 50%, transparent);
    outline-offset: 2px;
  }
  :where(.lm) :where(input[type=checkbox], input[type=radio]):disabled { cursor: not-allowed; opacity: .5; }

  /* Inline cell editors (control placed directly in a <td>) are one size smaller (h-8) */
  :where(.lm) :where(td > input:not([type=checkbox], [type=radio]), td > select) { height: 2rem; }

  /* Labels and field stacks */
  :where(.lm) :where(label) {
    display: block;
    margin-bottom: .5rem;
    color: var(--foreground);
    font-size: .875rem;
    line-height: 1;
    font-weight: 500;
    -webkit-user-select: none;
    user-select: none;
  }
  :where(.lm) :where(label):has(> input[type=checkbox], > input[type=radio]) {
    display: flex; align-items: center; gap: .5rem; line-height: 1.25rem; cursor: pointer;
  }
  .field { min-width: 0; margin-bottom: 1rem; }
  .row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 1rem; }
  .row > * { flex: 1 1 160px; min-width: 0; }
  .row > .auto { flex: 0 0 auto; }
  /* Rows mixing .field stacks (with their default bottom margin) and buttons:
     give the buttons the same bottom margin so they line up with the inputs
     (align-items:flex-end). Rows whose fields set an inline margin are left alone. */
  .row:has(> .field:not([style*="margin"])) > :not(.field) { margin-bottom: 1rem; }
  /* ...and since every child of such a row already carries the 1rem bottom margin,
     drop the row gap so wrapped lines are 1rem apart, not 2rem (column gap stays 1rem). */
  .row:has(> .field:not([style*="margin"])) { row-gap: 0; }

  /* ---------- Buttons (shadcn Button) ---------- */
  .btn {
    --btn-bg: var(--background);
    --btn-fg: var(--foreground);
    --btn-border: var(--border);
    --btn-hover-bg: var(--muted);
    --btn-hover-fg: var(--foreground);
    --btn-shadow: 0 1px 2px 0 rgb(0 0 0 / .05);
    --btn-ring: color-mix(in oklab, var(--ring) 50%, transparent);
    --btn-focus-border: var(--ring);
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    gap: .375rem;
    height: 2.25rem;
    padding: 0 .75rem;
    border: 1px solid var(--btn-border);
    border-radius: calc(var(--radius) * .8);
    background-color: var(--btn-bg);
    background-clip: padding-box;
    color: var(--btn-fg);
    font-size: .875rem;
    line-height: 1.25rem;
    font-weight: 500;
    white-space: nowrap;
    text-decoration: none;
    box-shadow: var(--btn-shadow);
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
    outline: none;
    transition: color .15s cubic-bezier(.4, 0, .2, 1), background-color .15s cubic-bezier(.4, 0, .2, 1),
      border-color .15s cubic-bezier(.4, 0, .2, 1), box-shadow .15s cubic-bezier(.4, 0, .2, 1),
      opacity .15s cubic-bezier(.4, 0, .2, 1), transform .15s cubic-bezier(.4, 0, .2, 1);
  }
  /* outline variant in dark mode (dark:border-input dark:bg-input/30 dark:hover:bg-input/50) */
  :where(.dark) .btn {
    --btn-bg: color-mix(in oklab, var(--input) 30%, transparent);
    --btn-border: var(--input);
    --btn-hover-bg: color-mix(in oklab, var(--input) 50%, transparent);
  }
  .btn:hover { background-color: var(--btn-hover-bg); color: var(--btn-hover-fg); }
  .btn:focus-visible { border-color: var(--btn-focus-border); box-shadow: 0 0 0 3px var(--btn-ring), var(--btn-shadow); }
  .btn:active:not([aria-haspopup]) { transform: translateY(1px); }
  .btn:disabled, .btn[aria-disabled=true] { opacity: .5; pointer-events: none; }
  .btn svg { pointer-events: none; flex-shrink: 0; }
  .btn svg:not([class*="size-"]) { width: 1rem; height: 1rem; }

  /* default (filled) variant: .primary, and the legacy .red / .gold */
  .btn:is(.primary, .red, .gold) {
    --btn-bg: var(--primary);
    --btn-fg: var(--primary-foreground);
    --btn-border: transparent;
    --btn-hover-bg: color-mix(in oklab, var(--primary) 80%, transparent);
    --btn-hover-fg: var(--primary-foreground);
    --btn-shadow: 0 0 #0000;
  }
  .btn.secondary {
    --btn-bg: var(--secondary);
    --btn-fg: var(--secondary-foreground);
    --btn-border: transparent;
    --btn-hover-bg: color-mix(in oklch, var(--secondary), var(--foreground) 5%);
    --btn-hover-fg: var(--secondary-foreground);
    --btn-shadow: 0 0 #0000;
  }
  .btn.ghost {
    --btn-bg: transparent;
    --btn-border: transparent;
    --btn-hover-bg: var(--muted);
    --btn-hover-fg: var(--foreground);
    --btn-shadow: 0 0 #0000;
  }
  :where(.dark) .btn.ghost { --btn-hover-bg: color-mix(in oklab, var(--muted) 50%, transparent); }
  .btn.danger {
    --btn-bg: color-mix(in oklab, var(--destructive) 10%, transparent);
    --btn-fg: var(--destructive);
    --btn-border: transparent;
    --btn-hover-bg: color-mix(in oklab, var(--destructive) 20%, transparent);
    --btn-hover-fg: var(--destructive);
    --btn-shadow: 0 0 #0000;
    --btn-ring: color-mix(in oklab, var(--destructive) 20%, transparent);
    --btn-focus-border: color-mix(in oklab, var(--destructive) 40%, transparent);
  }
  :where(.dark) .btn.danger {
    --btn-bg: color-mix(in oklab, var(--destructive) 20%, transparent);
    --btn-hover-bg: color-mix(in oklab, var(--destructive) 30%, transparent);
    --btn-ring: color-mix(in oklab, var(--destructive) 40%, transparent);
  }
  /* ghost + danger = transparent red text button (row "Delete"/"Reverse") */
  .btn.ghost.danger { --btn-bg: transparent; --btn-hover-bg: color-mix(in oklab, var(--destructive) 10%, transparent); }

  /* sizes */
  /* font-size restated: the .small text utility below would otherwise shrink sm buttons to 13px (shadcn sm keeps text-sm) */
  .btn.small { height: 2rem; gap: .25rem; padding: 0 .625rem; border-radius: min(calc(var(--radius) * .8), 10px); font-size: .875rem; line-height: 1.25rem; }
  .btn.xs { height: 1.5rem; gap: .25rem; padding: 0 .5rem; border-radius: min(calc(var(--radius) * .8), 8px); font-size: .75rem; line-height: 1rem; }
  .btn.xs svg:not([class*="size-"]) { width: .75rem; height: .75rem; }
  .btn.icon { width: 2.25rem; padding: 0; }
  .btn.small.icon { width: 2rem; }
  .btn.xs.icon { width: 1.5rem; }
  .btn.block { width: 100%; height: 2.5rem; }
  .btn.block:not(.hidden) { display: flex !important; } /* beats the Tailwind `.block` utility */
  :where(td, th, p) > .btn + .btn { margin-inline-start: .25rem; }

  /* ---------- Cards ---------- */
  .panel {
    min-width: 0;
    margin-bottom: 1.5rem;
    overflow: hidden;
    border-radius: calc(var(--radius) * 1.4);
    background-color: var(--card);
    color: var(--card-foreground);
    font-size: .875rem;
    line-height: 1.25rem;
    box-shadow: 0 0 0 1px color-mix(in oklab, var(--foreground) 10%, transparent), 0 1px 2px 0 rgb(0 0 0 / .05);
  }
  .panel > .ph {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: .75rem 1rem;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
  }
  .panel > .pb { padding: 1.5rem; }
  .panel > .pb:has(> .tbl-wrap:only-child, > table:only-child) { padding: 0; }
  .panel:not(:has(> .ph, > .pb, > .issue-head)) { padding: 1.5rem; }
  .panel h3 { margin: 0 0 .75rem; font-size: 1rem; line-height: 1.375; font-weight: 600; }
  .panel > .ph h3 { margin: 0; }
  .sub { margin: 0 0 .75rem; color: var(--muted-foreground); font-size: .875rem; line-height: 1.25rem; }
  h3 + .sub { margin-top: -.5rem; }
  .ph .sub { margin: .25rem 0 0; }
  .section-title {
    margin: .25rem 0 .75rem;
    color: var(--muted-foreground);
    font-size: .875rem;
    line-height: 1.25rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
  }

  /* ---------- Page header / toolbar ---------- */
  .page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; }
  .page-head h1, .page-title { margin: 0; font-size: 1.5rem; line-height: 2rem; font-weight: 600; letter-spacing: -.025em; }
  .page-desc { margin: .25rem 0 0; color: var(--muted-foreground); font-size: .875rem; line-height: 1.25rem; }
  .toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
  #toolbar:empty, #toolbar:has(#topControls:empty) { display: none !important; }
  #topControls { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
  #topControls > * { flex: 0 1 auto; width: auto; margin: 0; }
  #topControls > select { min-width: 9rem; }
  #view { width: 100%; min-width: 0; }
  #view > :last-child { margin-bottom: 0; }

  /* ---------- Tables ---------- */
  .tbl-wrap { position: relative; width: 100%; overflow-x: auto; }
  :where(.lm) :where(table) { width: 100%; border-collapse: collapse; caption-side: bottom; font-size: .875rem; line-height: 1.25rem; }
  :where(.lm) :where(tr) { border-bottom: 1px solid var(--border); transition: background-color .15s cubic-bezier(.4, 0, .2, 1); }
  :where(.lm) :where(tbody tr:last-child) { border-bottom: 0; }
  :where(.lm) :where(tbody tr):hover { background-color: color-mix(in oklab, var(--muted) 50%, transparent); }
  :where(.lm) :where(th) {
    height: 2.5rem;
    padding: 0 .5rem;
    color: var(--muted-foreground);
    font-weight: 500;
    text-align: left;
    vertical-align: middle;
    white-space: nowrap;
  }
  :where(.lm) :where(td) { height: 3rem; padding: .5rem; vertical-align: middle; }
  /* flush tables (directly in a card) line up with php-admin's first:pl-4 last:px-4 */
  :where(.lm) :where(th, td):first-child { padding-left: 1rem; }
  :where(.lm) :where(th, td):last-child { padding-right: 1rem; }
  /* tables inside padded containers keep the plain px-2 cell padding */
  :where(.pb:not(:has(> .tbl-wrap:only-child, > table:only-child)), .box, .paybox, .panel:not(:has(> .ph, > .pb, > .issue-head))) :where(th, td):first-child { padding-left: .5rem; }
  :where(.pb:not(:has(> .tbl-wrap:only-child, > table:only-child)), .box, .paybox, .panel:not(:has(> .ph, > .pb, > .issue-head))) :where(th, td):last-child { padding-right: .5rem; }
  tr.click { cursor: pointer; }
  tr.editing > td { background-color: color-mix(in oklab, var(--muted) 30%, transparent); }
  tr.total > td { border-top: 1px solid var(--border); background-color: color-mix(in oklab, var(--muted) 40%, transparent); font-weight: 600; }
  td.n, th.n { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
  td.m { font-family: var(--font-geist-mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace); font-size: .8125rem; }

  /* ---------- Badges & pill ---------- */
  .badge {
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    gap: .25rem;
    width: fit-content;
    height: 1.25rem;
    padding: .125rem .5rem;
    overflow: hidden;
    border: 1px solid transparent;
    border-radius: calc(var(--radius) * 2.6);
    background-color: var(--secondary);
    color: var(--secondary-foreground);
    font-size: .75rem;
    line-height: 1rem;
    font-weight: 500;
    white-space: nowrap;
    vertical-align: middle;
  }
  .badge > svg { width: .75rem; height: .75rem; pointer-events: none; }
  .badge:is(.success, .APPROVED, .COMPLETED, .PASS, .CONFIRMED, .RECEIVED, .SETTLED) {
    background-color: color-mix(in oklab, var(--success) 10%, transparent);
    color: var(--success);
  }
  .badge:is(.warning, .SUBMITTED, .PENDING_APPROVAL, .WARNING, .PARTIALLY_RECEIVED, .PART) {
    background-color: color-mix(in oklab, var(--warning) 10%, transparent);
    color: var(--warning);
  }
  .badge:is(.danger, .REJECTED, .VOID, .ERROR, .REVERSED, .REVERSAL, .CANCELLED) {
    background-color: color-mix(in oklab, var(--destructive) 10%, transparent);
    color: var(--destructive);
  }
  :where(.dark) .badge:is(.danger, .REJECTED, .VOID, .ERROR, .REVERSED, .REVERSAL, .CANCELLED) {
    background-color: color-mix(in oklab, var(--destructive) 20%, transparent);
  }
  .badge.info { background-color: color-mix(in oklab, var(--info) 10%, transparent); color: var(--info); }

  /* subscription status pill (navbar #subPill; JS sets className = 'pill [warn|bad]') */
  .pill {
    display: inline-flex;
    align-items: center;
    gap: .375rem;
    height: 1.5rem;
    padding: 0 .625rem;
    border: 1px solid color-mix(in oklab, var(--success) 25%, transparent);
    border-radius: calc(var(--radius) * 2.6);
    background-color: color-mix(in oklab, var(--success) 10%, transparent);
    color: var(--success);
    font-size: .75rem;
    line-height: 1rem;
    font-weight: 500;
    white-space: nowrap;
  }
  .pill::before { content: ""; flex-shrink: 0; width: 6px; height: 6px; border-radius: 9999px; background-color: currentColor; }
  .pill.warn { border-color: color-mix(in oklab, var(--warning) 25%, transparent); background-color: color-mix(in oklab, var(--warning) 10%, transparent); color: var(--warning); }
  .pill.bad { border-color: color-mix(in oklab, var(--destructive) 25%, transparent); background-color: color-mix(in oklab, var(--destructive) 10%, transparent); color: var(--destructive); }

  /* account name chip (#accName, non super-admin) and the signed-in user block */
  .acc-name {
    display: inline-block;
    max-width: 16rem;
    height: 2.25rem;
    padding: 0 .75rem;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) * .8);
    background-color: color-mix(in oklab, var(--muted) 50%, transparent);
    font-size: .875rem;
    line-height: calc(2.25rem - 2px);
    font-weight: 500;
    white-space: nowrap;
    text-overflow: ellipsis;
    vertical-align: middle;
  }
  .who { display: flex; flex-direction: column; min-width: 0; color: var(--muted-foreground); font-size: .75rem; line-height: 1rem; }

  /* ---------- KPI stat cards ---------- */
  .kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
  .kpi {
    display: flow-root;
    min-width: 0;
    padding: 1.25rem;
    border: 0;
    border-radius: calc(var(--radius) * 1.4);
    background-color: var(--card);
    color: var(--card-foreground);
    font-size: .875rem;
    line-height: 1.25rem;
    text-align: left;
    box-shadow: 0 0 0 1px color-mix(in oklab, var(--foreground) 10%, transparent), 0 1px 2px 0 rgb(0 0 0 / .05);
  }
  .kpi .k { color: var(--muted-foreground); font-size: .875rem; line-height: 1.25rem; }
  .kpi .v { margin-top: .25rem; font-size: 1.5rem; line-height: 2rem; font-weight: 600; font-variant-numeric: tabular-nums; }
  .kpi .d { margin-top: .25rem; color: var(--muted-foreground); font-size: .75rem; line-height: 1rem; }
  /* optional icon box: put <div class="ic"> FIRST inside .kpi, it floats top-right */
  .kpi .ic {
    float: right;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    margin: 0 0 .5rem .75rem;
    border-radius: calc(var(--radius) * .8);
    background-color: color-mix(in oklab, var(--primary) 10%, transparent);
    color: var(--primary);
  }
  .kpi .ic > svg { flex-shrink: 0; }
  .kpi .ic > svg:not([class*="size-"]) { width: 1.1rem; height: 1.1rem; }
  button.kpi {
    width: 100%;
    font: inherit;
    cursor: pointer;
    transition: background-color .15s cubic-bezier(.4, 0, .2, 1), box-shadow .15s cubic-bezier(.4, 0, .2, 1);
  }
  button.kpi:hover {
    background-color: color-mix(in oklab, var(--muted) 40%, var(--card));
    box-shadow: 0 0 0 1px color-mix(in oklab, var(--foreground) 20%, transparent), 0 1px 2px 0 rgb(0 0 0 / .05);
  }
  button.kpi:focus-visible {
    outline: none;
    box-shadow: 0 0 0 1px var(--ring), 0 0 0 4px color-mix(in oklab, var(--ring) 50%, transparent);
  }

  /* ---------- Strip: one card split into equal cells ---------- */
  .strip {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    margin-bottom: 1.5rem;
    overflow: hidden;
    border-radius: calc(var(--radius) * 1.4);
    background-color: var(--card);
    color: var(--card-foreground);
    box-shadow: 0 0 0 1px color-mix(in oklab, var(--foreground) 10%, transparent), 0 1px 2px 0 rgb(0 0 0 / .05);
  }
  /* each cell draws a 1px line on its left and top; lines on the outer edge are
     clipped by the card, so separators stay correct for 4, 2 or 1 columns */
  /* five figures (Day settlement) share one row on wide screens; narrower screens keep the 2 / 1 column rules below */
  @media (min-width: 1101px) { .strip:has(> .cell:nth-child(5)) { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
  .strip > .cell { min-width: 0; min-height: 5.75rem; padding: 1.25rem 1.5rem; box-shadow: -1px 0 0 0 var(--border), 0 -1px 0 0 var(--border); }
  .strip .k { color: var(--muted-foreground); font-size: .875rem; line-height: 1.25rem; }
  .strip .v { margin-top: .25rem; font-size: 1.5rem; line-height: 2rem; font-weight: 600; font-variant-numeric: tabular-nums; }
  .strip .d { margin-top: .25rem; color: var(--muted-foreground); font-size: .75rem; line-height: 1rem; }

  /* ---------- Profit flow (ticket with stubs) ---------- */
  .ticket {
    display: flex;
    margin-bottom: 1.5rem;
    overflow-x: auto;
    border-radius: calc(var(--radius) * 1.4);
    background-color: var(--card);
    color: var(--card-foreground);
    box-shadow: 0 0 0 1px color-mix(in oklab, var(--foreground) 10%, transparent), 0 1px 2px 0 rgb(0 0 0 / .05);
  }
  .ticket .stub { position: relative; flex: 1 0 150px; padding: 1rem 1.25rem; }
  .ticket .stub + .stub { border-left: 2px dashed var(--border); }
  .ticket .stub .k { color: var(--muted-foreground); font-size: .8125rem; line-height: 1.25rem; }
  .ticket .stub .v { margin-top: .25rem; font-size: 1.25rem; line-height: 1.75rem; font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
  .ticket .stub .op {
    position: absolute;
    top: 50%;
    left: calc(-.6875rem - 1px);
    z-index: 1;
    display: grid;
    place-items: center;
    width: 1.375rem;
    height: 1.375rem;
    border-radius: 9999px;
    background-color: var(--background);
    box-shadow: 0 0 0 1px var(--border);
    color: var(--muted-foreground);
    font-size: .75rem;
    line-height: 1;
    font-weight: 600;
    transform: translateY(-50%);
  }
  .ticket .stub.result { background-color: var(--primary); color: var(--primary-foreground); }
  .ticket .stub.result .k { color: color-mix(in oklab, var(--primary-foreground) 70%, transparent); }
  .flowline { display: flex; flex-wrap: wrap; align-items: baseline; gap: .375rem .875rem; font-size: .875rem; font-variant-numeric: tabular-nums; }
  .flowline b { font-size: 1.125rem; line-height: 1.75rem; font-weight: 600; }
  .flowline .op { color: var(--muted-foreground); }

  /* ---------- Layout grids ---------- */
  .grid2, .grid3 { display: grid; gap: 1.5rem; margin-bottom: 1.5rem; }
  .grid2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  :is(.grid2, .grid3) > * { min-width: 0; }
  :is(.grid2, .grid3) > .panel { margin-bottom: 0; }

  /* ---------- Issue tickets (POS) / returns: order layout ---------- */
  .issue-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; align-items: start; gap: 1.5rem; margin-bottom: 1.5rem; }
  .issue-layout > * { min-width: 0; }
  .issue-layout > .panel { margin-bottom: 0; }
  .issue-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 1rem; padding: 1rem 1.5rem; border-bottom: 1px solid var(--border); }
  .issue-head .field { margin: 0; }
  .paybox {
    position: sticky;
    top: 5rem;
    padding: 1.5rem;
    border-radius: calc(var(--radius) * 1.4);
    background-color: var(--card);
    color: var(--card-foreground);
    font-size: .875rem;
    line-height: 1.25rem;
    box-shadow: 0 0 0 1px color-mix(in oklab, var(--foreground) 10%, transparent), 0 1px 2px 0 rgb(0 0 0 / .05);
  }
  .paybox > .btn.block { margin-top: .75rem; }
  /* Issue tickets: the Summary never grows past the screen, so it stays in view while the item sheet scrolls */
  #iPay.paybox { max-height: calc(100vh - 6rem); max-height: calc(100dvh - 6rem); overflow-y: auto; overscroll-behavior: contain; }
  .ln { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; padding: .5rem 0; border-bottom: 1px dashed var(--border); }
  .ln span:last-child { font-family: var(--font-geist-mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace); font-variant-numeric: tabular-nums; white-space: nowrap; }
  .ln.big { border-bottom: 0; font-size: 1.125rem; line-height: 1.75rem; font-weight: 600; }
  .ln.muted span { color: var(--muted-foreground); }
  .credit { margin: .5rem 0; padding: .625rem .75rem; border-radius: var(--radius); background-color: var(--muted); font-size: .875rem; line-height: 1.25rem; }
  .credit:empty { display: none; }
  .credit.over { background-color: color-mix(in oklab, var(--destructive) 10%, transparent); color: var(--destructive); }
  .totals { margin-top: .75rem; }
  .totals > div { display: flex; justify-content: space-between; gap: 1rem; padding: .25rem 0; font-variant-numeric: tabular-nums; }
  .totals .big { margin-top: .25rem; padding-top: .5rem; border-top: 2px solid var(--border); font-size: 1.125rem; line-height: 1.75rem; font-weight: 600; }

  /* ---------- Feedback: alerts, banner, empty and error states ---------- */
  .alerts > div,
  #banner,
  .page-error {
    position: relative;
    padding: .75rem 1rem .75rem 2.625rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background-color: var(--card);
    color: var(--card-foreground);
    font-size: .875rem;
    line-height: 1.25rem;
  }
  .alerts > div::before,
  #banner::before,
  .page-error::before {
    content: "";
    position: absolute;
    top: .875rem;
    left: 1rem;
    width: 1rem;
    height: 1rem;
    background-color: currentColor;
    /* lucide "info" */
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='M12 16v-4'/%3E%3Cpath d='M12 8h.01'/%3E%3C/svg%3E") center / contain no-repeat;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='M12 16v-4'/%3E%3Cpath d='M12 8h.01'/%3E%3C/svg%3E") center / contain no-repeat;
  }
  .alerts > div { margin-bottom: .5rem; }
  .alerts > div:last-child { margin-bottom: 0; }
  .alerts > div:not([class]) { color: var(--muted-foreground); }
  .alerts > .warning, #banner {
    border-color: color-mix(in oklab, var(--warning) 30%, transparent);
    background-color: color-mix(in oklab, var(--warning) 10%, transparent);
    color: color-mix(in oklab, var(--warning) 75%, var(--foreground));
  }
  .alerts > .error, .page-error {
    border-color: color-mix(in oklab, var(--destructive) 30%, transparent);
    background-color: color-mix(in oklab, var(--destructive) 10%, transparent);
    color: var(--destructive);
  }
  .alerts > .info { border-color: color-mix(in oklab, var(--info) 30%, transparent); background-color: color-mix(in oklab, var(--info) 10%, transparent); color: var(--info); }
  .alerts > .warning::before, #banner::before {
    /* lucide "triangle-alert" */
    -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3'/%3E%3Cpath d='M12 9v4'/%3E%3Cpath d='M12 17h.01'/%3E%3C/svg%3E");
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3'/%3E%3Cpath d='M12 9v4'/%3E%3Cpath d='M12 17h.01'/%3E%3C/svg%3E");
  }
  .alerts > .error::before, .page-error::before {
    /* lucide "circle-alert" */
    -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='M12 8v4'/%3E%3Cpath d='M12 16h.01'/%3E%3C/svg%3E");
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='M12 8v4'/%3E%3Cpath d='M12 16h.01'/%3E%3C/svg%3E");
  }
  /* subscription banner: full-width warning alert at the top of <main> (JS toggles .hidden) */
  #banner { display: block; width: 100%; margin-bottom: 1.5rem; font-weight: 500; }
  .empty { padding: 2.5rem 1rem; color: var(--muted-foreground); font-size: .875rem; line-height: 1.25rem; text-align: center; }

  /* ---------- Dialog (#modal overlay > .box content) ---------- */
  #modal {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: grid;
    place-items: center;
    padding: 1rem;
    background-color: rgb(0 0 0 / .1);
    animation: lm-fade-in .1s cubic-bezier(0, 0, .2, 1);
  }
  @supports ((-webkit-backdrop-filter: blur(4px)) or (backdrop-filter: blur(4px))) {
    #modal { -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
  }
  #modal .box {
    position: relative;
    width: 100%;
    max-width: 900px;
    max-height: 90vh;
    max-height: 90dvh;
    overflow: auto;
    padding: 1.5rem;
    border-radius: calc(var(--radius) * 1.4);
    background-color: var(--popover);
    color: var(--popover-foreground);
    font-size: .875rem;
    line-height: 1.25rem;
    outline: none;
    box-shadow: 0 0 0 1px color-mix(in oklab, var(--foreground) 10%, transparent),
      0 10px 15px -3px rgb(0 0 0 / .1), 0 4px 6px -4px rgb(0 0 0 / .1);
    animation: lm-dialog-in .1s cubic-bezier(0, 0, .2, 1);
  }
  #modal .head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
  #modal .head h3 { margin: 0; font-size: 1.125rem; line-height: 1.25; font-weight: 600; }
  #modalClose { flex-shrink: 0; margin: -.375rem -.5rem 0 0; }
  .dlg-foot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .5rem; margin-top: 1.5rem; }
  @keyframes lm-fade-in { from { opacity: 0; } }
  @keyframes lm-dialog-in { from { opacity: 0; transform: scale(.95); } }

  /* ---------- Toasts (sonner look) ---------- */
  #toast {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 70;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: .5rem;
    max-width: calc(100vw - 2rem);
    pointer-events: none;
  }
  #toast > div {
    display: flex;
    align-items: flex-start;
    gap: .5rem;
    width: 356px;
    max-width: min(380px, 100%);
    padding: .75rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background-color: var(--popover);
    color: var(--popover-foreground);
    font-size: .875rem;
    line-height: 1.25rem;
    font-weight: 500;
    pointer-events: auto;
    box-shadow: 0 10px 15px -3px rgb(0 0 0 / .1), 0 4px 6px -4px rgb(0 0 0 / .1);
    animation: lm-toast-in .25s cubic-bezier(.16, 1, .3, 1);
  }
  #toast > div > svg { flex-shrink: 0; width: 1rem; height: 1rem; margin-top: .125rem; }
  #toast > div.err { color: var(--destructive); }
  @keyframes lm-toast-in { from { opacity: 0; transform: translateY(.75rem); } }

  /* ---------- Loading bar (JS toggles .hidden) ---------- */
  #loading {
    position: fixed;
    top: 0;
    right: 0;
    left: 0;
    z-index: 80;
    height: 2px;
    overflow: hidden;
    background-color: color-mix(in oklab, var(--primary) 15%, transparent);
    pointer-events: none;
  }
  #loading::before {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: 40%;
    background-color: var(--primary);
    animation: lm-loading 1s cubic-bezier(.4, 0, .2, 1) infinite;
  }
  @keyframes lm-loading { from { transform: translateX(-100%); } to { transform: translateX(250%); } }

  /* ---------- Receipt / printable notes ---------- */
  .receipt { max-width: 320px; margin: 0 auto; font-size: .875rem; line-height: 1.25rem; }
  .receipt h4 { margin: 0 0 .25rem; font-size: 1rem; line-height: 1.5rem; text-align: center; }
  .receipt .c { color: var(--muted-foreground); text-align: center; }
  .receipt :is(th, td) { height: auto; padding: .1875rem .125rem; }

  /* ---------- Text utilities (last, so they win over component colours) ---------- */
  .muted { color: var(--muted-foreground); }
  .small { font-size: .8125rem; line-height: 1.25rem; }
  .item-sub { display: block; margin-top: .125rem; color: var(--muted-foreground); font-size: .75rem; line-height: 1rem; font-weight: 400; }
  .qty-in { max-width: 90px; text-align: left; }
  .serial-in { max-width: 120px; }
  .mono { font-family: var(--font-geist-mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace); font-variant-numeric: tabular-nums; }
  .num { font-variant-numeric: tabular-nums; }
  .neg, .mv-out { color: var(--destructive); }
  .pos, .green, .mv-in { color: var(--success); }
  .warn-text { color: var(--warning); }
  .amber { color: var(--warning); }

  /* ---------- Responsive ---------- */
  @media (max-width: 1100px) {
    .issue-layout, .grid2, .grid3 { grid-template-columns: minmax(0, 1fr); }
    .paybox { position: static; }
    #iPay.paybox { max-height: none; overflow: visible; }
    .strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  }
  @media (max-width: 767.98px) {
    /* shadcn inputs are text-base below md (also stops iOS zoom-on-focus) */
    :where(.lm) :where(input:not([type=checkbox], [type=radio], [type=range], [type=color], [type=hidden], [type=button], [type=submit], [type=reset], [type=image]), select, textarea),
    :where(#accSel) { font-size: 1rem; }
  }
  @media (max-width: 760px) {
    .panel > .ph { padding: .875rem 1rem; }
    .panel > .pb { padding: 1rem; }
    .panel:not(:has(> .ph, > .pb, > .issue-head)) { padding: 1rem; }
    .paybox { padding: 1rem; }
    .issue-head { padding: 1rem; }
    :where(.lm) :where(th, td):first-child { padding-left: .75rem; }
    :where(.lm) :where(th, td):last-child { padding-right: .75rem; }
    :where(.pb:not(:has(> .tbl-wrap:only-child, > table:only-child)), .box, .paybox, .panel:not(:has(> .ph, > .pb, > .issue-head))) :where(th, td):first-child { padding-left: .5rem; }
    :where(.pb:not(:has(> .tbl-wrap:only-child, > table:only-child)), .box, .paybox, .panel:not(:has(> .ph, > .pb, > .issue-head))) :where(th, td):last-child { padding-right: .5rem; }
    .kpis { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
    .ticket .stub { flex-basis: 140px; }
    .page-head h1, .page-title { font-size: 1.25rem; line-height: 1.75rem; }
  }
  @media (max-width: 760px) and (pointer: coarse) {
    /* larger touch targets on phones / tablets */
    .btn, .btn.small, .btn.xs { height: auto; min-height: 2.5rem; }
    .btn.icon { min-width: 2.5rem; }
  }
  @media (max-width: 640px) {
    .strip { grid-template-columns: minmax(0, 1fr); }
    .page-head { flex-direction: column; align-items: stretch; }
    #toolbar { width: 100%; }
    #topControls > * { flex: 1 1 9rem; }
    #modal { padding: .5rem; }
    #modal .box { max-height: calc(100vh - 1rem); max-height: calc(100dvh - 1rem); padding: 1rem; }
    .dlg-foot { flex-direction: column-reverse; }
    .dlg-foot > .btn { width: 100%; }
    #toast { left: 1rem; align-items: stretch; }
    #toast > div { width: auto; max-width: none; }
  }
  @media (prefers-reduced-motion: reduce) {
    #modal, #modal .box, #toast > div { animation: none; }
    #loading::before { width: 100%; opacity: .6; animation: none; }
    .btn:active:not([aria-haspopup]) { transform: none; }
  }

  /* ---------- Print ---------- */
  @media print {
    /* original LMPOS rule: only .print-area is visible, drawn from the page top-left */
    body * { visibility: hidden; }
    .print-area, .print-area * { visibility: visible; }
    .print-area { position: absolute; top: 0; left: 0; width: 100%; }
    .no-print { display: none !important; }
    /* Where :has() exists: collapse everything that is neither a printable area,
       inside one, nor an ancestor of one (no blank trailing pages), neutralise the
       ancestors' positioning / clipping / padding, and let the area flow normally
       so it can run over several pages (the dialog .box no longer clips at 90vh). */
    @supports selector(:has(a)) {
      body *:not(.print-area, .print-area *, :has(.print-area)) { display: none !important; }
      body *:has(.print-area) {
        position: static !important;
        inset: auto !important;
        width: auto !important;
        max-width: none !important;
        height: auto !important;
        min-height: 0 !important;
        max-height: none !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: visible !important;
        border: 0 !important;
        border-radius: 0 !important;
        background: none !important;
        box-shadow: none !important;
        transform: none !important;
        filter: none !important;
        -webkit-backdrop-filter: none !important;
        backdrop-filter: none !important;
        animation: none !important;
      }
      .print-area { position: static; }
    }
    .panel, .kpi, .strip, .ticket, .paybox { border: 1px solid var(--border); box-shadow: none; break-inside: avoid; }
    .tbl-wrap { overflow: visible; }
    :where(.lm) :where(tr) { break-inside: avoid; }
    :where(.lm) :where(tbody tr):hover { background-color: transparent; }
  }
}

/* ======================= 3. Core helper additions ========================
 * Used by the shared helpers in assets/js/script.js (see HELPERS.md):
 * modal(title, html, size), loading / pending / no-access states, emptyState(),
 * facts(), form() checkbox fields, table() empty row and the note dialog.
 */
@layer components {
  /* dialog widths: modal(title, html, 'sm' | 'md' | 'lg'); no size = 900px */
  #modal .box.sm { max-width: 28rem; }
  #modal .box.md { max-width: 44rem; }
  #modal .box.lg { max-width: 72rem; }
  .row + .dlg-foot { margin-top: .5rem; } /* the fields above already keep 1rem below them */

  /* centred state card (screen not migrated yet, no access) and the icon tile shared with .empty */
  .panel > .pb.state { display: flex; flex-direction: column; align-items: center; gap: .5rem; padding: 2.5rem 1.5rem; text-align: center; }
  .state h3 { margin: 0; font-size: 1rem; line-height: 1.5rem; font-weight: 600; }
  .state p { max-width: 36rem; margin: 0; }
  .state .toolbar { justify-content: center; margin-top: .75rem; }
  .state-ic, .empty-ic {
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
    width: 2.5rem; height: 2.5rem; margin-bottom: .5rem;
    border-radius: var(--radius); background-color: var(--muted); color: var(--foreground);
  }
  .empty > .empty-ic { margin: 0 auto .75rem; }
  .state-ic > svg, .empty-ic > svg { width: 1.25rem; height: 1.25rem; }

  /* spinning icon (loading card) */
  .spin { animation: lm-spin 1s linear infinite; }
  @keyframes lm-spin { to { transform: rotate(360deg); } }

  /* detail facts: <dl class="facts"><div><dt>Label</dt><dd>Value</dd></div>…</dl> */
  .facts {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr)); gap: 1rem 1.5rem;
    margin: 0 0 1.5rem; padding: 1rem 1.25rem;
    border: 1px solid var(--border); border-radius: var(--radius);
    background-color: color-mix(in oklab, var(--muted) 40%, transparent);
  }
  .facts > div { min-width: 0; }
  .facts dt { color: var(--muted-foreground); font-size: .75rem; line-height: 1rem; font-weight: 500; }
  .facts dd { margin: .25rem 0 0; font-size: .875rem; line-height: 1.25rem; font-weight: 500; overflow-wrap: anywhere; }
  .note-doc .tbl-wrap { margin-bottom: 1.5rem; }
  .note-foot { margin: 0; color: var(--muted-foreground); font-size: .8125rem; text-align: center; }

  /* form() checkbox field: box + label on one line, centred on the neighbouring inputs */
  .field.check > label { min-height: 2.25rem; margin: 0; }

  /* table() with no rows */
  :where(tr.empty-row) > td { height: 6rem; text-align: center; }
  :where(.lm) :where(tbody tr.empty-row):hover { background-color: transparent; }

  /* toast text next to its icon */
  #toast > div > span { min-width: 0; overflow-wrap: anywhere; }

  /* ---------- Tomorrow's order: day picker ---------- */
  .ord-modes { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: .75rem; }
  .ord-days { display: grid; grid-template-columns: repeat(auto-fill, minmax(7.5rem, 1fr)); gap: .5rem; }
  .ord-day { display: flex; align-items: center; gap: .5rem; padding: .5rem .625rem; border: 1px solid var(--border); border-radius: var(--radius, .5rem); cursor: pointer; font-size: .875rem; }
  .ord-day > span { display: flex; flex-direction: column; line-height: 1.2; }
  .ord-day.on { border-color: var(--primary); background-color: color-mix(in oklab, var(--primary) 8%, transparent); }
  .ord-day input { width: auto; margin: 0; }
  .ord-opts { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem 1.25rem; margin-top: .75rem; font-size: .875rem; }
  .ord-opts label { display: flex; align-items: center; gap: .5rem; }
  .ord-opts input { width: 5.5rem; }
  tfoot th { border-top: 2px solid var(--border); }
  /* the order quantity stays in view while the day columns scroll */
  .ord-tbl.with-qty :is(th, td):last-child { position: sticky; right: 0; z-index: 1; background-color: var(--card); box-shadow: -1px 0 0 var(--border); }

  /* ---------- Settings tabs ---------- */
  .set-tabs { display: flex; gap: .25rem; margin-bottom: 1.25rem; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: thin; }
  .set-tabs button { display: inline-flex; align-items: center; gap: .5rem; flex: 0 0 auto; padding: .625rem .875rem; margin-bottom: -1px;
    border: 0; border-bottom: 2px solid transparent; background: none; color: var(--muted-foreground); font: inherit; font-size: .875rem; font-weight: 500; cursor: pointer; white-space: nowrap; }
  .set-tabs button svg { width: 1rem; height: 1rem; }
  .set-tabs button:hover { color: var(--foreground); }
  .set-tabs button.on { color: var(--foreground); border-bottom-color: var(--foreground); }
  .set-tabs button:focus-visible { outline: 2px solid var(--ring); outline-offset: -2px; border-radius: calc(var(--radius) - 4px); }
  .set-tab[hidden] { display: none; }

  /* ---------- Distributor settings: shared items picker, SMS gateway fields ---------- */
  .tn-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr)); gap: .375rem 1rem; max-height: 22rem; overflow-y: auto;
    padding: .75rem; border: 1px solid var(--border); border-radius: var(--radius); font-size: .875rem; }
  .tn-pick[hidden], #tnCustom[hidden], #tnWaApi[hidden], .field[hidden] { display: none; }
  /* Requested tickets grid against the repeat day's MINs */
  .rq-in.rq-miss { background-color: color-mix(in oklab, var(--warning, #f59e0b) 22%, transparent); border-color: var(--warning, #f59e0b); }
  .rq-in.rq-diff { background-color: color-mix(in oklab, var(--destructive, #dc2626) 14%, transparent); border-color: var(--destructive, #dc2626); font-weight: 600; }
  .rq-key { display: inline-block; padding: 0 .4rem; border-radius: 4px; border: 1px solid; }
  .rq-key.rq-miss { background-color: color-mix(in oklab, var(--warning, #f59e0b) 22%, transparent); border-color: var(--warning, #f59e0b); }
  .rq-key.rq-diff { background-color: color-mix(in oklab, var(--destructive, #dc2626) 14%, transparent); border-color: var(--destructive, #dc2626); }
  .wa-text { white-space: pre-wrap; font-size: .875rem; padding: .75rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--muted); max-height: 14rem; overflow-y: auto; }

  /* ---------- Subscription: how to pay (payModal) and the payment details card ---------- */
  .pay-opts { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: .75rem; }
  .pay-opt { padding: .875rem 1rem; border: 1px solid var(--border); border-radius: var(--radius); }
  .pay-opt h4 { margin: 0 0 .5rem; font-size: .9375rem; font-weight: 600; }
  .pay-opt .totals { margin-top: 0; }
  .pay-opt img { display: block; width: 100%; max-width: 13rem; margin: 0 auto; border-radius: calc(var(--radius) - 2px); }
  .qr-prev { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
  .qr-prev img { width: 8rem; height: 8rem; object-fit: contain; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; }
  #banner .btn { color: var(--foreground); }

  /* ---------- Issue note on one A4 page (issueNoteA4 in script.js) ---------- */
  .a4-note { font-size: .875rem; line-height: 1.3; }
  .a4-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; padding-bottom: .75rem; border-bottom: 2px solid var(--foreground); }
  .a4-head h2 { margin: 0; font-size: 1.375rem; line-height: 1.2; font-weight: 700; }
  .a4-kind { margin-top: .125rem; color: var(--muted-foreground); font-size: .8125rem; text-transform: uppercase; letter-spacing: .06em; }
  .a4-no { display: flex; flex-direction: column; align-items: flex-end; gap: .125rem; text-align: right; }
  .a4-no b { font-size: 1.125rem; }
  .a4-no span { color: var(--muted-foreground); font-size: .8125rem; }
  .a4-meta { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: .75rem; margin: .75rem 0; }
  .a4-meta span { display: block; color: var(--muted-foreground); font-size: .75rem; }
  .a4-meta b { font-size: .9375rem; overflow-wrap: anywhere; }
  .a4-tbl { width: 100%; border-collapse: collapse; }
  .a4-tbl :is(th, td) { height: auto; padding: .3rem .4rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
  .a4-tbl :is(th, td).n { text-align: right; white-space: nowrap; }
  .a4-tbl thead th { border-bottom: 2px solid var(--foreground); font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; }
  .a4-tbl tfoot th { border-top: 2px solid var(--foreground); border-bottom: 0; font-weight: 700; color: var(--foreground); }
  .a4-note .totals > div > span:last-child { white-space: nowrap; }
  .a4-tbl td.mono { font-size: .8125rem; white-space: nowrap; }
  .a4-bottom { display: grid; grid-template-columns: 1fr minmax(16rem, 20rem); gap: 2rem; align-items: end; margin-top: 1rem; }
  .a4-bottom .totals { margin-top: 0; }
  .a4-sign { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; color: var(--muted-foreground); font-size: .8125rem; }
  .a4-sign span { display: block; height: 2.25rem; margin-bottom: .25rem; border-bottom: 1px solid var(--foreground); }
  .a4-foot { margin: 1rem 0 0; color: var(--muted-foreground); font-size: .8125rem; text-align: center; }
  @page issue-a4 { size: A4 portrait; margin: 10mm 12mm; }
  /* Issue tickets › Summary: stock total line */
  .ln.onhand { margin-bottom: .25rem; padding-bottom: .4rem; border-bottom: 1px solid var(--border); font-weight: 600; }

  /* Issue note (MIN) for the Epson LQ-50: 6 inch fanfold / roll paper, about 50 columns, fixed-width type, black only */
  .lq-note { max-width: 127mm; margin: 0 auto; font-family: "Courier New", Courier, ui-monospace, monospace; font-size: 10pt; line-height: 1.3; color: var(--foreground); }
  .lq-note .lq-c { text-align: center; }
  .lq-note .lq-co { font-size: 12pt; }
  .lq-note > div { margin: 2pt 0; }
  .lq-tbl { width: 100%; border-collapse: collapse; margin: 3pt 0; font: inherit; }
  .lq-tbl :is(thead, tbody, tr) { border: 0; box-shadow: none; background: none; }
  .lq-tbl :is(th, td) { height: auto; padding: 0 2pt; border: 0; box-shadow: none; font: inherit; text-align: left; vertical-align: top; color: inherit; background: none; }
  .lq-tbl :is(th, td).n { text-align: right; white-space: nowrap; }
  .lq-tbl th { font-weight: 700; }
  .lq-tbl .lq-rule td { padding: 0; border-top: 1px dashed currentColor; }
  .lq-tbl .lq-big td { font-weight: 700; }
  .lq-note .lq-sign { margin-top: 10pt; }
  @page lq50 { size: 152.4mm 279.4mm; margin: 4mm 6mm; }
  @media print {
    .lq-note { page: lq50; max-width: none; margin: 0; color: #000; }
    .lq-tbl tr { break-inside: avoid; }
  }
  /* Day settlement on paper: A4 portrait, the whole client table across the page width */
  @page settle-a4 { size: A4 portrait; margin: 10mm; }
  @media print {
    .settle-print { page: settle-a4; font-size: 8.5pt; line-height: 1.2; color: #000; }
    .settle-print .settle-head { display: block; margin-bottom: 6pt; }
    .settle-print .settle-head h2 { margin: 0 0 2pt; font-size: 13pt; }
    .settle-print .panel { border: 0; }
    .settle-print .ph { padding: 0 0 4pt; }
    .settle-print .ph h3 { font-size: 10pt; }
    .settle-print table { width: 100%; table-layout: auto; }
    .settle-print :is(th, td) { height: auto; padding: 2pt 3pt; line-height: 1.15; white-space: nowrap; }
    .settle-print .item-sub { font-size: 7pt; }
    .settle-print tr.editing { display: none; }
    .settle-print .badge { padding: 0 2pt; font-size: 7pt; border: .5pt solid #000; background: none; color: #000; }
  }
  /* MIN notes by client: notes one after another on screen, one per page on paper */
  .min-doc { padding: 1.25rem 0; border-top: 1px dashed var(--border); }
  .min-doc:first-of-type, .no-print + .min-doc { border-top: 0; }
  @media print {
    /* only this note uses the named A4 page; slip receipts keep the printer's own paper size */
    .a4-note { page: issue-a4; font-size: 9.5pt; line-height: 1.2; color: #000; }
    .a4-head { padding-bottom: 6pt; }
    .a4-head h2 { font-size: 16pt; }
    .a4-meta { margin: 6pt 0; }
    .a4-tbl :is(th, td) { padding: 2pt 4pt; line-height: 1.15; }
    .a4-bottom { margin-top: 8pt; }
    .a4-note .totals > div { padding: 1pt 0; }
    .a4-note .totals .big { margin-top: 2pt; padding-top: 3pt; font-size: 11pt; line-height: 1.3; }
    .a4-sign span { height: 22pt; }
    .a4-foot { margin-top: 6pt; }
    /* many lines: smaller type and tighter rows, so up to about 45 lines still fit one page */
    .a4-note.dense { font-size: 8.5pt; }
    .a4-note.dense .a4-tbl :is(th, td) { padding: 1pt 4pt; }
    .a4-note.xdense { font-size: 7.5pt; }
    .a4-note.xdense .a4-tbl :is(th, td) { padding: .5pt 3pt; }
    .a4-tbl tr, .a4-bottom { break-inside: avoid; }
    .min-doc { padding: 0; border: 0; }
    .min-doc + .min-doc { break-before: page; }
  }

  /* ---------- Requested tickets: blank form to write on, and the entry grid on Purchase orders ---------- */
  .req-form table { border-collapse: collapse; }
  .req-form :is(th, td) { border: 1px solid var(--border); }
  .req-form tbody td { height: 2rem; }
  .req-form .req-colno th { font-size: 1rem; font-weight: 700; color: var(--foreground); }
  .req-grid :is(th, td):first-child { position: sticky; left: 0; z-index: 1; background-color: var(--card); box-shadow: 1px 0 0 var(--border); }
  .req-grid thead th { white-space: normal; vertical-align: bottom; min-width: 4.5rem; }
  .req-grid .rq-in { width: 4.5rem; padding: .25rem .4rem; text-align: right; }
  /* filled from a scan or photo: check it against the paper */
  .req-grid .rq-in.ocr-filled { border-color: var(--warning); background-color: color-mix(in oklab, var(--warning) 14%, transparent); font-weight: 600; }
  .req-grid .rq-in.ocr-unsure { border-color: var(--destructive); background-color: color-mix(in oklab, var(--destructive) 12%, transparent); }
  /* a figure that differs from what was requested (and requested tickets still waiting for approval) */
  .chk-diff { background-color: color-mix(in oklab, var(--warning) 22%, transparent); font-weight: 600; }
  @media print {
    .req-form :is(th, td) { border: .5pt solid #000; }
    .req-form tbody td { height: 7mm; }
  }

  /* Approved requests on paper: equal item columns under short codes, fitted to landscape A4 */
  .req-print table { width: 100%; table-layout: fixed; border-collapse: collapse; font-size: var(--rp-fs, 8.5pt); }
  .req-print :is(th, td) { border: 1px solid var(--border); padding: 2px 3px; overflow: hidden; white-space: nowrap; }
  .req-print col.rp-no { width: 2.2em; } .req-print col.rp-client { width: 13em; } .req-print col.rp-tot { width: 4.5em; }
  .req-print :is(thead, tfoot) th { text-align: center; font-weight: 700; color: var(--foreground); }
  .req-print .rp-cl { text-overflow: ellipsis; }
  .req-print .rp-rt { font-size: .85em; color: var(--muted-foreground); }
  .req-print tfoot th { text-align: right; }
  .req-print .rp-key { margin-top: 6pt; font-size: calc(var(--rp-fs, 8.5pt) - .5pt); line-height: 1.5; }
  .req-print .rp-key span { white-space: nowrap; }
  @media print {
    .req-print :is(th, td) { border: .5pt solid #000; padding: 2.5pt 3pt; height: auto; color: #000; }
    .rep-wide.req-print table { font-size: var(--rp-fs, 8.5pt); }
    .rep-wide.req-print tbody td:nth-child(-n+3) { white-space: nowrap; }
    .req-print .rp-rt { color: #333; }
  }

  /* ---------- Wide reports (one column per item) ---------- */
  .rep-wide thead th { white-space: normal; vertical-align: bottom; }
  .rep-wide .min-items thead th .item-sub { font-size: inherit; line-height: inherit; font-weight: 600; color: var(--foreground); }
  .rep-wide .min-items tbody td:first-child { white-space: nowrap; }
  .rep-block { margin: 1rem 0 .25rem; font-weight: 600; }
  @page rep-landscape { size: A4 landscape; margin: 10mm; }
  @media print {
    .rep-wide { page: rep-landscape; font-size: 8pt; color: #000; }
    .rep-wide h3 { margin: 0 0 2pt; font-size: 12pt; }
    .rep-wide .sub { margin: 0 0 6pt; font-size: 8pt; }
    .rep-wide table { font-size: 8pt; }
    .rep-wide :is(th, td) { height: auto; padding: 1.5pt 3pt; line-height: 1.15; }
    .rep-wide tbody td:nth-child(-n+3) { white-space: nowrap; }
    .rep-wide thead { display: table-header-group; }
    .rep-wide .min-items { break-inside: auto; margin-bottom: 8pt; }
    .rep-wide p { font-size: 8pt; }
    .rep-block { margin: 8pt 0 2pt; font-size: 9pt; }
    .rep-blk + .rep-blk { break-before: page; }
  }

  /* shown only on paper (e.g. the company / document heading of a printed note) */
  .print-only { display: none; }
  @media print {
    .print-only { display: block; }
    .facts { background: none; }
    /* The theme script puts color-scheme:dark INLINE on <html> in dark mode, which beats the unlayered
       print reset at the top of this file and paints the printed page (its margins) dark.
       An !important declaration outranks a normal inline one, so paper is always light. */
    :root { color-scheme: light !important; }
  }
  @media (prefers-reduced-motion: reduce) { .spin { animation: none; } }
}
