* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

:root {
  --primary: #0F6E56;
  --bg: #F2F2F7;
  --card: #FFFFFF;
  --text: #1C1C1E;
  --text2: #3C3C43;
  --muted: #8E8E93;
  --border: rgba(60,60,67,0.12);
  --red: #FF3B30;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.14);
}

html { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100%;
  max-width: 430px;
  margin: 0 auto;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ── TOP BAR ── */
#topbar {
  background: var(--primary);
  padding: 12px 18px;
  padding-top: calc(12px + env(safe-area-inset-top));
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

#topbar h1 {
  font-size: 18px;
  font-weight: 700;
  color: white;
  letter-spacing: -0.3px;
}

#topbar-right { display: flex; gap: 10px; align-items: center; }

#theme-btn {
  background: rgba(255,255,255,0.18);
  border: none;
  color: white;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s, background 0.15s;
}
#theme-btn:active { transform: scale(0.9); background: rgba(255,255,255,0.28); }

#mic-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255,255,255,0.95);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.18);
  transition: transform 0.15s, box-shadow 0.15s;
}
#mic-btn:active { transform: scale(0.9); }
#mic-btn svg { fill: var(--primary); width: 22px; height: 22px; transition: fill 0.2s; }

#mic-btn.recording {
  background: var(--red);
  animation: pulse 0.8s ease-in-out infinite;
}
#mic-btn.recording svg { fill: white; }

@keyframes pulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(255,59,48,0.4); }
  50% { box-shadow: 0 0 0 10px rgba(255,59,48,0); }
}

/* ── SEARCH ── */
#search-wrap {
  padding: 12px 16px 10px;
  background: var(--primary);
}

#search-input {
  width: 100%;
  padding: 11px 16px;
  font-size: 16px;
  font-family: inherit;
  background: rgba(255,255,255,0.15);
  border: 1.5px solid rgba(255,255,255,0.25);
  border-radius: 12px;
  outline: none;
  color: white;
  transition: background 0.2s, border-color 0.2s;
  -webkit-appearance: none;
}
#search-input::placeholder { color: rgba(255,255,255,0.6); }
#search-input:focus {
  background: rgba(255,255,255,0.22);
  border-color: rgba(255,255,255,0.5);
}

/* ── RESULTS COUNT ── */
#results-count {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  padding: 10px 18px 4px;
  letter-spacing: 0.1px;
}

/* ── ITEM LIST ── */
#results {
  padding-bottom: calc(90px + env(safe-area-inset-bottom));
}

.section-bg {
  background: var(--card);
  margin: 8px 12px;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.item-row {
  display: flex;
  align-items: center;
  padding: 13px 16px;
  gap: 12px;
  position: relative;
}

.item-row::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 16px;
  right: 0;
  height: 0.5px;
  background: var(--border);
}
.item-row:last-child::after { display: none; }

.item-info { flex: 1; min-width: 0; }

.item-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-sub {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}

.item-unit { font-size: 12px; color: var(--muted); }

.stock-badge {
  font-size: 10px;
  font-weight: 700;
  color: var(--red);
  background: rgba(255,59,48,0.1);
  padding: 2px 7px;
  border-radius: 8px;
}

.item-price {
  font-size: 16px;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: -0.3px;
  margin-right: 4px;
}

.add-btn {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 10px;
  width: 36px;
  height: 36px;
  font-size: 22px;
  font-weight: 300;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(15,110,86,0.3);
  transition: transform 0.12s cubic-bezier(0.34,1.56,0.64,1), box-shadow 0.12s;
  will-change: transform;
}
.add-btn:active {
  transform: scale(0.82);
  box-shadow: 0 1px 4px rgba(15,110,86,0.2);
}

.add-btn.pop {
  animation: pop 0.3s cubic-bezier(0.34,1.56,0.64,1);
}
@keyframes pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.3); }
  100% { transform: scale(1); }
}

/* ── FOOTER ── */
#footer {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 430px;
  background: rgba(15,110,86,0.97);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  padding: 12px 18px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 100;
  box-shadow: 0 -1px 0 rgba(255,255,255,0.1), 0 -8px 24px rgba(0,0,0,0.12);
}

.footer-lbl { font-size: 11px; color: rgba(255,255,255,0.65); font-weight: 500; }
.footer-total {
  font-size: 24px;
  font-weight: 800;
  color: white;
  letter-spacing: -0.5px;
  transition: all 0.2s;
}
.footer-count { font-size: 11px; color: rgba(255,255,255,0.65); }

#pay-btn {
  background: white;
  color: var(--primary);
  border: none;
  border-radius: 12px;
  padding: 13px 22px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  box-shadow: 0 2px 12px rgba(0,0,0,0.15);
  transition: transform 0.15s cubic-bezier(0.34,1.56,0.64,1);
  letter-spacing: -0.2px;
}
#pay-btn:active { transform: scale(0.94); }
#pay-btn:disabled { opacity: 0.35; transform: none; }

/* ── SHEET BASE ── */
.sheet-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0);
  z-index: 300;
  align-items: flex-end;
  transition: background 0.3s;
}
.sheet-overlay.open {
  display: flex;
  background: rgba(0,0,0,0.45);
}

.sheet {
  background: var(--bg);
  width: 100%;
  border-radius: 22px 22px 0 0;
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: var(--shadow-lg);
  animation: sheetUp 0.38s cubic-bezier(0.32,0.72,0,1);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
}

@keyframes sheetUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.sheet-handle {
  width: 36px;
  height: 4px;
  background: rgba(60,60,67,0.18);
  border-radius: 2px;
  margin: 10px auto 0;
  flex-shrink: 0;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px 12px;
  border-bottom: 0.5px solid var(--border);
  flex-shrink: 0;
}
.sheet-header h2 { font-size: 17px; font-weight: 700; letter-spacing: -0.3px; }

.sheet-close {
  background: rgba(120,120,128,0.16);
  border: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  font-size: 14px;
  color: var(--text2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  transition: transform 0.15s;
}
.sheet-close:active { transform: scale(0.88); }

/* ── BASKET SHEET ── */
#basket-panel { @extend .sheet-overlay; }
#basket-sheet { @extend .sheet; }

#basket-items {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.b-section {
  background: var(--card);
  margin: 8px 12px;
  border-radius: 14px;
  overflow: hidden;
}

.b-row {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  gap: 12px;
  position: relative;
}
.b-row::after {
  content: '';
  position: absolute;
  bottom: 0; left: 16px; right: 0;
  height: 0.5px;
  background: var(--border);
}
.b-row:last-child::after { display: none; }

.b-info { flex: 1; min-width: 0; }
.b-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.b-line { font-size: 13px; color: var(--primary); font-weight: 700; margin-top: 2px; }

.b-controls { display: flex; align-items: center; gap: 8px; }

.bq {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 1.5px solid rgba(15,110,86,0.4);
  background: white;
  color: var(--primary);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.12s;
}
.bq:active { transform: scale(0.85); background: rgba(15,110,86,0.08); }

.bq-num { font-size: 15px; font-weight: 700; min-width: 22px; text-align: center; color: var(--text); }

.b-del {
  background: rgba(255,59,48,0.1);
  border: none;
  color: var(--red);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 5px 8px;
  border-radius: 8px;
  transition: transform 0.12s;
}
.b-del:active { transform: scale(0.88); }

#basket-footer {
  padding: 14px 16px;
  padding-bottom: calc(14px + env(safe-area-inset-bottom));
  border-top: 0.5px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}

#basket-total {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 12px;
  letter-spacing: -0.3px;
}
#basket-total span { color: var(--primary); }

#checkout-btn {
  width: 100%;
  padding: 16px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  box-shadow: 0 4px 16px rgba(15,110,86,0.35);
  transition: transform 0.15s cubic-bezier(0.34,1.56,0.64,1);
  letter-spacing: -0.2px;
}
#checkout-btn:active { transform: scale(0.97); }

/* ── CHECKOUT ── */
#checkout-screen {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 400;
  flex-direction: column;
  max-width: 430px;
  left: 50%;
  transform: translateX(-50%);
  animation: screenIn 0.32s cubic-bezier(0.32,0.72,0,1);
}
#checkout-screen.open { display: flex; }

@keyframes screenIn {
  from { transform: translateX(calc(-50% + 100%)); }
  to { transform: translateX(-50%); }
}

#checkout-bar {
  background: var(--primary);
  color: white;
  padding: 14px 18px;
  padding-top: calc(14px + env(safe-area-inset-top));
  display: flex;
  align-items: center;
  gap: 12px;
}
#checkout-back {
  background: rgba(255,255,255,0.18);
  border: none;
  color: white;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.15s;
}
#checkout-back:active { transform: scale(0.88); }
#checkout-bar h2 { font-size: 17px; font-weight: 700; letter-spacing: -0.3px; }

#checkout-body {
  flex: 1;
  padding: 20px 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.co-lbl { font-size: 12px; font-weight: 500; color: var(--muted); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.4px; }

#co-total {
  font-size: 40px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 28px;
  letter-spacing: -1px;
}
#co-total span { color: var(--primary); }

.co-card {
  background: var(--card);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

#cash-display {
  font-size: 32px;
  font-weight: 700;
  text-align: right;
  color: var(--text);
  letter-spacing: -0.8px;
  min-height: 44px;
}

#change-box {
  background: rgba(15,110,86,0.08);
  border-radius: 16px;
  padding: 16px;
  text-align: center;
  margin-bottom: 20px;
  border: 1.5px solid rgba(15,110,86,0.15);
}
#change-val {
  font-size: 44px;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -1.2px;
  transition: color 0.2s;
}
#change-val.neg { color: var(--red); }

#numpad {
  display: grid;
  grid-template-columns: repeat(3,1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.np {
  padding: 17px 0;
  font-size: 22px;
  font-weight: 500;
  border: none;
  background: var(--card);
  border-radius: 12px;
  cursor: pointer;
  color: var(--text);
  font-family: inherit;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  transition: transform 0.1s cubic-bezier(0.34,1.56,0.64,1), background 0.1s;
  letter-spacing: -0.3px;
}
.np:active { transform: scale(0.92); background: #e8e8ed; }
.np.np0 { grid-column: span 2; }
.np.npdel { background: rgba(255,59,48,0.08); color: var(--red); }
.np.npdel:active { background: rgba(255,59,48,0.16); }

#done-btn {
  width: 100%;
  padding: 17px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 14px;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  box-shadow: 0 4px 16px rgba(15,110,86,0.35);
  letter-spacing: -0.3px;
  transition: transform 0.15s cubic-bezier(0.34,1.56,0.64,1);
}
#done-btn:active { transform: scale(0.97); }

/* ── THEME PICKER ── */
#theme-panel {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 500;
  align-items: flex-end;
}
#theme-panel.open { display: flex; }

#theme-sheet {
  background: var(--bg);
  width: 100%;
  border-radius: 22px 22px 0 0;
  padding: 0 20px calc(24px + env(safe-area-inset-bottom));
  animation: sheetUp 0.38s cubic-bezier(0.32,0.72,0,1);
}

.theme-handle {
  width: 36px; height: 4px;
  background: rgba(60,60,67,0.18);
  border-radius: 2px;
  margin: 10px auto 16px;
}

#theme-sheet h3 {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 16px;
  letter-spacing: -0.3px;
}

#colour-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}

.colour-opt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.colour-swatch {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: 3px solid transparent;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  transition: transform 0.2s cubic-bezier(0.34,1.56,0.64,1), border-color 0.15s;
}
.colour-opt:active .colour-swatch { transform: scale(0.88); }
.colour-opt.active .colour-swatch { border-color: var(--text); transform: scale(1.08); }

.colour-name { font-size: 11px; color: var(--muted); font-weight: 500; text-align: center; }

/* ── TOAST ── */
#toast {
  position: fixed;
  bottom: calc(88px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: rgba(28,28,30,0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  color: white;
  padding: 9px 18px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
  z-index: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s cubic-bezier(0.34,1.56,0.64,1);
  white-space: nowrap;
  letter-spacing: -0.1px;
}
#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── EMPTY STATE ── */
.empty {
  text-align: center;
  padding: 56px 24px;
  color: var(--muted);
  font-size: 15px;
  font-weight: 500;
}

/* ── SCAN BUTTON ── */
#scan-btn {
  background: rgba(255,255,255,0.18);
  border: none;
  color: white;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s, background 0.15s;
}
#scan-btn svg { width: 20px; height: 20px; stroke: white; }
#scan-btn:active { transform: scale(0.9); background: rgba(255,255,255,0.28); }

/* ── SCANNER OVERLAY ── */
#scanner-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 600;
  flex-direction: column;
}
#scanner-overlay.open { display: flex; }

#scanner-bar {
  background: var(--primary);
  padding: 14px 16px;
  padding-top: calc(14px + env(safe-area-inset-top));
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
#scanner-bar span { color: white; font-size: 16px; font-weight: 700; letter-spacing: -0.3px; }
#scanner-close {
  background: rgba(255,255,255,0.18);
  border: none;
  color: white;
  width: 34px; height: 34px;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.15s;
}
#scanner-close:active { transform: scale(0.88); }

#scanner-viewport {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

#scanner-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#scanner-frame {
  position: absolute;
  width: 260px;
  height: 160px;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.corner {
  position: absolute;
  width: 24px; height: 24px;
  border-color: white;
  border-style: solid;
}
.corner.tl { top: 0; left: 0; border-width: 3px 0 0 3px; border-radius: 4px 0 0 0; }
.corner.tr { top: 0; right: 0; border-width: 3px 3px 0 0; border-radius: 0 4px 0 0; }
.corner.bl { bottom: 0; left: 0; border-width: 0 0 3px 3px; border-radius: 0 0 0 4px; }
.corner.br { bottom: 0; right: 0; border-width: 0 3px 3px 0; border-radius: 0 0 4px 0; }

#scanner-line {
  position: absolute;
  left: 4px; right: 4px;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--primary), white, var(--primary), transparent);
  top: 0;
  animation: scanline 2s ease-in-out infinite;
}
@keyframes scanline {
  0%   { top: 4px; opacity: 1; }
  90%  { top: calc(100% - 6px); opacity: 1; }
  100% { top: calc(100% - 6px); opacity: 0; }
}

#scanner-hint {
  position: absolute;
  bottom: 48px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(8px);
  color: white;
  padding: 8px 20px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
}
