:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --border: #334155;
  --text: #f8fafc;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-dim: #0ea5e9;
  --danger: #f87171;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100dvh;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding: calc(12px + var(--safe-top)) 16px calc(16px + var(--safe-bottom));
  line-height: 1.45;
}

.app {
  max-width: 520px;
  margin: 0 auto;
}

.header {
  margin-bottom: 1.25rem;
}

.header h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.tagline {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.toolbar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 1rem;
}

.storage-panel {
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  margin-bottom: 4px;
}

.storage-info {
  margin: 0 0 10px;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.45;
}

.storage-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn-outline {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}

.btn-outline:active {
  background: rgba(255, 255, 255, 0.06);
}

.capture-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  width: 100%;
  cursor: pointer;
}

.btn-secondary:active {
  transform: scale(0.98);
}

label.btn-secondary {
  margin: 0;
  text-align: center;
}

.sort-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.sort-row label {
  color: var(--muted);
  font-size: 0.85rem;
}

.sort-row select {
  flex: 1;
  min-width: 200px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 14px 20px;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.btn-primary {
  background: linear-gradient(145deg, var(--accent), var(--accent-dim));
  color: #0f172a;
  width: 100%;
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  padding: 8px 12px;
  font-size: 0.85rem;
}

.btn-danger {
  background: rgba(248, 113, 113, 0.15);
  color: var(--danger);
  padding: 8px 12px;
  font-size: 0.85rem;
}

.ocr-status {
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 1rem;
}

.storage-banner {
  padding: 12px 14px;
  border-radius: var(--radius);
  background: rgba(248, 113, 113, 0.18);
  border: 1px solid var(--danger);
  color: #fecaca;
  font-size: 0.9rem;
  margin-bottom: 1rem;
  line-height: 1.4;
}

.ocr-status.hidden,
.hidden {
  display: none !important;
}

.bon-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Wischen zum Löschen */
.bon-swipe {
  position: relative;
  list-style: none;
  margin: 0;
  border-radius: var(--radius);
  overflow: hidden;
  touch-action: pan-y;
}

.bon-swipe-delete {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 80px;
  z-index: 0;
  border: none;
  margin: 0;
  padding: 8px;
  background: #b91c1c;
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}

.bon-swipe-panel {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 0;
  min-height: 100px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  will-change: transform;
}

.bon-thumb-wrap {
  background: #0c1222;
  display: flex;
  align-items: center;
  justify-content: center;
}

.bon-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  min-height: 100px;
  cursor: pointer;
}

.bon-body {
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.bon-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: baseline;
}

.bon-date {
  font-weight: 600;
  font-size: 0.95rem;
}

.bon-amount {
  color: var(--accent);
  font-weight: 700;
  font-size: 1rem;
}

.bon-merchant {
  color: var(--muted);
  font-size: 0.85rem;
  line-clamp: 2;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.bon-pending {
  font-style: italic;
  color: var(--accent);
}

.bon-actions {
  display: flex;
  gap: 8px;
  margin-top: auto;
  flex-wrap: wrap;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 2rem 1rem;
  font-size: 0.95rem;
}

.footer {
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.footer small {
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.4;
}

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--safe-top) 12px var(--safe-bottom);
}

.lightbox img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
}

/* Bon bearbeiten */
.edit-modal {
  position: fixed;
  inset: 0;
  z-index: 180;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}

.edit-modal.hidden {
  display: none !important;
}

.edit-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}

.edit-modal-sheet {
  position: relative;
  width: 100%;
  max-width: 520px;
  max-height: 85dvh;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  padding: 20px 18px calc(20px + var(--safe-bottom));
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.35);
}

.edit-modal-title {
  margin: 0 0 8px;
  font-size: 1.2rem;
}

.edit-modal-hint {
  margin: 0 0 16px;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.35;
}

.edit-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
  font-size: 0.85rem;
  color: var(--muted);
}

.edit-field input {
  padding: 12px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

.edit-modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 20px;
}

.btn-edit-cancel,
.btn-edit-save {
  padding: 14px 16px;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  touch-action: manipulation;
}

.btn-edit-cancel {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.btn-edit-save {
  background: linear-gradient(145deg, var(--accent), var(--accent-dim));
  color: #0f172a;
}

.lightbox-close {
  position: absolute;
  top: calc(12px + var(--safe-top));
  right: 16px;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 1.75rem;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
}

/* Live-Scan (Kamera) */
.scan-modal {
  position: fixed;
  inset: 0;
  z-index: 150;
  background: #020617;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

.scan-top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  flex-shrink: 0;
}

.btn-scan-cancel {
  flex-shrink: 0;
  padding: 10px 14px;
  border-radius: 10px;
  border: none;
  background: rgba(255, 255, 255, 0.12);
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}

.scan-title {
  margin: 0;
  flex: 1;
  text-align: center;
  font-size: 0.9rem;
  color: var(--muted);
  padding-left: 8px;
  padding-right: 8px;
}

.btn-scan-torch {
  flex-shrink: 0;
  min-width: 64px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}

.btn-scan-torch[aria-pressed="true"] {
  background: rgba(250, 204, 21, 0.35);
  border-color: rgba(250, 204, 21, 0.7);
  color: #fef9c3;
}

.scan-viewport {
  position: relative;
  flex: 1;
  min-height: 0;
  margin: 0 12px;
  border-radius: 16px;
  overflow: hidden;
  background: #000;
}

.scan-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* iPhone & Co.: Safari stellt oft keine Web-Taschenlampe bereit — digital aufhellen */
.scan-video.scan-video--boost {
  filter: brightness(1.48) contrast(1.08);
}

.scan-frame {
  position: absolute;
  inset: 8%;
  border: 2px solid rgba(56, 189, 248, 0.85);
  border-radius: 12px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}

.scan-bottom {
  flex-shrink: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px 16px 28px;
}

.scan-shutter {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, 0.9);
  background: transparent;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
  position: relative;
}

.scan-shutter::after {
  content: "";
  position: absolute;
  inset: 8px;
  border-radius: 50%;
  background: #fff;
}

.scan-shutter:active::after {
  transform: scale(0.92);
}
