:root {
  --bg: #F3F0E8;
  --surface: #FFFFFF;
  --surface-2: #FAF8F2;
  --ink: #1B1B1F;
  --muted: #6E6B64;
  --line: #E2DDD0;
  --accent: #E4572E;
  --accent-ink: #FFFFFF;
  --ok: #1E9E6A;
  --warn: #C98A00;
  --danger: #C8321F;
  --radius: 14px;
  --nav-h: 64px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141417;
    --surface: #1F1F24;
    --surface-2: #26262C;
    --ink: #F2F0EA;
    --muted: #A09C93;
    --line: #34343B;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif; overscroll-behavior-y: none; }
body { min-height: 100vh; }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 26px; margin: 0 0 4px; letter-spacing: -0.02em; }
h2 { font-size: 18px; margin: 22px 0 10px; }
h3 { font-size: 15px; margin: 14px 0 6px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
p { margin: 0 0 10px; }
a { color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.row { display: flex; gap: 10px; align-items: center; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.view { padding: calc(var(--sat) + 16px) 16px calc(var(--nav-h) + var(--sab) + 24px); max-width: 640px; margin: 0 auto; }
.view.fullscreen { padding: 0; max-width: none; }

/* Navigation */
.nav { position: fixed; left: 0; right: 0; bottom: 0; height: calc(var(--nav-h) + var(--sab)); padding-bottom: var(--sab); background: var(--surface); border-top: 1px solid var(--line); display: flex; justify-content: space-around; align-items: stretch; z-index: 20; }
.nav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; text-decoration: none; font-size: 11px; color: var(--muted); }
.nav a.active { color: var(--ink); font-weight: 600; }
.nav .ico { font-size: 20px; line-height: 1; }
.nav .scan-btn { width: 54px; height: 54px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: flex; align-items: center; justify-content: center; font-size: 32px; margin-top: -22px; box-shadow: 0 6px 16px rgba(228, 87, 46, 0.35); }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 10px 18px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-weight: 600; cursor: pointer; text-decoration: none; }
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.dark { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.block { width: 100%; }
.btn.big { min-height: 60px; font-size: 18px; }
.btn.sm { min-height: 36px; padding: 6px 12px; font-size: 14px; border-radius: 10px; }
.btn[disabled] { opacity: 0.5; pointer-events: none; }
.btn-row { display: flex; gap: 10px; margin-top: 14px; }
.btn-row .btn { flex: 1; }
.actionbar { position: fixed; left: 0; right: 0; bottom: 0; padding: 12px 16px calc(var(--sab) + 12px); background: linear-gradient(to top, var(--bg) 70%, transparent); z-index: 15; }
.actionbar .inner { max-width: 640px; margin: 0 auto; display: flex; gap: 10px; }
.actionbar .btn { flex: 1; }
.has-actionbar { padding-bottom: calc(var(--sab) + 100px); }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card.tap { cursor: pointer; }
.card.tap:active { background: var(--surface-2); }
.card h2 { margin-top: 0; }
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat .v { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; }
.stat .l { font-size: 13px; color: var(--muted); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* Lists */
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-bottom: 12px; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); min-height: 60px; text-decoration: none; }
.item:last-child { border-bottom: 0; }
.item.tap { cursor: pointer; }
.item.tap:active { background: var(--surface-2); }
.item .thumb { width: 44px; height: 56px; object-fit: cover; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--line); flex-shrink: 0; }
.item .t { font-weight: 600; }
.item .s { font-size: 13px; color: var(--muted); }
.item .amt { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.item .chev { color: var(--muted); font-size: 20px; }
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); vertical-align: middle; }
.badge.co { color: #111; border: 0; }
.badge.ok { background: rgba(30,158,106,0.15); color: var(--ok); border-color: transparent; }
.badge.warn { background: rgba(201,138,0,0.15); color: var(--warn); border-color: transparent; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }

/* Forms */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; font-weight: 600; }
.input, textarea.input, select.input { width: 100%; min-height: 48px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); outline: none; font-size: 17px; }
.input:focus { border-color: var(--accent); }
textarea.input { min-height: 80px; resize: vertical; }
.input-amount { font-size: 28px; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.inline-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.inline-fields.three { grid-template-columns: 2fr 1fr 1fr; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { padding: 9px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-size: 15px; cursor: pointer; min-height: 40px; display: inline-flex; align-items: center; gap: 6px; }
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip.add { border-style: dashed; color: var(--muted); }
.chip .dot { margin-right: 2px; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile { padding: 16px 14px; border-radius: var(--radius); border: 2px solid var(--line); background: var(--surface); text-align: left; cursor: pointer; min-height: 72px; display: flex; flex-direction: column; justify-content: center; gap: 4px; }
.tile .n { font-weight: 700; font-size: 16px; }
.tile .s { font-size: 13px; color: var(--muted); }
.tile.on { border-color: var(--ink); background: var(--surface-2); }
.tile .bar { height: 5px; border-radius: 3px; margin-bottom: 6px; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--surface); }
.seg button { flex: 1; min-height: 48px; border: 0; background: transparent; font-weight: 600; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--ink); color: var(--bg); }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 12px; cursor: pointer; }
.toggle .lbl { font-weight: 600; }
.toggle .sub { font-size: 13px; color: var(--muted); }
.switch { width: 52px; height: 32px; border-radius: 16px; background: var(--line); position: relative; flex-shrink: 0; transition: background 0.15s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.3); transition: left 0.15s; }
.switch.on { background: var(--ok); }
.switch.on::after { left: 23px; }
.check { display: flex; align-items: center; gap: 12px; }
.check input { width: 24px; height: 24px; accent-color: var(--accent); }
details.more summary { cursor: pointer; color: var(--muted); font-size: 14px; padding: 6px 0; }

/* Steps */
.steps { display: flex; gap: 6px; margin: 4px 0 18px; }
.steps span { flex: 1; height: 4px; border-radius: 2px; background: var(--line); }
.steps span.on { background: var(--accent); }
.topbar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.topbar .back { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); display: flex; align-items: center; justify-content: center; font-size: 20px; cursor: pointer; }
.topbar h1 { font-size: 20px; margin: 0; }
.preview { width: 100%; max-height: 220px; object-fit: contain; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); margin-bottom: 12px; }
.preview.full { max-height: none; }

/* Scanner / Crop */
.crop-wrap { position: fixed; inset: 0; background: #111; z-index: 30; display: flex; flex-direction: column; }
.crop-stage { flex: 1; position: relative; overflow: hidden; touch-action: none; }
.crop-stage canvas { position: absolute; left: 0; top: 0; }
.crop-stage svg { position: absolute; left: 0; top: 0; }
.crop-bar { padding: 12px 16px calc(var(--sab) + 12px); display: flex; gap: 10px; background: #111; }
.crop-bar .btn { flex: 1; background: #2A2A2E; border-color: #2A2A2E; color: #fff; }
.crop-bar .btn.primary { background: var(--accent); border-color: var(--accent); }
.crop-hint { position: absolute; top: calc(var(--sat) + 12px); left: 0; right: 0; text-align: center; color: #fff; font-size: 14px; text-shadow: 0 1px 3px #000; pointer-events: none; }
.handle { fill: rgba(228,87,46,0.9); stroke: #fff; stroke-width: 2; }
.handle-hit { fill: transparent; }
.crop-poly { fill: rgba(228,87,46,0.12); stroke: var(--accent); stroke-width: 2; }

/* Signature */
.sig-wrap { position: relative; }
.sig-pad { width: 100%; height: 160px; border: 1px dashed var(--line); border-radius: 12px; background: #fff; touch-action: none; display: block; }
.sig-img { width: 100%; height: 120px; object-fit: contain; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.sig-clear { position: absolute; right: 8px; top: 8px; }

/* Overlay / Toast / Modal */
.overlay { position: fixed; inset: 0; background: rgba(20,20,24,0.75); color: #fff; z-index: 50; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; font-weight: 600; }
.spinner { width: 36px; height: 36px; border: 4px solid rgba(255,255,255,0.25); border-top-color: #fff; border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; left: 16px; right: 16px; bottom: calc(var(--nav-h) + var(--sab) + 16px); background: var(--ink); color: var(--bg); padding: 12px 16px; border-radius: 12px; z-index: 60; text-align: center; font-weight: 600; box-shadow: 0 8px 24px rgba(0,0,0,0.25); }
.toast.err { background: var(--danger); color: #fff; }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 55; display: flex; align-items: flex-end; justify-content: center; }
.modal .sheet { background: var(--bg); width: 100%; max-width: 640px; border-radius: 20px 20px 0 0; padding: 18px 16px calc(var(--sab) + 18px); max-height: 90vh; overflow: auto; }
.modal h2 { margin-top: 0; }

/* Login */
.login { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; padding: 24px; max-width: 420px; margin: 0 auto; }
.login .logo { font-size: 44px; margin-bottom: 8px; }

.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.total-line { display: flex; justify-content: space-between; padding: 12px 14px; font-weight: 700; font-size: 17px; }
.sum-table { width: 100%; border-collapse: collapse; }
.sum-table td { padding: 8px 4px; border-bottom: 1px solid var(--line); }
.sum-table td:last-child { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.sum-table tr:last-child td { border-bottom: 0; }
.swatch { width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }
.swatch.on { border-color: var(--ink); }
.filters { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 8px; -webkit-overflow-scrolling: touch; }
.filters .chip { flex-shrink: 0; }
.hero-scan { display: flex; align-items: center; gap: 14px; padding: 18px; border-radius: 18px; background: var(--accent); color: #fff; margin-bottom: 14px; cursor: pointer; border: 0; width: 100%; text-align: left; }
.hero-scan .big { font-size: 20px; font-weight: 700; }
.hero-scan .cam { font-size: 34px; }

/* hidden-Attribut hat immer Vorrang */
[hidden] { display: none !important; }

/* Autovervollständigung */
.ac-wrap { position: relative; }
.ac-list { position: absolute; left: 0; right: 0; top: calc(100% + 4px); background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,0.18); z-index: 10; overflow: hidden; max-height: 280px; overflow-y: auto; }
.ac-list button { display: block; width: 100%; text-align: left; padding: 12px 14px; border: 0; border-bottom: 1px solid var(--line); background: transparent; font-size: 16px; cursor: pointer; }
.ac-list button:last-child { border-bottom: 0; }
.ac-list button:active { background: var(--surface-2); }
.ac-list .ac-new { color: var(--accent); font-weight: 600; }
.chip.on button { border: 0; background: transparent; color: inherit; font-size: 14px; padding: 0 0 0 4px; cursor: pointer; opacity: 0.8; }
.code-input { font-size: 28px; letter-spacing: 0.25em; text-align: center; font-variant-numeric: tabular-nums; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.95em; }
