:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --danger: #d03b3b;
  --good: #006300;
  --s1: #2a78d6; /* Umsatz */
  --s2: #eb6834; /* Deckungsbeitrag */
  --s3: #1baf7a; /* Dienstleistung */
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #262624;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --accent: #3987e5;
    --good: #0ca30c;
    --s1: #3987e5;
    --s2: #d95926;
    --s3: #199e70;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--page); color: var(--ink); line-height: 1.45; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1rem; }
a { color: var(--accent); }

/* ---------- Login */
#login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-box {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 32px; width: min(360px, 100%); text-align: center;
}
.login-box p { color: var(--ink-2); margin: 6px 0 20px; }
.login-box input {
  font-size: 1.6rem; letter-spacing: 0.4em; text-align: center; width: 100%;
}
.login-box button { width: 100%; margin-top: 14px; justify-content: center; }
.meldung-fehler { color: var(--danger); min-height: 1.4em; margin-top: 10px; font-size: 0.9rem; }

/* ---------- Layout */
header.top {
  position: sticky; top: 0; z-index: 10; background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px; padding: 10px 20px; flex-wrap: wrap;
}
header.top .titel { display: flex; flex-direction: column; margin-right: auto; }
header.top .titel small { color: var(--muted); font-size: 0.8rem; }
nav { display: flex; gap: 4px; flex-wrap: wrap; }
nav a {
  text-decoration: none; color: var(--ink-2); padding: 7px 12px; border-radius: 8px; font-weight: 500;
}
nav a:hover { background: var(--surface-2); }
nav a.aktiv { background: var(--accent); color: var(--accent-ink); }
main { max-width: 1200px; margin: 0 auto; padding: 24px 20px 60px; }
.seitenkopf { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.seitenkopf h2 { margin-right: auto; }
.karte {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; margin-bottom: 20px;
}

/* ---------- Formulare */
label { display: block; font-size: 0.85rem; color: var(--ink-2); margin-bottom: 4px; font-weight: 500; }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--axis); border-radius: 8px; padding: 8px 10px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.raster { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px 18px; }
.raster .breit { grid-column: 1 / -1; }
.pflicht::after { content: " *"; color: var(--danger); }
.hinweis { color: var(--muted); font-size: 0.8rem; margin-top: 3px; }
.berechnet { display: flex; gap: 24px; flex-wrap: wrap; padding: 12px 14px; background: var(--surface-2); border-radius: 8px; margin-top: 16px; }
.berechnet div { font-size: 0.85rem; color: var(--ink-2); }
.berechnet b { display: block; font-size: 1.05rem; color: var(--ink); font-variant-numeric: tabular-nums; }
.knopfleiste { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }

button, .knopf {
  font: inherit; font-weight: 500; cursor: pointer; border-radius: 8px; padding: 8px 16px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--ink); text-decoration: none;
  display: inline-flex; align-items: center; gap: 6px;
}
button:hover, .knopf:hover { filter: brightness(0.96); }
button.primaer { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
button.gefahr { color: var(--danger); }
button.klein { padding: 4px 10px; font-size: 0.85rem; }
button:disabled { opacity: 0.5; cursor: default; }

/* ---------- Filterzeile */
.filter { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 16px; }
.filter > div { min-width: 150px; flex: 1 1 150px; max-width: 240px; }
.segment { display: inline-flex; border: 1px solid var(--axis); border-radius: 8px; overflow: hidden; }
.segment button { border: 0; border-radius: 0; background: transparent; color: var(--ink-2); }
.segment button.aktiv { background: var(--accent); color: var(--accent-ink); }

/* ---------- Tabellen */
.tabelle-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th { color: var(--ink-2); font-weight: 600; font-size: 0.8rem; position: sticky; top: 0; background: var(--surface); }
td.zahl, th.zahl { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: var(--surface-2); }
tbody tr.klickbar { cursor: pointer; }
tfoot td { font-weight: 600; border-top: 2px solid var(--axis); border-bottom: 0; }
td.umbruch { white-space: normal; min-width: 180px; }

/* ---------- Kennzahlen */
.kacheln { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 20px; }
.kachel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.kachel span { color: var(--ink-2); font-size: 0.85rem; }
.kachel b { display: block; font-size: 1.5rem; font-weight: 600; margin-top: 4px; }
.kachel small { color: var(--muted); font-size: 0.8rem; }

/* ---------- Diagramme */
.diagramm-kopf { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.diagramm-kopf h3 { margin-right: auto; }
.legende { display: flex; gap: 16px; flex-wrap: wrap; font-size: 0.85rem; color: var(--ink-2); }
.legende i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.diagramm { position: relative; width: 100%; }
.diagramm svg { display: block; width: 100%; height: auto; overflow: visible; }
.diagramm text { fill: var(--muted); font-size: 11px; font-family: inherit; }
.tooltip {
  position: absolute; pointer-events: none; background: var(--surface); color: var(--ink);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 0.82rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12); white-space: nowrap; z-index: 5;
}
.tooltip .tt-titel { font-weight: 600; margin-bottom: 4px; }
.tooltip .tt-zeile { display: flex; gap: 10px; justify-content: space-between; }
.tooltip .tt-zeile span:last-child { font-variant-numeric: tabular-nums; font-weight: 500; }
.tooltip i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }

/* ---------- Dialog & Toast */
dialog {
  border: 1px solid var(--border); border-radius: 14px; padding: 24px; background: var(--surface); color: var(--ink);
  width: min(900px, calc(100% - 24px)); max-height: calc(100vh - 40px);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--page);
  padding: 10px 18px; border-radius: 8px; font-size: 0.9rem; z-index: 100;
}
.leer { color: var(--muted); padding: 30px; text-align: center; }
.zaehler { color: var(--muted); font-size: 0.85rem; }

.stamm-raster { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(400px, 100%), 1fr)); gap: 20px; }
.stamm-liste { max-height: 420px; overflow: auto; }
.stamm-raster .stamm-liste td { white-space: normal; }
.stamm-raster .stamm-liste td.zahl { white-space: nowrap; width: 1%; }
.inline-form { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.inline-form input, .inline-form select { flex: 1 1 140px; width: auto; }

@media (max-width: 640px) {
  header.top { padding: 10px 12px; }
  main { padding: 16px 12px 60px; }
  .karte { padding: 14px; }
}
@media print {
  header.top, .filter, .knopfleiste, button { display: none !important; }
  body { background: #fff; }
  .karte { border: 0; padding: 0; }
}
