:root {
  --bg: #f3f5f4;
  --surface: #ffffff;
  --surface-2: #e8edeb;
  --text: #14201b;
  --muted: #5b6b64;
  --border: #d3dcd8;
  --accent: #0f6b4f;
  --accent-press: #0b5540;
  --accent-text: #ffffff;
  --accent-soft: #dcefe6;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.06), 0 6px 20px rgb(0 0 0 / 0.06);
  --radius: 16px;
  --gutter: 16px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1412;
    --surface: #17201c;
    --surface-2: #202b26;
    --text: #e8efec;
    --muted: #94a49d;
    --border: #2c3833;
    --accent: #34b386;
    --accent-press: #2a976f;
    --accent-text: #04140d;
    --accent-soft: #163a2d;
    --danger: #ff8a80;
    --danger-soft: #3a1c1a;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.4 var(--font);
  -webkit-tap-highlight-color: transparent;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

body.has-actionbar main { padding-bottom: calc(110px + env(safe-area-inset-bottom)); }

button, input { font: inherit; color: inherit; }
p, small { text-wrap: pretty; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.i {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

/* ---------- Kopfzeile ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 560px;
  margin: 0 auto;
  padding: 10px var(--gutter);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}

.topbar h1 { margin: 0; font-size: 30px; font-weight: 700; letter-spacing: -0.02em; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--shadow);
}

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 4px var(--gutter) 32px;
}

/* Update-Hinweis */
.update-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 12px;
  padding: 12px 12px 12px 16px;
  border-radius: 14px;
  background: var(--accent);
  color: var(--accent-text);
}
.update-banner span { display: grid; }
.update-banner small { font-size: 14px; opacity: 0.85; }
.update-banner .btn.primary { background: var(--accent-text); color: var(--accent); }

.small-btn { min-height: 40px; padding: 0 14px; font-size: 15px; border-radius: 10px; }

.app-info { margin-top: 0; }
.row .app-info-actions { display: flex; align-items: center; gap: 8px; flex: none; }

/* Empfängerzeile */
.target {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin: 0 0 16px;
  padding: 10px 12px;
  border: 0;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 15px;
  text-align: left;
}
.target .i { width: 18px; height: 18px; }
.target span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.target[data-state="error"] { background: var(--danger-soft); color: var(--danger); }
.target[data-state="error"] span { white-space: normal; }

/* ---------- Startansicht ---------- */

.hero { display: grid; gap: 12px; }

.capture {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 14px;
  min-height: 46dvh;
  padding: 32px 16px;
  border: 0;
  border-radius: 24px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 22px;
  font-weight: 650;
  box-shadow: var(--shadow);
  transition: transform 0.12s ease, background 0.12s ease;
}
.capture:active { transform: scale(0.985); background: var(--accent-press); }
.capture .i { width: 64px; height: 64px; stroke-width: 1.6; }

.link-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  border: 0;
  background: none;
  color: var(--accent);
  font-weight: 600;
}
.link-btn.small { min-height: 32px; font-size: 15px; font-weight: 500; }

.hint { margin: 0; color: var(--muted); font-size: 15px; text-align: center; }

/* ---------- Seiten ---------- */

.pages {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 0 0 16px;
  padding: 0;
  list-style: none;
}

.page {
  position: relative;
  aspect-ratio: 3 / 4;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.page-img {
  display: block;
  width: 100%;
  height: 100%;
  padding: 8px 8px 52px;
  border: 0;
  background: var(--surface-2);
}
.page-img img { width: 100%; height: 100%; object-fit: contain; display: block; }

.page-no {
  position: absolute;
  top: 8px;
  left: 8px;
  min-width: 26px;
  height: 26px;
  padding: 0 8px;
  border-radius: 13px;
  background: rgb(0 0 0 / 0.65);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  line-height: 26px;
  text-align: center;
}

.page-tools {
  position: absolute;
  inset: auto 0 0 0;
  display: flex;
  justify-content: space-around;
  padding: 4px;
  background: var(--surface);
}
.page-tools button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--muted);
}
.page-tools button:active { background: var(--surface-2); }

.page.add { background: transparent; box-shadow: none; }
.page.add button {
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 8px;
  width: 100%;
  height: 100%;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: none;
  color: var(--accent);
  font-size: 15px;
  font-weight: 600;
}
.page.add .i { width: 32px; height: 32px; }

/* Zahlart */
.payment {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 0 0 12px;
  padding: 0;
  border: 0;
}
.payment legend { float: left; grid-column: 1 / -1; padding: 0 0 2px; font-weight: 600; font-size: 15px; }
.payment label { position: relative; }
.payment input { position: absolute; inset: 0; opacity: 0; margin: 0; }
.payment label > span {
  display: grid;
  justify-items: center;
  gap: 2px;
  padding: 14px 8px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: center;
  transition: border-color 0.12s ease, background 0.12s ease;
}
.payment strong { font-size: 19px; }
.payment small { color: var(--muted); font-size: 14px; }
.payment input:checked + span { border-color: var(--accent); background: var(--accent-soft); }
.payment input:checked + span small { color: var(--accent); }
.payment input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.payment-hint {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 14px;
  color: var(--muted);
}
.payment-hint[data-state="found"] { color: var(--accent); font-weight: 600; }
.payment-hint[data-state="conflict"] { color: var(--danger); font-weight: 600; }
.mini-spinner {
  display: none;
  width: 14px;
  height: 14px;
  border: 2px solid var(--accent-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex: none;
}
.payment-hint[data-state="pending"] .mini-spinner { display: block; }
.payment.missing label > span { border-color: var(--danger); animation: shake 0.3s ease; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

/* Schalter & Felder */
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  margin-bottom: 12px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.row span { display: grid; }
.row small { color: var(--muted); font-size: 14px; }

.switch input {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  flex: none;
  width: 51px;
  height: 31px;
  margin: 0;
  border-radius: 16px;
  background: var(--border);
  transition: background 0.15s ease;
}
.switch input::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.25);
  transition: transform 0.15s ease;
}
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(20px); }

.field { display: grid; gap: 6px; margin-bottom: 12px; }
.field > span { font-weight: 600; font-size: 15px; }
.field small { color: var(--muted); font-weight: 400; }
.field input {
  width: 100%;
  min-height: 50px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  font-size: 17px;
}
.field input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }

/* ---------- Aktionsleiste ---------- */

.actionbar {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 6;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  max-width: 560px;
  margin: 0 auto;
  padding: 12px var(--gutter) calc(12px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 54px;
  padding: 0 20px;
  border: 0;
  border-radius: 14px;
  font-weight: 650;
  transition: transform 0.12s ease, background 0.12s ease;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.primary:active { background: var(--accent-press); }
.btn.ghost { background: var(--surface-2); color: var(--text); }
.btn.wide { width: 100%; }

/* ---------- Erfolg ---------- */

.done {
  display: grid;
  justify-items: center;
  gap: 4px;
  padding: 32px 16px 24px;
  border-radius: 24px;
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
}
.done h2 { margin: 12px 0 0; font-size: 24px; }
.done p { margin: 0 0 20px; color: var(--muted); overflow-wrap: anywhere; }
.done-badge {
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  animation: pop 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.3);
}
.done-badge .i { width: 40px; height: 40px; stroke-width: 2.6; }
@keyframes pop { from { transform: scale(0.4); opacity: 0; } }

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

.history { margin-top: 28px; }
.history-head { display: flex; align-items: center; justify-content: space-between; }
.history h2 { margin: 0; font-size: 15px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.history ul {
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.history li { display: flex; align-items: center; gap: 12px; padding: 12px 16px; }
.history li + li { border-top: 1px solid var(--border); }
.h-check { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); flex: none; }
.h-check .i { width: 16px; height: 16px; stroke-width: 3; }
.h-main { display: grid; min-width: 0; }
.h-main strong { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.h-main small { color: var(--muted); font-size: 14px; }

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

dialog { color: var(--text); }
dialog::backdrop { background: rgb(0 0 0 / 0.45); }

.sheet {
  width: 100%;
  max-width: 560px;
  margin: auto auto 0;
  padding: 24px var(--gutter) calc(20px + env(safe-area-inset-bottom));
  border: 0;
  border-radius: 24px 24px 0 0;
  background: var(--bg);
}
.sheet[open] { animation: slide-up 0.22s ease-out; }
@keyframes slide-up { from { transform: translateY(40px); opacity: 0; } }
.sheet h2 { margin: 0 0 16px; font-size: 22px; }
.sheet p { margin: 0 0 12px; }
.sheet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 20px; }

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin: 0 0 16px;
  padding: 4px;
  border: 0;
  border-radius: 12px;
  background: var(--surface-2);
}
.segmented legend { padding: 0 0 6px; font-weight: 600; font-size: 15px; float: left; grid-column: 1 / -1; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; }
.segmented span {
  display: grid;
  place-items: center;
  min-height: 40px;
  padding: 0 12px;
  border-radius: 9px;
  font-size: 15px;
  font-weight: 600;
  color: var(--muted);
}
.segmented input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); }

.muted { color: var(--muted); }
.small { font-size: 14px; }
.status { min-height: 1.4em; font-size: 15px; font-weight: 600; color: var(--muted); }
.status.error { color: var(--danger); }

.preview {
  max-width: 100vw;
  max-height: 100dvh;
  width: 100vw;
  height: 100dvh;
  margin: 0;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
  border: 0;
  background: #000;
}
.preview img { width: 100%; height: 100%; object-fit: contain; }

/* ---------- Zuschneiden ---------- */

.cropper {
  width: 100vw;
  height: 100dvh;
  max-width: 100vw;
  max-height: 100dvh;
  margin: 0;
  padding: calc(12px + env(safe-area-inset-top)) var(--gutter) calc(12px + env(safe-area-inset-bottom));
  border: 0;
  background: #0b0f0d;
  color: #fff;
}
.cropper[open] { display: flex; flex-direction: column; gap: 8px; }
.crop-title { margin: 0; text-align: center; font-size: 15px; color: #c9d4cf; }
.crop-stage { flex: 1; min-height: 0; display: grid; place-items: center; }
.crop-area { position: relative; touch-action: none; }
.crop-area img { display: block; width: 100%; height: 100%; user-select: none; -webkit-user-select: none; pointer-events: none; }
.crop-overlay { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
#crop-shade { fill: rgb(0 0 0 / 0.55); }
#crop-line { fill: none; stroke: #34b386; stroke-width: 2.5; vector-effect: non-scaling-stroke; }
.crop-handle {
  position: absolute;
  width: 44px;
  height: 44px;
  margin: -22px 0 0 -22px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  touch-action: none;
}
.crop-handle::after {
  content: "";
  position: absolute;
  inset: 11px;
  border: 3px solid #34b386;
  border-radius: 50%;
  background: rgb(255 255 255 / 0.9);
  box-shadow: 0 1px 6px rgb(0 0 0 / 0.5);
  transition: transform 0.1s ease;
}
.crop-handle.active::after { transform: scale(1.35); }
.crop-tools { display: flex; justify-content: center; gap: 24px; }
.crop-tools .link-btn { color: #7fd8b5; }
.crop-bar { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.cropper .btn.ghost { background: #26302c; color: #fff; }

/* ---------- Ladeanzeige & Hinweise ---------- */

.busy {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 16px;
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.busy p { margin: 0; font-weight: 600; }
.spinner {
  width: 44px;
  height: 44px;
  border: 4px solid var(--accent-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  z-index: 30;
  width: max-content;
  max-width: calc(100vw - 2 * var(--gutter));
  padding: 12px 16px;
  border-radius: 14px;
  background: #1d2622;
  color: #fff;
  font-size: 15px;
  box-shadow: 0 8px 30px rgb(0 0 0 / 0.25);
  opacity: 0;
  transform: translate(-50%, 12px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

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