:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1c1e21;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #4f46e5;
  --accent-b: #0891b2;
  --danger: #dc2626;
  --shared: #d97706;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.9rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar h1 { font-size: 1.1rem; margin: 0; }

.icon-btn {
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  padding: 0.2rem 0.5rem;
  color: var(--text);
}

#app {
  flex: 1;
  max-width: 480px;
  width: 100%;
  margin: 0 auto;
  padding: 1rem;
  padding-bottom: 6rem;
}

.view[hidden] { display: none; }

/* ---------- receipt list ---------- */

.receipt-list { display: flex; flex-direction: column; gap: 0.75rem; }

.receipt-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.9rem 1rem;
  position: relative;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.receipt-card-main { display: flex; flex-direction: column; gap: 0.15rem; }
.receipt-card-main .muted { color: var(--muted); font-size: 0.82rem; }
.receipt-card-totals { display: flex; justify-content: space-between; font-size: 0.9rem; color: var(--muted); }
.delete-btn { position: absolute; top: 0.4rem; right: 0.5rem; color: var(--muted); }
.delete-btn:hover { color: var(--danger); }

.empty { color: var(--muted); text-align: center; margin-top: 3rem; }

.fab {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: white;
  font-size: 1.8rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

/* ---------- forms ---------- */

.form { display: flex; flex-direction: column; gap: 0.9rem; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 1rem; margin-bottom: 1rem; }
.form h3 { margin: 0; font-size: 0.95rem; }
.form label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.85rem; color: var(--muted); }
.form input, .form select {
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  color: var(--text);
  background: var(--bg);
}
.form .hint { font-size: 0.78rem; color: var(--muted); margin: 0; }

button.primary, button.secondary {
  border: none;
  border-radius: 8px;
  padding: 0.7rem 1rem;
  font-size: 0.95rem;
  cursor: pointer;
}
button.primary { background: var(--accent); color: white; }
button.secondary { background: var(--accent-b); color: white; }

/* ---------- tabs ---------- */

.tabs { display: flex; gap: 0.4rem; margin-bottom: 1rem; }
.tab-btn {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem;
  cursor: pointer;
  color: var(--muted);
  font-size: 0.85rem;
}
.tab-btn.active { background: var(--accent); color: white; border-color: var(--accent); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---------- deck ---------- */

.deck {
  position: relative;
  height: 320px;
  margin: 1rem 0;
}

.deck-empty { text-align: center; color: var(--muted); padding: 4rem 1rem; }

.card {
  position: absolute;
  inset: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.08);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 1.5rem;
  touch-action: none;
  user-select: none;
}
.card.top { cursor: grab; z-index: 3; }
.card.dragging { cursor: grabbing; transition: none; }
.card:not(.top):nth-last-child(2) { transform: scale(0.96) translateY(10px); z-index: 2; opacity: 0.85; }
.card:not(.top):nth-last-child(3) { transform: scale(0.92) translateY(20px); z-index: 1; opacity: 0.7; }

.card-img {
  width: 100px;
  height: 100px;
  object-fit: contain;
  border-radius: 8px;
  background: var(--bg);
}
.card-name { font-size: 1.3rem; font-weight: 600; text-align: center; }
.card-price { font-size: 1.6rem; color: var(--accent); font-weight: 700; }
.card-qty { color: var(--muted); font-size: 0.9rem; }
.badge {
  position: absolute;
  top: 0.7rem;
  left: 0.7rem;
  background: var(--shared);
  color: white;
  font-size: 0.7rem;
  text-transform: uppercase;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
}

.qty-stepper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin: 0.6rem 0;
  color: var(--muted);
  font-size: 0.9rem;
}
.qty-stepper .mini-btn { font-size: 1rem; padding: 0.25rem 0.7rem; }
#qtyValue { font-weight: 700; color: var(--text); min-width: 1.2em; text-align: center; }

.swipe-controls { display: flex; gap: 0.6rem; justify-content: center; margin-top: 0.5rem; }
.swipe-btn {
  flex: 1;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 10px;
  padding: 0.7rem 0.4rem;
  font-size: 0.85rem;
  cursor: pointer;
}
.swipe-btn.shared { color: var(--shared); border-color: var(--shared); }

.undo-btn {
  display: block;
  margin: 0.9rem auto 0;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.85rem;
}
.undo-btn:disabled { opacity: 0.4; cursor: default; }

/* ---------- bins ---------- */

.bins { display: flex; flex-direction: column; gap: 1rem; }
.bin { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 0.8rem; }
.bin h3 { margin: 0 0 0.5rem; font-size: 0.9rem; }
.shared-bin h3 { color: var(--shared); }
.bin-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.4rem; }
.bin-item { display: flex; align-items: center; gap: 0.5rem; font-size: 0.88rem; padding: 0.35rem 0; border-bottom: 1px solid var(--border); }
.bin-item:last-child { border-bottom: none; }
.bin-item-name { flex: 1; display: flex; align-items: center; gap: 0.4rem; }
.bin-item-thumb { width: 28px; height: 28px; object-fit: contain; border-radius: 4px; background: var(--bg); }
.bin-item-price { color: var(--muted); }
.bin-item-actions { display: flex; gap: 0.2rem; }
.mini-btn { border: 1px solid var(--border); background: var(--bg); border-radius: 6px; padding: 0.15rem 0.4rem; cursor: pointer; font-size: 0.8rem; }

/* ---------- totals footer ---------- */

.totals-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 0.7rem 1rem;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.totals-footer > div { display: flex; justify-content: space-between; font-size: 0.95rem; }
.totals-footer .muted-line { color: var(--shared); font-size: 0.78rem; justify-content: center; }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  bottom: 5rem;
  left: 50%;
  transform: translateX(-50%);
  background: #1c1e21;
  color: white;
  padding: 0.6rem 1rem;
  border-radius: 8px;
  font-size: 0.85rem;
  max-width: 90%;
  text-align: center;
  z-index: 50;
}

/* ---------- modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  z-index: 100;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: var(--surface);
  border-radius: 12px;
  padding: 1.25rem;
  max-width: 340px;
  width: 100%;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}
.modal p { margin: 0 0 1rem; font-size: 0.95rem; }
.modal-actions { display: flex; gap: 0.6rem; justify-content: flex-end; }
.modal-actions button { padding: 0.55rem 1rem; font-size: 0.9rem; }
