/* Inventory & Sales — shared styles */
* { box-sizing: border-box; touch-action: manipulation; } /* taps never double-tap-zoom on iOS */
/* iOS Safari auto-zooms any focused input under 16px — keep ALL fields at 16px minimum */
input, select, textarea { font-size: 16px; }
/* Dropdowns match normal text boxes everywhere (macOS renders native selects tiny) */
select {
  -webkit-appearance: none; -moz-appearance: none; appearance: none;
  width: 100%; padding: 11px 36px 11px 12px;
  border: 1px solid var(--line); border-radius: 10px;
  color: var(--ink); cursor: pointer;
  background: #fff url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2367748c' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 12px center;
}
:root {
  --bg: #f2f4f7;
  --card: #ffffff;
  --ink: #1a2233;
  --muted: #67748c;
  --line: #e4e8ef;
  --primary: #6d28d9;        /* app theme: purple */
  --primary-dark: #5b21b6;
  --primary-light: #ede9fe;  /* light purple button fill */
  --primary-press: #ddd6fe;
  --green: #059669;
  --red: #dc2626;
  --amber: #b45309;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
}
html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px; line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  background: #1e0a47; color: #fff;
  padding: 12px 18px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  position: sticky; top: 0; z-index: 50;
}
.topbar .brand { font-weight: 700; font-size: 17px; letter-spacing: .2px; }
.topbar .who { color: #c4b5fd; font-size: 14px; }
.topbar .spacer { flex: 1; }
.topbar a { color: #ddd6fe; font-size: 14px; font-weight: 600; }
/* Buttons in the header: light chip on the dark purple bar */
.topbar .btn, .topbar .btn.primary {
  background: var(--primary-light); border-color: var(--primary-light); color: var(--primary-dark);
}
.topbar .btn:hover, .topbar .btn.primary:hover { background: var(--primary-press); }

.wrap { max-width: 980px; margin: 0 auto; padding: 18px 14px 80px; }
.wrap.narrow { max-width: 560px; }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; margin-bottom: 16px;
}
.card h2 { margin: 0 0 12px; font-size: 18px; }
/* Desktop pages (admin/manager): divider line under every card title */
body.desktop .card > h2 {
  border-bottom: 1.5px solid var(--line);
  padding-bottom: 12px; margin-bottom: 14px;
}
/* Desktop pages: dropdowns and text fields stay a tidy width instead of
   stretching across the whole page */
body.desktop .field select,
body.desktop .field input { max-width: 340px; }
.card h3 { margin: 18px 0 8px; font-size: 15px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1.5px solid var(--primary); background: var(--primary); color: #fff;
  border-radius: 8px; padding: 10px 16px; font-size: 15px; font-weight: 600;
  cursor: pointer; transition: background .12s, transform .05s;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: var(--primary-dark); }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.green { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.green:hover { background: var(--primary-dark); }
.btn.danger { background: #fff; border-color: #fca5a5; color: var(--red); }
.btn.big { width: 100%; padding: 16px; font-size: 17px; border-radius: 12px; }
.btn.small { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 11px 12px; font-size: 16px;
  border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(109, 40, 217, .14);
}
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > .field { flex: 1; min-width: 130px; margin-bottom: 0; }

.grid { display: grid; gap: 10px; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 640px) {
  .grid.cols-3 { grid-template-columns: repeat(2, 1fr); }
}

table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th {
  text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .4px;
  color: var(--muted); padding: 8px 10px; border-bottom: 2px solid var(--line);
  white-space: nowrap;
}
.tbl td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
/* Tall multi-line cells (e.g. transfer items): pin every column to the top row */
.tbl.top td { vertical-align: top; padding-top: 12px; }
.tbl tr:last-child td { border-bottom: none; }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl tfoot td { font-weight: 700; border-top: 2px solid var(--line); }
.tbl-scroll { overflow-x: auto; }

.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 12.5px; font-weight: 700;
}
.badge.ok { background: #d1fae5; color: #065f46; }
.badge.low { background: #fef3c7; color: #92400e; }
.badge.out { background: #fee2e2; color: #991b1b; }
.badge.gray { background: #eef1f5; color: var(--muted); }
/* Quantity badges: light green fill, darker green outline, squarer corners */
.badge.qty {
  background: #dcfce7; color: #166534;
  border: 1px solid #16a34a; border-radius: 6px;
}
/* Product name chip + plain-text quantity. Chip color follows the (A)/(B)/(C)
   classification in the product name; unclassified products default to green. */
.nm-chip {
  display: inline-block; background: #dcfce7; color: #166534;
  border: 1px solid #16a34a; border-radius: 6px;
  padding: 4px 10px; font-weight: 700; font-size: 15px;
}
.nm-chip.cls-b { background: #dbeafe; color: #1e40af; border-color: #2563eb; }
.nm-chip.cls-c { background: #ffedd5; color: #9a3412; border-color: #ea580c; }
.nm-chip.sm { font-size: 12.5px; padding: 2px 8px; font-weight: 600; }
.nm-chip.lg { font-size: 18px; padding: 6px 12px; }
/* Batch age chips, traffic-light aging: green = oldest (move it first),
   yellow = older middle batches, red = newest */
.age-chip {
  display: inline-block; padding: 2px 8px; border-radius: 6px;
  font-size: 12.5px; font-weight: 700; margin-left: 6px;
}
.age-chip.oldest { background: var(--green); color: #fff; }
.age-chip.mid { background: #facc15; color: #713f12; }
.age-chip.new { background: var(--red); color: #fff; }
/* Name chip + age chip always ride side by side — never wrap apart */
.chip-pair { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; max-width: 100%; }
.chip-pair .age-chip { margin-left: 0; flex-shrink: 0; }
/* Age chip inside a pick button: tighter so the button stays compact */
button .age-chip { margin-left: 4px; padding: 1px 6px; font-size: 11.5px; }

/* Transfer status chips: light purple until confirmed, solid purple once received */
.status-chip {
  display: inline-block; padding: 4px 12px; border-radius: 8px;
  font-size: 12.5px; font-weight: 700;
  background: var(--primary-light); border: 1.5px solid var(--primary); color: var(--primary-dark);
}
.status-chip.filled { background: var(--primary); color: #fff; }

/* Quantity chip: white fill, black border, same corners as the name chips */
.qty-chip {
  display: inline-block; background: #fff; color: var(--ink);
  border: 1px solid #1a2233; border-radius: 6px;
  padding: 4px 10px; font-weight: 600; font-size: 14px;
}
.qty-text { color: var(--ink); font-weight: 600; font-size: 14px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
}
.stat .lbl { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); }
.stat .val { font-size: 24px; font-weight: 800; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .val.green { color: var(--green); }
.stat .val.red { color: var(--red); }

/* Tabs */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.tabs button {
  border: 1px solid var(--line); background: #fff; color: var(--muted);
  padding: 8px 14px; border-radius: 8px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.tabs button.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* Modal */
.modal-back {
  position: fixed; inset: 0; background: rgba(16, 24, 40, .55);
  display: none; align-items: flex-end; justify-content: center; z-index: 100;
  padding: 0;
}
.modal-back.open { display: flex; }
.modal {
  background: #fff; width: 100%; max-width: 480px;
  border-radius: 18px 18px 0 0;
  /* extra bottom padding keeps buttons clear of the iPhone address bar / home indicator */
  padding: 20px 18px calc(30px + env(safe-area-inset-bottom, 0px));
  max-height: 96vh; max-height: 96dvh; overflow-y: auto;
}
@media (min-width: 640px) {
  .modal-back { align-items: center; padding: 20px; }
  .modal { border-radius: 18px; }
}
.modal h2 { margin: 0 0 4px; font-size: 19px; }
/* Action buttons stay visible even when tall popup content scrolls */
.modal .modal-actions {
  position: sticky; bottom: 0; background: #fff;
  padding-top: 10px; margin-bottom: -6px;
}
.modal .sub { color: var(--muted); font-size: 14px; margin-bottom: 14px; }

/* Quantity stepper */
.stepper { display: flex; align-items: stretch; gap: 6px; }
.stepper button {
  width: 46px; min-height: 42px; font-size: 20px; font-weight: 700;
  border: 1.5px solid var(--primary);
  border-radius: 6px;
  background: var(--primary);          /* solid dark purple, matching all buttons */
  color: #fff;
  cursor: pointer;
}
.stepper button:active { background: var(--primary-dark); }
.stepper input {
  flex: 1; text-align: center; font-size: 18px; font-weight: 700;
  border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink);
  -moz-appearance: textfield; appearance: textfield;
}
/* the +/− buttons replace the browser's tiny number spinners */
.stepper input::-webkit-outer-spin-button,
.stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
/* plain number boxes with no spinner arrows */
input.no-spin::-webkit-outer-spin-button,
input.no-spin::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input.no-spin { -moz-appearance: textfield; appearance: textfield; }
/* Compact variant for placing the stepper in a header line */
.stepper.inline { flex-shrink: 0; }
.stepper.inline button { width: 42px; }
.stepper.inline input { flex: 0 0 52px; width: 52px; }
/* Mini variant for table rows (e.g. transfer send-qty) */
.stepper.mini { gap: 4px; justify-content: flex-end; }
.stepper.mini button { width: 30px; min-height: 30px; font-size: 15px; border-radius: 5px; }
.stepper.mini button:disabled { opacity: .4; cursor: not-allowed; }
.stepper.mini input { flex: 0 0 54px; width: 54px; min-height: 30px; padding: 2px; font-size: 15px; }

/* Sale math summary */
.mathbox {
  background: #f8fafc; border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 14px; margin: 14px 0; font-size: 15px;
}
.mathbox .mrow { display: flex; justify-content: space-between; padding: 3px 0; }
.mathbox .mrow.total { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 8px; font-weight: 800; font-size: 17px; }

/* Available Products (sell page): one tall, tappable row per product in a
   table layout — Product | Price | Quantity — colored by A/B/C classification */
.prod-head {
  display: grid; gap: 8px; padding: 0 12px 6px;
  font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .4px; color: var(--muted);
}
.prod-row {
  display: grid; gap: 8px; align-items: center;
  width: 100%; text-align: left; font: inherit; cursor: pointer;
  background: #dcfce7; border: 1px solid #16a34a; color: #166534;
  border-radius: 0;
  padding: 16px 12px; margin: 0;
}
.prod-row + .prod-row { margin-top: -1px; }  /* stacked rows share a border */
.prod-row.cls-b { background: #dbeafe; border-color: #2563eb; color: #1e40af; }
.prod-row.cls-c { background: #ffedd5; border-color: #ea580c; color: #9a3412; }
.prod-row:active { transform: scale(.99); }
.prod-row .p-name { font-weight: 700; font-size: 15.5px; }
.prod-row .p-price { font-weight: 600; }
.prod-row .p-qty { font-weight: 800; font-size: 16px; }
.prod-head .num, .prod-row .num { text-align: right; }

/* Scanner overlay */
#scan-overlay {
  position: fixed; inset: 0; background: #000; z-index: 200; display: none;
  flex-direction: column;
}
#scan-overlay.open { display: flex; }
#scan-overlay .scan-top { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; color: #fff; }
#qr-reader { flex: 1; overflow: hidden; }
#qr-reader video { object-fit: cover; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.right { text-align: right; }
.mt { margin-top: 14px; }
.money { font-variant-numeric: tabular-nums; }
.pos { color: var(--green); font-weight: 700; }
.neg { color: var(--red); font-weight: 700; }

/* Toasts sit dead-center so they can't be missed (bottom felt buried).
   pointer-events:none keeps taps working right through them. */
.toast {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  background: #101828; color: #fff; padding: 14px 22px; border-radius: 12px;
  font-size: 15px; font-weight: 600; z-index: 300; box-shadow: 0 8px 24px rgba(0,0,0,.25);
  opacity: 0; transition: opacity .2s; pointer-events: none; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; }
.toast.err { background: var(--red); }

.empty { text-align: center; color: var(--muted); padding: 26px 10px; font-size: 14.5px; }

/* Toggle switch */
.switch { position: relative; width: 48px; height: 28px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute; inset: 0; background: #cbd5e1; border-radius: 999px;
  transition: background .15s; cursor: pointer;
}
.switch .track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px;
  background: #fff; border-radius: 50%; transition: left .15s;
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.switch input:checked + .track { background: var(--green); }
.switch input:checked + .track::after { left: 23px; }
.setting-row { display: flex; align-items: center; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.setting-row:last-child { border-bottom: none; }
.setting-row .info { flex: 1; }
.setting-row .info .t { font-weight: 600; }
.setting-row .info .d { font-size: 13px; color: var(--muted); }

/* Mobile fallback for the desktop consoles (admin/manager): functional, not
   fancy. Scoped to small screens only — desktop rendering is untouched. */
@media (max-width: 700px) {
  /* tab bar becomes its own card: all tabs visible, no scrolling */
  body.desktop .tabs {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
    background: var(--card); border: 1px solid var(--line);
    border-radius: var(--radius); box-shadow: var(--shadow); padding: 10px;
  }
  body.desktop .tabs button { padding: 9px 6px; font-size: 13px; }
  /* forms stack one field per line; fields use the full width */
  body.desktop .row { flex-wrap: wrap !important; }
  body.desktop .row > .field { flex: 1 1 100% !important; }
  /* desktop-sized buttons are marginal thumb targets — give row buttons (Add
     facility/manager/salesman etc.) a proper 46px tap height on phones */
  body.desktop .row > .btn { min-height: 46px; padding-top: 12px; padding-bottom: 12px; }
  body.desktop .field select, body.desktop .field input { max-width: none; }
  /* dashboard stats: two per row instead of five crushed columns */
  body.desktop .stat-grid { grid-template-columns: repeat(2, 1fr) !important; }
  /* Create Bulk Inventory: quantity stepper + target price share a line */
  body.desktop .row > .field:has(> .stepper) { flex: 0 0 auto !important; }
  body.desktop .row > .field:has(> #b-new-price) { flex: 1 1 0 !important; min-width: 110px; }
  /* Transfer History: shrink the "Transfer" header to "#" so columns fit */
  body.desktop th.th-xfer { font-size: 0; }
  body.desktop th.th-xfer::before { content: "#"; font-size: 12px; }
  /* Batches card: "Batch ID" header shrinks to "ID"; action buttons drop to
     their own right-aligned line under each row */
  body.desktop th.th-bid { font-size: 0; }
  body.desktop th.th-bid::before { content: "ID"; font-size: 12px; }
  body.desktop table.batches thead th:last-child { display: none; }
  body.desktop table.batches tr {
    display: grid; grid-template-columns: 1.1fr 1.6fr .9fr 1fr .5fr;
    align-items: start;
  }
  body.desktop table.batches th,
  body.desktop table.batches td { display: block; border-bottom: 0; }
  body.desktop table.batches thead tr { border-bottom: 2px solid var(--line); }
  body.desktop table.batches tbody tr { border-bottom: 1px solid var(--line); }
  body.desktop table.batches tbody tr:last-child { border-bottom: none; }
  body.desktop table.batches td:last-child {
    grid-column: 1 / -1; text-align: right; padding-top: 10px; padding-bottom: 12px;
  }
  body.desktop .wrap { padding-left: 10px; padding-right: 10px; }
}

@media print {
  .topbar, .tabs, .no-print { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; border: none; }
}
