:root {
  color-scheme: light dark;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef1f4;
  --text: #14202b;
  --muted: #5a6b7b;
  --border: #d9e0e7;
  --accent: #0f766e;
  --accent-text: #ffffff;
  --accent-soft: #d6f1ed;
  --ok: #166534;
  --ok-bg: #e5f6ea;
  --ok-border: #9fd8b0;
  --bad: #b42318;
  --bad-bg: #fdecea;
  --bad-border: #f2b0a9;
  --warn: #9a5b00;
  --warn-bg: #fff3dc;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 4px 16px rgb(0 0 0 / 6%);
  --radius: 14px;
  --tap: 48px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1418;
    --surface: #182128;
    --surface-2: #212c35;
    --text: #e7eef3;
    --muted: #9aabb9;
    --border: #2d3a45;
    --accent: #2cc5b2;
    --accent-text: #04201c;
    --accent-soft: #123a36;
    --ok: #6ee39a;
    --ok-bg: #11291b;
    --ok-border: #24573a;
    --bad: #ff8f86;
    --bad-bg: #351614;
    --bad-border: #6d2a25;
    --warn: #ffc65c;
    --warn-bg: #33270f;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%);
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}

h1, h2 { line-height: 1.2; margin: 0 0 12px; }
h2 { font-size: 1.15rem; }
p { margin: 0 0 8px; }
a { color: var(--accent); }
code { font-family: var(--mono); font-size: 0.9em; background: var(--surface-2); padding: 1px 4px; border-radius: 4px; }

.mono { font-family: var(--mono); letter-spacing: 0.02em; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.strong { font-weight: 650; }
.hint { color: var(--muted); font-size: 0.875rem; margin: 6px 0 0; }
[hidden] { display: none !important; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.i { width: 1.35em; height: 1.35em; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon { display: inline-flex; }
.i .fill { fill: currentColor; stroke: none; }

/* ---------------------------------------------------------------- Kopf & Navigation */

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: center; gap: 8px; font-size: 1.15rem; margin: 0; }
.net {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 0.8rem; font-weight: 600; color: var(--warn); background: var(--warn-bg);
  padding: 4px 10px; border-radius: 999px;
}

main { max-width: 640px; margin: 0 auto; padding: 4px 16px 24px; }

.tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 6;
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 60px; border: 0; background: none; color: var(--muted); font: inherit; font-size: 0.8rem; cursor: pointer;
}
.tabbar button .i { width: 26px; height: 26px; }
.tabbar button[aria-current="page"] { color: var(--accent); font-weight: 650; }
.badge {
  position: absolute; top: 6px; left: calc(50% + 8px);
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
  background: var(--accent); color: var(--accent-text); font-size: 0.72rem; font-weight: 700; line-height: 20px; text-align: center;
}

/* ---------------------------------------------------------------- Bedienelemente */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 10px 16px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--bad); border-color: var(--bad-border); }
.btn.big { min-height: 56px; font-size: 1.05rem; }
.btn.small { min-height: 44px; padding: 6px 12px; font-size: 0.9rem; }
.btn.icon-only { min-width: var(--tap); padding: 0; font-size: 1.2rem; }

input, textarea, select {
  width: 100%; min-height: var(--tap); padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); color: var(--text); font: inherit;
}
textarea { min-height: 120px; resize: vertical; }
input:focus-visible, textarea:focus-visible, .btn:focus-visible, .tabbar button:focus-visible, .item:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px;
}
input[type="checkbox"], input[type="radio"] { width: 22px; height: 22px; min-height: 0; accent-color: var(--accent); }

.label { display: block; font-weight: 600; margin-bottom: 6px; }
.field { display: block; border: 0; padding: 0; margin: 0 0 14px; min-width: 0; }
.check-label { display: flex; align-items: center; gap: 10px; min-height: var(--tap); cursor: pointer; }
.form-error { color: var(--bad); font-weight: 600; margin: 0; }
.form-error:empty { display: none; }

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 10px 0; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px 0; }
.actions > .btn { flex: 1 1 200px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 8px 0; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin: 0 0 16px; box-shadow: var(--shadow);
}
.card > .btn { margin-top: 10px; }

/* ---------------------------------------------------------------- Prüfen */

.check { margin: 8px 0 16px; }
.check-row { display: flex; gap: 8px; }
.check-row input { flex: 1; min-height: 56px; font-size: 1.15rem; }
.check-row .btn { min-height: 56px; }
.view.drop { outline: 3px dashed var(--accent); outline-offset: 6px; border-radius: var(--radius); }

.result {
  display: flex; gap: 14px; align-items: flex-start;
  padding: 16px; margin: 0 0 4px; border-radius: var(--radius);
  background: var(--surface); border: 2px solid var(--border);
}
.result .icon .i { width: 40px; height: 40px; stroke-width: 2.2; }
.result-title { font-size: 1.3rem; font-weight: 750; margin: 2px 0 4px; }
.result-text { margin: 0 0 2px; color: var(--muted); overflow-wrap: anywhere; }
.result.ok { background: var(--ok-bg); border-color: var(--ok-border); }
.result.ok .icon, .result.ok .result-title { color: var(--ok); }
.result.bad { background: var(--bad-bg); border-color: var(--bad-border); }
.result.bad .icon, .result.bad .result-title { color: var(--bad); }

.note {
  display: flex; align-items: center; gap: 8px;
  color: var(--warn); background: var(--warn-bg); border-radius: 10px; padding: 8px 12px; font-weight: 600; font-size: 0.9rem;
}

.form { margin-top: 12px; }
.form details { margin: 4px 0 14px; }
.form summary { cursor: pointer; min-height: var(--tap); display: flex; align-items: center; font-weight: 600; color: var(--accent); }
.preview { display: block; max-width: 100%; max-height: 260px; margin: 0 auto 14px; border-radius: 10px; border: 1px solid var(--border); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.chip span {
  display: inline-flex; align-items: center; min-height: var(--tap); padding: 0 16px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface); font-weight: 650;
}
.chip input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.chip input:focus-visible + span { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; }
.chip-input { width: 7.5em; border-radius: 999px; }

/* ---------------------------------------------------------------- Liste */

.segmented {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; margin: 8px 0 12px;
  background: var(--surface-2); border-radius: 12px;
}
.segmented button {
  min-height: 44px; border: 0; border-radius: 9px; background: none; color: var(--muted);
  font: inherit; font-weight: 650; cursor: pointer;
}
.segmented button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.count { display: inline-block; min-width: 1.6em; padding: 0 6px; margin-left: 4px; border-radius: 999px; background: var(--surface-2); font-size: 0.8rem; }

.list-tools { display: grid; gap: 6px; }
.list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 10px; }
.list .empty { color: var(--muted); text-align: center; padding: 28px 12px; }

.item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  min-height: 72px; padding: 10px 12px; text-align: left;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius);
  font: inherit; cursor: pointer; box-shadow: var(--shadow);
}
.item.soon { border-left: 5px solid var(--warn); }
.item.urgent { border-left: 5px solid var(--bad); }
.thumb {
  flex: none; width: 56px; height: 70px; border-radius: 8px; object-fit: cover; object-position: top;
  background: #fff; border: 1px solid var(--border);
}
.thumb-code, .thumb-used { display: flex; align-items: center; justify-content: center; color: var(--muted); background: var(--surface-2); }
.thumb-used { color: var(--bad); height: 56px; }
.item-main { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.item-title { font-size: 1.25rem; font-weight: 750; }
.item-sub { color: var(--muted); font-size: 0.9rem; }
.item-num { font-size: 0.85rem; color: var(--muted); overflow-wrap: anywhere; }
.item-num.strong { color: var(--text); font-size: 1rem; }
.item-days {
  flex: none; display: inline-flex; align-items: center; gap: 4px;
  font-size: 0.8rem; font-weight: 700; padding: 4px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted);
}
.item-days .i { width: 16px; height: 16px; }
.item-days.soon { background: var(--warn-bg); color: var(--warn); }
.item-days.urgent { background: var(--bad-bg); color: var(--bad); }

/* ---------------------------------------------------------------- Mehrere prüfen */

.table-wrap { overflow-x: auto; margin-top: 8px; }
.table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.table th, .table td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { color: var(--muted); font-weight: 600; font-size: 0.85rem; }
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.badge-status { display: inline-flex; align-items: center; gap: 4px; font-weight: 650; white-space: nowrap; }
.badge-status .i { width: 18px; height: 18px; }
.badge-status.ok { color: var(--ok); }
.badge-status.bad { color: var(--bad); }

/* ---------------------------------------------------------------- Dialoge */

dialog {
  width: min(640px, calc(100vw - 16px)); max-height: calc(100dvh - 16px);
  padding: 16px; border: 1px solid var(--border); border-radius: 18px;
  background: var(--surface); color: var(--text); overflow: auto;
}
dialog::backdrop { background: rgb(0 0 0 / 55%); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.sheet-head h2 { margin: 0; font-size: 1.3rem; }

.coupon-visual { background: #fff; border-radius: 12px; padding: 8px; border: 1px solid var(--border); }
.coupon-img { display: block; width: 100%; height: auto; border-radius: 6px; }
.barcode-box { padding: 12px 4px; color: #000; }
.barcode { display: block; width: 100%; height: 120px; }
.barcode-num { text-align: center; font-size: 1.15rem; margin-top: 8px; }

.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 12px 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }

.scan { padding: 12px; }
.scan-video { position: relative; background: #000; border-radius: 12px; overflow: hidden; aspect-ratio: 3 / 4; max-height: 65dvh; width: 100%; }
.scan-video video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-frame {
  position: absolute; left: 5%; right: 5%; top: 25%; bottom: 25%;
  border: 3px solid rgb(255 255 255 / 90%); border-radius: 12px; box-shadow: 0 0 0 100vmax rgb(0 0 0 / 35%);
}
.scan-status { text-align: center; margin: 10px 0 0; font-weight: 600; }

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

.toast {
  position: fixed; z-index: 20; left: 50%; bottom: calc(76px + env(safe-area-inset-bottom));
  transform: translateX(-50%); width: min(600px, calc(100vw - 24px));
  display: flex; align-items: center; justify-content: space-between; gap: 12px; overflow: hidden;
  padding: 10px 12px 12px 16px; border-radius: 14px;
  background: #1f2a33; color: #fff; box-shadow: 0 8px 30px rgb(0 0 0 / 30%); font-weight: 600;
}
.toast.error { background: #8d1d14; }
.toast .btn { background: transparent; color: #7ff0df; border-color: rgb(255 255 255 / 30%); flex: none; }
.toast-bar { position: absolute; left: 0; bottom: 0; height: 3px; width: 100%; background: #7ff0df; transform-origin: left; transform: scaleX(0); }
.toast.with-undo.run .toast-bar { animation: shrink 10s linear forwards; }
@keyframes shrink { from { transform: scaleX(1); } to { transform: scaleX(0); } }

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

.login-page { padding-bottom: 0; }
.login {
  max-width: 400px; min-height: 100dvh; margin: 0 auto; padding: 24px 16px;
  display: flex; flex-direction: column; justify-content: center; align-items: stretch; text-align: center;
}
.login img { align-self: center; margin-bottom: 8px; }
.login .form { text-align: left; }
.login .btn { width: 100%; }

@media (min-width: 720px) {
  .tabbar { left: 50%; right: auto; transform: translateX(-50%); width: 640px; border: 1px solid var(--border); border-bottom: 0; border-radius: 16px 16px 0 0; }
}

@media (prefers-reduced-motion: reduce) {
  .toast.with-undo.run .toast-bar { animation: none; }
}
