/* Trebax Inventory redesign — shared design tokens + tbx- component classes.
   Layered on top of Bootstrap 5.3 (CDN, no Sass build step) — Bootstrap still
   handles grid/layout/JS (offcanvas, dropdowns); this file owns color/shape/type. */

:root {
  /* Accent */
  --tbx-accent: #D81B2A;
  --tbx-accent-hover: #B5141F;
  --tbx-accent-soft: #FCE9EB;

  /* Surfaces */
  --tbx-bg: #F6F7F9;
  --tbx-surface: #FFFFFF;
  --tbx-border: #E8EAEE;
  --tbx-border-subtle: #F0F1F3;
  --tbx-border-subtle-2: #F2F3F5;
  --tbx-border-band: #F4F5F7;
  --tbx-border-table: #ECEEF1;
  --tbx-input-border: #DCDFE4;

  /* Text */
  --tbx-text-primary: #1A1D23;
  --tbx-text-secondary: #3A4049;
  --tbx-text-muted: #8A909C;
  --tbx-text-disabled: #C7CBD2;

  /* Dark button / avatar */
  --tbx-dark: #22262C;
  --tbx-dark-hover: #33383F;

  /* Semantic chip colors */
  --tbx-success-text: #0F7A43;
  --tbx-success-bg: #E7F4EC;
  --tbx-info-text: #1F6FEB;
  --tbx-info-bg: #E7F0FE;
  --tbx-purple-text: #6B45C9;
  --tbx-purple-bg: #EFEAFB;
  --tbx-red-text: #C12534;
  --tbx-red-bg: #FCE9EB;
  --tbx-amber-text: #9A6700;
  --tbx-amber-bg: #FBF1D9;

  /* Shape */
  --tbx-radius-card: 14px;
  --tbx-radius-control: 9px;
  --tbx-radius-chip: 999px;
  --tbx-radius-badge: 6px;
  --tbx-shadow-card: 0 1px 2px rgba(16, 24, 40, .05);

  /* Shell */
  --tbx-header-h: 56px;
  --tbx-sidebar-w: 248px;
  --tbx-drawer-w: 300px;

  /* Type scale — one named set of font sizes, used app-wide instead of inline
     "magic numbers". Keep these in sync with the helper classes below. */
  --tbx-fs-title: 24px;    /* page <h1> */
  --tbx-fs-section: 18px;  /* section / sub-header */
  --tbx-fs-body: 13.5px;   /* default table / card text */
  --tbx-fs-small: 12.5px;  /* secondary / meta text */
  --tbx-fs-micro: 12px;    /* chips, table column headers (12px minimum for phone readability) */

  /* Inter is our committed UI face (loaded in base.html); the system mono stack
     below handles codes, prices and dates via .tbx-mono / .tbx-code. */
  --tbx-font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ── Base ── */
body {
  background: var(--tbx-bg);
  color: var(--tbx-text-primary);
}

/* ── Type scale helpers ── */
.tbx-h1 {
  font-size: var(--tbx-fs-title);
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-bottom: 2px;
}
.tbx-h2 {
  font-size: var(--tbx-fs-section);
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-bottom: 2px;
}
.tbx-page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.tbx-page-header-meta {
  font-size: var(--tbx-fs-small);
  color: var(--tbx-text-muted);
}
.tbx-page-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* Neutral identifier style for short/product codes — mono + semibold is enough
   to read as "an identifier" without borrowing the accent's danger/urgency
   connotation. Red is reserved for primary actions, active nav, focus rings,
   and true warning/danger chips (see component classes below). */
.tbx-code {
  font-family: var(--tbx-font-mono);
  font-weight: 600;
  color: var(--tbx-text-primary);
}

/* Text-size utilities, mapped to the type scale tokens — use instead of inline
   font-size styles. */
.tbx-text-body { font-size: var(--tbx-fs-body); }
.tbx-text-small { font-size: var(--tbx-fs-small); }
.tbx-text-micro { font-size: var(--tbx-fs-micro); }
.tbx-card-meta { font-size: var(--tbx-fs-small); }
.tbx-filter-label { font-size: var(--tbx-fs-micro); font-weight: 600; }

/* Offer price cell — used wherever a discounted/offer price is shown next to
   a list price, so the saving stands out without reaching for the accent. */
.tbx-price-offer { color: var(--tbx-success-text); font-weight: 600; }

.tbx-mono {
  font-family: var(--tbx-font-mono);
}

/* ── Header shell ── */
/* Sticky so the shell stays whole on scroll — the sidebar below already offsets
   itself by --tbx-header-h. 1030 sits below the drawer (1045) and modals (1055). */
.tbx-header {
  height: var(--tbx-header-h);
  background: var(--tbx-surface);
  border-bottom: 1px solid var(--tbx-border);
  position: sticky;
  top: 0;
  z-index: 1030;
}
.tbx-header-divider {
  width: 1px;
  height: 24px;
  background: var(--tbx-border);
}
.tbx-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--tbx-dark);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12.5px;
  font-weight: 600;
}
.tbx-hamburger {
  border: 1px solid var(--tbx-input-border);
  border-radius: var(--tbx-radius-control);
  padding: 0.35rem 0.55rem;
  background: var(--tbx-surface);
  line-height: 1;
}
.tbx-hamburger:hover {
  background: var(--tbx-border-subtle-2);
}

/* ── Sidebar ── */
.tbx-sidebar {
  width: var(--tbx-sidebar-w);
  flex-shrink: 0;
  background: var(--tbx-surface);
  border-right: 1px solid var(--tbx-border);
}
.tbx-sidebar-section-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--tbx-text-muted);
  padding: 1rem 0.7rem 0.25rem;
  display: block;
}
.tbx-sidebar-link {
  display: flex;
  align-items: center;
  gap: 11px;
  color: var(--tbx-text-secondary);
  padding: 9px 11px;
  border-radius: var(--tbx-radius-control);
  font-size: 0.875rem;
  font-weight: 500;
  transition: background 0.12s ease, color 0.12s ease;
}
.tbx-sidebar-link:hover {
  background: var(--tbx-border-subtle-2);
  color: var(--tbx-text-primary);
}
.tbx-sidebar-link.active {
  background: var(--tbx-accent-soft);
  color: var(--tbx-accent);
  font-weight: 600;
}
.tbx-sidebar-icon {
  flex: 0 0 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--tbx-text-muted);
}
.tbx-sidebar-link.active .tbx-sidebar-icon {
  color: var(--tbx-accent);
}

/* ── Main content area ── */
.tbx-main {
  padding: 28px 32px 64px;
}
@media (max-width: 899.98px) {
  .tbx-main {
    padding: 16px;
  }
}

/* ── Cards ── */
.tbx-card {
  background: var(--tbx-surface);
  border: 1px solid var(--tbx-border);
  border-radius: var(--tbx-radius-card);
  box-shadow: var(--tbx-shadow-card);
}
.tbx-card-header {
  padding: 16px 18px;
  border-bottom: 1px solid var(--tbx-border);
  font-size: 14px;
  font-weight: 600;
}
.tbx-card-body {
  padding: 16px 18px;
}
.tbx-collapse-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: none;
  border: 0;
  cursor: pointer;
  font: inherit;
  color: inherit;
  text-align: left;
}
.tbx-collapse-toggle .chevron {
  transition: transform 0.15s ease;
  color: var(--tbx-text-secondary);
  font-size: 12px;
  margin-left: 8px;
  flex-shrink: 0;
}
.tbx-collapse-toggle[aria-expanded="true"] .chevron {
  transform: rotate(180deg);
}
.tbx-card-toolbar {
  border-bottom: 1px solid var(--tbx-border);
}

/* ── Catalogue link cards (external website/PDF links) ── */
.tbx-link-card {
  display: block;
  color: inherit;
  text-decoration: none;
  overflow: hidden;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}
.tbx-link-card:hover {
  color: inherit;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
  transform: translateY(-1px);
}
.tbx-link-card-thumb {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 140px;
  background: var(--tbx-border-band);
  border-bottom: 1px solid var(--tbx-border);
}
.tbx-link-card-thumb img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.tbx-link-card-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--tbx-accent-soft);
  color: var(--tbx-accent);
}

/* ── Inputs / buttons ── */
.tbx-input {
  height: 38px;
  border: 1px solid var(--tbx-input-border);
  border-radius: var(--tbx-radius-control);
  font-size: 13.5px;
  color: var(--tbx-text-primary);
  background: var(--tbx-surface);
  line-height: 36px;
  padding-top: 0;
  padding-bottom: 0;
}
.tbx-input:focus {
  border-color: var(--tbx-accent);
  box-shadow: 0 0 0 3px var(--tbx-accent-soft);
  outline: none;
}
textarea.tbx-input {
  height: auto;
  line-height: 1.35;
  padding-top: 0.25rem;
  padding-bottom: 0.25rem;
}
.tbx-hs-code-input {
  width: 160px;
  max-width: 100%;
}
@media (max-width: 899.98px) {
  .tbx-input {
    height: 42px;
    border-radius: 10px;
    line-height: 40px;
  }
  textarea.tbx-input {
    line-height: 1.35;
  }
}

.tbx-btn {
  height: 38px;
  padding: 0 14px;
  border-radius: var(--tbx-radius-control);
  font-size: 13px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  border: 1px solid transparent;
  white-space: nowrap;
  text-decoration: none;
}
.tbx-btn-accent {
  background: var(--tbx-accent);
  border-color: var(--tbx-accent);
  color: #fff;
}
.tbx-btn-accent:hover {
  background: var(--tbx-accent-hover);
  border-color: var(--tbx-accent-hover);
  color: #fff;
}
.tbx-btn-accent-outline {
  background: var(--tbx-surface);
  border-color: var(--tbx-accent);
  color: var(--tbx-accent);
}
.tbx-btn-accent-outline:hover {
  background: var(--tbx-accent-soft);
  color: var(--tbx-accent);
}
.tbx-btn-outline {
  background: var(--tbx-surface);
  border-color: var(--tbx-input-border);
  color: var(--tbx-text-secondary);
}
.tbx-btn-outline:hover {
  background: var(--tbx-border-subtle-2);
}
.tbx-btn-dark {
  background: var(--tbx-dark);
  border-color: var(--tbx-dark);
  color: #fff;
}
.tbx-btn-dark:hover {
  background: var(--tbx-dark-hover);
  border-color: var(--tbx-dark-hover);
  color: #fff;
}
.tbx-btn-success {
  background: var(--tbx-success-text);
  border-color: var(--tbx-success-text);
  color: #fff;
}
.tbx-btn-success:hover {
  background: #0c5e34;
  border-color: #0c5e34;
  color: #fff;
}
.tbx-btn-icon {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: var(--tbx-radius-control);
  border: 1px solid var(--tbx-input-border);
  background: var(--tbx-surface);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--tbx-text-secondary);
}
.tbx-btn-icon:hover {
  background: var(--tbx-border-subtle-2);
}
.tbx-btn-icon.active {
  background: var(--tbx-accent-soft);
  border-color: var(--tbx-accent);
  color: var(--tbx-accent);
}
.tbx-btn-dashed {
  background: var(--tbx-surface);
  border: 1px dashed var(--tbx-input-border);
  border-radius: var(--tbx-radius-control);
  color: var(--tbx-text-secondary);
  font-size: 13px;
  font-weight: 600;
  height: 38px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}
.tbx-btn-dashed:hover {
  background: var(--tbx-border-subtle-2);
}

/* Small button modifier — for dense table-row actions where the default
   38px-tall tbx-btn would be too bulky (order/quotation builder lines etc). */
.tbx-btn-sm {
  height: 28px;
  padding: 0 10px;
  font-size: var(--tbx-fs-micro);
}
.tbx-btn-icon-sm {
  width: 28px;
  height: 28px;
}

/* ── Chips / status pills ── */
.tbx-chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: var(--tbx-radius-chip);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.tbx-chip-green { background: var(--tbx-success-bg); color: var(--tbx-success-text); }
.tbx-chip-blue { background: var(--tbx-info-bg); color: var(--tbx-info-text); }
.tbx-chip-purple { background: var(--tbx-purple-bg); color: var(--tbx-purple-text); }
.tbx-chip-red { background: var(--tbx-red-bg); color: var(--tbx-red-text); }
.tbx-chip-amber { background: var(--tbx-amber-bg); color: var(--tbx-amber-text); }
.tbx-chip-grey { background: var(--tbx-border-subtle-2); color: var(--tbx-text-secondary); }

/* A chip-shaped navigation link — used where a "go to the fuller report" link sits in a
   row of status chips and a bordered button would out-shout its neighbours. Inherits the
   chip's size/shape so it stays in step with them. */
.tbx-chip-link {
  background: transparent;
  color: var(--tbx-accent);
  text-decoration: none;
  transition: background 0.12s ease;
}
.tbx-chip-link:hover { background: var(--tbx-accent-soft); color: var(--tbx-accent); }

/* Small hover-for-detail icon (e.g. "expected Excel columns" reminder next to an
   upload field) — deliberately quiet, native title tooltip, no JS. */
.tbx-help-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--tbx-border-subtle-2);
  color: var(--tbx-text-secondary);
  font-size: 12px;
  cursor: help;
}

/* Small count badge (sidebar wishlist/compare counts) — 6px radius per spec,
   deliberately not the 999px pill radius used by status chips. */
.tbx-count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: var(--tbx-radius-badge);
  font-size: 11px;
  font-weight: 700;
  background: var(--tbx-accent-soft);
  color: var(--tbx-accent);
}

/* ── Tables ── */
.tbx-table {
  width: 100%;
  border-collapse: collapse;
}
.tbx-table thead th.sortable {
  cursor: pointer;
  user-select: none;
}
.tbx-table thead th {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--tbx-text-muted);
  background: #FAFBFC;
  border-bottom: 1px solid var(--tbx-border-table);
  padding: 10px 14px;
  text-align: left;
}
.tbx-table tbody td {
  font-size: 13.5px;
  color: var(--tbx-text-primary);
  border-bottom: 1px solid var(--tbx-border-subtle-2);
  padding: var(--tbx-row-pad, 14px);
  vertical-align: middle;
}
.tbx-table tbody tr:hover {
  background: #FAFBFC;
}
.tbx-table tbody tr.tbx-row {
  cursor: pointer;
}

/* Small product thumbnail shown in order line tables. */
.tbx-line-thumb {
  width: 64px;
  height: 64px;
  object-fit: contain;
  border-radius: var(--tbx-radius-badge);
  background: var(--tbx-bg);
  vertical-align: middle;
}
.tbx-line-thumb-empty {
  display: inline-block;
  border: 1px solid var(--tbx-border);
}
/* Compact 40px variant used in the product-detail set-contents / consumables tables. */
.tbx-line-thumb-sm {
  width: 40px;
  height: 40px;
}

/* ── Key/value rows (Overview, Specifications) ── */
.tbx-kv-row {
  display: flex;
  padding: 8px 0;
  border-bottom: 1px solid var(--tbx-border-subtle-2);
  gap: 12px;
}
.tbx-kv-row:last-child {
  border-bottom: none;
}
.tbx-kv-label {
  flex: 0 0 130px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--tbx-text-muted);
}
.tbx-kv-label-wide {
  flex-basis: 180px;
}
.tbx-kv-value {
  font-size: 13.5px;
  color: var(--tbx-text-primary);
  min-width: 0;
  overflow-wrap: anywhere;
}

/* ── Filter card (product list) ── */
.tbx-filter-card {
  background: var(--tbx-surface);
  border: 1px solid var(--tbx-border);
  border-radius: var(--tbx-radius-card);
  box-shadow: var(--tbx-shadow-card);
  padding: 16px;
}
.tbx-filter-toggle {
  background: var(--tbx-surface);
  border: 1px solid var(--tbx-input-border);
  border-radius: var(--tbx-radius-control);
  color: var(--tbx-text-secondary);
  font-size: 13px;
  font-weight: 600;
  height: 38px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}
.tbx-filter-toggle:hover {
  background: var(--tbx-border-subtle-2);
}
.tbx-filter-toggle .chevron {
  transition: transform 0.15s ease;
}
.tbx-filter-toggle.expanded .chevron {
  transform: rotate(180deg);
}
.tbx-filter-badge {
  background: var(--tbx-accent);
  color: #fff;
  border-radius: var(--tbx-radius-chip);
  font-size: 11px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
}

/* ── VAT toggle switch ── */
.tbx-switch {
  width: 34px;
  height: 20px;
  border-radius: var(--tbx-radius-chip);
  background: var(--tbx-input-border);
  position: relative;
  display: inline-block;
  cursor: pointer;
  transition: background 0.18s ease;
  border: none;
  padding: 0;
}
.tbx-switch.on {
  background: var(--tbx-accent);
}
.tbx-switch .knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.18s ease;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .25);
}
.tbx-switch.on .knob {
  transform: translateX(14px);
}

/* ── Search icon wrapper ── */
.tbx-search-wrap {
  position: relative;
}
.tbx-search-wrap .tbx-search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--tbx-text-muted);
}
.tbx-search-wrap input {
  padding-left: 32px;
}

/* ── Product detail layout ── */
.tbx-detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 400px) minmax(0, 1fr);
  gap: 22px;
  align-items: start;
}
@media (max-width: 899.98px) {
  .tbx-detail-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}
/* The image follows the reader down the much taller right column instead of
   leaving the left side blank. Desktop only — below 900px the grid is one
   column, where sticky has nothing to slide against. */
@media (min-width: 900px) {
  .tbx-detail-image {
    position: sticky;
    top: calc(var(--tbx-header-h) + 20px);
  }
}
.tbx-detail-sections {
  display: flex;
  flex-direction: column;
  gap: 18px;
}
@media (max-width: 899.98px) {
  .tbx-detail-actions {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    width: 100%;
  }
  .tbx-detail-actions > * {
    width: 100%;
    justify-content: center;
  }
  .tbx-detail-actions input#pd-qty {
    width: 100% !important;
  }
  .tbx-detail-actions .tbx-detail-actions-full {
    grid-column: 1 / -1;
  }
}

/* ── Compare table ── */
.tbx-compare-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
}
.tbx-compare-table th,
.tbx-compare-table td {
  border-bottom: 1px solid var(--tbx-border-subtle-2);
  padding: 12px 14px;
}
.tbx-compare-label {
  background: #FAFBFC;
  font-size: 13px;
  font-weight: 600;
  color: var(--tbx-text-secondary);
  width: 216px;
}
.tbx-compare-band {
  background: var(--tbx-border-band);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--tbx-text-muted);
}
.tbx-compare-remove {
  position: absolute;
  top: 8px;
  right: 8px;
}

/* ── Shell responsiveness: custom 900px breakpoint (spec's load-bearing
   breakpoint for the sidebar/drawer switch and, in later steps, the
   products table/card switch) — independent of Bootstrap's 768/992 grid
   breakpoints, which stay in effect everywhere else. ── */
.tbx-desktop-only { display: block; }
.tbx-mobile-only { display: none; }
@media (max-width: 899.98px) {
  .tbx-desktop-only { display: none; }
  .tbx-mobile-only { display: block; }
}

@media (min-width: 900px) {
  .tbx-hamburger {
    display: none;
  }
  /* Force the Bootstrap offcanvas sidebar into a permanently-visible, sticky
     column instead of a slide-in drawer once we're past the custom 900px
     breakpoint (Bootstrap's own "-md" responsive offcanvas classes are
     hardwired to 768px, which is too narrow for this spec). */
  #sidebarOffcanvas.tbx-sidebar {
    width: var(--tbx-sidebar-w);
    position: sticky;
    top: var(--tbx-header-h);
    left: auto;
    transform: none !important;
    visibility: visible !important;
    height: calc(100vh - var(--tbx-header-h));
    box-shadow: none;
    z-index: auto;
  }
}
@media (max-width: 899.98px) {
  #sidebarOffcanvas.tbx-sidebar {
    width: var(--tbx-drawer-w);
  }
}

/* ── VAT toggle (kept as a native checkbox for zero JS risk; just resized/
   recolored to match the spec's 34x20px track) ── */
/* Switch + label as one centred row: smaller switch, a real gap between the two,
   and no Bootstrap padding-left indent (the switch is a flex item, not a float). */
.tbx-vat-switch {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding-left: 0;
}
.tbx-vat-switch .form-check-label { margin: 0; }
.tbx-vat-switch .form-check-input {
  width: 30px;
  height: 17px;
  margin: 0;
  float: none;
  flex-shrink: 0;
  border-radius: 999px;
  cursor: pointer;
}
.tbx-vat-switch .form-check-input:checked {
  background-color: var(--tbx-accent);
  border-color: var(--tbx-accent);
}
.tbx-vat-switch .form-check-input:focus {
  box-shadow: 0 0 0 3px var(--tbx-accent-soft);
  border-color: var(--tbx-accent);
}

/* ── Mobile/responsive helpers (UI-improvement pass) ──
   Column-width classes replace per-template style="width:__px" attributes:
   min-width keeps inputs usable while letting .table-responsive handle overflow. */
.tbx-col-qty { min-width: 100px; }
.tbx-col-price { min-width: 120px; }
.tbx-col-note { min-width: 160px; }
/* Shrink-to-fit label column in key/value summary tables (no fixed pixels). */
.tbx-kv-col { width: 1%; white-space: nowrap; padding-right: 1.5rem; }
/* Compact numeric inputs inside table cells. */
.tbx-input-qty { width: 5rem; max-width: 100%; display: inline-block; }
.tbx-input-price { width: 7rem; max-width: 100%; display: inline-block; }
/* Type-to-filter category dropdown lists (was a repeated inline style). */
.cat-dropdown-items { max-height: 260px; overflow-y: auto; }
/* Stage tab bar: scroll sideways on narrow screens instead of wrapping/overflowing. */
.tbx-tabs-scroll { flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; white-space: nowrap; }
.tbx-tabs-scroll .nav-link { white-space: nowrap; }
/* Element busy state while an async save is in flight. */
.tbx-busy { opacity: .6; pointer-events: none; }
/* Chart wrapper: give the canvas an explicit height instead of letting Chart.js
   lock a fixed wide aspect ratio (which collapsed to ~100px on phones). Pairs
   with maintainAspectRatio: false on the Chart config; position: relative is
   what Chart.js sizes the canvas against. */
.tbx-chart-wrap { position: relative; height: 300px; }
@media (max-width: 899.98px) {
  .tbx-chart-wrap { height: 260px; }
}

/* ── Segmented control: two or three mutually exclusive views, drawn as a pill
   group. Used for the sales dashboard's Historical / Compare years switch,
   which is plain links (each view reloads) rather than Bootstrap tabs. ── */
.tbx-segment {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: var(--tbx-border-band);
  border: 1px solid var(--tbx-border);
  border-radius: var(--tbx-radius-control);
}
.tbx-segment a {
  display: inline-flex;
  align-items: center;
  height: 30px;
  padding: 0 14px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 600;
  color: var(--tbx-text-secondary);
  text-decoration: none;
  white-space: nowrap;
}
.tbx-segment a:hover { color: var(--tbx-text-primary); }
.tbx-segment a.active {
  background: var(--tbx-surface);
  color: var(--tbx-text-primary);
  box-shadow: var(--tbx-shadow-card);
}
.tbx-segment a:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--tbx-accent-soft);
}
@media (max-width: 899.98px) {
  .tbx-segment a { height: 34px; }
}

/* A pair of inputs drawn as one control (e.g. a From/To date range): the group
   owns the border and focus ring, the inputs inside go borderless. */
.tbx-field-group {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--tbx-input-border);
  border-radius: var(--tbx-radius-control);
  background: var(--tbx-surface);
}
.tbx-field-group:focus-within {
  border-color: var(--tbx-accent);
  box-shadow: 0 0 0 3px var(--tbx-accent-soft);
}
.tbx-field-group .tbx-input {
  border: 0;
  border-radius: 0;
  background: transparent;
}
.tbx-field-group .tbx-input:focus { box-shadow: none; }
.tbx-field-group .tbx-field-sep {
  color: var(--tbx-text-muted);
  font-size: 12px;
  padding: 0 2px;
}

/* Muted footer strip on a toolbar card: says what the page is currently
   showing, and offers the undo for it. */
.tbx-toolbar-status {
  padding: 8px 18px;
  border-top: 1px solid var(--tbx-border-subtle);
  font-size: var(--tbx-fs-small);
  color: var(--tbx-text-muted);
}

/* Metric card strip: 2 up on phones and 3 on tablets (matching the previous
   col-6 / col-md-4 exactly), then every card in one row on wide screens.
   Bootstrap's 12-column grid can't express sevenths, hence a plain CSS grid.
   The 7-across rule waits until 1400px: with the 248px sidebar, a narrower
   window leaves each card too tight for a figure like "€ 203,853.47". */
.tbx-metric-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px; /* matches the Bootstrap `g-3` gutter this replaced */
}
@media (min-width: 768px) {
  .tbx-metric-grid { grid-template-columns: repeat(3, 1fr); }
}
/* 1560px, not 1200px: measured against the longest figure the page can show
   ("€ 203,853.47" needs ~138px of text). Below this the cards stay 3-up rather
   than wrapping that figure onto a second line. */
@media (min-width: 1560px) {
  .tbx-metric-grid {
    grid-template-columns: repeat(7, 1fr);
    gap: 12px;
  }
  /* Step both lines down a touch so the widest figure ("€ 203,853.47") and the
     longest label ("Shortage cost · 0 units") each stay on one line. A label
     that wraps would stretch every card in the row, since they share a height. */
  .tbx-metric-grid .h5 { font-size: 1rem; }
  .tbx-metric-grid .small { font-size: 11.5px; }
}

/* Two variants of the same grid for the sales dashboard's split headline
   (3 primary cards) / secondary (4 compact cards) rows — sized so both rows
   fill the same width instead of the base grid's phone/tablet/7-across
   steps, which don't land evenly at 3 or 4 columns. */
.tbx-metric-grid--3 {
  grid-template-columns: repeat(1, 1fr);
}
@media (min-width: 768px) {
  .tbx-metric-grid--3 { grid-template-columns: repeat(3, 1fr); }
}
.tbx-metric-grid--4 {
  grid-template-columns: repeat(2, 1fr);
}
@media (min-width: 768px) {
  .tbx-metric-grid--4 { grid-template-columns: repeat(4, 1fr); }
}

/* The "▲ 12.4% vs …" line under a headline metric card. */
.tbx-metric-delta {
  display: flex;
  align-items: baseline;
  gap: 4px;
  margin-top: 2px;
}

/* Row cells in the top-products/top-customers panels: clip a long name to one
   line with an ellipsis instead of wrapping it onto a second line, which is
   what made those two panels' rows uneven heights. Needs `table-layout:
   fixed` on the parent table so `max-width: 0` can force the shrink. */
.tbx-truncate {
  max-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tbx-table-fixed {
  table-layout: fixed;
}

/* An anchor target that has to clear the sticky app header. Without this,
   jumping to #some-id parks the element's top edge at the very top of the
   window and .tbx-header (position: sticky) covers it. */
.tbx-scroll-anchor {
  scroll-margin-top: calc(var(--tbx-header-h) + 16px);
}

/* ── Sales-dashboard leaderboard panels (Top products / Top customers /
   Losing money in this period). Table on desktop, stacked label/value blocks
   on phones — see fifo/_dashboard_panel.html. ── */
.tbx-panel-table thead th { padding: 10px 14px; }
.tbx-panel-table tbody td { padding: 12px 14px; }

/* The whole code+name block is one link that inherits its colour, so a row
   never mixes blue link text with black body text. Only the name reacts on
   hover, which keeps the code reading as an identifier rather than a control. */
.tbx-panel-ident {
  display: block;
  color: inherit;
  text-decoration: none;
  min-width: 0;
}
.tbx-panel-ident:hover { color: inherit; }
.tbx-panel-ident:hover .tbx-panel-name { text-decoration: underline; }
.tbx-panel-ident:focus-visible {
  outline: none;
  border-radius: var(--tbx-radius-badge);
  box-shadow: 0 0 0 3px var(--tbx-accent-soft);
}
/* Clamped to two lines so a long product name can't stretch one row taller
   than its neighbours. Clamping this inner block works where truncating the
   <td> itself did not. */
.tbx-panel-name {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: var(--tbx-fs-small);
  color: var(--tbx-text-muted);
  line-height: 1.35;
}

/* Figures: right-aligned with fixed-width digits so they line up as a rail
   down the panel, which is what makes a ranked list scannable.
   These selectors are deliberately over-qualified: the base `.tbx-table thead
   th` / `.tbx-table tbody td` rules are more specific than a lone class, so a
   bare `.tbx-num` / `.tbx-pos` silently loses to them. */
.tbx-num,
.tbx-panel-table thead th.tbx-num,
.tbx-panel-table tbody td.tbx-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.tbx-panel-table tbody td.tbx-pos,
.tbx-panel-item .tbx-kv-value.tbx-pos { color: var(--tbx-success-text); }
.tbx-panel-table tbody td.tbx-neg,
.tbx-panel-item .tbx-kv-value.tbx-neg { color: var(--tbx-red-text); }

/* Phone: one hairline-separated block per entry. Deliberately not a nested
   .tbx-card — the panel is already a card, and a card inside a card doubles
   up the border. */
.tbx-panel-item + .tbx-panel-item {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--tbx-border);
}
.tbx-panel-item .tbx-panel-ident { margin-bottom: 6px; }
.tbx-panel-item .tbx-kv-label { flex: 1 1 auto; }
.tbx-panel-item .tbx-kv-value { flex: 0 0 auto; }

/* Touch-target pass: below the mobile breakpoint, raise the dense table-row
   controls (small buttons/selects/inputs) so every tap target clears ~38px.
   Layers on top of the fixed heights set above. */
@media (max-width: 899.98px) {
  .tbx-btn-sm,
  .form-control-sm,
  .form-select-sm { min-height: 38px; }
  .tbx-btn-icon-sm { width: 38px; height: 38px; }
}

/* ── Mobile line cards (stacked alternative to the widest order/report tables) ── */
.tbx-line-card { margin-bottom: 10px; }
.tbx-line-card:last-child { margin-bottom: 0; }
.tbx-line-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 8px;
}
.tbx-line-card .tbx-kv-label { flex-basis: 140px; }

/* ── Scrollable history/movements tables ── */
.tbx-scroll-table {
  max-height: 300px;
  overflow-y: auto;
}
.tbx-scroll-table table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
}

/* ── Product picker ──────────────────────────────────────────────────────────
   The shared "Add product" modal (static/inventory/product_picker.js), used by
   the order builder, quotations, quick-quote and consumables.

   Each result is a card laid out as a purchasing decision rather than a search
   hit: who it is on the left, the facts that decide the quantity in one strip
   below, and the commit control pinned top-right. The control is deliberately
   the only accent-coloured thing in the card. */

.tbx-picker-search {
  position: sticky;
  top: 0;
  z-index: 2;
  /* Cancel the modal body's padding so the sticky bar spans edge to edge, then
     put it back inside. Without this, rows scroll through the visible gutters. */
  margin: -16px -16px 12px;
  padding: 16px;
  background: var(--tbx-surface);
  border-bottom: 1px solid var(--tbx-border-subtle);
}
.tbx-picker-search .tbx-input {
  width: 100%;
}

.tbx-picker-empty {
  padding: 20px 2px;
  font-size: var(--tbx-fs-small);
  color: var(--tbx-text-muted);
}
.tbx-picker-empty.is-error {
  color: var(--tbx-red-text);
}

/* ── The result card ── */
.tbx-picker-card {
  border: 1px solid var(--tbx-border);
  border-radius: var(--tbx-radius-card);
  background: var(--tbx-surface);
  padding: 14px;
  margin-bottom: 10px;
}
.tbx-picker-card:last-child {
  margin-bottom: 0;
}
.tbx-picker-card:hover {
  border-color: var(--tbx-input-border);
}

/* flex-start, not center: a card with its movements panel open is ~300px tall,
   and centring would leave the commit control floating in the middle of it. */
.tbx-picker-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}
.tbx-picker-ident {
  min-width: 0; /* lets long names ellipsize instead of widening the card */
  flex: 1;
}
.tbx-picker-name {
  font-size: var(--tbx-fs-body);
  font-weight: 600;
  color: var(--tbx-text-primary);
  line-height: 1.35;
}
.tbx-picker-codes {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 5px;
}
.tbx-picker-code {
  font-family: var(--tbx-font-mono);
  font-size: var(--tbx-fs-micro);
  color: var(--tbx-text-muted);
}
/* Middot separator between codes — drawn, not typed, so it never lands at the
   start of a wrapped line. */
.tbx-picker-code + .tbx-picker-code::before {
  content: "·";
  margin-right: 6px;
}

/* ── The commit control (quantity + Add, welded into one object) ── */
.tbx-picker-commit {
  display: flex;
  align-items: stretch;
  flex: none;
}
.tbx-picker-qty {
  width: 56px;
  height: 34px;
  padding: 0 8px;
  text-align: center;
  font-size: var(--tbx-fs-small);
  color: var(--tbx-text-primary);
  background: var(--tbx-surface);
  border: 1px solid var(--tbx-input-border);
  border-right: 0;
  border-radius: var(--tbx-radius-control) 0 0 var(--tbx-radius-control);
}
.tbx-picker-qty:focus {
  outline: none;
  border-color: var(--tbx-accent);
  box-shadow: 0 0 0 3px var(--tbx-accent-soft);
  position: relative; /* keep the focus ring above the adjoining button */
  z-index: 1;
}
.tbx-picker-add {
  height: 34px;
  padding: 0 16px;
  font-size: var(--tbx-fs-small);
  font-weight: 600;
  color: #fff;
  background: var(--tbx-accent);
  border: 1px solid var(--tbx-accent);
  border-radius: 0 var(--tbx-radius-control) var(--tbx-radius-control) 0;
  cursor: pointer;
  white-space: nowrap;
}
.tbx-picker-commit-solo .tbx-picker-add {
  border-radius: var(--tbx-radius-control);
}
.tbx-picker-add:hover:not(:disabled) {
  background: var(--tbx-accent-hover);
  border-color: var(--tbx-accent-hover);
}
.tbx-picker-add:focus-visible {
  outline: 2px solid var(--tbx-accent);
  outline-offset: 2px;
}
.tbx-picker-add:disabled {
  cursor: default;
  opacity: 0.75;
}
/* Confirmed state — set by the picker after onPick() succeeds. */
.tbx-picker-add.is-added,
.tbx-picker-add.is-added:disabled {
  background: var(--tbx-success-text);
  border-color: var(--tbx-success-text);
  opacity: 1;
}

/* ── The facts strip ── */
/* Grid, not flex, so every fact column is the same width and the figures line
   up vertically from card to card. auto-flow/auto-columns rather than a fixed
   column count because the number of facts varies: five with valuation
   permission, one or two without. */
.tbx-picker-facts {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--tbx-border-subtle);
}
.tbx-picker-fact {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  text-align: center;
}
.tbx-picker-fact-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--tbx-text-muted);
}
.tbx-picker-fact-value {
  font-size: var(--tbx-fs-small);
  font-weight: 600;
  color: var(--tbx-text-primary);
  font-variant-numeric: tabular-nums;
}
/* Only the on-hand figure is coloured — it's the one that changes the decision. */
.tbx-picker-fact-value.is-positive { color: var(--tbx-success-text); }
.tbx-picker-fact-value.is-negative { color: var(--tbx-red-text); }

/* ── The stock disclosure bar ── */
.tbx-picker-stockbar {
  display: flex;
  align-items: stretch;
  gap: 8px;
  margin-top: 12px;
}
.tbx-picker-disclosure {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 34px;
  padding: 0 12px;
  font-size: var(--tbx-fs-micro);
  font-weight: 600;
  color: var(--tbx-text-secondary);
  background: var(--tbx-surface);
  border: 1px solid var(--tbx-input-border);
  border-radius: var(--tbx-radius-control);
  cursor: pointer;
  text-align: left;
}
.tbx-picker-disclosure:hover,
.tbx-picker-openlink:hover {
  background: var(--tbx-border-subtle-2);
}
.tbx-picker-disclosure:focus-visible,
.tbx-picker-openlink:focus-visible {
  outline: 2px solid var(--tbx-accent);
  outline-offset: 2px;
}
.tbx-picker-caret {
  transition: transform 0.15s ease;
  color: var(--tbx-text-muted);
}
.tbx-picker-disclosure.is-open .tbx-picker-caret {
  transform: rotate(180deg);
}
@media (prefers-reduced-motion: reduce) {
  .tbx-picker-caret { transition: none; }
}
.tbx-picker-openlink {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  flex: none;
  color: var(--tbx-text-secondary);
  text-decoration: none;
  background: var(--tbx-surface);
  border: 1px solid var(--tbx-input-border);
  border-radius: var(--tbx-radius-control);
}

/* ── The movements panel ── */
.tbx-picker-movements {
  margin-top: 10px;
}
.tbx-picker-note {
  font-size: var(--tbx-fs-small);
  color: var(--tbx-text-muted);
  padding: 8px 2px;
}
.tbx-picker-note.is-error {
  color: var(--tbx-red-text);
}
/* Scrolls both ways: six columns don't fit a phone, and a long history
   shouldn't push the rest of the results off screen. */
.tbx-picker-mv-scroll {
  max-height: 260px;
  overflow: auto;
  border: 1px solid var(--tbx-border-subtle);
  border-radius: var(--tbx-radius-control);
}
.tbx-picker-mv-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--tbx-fs-micro);
}
.tbx-picker-mv-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--tbx-border-band);
  font-weight: 600;
  color: var(--tbx-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 11px;
}
.tbx-picker-mv-table th,
.tbx-picker-mv-table td {
  padding: 7px 10px;
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--tbx-border-subtle);
}
.tbx-picker-mv-table td {
  color: var(--tbx-text-secondary);
}
/* In / Out / On hand: equal fixed width and centred, so the three numeric
   columns read as a set rather than three ragged right-aligned edges. */
.tbx-picker-mv-table th.tbx-picker-mv-num,
.tbx-picker-mv-table td.tbx-picker-mv-num {
  width: 76px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.tbx-picker-mv-table tbody tr:last-child td {
  border-bottom: 0;
}

.tbx-picker-error:empty {
  display: none;
}
.tbx-picker-error {
  margin-top: 10px;
  font-size: var(--tbx-fs-small);
  color: var(--tbx-red-text);
}

/* ── Picker on a phone ──
   The card head stacks and the commit control drops to its own full-width row,
   so the quantity and Add stop competing with the product name for space. */
@media (max-width: 899.98px) {
  .tbx-picker-search {
    margin: -16px -16px 12px;
  }
  .tbx-picker-head {
    flex-direction: column;
    gap: 12px;
  }
  .tbx-picker-commit {
    width: 100%;
  }
  .tbx-picker-qty {
    width: 84px;
    height: 42px;
    font-size: var(--tbx-fs-body);
  }
  .tbx-picker-add {
    flex: 1;
    height: 42px;
    font-size: var(--tbx-fs-body);
  }
  .tbx-picker-disclosure,
  .tbx-picker-openlink {
    height: 42px;
  }
  .tbx-picker-openlink {
    width: 42px;
  }
  /* Five equal columns are too tight at 375px — wrap to 3 + 2 instead of
     compressing each one until the labels break. */
  .tbx-picker-facts {
    grid-auto-flow: row;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px 8px;
  }
}

/* ── Barcode scanner (product list, mobile) ───────────────────────────────────
   The camera preview in #tbxScanModal. html5-qrcode injects its own <video> into
   .tbx-scan-stage at whatever size the stream reports, so the stage fixes the
   shape and the video is told to cover it — otherwise the dialog resizes itself
   the moment the camera starts. */
/* The reticle sits outside the stage (html5-qrcode empties the stage when it
   starts), so the frame is what both position against. */
.tbx-scan-frame {
  position: relative;
}

.tbx-scan-stage {
  width: 100%;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border-radius: var(--tbx-radius-control);
  background: var(--tbx-dark);
}

.tbx-scan-stage video {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover;
  display: block;
}

/* html5-qrcode also drops in a shaded region + border overlay of its own; ours
   is the only guide we want, so hide theirs. */
.tbx-scan-stage #qr-shaded-region { display: none !important; }

/* Aiming guide: a wide, short window, matching the shape of a 1D barcode and the
   qrbox passed to the scanner in barcode_scan.js. */
.tbx-scan-reticle {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 78%;
  height: 45%;
  border: 2px solid var(--tbx-accent);
  border-radius: var(--tbx-radius-control);
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .35);
  pointer-events: none;
}

.tbx-scan-hint {
  margin: 10px 0 0;
  text-align: center;
  color: var(--tbx-text-muted);
  font-size: var(--tbx-fs-small);
}

/* ── Customer picker (type-to-search combobox) ───────────────────────────────
   A text input + dropdown standing in for a plain <select> where the list of
   customers could grow past what's comfortable to render in full. */
.tbx-combo {
  position: relative;
}
.tbx-combo-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 20;
  max-height: 260px;
  overflow-y: auto;
  background: var(--tbx-surface);
  border: 1px solid var(--tbx-border);
  border-radius: var(--tbx-radius-control);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .12);
}
.tbx-combo-item {
  padding: 8px 12px;
  font-size: var(--tbx-fs-small);
  color: var(--tbx-text-primary);
  cursor: pointer;
}
.tbx-combo-item:hover,
.tbx-combo-item.is-active {
  background: var(--tbx-border-band);
}
.tbx-combo-empty {
  padding: 8px 12px;
  font-size: var(--tbx-fs-small);
  color: var(--tbx-text-muted);
}
