/* ===== Basis ===== */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1a202c;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --primary: #1e3a5f;
  --primary-light: #2d5386;
  --accent: #2563eb;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #b45309;
  --warning-bg: #fef3c7;
  --success-bg: #dcfce7;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --nav-height: 62px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10151c;
    --surface: #1a222d;
    --text: #e8edf3;
    --text-muted: #8b9bb0;
    --border: #2a3543;
    --primary: #3b6ea5;
    --primary-light: #4a82be;
    --warning-bg: #3a2e10;
    --success-bg: #10301c;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
}

h1, h2, h3 { font-weight: 650; }
.muted { color: var(--text-muted); }
.error { color: var(--danger); font-size: 0.9rem; margin-top: 0.75rem; }

/* ===== App-Rahmen ===== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--primary);
  color: #fff;
  padding: calc(env(safe-area-inset-top) + 0.8rem) 1rem 0.8rem;
}
.app-header h1 { font-size: 1.15rem; }

.view {
  padding: 1rem 1rem calc(var(--nav-height) + env(safe-area-inset-bottom) + 1.5rem);
  max-width: 640px;
  margin: 0 auto;
}

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  height: calc(var(--nav-height) + env(safe-area-inset-bottom));
}
.bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 0.68rem;
  -webkit-tap-highlight-color: transparent;
}
.bottom-nav a svg { width: 23px; height: 23px; }
.bottom-nav a.active { color: var(--primary-light); }
.nav-capture .capture-circle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  margin-top: -18px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}
.nav-capture .capture-circle svg { width: 22px; height: 22px; }

/* ===== Login ===== */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 1.5rem;
}
.login-box {
  width: 100%;
  max-width: 340px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem 1.5rem;
  text-align: center;
}
.login-logo { font-size: 2.8rem; margin-bottom: 0.5rem; }
.login-box h1 { margin-bottom: 0.25rem; }
.login-box form { margin-top: 1.5rem; }
.login-box input {
  text-align: center;
  font-size: 1.4rem;
  letter-spacing: 0.4em;
}

/* ===== Karten ===== */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  margin-bottom: 0.9rem;
}
.card.tappable { cursor: pointer; transition: transform 0.06s; }
.card.tappable:active { transform: scale(0.985); }

.card-total { background: var(--primary); color: #fff; }
.card-total .muted { color: rgba(255, 255, 255, 0.75); }
.card-total .progress-track { background: rgba(255, 255, 255, 0.25); }

.card-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
}
.card-title { font-size: 1rem; font-weight: 650; }
.card-amount { font-size: 0.95rem; font-weight: 650; white-space: nowrap; }

.progress-track {
  height: 8px;
  border-radius: 4px;
  background: var(--border);
  margin: 0.6rem 0 0.45rem;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 4px;
  background: var(--accent);
  transition: width 0.3s;
}
.progress-fill.over { background: var(--danger); }

.card-sub {
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
  color: var(--text-muted);
}
.card-total .card-sub { color: rgba(255, 255, 255, 0.75); }
.rest-negative { color: var(--danger); font-weight: 650; }

/* ===== Formulare ===== */
.form-group { margin-bottom: 0.9rem; }
.form-group label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
}
input, select, textarea {
  width: 100%;
  padding: 0.7rem 0.8rem;
  font-size: 1rem;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary-light); }
.form-hint { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.3rem; }

.input-suffix { position: relative; }
.input-suffix input { padding-right: 2.2rem; }
.input-suffix::after {
  content: "€";
  position: absolute;
  right: 0.9rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.2rem;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  text-decoration: none;
}
.btn:active { opacity: 0.85; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-danger { background: transparent; color: var(--danger); border: 1.5px solid var(--danger); }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: default; }

.btn-row { display: flex; gap: 0.6rem; margin-top: 1rem; }
.btn-row .btn { flex: 1; }

/* ===== Erfassen ===== */
.capture-options { display: flex; flex-direction: column; gap: 0.8rem; margin-top: 1rem; }
.capture-btn {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 1.1rem 1rem;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  color: var(--text);
  cursor: pointer;
  box-shadow: var(--shadow);
  text-align: left;
}
.capture-btn:active { transform: scale(0.985); }
.capture-btn .icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
  flex-shrink: 0;
}
.capture-btn .icon svg { width: 24px; height: 24px; }
.capture-btn.secondary .icon { background: var(--border); color: var(--text-muted); }
.capture-btn small { display: block; font-weight: 400; color: var(--text-muted); font-size: 0.8rem; }

.receipt-preview {
  width: 100%;
  max-height: 240px;
  object-fit: contain;
  border-radius: 10px;
  background: var(--border);
  margin-bottom: 1rem;
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 99px;
  font-size: 0.72rem;
  font-weight: 650;
  vertical-align: middle;
}
.badge-ok { background: var(--success-bg); color: var(--success); }
.badge-warn { background: var(--warning-bg); color: var(--warning); }

.suggestion-reason { font-size: 0.78rem; color: var(--text-muted); margin-top: 0.3rem; }

/* ===== Fortschritt/Laden ===== */
.loading { display: flex; justify-content: center; padding: 3rem 0; }
.spinner {
  width: 34px;
  height: 34px;
  border: 3.5px solid var(--border);
  border-top-color: var(--primary-light);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.upload-status { text-align: center; padding: 2.5rem 1rem; }
.upload-status .spinner { margin: 0 auto 1rem; }
.upload-bar {
  height: 8px;
  border-radius: 4px;
  background: var(--border);
  overflow: hidden;
  margin: 1rem 0 0.5rem;
}
.upload-bar-fill { height: 100%; background: var(--accent); border-radius: 4px; transition: width 0.15s; }

/* ===== Listen ===== */
.receipt-item {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.receipt-item:last-child { border-bottom: none; }
.receipt-thumb {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--border);
  flex-shrink: 0;
}
.receipt-thumb.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}
.receipt-thumb.placeholder svg { width: 22px; height: 22px; }
.receipt-info { flex: 1; min-width: 0; }
.receipt-vendor {
  font-weight: 600;
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.receipt-date { font-size: 0.78rem; color: var(--text-muted); }
.receipt-amount { font-weight: 650; font-size: 0.95rem; white-space: nowrap; }
.receipt-amount.negative { color: var(--success); }

.empty-state { text-align: center; padding: 2.5rem 1rem; color: var(--text-muted); }
.empty-state .big { font-size: 2.5rem; margin-bottom: 0.6rem; }

/* ===== Budget-Verwaltung ===== */
.color-palette { display: flex; gap: 0.55rem; flex-wrap: wrap; }
.color-swatch {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  padding: 0;
}
.color-swatch.selected { border-color: var(--text); }

.budget-list-item {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}
.budget-color-dot { width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0; }
.budget-list-info { flex: 1; min-width: 0; }
.budget-keywords {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ===== Detail / Overlay ===== */
.photo-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.photo-overlay img { max-width: 100%; max-height: 100%; object-fit: contain; }
.photo-overlay .close {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 0.8rem);
  right: 1rem;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  font-size: 1.3rem;
  cursor: pointer;
}

details.ocr-details { margin-top: 1rem; }
details.ocr-details summary { font-size: 0.85rem; color: var(--text-muted); cursor: pointer; }
details.ocr-details pre {
  margin-top: 0.5rem;
  padding: 0.7rem;
  background: var(--bg);
  border-radius: 8px;
  font-size: 0.72rem;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 300px;
  overflow-y: auto;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: calc(var(--nav-height) + env(safe-area-inset-bottom) + 1rem);
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 0.6rem 1.2rem;
  border-radius: 99px;
  font-size: 0.88rem;
  font-weight: 600;
  z-index: 200;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  white-space: nowrap;
}

/* ===== Einstellungen ===== */
.settings-list { display: flex; flex-direction: column; gap: 0.8rem; }
.section-title { font-size: 0.85rem; color: var(--text-muted); margin: 1.2rem 0 0.5rem; font-weight: 600; }
