/*
  Energiewirtschafts-Wiki — Basis-Stil.
  Von Hand gepflegt (kein Build-Schritt). Ruhig, textorientiert, Lesekomfort.
  Dark Mode ueber prefers-color-scheme; manuelles Umschalten setzt
  data-theme="light|dark" am <html>.
*/

:root {
  --max-text: 72ch;

  --c-bg: #ffffff;
  --c-surface: #f6f7f8;
  --c-border: #e2e5e9;
  --c-ink: #1c2024;
  --c-ink-soft: #5b6470;
  --c-brand: #1f6f5c;
  --c-brand-ink: #0f3d33;
  --c-link: #14624f;
  --c-link-missing: #b23b3b;
  --c-badge-review-bg: #fdf0d5;
  --c-badge-review-ink: #8a5a00;
  --c-badge-ki-bg: #e7f0fb;
  --c-badge-ki-ink: #1b4f8a;
  --c-callout-hinweis: #1b6ec2;
  --c-callout-warnung: #c2451b;
  --c-callout-merke: #1f6f5c;

  --font-sans: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-text: "Source Serif 4", Georgia, "Times New Roman", serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --c-bg: #14171a;
    --c-surface: #1c2126;
    --c-border: #2c333b;
    --c-ink: #e6e9ec;
    --c-ink-soft: #9aa4b0;
    --c-brand: #4fb99f;
    --c-brand-ink: #8fd4c4;
    --c-link: #62c3aa;
    --c-link-missing: #e07a7a;
    --c-badge-review-bg: #3a2f16;
    --c-badge-review-ink: #e8c583;
    --c-badge-ki-bg: #1a2c40;
    --c-badge-ki-ink: #8fbce8;
  }
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] {
  color-scheme: dark;
  --c-bg: #14171a; --c-surface: #1c2126; --c-border: #2c333b;
  --c-ink: #e6e9ec; --c-ink-soft: #9aa4b0; --c-brand: #4fb99f;
  --c-link: #62c3aa; --c-link-missing: #e07a7a;
  --c-badge-review-bg: #3a2f16; --c-badge-review-ink: #e8c583;
  --c-badge-ki-bg: #1a2c40; --c-badge-ki-ink: #8fbce8;
}

* { box-sizing: border-box; }
html { font-size: 17px; }
body {
  margin: 0;
  background: var(--c-bg);
  color: var(--c-ink);
  font-family: var(--font-sans);
  line-height: 1.6;
}

a { color: var(--c-link); text-underline-offset: 2px; }
a:hover { text-decoration: underline; }
code, pre { font-family: var(--font-mono); font-size: 0.9em; }

.skip-link {
  position: absolute; left: -999px; top: 0;
  background: var(--c-brand); color: #fff; padding: .5rem 1rem; z-index: 10;
}
.skip-link:focus { left: 0; }

/* --- Kopf / Fuss ------------------------------------------------------- */
.site-header {
  border-bottom: 1px solid var(--c-border);
  background: var(--c-surface);
  position: sticky; top: 0; z-index: 5;
}
.site-header__inner {
  display: flex; align-items: center; gap: 1rem;
  max-width: 1200px; margin: 0 auto; padding: .7rem 1.2rem;
}
.site-title { font-weight: 700; font-size: 1.05rem; text-decoration: none; color: var(--c-ink); }
.suche { flex: 1; }
.suche input {
  width: 100%; max-width: 420px; padding: .45rem .7rem;
  border: 1px solid var(--c-border); border-radius: 6px;
  background: var(--c-bg); color: var(--c-ink);
}
.theme-toggle {
  border: 1px solid var(--c-border); background: var(--c-bg); color: var(--c-ink);
  border-radius: 6px; width: 2rem; height: 2rem; cursor: pointer; font-size: 1rem;
}
.site-user { display: flex; align-items: center; gap: .5rem; font-size: .85rem; color: var(--c-ink-soft); white-space: nowrap; }
.site-user__logout { display: inline; }
.site-user__logout button {
  border: 1px solid var(--c-border); background: var(--c-bg); color: var(--c-ink-soft);
  border-radius: 6px; padding: .25rem .6rem; cursor: pointer; font: inherit;
}
.site-footer {
  border-top: 1px solid var(--c-border); color: var(--c-ink-soft);
  font-size: .85rem; text-align: center; padding: 1.5rem 1rem;
}

/* --- Layout: Baum | Inhalt | TOC ------------------------------------ */
.layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 240px;
  gap: 2rem;
  max-width: 1200px; margin: 0 auto; padding: 1.5rem 1.2rem 3rem;
}
.sidebar { font-size: .9rem; }
.toc-column { font-size: .85rem; }
.sidebar, .toc-column { position: sticky; top: 4rem; align-self: start; max-height: calc(100vh - 5rem); overflow-y: auto; }

@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar, .toc-column { position: static; max-height: none; }
  .toc-column { order: 3; }
}

/* --- Kategoriebaum -------------------------------------------------- */
.cat-tree { list-style: none; margin: 0; padding-left: .8rem; border-left: 1px solid var(--c-border); }
.sidebar > .cat-tree,
.sidebar > nav > .cat-tree { padding-left: 0; border-left: none; }
.cat-tree__item > a { display: block; padding: .18rem .3rem; border-radius: 4px; text-decoration: none; color: var(--c-ink-soft); }
.cat-tree__item > a:hover { background: var(--c-surface); color: var(--c-ink); }
.cat-tree__item.is-active > a { color: var(--c-ink); font-weight: 600; }
.cat-tree__item > a[aria-current="page"] { background: var(--c-surface); color: var(--c-brand-ink); }

/* --- Inhalt / Typo ----------------------------------------------------- */
.content { min-width: 0; }
.content h1 { font-size: 1.9rem; line-height: 1.25; margin: 0 0 .6rem; }
.content h2 { font-size: 1.35rem; margin: 2rem 0 .6rem; padding-bottom: .2rem; border-bottom: 1px solid var(--c-border); }
.content h3 { font-size: 1.1rem; margin: 1.4rem 0 .4rem; }
.lede { font-size: 1.1rem; color: var(--c-ink-soft); max-width: var(--max-text); }

.prose { max-width: var(--max-text); font-family: var(--font-text); font-size: 1.06rem; }
.prose p, .prose li { line-height: 1.7; }
.prose pre { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: 6px; padding: .9rem 1rem; overflow-x: auto; }
.prose :not(pre) > code { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: 4px; padding: .05rem .35rem; }
.prose table { border-collapse: collapse; width: 100%; font-family: var(--font-sans); font-size: .95rem; }
.prose th, .prose td { border: 1px solid var(--c-border); padding: .4rem .6rem; text-align: left; }
.prose blockquote { border-left: 3px solid var(--c-border); margin: 1rem 0; padding: .2rem 1rem; color: var(--c-ink-soft); }
.prose img.embed-asset { border: 1px solid var(--c-border); border-radius: 6px; }

/* Wikilinks */
a.wikilink { text-decoration: none; border-bottom: 1px solid currentColor; }
a.wikilink--fehlt { color: var(--c-link-missing); border-bottom-style: dotted; }

/* Callouts */
.callout { border: 1px solid var(--c-border); border-left-width: 4px; border-radius: 6px; padding: .7rem 1rem; margin: 1.2rem 0; background: var(--c-surface); }
.callout__label { margin: 0 0 .3rem; font-family: var(--font-sans); font-weight: 700; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
.callout--hinweis { border-left-color: var(--c-callout-hinweis); }
.callout--warnung { border-left-color: var(--c-callout-warnung); }
.callout--merke   { border-left-color: var(--c-callout-merke); }
.callout > :last-child { margin-bottom: 0; }

/* Mermaid: bis das Skript rendert, den Quelltext dezent halten */
pre.mermaid { background: var(--c-surface); border: 1px dashed var(--c-border); text-align: center; }

/* --- Kacheln / Listen ------------------------------------------------- */
.tile-grid { list-style: none; padding: 0; margin: 1rem 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .8rem; }
.tile a { display: block; height: 100%; padding: .9rem 1rem; border: 1px solid var(--c-border); border-radius: 8px; text-decoration: none; color: var(--c-ink); background: var(--c-surface); }
.tile a:hover { border-color: var(--c-brand); }
.tile__title { display: block; font-weight: 600; }
.tile__desc { display: block; margin-top: .25rem; font-size: .85rem; color: var(--c-ink-soft); }

.article-list { padding-left: 1.1rem; }
.article-list li { margin: .3rem 0; }

/* --- Badges / Chips ------------------------------------------------- */
.badge { display: inline-block; font-size: .72rem; font-weight: 700; padding: .1rem .45rem; border-radius: 4px; vertical-align: middle; }
.badge--review { background: var(--c-badge-review-bg); color: var(--c-badge-review-ink); }
.badge--ki { background: var(--c-badge-ki-bg); color: var(--c-badge-ki-ink); }
.chip { display: inline-block; font-size: .78rem; padding: .1rem .5rem; margin: .1rem .2rem .1rem 0; border: 1px solid var(--c-border); border-radius: 999px; color: var(--c-ink-soft); }
.muted { color: var(--c-ink-soft); }

/* --- Brotkrumen / Meta ---------------------------------------------- */
.breadcrumb ol { list-style: none; display: flex; flex-wrap: wrap; gap: .3rem; padding: 0; margin: 0 0 1rem; font-size: .85rem; color: var(--c-ink-soft); }
.breadcrumb li:not(:last-child)::after { content: "›"; margin-left: .3rem; }
.article__meta { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; font-size: .85rem; margin-bottom: 1.5rem; }
.article__footer { margin-top: 2.5rem; padding-top: 1rem; border-top: 1px solid var(--c-border); font-size: .9rem; }
.backlinks ul { padding-left: 1.1rem; }

/* --- Formular-Buttons ---------------------------------------------- */
.btn {
  display: inline-block; padding: .5rem .9rem; border-radius: 6px;
  border: 1px solid var(--c-brand); background: var(--c-brand); color: #fff;
  font: inherit; cursor: pointer; text-decoration: none;
}
.btn:hover { filter: brightness(1.05); }
.btn--ghost { background: transparent; color: var(--c-link); }

/* --- Admin --------------------------------------------------------- */
.admin-nav { display: flex; flex-wrap: wrap; gap: .3rem 1rem; align-items: center;
  margin: 1rem 0 1.5rem; padding-bottom: .8rem; border-bottom: 1px solid var(--c-border); font-size: .9rem; }
.admin-nav__logout { margin-left: auto; }
.admin-nav__logout button { border: 1px solid var(--c-border); background: var(--c-bg);
  color: var(--c-ink-soft); border-radius: 6px; padding: .3rem .7rem; cursor: pointer; font: inherit; }
.admin-table { border-collapse: collapse; width: 100%; font-size: .9rem; margin: 1rem 0; }
.admin-table th, .admin-table td { border: 1px solid var(--c-border); padding: .4rem .6rem; text-align: left; vertical-align: top; }
.admin-table th { background: var(--c-surface); }

/* --- Suche ------------------------------------------------------------- */
.such-formular { margin: 1rem 0 1.5rem; }
.such-formular__zeile { display: flex; gap: .5rem; }
.such-formular__q { flex: 1; padding: .5rem .7rem; border: 1px solid var(--c-border);
  border-radius: 6px; background: var(--c-bg); color: var(--c-ink); }
.such-formular__zeile button { padding: .5rem 1rem; border: 1px solid var(--c-border);
  border-radius: 6px; background: var(--c-surface); color: var(--c-ink); cursor: pointer; }
.such-formular__filter { display: flex; flex-wrap: wrap; gap: .8rem; margin-top: .6rem;
  font-size: .85rem; color: var(--c-ink-soft); }
.such-formular__filter label { display: flex; flex-direction: column; gap: .2rem; }
.such-formular__filter select, .such-formular__filter input { padding: .3rem .4rem;
  border: 1px solid var(--c-border); border-radius: 5px; background: var(--c-bg); color: var(--c-ink); }
.such-anzahl { margin: .3rem 0 1rem; }
.such-liste { list-style: none; padding: 0; margin: 0; }
.such-treffer { padding: .8rem 0; border-top: 1px solid var(--c-border); }
.such-treffer__kopf { display: flex; align-items: baseline; gap: .5rem; flex-wrap: wrap; }
.such-treffer__titel { font-weight: 600; font-size: 1.05rem; }
.such-treffer__pfad { font-size: .8rem; margin: .15rem 0; }
.such-treffer__ausschnitt { margin: .3rem 0 0; }
.such-treffer__ausschnitt mark { background: var(--c-badge-review-bg);
  color: var(--c-badge-review-ink); padding: 0 .1em; border-radius: 2px; }

/* --- TOC ------------------------------------------------------------- */
.toc__title { font-weight: 700; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--c-ink-soft); }
.toc ul { list-style: none; padding: 0; margin: 0; }
.toc li { margin: .2rem 0; }
.toc__level-3 { padding-left: .8rem; }
.toc a { color: var(--c-ink-soft); text-decoration: none; }
.toc a:hover { color: var(--c-ink); }


/* =====================================================================
   Paket 3a — Lesen & Finden: Design-Durchgang
   Glossar-Autolink, Live-Suchvorschlaege, Glossarseite, Artikel-Feinschliff,
   Anker-Links, Scrollspy, mobile Navigation, Druckansicht.
   ===================================================================== */

:root {
  --c-glossar-underline: #9fb8c4;
  --c-suggest-bg: var(--c-bg);
  --c-mark-bg: #fff2ac;
  --c-mark-ink: #4a3a00;
}
@media (prefers-color-scheme: dark) {
  :root { --c-glossar-underline: #4a6b78; --c-mark-bg: #5a4a12; --c-mark-ink: #f0e0b0; }
}
:root[data-theme="dark"] { --c-glossar-underline: #4a6b78; --c-mark-bg: #5a4a12; --c-mark-ink: #f0e0b0; }

/* --- Lesetypografie: etwas mehr Ruhe -------------------------------- */
.content h1 { text-wrap: balance; letter-spacing: -0.01em; }
.content h2, .content h3 { text-wrap: balance; }
.prose p { text-wrap: pretty; }
.prose > * + * { margin-top: 1rem; }
.prose h2 + p, .prose h3 + p { margin-top: .5rem; }
.prose ul, .prose ol { padding-left: 1.35rem; }
.prose li + li { margin-top: .3rem; }
.prose li::marker { color: var(--c-ink-soft); }
.lede { text-wrap: pretty; }

/* --- Kopfzeile: Bereichsnavigation -------------------------------- */
.site-nav { display: flex; gap: .8rem; font-size: .9rem; white-space: nowrap; }
.site-nav a { color: var(--c-ink-soft); text-decoration: none; }
.site-nav a:hover { color: var(--c-ink); }
.suche { position: relative; }

/* --- Live-Suchvorschlaege ---------------------------------------- */
.suggest {
  position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + .35rem);
  max-width: 480px; background: var(--c-suggest-bg);
  border: 1px solid var(--c-border); border-radius: 8px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .16); overflow: hidden;
}
.suggest__liste { list-style: none; margin: 0; padding: .25rem; }
.suggest__item > a {
  display: flex; flex-direction: column; gap: .1rem;
  padding: .4rem .6rem; border-radius: 6px; text-decoration: none; color: var(--c-ink);
}
.suggest__item.is-active > a,
.suggest__item > a:hover { background: var(--c-surface); }
.suggest__titel { font-weight: 600; font-size: .92rem; }
.suggest__pfad { font-size: .76rem; color: var(--c-ink-soft); }
.suggest__item--alle { border-top: 1px solid var(--c-border); margin-top: .25rem; }
.suggest__item--alle > a { color: var(--c-link); font-size: .85rem; }

/* --- Startseite ------------------------------------------------------ */
.startseite-hero { margin-bottom: 2.5rem; }
.startseite-hero h1 { font-size: 2.1rem; margin-bottom: .5rem; }
.startseite-suche {
  position: relative; display: flex; gap: .5rem; margin-top: 1.25rem; max-width: var(--max-text);
}
.startseite-suche input {
  flex: 1; padding: .6rem .85rem; font-size: 1rem;
  border: 1px solid var(--c-border); border-radius: 8px;
  background: var(--c-bg); color: var(--c-ink);
}
.startseite-suche button {
  padding: .6rem 1.2rem; border: 1px solid var(--c-brand); background: var(--c-brand);
  color: #fff; border-radius: 8px; cursor: pointer; font: inherit;
}
.startseite-suche .suggest { max-width: none; top: calc(100% + .35rem); }

/* --- Automatische Begriffsverlinkung ---------------------------- */
a.glossar-link {
  color: inherit; text-decoration: none;
  border-bottom: 1px dotted var(--c-glossar-underline);
}
a.glossar-link:hover { border-bottom-color: var(--c-link); color: var(--c-link); }

/* --- Artikelkopf / Meta ------------------------------------------- */
.article__header { margin-bottom: 1.75rem; }
.article__header h1 { margin-bottom: .4rem; }
.article__review-hinweis {
  margin: .8rem 0; padding: .5rem .85rem; font-size: .9rem;
  background: var(--c-badge-review-bg); color: var(--c-badge-review-ink);
  border-radius: 6px; max-width: var(--max-text);
}
.article__meta {
  gap: .4rem .6rem; margin-top: 1rem; margin-bottom: 0; font-size: .8rem;
}
.article__meta .meta-item {
  padding: .12rem .5rem; border: 1px solid var(--c-border); border-radius: 999px;
  color: var(--c-ink-soft); white-space: nowrap;
}
.article__meta .meta-item--ki { border-color: var(--c-badge-ki-bg); color: var(--c-badge-ki-ink); background: var(--c-badge-ki-bg); }
.article__header .lede { margin-top: .2rem; }

/* --- Quellen / Siehe auch --------------------------------------- */
.quellen-liste, .siehe-auch-liste { font-family: var(--font-sans); font-size: .95rem; }
.quellen-liste li { margin: .35rem 0; }
.siehe-auch-liste { list-style: none; padding-left: 0; display: flex; flex-wrap: wrap; gap: .4rem .9rem; }
.siehe-auch-liste a { text-decoration: none; border-bottom: 1px solid currentColor; }

a.chip { text-decoration: none; }
a.chip:hover { border-color: var(--c-brand); color: var(--c-ink); }
.article__herkunft { margin-top: 1.2rem; font-size: .8rem; }

/* --- Anker-Links an Ueberschriften ------------------------------ */
.prose h2, .prose h3 { position: relative; scroll-margin-top: 4.5rem; }
.heading-anchor {
  position: absolute; left: -1.1rem; top: 0; padding-right: .35rem;
  color: var(--c-ink-soft); text-decoration: none; opacity: 0;
  transition: opacity .12s ease; font-weight: 400;
}
.prose h2:hover .heading-anchor,
.prose h3:hover .heading-anchor,
.heading-anchor:focus { opacity: 1; }
@media (max-width: 700px) { .heading-anchor { display: none; } }

/* --- Inhaltsverzeichnis: aktiver Abschnitt --------------------- */
.toc a.is-current { color: var(--c-brand); font-weight: 600; }

/* --- Kategoriebaum als aufklappbare Box (mobil) --------------- */
.sidebar { border: none; }
.sidebar__toggle {
  display: none; font-family: var(--font-sans); font-weight: 600; font-size: .9rem;
  padding: .5rem .7rem; border: 1px solid var(--c-border); border-radius: 6px;
  cursor: pointer; list-style: none; margin-bottom: .5rem;
}
.sidebar__toggle::-webkit-details-marker { display: none; }
.sidebar > nav { display: block; }
@media (max-width: 980px) {
  .sidebar__toggle { display: block; }
  .sidebar:not([open]) > nav { display: none; }
}

/* --- Glossarseite ---------------------------------------------- */
.glossar-az {
  display: flex; flex-wrap: wrap; gap: .3rem; margin: 1.25rem 0 2rem;
  font-family: var(--font-sans);
}
.glossar-az a {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 2rem; height: 2rem; padding: 0 .4rem;
  border: 1px solid var(--c-border); border-radius: 6px;
  text-decoration: none; color: var(--c-link); font-weight: 600; font-size: .9rem;
}
.glossar-az a:hover { border-color: var(--c-brand); background: var(--c-surface); }
.glossar-gruppe { margin: 2rem 0; }
.glossar-gruppe > h2 {
  font-size: 1.1rem; color: var(--c-brand-ink); border-bottom: 1px solid var(--c-border);
  padding-bottom: .2rem; scroll-margin-top: 4.5rem;
}
.glossar-liste { margin: .75rem 0 0; }
.glossar-liste dt { font-weight: 600; margin-top: .9rem; }
.glossar-liste dt a { text-decoration: none; }
.glossar-liste dt a:hover { text-decoration: underline; }
.glossar-liste dd { margin: .15rem 0 0; color: var(--c-ink-soft); max-width: var(--max-text); }

/* --- Suchtreffer-Hervorhebung angleichen ---------------------- */
.such-treffer__ausschnitt mark,
.prose mark { background: var(--c-mark-bg); color: var(--c-mark-ink); padding: 0 .12em; border-radius: 2px; }

/* --- Druckansicht (Browser -> PDF; WeasyPrint folgt in 3b) --- */
@media print {
  .site-header, .site-footer, .sidebar, .toc-column,
  .article__footer, .heading-anchor, .suggest { display: none !important; }
  .layout { display: block; max-width: none; margin: 0; padding: 0; }
  body { font-size: 11pt; color: #000; background: #fff; }
  .prose { max-width: none; }
  a { color: #000; text-decoration: none; }
  .prose a[href^="http"]::after { content: " (" attr(href) ")"; font-size: .85em; word-break: break-all; }
  .article__review-hinweis { border: 1px solid #000; }
  h1, h2, h3 { page-break-after: avoid; }
  pre, blockquote, table, figure { page-break-inside: avoid; }
}
