:root {
  --bg: #0b1220;
  --bg-elevated: #121b2e;
  --card: #16213a;
  --border: #253352;
  --text: #eef2ff;
  --text-dim: #93a1c4;
  --accent: #22d3ee;
  --accent-2: #38bdf8;
  --green: #16a34a;
  --green-hover: #15803d;
  --red: #dc2626;
  --red-hover: #b91c1c;
  --radius: 16px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

button, input {
  font-family: inherit;
}

button {
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.hidden { display: none !important; }

/* ---------- Overlay: user select ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at top, #142038, #060a14 75%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 100;
}

.overlay-card {
  width: 100%;
  max-width: 420px;
  text-align: center;
}

.overlay-card h1 {
  font-size: 1.6rem;
  margin: 0 0 4px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.subtitle {
  color: var(--text-dim);
  margin: 0 0 24px;
  font-size: 1rem;
}

.user-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.user-grid button {
  padding: 22px 12px;
  font-size: 1.15rem;
  font-weight: 700;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease;
}

.user-grid button:active {
  transform: scale(0.96);
  background: var(--bg-elevated);
}

.new-user-form {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.new-user-form input {
  flex: 1;
  padding: 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 1rem;
}

/* ---------- App shell ---------- */
.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  padding-top: max(14px, env(safe-area-inset-top));
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.brand {
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: 0.2px;
  color: var(--accent);
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
}

.content {
  flex: 1;
  overflow-y: auto;
  padding: 12px 12px 12px;
  -webkit-overflow-scrolling: touch;
}

.tab { display: block; }

/* ---------- Buttons ---------- */
.btn {
  border: none;
  border-radius: 12px;
  padding: 10px 16px;
  font-weight: 700;
  cursor: pointer;
  font-size: 0.95rem;
  transition: transform 0.1s ease, opacity 0.15s ease;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.btn:active { transform: scale(0.96); }

.btn-small { padding: 8px 12px; font-size: 0.85rem; background: var(--card); color: var(--text); border: 1px solid var(--border); }
.btn-primary { background: var(--accent-2); color: #04121f; }
.btn-ghost { background: transparent; color: var(--accent); border: 1px solid var(--border); text-decoration: none; display: inline-block; text-align: center; }
.btn-success { background: var(--green); color: white; }
.btn-success:active { background: var(--green-hover); }
.btn-danger { background: var(--red); color: white; }
.btn-danger:active { background: var(--red-hover); }

/* ---------- Bestellung: product grid ---------- */
.product-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

@media (min-width: 480px) {
  .product-grid { grid-template-columns: repeat(3, 1fr); }
}

.product-btn {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 10px;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  min-height: 84px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
}

.product-btn:active {
  transform: scale(0.97);
  background: var(--bg-elevated);
  border-color: var(--accent);
}

.product-btn.is-retoure {
  border-color: #7c2d12;
  background: linear-gradient(180deg, #1c1220, #16213a);
}

.product-name {
  font-weight: 700;
  font-size: 0.92rem;
  line-height: 1.25;
}

.product-price {
  font-weight: 800;
  font-size: 1.05rem;
  color: var(--accent);
}

.is-retoure .product-price { color: #fb923c; }

/* ---------- Cart ---------- */
.cart-panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 60px;
}

.cart-list { padding: 4px; }

.cart-empty {
  padding: 18px;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.9rem;
}

.cart-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  gap: 8px;
}
.cart-row:last-child { border-bottom: none; }

.cart-row-name {
  font-weight: 600;
  font-size: 0.9rem;
  flex: 1;
}

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

.qty-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cart-row-qty {
  min-width: 22px;
  text-align: center;
  font-weight: 700;
}

.cart-row-sum {
  min-width: 62px;
  text-align: right;
  font-weight: 700;
  color: var(--accent);
}

/* ---------- Checkout bar ---------- */
.checkout-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 62px;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  padding: 12px 14px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  z-index: 20;
}

.checkout-total {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.checkout-total-label {
  font-size: 0.75rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

#checkout-total-value {
  font-size: 1.8rem;
  font-weight: 800;
}

.checkout-actions { display: flex; gap: 10px; }
.checkout-actions .btn { padding: 16px 18px; font-size: 1rem; }

/* ---------- Change calculator ---------- */
.change-calc {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-top: 10px;
}

.change-calc-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.change-calc-row label {
  font-size: 0.8rem;
  color: var(--text-dim);
  font-weight: 600;
}

.change-calc-row input {
  padding: 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 700;
}

.quick-amounts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.quick-amt-btn {
  flex: 1;
  min-width: 60px;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
}

.quick-amt-btn:active { transform: scale(0.95); background: var(--bg-elevated); }
.quick-amt-exact { flex-basis: 100%; color: var(--accent); border-color: var(--accent); }

.change-result {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.change-result-label { font-size: 0.85rem; color: var(--text-dim); font-weight: 600; }
#change-result-value { font-size: 1.4rem; font-weight: 800; color: var(--green); }
#change-result-value.negative { color: var(--red); }

/* ---------- Scroll spacers (keep content clear of fixed bars) ---------- */
.bottom-spacer-order { height: 210px; }
.bottom-spacer { height: 90px; }

/* ---------- Produkte tab ---------- */
.section-title { margin: 6px 0 14px; font-size: 1.2rem; }
.subsection-title { margin: 22px 0 10px; font-size: 1rem; color: var(--text-dim); }

.product-list { display: flex; flex-direction: column; gap: 8px; }

.product-list-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
}

.product-list-row .name { font-weight: 600; }
.product-list-row .meta { color: var(--text-dim); font-size: 0.8rem; margin-top: 2px; }
.product-list-row .price { font-weight: 800; color: var(--accent); font-size: 1.05rem; }

/* ---------- Analyse tab ---------- */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 6px;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 8px;
  text-align: center;
}

.stat-value { font-size: 1.15rem; font-weight: 800; color: var(--accent); }
.stat-label { font-size: 0.7rem; color: var(--text-dim); margin-top: 4px; }

.table-wrap {
  overflow-x: auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
}

.stat-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.stat-table th, .stat-table td { padding: 10px 12px; text-align: left; white-space: nowrap; }
.stat-table thead th { color: var(--text-dim); font-weight: 600; border-bottom: 1px solid var(--border); }
.stat-table tbody tr:not(:last-child) td { border-bottom: 1px solid var(--border); }
.stat-table td.num { text-align: right; font-weight: 700; }

.analyse-actions {
  display: flex;
  gap: 10px;
  margin: 20px 0;
}
.analyse-actions .btn { flex: 1; padding: 14px; }

.empty-row td { color: var(--text-dim); text-align: center; padding: 18px; }

/* ---------- Transaction history ---------- */
.history-list { display: flex; flex-direction: column; gap: 8px; }

.history-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
}

.history-main { flex: 1; min-width: 0; }

.history-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.history-user { font-weight: 700; }
.history-time { color: var(--text-dim); font-size: 0.78rem; white-space: nowrap; }

.history-items {
  color: var(--text-dim);
  font-size: 0.8rem;
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.history-total { font-weight: 800; color: var(--accent); }

.history-delete-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 36px;
  height: 36px;
  font-size: 1.05rem;
  cursor: pointer;
  color: var(--red);
  flex-shrink: 0;
}
.history-delete-btn:active { transform: scale(0.92); background: var(--bg-elevated); }

.history-delete-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  color: var(--text-dim);
}
.history-delete-btn:disabled:active { transform: none; background: none; }

.reset-hint {
  color: var(--text-dim);
  font-size: 0.78rem;
  margin: -10px 0 14px;
}

/* ---------- Bottom nav ---------- */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 62px;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  display: flex;
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 30;
}

.nav-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 0.7rem;
  font-weight: 600;
  cursor: pointer;
}

.nav-icon { font-size: 1.25rem; }

.nav-btn.active { color: var(--accent); }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 140px;
  transform: translateX(-50%);
  background: #0f2e1c;
  border: 1px solid var(--green);
  color: #d1fae5;
  padding: 10px 18px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 0.9rem;
  z-index: 200;
  transition: opacity 0.3s ease;
}

.toast.error {
  background: #2e0f0f;
  border-color: var(--red);
  color: #fee2e2;
}
