:root {
  --bg: #f7f7f8;
  --surface: #ffffff;
  --surface-2: #fbfbfc;
  --border: #e2e2e6;
  --border-strong: #cfcfd6;
  --text: #16171a;
  --text-muted: #63646b;
  --accent: #1f4ed8;
  --accent-soft: #eaefff;
  --ok: #17663c;
  --ok-soft: #e4f4ea;
  --warn: #8a5a00;
  --warn-soft: #fdf2dc;
  --fail: #a32020;
  --fail-soft: #fdeaea;
  --info: #37474f;
  --info-soft: #eceff1;
  --radius: 10px;
  --mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131417;
    --surface: #1b1c20;
    --surface-2: #212227;
    --border: #2e3036;
    --border-strong: #3d4048;
    --text: #e9e9ec;
    --text-muted: #9a9ba3;
    --accent: #7ea2ff;
    --accent-soft: #1e2740;
    --ok: #6ad39a;
    --ok-soft: #14301f;
    --warn: #e8bb62;
    --warn-soft: #332713;
    --fail: #f58a8a;
    --fail-soft: #3a1c1c;
    --info: #b0bec5;
    --info-soft: #23282b;
  }
}

* { box-sizing: border-box; }

/* Das hidden-Attribut muss die display-Regeln der Komponenten schlagen -
   sonst bleiben ausgeblendete Buttons sichtbar. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------------------------------------------------------------- Kopfleiste */

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-inner {
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 28px;
  min-height: 58px;
  flex-wrap: wrap;
}

.logo {
  font-weight: 700;
  letter-spacing: .04em;
  color: var(--text);
  font-size: 15px;
  white-space: nowrap;
}
.logo span { color: var(--text-muted); font-weight: 400; letter-spacing: 0; }

.nav { display: flex; gap: 4px; flex-wrap: wrap; }
.nav a {
  padding: 7px 12px;
  border-radius: 7px;
  color: var(--text-muted);
  font-size: 14px;
  white-space: nowrap;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.is-active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }

/* -------------------------------------------------------------------- Layout */

main { max-width: 1240px; margin: 0 auto; padding: 28px 20px 72px; }

.page-head { margin-bottom: 24px; }
.page-head h1 { font-size: 24px; margin: 0 0 6px; letter-spacing: -.01em; }
.page-head p { margin: 0; color: var(--text-muted); max-width: 72ch; }

h2 { font-size: 17px; margin: 32px 0 12px; letter-spacing: -.01em; }
h3 { font-size: 15px; margin: 22px 0 10px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 18px;
}
.card > :first-child { margin-top: 0; }
.card > :last-child { margin-bottom: 0; }

.grid { display: grid; gap: 16px; }
/* Rasterelemente dürfen schmaler als ihr Inhalt werden - breite Tabellen scrollen dann in .table-wrap. */
.grid > * { min-width: 0; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }

/* ---------------------------------------------------------------- Kennzahlen */

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.stat-label { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); }
.stat-value { font-size: 26px; font-weight: 650; margin-top: 6px; letter-spacing: -.02em; }
.stat-note { font-size: 13px; color: var(--text-muted); margin-top: 4px; }
.stat-value.is-ok { color: var(--ok); }
.stat-value.is-warn { color: var(--warn); }
.stat-value.is-fail { color: var(--fail); }

/* -------------------------------------------------------------------- Tabelle */

.table-wrap { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  font-weight: 600;
  white-space: nowrap;
  border-bottom: 1px solid var(--border-strong);
}
tbody tr:last-child td, tbody tr:last-child th { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-fixed { table-layout: auto; }
/* Capability-Matrix: alle Providerspalten muessen ohne horizontales Scrollen
   nebeneinander passen. Die Nachweis-Zeilen werden deshalb hart begrenzt -
   der vollstaendige Wert steht im title-Attribut. */
.matrix th:first-child, .matrix td:first-child {
  position: sticky;
  left: 0;
  background: var(--surface);
  min-width: 170px;
  max-width: 230px;
}
.matrix tbody tr:hover td:first-child { background: var(--surface-2); }
.matrix th { white-space: nowrap; }
.matrix td { text-align: center; }
.matrix td:first-child { text-align: left; }

/* -------------------------------------------------------------------- Status */

.tag {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.7;
  white-space: nowrap;
}
.tag-ok   { background: var(--ok-soft);   color: var(--ok); }
.tag-warn { background: var(--warn-soft); color: var(--warn); }
.tag-fail { background: var(--fail-soft); color: var(--fail); }
.tag-info { background: var(--info-soft); color: var(--info); }
.tag-accent { background: var(--accent-soft); color: var(--accent); }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 7px; vertical-align: 1px; }
.dot-ok { background: var(--ok); }
.dot-warn { background: var(--warn); }
.dot-fail { background: var(--fail); }
.dot-info { background: var(--info); }

/* ------------------------------------------------------------------ Formular */

label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; }
.hint { font-size: 13px; color: var(--text-muted); margin: 4px 0 0; }

input[type=text], input[type=url], input[type=number], input[type=password], textarea, select {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
}
input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}
textarea { min-height: 76px; resize: vertical; line-height: 1.5; }

.field { margin-bottom: 16px; }
.field-row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

.check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
  background: var(--surface);
  cursor: pointer;
  font-weight: 400;
}
.check:hover { border-color: var(--border-strong); }
.check input { margin-top: 3px; flex-shrink: 0; }
.check.is-disabled { opacity: .55; cursor: not-allowed; }
.check-title { font-weight: 600; font-size: 14px; }
.check-note { font-size: 13px; color: var(--text-muted); }
.check-body { flex: 1; min-width: 0; }
/* Kostenschätzung je Provider, rechtsbündig neben der Auswahl */
.check-cost { display: flex; flex-direction: column; align-items: flex-end; text-align: right; flex-shrink: 0; }
.check-cost-total { font-weight: 600; font-size: 14px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.check-cost { max-width: 50%; }
.check-cost .check-note { font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.check-cost .check-cost-basis { white-space: normal; }
.check:has(input:not(:checked)) .check-cost-total { color: var(--text-muted); font-weight: 400; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-danger { color: var(--fail); border-color: var(--fail); background: transparent; }
.btn-danger:hover { background: var(--fail-soft); }
.btn-small { padding: 5px 11px; font-size: 13px; }
.table-mehr { margin-top: 10px; }
.flash-form { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin: 0; }
.flash-form span { flex: 1 1 280px; }
.flash-form strong { display: inline; }
/* Zurückhaltender Zeilen-Button: erscheint voll erst bei Hover/Fokus der Zeile. */
.btn-zeile {
  padding: 2px 8px; font-size: 12px; border-radius: 6px; border: 1px solid transparent;
  background: transparent; color: var(--text-muted); cursor: pointer; font: inherit; font-size: 12px;
}
.btn-zeile:hover, .btn-zeile:focus-visible { border-color: var(--border); color: var(--text); background: var(--surface-2); }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
td.aktion { width: 1%; white-space: nowrap; text-align: right; }
td.aktion form { margin: 0; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 18px; }

/* ------------------------------------------------------------------ Hinweise */

.notice {
  border-radius: var(--radius);
  padding: 13px 16px;
  margin-bottom: 18px;
  font-size: 14px;
  border: 1px solid;
}
.notice-info { background: var(--info-soft); border-color: var(--border-strong); color: var(--text); }
.notice-warn { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }
.notice-fail { background: var(--fail-soft); border-color: var(--fail); color: var(--fail); }
.notice-ok   { background: var(--ok-soft);   border-color: var(--ok);   color: var(--ok); }
.notice strong { display: block; margin-bottom: 3px; }
.notice p { margin: 0; }

/* ----------------------------------------------------------------- Fortschritt */

.progress {
  height: 8px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
  margin: 12px 0 6px;
}
.progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width .4s ease;
}
.progress-bar.is-done { background: var(--ok); }
.progress-bar.is-failed { background: var(--fail); }

.log {
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.55;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  max-height: 460px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}

.spinner {
  display: inline-block;
  width: 13px; height: 13px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2.4s; }
  .progress-bar { transition: none; }
}

/* --------------------------------------------------------------------- Rest */

code, .mono { font-family: var(--mono); font-size: .92em; }
.muted { color: var(--text-muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.truncate { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

details.raw { margin-top: 10px; }
details.raw summary { cursor: pointer; font-size: 13px; color: var(--text-muted); padding: 5px 0; }
details.raw summary:hover { color: var(--text); }
details.raw pre {
  font-family: var(--mono);
  font-size: 12.5px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  overflow: auto;
  max-height: 380px;
  margin: 8px 0 0;
}

.empty { text-align: center; padding: 44px 20px; color: var(--text-muted); }
.empty p { margin: 0 0 16px; }

.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--text-muted); margin-bottom: 12px; }

.bar-cell { display: flex; align-items: center; gap: 9px; }
.bar { height: 6px; border-radius: 999px; background: var(--accent); min-width: 2px; }
.bar.is-brand { background: var(--accent); }
.bar.is-competitor { background: var(--border-strong); }

@media (max-width: 720px) {
  .topbar-inner { min-height: auto; padding: 10px 16px; }
  main { padding: 20px 16px 56px; }
  .table-wrap { margin: 0 -16px; padding: 0 16px; }
  .card { padding: 16px; }
}

/* --------------------------------------------------------------- Diagramme */

/* Kategoriale Serienfarben. Beide Modi sind eigens für ihre Fläche gewählt und
   mit dem Palettenprüfer validiert (CVD-Abstand, Helligkeitsband, Chroma,
   Kontrast) - der dunkle Satz ist keine automatische Umkehrung des hellen.
   Slot 3 liegt im hellen Modus unter 3:1 Kontrast; deshalb tragen alle Serien
   ein direktes Label und es gibt immer die Tabellenansicht. */
.viz {
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  margin: 0;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .viz {
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
  }
}
:root[data-theme="dark"] .viz {
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
}

.viz figcaption { margin-bottom: 10px; }
.viz figcaption strong { font-size: 15px; display: block; }
.viz figcaption span { display: block; margin-top: 2px; }

.viz-legend { display: flex; gap: 18px; flex-wrap: wrap; margin-bottom: 6px; font-size: 13px; }
.viz-legend-item { display: inline-flex; align-items: center; gap: 7px; color: var(--text-muted); }
.viz-swatch { width: 11px; height: 11px; border-radius: 3px; flex-shrink: 0; }

.viz svg { width: 100%; height: auto; display: block; overflow: visible; }

.viz-grid { stroke: var(--border); stroke-width: 1; }
.viz-tick { fill: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.viz-serie-label { font-size: 11.5px; font-weight: 600; }
.viz-crosshair { stroke: var(--border-strong); stroke-width: 1; }
.viz-hit { cursor: crosshair; }

.viz-tooltip {
  position: absolute;
  z-index: 5;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 13px;
  box-shadow: 0 4px 14px rgb(0 0 0 / .13);
  pointer-events: none;
  min-width: 170px;
}
.viz-tooltip strong { display: block; margin-bottom: 5px; font-size: 12px; }
.viz-tooltip-row { display: flex; align-items: center; gap: 7px; justify-content: space-between; }
.viz-tooltip-row span:first-child { display: inline-flex; align-items: center; gap: 6px; color: var(--text-muted); }
.viz-tooltip-row b { font-variant-numeric: tabular-nums; }

.card:has(.viz) { position: relative; }

/* Gestapelter Balken (Teil-zu-Ganzes). 2px Lücke zwischen den Segmenten statt
   einer Kontur - eine Umrandung würde die Farben verfälschen. */
.stacked-bar { display: flex; gap: 2px; height: 22px; border-radius: 5px; overflow: hidden; }
.stacked-seg { display: block; height: 100%; min-width: 3px; }
.stacked-seg:first-child { border-radius: 5px 0 0 5px; }
.stacked-seg:last-child { border-radius: 0 5px 5px 0; }

/* ------------------------------------------------------------------ Anmeldung */
.login { max-width: 24rem; margin: 8vh auto; }
.logout-form { margin: 0; }

/* ------------------------------------------------------- Antworten im Wortlaut */
/* Zeilenkopf ist Inhalt, kein Spaltenkopf: normale Schrift statt Versalien. */
.antwort-matrix th[scope="row"] {
  min-width: 180px; max-width: 280px; vertical-align: top;
  font-weight: 400; font-size: 14px; text-transform: none; letter-spacing: normal;
  color: var(--text); white-space: normal;
}
.matrix-prompt { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin-top: 2px; }
.antwort-matrix td { vertical-align: top; min-width: 120px; }
.matrix-zelle {
  display: flex; flex-direction: column; gap: 3px;
  padding: 8px 10px; margin: -4px -6px;
  border: 1px solid transparent; border-radius: 8px;
  color: inherit; text-decoration: none;
}
.matrix-zelle:hover { border-color: var(--border-strong); background: var(--surface-2); }
.matrix-zelle:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.matrix-zelle.is-active { border-color: var(--accent); background: var(--surface-2); }
.matrix-wert { font-weight: 600; white-space: nowrap; }
.matrix-link { color: var(--accent); }

.antwortgruppe { display: none; scroll-margin-top: 80px; }
.antwortgruppe:target { display: block; }
.antwortgruppe-kopf { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin: 8px 0 12px; }
.tabelle-fehler { color: var(--fail); white-space: normal; min-width: 160px; max-width: 260px; margin-top: 4px; }

/* ------------------------------------------------------ Zitierte eigene Seiten */
.zitat-kennzahlen { display: flex; flex-wrap: wrap; gap: 8px 28px; margin: 4px 0 14px; }
.zitat-kennzahlen dt { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; }
.zitat-kennzahlen dd { margin: 2px 0 0; font-size: 20px; font-weight: 650; }
.zitat-kennzahlen .zitat-top { min-width: 0; flex: 1 1 260px; }
.zitat-kennzahlen .zitat-top dd { font-size: 14px; font-weight: 400; overflow-wrap: anywhere; }

/* ------------------------------------------- Aufklappbare Gruppen (Laufansicht)
   Eine Zeile je Gruppe mit den zusammengefassten Werten; die Einzelheiten
   stehen im aufgeklappten Teil. Die Spalten legt der Modifier fest. */
.gruppen { border-top: 1px solid var(--border); }
.gruppen-kopf, .gruppe > summary {
  display: grid; grid-template-columns: var(--gruppen-spalten);
  gap: 12px; align-items: baseline; padding: 9px 4px;
}
.gruppen-kopf { text-transform: uppercase; letter-spacing: .06em; font-size: 12px; border-bottom: 1px solid var(--border); }
.gruppe { border-bottom: 1px solid var(--border); }
.gruppe > summary { cursor: pointer; list-style: none; }
.gruppe > summary::-webkit-details-marker { display: none; }
/* Pfeil per Rahmen gezeichnet - ein Zeichen wie ▸ fehlt in manchen Schriften. */
.gruppe-name::before {
  content: ''; display: inline-block; width: 6px; height: 6px; margin: 0 10px 2px 2px;
  border-right: 2px solid var(--text-muted); border-bottom: 2px solid var(--text-muted);
  transform: rotate(-45deg); transition: transform .15s;
}
.gruppe[open] > summary .gruppe-name::before { transform: rotate(45deg); }
.gruppe > summary:hover { background: var(--surface-2); }
.gruppe > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.gruppe[open] { padding-bottom: 10px; }
.gruppen-kopf .num, .gruppe > summary .num { text-align: right; font-variant-numeric: tabular-nums; }

.gruppen--zitate { --gruppen-spalten: minmax(0, 2fr) 70px 70px minmax(0, 3fr); }
.gruppen--pruefungen { --gruppen-spalten: minmax(0, 1.4fr) 110px minmax(0, 3fr); }
.gruppe-inhalt { padding: 6px 4px 0 24px; }
.gruppen--provider {
  --gruppen-spalten: minmax(0, 1.1fr) 84px minmax(0, 1.2fr) minmax(0, 1.2fr) minmax(0, 1.4fr) minmax(0, 1fr) 64px 60px 72px;
}

@media (max-width: 720px) {
  .gruppen-kopf { display: none; }
  .gruppe > summary { grid-template-columns: minmax(0, 1fr) auto; }
  /* Zitate: Bereich und Zitate in einer Zeile, Anbieter darunter. */
  .gruppen--zitate .gruppe > summary > span:nth-child(3) { display: none; }
  .gruppen--zitate .gruppe > summary > span:nth-child(4) { grid-column: 1 / -1; }
  /* Prüfungen: Name und Status in einer Zeile, Ergebnis darunter. */
  .gruppen--pruefungen .gruppe > summary > span:nth-child(3) { grid-column: 1 / -1; }
  .gruppe-inhalt { padding-left: 4px; }
  /* Provider: Name und Nennungen; der Rest steht im aufgeklappten Teil. */
  .gruppen--provider .gruppe > summary > span:nth-child(2),
  .gruppen--provider .gruppe > summary > span:nth-child(n+4) { display: none; }
}

/* ----------------------------------------------------------------------- Tabs */
.tab-leiste {
  display: flex; gap: 2px; margin: 8px 0 20px; scroll-margin-top: 76px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto; scrollbar-width: thin;
}
.tab {
  flex-shrink: 0; padding: 10px 14px; margin-bottom: -1px;
  background: none; border: 0; border-bottom: 2px solid transparent;
  font: inherit; font-size: 14px; color: var(--text-muted);
  cursor: pointer; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--text); font-weight: 600; border-bottom-color: var(--accent); }
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 6px 6px 0 0; }
.tab-panel[hidden] { display: none; }
/* Sprungziele innerhalb eines Tabs nicht unter der feststehenden Kopfzeile verstecken. */
.tab-panel [id] { scroll-margin-top: 76px; }
/* Der Tab trägt den Namen; die Überschrift bleibt für Screenreader erhalten. */
.tabs-aktiv .tab-titel {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
