/* Steuer-Belege — eigene Palette: Graublau #334155 + Aktenordner-Beige */
:root {
  --slate-900: #1e293b;
  --slate-800: #273449;
  --slate-700: #334155;
  --slate-600: #475569;
  --slate-500: #64748b;
  --slate-400: #94a3b8;
  --slate-300: #cbd5e1;

  --beige-50: #faf6ee;
  --beige-100: #f4ecdc;
  --beige-200: #e9dcc2;
  --beige-300: #dcc9a3;
  --beige-accent: #c8a96a;

  --bg: var(--beige-50);
  --bg-alt: var(--beige-100);
  --surface: #ffffff;
  --surface-2: #fbf8f1;
  --border: var(--beige-200);
  --text: var(--slate-900);
  --text-soft: var(--slate-600);
  --text-muted: var(--slate-500);
  --primary: var(--slate-700);
  --primary-dark: var(--slate-800);
  --primary-contrast: #ffffff;
  --accent: var(--beige-accent);
  --danger: #b04632;
  --danger-bg: #fbeae6;
  --ok: #3f7d52;
  --shadow: 0 2px 10px rgba(30, 41, 59, 0.10);
  --shadow-lg: 0 12px 40px rgba(30, 41, 59, 0.28);
  --radius: 14px;
  --radius-sm: 9px;
  --focus: 0 0 0 3px rgba(200, 169, 106, 0.55);
  --maxw: 760px;
}

[data-theme="dark"] {
  --bg: #161d27;
  --bg-alt: #1b2430;
  --surface: #212c3a;
  --surface-2: #1a2330;
  --border: #33414f;
  --text: #eef2f7;
  --text-soft: #c2cddb;
  --text-muted: #93a2b5;
  --primary: #4d6584;
  --primary-dark: #3b4f6a;
  --primary-contrast: #ffffff;
  --accent: #d6b878;
  --danger: #e08a76;
  --danger-bg: #3a2520;
  --ok: #6cb585;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 14px 44px rgba(0, 0, 0, 0.55);
  --focus: 0 0 0 3px rgba(214, 184, 120, 0.55);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  background:
    linear-gradient(180deg, var(--bg) 0%, var(--bg-alt) 100%);
  background-attachment: fixed;
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-font-smoothing: antialiased;
  overflow-wrap: anywhere;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--primary);
  color: var(--primary-contrast);
  padding: 10px 14px;
  border-radius: 0 0 var(--radius-sm) 0;
  z-index: 100;
}
.skip-link:focus { left: 0; }

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

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 14px clamp(14px, 4vw, 28px);
  padding-top: calc(14px + env(safe-area-inset-top));
  background: linear-gradient(135deg, var(--slate-700), var(--slate-800));
  color: #fff;
  box-shadow: var(--shadow);
  border-bottom: 3px solid var(--accent);
}
[data-theme="dark"] .app-header {
  background: linear-gradient(135deg, #243245, #1a2532);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px; height: 44px;
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.12);
  color: var(--accent);
  flex: none;
  border: 1px solid rgba(255,255,255,0.14);
}
.brand-text { min-width: 0; }
.brand h1 { font-size: 1.18rem; margin: 0; line-height: 1.15; letter-spacing: 0.2px; }
.brand-sub { margin: 0; font-size: 0.74rem; color: var(--beige-200); opacity: 0.9; }

.header-actions { display: flex; align-items: center; gap: 8px; }

/* Layout */
.container {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: clamp(14px, 4vw, 26px) clamp(12px, 4vw, 24px) 40px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(14px, 3.5vw, 22px);
}
.card-title {
  margin: 0 0 14px;
  font-size: 1.05rem;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-title::before {
  content: "";
  width: 4px; height: 18px;
  border-radius: 3px;
  background: var(--accent);
  display: inline-block;
}

/* Fields */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; min-width: 0; }
.field:last-child { margin-bottom: 0; }
.field-label, label { font-size: 0.82rem; font-weight: 600; color: var(--text-soft); }

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 52px; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus);
}
input::placeholder, textarea::placeholder { color: var(--text-muted); }
select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2364748b' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 34px;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }

/* Foto */
.photo-field { margin-bottom: 16px; }
.photo-row { display: flex; gap: 14px; align-items: flex-start; flex-wrap: wrap; }
.photo-preview {
  width: 96px; height: 96px;
  border-radius: var(--radius-sm);
  border: 2px dashed var(--border);
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex: none;
}
.photo-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-placeholder { font-size: 0.74rem; color: var(--text-muted); text-align: center; padding: 4px; }
.photo-controls { display: flex; flex-direction: column; gap: 8px; min-width: 160px; flex: 1; }
.hint { margin: 0; font-size: 0.74rem; color: var(--text-muted); }

/* Buttons */
.btn {
  font: inherit;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  cursor: pointer;
  transition: background .15s, transform .08s, box-shadow .15s, border-color .15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  line-height: 1.2;
  text-align: center;
}
.btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn:active { transform: translateY(1px); }

.btn-primary { background: var(--primary); color: var(--primary-contrast); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary {
  background: var(--beige-100);
  color: var(--slate-800);
  border-color: var(--beige-200);
}
[data-theme="dark"] .btn-secondary { background: #2c3a4c; color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--beige-200); }
[data-theme="dark"] .btn-secondary:hover { background: #344458; }
.btn-ghost { background: transparent; color: var(--text-soft); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(0.94); }
.btn-icon {
  background: rgba(255,255,255,0.12);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.16);
  width: 40px; height: 40px;
  padding: 0;
  font-size: 1.2rem;
}
.btn-icon:hover { background: rgba(255,255,255,0.22); }
.modal .btn-icon { background: var(--surface-2); color: var(--text-soft); border-color: var(--border); }
.modal .btn-icon:hover { background: var(--bg-alt); }
.file-label { cursor: pointer; }

.form-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.form-actions .btn { flex: 1 1 auto; min-width: 130px; }

/* Filter & Übersicht */
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }

.totals {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin: 4px 0 16px;
}
.total-main {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  padding-bottom: 10px;
  border-bottom: 1px dashed var(--border);
  margin-bottom: 10px;
}
.total-label { font-size: 0.86rem; color: var(--text-soft); font-weight: 600; }
.total-value { font-size: 1.4rem; font-weight: 800; color: var(--text); }
.cat-totals { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 5px; }
.cat-totals li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.86rem;
  color: var(--text-soft);
}
.cat-totals .cat-name { display: flex; align-items: center; gap: 7px; }
.cat-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.cat-totals .cat-sum { font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }

.list-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.count-label { font-size: 0.84rem; color: var(--text-muted); font-weight: 600; }

/* Liste */
.beleg-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.beleg-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  cursor: pointer;
  font: inherit;
  color: var(--text);
  transition: box-shadow .15s, transform .08s, border-color .15s;
}
.beleg-item:hover { box-shadow: var(--shadow); }
.beleg-item:focus-visible { outline: none; box-shadow: var(--focus); }
.beleg-item:active { transform: translateY(1px); }
.beleg-thumb {
  width: 48px; height: 48px;
  border-radius: 8px;
  overflow: hidden;
  flex: none;
  background: var(--bg-alt);
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--border);
}
.beleg-thumb img { width: 100%; height: 100%; object-fit: cover; }
.beleg-thumb .thumb-icon { color: var(--text-muted); font-size: 1.2rem; }
.beleg-main { flex: 1; min-width: 0; }
.beleg-title { font-weight: 700; font-size: 0.95rem; }
.beleg-meta { font-size: 0.78rem; color: var(--text-muted); display: flex; gap: 8px; flex-wrap: wrap; margin-top: 2px; }
.beleg-cat-tag {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 20px;
  color: #fff;
  white-space: nowrap;
}
.beleg-amount {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  flex: none;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 22px 10px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  margin: 4px 0 0;
}

.app-footer { text-align: center; color: var(--text-muted); font-size: 0.76rem; padding: 6px 4px 0; }
.app-footer p { margin: 0; }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, 0.55); backdrop-filter: blur(2px); }
.modal-box {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow: auto;
  animation: pop .16s ease-out;
}
.modal-sm { max-width: 380px; }
@keyframes pop { from { transform: scale(.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-header {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; font-size: 1.05rem; }
.modal-body { padding: 18px; }
.modal-footer {
  display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end;
  padding: 14px 18px;
  border-top: 1px solid var(--border);
}
.modal-footer .btn { flex: 1 1 auto; }

.detail-photo {
  width: 100%;
  max-height: 320px;
  object-fit: contain;
  border-radius: var(--radius-sm);
  background: var(--bg-alt);
  border: 1px solid var(--border);
  margin-bottom: 14px;
  display: block;
}
.detail-no-photo {
  padding: 22px;
  text-align: center;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
  font-size: 0.85rem;
}
.detail-grid { display: flex; flex-direction: column; gap: 10px; }
.detail-row {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.detail-row:last-child { border-bottom: none; }
.detail-key { color: var(--text-muted); font-size: 0.84rem; flex: none; }
.detail-val { font-weight: 600; text-align: right; }
.detail-val.amount { font-size: 1.1rem; font-weight: 800; }
.detail-note { white-space: pre-wrap; text-align: left; font-weight: 400; }

.export-area {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.8rem;
  line-height: 1.45;
  background: var(--surface-2);
}

/* Toasts */
.toast-wrap {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(90vw, 360px);
  pointer-events: none;
}
.toast {
  background: var(--slate-800);
  color: #fff;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  font-size: 0.88rem;
  font-weight: 600;
  border-left: 4px solid var(--accent);
  animation: toastIn .2s ease-out;
}
.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--danger); }
.toast.out { animation: toastOut .25s ease-in forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(12px); } }

/* Responsive */
@media (max-width: 540px) {
  .grid-2, .filters { grid-template-columns: 1fr; gap: 0; }
  .brand h1 { font-size: 1.05rem; }
  .total-value { font-size: 1.25rem; }
  .modal-footer .btn { flex: 1 1 100%; }
}

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