:root {
  --navy: #07122a;
  --navy-2: #0b1937;
  --panel: #102044;
  --panel-2: #0b1733;
  --line: #27406f;
  --line-soft: #1b315c;
  --text: #f5f7ff;
  --muted: #9eadd0;
  --gold: #e0b33a;
  --gold-2: #f3cd64;
  --good: #2f9e44;
  --danger: #e03131;
  --accent: #e0b33a;
  --shadow: 0 14px 38px rgba(0, 0, 0, .26);
  --radius: 16px;
  --side: 238px;
  --bottom-nav: 68px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; min-height: 100%; }
body {
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  color: var(--text);
  min-height: 100vh;
  background:
    radial-gradient(900px 420px at 12% -8%, #18336e 0%, transparent 55%),
    radial-gradient(760px 360px at 100% 0%, #332710 0%, transparent 48%),
    linear-gradient(180deg, var(--navy) 0%, #050b19 100%);
}
button, input, select, textarea { font: inherit; }
button, a, input, select { -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }
.mobile-only { display: none !important; }

/* Header */
#topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: 68px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 18px;
  background: rgba(7, 18, 42, .95);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}
.brand-wrap { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo-mark {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 12px;
  box-shadow: 0 0 0 2px rgba(224, 179, 58, .28);
}
.brand { font-weight: 850; letter-spacing: .15px; line-height: 1.05; white-space: nowrap; }
.brand span { color: var(--gold); }
.brand small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.35px;
}
.top-spacer { flex: 1; }
.mode-pill, .status-pill {
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 999px;
  background: #102958;
  color: #bdd0ff;
  border: 1px solid #284c8f;
}

/* App layout */
.workspace { display: grid; grid-template-columns: var(--side) minmax(0, 1fr); min-height: calc(100vh - 68px); }
.side-nav {
  position: sticky;
  top: 68px;
  align-self: start;
  height: calc(100vh - 68px);
  overflow: auto;
  padding: 18px 12px;
  background: rgba(7, 18, 42, .72);
  border-right: 1px solid var(--line);
}
.nav-group + .nav-group { margin-top: 22px; }
.nav-label {
  padding: 0 10px 7px;
  color: #7083ad;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1.5px;
  text-transform: uppercase;
}
.side-nav button {
  width: 100%;
  display: block;
  text-align: left;
  color: var(--text);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 10px 11px;
  margin: 2px 0;
  cursor: pointer;
}
.side-nav button span { display: block; font-weight: 700; }
.side-nav button small { display: block; color: var(--muted); margin-top: 2px; font-size: 11px; }
.side-nav button:hover { background: #102755; border-color: #294a87; }
.side-nav button.active {
  background: linear-gradient(135deg, rgba(224,179,58,.20), rgba(224,179,58,.08));
  border-color: rgba(224,179,58,.62);
}
.side-nav button.active span { color: var(--gold-2); }

main { min-width: 0; width: 100%; max-width: 1500px; margin: 0 auto; padding: 24px 28px 38px; }
.view { animation: viewIn .14s ease-out; }
@keyframes viewIn { from { opacity: .5; transform: translateY(2px); } to { opacity: 1; transform: none; } }
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}
.page-head h1, .view h1 { margin: 1px 0 5px; font-size: clamp(25px, 2.2vw, 34px); line-height: 1.1; }
.eyebrow { display: block; color: var(--gold-2); font-size: 11px; font-weight: 850; letter-spacing: 1.35px; text-transform: uppercase; }
.hint { color: var(--muted); margin: 0 0 12px; line-height: 1.45; }
.status-line {
  color: #c3d0ee;
  background: rgba(12, 27, 61, .65);
  border: 1px solid var(--line-soft);
  border-radius: 11px;
  padding: 10px 12px;
  margin: 0 0 13px;
  line-height: 1.4;
}

/* Controls */
.card {
  background: linear-gradient(180deg, rgba(18,36,77,.96) 0%, rgba(12,27,61,.96) 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.row, .toolbar-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.toolbar-row { padding: 12px; }
.grow { flex: 1; min-width: 220px; }
.wide { width: 100%; }
label { display: block; color: var(--muted); font-size: 12px; font-weight: 650; margin-bottom: 5px; }
input[type="text"], input[type="number"], input[type="password"], input[type="search"], input[type="file"], select, textarea, input:not([type]) {
  width: 100%;
  color: var(--text);
  background: #071328;
  border: 1px solid #35538a;
  border-radius: 11px;
  padding: 11px 12px;
  outline: none;
  transition: border-color .12s ease, box-shadow .12s ease;
}
input:focus, select:focus, textarea:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(224,179,58,.12); }
.scan-input { font-size: 20px; min-height: 52px; padding: 13px 15px; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  color: var(--text);
  background: #16305f;
  border: 1px solid #3d5ea0;
  border-radius: 10px;
  padding: 9px 14px;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.09); }
.btn.primary { background: var(--gold); color: #1a1404; border-color: #c79a22; font-weight: 800; }
.btn.good { background: var(--good); color: #fff; border-color: #2b8a3e; font-weight: 750; }
.btn.danger { background: var(--danger); color: #fff; border-color: #c92a2a; }
.btn.quiet { background: transparent; border-color: #324d80; }
.btn.compact { min-height: 32px; padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.icon-btn {
  width: 42px;
  height: 42px;
  display: inline-grid;
  place-items: center;
  border: 1px solid #35538a;
  border-radius: 10px;
  background: #102958;
  color: var(--text);
  cursor: pointer;
  font-size: 22px;
}

.search-card { padding: 11px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-top: 14px; }
.form-grid .span-2 { grid-column: span 2; }
.compact-grid { grid-template-columns: 1.5fr .75fr .85fr; }
.item-summary {
  min-height: 52px;
  display: flex;
  align-items: center;
  padding: 11px 12px;
  margin: 10px 0 2px;
  border: 1px solid var(--line-soft);
  border-radius: 11px;
  background: rgba(5, 13, 30, .45);
  color: #dbe4fb;
}

.stat {
  background: linear-gradient(180deg, #10234a, #0b1937);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  min-height: 92px;
}
.stat .k { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .7px; }
.stat .v { margin-top: 7px; color: var(--gold-2); font-size: 22px; font-weight: 850; }
.stats-grid { margin-bottom: 14px; grid-template-columns: repeat(3, minmax(180px, 1fr)); }

/* Audit */
.audit-flow { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.step-card { display: flex; align-items: flex-end; gap: 12px; }
.step-number {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--gold);
  color: #1a1404;
  font-weight: 900;
  margin-bottom: 9px;
}
.step-body { flex: 1; min-width: 0; }
.step-action { margin-bottom: 0; }

/* Sell */
.sell-layout { display: grid; grid-template-columns: minmax(360px, .8fr) minmax(500px, 1.2fr); gap: 14px; align-items: start; }
.cart-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.cart-head h2 { margin: 2px 0 0; }
.sale-total { color: var(--gold-2); font-size: 30px; font-weight: 900; }
.cart-table-wrap { margin-top: 12px; }

/* Tables */
.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 235px);
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--panel-2);
}
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 9px 10px; border-bottom: 1px solid #1b315b; text-align: left; vertical-align: middle; white-space: nowrap; }
th { position: sticky; top: 0; z-index: 2; background: #15305f; color: #ffe8a3; font-size: 12px; }
.sort-btn {
  background: transparent;
  border: 0;
  color: inherit;
  font: inherit;
  font-weight: 800;
  min-height: 0;
  padding: 0;
  text-align: left;
  cursor: pointer;
}
.sort-btn:hover { color: #fff; }
tbody tr:hover { background: #122956; }
tbody tr:last-child td { border-bottom: 0; }
td input, td select { min-width: 110px; }

/* Past Sales: keep the full desktop report inside the available window.
   Description/notes absorb extra space and wrap instead of forcing horizontal scroll. */
.sales-table-wrap {
  overflow-x: hidden;
}
#sales-table {
  width: 100%;
  table-layout: fixed;
  font-size: clamp(10.5px, .82vw, 12.5px);
}
#sales-table th,
#sales-table td {
  padding: 7px 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#sales-table th:nth-child(1), #sales-table td:nth-child(1) { width: 4.5%; }
#sales-table th:nth-child(2), #sales-table td:nth-child(2) { width: 9%; }
#sales-table th:nth-child(3), #sales-table td:nth-child(3) { width: 10%; }
#sales-table th:nth-child(4), #sales-table td:nth-child(4) { width: 8%; }
#sales-table th:nth-child(5), #sales-table td:nth-child(5) { width: 18%; }
#sales-table th:nth-child(6), #sales-table td:nth-child(6) { width: 7%; }
#sales-table th:nth-child(7), #sales-table td:nth-child(7) { width: 4%; text-align: center; }
#sales-table th:nth-child(8), #sales-table td:nth-child(8),
#sales-table th:nth-child(9), #sales-table td:nth-child(9),
#sales-table th:nth-child(10), #sales-table td:nth-child(10),
#sales-table th:nth-child(11), #sales-table td:nth-child(11) { width: 6.5%; }
#sales-table th:nth-child(12), #sales-table td:nth-child(12) { width: 8%; }
#sales-table th:nth-child(13), #sales-table td:nth-child(13) { width: 5.5%; text-align: center; }
#sales-table th:nth-child(5), #sales-table td:nth-child(5),
#sales-table th:nth-child(12), #sales-table td:nth-child(12) {
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  overflow-wrap: anywhere;
  line-height: 1.25;
}
#sales-table td:nth-child(5) {
  color: #dfe7fb;
}
#sales-table td:nth-child(8),
#sales-table td:nth-child(9),
#sales-table td:nth-child(10),
#sales-table td:nth-child(11) {
  font-variant-numeric: tabular-nums;
}
#sales-table td:last-child .btn {
  width: 100%;
  min-width: 0;
  padding-left: 5px;
  padding-right: 5px;
}

/* Search/Edit + In-Stock: size columns to content so Edit/Photos stay on screen. */
#search-table,
#stock-table {
  width: max-content;
  min-width: 100%;
  table-layout: auto;
  font-size: clamp(11px, .9vw, 13px);
}
#search-table th,
#search-table td,
#stock-table th,
#stock-table td {
  padding: 8px 7px;
  white-space: nowrap;
}
#search-table th:nth-child(3), #search-table td:nth-child(3),
#stock-table th:nth-child(3), #stock-table td:nth-child(3) {
  white-space: normal;
  overflow-wrap: anywhere;
  min-width: 140px;
  max-width: 280px;
  line-height: 1.25;
}
#search-table td:last-child,
#stock-table td:last-child {
  overflow: visible;
  white-space: nowrap;
  min-width: 168px;
}
.row-actions {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  flex-wrap: nowrap;
}
.row-actions .btn {
  width: auto;
  min-width: 72px;
  padding-left: 10px;
  padding-right: 10px;
}
.badge { display: inline-block; padding: 3px 8px; border-radius: 999px; font-size: 11px; font-weight: 800; }
.MATCH { background: #25532d; color: #b2f2bb; }
.MISSING { background: #5c1a1a; color: #ffc9c9; }
.EXCESS, .UNEXPECTED { background: #5c3b11; color: #ffec99; }

/* Sticky action bars */
.sticky-actions {
  position: sticky;
  bottom: 12px;
  z-index: 10;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: rgba(7, 18, 42, .94);
  backdrop-filter: blur(12px);
  box-shadow: 0 10px 30px rgba(0,0,0,.3);
}
.sticky-actions.inside-card { position: static; margin-bottom: -2px; background: transparent; border: 0; padding: 12px 0 0; box-shadow: none; }

/* Login */
.gate { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: min(420px, 100%); text-align: center; }
.login-card h1 { margin: 4px 0 8px; }
.login-card label { text-align: left; }
.login-card .wide { margin-top: 12px; }
.logo-hero {
  width: min(245px, 67vw);
  height: auto;
  display: block;
  margin: 0 auto 18px;
  border-radius: 24px;
  box-shadow: 0 18px 40px rgba(0,0,0,.4);
}
.logo-hero.small { width: 128px; border-radius: 18px; }

/* Scanner */
.scan-row { display: flex; gap: 8px; align-items: stretch; flex-wrap: wrap; }
.scan-row .scan-input, .scan-row input { flex: 1; min-width: 0; }
.scan-btn, .find-btn { white-space: nowrap; }
.find-btn { min-width: 72px; }
.scanner-back, .modal-back {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(3, 8, 20, .88);
  backdrop-filter: blur(5px);
}
.scanner-card, .app-modal {
  width: min(560px, 100%);
  max-height: min(86vh, 780px);
  overflow: auto;
  background: linear-gradient(180deg, #10244c, #0b1834);
  border: 1px solid #4a6293;
  border-radius: 18px;
  padding: 16px;
  box-shadow: 0 26px 80px rgba(0,0,0,.5);
}
.scanner-top, .modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.modal-head h2 { margin: 2px 0 0; }
.modal-body { color: #dfe7fb; line-height: 1.45; }
.modal-body p:first-child { margin-top: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 16px; }
.modal-choice-list { display: grid; gap: 8px; margin-top: 12px; }
.modal-choice {
  width: 100%;
  text-align: left;
  padding: 12px;
  color: var(--text);
  background: #0a1835;
  border: 1px solid #31518d;
  border-radius: 11px;
  cursor: pointer;
}
.modal-choice:hover { border-color: var(--gold); background: #112651; }
.modal-choice-primary {
  order: -1;
  font-weight: 700;
  color: #102044;
  background: var(--gold);
  border-color: var(--gold);
}
.modal-choice-primary:hover { color: #102044; background: #e8c76a; }
#scanner-reader { width: 100%; min-height: 240px; border-radius: 12px; background: #000; overflow: hidden; }
#scanner-reader video { max-height: 70vh; object-fit: cover; border-radius: 12px; }

/* Toast */
.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 100;
  max-width: 440px;
  padding: 12px 14px;
  white-space: pre-line;
  color: var(--text);
  background: #102044;
  border: 1px solid var(--gold);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

/* Mobile drawer */
.drawer-back { position: fixed; inset: 0; z-index: 60; background: rgba(2,7,18,.64); }
.mobile-drawer {
  position: absolute;
  top: 0;
  left: 0;
  width: min(340px, 88vw);
  height: 100%;
  padding: calc(14px + env(safe-area-inset-top)) 12px 18px;
  background: #08152f;
  border-right: 1px solid var(--line);
  box-shadow: 18px 0 60px rgba(0,0,0,.42);
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 5px 4px 14px; }
.drawer-head strong { font-size: 20px; }
.mobile-drawer > button:not(.icon-btn) {
  width: 100%;
  display: block;
  text-align: left;
  margin: 5px 0;
  padding: 13px 12px;
  color: var(--text);
  background: #10234a;
  border: 1px solid #294879;
  border-radius: 12px;
}
.mobile-drawer button small { display: block; margin-top: 3px; color: var(--muted); }
.mobile-drawer .drawer-logout { margin-top: 20px !important; border-color: #704040 !important; background: #351a25 !important; }

@media (max-width: 1100px) {
  .sell-layout { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, minmax(180px, 1fr)); }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .compact-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 820px) {
  .desktop-only { display: none !important; }
  .mobile-only { display: flex !important; }
  /* Hidden must win over mobile-only so overlays/drawers can actually close. */
  .mobile-only.hidden,
  .drawer-back.hidden { display: none !important; }
  body { padding-bottom: calc(var(--bottom-nav) + env(safe-area-inset-bottom)); }
  #topbar {
    height: 60px;
    padding: calc(7px + env(safe-area-inset-top)) 11px 7px;
    gap: 9px;
  }
  .logo-mark { width: 38px; height: 38px; border-radius: 10px; }
  .brand { font-size: 15px; }
  .brand small { max-width: 160px; overflow: hidden; text-overflow: ellipsis; letter-spacing: .85px; }
  .workspace { display: block; min-height: 0; }
  main { padding: 14px 11px 26px; }
  .page-head { align-items: flex-start; margin-bottom: 11px; }
  .page-head h1, .view h1 { font-size: 24px; }
  .page-head .hint { margin-bottom: 0; }
  .card { border-radius: 14px; padding: 12px; margin-bottom: 11px; box-shadow: 0 10px 25px rgba(0,0,0,.22); }
  .toolbar-row { align-items: stretch; }
  .toolbar-row .btn, .toolbar-row a.btn { width: 100%; }
  .grow { min-width: 0; width: 100%; }
  .grid, .stats-grid, .form-grid, .compact-grid, .audit-flow { grid-template-columns: 1fr; }
  .form-grid .span-2, .compact-grid .span-2 { grid-column: span 1; }
  .scan-input { min-height: 50px; font-size: 17px; padding: 12px 13px; }
  input, select, textarea, button, .btn { font-size: 16px; min-height: 44px; }
  .step-card { align-items: center; }
  .step-number { margin-bottom: 0; }
  .step-action { align-self: stretch; }
  .status-line { font-size: 13px; padding: 9px 10px; }
  .sale-total { font-size: 27px; }
  .sticky-actions {
    bottom: calc(var(--bottom-nav) + 8px + env(safe-area-inset-bottom));
    display: grid;
    grid-template-columns: 1fr 1.25fr;
    gap: 8px;
    margin-left: -2px;
    margin-right: -2px;
  }
  .sticky-actions .btn { width: 100%; }
  .sticky-actions.inside-card { display: grid; }

  /* Turn each data row into a readable card instead of a horizontal spreadsheet. */
  .responsive-table { overflow: visible; max-height: none; border: 0; background: transparent; }
  .responsive-table table, .responsive-table tbody { display: block; width: 100%; }
  .responsive-table thead { display: none; }
  .responsive-table tbody { display: grid; gap: 10px; }
  .responsive-table tr {
    display: block;
    width: 100%;
    overflow: hidden;
    background: linear-gradient(180deg, #10234a, #0b1937);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: 0 8px 22px rgba(0,0,0,.18);
  }
  .responsive-table tr:hover { background: linear-gradient(180deg, #10234a, #0b1937); }
  .responsive-table td {
    display: grid;
    grid-template-columns: minmax(92px, 38%) minmax(0, 1fr);
    align-items: center;
    gap: 10px;
    min-height: 40px;
    padding: 8px 11px;
    border-bottom: 1px solid #1b315b;
    white-space: normal;
    overflow-wrap: anywhere;
  }
  .responsive-table td:last-child { border-bottom: 0; }
  .responsive-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .7px;
    text-transform: uppercase;
  }
  .responsive-table td[data-label=""], .responsive-table td[data-label="Action"] { grid-template-columns: 1fr; }
  .responsive-table td[data-label=""]::before, .responsive-table td[data-label="Action"]::before { display: none; }
  .responsive-table td input, .responsive-table td select { min-width: 0; width: 100%; }
  .responsive-table td .btn { width: 100%; }

  /* Past Sales follows the same card layout on phones. */
  .sales-table-wrap { overflow: visible; }
  #sales-table { table-layout: auto; font-size: 13px; }
  #sales-table th,
  #sales-table td,
  #sales-table th:nth-child(n),
  #sales-table td:nth-child(n) {
    width: auto;
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    text-align: left;
  }

  /* Search/Edit and In-Stock use the same readable card layout on phones. */
  #search-table,
  #stock-table { table-layout: auto; font-size: 13px; }
  #search-table th,
  #search-table td,
  #search-table th:nth-child(n),
  #search-table td:nth-child(n),
  #stock-table th,
  #stock-table td,
  #stock-table th:nth-child(n),
  #stock-table td:nth-child(n) {
    width: auto;
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    text-align: left;
  }

  .mobile-bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 50;
    height: calc(var(--bottom-nav) + env(safe-area-inset-bottom));
    padding: 5px 5px env(safe-area-inset-bottom);
    align-items: stretch;
    justify-content: space-around;
    background: rgba(6, 16, 37, .97);
    border-top: 1px solid var(--line);
    backdrop-filter: blur(14px);
  }
  .mobile-bottom-nav button {
    flex: 1;
    min-width: 0;
    color: var(--muted);
    background: transparent;
    border: 0;
    border-radius: 10px;
    padding: 5px 2px;
  }
  .mobile-bottom-nav button span { display: block; color: inherit; font-size: 20px; font-weight: 800; line-height: 1.05; }
  .mobile-bottom-nav button small { display: block; margin-top: 3px; font-size: 10px; font-weight: 700; }
  .mobile-bottom-nav button.active { color: var(--gold-2); background: rgba(224,179,58,.10); }

  .scanner-card, .app-modal {
    width: 100%;
    max-height: 92vh;
    align-self: end;
    border-radius: 19px 19px 0 0;
    border-bottom: 0;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
  .scanner-back, .modal-back { place-items: end center; padding: 0; }
  .modal-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .modal-actions .btn { width: 100%; }
  .toast {
    left: 10px;
    right: 10px;
    bottom: calc(var(--bottom-nav) + 10px + env(safe-area-inset-bottom));
    max-width: none;
  }
  .scan-btn { padding-left: 11px; padding-right: 11px; }
}

@media (min-width: 821px) {
  .scan-btn { display: none; }
}


/* SQL user/role authentication */
.remember-row{display:flex;align-items:center;gap:.55rem;margin:.8rem 0 1rem;color:var(--muted);font-weight:500}.remember-row input{width:auto}.user-badge{font-size:.84rem;color:var(--muted);padding:.45rem .75rem;border:1px solid var(--border);border-radius:999px;white-space:nowrap}.role-hidden{display:none!important}.login-card>label:not(.remember-row){display:block;margin-top:.7rem}.login-card>input{width:100%}.user-actions{display:flex;gap:.45rem;flex-wrap:wrap}.user-role{font-weight:700;letter-spacing:.03em}.user-disabled{opacity:.55}

/* V8 - Sales Floor workflow + listed price */
.stage-mode-tabs { display:flex; gap:10px; margin-bottom:14px; flex-wrap:wrap; }
.stage-card { max-width:900px; }
.stage-card h2 { margin-top:0; }
.stage-move-btn { margin-top:14px; }
.stage-original-actions { margin-top:10px; line-height:2; }
.link-chip {
  appearance:none; border:1px solid var(--line); background:#0d2146; color:var(--gold-2);
  border-radius:999px; padding:5px 10px; margin:2px 3px; font:inherit; font-weight:700; cursor:pointer;
}
.link-chip:hover { border-color:var(--gold); }
.stage-floor-card h2 { margin: 0; }
.floor-list { display: grid; gap: 10px; margin-top: 10px; }
.floor-item {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #0b1937;
}
.floor-item-copy { display: grid; gap: 3px; }
.floor-item-copy strong { font-size: 16px; }
.floor-item-actions { display: grid; grid-template-columns: 1.2fr 1fr 1fr 0.8fr; gap: 8px; }
.floor-item-actions .btn { width: 100%; }
.share-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.share-row .btn { width: 100%; }
.photo-grid { display: grid; gap: 10px; margin: 12px 0; }
.photo-card {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #0b1937;
}
.photo-card.primary { border-color: var(--gold); }
.photo-card img {
  width: 100%;
  max-height: 220px;
  object-fit: contain;
  background: #071224;
  border-radius: 10px;
}
.photo-meta { display: grid; gap: 2px; }
.photo-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.photo-upload { display: grid; gap: 8px; margin-top: 8px; }
.photo-file-btn { position: relative; overflow: hidden; text-align: center; }
.photo-file-btn input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

@media (min-width:821px) {
  #search-table, #stock-table { table-layout: auto; width: max-content; min-width: 100%; }
  #search-table td:last-child, #stock-table td:last-child { min-width: 168px; }
}

@media (max-width:820px) {
  .stage-mode-tabs { display:grid; grid-template-columns:1fr 1fr; }
  .stage-card { max-width:none; }
}


/* V10 - SalesFloor quantity + movement history */
#stage-source-wrap #stage-pull-qty { max-width: 160px; }
.location-history-card { margin-top: 16px; }
#history-table { width: 100%; table-layout: fixed; font-size: clamp(11px, .88vw, 13px); }
#history-table th, #history-table td { padding: 7px 6px; overflow-wrap: anywhere; white-space: normal; }
#history-table th:nth-child(1), #history-table td:nth-child(1) { width: 15%; }
#history-table th:nth-child(2), #history-table td:nth-child(2) { width: 13%; }
#history-table th:nth-child(3), #history-table td:nth-child(3) { width: 12%; }
#history-table th:nth-child(4), #history-table td:nth-child(4),
#history-table th:nth-child(5), #history-table td:nth-child(5) { width: 11%; }
#history-table th:nth-child(6), #history-table td:nth-child(6) { width: 5%; text-align:center; }
#history-table th:nth-child(7), #history-table td:nth-child(7) { width: 12%; }
#history-table th:nth-child(8), #history-table td:nth-child(8) { width: 9%; }
#history-table th:nth-child(9), #history-table td:nth-child(9) { width: 12%; }


/* V10.1 - In-Stock camera must remain available on phones.
   Keep this after all responsive scan-button rules so Safari cannot hide it. */
#view-stock .stock-camera-btn {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}
@media (max-width: 820px) {
  #view-stock .toolbar-row.scan-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
  }
  #view-stock .stock-camera-btn {
    min-height: 50px;
    padding-left: 13px;
    padding-right: 13px;
  }
}


/* V11 - dedicated Location History investigation view */
.history-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 0 0 14px;
}
.history-summary .metric {
  background: var(--panel, #111d3a);
  border: 1px solid var(--line, #294574);
  border-radius: 16px;
  padding: 14px 16px;
}
.history-summary .metric span,
.history-summary .metric small {
  display: block;
}
.history-summary .metric span {
  color: var(--muted, #9da9c5);
  font-size: .82rem;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.history-summary .metric strong {
  display: block;
  margin-top: 5px;
  font-size: 1rem;
}
.history-summary .metric small {
  margin-top: 4px;
  color: var(--muted, #9da9c5);
}
.history-legend { margin: 10px 0 0; }
#history-table { table-layout: fixed; width: 100%; }
#history-table th:nth-child(1), #history-table td:nth-child(1) { width: 12%; }
#history-table th:nth-child(2), #history-table td:nth-child(2) { width: 10%; }
#history-table th:nth-child(3), #history-table td:nth-child(3) { width: 10%; }
#history-table th:nth-child(4), #history-table td:nth-child(4),
#history-table th:nth-child(5), #history-table td:nth-child(5) { width: 10%; }
#history-table th:nth-child(6), #history-table td:nth-child(6) { width: 5%; }
#history-table th:nth-child(7), #history-table td:nth-child(7) { width: 13%; }
#history-table th:nth-child(8), #history-table td:nth-child(8) { width: 9%; }
#history-table th:nth-child(9), #history-table td:nth-child(9) { width: 21%; white-space: normal; overflow-wrap: anywhere; }
@media (max-width: 700px) {
  .history-summary { grid-template-columns: 1fr; }
}


/* V12 commissions */
.commission-summary { display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); gap:14px; margin:0 0 18px; }
.commission-summary .metric { background:var(--panel,#0e2147); border:1px solid var(--line,#294879); border-radius:16px; padding:16px; display:grid; gap:5px; }
.commission-summary .metric span,.commission-summary .metric small { opacity:.72; }
.commission-summary .metric strong { font-size:1.55rem; }
.commission-admin-card { margin-bottom:12px; }
.compact-head { margin-top:24px; margin-bottom:10px; }
.muted { opacity:.65; }
@media (max-width:700px) { .commission-summary { grid-template-columns:1fr; } .commission-summary .metric { padding:14px; } }

.export-actions { display:flex; gap:8px; flex-wrap:wrap; justify-content:flex-end; }
@media (max-width: 820px) { .export-actions { width:100%; justify-content:flex-start; } }

[data-view="sell"] { position: relative; }
.cart-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  margin-left: 6px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--gold, #d7b15a);
  color: #1a1408;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
}
.cart-badge.hidden { display: none; }
.mobile-bottom-nav [data-view="sell"] .cart-badge {
  position: absolute;
  top: 2px;
  right: 8px;
  margin: 0;
}


/* V15.1 - desktop In-Stock admin table: 15-column shipping layout.
   Shrink identifier columns and reserve explicit space for dimensions + Edit. */
@media (min-width: 821px) {
  #stock-table.stock-admin-layout {
    table-layout: fixed;
    width: 100%;
    font-size: clamp(10px, .72vw, 12px);
  }
  #stock-table.stock-admin-layout th,
  #stock-table.stock-admin-layout td {
    padding-left: 5px;
    padding-right: 5px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #stock-table.stock-admin-layout th:nth-child(1),
  #stock-table.stock-admin-layout td:nth-child(1)  { width: 8.5%; }
  #stock-table.stock-admin-layout th:nth-child(2),
  #stock-table.stock-admin-layout td:nth-child(2)  { width: 8%; }
  #stock-table.stock-admin-layout th:nth-child(3),
  #stock-table.stock-admin-layout td:nth-child(3)  { width: 14%; white-space: normal; overflow-wrap: anywhere; line-height: 1.2; }
  #stock-table.stock-admin-layout th:nth-child(4),
  #stock-table.stock-admin-layout td:nth-child(4)  { width: 8%; }
  #stock-table.stock-admin-layout th:nth-child(5),
  #stock-table.stock-admin-layout td:nth-child(5)  { width: 4%; text-align: center; }
  #stock-table.stock-admin-layout th:nth-child(6),
  #stock-table.stock-admin-layout td:nth-child(6)  { width: 6.5%; }
  #stock-table.stock-admin-layout th:nth-child(7),
  #stock-table.stock-admin-layout td:nth-child(7)  { width: 7%; }
  #stock-table.stock-admin-layout th:nth-child(8),
  #stock-table.stock-admin-layout td:nth-child(8)  { width: 6%; }
  #stock-table.stock-admin-layout th:nth-child(9),
  #stock-table.stock-admin-layout td:nth-child(9),
  #stock-table.stock-admin-layout th:nth-child(10),
  #stock-table.stock-admin-layout td:nth-child(10),
  #stock-table.stock-admin-layout th:nth-child(11),
  #stock-table.stock-admin-layout td:nth-child(11) { width: 4%; text-align: center; }
  #stock-table.stock-admin-layout th:nth-child(12),
  #stock-table.stock-admin-layout td:nth-child(12) { width: 5%; text-align: center; }
  #stock-table.stock-admin-layout th:nth-child(13),
  #stock-table.stock-admin-layout td:nth-child(13) { width: 3%; text-align: center; }
  #stock-table.stock-admin-layout th:nth-child(14),
  #stock-table.stock-admin-layout td:nth-child(14) { width: 7%; text-align: center; overflow: visible; }
  #stock-table.stock-admin-layout th:nth-child(15),
  #stock-table.stock-admin-layout td:nth-child(15) { width: 10.5%; text-align: center; overflow: visible; }

  #stock-table.stock-admin-layout td:nth-child(14) .btn,
  #stock-table.stock-admin-layout td:nth-child(15) .btn {
    width: auto;
    min-width: 48px;
    max-width: 100%;
    padding: 6px 8px;
    white-space: nowrap;
  }
  #stock-table tr.stock-editing {
    outline: 2px solid var(--gold, #d7b15a);
    outline-offset: -2px;
  }

  #stock-table.stock-inline-edit td {
    overflow: visible;
  }
  #stock-table.stock-inline-edit td input.cell-edit {
    width: 100%;
    min-width: 0;
    min-height: 32px;
    padding: 4px 6px;
    font-size: inherit;
  }
  #stock-table.stock-inline-edit td input.cell-check {
    width: 16px;
    min-width: 16px;
    min-height: 16px;
  }
  #stock-table.stock-inline-edit .cell-check-wrap {
    display: flex;
    justify-content: center;
  }
  #stock-table.stock-inline-edit input.cell-edit.saving {
    outline: 1px solid #d7b15a;
  }
  #stock-table.stock-inline-edit input.cell-edit.saved {
    outline: 1px solid #3ecf8e;
  }
  #stock-table.stock-inline-edit .photo-count-btn {
    font-variant-numeric: tabular-nums;
  }
}
