:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --bg: #f1f5f9;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
}

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

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
}

/* ── Layout ── */
.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 1.25rem;
}

/* ── Navigation ── */
.nav {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-inner {
  display: flex;
  align-items: center;
  gap: 0;
  height: 56px;
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 1.25rem;
}

.nav-brand {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
  text-decoration: none;
  margin-right: 1.5rem;
  white-space: nowrap;
}

.nav-brand span {
  color: var(--primary);
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex: 1;
  flex-wrap: wrap;
}

.nav-link {
  color: var(--text-muted);
  text-decoration: none;
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

.nav-link:hover { background: var(--bg); color: var(--text); }
.nav-link.active { background: #eff6ff; color: var(--primary); }

.nav-year {
  margin-left: 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.nav-year select,
.nav-year-mobile select {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.3rem 0.6rem;
  font-size: 0.9rem;
  background: white;
  cursor: pointer;
}

.nav-year-mobile { display: none; }

/* ── Page header ── */
.page-header {
  padding: 1.75rem 0 0.5rem;
}

.page-title {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.page-sub {
  color: var(--text-muted);
  margin-top: 0.2rem;
  font-size: 0.95rem;
}

/* ── Cards ── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
}

/* ── KPI cards ── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin: 1.25rem 0;
}

.kpi {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.kpi-label {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.kpi-value {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.kpi-value.positive { color: var(--success); }
.kpi-value.negative { color: var(--danger); }
.kpi-value.neutral  { color: var(--primary); }

/* ── Section titles ── */
.section-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.78rem;
}

/* ── Charts ── */
.chart-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin: 1rem 0;
}

.chart-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
}

.chart-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 1rem;
}

.chart-wrap {
  position: relative;
  height: 280px;
}

/* ── Monthly table ── */
.table-wrap {
  overflow-x: auto;
  margin: 1rem 0;
}

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

thead th {
  background: var(--bg);
  text-align: left;
  padding: 0.65rem 1rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

thead th.num { text-align: right; }

tbody tr { border-bottom: 1px solid var(--border); transition: background 0.1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }

tbody td {
  padding: 0.7rem 1rem;
}

tbody td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-family: ui-monospace, 'SF Mono', monospace;
  font-size: 0.88rem;
  white-space: nowrap;
}

tfoot td {
  padding: 0.75rem 1rem;
  font-weight: 700;
  border-top: 2px solid var(--border);
  font-size: 0.88rem;
}

tfoot td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-family: ui-monospace, 'SF Mono', monospace;
  white-space: nowrap;
}

.positive { color: var(--success); }
.negative { color: var(--danger); }

.month-link {
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
}

.month-link:hover { color: var(--primary); text-decoration: underline; }

/* ── Month nav ── */
.month-nav {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 0.5rem;
}

.month-nav a {
  color: var(--primary);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.3rem 0.75rem;
  border: 1px solid var(--primary);
  border-radius: 6px;
  transition: background 0.15s, color 0.15s;
}

.month-nav a:hover { background: var(--primary); color: white; }

/* ── Transaction list ── */
.tx-type-badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge-ausgabe { background: #fee2e2; color: #991b1b; }
.badge-einnahme { background: #dcfce7; color: #166534; }

/* ── Filter form ── */
.filter-form {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem 1.5rem;
  margin: 1rem 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-end;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  min-width: 140px;
}

.filter-group label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.filter-group input,
.filter-group select {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 0.65rem;
  font-size: 0.9rem;
  background: white;
  color: var(--text);
}

.filter-group input:focus,
.filter-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

.btn {
  padding: 0.45rem 1.1rem;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background 0.15s, transform 0.1s;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg); }

.result-count {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
}

/* ── Delete button ── */
.del-cell { width: 36px; text-align: center; padding: 0 !important; }
.del-cell form { margin: 0; }
.btn-del {
  background: none;
  border: none;
  color: var(--border);
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0.3rem 0.5rem;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
  line-height: 1;
}
.btn-del:hover { color: var(--danger); background: #fee2e2; }

/* ── Sort links ── */
.sort-link { color: inherit; text-decoration: none; }
.sort-link:hover { color: var(--primary); }
.sort-arrow { font-size: 0.7rem; margin-left: 2px; }

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

.empty-state-icon { font-size: 2.5rem; margin-bottom: 0.75rem; }
.empty-state p { font-size: 0.95rem; }

/* ── Error page ── */
.error-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  text-align: center;
  gap: 1rem;
}

.error-code {
  font-size: 4rem;
  font-weight: 800;
  color: var(--border);
  line-height: 1;
}

/* ── New entry form ── */
.nav-link-new {
  margin-left: 0.5rem;
  background: var(--primary);
  color: white !important;
  border-radius: 6px;
}
.nav-link-new:hover { background: var(--primary-dark) !important; color: white !important; }
.nav-link-new.active { background: var(--primary-dark); color: white !important; }

.form-group { margin-bottom: 1.25rem; }

.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}

.form-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.8rem;
  font-size: 1rem;
  color: var(--text);
  background: white;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

.radio-group {
  display: flex;
  gap: 0.75rem;
}

.radio-option {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.95rem;
  transition: border-color 0.15s, background 0.15s;
  user-select: none;
}

.radio-option input[type="radio"] { display: none; }
.radio-option:hover { border-color: var(--primary); background: #eff6ff; }
.radio-option.active { border-color: var(--primary); background: #eff6ff; color: var(--primary); }

.btn-full { width: 100%; padding: 0.7rem; font-size: 1rem; margin-top: 0.5rem; }

/* ── Alerts ── */
.alert {
  border-radius: var(--radius);
  padding: 0.9rem 1.25rem;
  margin-bottom: 1rem;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.alert-success {
  background: #dcfce7;
  color: #166534;
  border: 1px solid #bbf7d0;
}

.alert-error {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.alert-link {
  margin-left: auto;
  color: inherit;
  font-weight: 600;
  text-decoration: underline;
  white-space: nowrap;
}

/* ── Spacing utilities ── */
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }

/* ── Burger menu ── */
.nav-burger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.4rem;
  margin-left: auto;
}

.nav-burger span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: transform 0.2s, opacity 0.2s;
}

.nav-burger.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nav-burger.open span:nth-child(2) { opacity: 0; }
.nav-burger.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ── Responsive ── */
@media (max-width: 900px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .chart-grid { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .nav-year { display: none; }
  .filter-form { flex-direction: column; }
  .filter-group { min-width: unset; width: 100%; }
  .page-title { font-size: 1.25rem; }
  .kpi-value { font-size: 1.2rem; }
  .chart-wrap { height: 220px; }

  .nav-burger { display: flex; }
  .nav-year { display: none; }
  .nav-year-mobile {
    display: block;
    padding: 0.5rem 0.75rem 0.25rem;
    border-top: 1px solid var(--border);
    margin-top: 0.25rem;
  }
  .nav-links {
    display: none;
    position: absolute;
    top: 56px;
    left: 0;
    right: 0;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    flex-direction: column;
    padding: 0.5rem 1rem 1rem;
    gap: 0.25rem;
    box-shadow: 0 4px 12px rgba(0,0,0,.08);
  }
  .nav-links.open { display: flex; }
  .nav-link { font-size: 1rem; padding: 0.6rem 0.75rem; }
}

@media (max-width: 420px) {
  .kpi-grid { grid-template-columns: 1fr; }
}
