:root {
  color-scheme: light;
  --font: "NeverMind", system-ui, sans-serif;
  --surface-0: #f4f4f2;
  --surface-1: #fcfcfb;
  --border: #e2e1dc;
  --grid: #e8e7e2;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #77766f;
  --accent: #2a78d6;
  /* Kategorie-Farben in fester Reihenfolge (validierte Palette, siehe README) */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #6250d6;
  --series-8: #e34948;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-0: #111110;
    --surface-1: #1a1a19;
    --border: #2f2f2c;
    --grid: #2a2a28;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #96958c;
    --accent: #3987e5;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-0: #111110;
  --surface-1: #1a1a19;
  --border: #2f2f2c;
  --grid: #2a2a28;
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted: #96958c;
  --accent: #3987e5;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;
}

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

body {
  margin: 0;
  background: var(--surface-0);
  color: var(--text-primary);
  font-family: var(--font);
  line-height: 1.5;
}

a { color: var(--accent); }

.site-header {
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
}

.site-header .inner,
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px;
}

.site-header .inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 24px;
  min-height: 56px;
}

.brand {
  font-weight: 700;
  color: var(--text-primary);
  text-decoration: none;
}

.nav-menu { position: relative; margin-left: auto; }

.nav-menu summary {
  display: flex;
  align-items: center;
  gap: 8px;
  list-style: none;
  cursor: pointer;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-0);
  color: var(--text-primary);
  font-weight: 600;
  user-select: none;
}
.nav-menu summary::-webkit-details-marker { display: none; }
.nav-menu summary:hover { border-color: var(--text-muted); }
.nav-menu summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.nav-menu .caret { transition: transform 0.15s; }
.nav-menu[open] .caret { transform: rotate(180deg); }

.nav-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 50;
  width: min(300px, calc(100vw - 32px));
  max-height: calc(100vh - 80px);
  overflow-y: auto;
  padding: 8px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.14);
}

.nav-heading {
  margin: 4px 8px 6px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.nav-panel ul { list-style: none; margin: 0; padding: 0; }

.nav-panel a {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 7px 8px;
  border-radius: 6px;
  color: var(--text-primary);
  text-decoration: none;
}
.nav-panel a:hover, .nav-panel a:focus-visible { background: var(--surface-0); outline: none; }
.nav-panel a[aria-current="page"] { background: var(--surface-0); box-shadow: inset 3px 0 0 var(--accent); font-weight: 600; }

.nav-total { color: var(--text-secondary); font-size: 0.875rem; font-variant-numeric: tabular-nums; white-space: nowrap; }

.nav-tag {
  display: inline-block;
  margin-left: 4px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 600;
  vertical-align: 1px;
}

.nav-compare {
  margin-top: 6px;
  border-top: 1px solid var(--border);
  border-radius: 0 0 6px 6px !important;
  padding-top: 10px !important;
  color: var(--accent) !important;
  font-weight: 600;
}

main { padding-top: 24px; padding-bottom: 48px; }

h1 { font-size: 1.75rem; margin: 0 0 4px; }
h2 { font-size: 1.25rem; margin: 0 0 12px; }

.lead { color: var(--text-secondary); margin: 0 0 24px; }

.panel {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 24px;
}

.panel-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 16px;
  margin-bottom: 12px;
}

.panel-header h2 { margin: 0; }

.muted { color: var(--text-muted); }
.small { font-size: 0.875rem; }

/* Kennzahlen */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
}

.stat .label { color: var(--text-secondary); font-size: 0.875rem; }
.stat .value { font-size: clamp(1.35rem, 1.1rem + 0.8vw, 1.75rem); font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stat .sub { color: var(--text-secondary); font-size: 0.875rem; }

a.stat { color: inherit; text-decoration: none; }
a.stat:hover { border-color: var(--accent); }

/* Jahresnavigation */
.year-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 16px;
}

.year-nav .pager { display: flex; gap: 16px; }

/* Diagramme */
.chart { width: 100%; height: 420px; }
.chart.treemap { height: min(75vh, 720px); }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin: 0 0 8px;
  padding: 0;
  list-style: none;
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-right: 6px;
  vertical-align: baseline;
}

.c0 { background: var(--series-1); }
.c1 { background: var(--series-2); }
.c2 { background: var(--series-3); }
.c3 { background: var(--series-4); }
.c4 { background: var(--series-5); }
.c5 { background: var(--series-6); }
.c6 { background: var(--series-7); }
.c7 { background: var(--series-8); }

/* Formulare */
.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px;
}

.controls label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

select, button {
  font: inherit;
  color: var(--text-primary);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  max-width: 100%;
}

button { cursor: pointer; }
button:hover { border-color: var(--accent); }

/* Tabellen */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  font-size: 0.9375rem;
}

th, td {
  padding: 6px 8px;
  text-align: left;
  border-bottom: 1px solid var(--grid);
  vertical-align: top;
}

th { color: var(--text-secondary); font-weight: 600; font-size: 0.875rem; }
td.num, th.num { text-align: right; white-space: nowrap; }

tr.group td {
  font-weight: 700;
  background: var(--surface-0);
  border-top: 1px solid var(--border);
}

tr.total td {
  font-weight: 700;
  border-top: 2px solid var(--text-secondary);
  border-bottom: none;
}

td.indent { padding-left: 28px; }
td.indent-2 { padding-left: 48px; }
tr.subgroup td { font-weight: 600; color: var(--text-secondary); }

.note { display: block; color: var(--text-muted); font-size: 0.8125rem; }

.change-up::before { content: "▲ "; font-size: 0.7em; }
.change-down::before { content: "▼ "; font-size: 0.7em; }

details summary { cursor: pointer; color: var(--text-secondary); }

.notes-box { white-space: pre-line; color: var(--text-secondary); }

.empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--text-secondary);
}

@media (max-width: 480px) {
  .site-header .inner { flex-wrap: nowrap; }
  .nav-menu summary .long { display: none; }
}
