:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --border: #e0e4e9;
  --text: #1c2430;
  --muted: #6b7480;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --danger-dark: #b91c1c;
  --success: #16a34a;
  --warning: #f59e0b;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.06);
}

/* Toggled via [data-theme] on <html> by store.js's applyDisplayMode(),
   driven by the Settings dialog's Display Mode option — see settings.js.
   Everything built on the variables above (almost the entire stylesheet)
   re-themes for free. Only the neutral/structural colors change here —
   --primary/--primary-dark/--danger/--danger-dark are left exactly as
   they are in light mode on purpose: several rules pair them with white
   text on a solid fill (.btn-primary, .tab-btn.active, .btn-danger:hover,
   .toast-error), and those already have good contrast as-is — lightening
   them for "dark mode" would break that contrast instead of improving
   anything. A handful of other rules hardcode a color outright instead
   of using a variable (badges, toasts, the Google sign-in button) and
   are left as-is too, for the same reason: deliberately-colorful
   accents/brand elements that stay legible on either background. */
:root[data-theme="dark"] {
  --bg: #10141a;
  --surface: #1a1f28;
  --border: #2b323d;
  --text: #e8ecf1;
  --muted: #8b97a5;
  --success: #4ade80;
  --warning: #fbbf24;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.5), 0 1px 2px rgba(0, 0, 0, 0.4);
}

:root[data-theme="dark"] .card-photo {
  background: #232a34;
}

:root[data-theme="dark"] .auth-error {
  background: #3a1c1c;
  color: #fca5a5;
  border-color: #5c2626;
}

:root[data-theme="dark"] .data-table tr.row-unpaid {
  background: #332b12;
}

:root[data-theme="dark"] .data-table tr.row-issue-unresolved {
  background: #332b12;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.hidden {
  display: none !important;
}

/* The `hidden` attribute alone isn't enough on anything that also has an
   author `display` rule (fieldset, .form-grid, etc. below all set one) —
   author styles always beat the browser's own [hidden]{display:none},
   regardless of selector specificity, so those elements need this to
   actually disappear. (Same fix a few narrower [hidden] rules elsewhere in
   this file already worked around one class at a time — this covers every
   element instead.) */
[hidden] {
  display: none !important;
}

/* ------------------------------ Header ------------------------------ */

.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-title {
  margin: 6px 0 10px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

/* Sized in em so it scales with whichever heading it's inline with
   (.app-title's small subtitle vs. the onboarding screen's full-size h1). */
.title-logo {
  height: 1em;
  width: auto;
  vertical-align: -0.15em;
}

.tabs {
  background: #f8f8fd;
  border-radius: 25px;
  padding: 4px;
}

.tabs-list {
  overflow-x: auto;
}

.tabs-toggle {
  display: none;
  border: none;
  background: transparent;
  font-size: 1.1rem;
  line-height: 1;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  color: var(--text);
}

/* Below 480px, .tabs-list collapses into a dropdown opened by the
   hamburger button — toggled via #tabs-list.open in app.js. */
@media (max-width: 480px) {
  .tabs {
    position: relative;
  }

  .tabs-toggle {
    display: inline-block;
  }

  .tabs-list {
    display: none;
  }

  .tabs-list.open {
    display: flex;
    flex-direction: column;
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
    padding: 6px;
    z-index: 50;
  }

  .tabs-list.open .tab-btn {
    width: 100%;
    text-align: left;
    border-radius: 8px;
  }
}

.tab-btn {
  border: none;
  background: transparent;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}

.tab-btn:hover {
  background: var(--bg);
}

.tab-btn.active {
  background: var(--primary);
  color: white;
}

.loading-banner {
  background: #fef9c3;
  color: #713f12;
  text-align: center;
  padding: 8px;
  font-size: 0.9rem;
}

.user-menu {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.user-logo {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  object-fit: cover;
}

#user-company-name {
  font-weight: 700;
  font-size: 1.2rem;
  color: var(--text);
  margin-right: auto;
}

/* ------------------------------ Auth screen ------------------------------ */

.auth-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.auth-view-inner {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: 100%;
  max-width: 380px;
}

.auth-view-title {
  margin: 0 0 18px;
  font-size: 1.3rem;
  text-align: center;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 24px;
  width: 100%;
  max-width: 380px;
}

.auth-card h1 {
  margin: 0 0 18px;
  font-size: 1.3rem;
  text-align: center;
}

.btn-google {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10px;
  font-weight: 600;
  color: #3c4043;
}

.btn-google:hover {
  background: #f8f8f8;
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 16px 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.auth-divider::before,
.auth-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.auth-secondary-action {
  width: 100%;
  margin-top: 12px;
}

.auth-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 18px;
  background: var(--bg);
  border-radius: 999px;
  padding: 4px;
}

.auth-tab-btn {
  flex: 1;
  border: none;
  background: transparent;
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}

.auth-tab-btn.active {
  background: var(--primary);
  color: white;
}

.auth-form .btn-primary {
  width: 100%;
  padding: 10px;
}

.auth-error {
  background: #fef2f2;
  color: var(--danger-dark);
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.85rem;
}

.logo-preview-row,
.photo-preview-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: -6px;
}

.logo-preview-row img,
.photo-preview-row img {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--border);
}

/* ------------------------------- Main -------------------------------- */

.app-main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 18px;
}

.view-header h2 {
  margin: 0;
}

#sales-view,
#commissions-view {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
}

.header-controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

#sales-machine-filter {
  font-size: 1rem;
}

.period-nav {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.period-nav {
  container-type: inline-size;
}

.period-tabs {
  display: flex;
  gap: 6px;
  background: var(--bg);
  border-radius: 999px;
  padding: 4px;
}

/* Period tabs collapse into a dropdown when the nav is too narrow for them. */
.period-select {
  display: none;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}

@container (max-width: 440px) {
  .period-tabs {
    display: none;
  }

  .period-select {
    display: block;
  }
}

.period-tabs button {
  border: none;
  background: transparent;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}

.period-tabs button.active {
  background: var(--primary);
  color: white;
}

.period-range-label {
  font-weight: 600;
  margin: 0 4px;
}

/* A daily/weekly label switches to mm/dd/yy below 480px — see
   periodRangeLabelHtml() in sales.js. Monthly/quarterly/yearly labels have
   no narrow span at all (nothing to compact), so this never hides them. */
.period-label-narrow {
  display: none;
}

@media (max-width: 480px) {
  .period-label-wide {
    display: none;
  }

  .period-label-narrow {
    display: inline;
  }

  .period-nav-label {
    display: none;
  }
}

/* Prev / date range / Next / date picker move as one block when the nav wraps. */
.period-pager {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: nowrap;
  white-space: nowrap;
  margin-left: auto;
}

.period-date-form {
  margin-left: auto;
}

.period-date-form input[type="date"] {
  font-family: inherit;
  font-size: 0.85rem;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  background: var(--surface);
}

.summary-totals {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.summary-totals .stat {
  display: flex;
  flex-direction: column;
}

.summary-totals .stat .label {
  color: var(--muted);
  font-size: 0.8rem;
}

.sales-pie {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 16px 0;
}

.sales-pie svg {
  width: 100%;
  max-width: 480px;
  height: auto;
}

.sales-pie text {
  fill: var(--text);
  font-size: 12px;
}

.sub-period-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 4px 0;
}

.sub-period-nav-title {
  font-weight: 600;
}

.sub-period-nav label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--muted);
}

.sub-period-nav select {
  font-family: inherit;
  font-size: 0.9rem;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}

/* Bars are drawn at a fixed pixel width (see salesBarChartHtml() in
   sales.js), not stretched to the container like the pie — this scrolls
   horizontally instead of squeezing bars when there are many buckets. */
/* justify-content is set twice on purpose: centering an overflowing flex
   child leaves its start-side overflow unreachable by scrolling (a scroll
   container's scrollLeft can't go negative) — here, that hid the early
   hours of the 24-bucket Hour chart. "safe center" (the second line)
   centers only when the content fits and left-aligns it otherwise, so
   every bucket stays reachable; browsers that don't support that value
   ignore the invalid declaration and keep the plain "center" above. */
.sales-bar-chart {
  margin: 16px 0;
  overflow-x: auto;
  display: flex;
  justify-content: center;
  justify-content: safe center;
}

.sales-bar-chart svg {
  height: 240px;
  flex-shrink: 0;
}

.sales-bar-chart text {
  fill: var(--text);
  font-size: 9px;
}

.summary-totals .stat .value {
  font-size: 1.4rem;
  font-weight: 700;
}

.inline-filter {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.inline-filter select {
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

/* ------------------------------- Cards -------------------------------- */

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

/* Machine cards specifically: one full-width card per row instead of a
   multi-column grid, since each card already packs photo + info + a
   right-side stock-status column (see .card-stock-status). */
.card-grid-wide {
  grid-template-columns: 1fr;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.card-photo {
  height: 140px;
  background: #f0f2f5;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Product cards specifically: a square photo instead of the default
   fixed-height rectangle (locations/machines are unaffected). */
.card-photo-square {
  height: auto;
  aspect-ratio: 1 / 1;
}

.photo-placeholder {
  font-size: 2.5rem;
}

/* Add Reserve Stock dialog: a searchable grid of product tiles (photo +
   name) in place of a <select> — see openReserveStockForm() in
   reserve-stock.js. */
.product-picker-grid {
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 10px;
  margin-top: 8px;
  max-height: 370px;
  overflow-y: auto;
  padding: 2px;
}

.product-pick-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  font-family: inherit;
  cursor: pointer;
}

.product-pick-card .card-photo-square {
  border-radius: 6px;
  overflow: hidden;
}

.product-pick-card .photo-placeholder {
  font-size: 1.6rem;
}

.product-pick-card .product-pick-name {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.product-pick-card.selected {
  border-color: var(--primary);
  background: #eff6ff;
}

:root[data-theme="dark"] .product-pick-card.selected {
  background: #1e3a5f;
}

.card-body {
  padding: 14px 16px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.card-body h3 {
  margin: 0 0 2px;
  font-size: 1.05rem;
}

.card-actions {
  display: flex;
  gap: 8px;
  padding: 10px 16px 14px;
  border-top: 1px solid var(--border);
}

/* Photo-on-the-left variant (used by Machine cards). Two levels of flex:
   .card-horizontal itself lays out .card-top (photo + info) against
   .card-stock-status — row (stock status on the right) on wide screens,
   column (stock status at the bottom) on narrow ones — while .card-top's
   own photo-left/info-right layout stays a row at every width. .card-top is
   fixed/small so .card-stock-status can flex to take the rest of the card. */
.card-horizontal {
  flex-direction: row;
  align-items: stretch;
}

.card-top {
  display: flex;
  flex-direction: row;
  flex: 0 0 440px;
  min-width: 0;
}

.card-horizontal .card-photo {
  width: 110px;
  height: auto;
  flex-shrink: 0;
}

.card-horizontal .card-main {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.card-stock-status {
  flex: 1;
  min-width: 0;
  max-height: 250px;
  overflow-y: auto;
  padding: 14px 16px;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 8px;
}

.card-location-top {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
}

.card-body h3.card-machine-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
}

.more-link {
  align-self: flex-start;
  background: none;
  border: none;
  padding: 0;
  margin-top: 2px;
  color: var(--primary);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

/* Keeps a .more-link and a second one next to it on the same line, with the
   second one pushed to the right (e.g. products.js's Suppliers »/Add to
   reserve stock pair) — plain siblings would otherwise each land on their
   own line, since .card-body is a column flex container. */
.card-link-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-link-row .reserve-stock-link {
  margin-left: auto;
}

.more-link:hover {
  text-decoration: underline;
}

/* --------------------------- Data tables --------------------------- */

.table-wrap {
  overflow-x: auto;
  margin-top: 16px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.data-table th,
.data-table td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

/* Free-form text columns (e.g. Owner Issues' Message/Notes) clip to one
   line with an ellipsis instead of stretching the table; the full text is
   on each cell's title attribute, shown by the browser on hover. */
.data-table td.col-clip {
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Individual Sales: no line between rows of the same sale (its last row
   keeps the normal border, separating it from the next sale's group) —
   see the rowspan'd Timestamp/Location grouping in sales.js. */
.data-table tr.sale-group-row td {
  border-bottom: none;
}

.issue-note-text {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.data-table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.data-table tr.row-unpaid {
  background: #fffbeb;
}

/* Owner Issues tab: unresolved rows stand out light yellow; resolved rows
   are plain white (var(--surface), same as an unmarked row). */
.data-table tr.row-issue-unresolved {
  background: #fffbeb;
}

.data-table tr.row-issue-resolved {
  background: var(--surface);
}

/* Name and (on narrow screens) price share one block beside the product image. */
.product-text {
  display: inline-block;
  vertical-align: middle;
}

/* "x {quantity}" under the product name — always shown. .price-inline
   nested inside it is the gross sale for that row, hidden until the same
   narrow width where the Gross Sale column itself is hidden (.col-gross)
   — it then joins this same line (not a line of its own), after 4 spaces. */
.product-qty {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 2px;
}

.price-inline {
  display: none;
}

@media (max-width: 640px) {
  .ts-time {
    display: block;
  }

  .ts-sep {
    display: none;
  }

  .col-gross {
    display: none;
  }

  .price-inline {
    display: inline;
  }
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  line-height: 1;
  padding: 4px;
}

.icon-btn:hover {
  color: var(--text);
}

.table-photo-cell {
  display: flex;
  align-items: center;
  gap: 8px;
}

.table-photo {
  width: 28px;
  height: 28px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.table-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 4px;
}

.table-photo-placeholder {
  font-size: 1.1rem;
}

/* The Details dialog stacks on top of the already-open Replenishment
   Calculation dialog (see openReplenishmentDetailDialog() in
   reserve-stock.js) rather than replacing it, so it needs a higher
   z-index than the regular .modal-overlay (100) it's layered over. */
.replenishment-detail-overlay {
  z-index: 150;
}

.replenishment-more-suppliers {
  margin-top: 4px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card-bg-alt, rgba(127, 127, 127, 0.08));
  white-space: normal;
}

.replenishment-more-supplier+.replenishment-more-supplier {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-top: 16px;
}

.pagination-status {
  color: var(--muted);
  font-size: 0.85rem;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.table-icon {
  width: 28px;
  height: 28px;
  border-radius: 5px;
  object-fit: cover;
  vertical-align: middle;
  margin-right: 8px;
}

.sales-icon {
  width: 60px;
  height: 60px;
  border-radius: 8px;
}

.table-icon-placeholder {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  font-size: 1rem;
}

/* --------------------------- Machine stock status --------------------------- */

.stock-status {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 2px 0;
}

/* Icon in its own left column; name/count + the bar stack in a column to
   its right, so the bar spans only that right column, not the icon too. */
.stock-item {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.stock-item-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.stock-item-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.8rem;
}

/* 36x36 product icon in the stock status list */
.stock-item-icon {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border-radius: 4px;
  overflow: hidden;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
}

.stock-item-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.stock-item-icon-placeholder {
  font-size: 0.8rem;
  line-height: 1;
}

.stock-item-name {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stock-item-count {
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
}

/* Products > "Used in N machines »" dialog — plain .stock-item-row rows
   (see products.js's openUsedInMachinesDialog()), stacked with a little
   more breathing room than the Machine card's own stock list since
   there's no icon/bar here to visually separate rows. */
.used-in-machines-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stock-bar {
  display: flex;
  height: 8px;
  border-radius: 999px;
  background: var(--bg);
  overflow: hidden;
}

.stock-bar-fill {
  height: 100%;
  border-radius: 999px;
  flex-shrink: 0;
}

/* Blue segment appended after the fill: quantity about to be restocked. */
.stock-bar-restock {
  height: 100%;
  background: var(--primary);
  flex-shrink: 0;
}

/* Restock Orders: quantity to add, in its own column right of the bar. */
.stock-item-restock-qty {
  width: 3rem;
  flex-shrink: 0;
  text-align: center;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--primary);
}

/* Same column, but editable (New Restock Order dialog) — the operator can
   nudge the auto-generated quantity up/down, capped at its own `max` (how
   much reserve stock has left for that product in this order). Operator-
   only — restockers themselves can no longer adjust restock quantities.
   Plain text, not an input. */
.qty-stepper {
  width: 3rem;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.qty-num {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--primary);
  min-width: 1.4ch;
  text-align: right;
}

.qty-arrows {
  display: inline-flex;
  flex-direction: column;
  gap: 2px;
}

.qty-arrows button {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 4px;
  width: 1.4rem;
  height: 1rem;
  padding: 0;
  font-size: 0.55rem;
  line-height: 1;
  cursor: pointer;
  color: var(--text);
}

.qty-arrows button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* Sits over the quantity column (the first column, 3rem wide). */
.restock-qty-title {
  margin: 0 0 6px;
  width: 3rem;
  text-align: center;
  font-size: 0.65rem;
  font-weight: 600;
  line-height: 1.1;
  color: var(--muted);
}

.stock-bar-ok {
  background: var(--success);
}

.stock-bar-low {
  background: var(--warning);
}

.stock-bar-critical {
  background: var(--danger);
}

.stock-bar-unknown {
  background: var(--border);
}

.muted {
  color: var(--muted);
  font-size: 0.87rem;
}

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* ------------------------------- Badges -------------------------------- */

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: capitalize;
  width: fit-content;
  background: #e5e7eb;
  color: #374151;
}

.badge-drinks {
  background: #dbeafe;
  color: #1e40af;
}

.badge-snacks {
  background: #fef3c7;
  color: #92400e;
}

.badge-combo {
  background: #ede9fe;
  color: #5b21b6;
}

.badge-wifi {
  background: #dcfce7;
  color: #166534;
}

.badge-cellular {
  background: #ffedd5;
  color: #9a3412;
}

.badge-commission {
  background: #fce7f3;
  color: #9d174d;
}

.badge-paid {
  background: #dcfce7;
  color: #166534;
}

.badge-unpaid {
  background: #fef3c7;
  color: #92400e;
}

/* Owner Issues tab: one color per issue type ("Other" uses .badge's own
   default gray, so it has no modifier class here). */
.badge-machine-malfunction {
  background: #fee2e2;
  color: #991b1b;
}

.badge-restock-request {
  background: #dbeafe;
  color: #1e40af;
}

.badge-product-suggestion {
  background: #dcfce7;
  color: #166534;
}

.badge-commission-question {
  background: #fce7f3;
  color: #9d174d;
}

.badge-app-problem {
  background: #ffedd5;
  color: #9a3412;
}

/* -------------------------------- Buttons ------------------------------- */

.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 0.9rem;
  cursor: pointer;
  font-weight: 500;
}

.btn:hover {
  background: var(--bg);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 0.82rem;
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-danger {
  background: var(--surface);
  border-color: var(--danger);
  color: var(--danger);
}

.btn-danger:hover {
  background: var(--danger);
  color: white;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  padding: 0;
  flex-shrink: 0;
}

/* Wraps an .icon-btn that opens a .filter-popover — see
   toggle-product-filter in products.js. position: relative anchors the
   popover and the badge to this button specifically, not the page. */
.filter-popover-wrap {
  position: relative;
  display: inline-flex;
}

.filter-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--primary);
  color: white;
  font-size: 0.65rem;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
}

.filter-popover {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 50;
  min-width: 220px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* -------------------------------- Modal -------------------------------- */

.modal-root {
  display: none;
}

.modal-root.open {
  display: block;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px 12px;
  overflow-y: auto;
  z-index: 100;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 480px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
}

.modal-wide {
  max-width: 800px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.modal-close {
  border: none;
  background: transparent;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
}

/* -------------------------------- Forms -------------------------------- */

.form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.form-grid .span-2 {
  grid-column: 1 / -1;
}

.form label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.form input,
.form select {
  font-family: inherit;
  font-size: 0.95rem;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  background: var(--surface);
}

.form input:focus,
.form select:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.form input:disabled,
.form select:disabled {
  background: var(--bg);
  color: var(--muted);
  cursor: not-allowed;
}

/* Add/Edit Product (Shelf) dialog: "Product *" and its search box share a
   line, instead of .form label's usual stacked layout. Specificity has to
   beat ".form label" (a class + a type selector), not just match it, or
   that rule's column direction wins regardless of source order. */
.form label.product-slot-search-row {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.product-slot-search-row input {
  flex: 1;
  min-width: 0;
}

.checkbox-label {
  flex-direction: row !important;
  align-items: center;
  gap: 8px !important;
}

.checkbox-label input {
  width: auto;
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.slider-row input[type="range"] {
  flex: 1;
  padding: 0;
  accent-color: var(--primary);
}

.slider-value {
  font-weight: 700;
  font-size: 0.9rem;
  min-width: 3ch;
  text-align: right;
}

fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

legend {
  font-weight: 700;
  padding: 0 6px;
  font-size: 0.9rem;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 4px;
}

/* --------------------------- Machine details dialog --------------------------- */

.detail-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.detail-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.9rem;
}

.detail-row .label {
  color: var(--muted);
}

.detail-section {
  margin-top: 16px;
}

.detail-section h4 {
  margin: 0 0 6px;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
}

.detail-section ul {
  margin: 0;
  padding-left: 18px;
  font-size: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* ---------------------------- Repeatable rows ---------------------------- */

.repeatable {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.row-item {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr auto;
  gap: 8px;
  align-items: center;
}

/* Two equal-width fields + remove (e.g. Product's supplier name/SKU rows). */
.row-item-2col {
  grid-template-columns: 1fr 1fr auto;
}

/* Supplier Name field's custom suggestion dropdown (products.js) — shows
   every known supplier name, unfiltered by what's typed; see
   openSupplierSuggestions(). */
.supplier-name-field {
  position: relative;
}

.supplier-suggest-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 50;
  max-height: 109px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  padding: 4px;
}

.supplier-suggest-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 7px 10px;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  border-radius: 6px;
  cursor: pointer;
}

.supplier-suggest-item:hover {
  background: var(--bg);
}

/* Product + capacity/cost/price/count/shelf + remove (Add/Edit Machine dialog's Stock rows). */
.row-item-stock {
  grid-template-columns: 2fr 1fr 1fr 1fr 1fr 1fr auto;
}

.row-item select,
.row-item input {
  padding: 7px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
}

/* Product (opens a picker — see openPurchaseProductPicker() in
   reserve-stock.js) + Individuals checkbox + 3 value fields + remove
   (Log Purchase Receipt dialog's rows). */
.row-item-purchase {
  grid-template-columns: 1.4fr auto 1fr 1fr 1fr auto;
}

.row-product-btn {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 60px;
  width: 250px;
  word-wrap: break-word;
  white-space: break-spaces;
  text-align: left;
  overflow: hidden;
  font-size: 0.85rem;
}

.row-product-btn.picked {
  border-color: var(--primary);
}

.row-product-btn.locked {
  cursor: default;
}

.row-product-btn img {
  flex: 1;
  width: 50px;
  max-width: 50px;
  height: 50px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
}

.row-product-icon-placeholder {
  font-size: 1.1rem;
  line-height: 1;
}

.row-product-name {
  flex: stretch;
  line-height: 1.15;
}

.row-field-a,
.row-field-b,
.row-field-c {
  width: 100px;
}

.row-field-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.row-field-label {
  font-size: 0.65rem !important;
  font-weight: 600;
  color: var(--muted);
}

.row-individuals-label {
  white-space: nowrap;
  font-size: 0.85rem;
  color: var(--muted);
}

/* ------------------------------ Assign UI ------------------------------ */

.assigned-machine-list {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.assigned-machine-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.assign-row {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.assign-row select {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

/* -------------------------------- Toasts -------------------------------- */

.toast-root {
  position: fixed;
  bottom: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
}

.toast {
  background: #1c2430;
  color: white;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 0.9rem;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  box-shadow: var(--shadow);
  max-width: 320px;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast-error {
  background: var(--danger-dark);
}

.toast-success {
  background: #14532d;
}

/* ------------------------------ Responsive ------------------------------ */

@media (max-width: 640px) {
  .form-grid {
    grid-template-columns: 1fr;
  }

  .row-item {
    /* grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); */
    grid-template-columns: auto auto;
  }

  .row-item select {
    grid-column: 1 / -1;
  }

  .row-item-stock .row-field-group-wide {
    grid-column: 1 / -1;
  }

  .app-main {
    padding: 14px;
  }

  .modal-overlay {
    padding: 0;
  }

  .modal {
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
  }

  .toast-root {
    left: 12px;
    right: 12px;
    bottom: 12px;
  }

  .toast {
    max-width: 100%;
  }

  .card-horizontal .card-photo {
    width: 84px;
  }

  .card-horizontal .photo-placeholder {
    font-size: 1.6rem;
  }

  .card-horizontal {
    flex-direction: column;
  }

  /* .card-top's flex-basis (260px) sizes width in the row layout above but
     would size height once flex-direction flips to column — reset it back
     to natural content sizing here. */
  .card-top {
    flex: 0 0 auto;
  }

  .card-stock-status {
    border-left: none;
    border-top: 1px solid var(--border);
  }
}

/* ------------------------------ Restock Orders ------------------------------ */

.restock-settings {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
  margin-bottom: 14px;
}

@media (max-width: 640px) {
  .restock-settings {
    grid-template-columns: 1fr;
  }
}

.restock-settings-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
}

.restock-mode-radio {
  display: flex;
  gap: 16px;
  white-space: nowrap;
}

.restock-mode-radio .radio-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: normal;
  flex: 1;
}

.add-machine-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 50vh;
  overflow-y: auto;
}

.add-machine-btn-row {
  width: 100%;
  text-align: left;
}

.restock-route {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.restock-stop {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}

.restock-stop-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.restock-stop-totals {
  margin-left: auto;
  text-align: right;
  font-weight: 600;
  color: var(--primary);
  white-space: nowrap;
}

.restock-stop-num {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.restock-order-stops {
  margin: 6px 0 0;
  padding-left: 18px;
  font-size: 0.87rem;
}

.restock-order-stops li {
  margin-bottom: 14px;
}

.restock-order-table {
  margin-top: 6px;
}

.restock-order-table td:first-child,
.restock-order-table th:first-child {
  width: 10rem;
}

.restock-order-table tfoot td {
  font-weight: 700;
  border-top: 2px solid var(--border);
}

.restock-address {
  font-size: 0.87rem;
  color: var(--primary);
  text-decoration: none;
}

.restock-address:hover {
  text-decoration: underline;
}

.input-with-button {
  display: flex;
  gap: 6px;
}

.input-with-button select {
  flex: 1;
  min-width: 0;
}

/* Press-and-hold password reveal (see utils.js's revealPasswordHtml). */
.reveal-password {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.reveal-password input {
  width: 9rem;
  padding: 0;
  border: none;
  background: transparent;
  font: inherit;
  color: inherit;
  outline: none;
}

.reveal-eye {
  display: inline-flex;
  align-items: center;
  padding: 2px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.reveal-eye:hover,
.reveal-eye:active {
  color: var(--primary);
}

/* Restock order status: big bold label on the right of the order card. */
.restock-order-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.restock-status {
  font-size: 1.2rem;
  font-weight: 800;
  text-align: right;
  white-space: nowrap;
}

.restock-status-new {
  color: #2563eb;
}

.restock-status-in_progress {
  color: #e26400;
}

.restock-status-completed {
  color: #16a34a;
}

/* Restock order route map (Google Maps), under the machine list. */
.order-route-map {
  height: 340px;
  margin-top: 14px;
  border-radius: var(--radius);
  isolation: isolate;
  background: var(--bg);
}

.map-error {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 16px;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

.restock-eta {
  margin-top: 10px;
  font-size: 0.95rem;
}

.restock-eta strong {
  color: var(--primary);
}

/* Restock Orders: red note beside a product's name when reserve stock can't fill it. */
.stock-item-title {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.stock-item-title .stock-item-name {
  flex: 0 1 auto;
}

.stock-item-warn {
  color: var(--danger);
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}

/* "See Restock details >>" link and the product table it reveals (Restock Orders list). */
.details-toggle {
  display: inline-block;
  margin-top: 4px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--primary);
  text-decoration: none;
}

.details-toggle:hover {
  text-decoration: underline;
}

.restock-details[hidden] {
  display: none;
}

.sales-ranking-title {
  margin: 22px 0 8px;
}

/* --------------------------- Machine Template dialog --------------------------- */

.template-shelves {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 12px;
}

.shelf-box {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px;
}

.shelf-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.shelf-items {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.shelf-cell {
  position: relative;
  width: 104px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  text-align: center;
  cursor: pointer;
  font: inherit;
  color: inherit;
}

.shelf-cell-photo {
  width: 100%;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.shelf-cell-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 4px;
}

.shelf-cell-placeholder {
  font-size: 1.6rem;
}

.shelf-cell-name {
  margin-top: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.shelf-cell-capacity {
  margin-top: 2px;
  font-size: 0.7rem;
  color: var(--muted);
}

.shelf-cell-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  font-size: 0.65rem;
  line-height: 1;
  cursor: pointer;
}

.shelf-cell-add {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 104px;
  font-size: 2rem;
  color: var(--muted);
  background: transparent;
  border-style: dashed;
}


/* --------------------------- Template dialog: product picker --------------------------- */

.product-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  max-height: 180px;
  overflow-y: auto;
  padding: 4px 2px;
}

.product-pick {
  width: 104px;
  padding: 8px;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  text-align: center;
  cursor: pointer;
  font: inherit;
  color: inherit;
}

.product-pick.selected {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 12%, var(--bg));
}

.product-pick-photo {
  width: 100%;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.product-pick-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 4px;
}

.product-pick-placeholder {
  font-size: 1.6rem;
}

.product-pick-name {
  margin-top: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.form-note-danger {
  margin: 4px 0 0;
  padding: 10px 12px;
  border: 1px solid var(--danger-dark);
  border-radius: 8px;
  background: color-mix(in srgb, var(--danger-dark) 10%, var(--surface));
  color: var(--danger-dark);
  font-size: 0.85rem;
  font-weight: 600;
}

/* ------------------------------ Bypass Mode toggle ------------------------------ */

.bypass-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}

.bypass-toggle input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.bypass-toggle-switch {
  position: relative;
  width: 38px;
  height: 20px;
  border-radius: 999px;
  background: var(--border);
  transition: background 0.15s;
  flex-shrink: 0;
}

.bypass-toggle-switch::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  transition: transform 0.15s;
}

.bypass-toggle input:checked+.bypass-toggle-switch {
  background: var(--danger-dark);
}

.bypass-toggle input:checked+.bypass-toggle-switch::before {
  transform: translateX(18px);
}

.bypass-toggle input:focus-visible+.bypass-toggle-switch {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.bypass-toggle-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.bypass-toggle input:checked~.bypass-toggle-label {
  color: var(--danger-dark);
}