/* ==========================================================================
   Billing screen — the till. Optimised for speed and fat fingers.
   ========================================================================== */

.billing { display: grid; grid-template-columns: 1fr var(--cart-w); height: 100%; min-height: 0; }

/* --- left: search, categories, item grid --------------------------------- */
.bill-left { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.searchbar {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s3) var(--s4);
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.search-field { position: relative; flex: 1; min-width: 0; }
.search-ico {
  position: absolute; left: var(--s4); top: 50%; transform: translateY(-50%);
  font-size: var(--fs-lg); color: var(--text-faint); pointer-events: none;
}
.search-input { padding-left: var(--s10); font-size: var(--fs-lg); min-height: var(--tap-lg); font-weight: 600; }
.search-clear { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); }
.search-hint {
  font-size: var(--fs-xs); color: var(--text-faint); white-space: nowrap;
  display: flex; align-items: center; gap: var(--s2);
}
.kbd {
  display: inline-block; padding: 2px 6px; border-radius: var(--r-sm);
  background: var(--cream-100); border: 1px solid var(--line-strong);
  border-bottom-width: 2px; font-family: var(--font-mono); font-size: 11px; color: var(--text-muted);
}

.cat-tabs {
  display: flex; gap: var(--s2); overflow-x: auto; scrollbar-width: none;
  padding: var(--s3) var(--s4); background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.cat-tabs::-webkit-scrollbar { display: none; }
.cat-tab {
  display: flex; align-items: center; gap: var(--s2); flex: none;
  min-height: 40px; padding: 0 var(--s4);
  border: 1.5px solid var(--line); border-radius: var(--r-pill);
  background: var(--surface); color: var(--text-muted);
  font-size: var(--fs-sm); font-weight: 650; white-space: nowrap;
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
}
.cat-tab:hover { background: var(--cream-100); color: var(--text); }
.cat-tab.on { background: var(--ink-800); border-color: var(--ink-800); color: var(--text-on-dark); }
.cat-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.cat-tab.on .cat-dot { box-shadow: 0 0 0 2px rgba(255,255,255,.25); }

.item-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: var(--s4); }
.cat-group + .cat-group { margin-top: var(--s6); }
.cat-group-head {
  display: flex; align-items: center; gap: var(--s3);
  margin-bottom: var(--s3); padding-bottom: var(--s2);
  border-bottom: 2px solid var(--line);
}
.cat-group-name { font-size: var(--fs-sm); font-weight: 800; letter-spacing: .8px; text-transform: uppercase; }
.cat-group-count { font-size: var(--fs-xs); color: var(--text-faint); }

.item-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(152px, 1fr)); gap: var(--s3); }

.tile {
  position: relative; display: flex; flex-direction: column; gap: var(--s2);
  min-height: 104px; padding: var(--s3);
  border: 1.5px solid var(--line); border-radius: var(--r-lg);
  background: var(--surface); text-align: left;
  box-shadow: var(--sh-1);
  transition: transform var(--t-fast), box-shadow var(--t-fast), border-color var(--t-fast);
}
.tile:hover { border-color: var(--gold-500); box-shadow: var(--sh-2); transform: translateY(-1px); }
.tile:active { transform: scale(.975); }
.tile.in-cart { border-color: var(--gold-500); background: linear-gradient(180deg, #FFFDF6, var(--surface)); }
.tile.inactive { opacity: .45; }

.tile-top { display: flex; align-items: center; gap: var(--s2); }
.tile-code {
  display: grid; place-items: center; min-width: 24px; height: 22px; padding: 0 6px;
  border-radius: var(--r-sm); background: var(--cream-100); color: var(--text-muted);
  font-size: var(--fs-xs); font-weight: 800; font-variant-numeric: tabular-nums;
}
.tile.in-cart .tile-code { background: var(--gold-400); color: var(--ink-900); }
.tile-name {
  flex: 1; font-size: var(--fs-md); font-weight: 650; line-height: 1.25; color: var(--text);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.tile-price { margin-top: auto; font-size: var(--fs-lg); font-weight: 800; color: var(--ink-800); }
.tile-price small { font-size: var(--fs-xs); font-weight: 600; color: var(--text-faint); }
.tile-qty {
  position: absolute; top: -8px; right: -8px;
  min-width: 28px; height: 28px; padding: 0 7px;
  display: grid; place-items: center; border-radius: var(--r-pill);
  background: var(--success); color: #fff; font-size: var(--fs-sm); font-weight: 800;
  box-shadow: var(--sh-2); animation: pop var(--t-med);
}
@keyframes pop { from { transform: scale(.5); opacity: 0; } to { transform: none; opacity: 1; } }

/* --- right: the bill ----------------------------------------------------- */
.cart {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--surface); border-left: 1px solid var(--line); box-shadow: -2px 0 12px rgba(20,17,15,.05);
}
.cart-head {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s4); border-bottom: 1px solid var(--line);
}
.cart-title { font-size: var(--fs-lg); font-weight: 800; }
.cart-token { font-size: var(--fs-xs); color: var(--text-muted); }

.cart-lines { flex: 1; min-height: 0; overflow-y: auto; padding: var(--s2) var(--s3); }
.line {
  display: grid; grid-template-columns: 1fr auto; gap: var(--s1) var(--s3);
  padding: var(--s3); border-radius: var(--r-md);
  transition: background var(--t-fast);
}
.line + .line { border-top: 1px solid var(--line); border-radius: 0; }
.line:hover { background: var(--cream-50); }
.line.flash { animation: flash .5s; }
@keyframes flash { from { background: var(--gold-300); } to { background: transparent; } }
.line-name { font-size: var(--fs-md); font-weight: 650; line-height: 1.3; }
.line-name .line-code { color: var(--text-faint); font-weight: 700; margin-right: 5px; }
.line-amount { font-size: var(--fs-md); font-weight: 800; text-align: right; white-space: nowrap; }
.line-meta { display: flex; align-items: center; gap: var(--s3); grid-column: 1 / -1; }
.line-rate { font-size: var(--fs-sm); color: var(--text-muted); }

.stepper { display: flex; align-items: center; gap: 0; border: 1.5px solid var(--line-strong); border-radius: var(--r-md); overflow: hidden; }
.stepper button {
  width: 38px; height: 38px; border: 0; background: var(--surface);
  font-size: var(--fs-lg); font-weight: 700; color: var(--text-muted); line-height: 1;
  transition: background var(--t-fast), color var(--t-fast);
}
.stepper button:hover { background: var(--cream-100); color: var(--text); }
.stepper button.minus:hover { background: var(--danger-bg); color: var(--danger); }
.stepper button.plus:hover { background: var(--success-bg); color: var(--success); }
.stepper input {
  width: 46px; height: 38px; border: 0; border-left: 1.5px solid var(--line);
  border-right: 1.5px solid var(--line); text-align: center;
  font-size: var(--fs-md); font-weight: 800; font-variant-numeric: tabular-nums;
  background: var(--surface); -moz-appearance: textfield;
}
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.stepper input:focus { outline: none; background: var(--cream-50); }

.cart-empty { display: grid; place-items: center; gap: var(--s2); height: 100%; padding: var(--s6); text-align: center; color: var(--text-faint); }
.cart-empty-ico { font-size: 40px; opacity: .35; }

/* --- totals + actions ---------------------------------------------------- */
.cart-foot { border-top: 1px solid var(--line); background: var(--cream-50); padding: var(--s3) var(--s4) var(--s4); }
.sum-row { display: flex; justify-content: space-between; align-items: center; gap: var(--s3); font-size: var(--fs-sm); color: var(--text-muted); padding: 3px 0; }
.sum-row .v { font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.sum-row.discount .v { color: var(--success); }
.total-row {
  display: flex; justify-content: space-between; align-items: baseline; gap: var(--s3);
  margin: var(--s3) 0; padding-top: var(--s3); border-top: 2px dashed var(--line-strong);
}
.total-label { font-size: var(--fs-md); font-weight: 800; letter-spacing: .4px; text-transform: uppercase; }
.total-value { font-size: var(--fs-3xl); font-weight: 800; letter-spacing: -1px; color: var(--ink-900); font-variant-numeric: tabular-nums; }

.pay-label { font-size: var(--fs-xs); font-weight: 700; text-transform: uppercase; letter-spacing: .7px; color: var(--text-muted); margin-bottom: var(--s2); }

.tender { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2); margin-top: var(--s3); }
.tender-quick { display: flex; gap: var(--s2); grid-column: 1 / -1; }
.tender-quick .btn { flex: 1; }
.change-row {
  grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: center;
  padding: var(--s3) var(--s4); border-radius: var(--r-md);
  background: var(--success-bg); color: var(--success); font-weight: 800;
}
.change-row.short { background: var(--danger-bg); color: var(--danger); }
.change-row .amt { font-size: var(--fs-xl); font-variant-numeric: tabular-nums; }

.cart-actions { display: flex; gap: var(--s2); margin-top: var(--s3); }
.btn-save { flex: 1; font-size: var(--fs-lg); font-weight: 800; letter-spacing: .3px; }
.btn-save .f-key { font-size: var(--fs-xs); opacity: .7; font-weight: 600; }

/* --- saved / token confirmation ------------------------------------------ */
.saved-card { text-align: center; padding: var(--s4) 0 var(--s2); }
.saved-check {
  width: 62px; height: 62px; margin: 0 auto var(--s4); display: grid; place-items: center;
  border-radius: 50%; background: var(--success-bg); color: var(--success); font-size: var(--fs-2xl);
  animation: pop var(--t-med);
}
.saved-token { font-size: 72px; font-weight: 800; line-height: 1; letter-spacing: -3px; color: var(--ink-900); font-variant-numeric: tabular-nums; }
.saved-token-label { font-size: var(--fs-xs); font-weight: 700; text-transform: uppercase; letter-spacing: 1.4px; color: var(--text-muted); margin-bottom: var(--s2); }
.saved-meta { margin-top: var(--s4); display: flex; justify-content: center; gap: var(--s5); font-size: var(--fs-sm); color: var(--text-muted); }
.saved-meta b { display: block; font-size: var(--fs-lg); color: var(--text); }

/* --- mobile: cart becomes a bottom sheet --------------------------------- */
.cart-bar { display: none; }

@media (max-width: 900px) {
  .billing { grid-template-columns: 1fr; }
  .cart {
    position: fixed; inset: auto 0 0 0; z-index: var(--z-drawer);
    height: min(86dvh, 640px); border-left: 0;
    border-top-left-radius: var(--r-xl); border-top-right-radius: var(--r-xl);
    box-shadow: var(--sh-pop);
    transform: translateY(101%); transition: transform var(--t-med);
  }
  .billing.cart-open .cart { transform: none; }
  .cart-grab { width: 42px; height: 4px; border-radius: var(--r-pill); background: var(--line-strong); margin: var(--s2) auto 0; }

  .cart-bar {
    display: flex; align-items: center; gap: var(--s3);
    position: fixed; inset: auto 0 0 0; z-index: var(--z-sticky);
    padding: var(--s3) var(--s4); padding-bottom: max(var(--s3), env(safe-area-inset-bottom));
    background: var(--ink-800); color: var(--text-on-dark); box-shadow: 0 -4px 16px rgba(20,17,15,.25);
  }
  .billing.cart-open .cart-bar { display: none; }
  .cart-bar-count { font-size: var(--fs-sm); color: var(--text-on-dark-muted); }
  .cart-bar-total { font-size: var(--fs-xl); font-weight: 800; font-variant-numeric: tabular-nums; }
  .item-scroll { padding-bottom: 92px; }
  .search-hint { display: none; }
  .item-grid { grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); }
}

@media (max-width: 1180px) and (min-width: 901px) { :root { --cart-w: 340px; } }
