/* The app's pages (#appRoot inside the shell): page body, toolbars,
   buttons, form fields, inventory cards, usage log, forecasting,
   procurement codes, reports, modal sheets. Colours come from the tokens
   in base.css (the whole app is dark only); the page
   frame and sidebar live in shell.css.

   Shape rule (shared with shell.css and home.css): panels 16px, cards and
   rows 14px, inputs and buttons 10px, chips and badges are pills. */

#appRoot { --ease-out: cubic-bezier(0.23, 1, 0.32, 1); }

/* ---------- Page body ---------- */
/* Centred column, so wide screens get balanced margins instead of one
   empty band down the right. Same width as the page header. */
.page-body { max-width: 1440px; margin-inline: auto; padding: 28px 48px 72px; }
.view { display: none; }
/* Page switches are instant: people jump between pages all day. */
.view.active { display: block; }

.view-toolbar {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap;
  gap: 12px 20px; margin-bottom: 20px;
}
.view-toolbar .field { margin-bottom: 0; }
.view-toolbar .section-title { margin: 0; }
.view-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.view-head p { margin: 0; color: var(--ink-soft); font-size: 14px; max-width: 56ch; }

.section-title {
  display: flex; align-items: baseline; gap: 10px;
  margin: 32px 0 14px; font-size: 17px; font-weight: 600; letter-spacing: -0.01em; color: var(--ink);
}
.section-title--spaced { margin-top: 44px; }
.panel {
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  padding: 20px 22px;
}
.panel > .section-title:first-child { margin-top: 0; }
.qty-mini { font-size: 12.5px; color: var(--ink-faint); }

/* Old-style back buttons on the full-page admin screens */
.home-btn { font-size: 12.5px; padding: 6px 11px; margin-bottom: 8px; }

.sync-pill { font-size: 12px; color: var(--ink-soft); display: flex; align-items: center; gap: 7px; }
.sync-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); flex-shrink: 0; }
.sync-dot.offline { background: var(--ink-faint); }

/* Inventory summary chips */
.stat-strip { display: flex; flex-wrap: wrap; gap: 8px; }
.stat {
  display: inline-flex; align-items: baseline; gap: 6px;
  padding: 6px 13px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--border);
}
.stat .num { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--ink); }
.stat .lbl { font-size: 13px; color: var(--ink-soft); }
.stat.critical { border-color: var(--critical-border); background: var(--critical-bg); }
.stat.critical .num { color: var(--critical); }
.stat.warning { border-color: var(--warning-border); background: var(--warning-bg); }
.stat.warning .num { color: var(--warning); }

/* ---------- Buttons ---------- */
button.primary {
  font-family: inherit; font-size: 14px; font-weight: 600;
  background: var(--brand); color: var(--on-brand); border: none;
  padding: 10px 18px; border-radius: 10px; cursor: pointer;
  white-space: nowrap;
  transition: background-color 150ms ease, transform 160ms var(--ease-out);
}
button.primary:hover { background: var(--brand-ink); }
button.primary:active { transform: scale(0.98); }
button.primary:disabled { opacity: 0.5; cursor: default; transform: none; }
button.secondary {
  font-family: inherit; font-size: 13.5px; font-weight: 600;
  background: var(--panel-alt); color: var(--ink); border: 1px solid var(--border);
  padding: 9px 15px; border-radius: 10px; cursor: pointer;
  transition: background-color 150ms ease, border-color 150ms ease, transform 160ms var(--ease-out);
}
button.secondary:hover { background: #15332f; border-color: rgba(92, 176, 169, 0.4); }
button.secondary:active { transform: scale(0.98); }

/* ---------- Form fields ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 500; color: var(--ink-soft); margin-bottom: 6px; }
.field input, .field select {
  width: 100%; font-family: inherit; font-size: 15px; padding: 10px 12px;
  border-radius: 10px; border: 1px solid var(--border); background-color: var(--bg); color: var(--ink);
  transition: border-color 150ms ease, box-shadow 150ms ease;
}
.field input::placeholder { color: var(--ink-faint); }
.field input:focus, .field select:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(79, 192, 184, 0.2);
}
.field select {
  appearance: none; -webkit-appearance: none; padding-right: 38px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238ea9a6' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 16px;
}
.search-field { width: min(100%, 380px); }
.field input.search-input {
  padding-left: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238ea9a6' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: 13px center; background-size: 17px;
}
.field input[type="checkbox"], #appRoot input[type="checkbox"] { accent-color: var(--brand); }

/* ---------- Inventory and usage cards ---------- */
.grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}
.card {
  position: relative;
  display: flex; flex-direction: column; align-items: flex-start;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  color: inherit;
  width: 100%;
  transition: border-color 150ms ease, background-color 150ms ease, transform 160ms var(--ease-out);
}
.card.critical { border-color: var(--critical-border); }
.card.warning { border-color: var(--warning-border); }
.card:active { transform: scale(0.99); }
@media (hover: hover) and (pointer: fine) {
  .card:hover { border-color: rgba(92, 176, 169, 0.45); background: #0f2a28; }
  .card.critical:hover { border-color: var(--critical); }
  .card.warning:hover { border-color: var(--warning); }
}
.cat {
  display: inline-block; font-size: 11px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--ink-soft); background: var(--panel-alt); padding: 4px 10px; border-radius: 999px; margin-bottom: 12px;
}
.card .name { font-size: 15.5px; font-weight: 600; margin-bottom: 12px; line-height: 1.35; color: var(--ink); }
/* Product photos (clinic setting, off by default). SSS photos have white
   backgrounds, so they sit on a light rounded square that reads as a
   deliberate thumbnail on the dark theme. A tile without a photo has no
   .card-photo at all, so nothing is reserved for it. */
.card-head { display: flex; align-items: flex-start; gap: 12px; width: 100%; }
.card-head-text { flex: 1; min-width: 0; }
.card-photo, .sheet-photo {
  flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  background: #F4F7F6; border-radius: 12px; overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.06);
}
.card-photo { width: 72px; height: 72px; padding: 6px; margin-bottom: 10px; }
.card-photo img, .sheet-photo img {
  display: block; max-width: 100%; max-height: 100%; object-fit: contain;
  mix-blend-mode: multiply; /* melts the photo's white into the square */
  opacity: 0; transition: opacity 0.2s ease;
}
.card-photo img.loaded, .sheet-photo img.loaded { opacity: 1; }
.sheet-head { display: flex; align-items: flex-start; gap: 14px; }
.sheet-head-text { flex: 1; min-width: 0; }
.sheet-photo { width: 56px; height: 56px; padding: 5px; }
.sheet-photo[hidden] { display: none; }
@media (max-width: 520px) {
  .card-photo { width: 60px; height: 60px; padding: 5px; }
}
.card .qty-row { display: flex; align-items: baseline; gap: 7px; margin-bottom: 8px; margin-top: auto; }
.card .qty { font-family: inherit; font-size: 30px; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1; }
.card .unit { font-size: 13px; color: var(--ink-soft); }
.box-sub { font-family: inherit; font-size: 12.5px; color: var(--brand-ink); margin-bottom: 10px; font-variant-numeric: tabular-nums; }
.card .name + .status-line { margin-top: auto; }
.status-pill, .card .status-line {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600;
  padding: 4px 10px; border-radius: 999px;
  background: var(--panel-alt); color: var(--ink-soft); border: 1px solid var(--border);
}
.status-pill::before, .card .status-line::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0;
}
.status-pill.critical, .card.critical .status-line { background: var(--critical-bg); color: var(--critical); border-color: var(--critical-border); }
.status-pill.warning, .card.warning .status-line { background: var(--warning-bg); color: var(--warning); border-color: var(--warning-border); }
.status-pill.ok, .card.ok .status-line { background: var(--ok-bg); color: var(--ok); border-color: var(--ok-border); }

/* Item detail (Usage → an item) */
.stat-tile-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin: 20px 0; }
.stat-tile { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 16px 18px; }
.stat-tile .stat-label { font-size: 13px; font-weight: 500; color: var(--ink-soft); margin-bottom: 10px; }
.stat-tile .stat-value {
  font-size: 26px; font-weight: 600; letter-spacing: -0.02em; color: var(--ink);
  display: flex; align-items: baseline; gap: 7px; font-variant-numeric: tabular-nums;
}
.stat-tile .stat-value .stat-unit { font-size: 13px; font-weight: 500; color: var(--ink-soft); letter-spacing: 0; }
.stat-delta { font-size: 15px; font-weight: 600; padding: 3px 10px; border-radius: 999px; display: inline-flex; align-items: center; gap: 3px; }
.stat-delta.up { background: var(--ok-bg); color: var(--ok); }
.stat-delta.down { background: var(--critical-bg); color: var(--critical); }
.stat-delta.flat { background: var(--panel-alt); color: var(--ink-soft); }

/* ---------- Usage log rows ---------- */
.log-list { display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 6px 16px; }
.log-row {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 0;
  font-size: 14px;
}
.log-row + .log-row { border-top: 1px solid var(--border); }
.log-list > .empty-state { padding: 28px 0; }
.log-icon {
  width: 36px; height: 36px; border-radius: 999px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.log-icon.used { background: var(--critical-bg); color: var(--critical); }
.log-icon.restocked { background: var(--ok-bg); color: var(--ok); }
.log-row .desc { flex: 1; min-width: 0; }
.log-row .desc b { font-weight: 600; }
.log-row .desc .used { color: var(--critical); font-weight: 600; }
.log-row .desc .restocked { color: var(--ok); font-weight: 600; }
.log-row .log-by { font-size: 12.5px; color: var(--ink-faint); margin-top: 2px; }
.log-row .time { color: var(--ink-faint); font-size: 12.5px; white-space: nowrap; flex-shrink: 0; font-variant-numeric: tabular-nums; }

.empty-state {
  text-align: center; padding: 56px 24px; color: var(--ink-soft); font-size: 14px; line-height: 1.55;
  border: 1px dashed var(--border); border-radius: 16px;
}
.empty-state .big { font-size: 16px; margin-bottom: 4px; color: var(--ink); font-weight: 600; }
.panel .empty-state { border: 0; padding: 32px 12px; }

/* ---------- Forecasting ---------- */
.timeframe-panel { margin-bottom: 20px; }
.timeframe-scope { font-size: 13.5px; color: var(--ink-soft); margin-bottom: 14px; }
.timeframe-scope b { color: var(--ink); font-weight: 600; }
.timeframe-row { display: flex; align-items: flex-end; flex-wrap: wrap; gap: 12px 14px; }
.timeframe-row .field { margin-bottom: 0; flex: 0 1 320px; }
.timeframe-row button.primary { height: 44px; }
.timeframe-status { font-size: 13px; color: var(--ink-soft); align-self: center; }

.rec-list { display: flex; flex-direction: column; gap: 10px; }
.rec-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  padding: 16px 18px;
  display: flex; gap: 14px; align-items: flex-start;
}
.rec-badge {
  min-width: 92px; text-align: center;
  font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px;
  flex-shrink: 0; margin-top: 1px; white-space: nowrap;
}
.rec-badge.critical { background: var(--critical-bg); color: var(--critical); border: 1px solid var(--critical-border); }
.rec-badge.warning { background: var(--warning-bg); color: var(--warning); border: 1px solid var(--warning-border); }
.rec-badge.ok { background: var(--ok-bg); color: var(--ok); border: 1px solid var(--ok-border); }
.rec-body .rec-name { font-weight: 600; font-size: 15px; margin-bottom: 4px; }
.rec-body .rec-reason { font-size: 13.5px; color: var(--ink-soft); line-height: 1.5; }
.rec-body .rec-order { font-size: 13px; color: var(--ink-faint); margin-top: 6px; font-variant-numeric: tabular-nums; }
.rec-body .rec-order-next { color: var(--ink-soft); }

.ai-empty {
  border: 1px dashed var(--border); border-radius: 16px;
  padding: 40px 24px; text-align: center;
}
.ai-empty p { color: var(--ink-soft); font-size: 14px; line-height: 1.55; max-width: 46ch; margin: 0 auto; }

/* ---------- Modal sheets ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(2, 10, 9, 0.62);
  display: none; align-items: flex-end; justify-content: center; z-index: 120;
}
.overlay.open { display: flex; }
@media (min-width: 640px) {
  .overlay { align-items: center; padding: 24px; }
}
.sheet {
  background: var(--panel); width: 100%; max-width: 440px;
  border-radius: 20px 20px 0 0;
  padding: 24px 24px 26px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55);
  max-height: 90vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.overlay.open .sheet { animation: sheetUp 260ms var(--ease-out, cubic-bezier(0.23, 1, 0.32, 1)); }
@keyframes sheetUp { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (min-width: 640px) {
  .sheet { border-radius: 20px; }
  .overlay.open .sheet { animation-name: sheetIn; animation-duration: 200ms; }
}
@keyframes sheetIn { from { transform: scale(0.97); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet h2 { margin: 0 0 4px 0; font-family: 'Outfit', 'IBM Plex Sans', sans-serif; font-size: 21px; font-weight: 600; letter-spacing: -0.01em; }
.sheet .sub { color: var(--ink-soft); font-size: 13.5px; line-height: 1.5; margin-bottom: 18px; }
.segmented { display: flex; background: var(--bg); border: 1px solid var(--border); border-radius: 12px; padding: 4px; margin-bottom: 18px; }
.segmented button {
  flex: 1; font-family: inherit; font-size: 13.5px; font-weight: 600;
  background: none; border: none; padding: 9px 10px; border-radius: 9px; cursor: pointer;
  color: var(--ink-soft); white-space: nowrap;
  transition: background-color 150ms ease, color 150ms ease;
}
.segmented button:hover { color: var(--ink); }
.segmented button.active { background: var(--brand-bg); color: var(--brand-ink); }
.stepper { display: flex; align-items: center; justify-content: center; gap: 20px; margin-bottom: 20px; }
.stepper button {
  width: 48px; height: 48px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--panel-alt); font-family: inherit; font-size: 22px; font-weight: 500; cursor: pointer; color: var(--ink);
  transition: border-color 150ms ease, transform 160ms cubic-bezier(0.23, 1, 0.32, 1);
}
.stepper button:hover { border-color: var(--brand); }
.stepper button:active { transform: scale(0.94); }
.stepper .amt {
  width: 104px; padding: 2px 0;
  font-family: inherit; font-size: 32px; font-weight: 600; text-align: center; font-variant-numeric: tabular-nums;
  color: var(--ink); background: transparent;
  border: none; border-bottom: 2px solid var(--border); border-radius: 0;
  -moz-appearance: textfield; appearance: textfield;
  transition: border-color 150ms ease;
}
.stepper .amt:focus { outline: none; border-bottom-color: var(--brand); }
.stepper .amt::-webkit-outer-spin-button, .stepper .amt::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
/* Quick-add chips under the quantity */
.qty-chips { display: flex; justify-content: center; gap: 8px; margin: -4px 0 16px; }
.qty-chips button {
  font-family: inherit; font-size: 13.5px; font-weight: 600; font-variant-numeric: tabular-nums;
  padding: 7px 16px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: var(--panel-alt); color: var(--ink-soft);
  transition: border-color 150ms ease, color 150ms ease, transform 160ms cubic-bezier(0.23, 1, 0.32, 1);
}
.qty-chips button:hover { color: var(--ink); border-color: var(--brand); }
.qty-chips button:active { transform: scale(0.96); }
.stepper-note { text-align: center; font-size: 12.5px; color: var(--ink-soft); margin-top: -12px; margin-bottom: 16px; min-height: 16px; }
.sheet-actions { display: flex; gap: 10px; margin-top: 8px; }
.sheet-actions button { flex: 1; padding: 12px; border-radius: 10px; font-size: 14.5px; }

/* ---------- Low-stock banner (top of Inventory) ---------- */
.low-stock-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 18px; margin-bottom: 20px; border-radius: 14px;
  background: var(--panel); border: 1px solid var(--border);
}
.low-stock-banner.critical { background: var(--critical-bg); border-color: var(--critical-border); }
.low-stock-banner.warning { background: var(--warning-bg); border-color: var(--warning-border); }
.lsb-main { font-size: 14.5px; color: var(--ink); }
.low-stock-banner.critical .lsb-main b { color: var(--critical); font-weight: 600; }
.low-stock-banner.warning .lsb-main { color: var(--warning); }
.lsb-sub { font-size: 13px; color: var(--ink-soft); margin-top: 3px; }
.low-stock-banner button { flex-shrink: 0; font-size: 13px; padding: 8px 14px; }

/* ---------- Toasts (ui/toast.js) ---------- */
#toastHost {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 300;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  width: calc(100% - 32px); max-width: 420px; pointer-events: none;
}
.toast {
  width: 100%; pointer-events: auto; cursor: pointer;
  padding: 12px 16px; border-radius: 12px;
  font-size: 14px; line-height: 1.45; color: var(--ink); background: #0f2b29;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5), 0 2px 6px rgba(0, 0, 0, 0.3);
  animation: toastIn 200ms cubic-bezier(0.23, 1, 0.32, 1);
}
.toast.critical { background: #2a1d1c; color: var(--critical); font-weight: 600; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ---------- Procurement ---------- */
.code-row {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  padding: 14px 18px; margin-bottom: 10px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.code-row.is-match { border-color: var(--brand); background: var(--brand-bg); }
.code-row .name { font-weight: 600; font-size: 14.5px; }
.code-row .qty-mini { color: var(--ink-faint); font-size: 12.5px; margin-left: 8px; font-weight: 400; }
.code-pills { display: flex; gap: 6px; flex-wrap: wrap; }
.code-pill {
  font-size: 12px; padding: 4px 10px; border-radius: 999px;
  background: var(--panel-alt); border: 1px solid var(--border); color: var(--ink-soft);
}
.code-pill.match { background: var(--brand-bg); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
.code-pill b { color: var(--ink); font-family: 'IBM Plex Mono', monospace; font-weight: 600; }
.code-manage-btn {
  font-family: inherit; font-size: 13px; font-weight: 600; color: var(--brand-ink);
  background: var(--brand-bg); border: 1px solid transparent; padding: 7px 12px; border-radius: 10px; cursor: pointer;
  transition: border-color 150ms ease, transform 160ms cubic-bezier(0.23, 1, 0.32, 1);
}
.code-manage-btn:hover { border-color: rgba(92, 176, 169, 0.45); }
.code-manage-btn:active { transform: scale(0.98); }
/* Live code suggestions: neutral rows, the code in teal, then the name */
.code-manage-btn.suggestion-row {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  color: var(--ink); font-weight: 500;
}
.code-manage-btn.suggestion-row:hover { border-color: rgba(92, 176, 169, 0.45); background: #0f2a28; }
.suggestion-text { display: flex; align-items: baseline; gap: 14px; min-width: 0; }
.suggestion-text b { color: var(--brand-ink); flex-shrink: 0; }
.code-chip-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.code-chip-row:last-child { border-bottom: none; }
.code-chip-row .remove-code { background: none; border: none; color: var(--critical); font-size: 13px; cursor: pointer; font-weight: 600; }
.no-codes { color: var(--ink-faint); font-size: 13px; padding: 10px 0; }

.notice {
  font-size: 13.5px; line-height: 1.5; padding: 11px 14px; border-radius: 10px; margin-bottom: 14px;
  background: var(--panel-alt); color: var(--ink-soft); border: 1px solid var(--border);
}

/* ---------- Reports (order list) ---------- */
.panel .export-row {
  background: transparent; border: 0; border-radius: 0; margin: 0;
  padding: 12px 0;
}
.panel .export-row + .export-row { border-top: 1px solid var(--border); }
.panel .export-actions { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); }

/* ---------- Locations ---------- */
#locationsAdminContainer h3 { font-size: 16px; font-weight: 600; }
.room-group {
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  padding: 18px 20px; margin-bottom: 14px;
}
.room-group.is-archived { opacity: 0.72; }
.room-group .device-row {
  background: transparent; border: 0; border-radius: 0; margin: 0;
  padding: 12px 0; border-top: 1px solid var(--border);
}
.room-group .device-row:last-of-type { border-bottom: 1px solid var(--border); }
.device-row { border-radius: 12px; }

/* ---------- Responsive ---------- */
/* Two order-list panels need room; stack them on narrower windows. */
@media (max-width: 1099px) {
  .export-split { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 1499px) {
  .page-body { padding-left: 40px; padding-right: 40px; }
}
@media (max-width: 767px) {
  .page-body { padding: 20px 16px 32px; }
  .low-stock-banner { flex-direction: column; align-items: stretch; }
  /* Clear of the bottom tab bar */
  #toastHost { bottom: calc(84px + env(safe-area-inset-bottom)); }
  .view-toolbar { margin-bottom: 16px; }
  .search-field { width: 100%; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .card { padding: 14px; }
  .card .qty { font-size: 26px; }
  .panel { padding: 16px; }
  .log-list { padding: 4px 14px; }
  /* Usage item page: the three summary tiles stay side by side */
  .stat-tile-row { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 16px 0; }
  .stat-tile { padding: 12px; }
  .stat-tile .stat-label { font-size: 12px; margin-bottom: 6px; }
  .stat-tile .stat-value { font-size: 20px; flex-wrap: wrap; gap: 4px; }
  .stat-tile .stat-value .stat-unit { font-size: 11.5px; }
  .stat-delta { font-size: 13px; padding: 2px 8px; }
  /* Usage chart: the five range buttons share the full width */
  #view-log .segmented { flex: 1 1 100%; max-width: none !important; }
  #view-log .segmented button { padding: 8px 4px; font-size: 12.5px; min-width: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .overlay.open .sheet, .toast { animation: none; }
}

/* ---------- Suppliers ---------- */
/* Ordering: one block per supplier under the order list. */
#supplierOrderBlocks:not(:empty) { margin-top: 22px; display: grid; gap: 12px; }
.supplier-block {
  border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px;
  background: var(--panel-alt);
}
.supplier-block.is-none { background: transparent; border-style: dashed; }
.supplier-block-title { margin: 0 0 4px; font-weight: 600; font-size: 14.5px; color: var(--ink); }
.supplier-block-title .qty-mini { margin-left: 6px; font-weight: 400; }
.panel .supplier-block .export-actions { margin-top: 10px; padding-top: 0; border-top: 0; flex-wrap: wrap; }

/* Your suppliers */
.supplier-row { padding: 14px 0; border-top: 1px solid var(--border); }
.supplier-row:first-of-type { border-top: 0; padding-top: 0; }
.supplier-row-head { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 4px; }
.supplier-row-head b { font-size: 15px; margin-right: 4px; }
.supplier-small-btn { font-size: 12px; padding: 4px 10px; }
.supplier-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 12px; margin-top: 10px; }
.supplier-fields .field { margin-bottom: 8px; }
.supplier-settings .shift-check { margin: 4px 0 0; }
.supplier-settings .export-actions { margin-top: 16px; }
.field[hidden] { display: none; }

/* ---------- Expiry dates (supabase/expiry.sql) ---------- */
/* Tones: "expired" and "soon" (within a month) in red, "low" (within two
   months) in amber. */
.card .expiry-badge {
  margin-top: 8px; align-self: flex-start; font-size: 12px; font-weight: 500; line-height: 1.3;
  padding: 3px 9px; border-radius: 999px; border: 1px solid var(--warning-border);
  background: var(--warning-bg); color: var(--warning);
}
.card .expiry-badge[data-tone="soon"], .card .expiry-badge[data-tone="expired"] {
  border-color: var(--critical-border); background: var(--critical-bg); color: var(--critical);
}
.expiry-section { border-top: 1px solid var(--border); margin-top: 18px; padding-top: 16px; }
.expiry-section[hidden] { display: none; }
.expiry-batches { list-style: none; margin: 0 0 6px; padding: 0; }
.expiry-batches li { padding: 6px 0; font-size: 14px; color: var(--ink); }
.expiry-batches li + li { border-top: 1px solid var(--border); }
.expiry-batches li[data-tone="soon"] .qty-mini, .expiry-batches li[data-tone="expired"] .qty-mini { color: var(--critical); }
.expiry-batches li[data-tone="low"] .qty-mini { color: var(--warning); }
.expiry-add { margin-top: 10px; }
.expiry-add[hidden] { display: none; }
.expiry-add summary { cursor: pointer; font-size: 13.5px; color: var(--brand-ink); padding: 4px 0; }
.expiry-add-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; margin-top: 10px; }

/* ---------- Barcode scanning ---------- */
.view-toolbar .scan-btn { display: inline-flex; align-items: center; gap: 7px; flex-shrink: 0; }
.scan-video-wrap { position: relative; margin: 14px 0 12px; border-radius: 14px; overflow: hidden; background: #000; aspect-ratio: 4 / 3; }
.scan-video-wrap video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-frame { position: absolute; inset: 22% 12%; border: 2px solid rgba(111, 214, 204, 0.85); border-radius: 12px; box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.25); pointer-events: none; }
.scan-manual { display: flex; gap: 8px; }
.scan-manual input { flex: 1; min-width: 0; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--panel-alt); color: var(--ink); font: inherit; font-size: 14px; }
#scanCameraPanel[hidden], #scanPickPanel[hidden], #scanAddNewBtn[hidden] { display: none; }
.scan-pick-list { max-height: 46vh; overflow: auto; margin-top: 10px; }
.scan-pick-item { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%; text-align: left; margin-bottom: 6px; padding: 10px 12px; }
