/* Pickerl
   Layout: eine Spalte wie ein Regal. Oben der Sucher mit einem Rahmen in Etikettenform,
   darunter die Liste als Stapel von E-Ink-Etiketten. Gelbe runde Pickerl markieren,
   welches Stück welcher Person ein Pickerl bekommt. Keine fremden Schriften. */

:root {
  --bg: #ecede8;
  --surface: #f7f7f3;
  --paper: #e1e2db;
  --ink: #151613;
  --muted: #5d6159;
  --rule: #cbcec4;
  --bezel: #1c1d1b;
  --on-bezel: #eeefe9;
  --sticker: #ffd21a;
  --sticker-ink: #1d1800;
  --ok: #3f8a17;
  --ok-bg: #8ee04a;
  --ok-ink: #102300;
  --alert: #c2321f;

  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-price: "DIN Alternate", "DIN 2014", Bahnschrift, "Roboto Condensed", "Arial Narrow", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  --r-tag: 6px;
  --gutter: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f100e;
    --surface: #191a17;
    --paper: #23241f;
    --ink: #ecede6;
    --muted: #9da096;
    --rule: #33352f;
    --bezel: #000000;
    --on-bezel: #eeefe9;
    --ok: #8ee04a;
    --ok-bg: #8ee04a;
    --ok-ink: #102300;
    --alert: #ff6b55;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f100e;
  --surface: #191a17;
  --paper: #23241f;
  --ink: #ecede6;
  --muted: #9da096;
  --rule: #33352f;
  --bezel: #000000;
  --on-bezel: #eeefe9;
  --ok: #8ee04a;
  --ok-bg: #8ee04a;
  --ok-ink: #102300;
  --alert: #ff6b55;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 var(--font-ui);
  padding: env(safe-area-inset-top, 0px) 0 env(safe-area-inset-bottom, 0px);
}
button, input, output { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
[hidden] { display: none !important; }

.app {
  max-width: 560px;
  margin: 0 auto;
  padding-inline: var(--gutter);
  padding-block: 8px 32px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ---------- Kopf ---------- */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { margin: 0; font-size: 24px; font-weight: 800; letter-spacing: -0.02em; }
.logo {
  display: inline-grid; place-items: center;
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--sticker); color: var(--sticker-ink);
  font: 800 11px/1 var(--font-price); letter-spacing: -0.02em;
  transform: rotate(-12deg);
  box-shadow: 0 1px 0 rgb(0 0 0 / 0.25);
}

.btn {
  border: 0; border-radius: 999px; padding: 10px 16px; font-weight: 650; font-size: 15px;
  background: var(--paper); color: var(--ink);
}
.btn.primary { background: var(--ink); color: var(--bg); }
.btn.ghost { background: transparent; color: var(--muted); padding-inline: 10px; }
.btn.danger { background: var(--alert); color: #fff; }
.btn:active { transform: translateY(1px); }

.confirm {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--surface); border: 1px solid var(--rule); border-radius: 12px; padding: 10px 12px;
}
.confirm-actions { display: flex; gap: 6px; }

/* ---------- Kamera ---------- */
.cam {
  position: relative;
  height: min(44vh, 400px);
  min-height: 260px;
  border-radius: 14px;
  overflow: hidden;
  background: var(--bezel);
  color: var(--on-bezel);
  isolation: isolate;
}
.cam video {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; opacity: 0; transition: opacity 0.25s;
}
.cam.on video { opacity: 1; }
.guide {
  position: absolute; left: 50%; top: 44%;
  width: 60%; aspect-ratio: 1.9 / 1; max-width: 100%;
  transform: translate(-50%, -50%);
  border-radius: 8px;
  box-shadow: 0 0 0 100vmax rgb(0 0 0 / 0.38);
  opacity: 0; transition: opacity 0.25s;
  pointer-events: none;
}
.cam.on .guide { opacity: 1; }
.guide i { position: absolute; width: 22px; height: 22px; border: 3px solid var(--sticker); }
.guide i:nth-child(1) { left: -3px; top: -3px; border-right: 0; border-bottom: 0; border-top-left-radius: 9px; }
.guide i:nth-child(2) { right: -3px; top: -3px; border-left: 0; border-bottom: 0; border-top-right-radius: 9px; }
.guide i:nth-child(3) { left: -3px; bottom: -3px; border-right: 0; border-top: 0; border-bottom-left-radius: 9px; }
.guide i:nth-child(4) { right: -3px; bottom: -3px; border-left: 0; border-top: 0; border-bottom-right-radius: 9px; }
.cam.hit .guide i { border-color: var(--ok-bg); }

.cam-idle {
  position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: center; align-items: flex-start;
  gap: 14px; padding: 20px;
  background:
    repeating-linear-gradient(180deg, transparent 0 62px, rgb(255 255 255 / 0.05) 62px 64px),
    var(--bezel);
}
.cam.on .cam-idle { display: none; }
.cam-lead { margin: 0; max-width: 30ch; font-size: 17px; line-height: 1.35; text-wrap: balance; }
.cam-idle .btn.primary { background: var(--sticker); color: var(--sticker-ink); padding: 12px 20px; font-size: 16px; }
.cam-error { margin: 0; max-width: 36ch; font-size: 14px; color: #ffb4a6; }

.cam-bar {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 10px 10px 14px;
  background: linear-gradient(transparent, rgb(0 0 0 / 0.65));
  font-size: 14px;
}
.cam:not(.on) .cam-bar { display: none; }
.cam-status { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
.cam-tools { display: flex; gap: 6px; flex: none; }
.chip {
  border: 0; border-radius: 999px; padding: 7px 12px; font-size: 13px; font-weight: 650;
  background: rgb(255 255 255 / 0.16); color: var(--on-bezel); backdrop-filter: blur(6px);
}
.chip[aria-pressed="true"] { background: var(--sticker); color: var(--sticker-ink); }

/* ---------- Erkannt-Karte ---------- */
.detect {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center;
  background: var(--surface); border: 1px solid var(--rule); border-radius: 12px; padding: 12px 14px;
}
.detect-state { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.pill { display: inline-block; border-radius: 999px; padding: 2px 9px; font-size: 12px; font-weight: 700; letter-spacing: 0.02em; }
.pill.ok { background: var(--ok-bg); color: var(--ok-ink); }
.pill.dup { background: var(--paper); color: var(--ink); }
.pill.warn { background: var(--sticker); color: var(--sticker-ink); }
.detect-name { min-width: 0; font-weight: 650; overflow-wrap: anywhere; }
.detect-price { font: 700 24px/1 var(--font-price); font-variant-numeric: tabular-nums; }
.detect-info { grid-column: 1 / -1; font-size: 14px; color: var(--muted); }
.detect-actions { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.detect-actions .btn { padding: 8px 14px; font-size: 14px; }

/* ---------- Steuerung ---------- */
.controls { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.stepper { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.stepper-label { font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stepper-row {
  display: grid; grid-template-columns: 40px 1fr 40px; align-items: center;
  background: var(--surface); border: 1px solid var(--rule); border-radius: 10px; height: 46px;
}
.stepper-row button { border: 0; background: transparent; height: 100%; font-size: 22px; font-weight: 500; color: var(--ink); }
.stepper-row button:disabled { color: var(--rule); cursor: default; }
.stepper-row output { text-align: center; font: 700 22px/1 var(--font-price); font-variant-numeric: tabular-nums; }
.more { grid-column: 1 / -1; }
.more summary { cursor: pointer; font-size: 14px; color: var(--muted); padding: 4px 0; width: max-content; }
.more-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); gap: 12px; align-items: end; padding-top: 8px; }
.switch { display: flex; gap: 10px; align-items: center; font-size: 14px; min-height: 46px; }
.switch input { width: 22px; height: 22px; accent-color: var(--ink); flex: none; }

/* ---------- Zusammenfassung ---------- */
.summary {
  display: flex; flex-direction: column; gap: 6px;
  border-top: 2px solid var(--ink); padding-top: 12px;
}
.sum-main { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.sum-saving { font: 800 34px/1 var(--font-price); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.sum-saving small { font: 600 15px/1 var(--font-ui); color: var(--muted); margin-left: 6px; letter-spacing: 0; }
.sum-meta { font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.sum-note { font-size: 14px; background: var(--surface); border-left: 4px solid var(--sticker); padding: 8px 10px; border-radius: 0 8px 8px 0; }
.sum-empty { font-size: 15px; color: var(--muted); margin: 0; }
.linkbtn { border: 0; background: none; padding: 0; color: var(--ink); text-decoration: underline; text-underline-offset: 3px; font-size: inherit; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; background: var(--paper); border-radius: 12px; padding: 4px; }
.tabs button {
  flex: 1; border: 0; border-radius: 9px; padding: 9px 8px; background: transparent; font-weight: 650; font-size: 15px; color: var(--muted);
}
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgb(0 0 0 / 0.12); }
.count { font-variant-numeric: tabular-nums; font-weight: 500; color: var(--muted); }

/* ---------- Liste: Etiketten ---------- */
.items { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.item { position: relative; }
.tag {
  position: relative;
  background: var(--paper);
  border: 5px solid var(--bezel);
  border-radius: var(--r-tag);
  padding: 8px 10px 8px 12px;
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 10px;
  min-height: 92px;
}
.item.off .tag { opacity: 0.62; border-color: var(--muted); }
.tag-name {
  grid-column: 1 / -1; padding-right: 40px;
  font-size: 15px; line-height: 1.25; overflow-wrap: anywhere;
  border: 0; background: none; text-align: left; padding-left: 0; padding-top: 0; padding-bottom: 0;
}
.tag-name.empty { color: var(--muted); font-style: italic; }
.tag-foot { grid-column: 1 / -1; display: flex; align-items: flex-end; justify-content: space-between; gap: 8px; }
.tag-sub { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.tag-price {
  border: 0; background: none; padding: 0;
  font: 700 34px/0.9 var(--font-price); font-variant-numeric: tabular-nums; letter-spacing: -0.01em;
}
.qty { display: inline-flex; align-items: center; gap: 2px; border: 1px solid var(--rule); border-radius: 999px; background: var(--surface); }
.qty button { border: 0; background: none; width: 34px; height: 30px; font-size: 18px; }
.qty button:disabled { color: var(--rule); cursor: default; }
.qty span { min-width: 22px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; font-size: 14px; }
.foot-left { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }

.stickers { position: absolute; top: -8px; right: -6px; display: flex; flex-direction: row-reverse; }
.sticker {
  display: grid; place-items: center; text-align: center;
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--sticker); color: var(--sticker-ink);
  font: 800 10px/1 var(--font-price);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.35);
  transform: rotate(-10deg);
  margin-left: -14px;
}
.sticker b { display: block; font-size: 15px; line-height: 1; }
.sticker:nth-child(2) { transform: rotate(7deg); }
.sticker:nth-child(3) { transform: rotate(-3deg); }

.cut {
  display: flex; align-items: center; gap: 10px; font-size: 12px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted);
  padding: 4px 0;
}
.cut::before, .cut::after { content: ""; flex: 1; border-top: 2px dashed var(--rule); }

.item.flash .tag { animation: flash 1s ease-out; }
@keyframes flash { 0% { box-shadow: 0 0 0 4px var(--ok-bg); } 100% { box-shadow: 0 0 0 4px transparent; } }

/* Bearbeiten */
.edit { display: grid; grid-template-columns: minmax(0, 1fr) 96px; gap: 8px; }
.edit input {
  width: 100%; min-width: 0; border: 1px solid var(--rule); border-radius: 8px; padding: 9px 10px; background: var(--surface); font-size: 16px;
}
.edit .edit-actions { grid-column: 1 / -1; display: flex; justify-content: space-between; gap: 8px; }
.edit .btn { padding: 8px 14px; font-size: 14px; }

.add {
  display: flex; flex-direction: column; gap: 8px;
  margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--rule);
}
.add-title { font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.add-row { display: grid; grid-template-columns: minmax(0, 1fr) 88px auto; gap: 8px; }
.add input {
  width: 100%; min-width: 0; border: 1px solid var(--rule); border-radius: 10px; padding: 10px 12px; background: var(--surface); font-size: 16px;
}
.add input[name="price"] { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Wer zahlt was ---------- */
.split { display: flex; flex-direction: column; gap: 12px; }
.person { background: var(--surface); border: 1px solid var(--rule); border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.person-head { display: flex; align-items: center; gap: 10px; }
.person-head .sticker { margin: 0; width: 34px; height: 34px; flex: none; }
.person-head input {
  flex: 1; min-width: 0; border: 0; border-bottom: 1px dashed var(--rule); background: transparent; font-size: 17px; font-weight: 700; padding: 4px 0;
}
.person-count { font-size: 13px; color: var(--muted); white-space: nowrap; }
.person ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.person li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; padding: 7px 0; border-top: 1px solid var(--rule); font-size: 15px; }
.person li span:first-child { overflow-wrap: anywhere; }
.money { font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.money s { color: var(--muted); margin-right: 6px; }
.person-foot { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; font-weight: 650; border-top: 2px solid var(--ink); padding-top: 8px; font-variant-numeric: tabular-nums; }
.person.idle { color: var(--muted); }
.rest h3 { margin: 0; font-size: 15px; }
.rest p { margin: 0; font-size: 14px; color: var(--muted); }

.foot { font-size: 12px; color: var(--muted); text-align: center; padding-top: 12px; }

/* ---------- Hinweis unten ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  width: min(528px, calc(100% - 32px));
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--ink); color: var(--bg); border-radius: 12px; padding: 10px 12px 10px 14px;
  box-shadow: 0 6px 24px rgb(0 0 0 / 0.25);
  font-size: 14px; z-index: 10;
}
.toast button { border: 0; background: none; color: var(--sticker); font-weight: 700; padding: 6px 4px; flex: none; }

@media (max-width: 380px) {
  .controls { gap: 6px; }
  .stepper-row { grid-template-columns: 34px 1fr 34px; }
  .more-body { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
