@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* --- Reset & Base --- */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --primary: #0891B2;
  --primary-light: #22D3EE;
  --primary-dark: #155E75;
  --accent: #10B981;
  --accent-dark: #065F46;
  --bg: #F8FAFC;
  --bg-card: #FFFFFF;
  --bg-hover: #F1F5F9;
  --text: #1E293B;
  --text-muted: #64748B;
  --border: #CBD5E1;
  --border-light: #E2E8F0;
  --danger: #DC2626;
  --danger-light: #FEE2E2;
  --warning: #D97706;
  --warning-light: #FEF3C7;
  --success: #059669;
  --success-light: #D1FAE5;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --transition: 200ms ease;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  max-width: 1040px;
  margin: 0 auto;
  padding: 1.5rem 1rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* --- Header --- */
header {
  margin-bottom: 2rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

h1 {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--primary-dark);
  letter-spacing: -0.02em;
}

h1::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  background: var(--primary);
  border-radius: 2px;
  margin-right: 0.5rem;
  vertical-align: middle;
  box-shadow: none;
}

h2 {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--primary-dark);
  margin-bottom: 0.75rem;
}

/* --- Drop Zone --- */
#drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  text-align: center;
  background: var(--bg-card);
  transition: all var(--transition);
  margin-bottom: 1.5rem;
  cursor: pointer;
}

#drop-zone:hover {
  border-color: var(--primary-light);
  background: var(--bg-hover);
}

#drop-zone.dragover {
  border-color: var(--primary);
  background: var(--bg-hover);
  box-shadow: 0 0 0 4px rgba(8, 145, 178, 0.1);
}

#drop-zone p {
  margin-bottom: 0.5rem;
  color: var(--text-muted);
  font-size: 0.95rem;
}

#drop-zone small {
  color: var(--text-muted);
  opacity: 0.7;
  font-size: 0.8rem;
}

.drop-zone-buttons {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
}

#file-btn, #camera-btn {
  padding: 0.5rem 1.25rem;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  transition: background var(--transition);
}

#file-btn:hover, #camera-btn:hover { background: var(--primary-dark); }

#camera-btn { background: var(--accent); }
#camera-btn:hover { background: var(--accent-dark); }

/* Hide camera button on desktop */
@media (pointer: fine) {
  #camera-btn { display: none; }
}

/* --- Progress --- */
#processing {
  margin-bottom: 1.5rem;
  background: var(--bg-card);
  padding: 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border-light);
}

#progress-bar {
  height: 5px;
  background: var(--border-light);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 0.5rem;
}

#progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--primary-light));
  border-radius: 3px;
  transition: width 0.3s ease;
  width: 0%;
}

#progress-text {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* --- Bulk-Vorschau --- */
#bulk-vorschau {
  margin-bottom: 1.5rem;
}

#bulk-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

#bulk-header h2 { margin-bottom: 0; }

#bulk-actions {
  display: flex;
  gap: 0.5rem;
}

#btn-confirm-all {
  padding: 0.45rem 1rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 500;
  transition: background var(--transition);
}

#btn-confirm-all:hover { background: var(--accent-dark); }

#btn-cancel-all {
  padding: 0.45rem 1rem;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 500;
  transition: all var(--transition);
}

#btn-cancel-all:hover { border-color: var(--danger); color: var(--danger); }

#bulk-cards {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

/* --- Beleg-Karte --- */
.beleg-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  box-shadow: var(--shadow);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.beleg-card:hover {
  border-color: var(--border);
}

.beleg-card.saved {
  border-color: var(--accent);
  background: var(--success-light);
  box-shadow: none;
}

.beleg-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.6rem;
}

.beleg-card-header .filename {
  font-weight: 600;
  font-size: 0.8rem;
  color: var(--primary);
  text-decoration: none;
  cursor: pointer;
  transition: color var(--transition);
}

.beleg-card-header .filename:hover {
  color: var(--primary-dark);
  text-decoration: underline;
}

.beleg-card-header .ki-badge {
  padding: 0.2rem 0.6rem;
  border-radius: 20px;
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.01em;
}

.ki-badge.success { background: var(--success-light); color: var(--accent-dark); }
.ki-badge.manual { background: var(--warning-light); color: var(--warning); }
.ki-badge.saved-badge { background: var(--success-light); color: var(--accent-dark); }

.beleg-card-fields {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.4rem;
}

.beleg-card-fields .field { margin-bottom: 0; }
.beleg-card-fields .field label {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  display: block;
  margin-bottom: 0.1rem;
}

.beleg-card-fields .field input,
.beleg-card-fields .field select {
  width: 100%;
  padding: 0.3rem 0.45rem;
  font-size: 0.8rem;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  transition: border-color var(--transition);
}

.beleg-card-fields .field input:focus,
.beleg-card-fields .field select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(8, 145, 178, 0.1);
}

.beleg-card-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.6rem;
}

.beleg-card-actions button {
  padding: 0.35rem 0.9rem;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 500;
  transition: all var(--transition);
}

.btn-card-confirm { background: var(--accent); color: #fff; }
.btn-card-confirm:hover { background: var(--accent-dark); }
.btn-card-remove { background: transparent; color: var(--text-muted); border: 1px solid var(--border) !important; }
.btn-card-remove:hover { border-color: var(--danger) !important; color: var(--danger); }

/* --- Jahrauswahl (inside liste) --- */
#jahr-section {
  margin-bottom: 0.75rem;
}

#jahr-tabs {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

#jahr-tabs button {
  padding: 0.45rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg-card);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 500;
  transition: all var(--transition);
}

#jahr-tabs button:hover {
  border-color: var(--primary);
  color: var(--primary);
}

#jahr-tabs button.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* --- Kategorie-Chips --- */
#kategorie-chips {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
  align-items: center;
}

.kat-chip {
  padding: 0.35rem 0.85rem;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  border: 1px solid var(--border);
  user-select: none;
}

.kat-chip.aktiv {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  cursor: default;
}

.kat-chip.editing {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.4rem;
  background: var(--bg-card);
  cursor: default;
}

.kat-edit-name {
  width: 100px;
  border: 1px solid var(--border-light);
  border-radius: 4px;
  padding: 0.2rem 0.35rem;
  font-size: 0.75rem;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
}

.kat-edit-prefix {
  width: 42px;
  border: 1px solid var(--border-light);
  border-radius: 4px;
  padding: 0.2rem 0.25rem;
  font-size: 0.7rem;
  font-family: inherit;
  color: var(--text-muted);
  background: var(--bg);
  text-align: center;
  text-transform: uppercase;
}

.kat-edit-name:focus,
.kat-edit-prefix:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(8, 145, 178, 0.1);
}

.kat-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0 0.15rem;
  transition: color var(--transition);
}

.kat-remove:hover {
  color: var(--danger);
}

.kat-add, .kat-done, .kat-edit-toggle {
  background: var(--bg-card);
  color: var(--text-muted);
  border: 1px dashed var(--border);
  font-size: 0.85rem;
}

.kat-add:hover, .kat-edit-toggle:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.kat-done {
  border-style: solid;
  border-color: var(--accent);
  color: var(--accent);
}

.kat-done:hover {
  background: var(--accent);
  color: #fff;
}

/* --- Toast --- */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: var(--primary-dark);
  color: #fff;
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 500;
  opacity: 0;
  transition: opacity 300ms ease, transform 300ms ease;
  z-index: 200;
  box-shadow: var(--shadow-md);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.toast-error {
  background: var(--danger);
}

/* --- Filter --- */
#filter-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.filter-group {
  display: flex;
  gap: 0.2rem;
  background: var(--bg);
  padding: 0.15rem;
  border-radius: var(--radius-sm);
}

.filter-btn {
  padding: 0.35rem 0.75rem;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 500;
  transition: all var(--transition);
}

.filter-btn:hover { color: var(--primary); }

.filter-btn.active {
  background: var(--bg-card);
  color: var(--primary);
  box-shadow: var(--shadow);
}

#filter-kategorie {
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--bg-card);
  cursor: pointer;
}

#filter-kategorie:focus {
  outline: none;
  border-color: var(--primary);
}

/* --- Liste --- */
#liste {
  background: var(--bg-card);
  padding: 1.25rem;
  border-radius: var(--radius);
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

th, td {
  padding: 0.55rem 0.6rem;
  text-align: left;
  border-bottom: 1px solid var(--border-light);
}

th {
  background: var(--bg);
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

tr:last-child td { border-bottom: none; }

tr:hover td { background: var(--bg-hover); }

td.betrag {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

#summen {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-light);
  font-size: 0.8rem;
  display: flex;
  gap: 1.5rem;
  font-weight: 500;
}

#summen .einnahmen { color: var(--accent); }
#summen .ausgaben { color: var(--danger); }
#summen .saldo { color: var(--primary-dark); font-weight: 700; }

.originaldatei a {
  color: var(--primary);
  text-decoration: none;
  font-size: 0.75rem;
  opacity: 0.8;
}
.originaldatei a:hover { text-decoration: underline; opacity: 1; }

/* --- Action Icons --- */
.actions-cell {
  white-space: nowrap;
}

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  padding: 0.15rem 0.35rem;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  line-height: 1;
}

.btn-edit-icon { color: var(--text-muted); }
.btn-edit-icon:hover { color: var(--primary); background: var(--bg-hover); }

.btn-delete-icon { color: var(--text-muted); font-size: 1.15rem; opacity: 0.6; }
.btn-delete-icon:hover { color: var(--danger); opacity: 1; }

.btn-save-icon { color: var(--accent); font-size: 1.1rem; }
.btn-save-icon:hover { color: var(--accent-dark); background: var(--success-light); }

.btn-cancel-icon { color: var(--text-muted); font-size: 1.15rem; }
.btn-cancel-icon:hover { color: var(--danger); }

/* --- Inline Editing --- */
.editing-row td {
  background: var(--bg-hover);
}

.inline-input {
  width: 100%;
  padding: 0.25rem 0.35rem;
  border: 1px solid var(--border-light);
  border-radius: 4px;
  font-size: 0.78rem;
  font-family: inherit;
  color: var(--text);
  background: var(--bg-card);
  transition: border-color var(--transition);
}

.inline-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(8, 145, 178, 0.1);
}

.inline-betrag {
  text-align: right;
  width: 80px;
}

/* --- Utility --- */
.hidden { display: none !important; }

/* --- Responsive --- */
@media (max-width: 768px) {
  body { padding: 1rem 0.75rem; }
  h1 { font-size: 1.3rem; }
  .beleg-card-fields { grid-template-columns: 1fr 1fr; }
  .edit-fields { grid-template-columns: 1fr; }
  table { font-size: 0.75rem; }
  th, td { padding: 0.4rem; }
  #summen { flex-direction: column; gap: 0.3rem; }
}

@media (max-width: 480px) {
  .beleg-card-fields { grid-template-columns: 1fr; }
  .filter-group { flex-wrap: wrap; }
  #filter-bar { flex-direction: column; align-items: flex-start; }
}

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