/*
 * Back-office styles (ADR 0010).
 * Load order: sneat core.css -> theme-tokens.css -> backoffice.css.
 * Rule: no colour literals here. Every colour comes from a token (--app-*) or a
 * Bootstrap/Sneat custom property (--bs-*-rgb) so the brand stays a one-line change.
 */

/* ---------- Base ---------- */
/* The hidden attribute must win over utility classes such as .d-flex. */
[hidden] { display: none !important; }

body {
  font-family: var(--app-font);
  background-color: var(--app-bg);
}

.bo-skip:focus {
  position: fixed;
  top: var(--app-space-2);
  left: var(--app-space-2);
  z-index: 2000;
  padding: var(--app-space-2) var(--app-space-3);
  background: var(--app-paper);
  color: var(--app-heading);
  border-radius: var(--app-radius);
  box-shadow: var(--app-focus-ring);
}

/* Money, quantities and percentages: right aligned, tabular figures (ui-research §10.2, §11). */
.bo-num,
.bo-grid td.bo-num,
.bo-grid th.bo-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.bo-tabular { font-variant-numeric: tabular-nums; }
.bo-mono { font-family: var(--app-font-mono); font-size: 0.875em; }
.bo-neg { color: var(--bs-danger-text-emphasis); }

.bo-page-title { color: var(--app-heading); }
.bo-muted { color: var(--app-muted); }

/* ---------- Navbar ---------- */
.bo-global-search .form-control { min-width: 18rem; }
.bo-navbar-btn { min-height: 2.25rem; }

.bo-sync-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--app-space-2);
  min-height: 2.25rem;
  padding: 0 var(--app-space-3);
  border: 1px solid var(--app-border);
  border-radius: 50rem;
  background: var(--app-paper);
  color: var(--app-heading);
  font-size: 0.8125rem;
  font-weight: 500;
  white-space: nowrap;
}
.bo-sync-pill:hover { border-color: var(--app-primary); color: var(--app-primary); }

/* Status dot: always paired with a text label, never colour alone (ui-research §11). */
.bo-dot {
  display: inline-block;
  flex: 0 0 auto;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--app-muted);
}
.bo-dot--online { background: var(--app-online); }
.bo-dot--syncing { background: var(--app-syncing); }
.bo-dot--offline { background: var(--app-offline); }

/* ---------- Status chips (badges with icon + text) ---------- */
.bo-status {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-weight: 500;
  white-space: nowrap;
}
.bo-status .icon-base { font-size: 0.875rem; }

/* ---------- Filter chips ---------- */
.bo-chips { display: flex; flex-wrap: wrap; gap: var(--app-space-2); align-items: center; }
.bo-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  min-height: 1.875rem;
  padding: 0 0.25rem 0 0.75rem;
  border: 1px solid var(--app-border);
  border-radius: 50rem;
  background: var(--app-paper);
  color: var(--app-heading);
  font-size: 0.8125rem;
  line-height: 1.2;
}
.bo-chip--toggle { padding-right: 0.75rem; cursor: pointer; }
.bo-chip.is-active,
.bo-chip[aria-pressed="true"] {
  border-color: var(--app-primary);
  background: var(--app-primary-subtle);
  color: var(--app-primary);
}
.bo-chip-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--app-target-dense);
  height: var(--app-target-dense);
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
}
.bo-chip-remove:hover { background: rgba(var(--app-primary-rgb), 0.12); }
.bo-chip-count {
  display: inline-block;
  min-width: 1.25rem;
  padding: 0 0.375rem;
  border-radius: 50rem;
  background: rgba(var(--bs-secondary-rgb), 0.16);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* ---------- Saved views ---------- */
.bo-views .nav-link { text-transform: none; min-height: 2.25rem; display: inline-flex; align-items: center; gap: 0.375rem; }

/* ---------- Data grid (ADR 0005 standard grid) ---------- */
.bo-grid-card { overflow: hidden; }
.bo-grid-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--app-space-2);
  align-items: center;
  padding: var(--app-space-3) var(--app-space-4);
  border-bottom: 1px solid var(--app-border);
}
.bo-grid-toolbar .bo-grow { flex: 1 1 16rem; }

.bo-grid-wrap {
  --bo-row-h: 40px;
  overflow: auto;
  max-height: 68vh;
}
.bo-grid-wrap[data-density="compact"] { --bo-row-h: 32px; }
.bo-grid-wrap[data-density="comfortable"] { --bo-row-h: 48px; }

.bo-grid { margin-bottom: 0; }
.bo-grid > :not(caption) > * > * {
  height: var(--bo-row-h);
  padding-top: 0;
  padding-bottom: 0;
  vertical-align: middle;
}
.bo-grid-wrap[data-density="compact"] .bo-grid > :not(caption) > * > * {
  padding-left: 0.625rem;
  padding-right: 0.625rem;
  font-size: 0.875rem;
}
.bo-grid thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--app-paper);
  color: var(--app-heading);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  white-space: nowrap;
  box-shadow: inset 0 -1px 0 var(--app-border);
}
.bo-grid tfoot td,
.bo-grid tfoot th {
  position: sticky;
  bottom: 0;
  z-index: 2;
  background: var(--app-paper);
  color: var(--app-heading);
  font-weight: 600;
  box-shadow: inset 0 1px 0 var(--app-border);
}
/* Row headers in body and footer read as normal text (Sneat uppercases every th). */
.bo-grid tbody th,
.bo-grid tfoot th {
  text-transform: none;
  letter-spacing: normal;
  font-size: inherit;
}

/* Frozen first data column (name / SKU). */
.bo-grid .bo-freeze {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--app-paper);
}
.bo-grid thead .bo-freeze { z-index: 4; }
.bo-grid .bo-freeze + .bo-freeze { left: 2.75rem; }
.bo-grid .bo-col-check { width: 2.75rem; min-width: 2.75rem; }

.bo-grid tbody tr:hover > * { background-color: rgba(var(--app-primary-rgb), 0.04); }
.bo-grid tbody tr.is-selected > * { background-color: rgba(var(--app-primary-rgb), 0.1); }
.bo-grid tbody td:focus-visible,
.bo-grid tbody th:focus-visible { box-shadow: inset 0 0 0 2px var(--app-primary); }

.bo-sort {
  display: inline-flex;
  align-items: center;
  gap: 0.125rem;
  min-height: var(--app-target-dense);
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
}

/* Hit area wrapper: keeps 24 px targets even in compact rows (WCAG 2.2 2.5.8). */
.bo-hit {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--app-target-dense);
  min-height: var(--app-target-dense);
  margin: 0;
  cursor: pointer;
}
.bo-hit .form-check-input { margin: 0; }
.bo-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--app-target-dense);
  min-height: var(--app-target-dense);
  padding: 0.125rem;
}

.bo-product-cell { display: flex; flex-direction: column; line-height: 1.2; min-width: 14rem; }
.bo-product-cell a { color: var(--app-heading); font-weight: 500; }
.bo-product-cell a:hover { color: var(--app-primary); }
.bo-product-cell small { color: var(--app-muted); }
.bo-grid-wrap[data-density="compact"] .bo-product-cell { flex-direction: row; gap: 0.5rem; align-items: baseline; white-space: nowrap; }

/* Inline edit: explicit save with Enter, cancel with Esc, dirty highlight (ui-research §10.2). */
.bo-inline {
  width: 6.5rem;
  min-height: var(--app-target-dense);
  margin-left: auto;
  padding: 0.125rem 0.5rem;
  border: 1px solid transparent;
  border-radius: var(--app-radius);
  background: transparent;
  color: var(--app-heading);
  text-align: right;
  font: inherit;
  font-variant-numeric: tabular-nums;
}
.bo-inline:hover { border-color: var(--app-border); }
.bo-inline:focus { border-color: var(--app-primary); background: var(--app-paper); outline: none; box-shadow: var(--app-focus-ring); }
.bo-inline.is-dirty { border-color: var(--app-warning); background: rgba(var(--bs-warning-rgb), 0.14); }
.bo-inline.is-invalid { border-color: var(--app-danger); background: rgba(var(--bs-danger-rgb), 0.08); }
.bo-inline.is-saved { border-color: var(--app-success); }
.bo-inline-wrap { display: flex; align-items: center; justify-content: flex-end; gap: 0.25rem; }
.bo-inline-unit { color: var(--app-muted); font-size: 0.8125rem; }

/* Bulk action bar: appears on selection, same height as a row (Carbon pattern). */
.bo-bulkbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--app-space-2);
  min-height: 3rem;
  padding: var(--app-space-2) var(--app-space-4);
  background: var(--app-primary-subtle);
  color: var(--app-heading);
  border-bottom: 1px solid var(--app-border);
}
.bo-bulkbar[hidden] { display: none; }

.bo-grid-footer {
  display: flex;
  flex-wrap: wrap;
  gap: var(--app-space-2);
  align-items: center;
  justify-content: space-between;
  padding: var(--app-space-2) var(--app-space-4);
  border-top: 1px solid var(--app-border);
  font-size: 0.8125rem;
}

/* Row states (never colour alone; each also carries an icon or text). */
.bo-row-warn > * { background-color: rgba(var(--bs-warning-rgb), 0.08); }
.bo-row-danger > * { background-color: rgba(var(--bs-danger-rgb), 0.06); }
.bo-row-ok > * { background-color: transparent; }

/* Drill-down rows in reports. */
.bo-drill-toggle[aria-expanded="true"] .bx-chevron-right { transform: rotate(90deg); }
.bo-drill-toggle .bx-chevron-right { transition: transform 0.15s ease; }
.bo-drill-row > * { background-color: rgba(var(--bs-secondary-rgb), 0.05); font-size: 0.875rem; }
.bo-drill-row .bo-indent { padding-left: 2.5rem; }
@media (prefers-reduced-motion: reduce) {
  .bo-drill-toggle .bx-chevron-right { transition: none; }
}

kbd.bo-kbd {
  padding: 0.0625rem 0.375rem;
  border: 1px solid var(--app-border);
  border-radius: var(--app-radius);
  background: var(--app-bg);
  color: var(--app-heading);
  font-family: var(--app-font-mono);
  font-size: 0.75rem;
  box-shadow: none;
}

/* ---------- Dashboard ---------- */
.bo-kpi { display: block; height: 100%; color: inherit; }
.bo-kpi:hover .card { box-shadow: 0 0 0 1px var(--app-primary), var(--app-shadow); }
.bo-kpi-label { color: var(--app-muted); font-size: 0.8125rem; font-weight: 500; }
.bo-kpi-value {
  color: var(--app-heading);
  font-size: 1.5rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1.25;
  white-space: nowrap;
}
.bo-kpi-meta { font-size: 0.8125rem; }
.bo-delta { display: inline-flex; align-items: center; gap: 0.125rem; font-weight: 500; font-variant-numeric: tabular-nums; }
.bo-delta--good .icon-base { color: var(--app-success); }
.bo-delta--bad .icon-base { color: var(--app-danger); }
.bo-delta--flat .icon-base { color: var(--app-muted); }

.bo-action-list .list-group-item > div { min-width: 0; }
.bo-action-list .list-group-item { display: flex; align-items: flex-start; gap: var(--app-space-3); padding-top: 0.625rem; padding-bottom: 0.625rem; }
.bo-action-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 2.25rem;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: var(--app-radius);
}
.bo-action-count { min-width: 2.5rem; color: var(--app-heading); font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }

.bo-chart { min-height: 15rem; }
.bo-chart--sm { min-height: 11rem; }

.bo-freshness { display: inline-flex; align-items: center; gap: 0.25rem; color: var(--app-muted); font-size: 0.8125rem; }

/* ---------- Scan-first screens (stock count, receiving) ---------- */
.bo-scan { position: relative; }
.bo-scan .form-control {
  min-height: var(--app-target-min);
  padding-left: 2.75rem;
  font-size: 1.125rem;
  font-variant-numeric: tabular-nums;
}
.bo-scan .bo-scan-icon {
  position: absolute;
  top: 50%;
  left: 0.875rem;
  transform: translateY(-50%);
  color: var(--app-muted);
  font-size: 1.375rem;
  pointer-events: none;
}
.bo-scan-flash { animation: bo-flash 0.6s ease-out; }
@keyframes bo-flash {
  from { box-shadow: 0 0 0 0.375rem rgba(var(--bs-success-rgb), 0.45); }
  to { box-shadow: 0 0 0 0 rgba(var(--bs-success-rgb), 0); }
}
@media (prefers-reduced-motion: reduce) {
  .bo-scan-flash { animation: none; outline: 2px solid var(--app-success); }
}

.bo-numpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--app-gap-pos); }
.bo-numpad .btn { min-height: var(--app-target-min); font-size: 1.125rem; font-variant-numeric: tabular-nums; }
.bo-last-scan-qty { color: var(--app-heading); font-size: var(--app-fs-total); font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1; }

/* Large-target (handheld) mode toggled on the page wrapper. */
.bo-large-targets .btn,
.bo-large-targets .form-control,
.bo-large-targets .form-select { min-height: var(--app-target-min); }
.bo-large-targets .bo-numpad .btn { min-height: var(--app-target-pos); font-size: 1.375rem; }
.bo-large-targets .bo-grid-wrap { --bo-row-h: 56px; }
.bo-large-targets .bo-qty-input { min-height: var(--app-target-min); font-size: 1.125rem; }

.bo-qty-input { width: 6rem; margin-left: auto; text-align: right; font-variant-numeric: tabular-nums; }
.bo-qty-input.is-under { border-color: var(--app-danger); }
.bo-qty-input.is-over { border-color: var(--app-warning); }

.bo-diff { display: inline-flex; align-items: center; gap: 0.25rem; justify-content: flex-end; font-weight: 600; font-variant-numeric: tabular-nums; }
.bo-diff--under { color: var(--bs-danger-text-emphasis); }
.bo-diff--over { color: var(--bs-warning-text-emphasis); }
.bo-diff--match { color: var(--app-muted); font-weight: 500; }

/* ---------- Product detail ---------- */
.bo-label-preview {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.25rem 1rem;
  max-width: 22rem;
  padding: var(--app-space-3);
  border: 1px dashed var(--app-border);
  border-radius: var(--app-radius);
  background: var(--app-paper);
  color: var(--app-heading);
}
.bo-label-preview .bo-label-price { grid-row: span 2; align-self: center; font-size: 2rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.bo-label-preview .bo-label-meta { color: var(--app-text); font-size: 0.75rem; }
.bo-label-preview .bo-label-barcode { grid-column: 1 / -1; font-family: var(--app-font-mono); letter-spacing: 0.2em; font-size: 0.75rem; }

.bo-timeline { list-style: none; margin: 0; padding: 0; }
.bo-timeline li { position: relative; padding: 0 0 var(--app-space-4) var(--app-space-4); border-left: 2px solid var(--app-border); }
.bo-timeline li:last-child { padding-bottom: 0; }
.bo-timeline li::before {
  content: "";
  position: absolute;
  top: 0.25rem;
  left: -0.4375rem;
  width: 0.75rem;
  height: 0.75rem;
  border: 2px solid var(--app-primary);
  border-radius: 50%;
  background: var(--app-paper);
}

.bo-required::after { content: " *"; color: var(--bs-danger-text-emphasis); }

/* ---------- Reports ---------- */
.bo-param-panel .form-label { font-size: 0.8125rem; }
.bo-report-meta { display: flex; flex-wrap: wrap; gap: var(--app-space-2) var(--app-space-4); align-items: center; }

/* ---------- Settings ---------- */
.bo-settings-nav .nav-link { justify-content: flex-start; text-align: left; display: flex; align-items: center; gap: 0.5rem; min-height: 2.5rem; }
.bo-adapter {
  border: 1px solid var(--app-border);
  border-radius: var(--app-radius-lg);
  padding: var(--app-space-3);
}
.bo-adapter.is-selected { border-color: var(--app-primary); box-shadow: 0 0 0 1px var(--app-primary); }
.bo-config-pre {
  margin: 0;
  padding: var(--app-space-3);
  border-radius: var(--app-radius);
  background: var(--app-bg);
  color: var(--app-heading);
  font-family: var(--app-font-mono);
  font-size: 0.8125rem;
  white-space: pre;
  overflow: auto;
}

/* ---------- Design notes ---------- */
.bo-notes { border-top: 3px solid var(--app-primary); }
.bo-notes-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  min-height: var(--app-target-min);
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--app-heading);
  font-weight: 600;
  text-align: left;
}
.bo-notes-toggle .bx-chevron-down { transition: transform 0.15s ease; }
.bo-notes-toggle[aria-expanded="true"] .bx-chevron-down { transform: rotate(180deg); }
.bo-notes ul { padding-left: 1.125rem; margin-bottom: 0; }
.bo-notes li + li { margin-top: 0.375rem; }

/* ---------- Gallery ---------- */
.bo-gallery-card { height: 100%; }
.bo-gallery-card a.stretched-link:focus-visible { box-shadow: none; }
.bo-gallery-card:focus-within { box-shadow: var(--app-focus-ring); }
.bo-gallery-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: var(--app-radius);
  background: var(--app-primary-subtle);
  color: var(--app-primary);
  font-size: 1.375rem;
}

/* Brand mark in the menu (replaces the Sneat demo logo). */
.bo-brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: var(--app-radius);
  background: var(--app-primary);
  color: var(--app-paper);
  font-size: 1.25rem;
}

/* Short tables in cards: no stray vertical scrollbar from sticky headers. */
.card .table-responsive { overflow-y: hidden; }

/* Sentence case for tabs and pills: Sneat capitalises every word, which breaks PL/ET labels. */
.nav-pills .nav-link,
.nav-tabs .nav-link { text-transform: none; }

/* Selects inside grid cells (reason codes) need room for their longest option. */
.bo-grid .form-select-sm { min-width: 11rem; }

/* Grid cells do not wrap; the grid scrolls horizontally with a frozen first column instead. */
.bo-grid > tbody > tr > td { white-space: nowrap; }

/* ---------- Validation summary fix ---------- */
.validation-summary-valid {
  display: none;
}