:root {
  color-scheme: dark;
  --bg: #0f131a;
  --bg-glow: #1a2334;
  --card: #1a2130;
  --card-2: #232d40;
  --input: #121826;
  --ink: #e9edf5;
  --muted: #94a1b5;
  --accent: #e23b4a;
  --accent-dark: #c02a38;
  --accent-ink: #ffffff;
  --ok: #43d17c;
  --warn: #f0b429;
  --danger: #ff7b7b;
  --danger-bg: rgba(226, 59, 74, .13);
  --danger-border: rgba(226, 59, 74, .38);
  --link: #6fb1ff;
  --line: #2b3547;
  --ice: #5aa9ff;
  --ice-bg: rgba(90, 169, 255, .14);
  --drink: #ff6ea1;
  --drink-bg: rgba(255, 110, 161, .14);
  --tally: #f0e6d2;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 10px 28px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100dvh;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: var(--bg);
  background-image: radial-gradient(900px 480px at 50% -8%, var(--bg-glow), transparent 70%);
  background-repeat: no-repeat;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

.offline-banner {
  padding: 8px 16px;
  background: rgba(240, 180, 41, .14);
  border-bottom: 1px solid rgba(240, 180, 41, .38);
  color: var(--warn);
  font-size: .82rem;
  text-align: center;
}

h1, h2, h3 { margin: 0; }
h2 { font-size: 1.05rem; }

p { margin: 0; }

.muted { color: var(--muted); }
.small { font-size: .82rem; }

button { font-family: inherit; touch-action: manipulation; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- App bar ---------- */

.app-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 12px;
  padding-top: calc(8px + env(safe-area-inset-top));
  background: rgba(15, 19, 26, .88);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.app-bar h1 {
  flex: 1;
  text-align: center;
  font-size: clamp(.95rem, 4.4vw, 1.1rem);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}

.icon-btn:active { background: rgba(255, 255, 255, .08); }
.icon-btn svg { display: block; }

/* ---------- Layout ---------- */

main, #historyScreen, #settingsScreen {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 16px calc(130px + env(safe-area-inset-bottom));
}

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

.card h2 { margin-bottom: 12px; }

.row-between {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.row-between h2 { margin: 0; }

/* ---------- Item counters ---------- */

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

@media (min-width: 560px) {
  .items { grid-template-columns: 1fr 1fr; }
}

.item-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 0;
}

.item-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.item-emoji { font-size: 1.8rem; line-height: 1; }
.item-info h2 { margin: 0 0 2px; font-size: 1.05rem; }
.item-info p { margin: 0; }

.add-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 68px;
  height: 68px;
  border: 0;
  border-radius: 50%;
  background: var(--ice-bg);
  color: var(--ice);
  cursor: pointer;
  transition: transform .06s ease, filter .12s ease;
}

.add-btn svg { display: block; }

.add-btn:active { transform: scale(.94); filter: brightness(1.3); }

[data-kind="drink"] .add-btn { background: var(--drink-bg); color: var(--drink); }

/* ---------- Kasse ---------- */

.quick-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

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

.cash-quick {
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card-2);
  color: var(--ink);
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
}

.cash-quick:active { background: #2c3850; }

.custom-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.custom-row input {
  flex: 1;
  min-width: 0;
  height: 48px;
  padding: 0 12px;
  font-size: 1rem;
  color: var(--ink);
  background: var(--input);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.custom-row input::placeholder { color: #66738a; }

.custom-row input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: transparent;
}

.primary {
  min-height: 48px;
  padding: 0 18px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

.primary:active { background: var(--accent-dark); }

.primary:disabled {
  background: var(--card-2);
  color: var(--muted);
  cursor: not-allowed;
}

.cash-foot {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-top: 12px;
}

.big-money {
  margin-left: auto;
  font-size: 1.5rem;
  font-variant-numeric: tabular-nums;
}

.link-btn {
  padding: 6px 2px;
  border: 0;
  background: none;
  color: var(--link);
  font-size: .88rem;
  cursor: pointer;
  text-decoration: underline;
}

.link-btn:disabled {
  color: var(--muted);
  cursor: default;
  text-decoration: none;
}

.status-ok { color: var(--ok); }
.status-warn { color: var(--warn); }

/* ---------- Strichliste ---------- */

.tally {
  min-height: 40px;
  color: var(--tally);
  overflow-x: auto;
}

.tally-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding-bottom: 3px;
  margin-bottom: 5px;
  border-bottom: 1px dashed #3a465c;
}

.tally-block {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.tally-check {
  position: relative;
  flex: none;
  width: 21px;
  height: 21px;
  border: 1.5px solid #55637c;
  border-radius: 6px;
  background: transparent;
  pointer-events: none;
}

.tally-check[aria-checked="true"],
.tally-check[aria-checked="mixed"] {
  background: var(--ok);
  border-color: var(--ok);
}

.tally-check[aria-checked="true"]::after {
  content: '';
  position: absolute;
  left: 7px;
  top: 3px;
  width: 5px;
  height: 10px;
  border: solid #0f131a;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.tally-check[aria-checked="mixed"]::after {
  content: '';
  position: absolute;
  left: 4px;
  right: 4px;
  top: 50%;
  height: 2px;
  margin-top: -1px;
  border-radius: 1px;
  background: #0f131a;
}

.tally-group svg {
  display: block;
  width: 22px;
  height: 30px;
}

.tally-group--empty {
  display: inline-block;
  width: 22px;
  height: 30px;
  border: 1px dashed #3a465c;
  border-radius: 6px;
  opacity: .55;
}

.tally-group svg line {
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
}

.tally-row-count {
  margin-left: auto;
  padding-left: 6px;
  font-size: .75rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.tally-empty {
  color: var(--muted);
  font-size: .88rem;
  line-height: 30px;
}

/* ---------- Abschluss ---------- */

.finalize-btn {
  width: 100%;
  margin-top: 12px;
}

/* ---------- Verlauf ---------- */

.history-list { display: flex; flex-direction: column; }

.history-totals {
  display: flex;
  gap: 32px;
}

.history-totals .sum strong { font-size: 1.5rem; }

.history-undo {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--card-2);
  color: var(--link);
  cursor: pointer;
}

.history-undo:active { background: #2c3850; }

.day-header {
  margin: 14px 0 6px;
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
}

.day-header:first-child { margin-top: 0; }

.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.history-item:last-child { border-bottom: 0; }

.history-time {
  min-width: 46px;
  font-size: .8rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

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

.history-label { display: block; }

.history-sub {
  display: block;
  margin-top: 2px;
  font-size: .78rem;
  color: var(--muted);
}

.history-value {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.history-value.ice { color: var(--ice); }
.history-value.drink { color: var(--drink); }
.history-value.cash-in { color: var(--ok); }
.history-value.cash-out,
.history-value.minus { color: var(--danger); }
.history-value.finalize { color: var(--warn); }
.history-value.muted { color: var(--muted); font-weight: 400; }

/* ---------- Sticky summary ---------- */

.summary {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr 1fr 1.15fr;
  gap: 8px;
  max-width: 720px;
  margin: 0 auto;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: rgba(20, 26, 37, .96);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.sum {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.sum-label {
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  white-space: nowrap;
}

.sum strong {
  font-size: 1.15rem;
  font-variant-numeric: tabular-nums;
}

.sum.diff { text-align: right; }

.sum.diff strong.ok { color: var(--ok); }
.sum.diff strong.warn { color: var(--danger); }

.sum-hint { font-size: .7rem; color: var(--muted); }
.sum-hint.ok { color: var(--ok); }
.sum-hint.warn { color: var(--danger); }

/* ---------- Einstellungen ---------- */

.field {
  display: block;
  margin-bottom: 12px;
  font-size: .9rem;
  color: var(--muted);
}

.field input {
  display: block;
  width: 100%;
  height: 48px;
  margin-top: 4px;
  padding: 0 12px;
  font-size: 1rem;
  color: var(--ink);
  background: var(--input);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.field input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: transparent;
}

#savePrices { width: 100%; }

.danger {
  display: block;
  width: 100%;
  min-height: 48px;
  margin-bottom: 8px;
  border: 1px solid var(--danger-border);
  border-radius: 12px;
  background: var(--danger-bg);
  color: var(--danger);
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
}

.danger:last-child { margin-bottom: 0; }
.danger:active { background: rgba(226, 59, 74, .25); }

/* ---------- Toast ---------- */

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(100px + env(safe-area-inset-bottom));
  z-index: 30;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 999px;
  background: #2b3547;
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: .88rem;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition: opacity .18s ease, transform .18s ease;
}

#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
