*, *::before, *::after { box-sizing: border-box; }

:root {
  --bg: #0b0b0c;
  --surface: #141416;
  --surface-2: #1b1b1e;
  --line: #2a2a2f;
  --text: #e8e8ea;
  --muted: #8b8b93;
  --faint: #5c5c66;
  --accent: #7dd3a0;
  --accent-ink: #0b0b0c;
  --warn: #e8b563;
  --danger: #e8776d;
}

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 1180px; margin: 0 auto; padding: 28px 20px 64px; }

header { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; justify-content: space-between; }
h1 { margin: 0; font-size: 1.375rem; font-weight: 600; letter-spacing: -.02em; }
.sub { margin: 4px 0 0; color: var(--muted); font-size: .8125rem; }
.header-right { display: flex; align-items: center; gap: 12px; }

nav { display: flex; gap: 4px; margin: 22px 0 26px; border-bottom: 1px solid var(--line); }
nav a, nav span {
  border-bottom: 2px solid transparent;
  color: var(--muted); font-size: .875rem; padding: 9px 14px;
  margin-bottom: -1px; text-decoration: none; white-space: nowrap;
}
nav a:hover { color: var(--text); }
nav span.disabled { color: var(--faint); cursor: not-allowed; }
nav [aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 22px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.stat dt { margin: 0 0 6px; color: var(--muted); font-size: .6875rem; text-transform: uppercase; letter-spacing: .06em; }
.stat dd { margin: 0; font-size: 1.5rem; font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }

.controls { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.controls input, .controls select {
  background: var(--surface); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 9px 12px; font: inherit; font-size: .875rem;
}
.controls input { flex: 1 1 240px; min-width: 0; }
.controls input::placeholder { color: var(--faint); }
.controls input:focus, .controls select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }

.table-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
caption { text-align: left; padding: 12px 16px; color: var(--muted); font-size: .8125rem; border-bottom: 1px solid var(--line); }

th, td { padding: 10px 14px; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--line); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
tbody tr.in-cart td { background: rgba(125, 211, 160, .06); }
tbody tr.in-cart td:first-child { box-shadow: inset 2px 0 0 var(--accent); }

thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface-2); color: var(--muted);
  font-size: .6875rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em;
}
thead th[data-key] { cursor: pointer; user-select: none; }
thead th[data-key]:hover { color: var(--text); }
thead th[data-key]::after { content: ""; display: inline-block; width: 12px; color: var(--accent); }
thead th[aria-sort="ascending"]::after { content: " ↑"; }
thead th[aria-sort="descending"]::after { content: " ↓"; }

.num { text-align: right; font-variant-numeric: tabular-nums; }
.sku { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .8125rem; color: var(--muted); }
.strain { font-weight: 500; }
.nil { color: var(--faint); }
.qty-col { text-align: right; }

.tag {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--line);
  font-size: .75rem; color: var(--muted);
}
.stock { font-weight: 600; }
.stock.ok { color: var(--accent); }
.stock.low { color: var(--warn); }
.stock.out { color: var(--danger); }

.empty { padding: 40px 16px; text-align: center; color: var(--muted); }

.btn {
  appearance: none; font: inherit; font-size: .8125rem; font-weight: 500;
  border-radius: 7px; padding: 5px 14px; cursor: pointer;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--line);
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); color: var(--accent-ink); }
.btn:disabled { opacity: .45; cursor: not-allowed; border-color: var(--line); color: var(--muted); }

.link {
  appearance: none; background: none; border: 0; padding: 0;
  color: var(--faint); font: inherit; font-size: .75rem; cursor: pointer; text-decoration: underline;
}
.link:hover { color: var(--danger); }

.stepper {
  display: inline-flex; align-items: center; gap: 2px;
  border: 1px solid var(--line); border-radius: 7px; background: var(--surface-2); overflow: hidden;
}
.stepper button {
  appearance: none; background: none; border: 0; color: var(--text);
  font: inherit; font-size: .9375rem; line-height: 1; padding: 5px 10px; cursor: pointer;
}
.stepper button:hover:not(:disabled) { background: var(--line); color: var(--accent); }
.stepper button:disabled { color: var(--faint); cursor: not-allowed; }
.stepper output {
  min-width: 2ch; text-align: center; font-size: .8125rem;
  font-variant-numeric: tabular-nums; font-weight: 600;
}

#cartToggle { position: relative; }
#cartTotal { font-variant-numeric: tabular-nums; color: var(--accent); }
#cartToggle:hover #cartTotal { color: inherit; }
.badge {
  position: absolute; top: -6px; right: -6px;
  min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 999px; background: var(--accent); color: var(--accent-ink);
  font-size: .6875rem; font-weight: 700; line-height: 18px; text-align: center;
}

#backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); z-index: 20; }

#cartPanel {
  position: fixed; top: 0; right: 0; z-index: 21;
  width: min(400px, 100%); height: 100dvh;
  display: flex; flex-direction: column;
  background: var(--surface); border-left: 1px solid var(--line);
  transform: translateX(100%); transition: transform .22s ease;
}
#cartPanel.open { transform: none; }
#cartPanel:focus { outline: none; }
@media (prefers-reduced-motion: reduce) { #cartPanel { transition: none; } }

.cart-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line);
}
.cart-head h2 { margin: 0; font-size: 1rem; font-weight: 600; }
.cart-head .sub { margin: 2px 0 0; }
.icon-btn {
  appearance: none; background: none; border: 0; color: var(--muted);
  font-size: 1.25rem; line-height: 1; padding: 4px 8px; cursor: pointer; border-radius: 6px;
}
.icon-btn:hover { color: var(--text); background: var(--surface-2); }

#cartBody { flex: 1; overflow-y: auto; padding: 8px 18px; }

.line { padding: 14px 0; border-bottom: 1px solid var(--line); }
.line:last-child { border-bottom: 0; }
.line-main { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.line-meta { display: flex; gap: 10px; font-size: .75rem; color: var(--muted); margin-top: 3px; }
.line-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 10px; }
.line-total { margin-left: auto; font-size: .875rem; font-weight: 600; font-variant-numeric: tabular-nums; }

#cartSummary { border-top: 1px solid var(--line); padding: 16px 18px; }
.total-row { display: flex; align-items: baseline; justify-content: space-between; }
.total-row .label { color: var(--muted); font-size: .8125rem; }
.total-row .value { font-size: 1.375rem; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
#unpriced { display: block; margin-top: 4px; color: var(--warn); font-size: .75rem; }
#cartUnits { display: block; margin-top: 2px; color: var(--faint); font-size: .75rem; }
.cart-foot { display: flex; gap: 8px; margin-top: 14px; }
.cart-foot .btn { flex: 1; padding: 9px 14px; text-align: center; }

body.locked { overflow: hidden; }

a.btn { display: inline-block; text-decoration: none; text-align: center; }

.checkout-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 18px; }
.panel h2 { margin: 0 0 6px; font-size: .9375rem; font-weight: 600; }
.panel .line:first-of-type { border-top: 1px solid var(--line); margin-top: 12px; }

.totals { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 14px; }
.totals .total-row + .total-row { margin-top: 6px; }
.note { margin: 12px 0 0; color: var(--faint); font-size: .75rem; }

.field { margin-top: 14px; display: flex; flex-direction: column; gap: 5px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field label { font-size: .8125rem; color: var(--muted); }
.field .opt { color: var(--faint); font-size: .75rem; }
.field input, .field textarea {
  background: var(--bg); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px 12px; font: inherit; font-size: .9375rem; width: 100%;
}
.field textarea { resize: vertical; }
.field input::placeholder, .field textarea::placeholder { color: var(--faint); }
.field input:focus, .field textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.field input[aria-invalid="true"] { border-color: var(--danger); }

.error { color: var(--danger); font-size: .75rem; min-height: 1em; }
.form-error { margin: 10px 0 0; text-align: right; }
.form-foot { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }
.form-foot .btn { padding: 10px 18px; }

.receipt-head { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.check {
  width: 40px; height: 40px; flex: none; border-radius: 999px;
  background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-size: 1.375rem; font-weight: 700;
}
.ref-label { margin: 0; color: var(--muted); font-size: .6875rem; text-transform: uppercase; letter-spacing: .06em; }
.ref { margin: 2px 0 0; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1.125rem; font-weight: 600; }

.detail-list { margin: 12px 0 0; display: flex; flex-direction: column; gap: 10px; }
.detail-list dt { color: var(--muted); font-size: .6875rem; text-transform: uppercase; letter-spacing: .06em; }
.detail-list dd { margin: 2px 0 0; font-size: .875rem; overflow-wrap: anywhere; }

.warning {
  margin: 0 0 16px; padding: 10px 14px; border-radius: 8px;
  background: rgba(232, 181, 99, .1); border: 1px solid rgba(232, 181, 99, .35);
  color: var(--warn); font-size: .8125rem;
}

.next-head { margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--line); }
.next-steps { margin: 10px 0 0; padding-left: 18px; color: var(--muted); font-size: .8125rem; }
.next-steps li + li { margin-top: 6px; }

.only-mobile { display: none; }
.cards { display: none; }
.count-line { margin: 0 0 10px; color: var(--muted); font-size: .8125rem; }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 13px 14px; margin-bottom: 8px;
}
.card.in-cart { border-color: var(--accent); background: rgba(125, 211, 160, .05); }
.card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.card-id { display: flex; flex-direction: column; min-width: 0; }
.card-id .strain { font-size: .9375rem; }
.card-top .stock { font-size: 1.0625rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.card-top .stock small { font-size: .6875rem; font-weight: 500; color: var(--muted); }
.card-meta { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 9px; font-size: .8125rem; }
.card-meta .price { font-weight: 600; font-variant-numeric: tabular-nums; }
.card-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-top: 11px; padding-top: 11px; border-top: 1px solid var(--line); font-size: .75rem;
}

.mobile-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 19;
  display: none; align-items: center; justify-content: space-between; gap: 12px;
  padding: 11px 16px calc(11px + env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--line);
  font-size: .8125rem; color: var(--muted);
}
.mobile-bar .btn { padding: 9px 18px; white-space: nowrap; }

@media (max-width: 760px) {
  .wrap { padding: 20px 14px 40px; }
  .stat dd { font-size: 1.25rem; }
  .stats { grid-template-columns: repeat(auto-fit, minmax(104px, 1fr)); gap: 8px; }
  .stat { padding: 11px 12px; }

  .only-mobile { display: block; }
  .table-scroll { display: none; }
  .cards { display: block; }

  .controls { gap: 8px; }
  .controls input { flex: 1 1 100%; }
  .controls select { flex: 1 1 calc(50% - 4px); min-width: 0; }
  .controls input, .controls select { padding: 11px 12px; font-size: 1rem; }

  nav { overflow-x: auto; scrollbar-width: none; }
  nav::-webkit-scrollbar { display: none; }
  nav button { white-space: nowrap; }

  .stepper button { padding: 9px 14px; font-size: 1rem; }
  .btn.add { padding: 9px 18px; }

  .mobile-bar:not([hidden]) { display: flex; }
  body:has(.mobile-bar:not([hidden])) .wrap { padding-bottom: 84px; }

  #cartPanel { width: 100%; border-left: 0; }

  .checkout-grid { grid-template-columns: 1fr; }
  .field-row { grid-template-columns: 1fr; gap: 0; }
  .field input, .field textarea { font-size: 1rem; }
  .form-foot { flex-direction: column-reverse; }
  .form-foot .btn { width: 100%; padding: 12px 18px; }
  .form-error { text-align: left; }
}

@media (max-width: 380px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
}
