/* NEX-T POS - back-office (manager) screens: js/backoffice/*.js. Built on css/base.css (tokens, buttons, fields, cards,
   tables, badges, dialogs); only what those screens add is here, all from the base tokens so dark mode follows.
   Responsive down to 375 px: on a phone (≤ 640 px) a table made by POS.bo.table becomes a list of cards (the main cell
   as the title, every other cell as "label  value" taken from data-label), toolbars wrap, grids go to one column.
   Sections: page pieces · fields · filters & range · tables (cards on phones) · thumbnails & colours · product picker ·
   dashboard & reports · products · stock · sales & shifts · users & account · settings & backup · phones */

/* ------------------------------------------------------------------ page pieces */
.bo-title-wrap { min-width: 0; }
.bo-title-wrap .card-sub { margin-top: 4px; }
.bo-head-actions { justify-content: flex-end; }
.bo-card-titles { flex: 1 1 auto; min-width: 0; }
.bo-ml { margin-left: 6px; }
.bo-card-foot { margin: 0; padding: 8px 16px 12px; }
.bo-card-tools { padding: 0 16px 12px; }
.card-flush .table-wrap { border: 0; border-radius: 0; }
.card-flush > .card-head { margin-bottom: 12px; }
.card-flush > div > .loading, .card-flush > div > .empty { padding: 24px 16px; }
.bo-tab-panel { min-height: 160px; }
.bo-more { display: flex; justify-content: center; margin-top: 14px; }
.bo-who { display: inline-flex; flex-direction: column; line-height: 1.3; }
.bo-method { display: inline-flex; align-items: center; gap: 8px; }
.bo-method .ico { color: var(--muted); }
.bo-flag-list { display: inline-flex; flex-wrap: wrap; gap: 4px; }

/* figures: a row of tiles */
.bo-stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin: 0 0 16px; }
.bo-stats > .card + .card { margin-top: 0; }
.bo-stat { padding: 14px 16px; border-top: 3px solid transparent; }
.bo-stat-accent { border-top-color: var(--accent); }
.bo-stat-warn { border-top-color: var(--warn); }
.bo-stat .stat-sub { overflow-wrap: anywhere; }

/* a share bar (tables) */
.bo-bar { position: relative; height: 10px; min-width: 60px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.bo-bar-fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: inherit; background: var(--accent); }
.bo-bar-warn .bo-bar-fill { background: var(--warn); }
.table td.bo-bar-cell { width: 28%; min-width: 80px; }

/* ------------------------------------------------------------------ fields and forms */
.bo-optional { font-weight: 400; font-size: 13px; color: var(--muted); }
.bo-form > * + *, .bo-form-main > * + *, .bo-form-side > * + * { margin-top: 14px; }
.bo-form .field-row + .field, .bo-form .field + .field-row { margin-top: 14px; }
.bo-form-error { margin: 0 0 4px; }
.bo-switch-field { display: flex; flex-direction: column; }
.bo-switch-field > .hint { margin: -6px 0 0 56px; color: var(--muted); font-size: 13px; }
.bo-switch-field .switch input:disabled + span { color: var(--muted); }
.field-label { font-weight: 600; font-size: 14px; }
.bo-int { max-width: 220px; }
.field .bo-int { max-width: none; }
.card-actions:empty { display: none; }

/* ------------------------------------------------------------------ filters and the date range */
.toolbar > .field + .field, .toolbar > * + .field { margin-top: 0; }
.bo-filter { min-width: 150px; flex: 0 1 auto; }
.bo-filter > label { font-size: 13px; font-weight: 600; color: var(--muted); }
.bo-filter-grow { flex: 1 1 240px; }
.bo-filter-switch { align-self: flex-end; }
.bo-search { position: relative; display: flex; align-items: center; min-width: 0; }
.bo-search-ico { position: absolute; left: 12px; color: var(--muted); pointer-events: none; }
.bo-search input { padding-left: 40px; }
.bo-range { flex: 0 1 auto; min-width: 0; }
.bo-range > .field-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.bo-range-seg { max-width: 100%; }
.bo-range-custom { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px 10px; margin-top: 8px; }
.bo-range-date { display: flex; flex-direction: column; gap: 3px; }
.bo-range-date input { width: auto; min-width: 150px; }
.bo-range-custom .field-error { flex-basis: 100%; }

/* ------------------------------------------------------------------ tables (POS.bo.table) */
.bo-table .cell-v { min-width: 0; }
.bo-table td.cell-empty { padding: 28px 16px; text-align: center; color: var(--muted); }
.bo-sort-ind { font-size: 10px; }
.table th .sort-btn:hover { color: var(--text); }
.bo-table tr.clickable:focus-visible td { background: var(--accent-soft); }

/* ------------------------------------------------------------------ product thumbnails and tile colours */
.bo-thumb { display: inline-flex; align-items: center; justify-content: center; flex: none; width: 36px; height: 36px; border-radius: 8px;
  object-fit: cover; font-weight: 800; font-size: 13px; line-height: 1; color: #fff; background: var(--surface-3); overflow: hidden; user-select: none; }
.bo-thumb-lg { width: 56px; height: 56px; font-size: 18px; border-radius: 10px; }
.bo-thumb-xl { width: 160px; height: 160px; font-size: 44px; border-radius: 14px; }
img.bo-thumb { background: var(--surface-2); border: 1px solid var(--line); }
/* the 8 tile colours (server.js COLORS): the same soft background + ink as the till's tiles (css/sell.css .tile-c-*),
   so the colour picked here looks as it will on the till */
.bo-color-grey { background: #e6e9ee; color: #3f4652; }
.bo-color-red { background: #fde0e0; color: #a01818; }
.bo-color-orange { background: #fde4cc; color: #9a4705; }
.bo-color-yellow { background: #fbefb4; color: #765800; }
.bo-color-green { background: #d8f2e1; color: #0f6b3c; }
.bo-color-teal { background: #d0f0ed; color: #0b655f; }
.bo-color-blue { background: #dde6fd; color: #1d44c4; }
.bo-color-purple { background: #ebdffb; color: #6a2bb8; }
@media (prefers-color-scheme: dark) {
  .bo-color-grey { background: #2b3242; color: #d3d9e4; }
  .bo-color-red { background: #4a1f25; color: #ffb3b8; }
  .bo-color-orange { background: #4a2d14; color: #ffc58f; }
  .bo-color-yellow { background: #45391a; color: #f6dc7a; }
  .bo-color-green { background: #173a27; color: #8fe0b2; }
  .bo-color-teal { background: #123b3a; color: #84e0d8; }
  .bo-color-blue { background: #1f2c58; color: #a9bdff; }
  .bo-color-purple { background: #34234f; color: #d4b8ff; }
}
.bo-prod { display: inline-flex; align-items: center; gap: 10px; min-width: 0; }
.bo-prod-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.bo-prod-name { font-weight: 600; overflow-wrap: anywhere; }

/* ------------------------------------------------------------------ the product picker (stock forms) */
.bo-pick { position: relative; }
.bo-pick-list { position: absolute; left: 0; right: 0; top: calc(var(--tap) + 4px); z-index: 20; max-height: 360px; overflow-y: auto; margin: 0; padding: 4px;
  list-style: none; background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); }
.bo-pick-item { display: flex; align-items: center; gap: 10px; min-height: var(--tap); padding: 6px 10px; border-radius: 6px; cursor: pointer; }
.bo-pick-item:hover, .bo-pick-item.on { background: var(--accent-soft); }
.bo-pick-name { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.bo-pick-note { margin-top: 4px; font-size: 13px; font-weight: 600; color: var(--muted); }
.bo-pick-note:empty { display: none; }

/* ------------------------------------------------------------------ dashboard and reports */
.bo-dash-grid, .bo-report-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(360px, 100%), 1fr)); gap: 14px; align-items: start; }
.bo-dash-grid > .card + .card, .bo-report-grid > .card + .card { margin-top: 0; }
.bo-dash-wide, .bo-span-all { grid-column: 1 / -1; }
.bo-report > .card + .card { margin-top: 14px; }
/* sales by hour: one bar per hour, the height is the amount */
.bo-hours-bars { display: flex; align-items: stretch; gap: 4px; height: 190px; margin: 0 0 8px; padding: 0; list-style: none; }
.bo-hour { display: flex; flex-direction: column; align-items: center; gap: 3px; flex: 1 1 0; min-width: 0; }
.bo-hour-count { min-height: 15px; font-size: 11px; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
.bo-hour-bar { position: relative; flex: 1 1 auto; width: 100%; border-radius: 4px 4px 0 0; background: var(--surface-2); }
.bo-hour-fill { position: absolute; left: 0; right: 0; bottom: 0; border-radius: 4px 4px 0 0; background: var(--accent); }
.bo-hour:hover .bo-hour-fill { background: var(--accent-hover); }
.bo-hour-label { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ products: the form, the import */
.bo-form-cols { display: grid; grid-template-columns: minmax(0, 1fr) 220px; gap: 20px; }
.bo-img-preview { display: flex; }
.bo-stock-now { display: flex; flex-direction: column; gap: 5px; }
.bo-product-dialog .dialog-actions [data-action="delete"] { margin-right: auto; }
.bo-colors { display: flex; flex-wrap: wrap; gap: 2px; }
.bo-color-opt { position: relative; display: inline-flex; align-items: center; justify-content: center; width: var(--tap); height: var(--tap); cursor: pointer; }
.bo-color-opt input { position: absolute; inset: 0; width: 100%; height: 100%; min-height: 0; margin: 0; padding: 0; opacity: 0; cursor: pointer; }
/* (the ring in the tile's ink colour tells the soft colours apart) */
.bo-swatch { display: block; width: 30px; height: 30px; border-radius: 50%; box-shadow: inset 0 0 0 2px currentColor; }
.bo-color-opt input:checked + .bo-swatch { box-shadow: inset 0 0 0 2px currentColor, 0 0 0 3px var(--surface), 0 0 0 5px var(--text); }
.bo-color-opt input:focus-visible + .bo-swatch { outline: 3px solid var(--focus); outline-offset: 5px; }
.bo-file-name { overflow-wrap: anywhere; font-weight: 600; }
.bo-import-out > * + * { margin-top: 10px; }
.bo-import-counts { gap: 6px; }
.bo-changes { color: var(--muted); }

/* ------------------------------------------------------------------ stock */
.bo-stock-cell { display: inline-flex; align-items: center; gap: 8px; }
.bo-move-form > .muted { margin: 0; }
.bo-lines-empty { display: flex; align-items: center; gap: 12px; padding: 18px; border: 2px dashed var(--line); border-radius: var(--radius-sm); }
.bo-lines-table td { vertical-align: middle; }
.bo-qty-group { display: inline-flex; align-items: center; gap: 6px; }
.bo-qty { width: 96px; text-align: right; font-variant-numeric: tabular-nums; }
.bo-dir { width: auto; min-width: 116px; }
.bo-qty-cell .field-error:empty { display: none; }
.bo-move-foot > * + * { margin-top: 14px; }
.bo-move-actions { gap: 10px; }
.bo-lines-table tr.bo-flash td { animation: bo-flash .9s ease-out; }
@keyframes bo-flash { from { background: var(--accent-soft); } }
.bo-result { margin: 0; }
.bo-result-list { margin: 6px 0 0; padding-left: 18px; }
.bo-move-details { overflow-wrap: anywhere; }

/* ------------------------------------------------------------------ sales and shifts (drawers) */
.bo-receipt-cell { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.bo-receipt-preview { padding: 12px; }
.bo-flags { padding: 10px 14px; border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent); border-radius: var(--radius-sm); background: var(--warn-soft); }
.bo-flags.is-reviewed { border-color: var(--line); background: var(--surface-2); color: var(--muted); }
.bo-flags-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.bo-flags-head .ico { color: var(--warn); }
.bo-flags.is-reviewed .bo-flags-head .ico { color: var(--ok); }
.bo-flag-items { margin: 0 0 8px; padding-left: 20px; }
.bo-flag-items li + li { margin-top: 3px; }
.bo-kv-money dd { font-variant-numeric: tabular-nums; }
.bo-sale-drawer .section-title, .bo-shift-drawer .section-title { margin: 8px 0 0; }
.bo-sale-drawer .table-wrap, .bo-shift-drawer .table-wrap { border-radius: var(--radius-sm); }

/* ------------------------------------------------------------------ users and my account */
.bo-password-row { align-items: stretch; }
.bo-password { flex: 1 1 200px; padding: 12px 16px; border: 2px dashed var(--line-strong); border-radius: var(--radius-sm); background: var(--surface-2);
  font: 700 26px/1.2 var(--mono); letter-spacing: .08em; text-align: center; user-select: all; overflow-wrap: anywhere; }
.bo-account { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(380px, 100%), 1fr)); gap: 14px; align-items: start; max-width: 960px; }
.bo-account > .card + .card { margin-top: 0; }
.bo-pin { font-family: var(--mono); letter-spacing: .3em; }

/* ------------------------------------------------------------------ settings and backup */
.bo-settings { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 16px; align-items: start; }
.bo-settings-main > .card + .card { margin-top: 14px; }
.bo-settings-main > .bo-form-error { margin-bottom: 14px; }
.bo-settings-side { position: sticky; top: calc(var(--topbar-h) + var(--safe-t) + 12px); }
.bo-settings-preview { padding: 10px; max-height: calc(100vh - var(--topbar-h) - 190px); overflow: auto; align-items: flex-start; }
.bo-preview-actions { margin-top: 12px; }
.bo-settings-side .hint { margin: 8px 0 0; color: var(--muted); font-size: 13px; }
.bo-savebar { position: sticky; bottom: var(--safe-b); z-index: 5; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 14px; padding: 10px 14px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.bo-savebar-text { color: var(--muted); font-weight: 600; }
.bo-savebar.is-dirty { border-color: var(--accent); box-shadow: var(--shadow-lg); }
.bo-savebar.is-dirty .bo-savebar-text { color: var(--accent); }
.bo-pct { max-width: 160px; }
.bo-pay-switches { display: flex; flex-direction: column; }
.bo-pay-switches > .field-label { margin-bottom: 2px; }
.bo-pay-switches > .hint { color: var(--muted); font-size: 13px; }
.bo-media-row { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 14px; }
.bo-media-row > .stack-sm { flex: 1 1 200px; min-width: 0; }
.bo-media-row .hint { color: var(--muted); font-size: 13px; }
/* (white behind it in dark mode too: a logo / QR is drawn for paper) */
.bo-media-preview { display: flex; flex: none; align-items: center; justify-content: center; width: 120px; height: 120px; overflow: hidden;
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fff; }
.bo-media-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
.bo-media-preview .muted { color: #5d6573; }
.bo-backup-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)); gap: 14px; align-items: start; }
.bo-backup-grid > .card + .card { margin-top: 0; }

@media (max-width: 1100px) {
  .bo-settings { grid-template-columns: minmax(0, 1fr); }
  .bo-settings-side { position: static; }
  .bo-settings-preview { max-height: none; }
}
@media (max-width: 720px) {
  .bo-form-cols { grid-template-columns: minmax(0, 1fr); }
  .bo-form-side { order: -1; display: flex; flex-wrap: wrap; gap: 14px 20px; }
  .bo-form-side > * + * { margin-top: 0; }
  .bo-thumb-xl { width: 120px; height: 120px; font-size: 34px; }
}

/* ------------------------------------------------------------------ phones: tables become cards, everything one column */
@media (max-width: 640px) {
  .bo-table .phone-hide { display: none; }
  .bo-cards thead { display: none; }
  .bo-cards, .bo-cards tbody, .bo-cards tfoot, .bo-cards tr, .bo-cards td { display: block; width: 100%; }
  .bo-cards tr { padding: 10px 14px; border-bottom: 1px solid var(--line); }
  .bo-cards tbody tr:last-child { border-bottom: 0; }
  .bo-cards tfoot tr { border-top: 2px solid var(--line-strong); border-bottom: 0; background: var(--surface-2); }
  .bo-cards td, .bo-cards tfoot td { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 3px 0; border: 0;
    text-align: right; white-space: normal; }
  .bo-cards td::before { content: attr(data-label); flex: none; max-width: 45%; color: var(--muted); font-size: 13px; font-weight: 600; text-align: left; }
  .bo-cards td:not([data-label])::before { content: none; }
  .bo-cards td > .cell-v { min-width: 0; overflow-wrap: anywhere; }
  .bo-cards td.cell-main { display: block; padding: 0 0 6px; text-align: left; font-size: 15px; font-weight: 700; }
  .bo-cards td.actions { justify-content: flex-start; padding-top: 8px; text-align: left; }
  .bo-cards td.cell-empty { display: block; text-align: center; }
  .bo-cards td.phone-hide { display: none; }
  .bo-cards .bo-who { align-items: flex-end; }
  .bo-cards td.cell-main .bo-who { align-items: flex-start; }
  .bo-cards .bo-bar-cell { width: 100%; }
  /* row colours on the whole card */
  .bo-cards tr td, .table.bo-cards tr.clickable:hover td, .table.bo-cards tr.is-warn td, .table.bo-cards tr.is-danger td,
  .table.bo-cards tr.is-selected td { background: transparent; }
  .table.bo-cards tr.clickable:hover, .table.bo-cards tr.clickable:focus-visible { background: var(--accent-soft); }
  .table.bo-cards tr.is-warn { background: var(--warn-soft); }
  .table.bo-cards tr.is-danger { background: var(--danger-soft); }
  .table.bo-cards tr.is-selected { background: var(--accent-soft); }
  .bo-lines-table tr.bo-flash { animation: bo-flash .9s ease-out; }
  .bo-lines-table td.bo-qty-cell > .cell-v { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }

  .toolbar { gap: 10px; }
  .bo-filter { flex: 1 1 140px; min-width: 0; }
  .bo-range, .bo-filter-grow { flex: 1 1 100%; }
  .bo-range-date { flex: 1 1 140px; }
  .bo-range-date input { width: 100%; min-width: 0; }
  .page-head .bo-head-actions { width: 100%; justify-content: flex-start; }
  .bo-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .bo-stat { padding: 12px; }
  .bo-stat .stat-value { font-size: 21px; overflow-wrap: anywhere; }
  .bo-hours-bars { height: 150px; gap: 2px; }
  .bo-hour-count { font-size: 10px; }
  .bo-password { font-size: 22px; }
  .bo-switch-field > .hint { margin-left: 0; margin-top: -4px; }
  .bo-move-actions .btn-lg { flex: 1 1 auto; }
  .bo-savebar .btn { flex: 1 1 auto; }
  .bo-media-preview { width: 96px; height: 96px; }
  .tabs .tab { padding: 8px 10px; }
}
