:root {
  --page: #e8e2d8;
  --bg: #f6f3ee;
  --text: #1f1a17;
  --muted: #6b625b;
  --brand: #7a4b4b;
  --accent: #4f8a4b;
  --danger: #b23a2e;
  --radius: 18px;
  --gap: 12px;
  --side: 16px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
}

* { box-sizing: border-box; }

html {
  height: 100%;
  background: var(--page);
}

body {
  height: 100%;
  height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button { font: inherit; color: inherit; }

/* ---------- Name ---------- */

.top {
  display: flex;
  align-items: stretch;
  gap: 6px;
  padding: calc(env(safe-area-inset-top) + 12px) var(--side) 8px;
}

/* logout (left) and admin gear (right) next to the name field */
.icon-form { display: flex; margin: 0; }

.icon-link {
  flex: none;
  width: 48px;
  display: grid;
  place-items: center;
  padding: 0;
  border: none;
  border-radius: 14px;
  background: transparent;
  color: var(--brand);
  cursor: pointer;
  touch-action: manipulation;
}

.icon-link:active { background: #ebe5dd; }
.icon-link:focus-visible { outline: 3px solid var(--brand); outline-offset: 1px; }

.icon-link svg {
  width: 28px;
  height: 28px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.name {
  flex: 1;
  min-width: 0;
  width: 100%;
  padding: 14px 16px;
  border: none;
  border-radius: var(--radius);
  background: var(--brand);
  color: #fff;
  font: inherit;
  font-size: clamp(1.75rem, 7.5vw, 2.25rem);
  font-weight: 600;
  text-align: center;
  outline: none;
  box-shadow: 0 2px 0 rgba(0, 0, 0, .12);
}

.name::placeholder { color: rgba(255, 255, 255, .6); font-weight: 400; }
.name:focus-visible { box-shadow: 0 0 0 3px rgba(122, 75, 75, .35); }

/* ---------- Item tiles ---------- */

.items-wrap {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 8px var(--side);
  container-type: size;
}

.items {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap);
  /* 3 rows (= 6 items) fill the visible area; more items scroll */
  grid-auto-rows: clamp(120px, calc((100cqh - 2 * var(--gap)) / 3), 240px);
}

.tile {
  position: relative;
  border-radius: var(--radius);
  background: var(--c);
  box-shadow: 0 2px 0 rgba(0, 0, 0, .12);
  user-select: none;
  -webkit-user-select: none;
  transition: transform .08s ease;
}

.tile:has(.add:active) { transform: scale(.97); }

.add {
  position: absolute;
  inset: 0;
  width: 100%;
  border: none;
  border-radius: inherit;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  touch-action: manipulation;
}

.add:focus-visible { outline: 3px solid var(--text); outline-offset: 2px; }

.count {
  font-size: clamp(2.5rem, 14cqh, 4.5rem);
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.tile.zero .count { opacity: .45; }

.tile.bump .count { animation: bump .18s ease; }

@keyframes bump {
  50% { transform: scale(1.18); }
}

.label {
  font-size: clamp(1.2rem, 5.5cqi, 1.6rem);
  font-weight: 600;
}

.price {
  font-size: clamp(.95rem, 4cqi, 1.15rem);
  color: rgba(0, 0, 0, .6);
  font-variant-numeric: tabular-nums;
}

.minus {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 1;
  width: 48px;
  height: 48px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, .6);
  font-size: 2rem;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
}

.minus:active { background: rgba(255, 255, 255, .9); }
.minus:disabled { opacity: .3; cursor: default; }

.items-status {
  margin: 24px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 1.1rem;
  text-align: center;
}

.items-status[hidden] { display: none; }
.items-status .btn { padding: 0 24px; }

/* ---------- Checkout button ---------- */

.bottom {
  padding: 8px var(--side) calc(env(safe-area-inset-bottom) + 12px);
}

.checkout {
  width: 100%;
  min-height: clamp(64px, 9dvh, 84px);
  padding: 12px 20px;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: clamp(1.5rem, 7vw, 2rem);
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 0 rgba(0, 0, 0, .12);
  touch-action: manipulation;
}

/* "2 Verkäufe noch nicht gesendet" – only visible when sending failed */
.outbox-status {
  margin: 0 4px 8px;
  padding: 8px 12px;
  border-radius: 12px;
  background: #fbeedb;
  color: #8a5a12;
  font-size: .95rem;
  font-weight: 600;
  text-align: center;
}

.outbox-status[hidden] { display: none; }

.checkout:disabled { opacity: .5; cursor: default; }
.checkout:not(:disabled):active { transform: scale(.98); }
.checkout-total { font-variant-numeric: tabular-nums; }

/* ---------- Checkout dialog ---------- */

/*
 * Everything in the dialog is sized in em, relative to this base font size.
 * It grows with the screen (height and width) between 15px and 21px,
 * so small phones still see everything and large screens use the space.
 */
.sheet {
  font-size: clamp(15px, min(2.3dvh, 4.4vw), 21px);
  width: min(100% - 24px, 560px);
  max-height: calc(100dvh - 24px);
  padding: 0;
  border: none;
  border-radius: 22px;
  background: #fff;
  color: var(--text);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}

.sheet::backdrop {
  background: rgba(30, 20, 15, .55);
}

.sheet[open] { animation: pop .18s ease; }

@keyframes pop {
  from { opacity: 0; transform: translateY(12px) scale(.98); }
}

.sheet-inner {
  display: flex;
  flex-direction: column;
  gap: .8em;
  padding: 1.1em 1.2em 1.2em;
  /* lets the big numbers also respect the available width (cqi) */
  container-type: inline-size;
}

.sheet-head h2 {
  margin: 0;
  font-size: 1.5em;
  line-height: 1.2;
  outline: none;
}

.sheet-who {
  margin: .1em 0 0;
  color: var(--muted);
}

.sheet-who:empty { display: none; }

.summary {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 1.15em;
  font-variant-numeric: tabular-nums;
}

.summary li {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: baseline;
  gap: .6em;
  padding: .4em 0;
  border-bottom: 1px solid #eee;
}

.summary .qty {
  min-width: 2.2em;
  font-weight: 700;
}

.summary .each {
  display: inline-block;
  color: var(--muted);
  font-size: .8em;
  margin-left: .3em;
  white-space: nowrap;
}

.sum-row,
.change-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  column-gap: .5em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

/* the number moves to its own line (right-aligned) if both don't fit */
.sum-row strong,
.change-row strong {
  margin-left: auto;
  white-space: nowrap;
}

.sum-row > span { font-size: min(2em, 9cqi); }
.sum-row strong { font-size: min(3.2em, 15cqi); }

.given {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .6em;
  font-size: 1.35em;
}

.given-field {
  display: flex;
  align-items: center;
  gap: .3em;
  font-size: 1.15em;
}

.given input {
  /* room for "123,45" (+ cursor); padding and border come on top */
  box-sizing: content-box;
  width: 6.4ch;
  min-width: 0;
  padding: .3em .45em;
  border: 2px solid #d8d2ca;
  border-radius: 12px;
  font: inherit;
  font-size: 1.25em;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.given input:focus {
  outline: none;
  border-color: var(--accent);
}

.quick {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: .45em;
}

.quick button {
  min-height: 2.9em;
  padding: 0 .2em;
  border: none;
  border-radius: 12px;
  background: #efebe5;
  font-size: min(1.3em, 7.5cqi);
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  touch-action: manipulation;
}

.quick button:active { filter: brightness(.88); }

/* colours of the euro banknotes (Europa series) */
.quick .note { box-shadow: inset 0 0 0 2px rgba(0, 0, 0, .12); }
.quick .note-5 { background: #b7bdb6; color: #1f1a17; }
.quick .note-10 { background: #c8463c; color: #fff; }
.quick .note-20 { background: #3a6db3; color: #fff; }
.quick .note-50 { background: #ee9437; color: #1f1a17; }

/* "passend" and "löschen" share the second row, a bit lower */
.quick .quick-wide {
  grid-column: span 2;
  min-height: 2.3em;
  font-size: min(1.1em, 6cqi);
}

.change-row {
  padding: .6em .8em;
  border-radius: 14px;
  background: #efebe5;
}

.change-row > span { font-size: min(1.8em, 8cqi); }
.change-row strong { font-size: min(3.2em, 14cqi); }
.change-row.ok { background: #e3f0e1; color: #2c6a28; }
.change-row.missing { background: #f8e1de; color: var(--danger); }

.sheet-actions {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: .6em;
}

.btn {
  min-height: 2.9em;
  border: none;
  border-radius: 14px;
  font-size: 1.25em;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}

.btn.primary { background: var(--accent); color: #fff; }
.btn.brand { background: var(--brand); color: #fff; }
.btn.secondary { background: #efebe5; }

/* small confirmation dialog (confirm.js), e.g. "Abmelden?" */
.confirm-sheet { width: min(100% - 24px, 420px); }

.confirm-title {
  margin: 0;
  font-size: 1.5em;
}

.confirm-text {
  margin: 0;
  color: var(--muted);
  line-height: 1.4;
}

/* very short screens: tighter spacing so the whole dialog still fits */
@media (max-height: 640px) {
  .sheet-inner { gap: .5em; padding: .9em 1em 1em; }
  .summary li { padding: .25em 0; }
  .quick button { min-height: 2.5em; }
  .quick .quick-wide { min-height: 2em; }
  .change-row { padding: .45em .8em; }
  .btn { min-height: 2.6em; }
}

/* ---------- Login ---------- */

.login {
  flex: 1;
  display: grid;
  place-items: center;
  padding: calc(env(safe-area-inset-top) + var(--side)) var(--side) calc(env(safe-area-inset-bottom) + var(--side));
}

.login-card {
  width: min(100%, 400px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 28px 24px;
  border-radius: 22px;
  background: #fff;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .12);
  text-align: center;
}

.login-logo {
  width: 72px;
  height: 72px;
  margin: 0 auto 4px;
  border-radius: 18px;
  background: var(--brand);
  color: #fff;
  font-size: 2.6rem;
  font-weight: 700;
  display: grid;
  place-items: center;
}

.login-card h1 {
  margin: 0;
  font-size: 2.2rem;
}

.login-sub {
  margin: -6px 0 8px;
  color: var(--muted);
}

.login-card label {
  text-align: left;
  font-weight: 600;
  font-size: 1.1rem;
}

.login-card input {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid #d8d2ca;
  border-radius: 14px;
  font: inherit;
  font-size: 1.4rem;
}

.login-card input:focus {
  outline: none;
  border-color: var(--accent);
}

.login-error {
  margin: 0;
  color: var(--danger);
  font-weight: 600;
}

.login-card .btn {
  min-height: 60px;
  margin-top: 4px;
  font-size: 1.35rem;
}
