:root {
  color-scheme: light;
  --bg: #f4f3f0;
  --surface: #fcfcfb;
  --surface-2: #efeee9;
  --border: #dddcd5;
  --text: #121211;
  --text-2: #52514e;
  --muted: #706f69;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --warn-bg: #fdf0d5;
  --warn-ink: #7a4b00;
  --danger: #c43c3b;
  --grid: #e6e5df;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s8: #e34948;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  --radius: 10px;
  --font: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211; --surface: #1a1a19; --surface-2: #242422; --border: #34342f;
    --text: #f4f3ef; --text-2: #c3c2b7; --muted: #9a998f; --accent: #3987e5;
    --warn-bg: #3a2c0c; --warn-ink: #f2c46b; --danger: #e66767; --grid: #2b2b28;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #242422; --border: #34342f;
  --text: #f4f3ef; --text-2: #c3c2b7; --muted: #9a998f; --accent: #3987e5;
  --warn-bg: #3a2c0c; --warn-ink: #f2c46b; --danger: #e66767; --grid: #2b2b28;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; font-weight: 600; }
h2 { font-size: 1.05rem; }
.small { font-size: .85rem; }
.muted { color: var(--muted); }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* Kopfzeile */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .6rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 600; color: var(--text); text-decoration: none; font-size: 1.05rem; }
.brand-mark { width: 18px; height: 18px; border-radius: 5px; background: linear-gradient(135deg, var(--s1) 0 50%, var(--s2) 50% 100%); }
.topnav { display: flex; align-items: center; gap: 1rem; }
.topnav a { color: var(--text-2); text-decoration: none; }
.topnav a[aria-current="page"] { color: var(--text); font-weight: 600; }
.icon-btn { background: none; border: 1px solid var(--border); color: var(--text); border-radius: 8px; width: 34px; height: 34px; cursor: pointer; font-size: 1rem; }

.scenario-bar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .75rem;
  padding: .75rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border); }
.scenario-title { display: flex; align-items: baseline; gap: .75rem; min-width: 0; flex: 1 1 260px; }
.title-input { font: 600 1.15rem var(--font); color: var(--text); background: transparent; border: 1px solid transparent;
  border-radius: 6px; padding: .2rem .35rem; min-width: 0; width: 100%; max-width: 32rem; }
.title-input:hover, .title-input:focus { border-color: var(--border); outline: none; }
.scenario-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; }

/* Bedienelemente */
.btn { font: 500 .9rem var(--font); background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: .4rem .75rem; cursor: pointer; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--danger); }
.btn.small { padding: .25rem .55rem; font-size: .82rem; }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.segmented button { font: 500 .88rem var(--font); background: transparent; color: var(--text-2); border: 0; padding: .4rem .7rem; cursor: pointer; }
.segmented button + button { border-left: 1px solid var(--border); }
.segmented button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.segmented.small button { font-size: .8rem; padding: .25rem .55rem; }
.switch { display: inline-flex; align-items: center; gap: .35rem; font-size: .9rem; cursor: pointer; user-select: none; }
.switch.small { font-size: .82rem; }
.menu { position: relative; }
.menu-panel { position: absolute; right: 0; top: calc(100% + 4px); background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.15); padding: .35rem; min-width: 230px; z-index: 30; }
.menu-panel button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: .45rem .6rem; border-radius: 6px;
  color: var(--text); font: .9rem var(--font); cursor: pointer; }
.menu-panel button:hover { background: var(--surface-2); }
.menu-panel hr { border: 0; border-top: 1px solid var(--border); margin: .3rem 0; }

/* Layout */
.layout { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 1rem; padding: 1rem; max-width: 1600px; margin: 0 auto; }
.sidebar { position: sticky; top: 64px; align-self: start; max-height: calc(100vh - 80px); overflow: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem 1rem 1rem; }
.main { display: flex; flex-direction: column; gap: 1rem; min-width: 0; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .5rem; margin-bottom: .5rem; }
.card-head h2 { margin: 0; }
.row-actions { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.chart-wrap { position: relative; height: 300px; }
.chart-wrap.tall { height: 380px; }
.chart-note { margin-top: .35rem; min-height: 1.2em; }

/* Regler */
.ctl-section { border-top: 1px solid var(--border); padding-top: .6rem; margin-top: .6rem; }
.ctl-section:first-child { border-top: 0; margin-top: 0; padding-top: 0; }
.ctl-section > summary { font-weight: 600; cursor: pointer; list-style: none; display: flex; justify-content: space-between; }
.ctl-section > summary::after { content: "▸"; color: var(--muted); }
.ctl-section[open] > summary::after { content: "▾"; }
.ctl { margin: .6rem 0; }
.ctl-label { display: flex; justify-content: space-between; gap: .5rem; font-size: .88rem; color: var(--text-2); }
.ctl-label output { font-family: var(--mono); color: var(--text); }
.ctl-help { font-size: .78rem; color: var(--muted); margin-top: .1rem; }
.ctl input[type="range"] { width: 100%; accent-color: var(--accent); }
.ctl select, .field input, .field select, .field textarea {
  font: .9rem var(--font); color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; padding: .3rem .45rem; width: 100%; }
.ctl select { margin-top: .2rem; }

/* Kennzahlen */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .6rem .8rem; }
.kpi .label { font-size: .78rem; color: var(--muted); }
.kpi .value { font: 500 1.35rem var(--mono); color: var(--text); }
.kpi .sub { font-size: .78rem; color: var(--text-2); }

/* Zeitleiste */
.timeline-wrap { margin-top: .4rem; overflow: hidden; }
.timeline { width: 100%; display: block; }
.timeline .tl-axis { stroke: var(--border); }
.timeline .tl-tick { fill: var(--muted); font: 11px var(--mono); }
.timeline .tl-ev { cursor: pointer; }
.timeline .tl-ev rect { rx: 3; }
.timeline .tl-ev.off rect { opacity: .25; }
.timeline .tl-ev:hover rect, .timeline .tl-ev:focus rect { stroke: var(--text); stroke-width: 1.5; }
.timeline .tl-ev text { fill: var(--text-2); font: 11px var(--font); pointer-events: none; }

/* Tabellen */
.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .87rem; }
th, td { text-align: left; padding: .35rem .5rem; border-bottom: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
th { font-weight: 600; color: var(--text-2); font-size: .8rem; }
td.num, th.num { text-align: right; }
td input[type="number"] { width: 5.5rem; font: .85rem var(--mono); color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 5px; padding: .15rem .3rem; }
td input[type="text"] { width: 12rem; font: .85rem var(--font); color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 5px; padding: .15rem .3rem; }
.linklike { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font: inherit; text-align: left; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: .4rem; vertical-align: -1px; }
.badge { display: inline-block; font-size: .72rem; padding: .05rem .4rem; border-radius: 999px; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }
.badge.warn { background: var(--warn-bg); color: var(--warn-ink); border-color: transparent; }
.cat-chip { font-size: .75rem; color: var(--muted); }

/* Dialog */
.dialog { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text); padding: 1.1rem 1.2rem;
  width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 32px); }
.dialog::backdrop { background: rgba(0,0,0,.4); }
.dialog-actions { display: flex; gap: .5rem; margin-top: 1rem; align-items: center; }
.spacer { flex: 1; }
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem .9rem; }
.field { display: flex; flex-direction: column; gap: .15rem; font-size: .85rem; color: var(--text-2); }
.field.wide { grid-column: 1 / -1; }
.field .help { font-size: .76rem; color: var(--muted); }
.source-list { font-size: .8rem; color: var(--text-2); margin: .5rem 0 0; padding-left: 1.1rem; }

.toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: .5rem .9rem; border-radius: 8px; font-size: .9rem; z-index: 50; max-width: calc(100vw - 32px); }

/* Methodik */
.prose { max-width: 900px; margin: 0 auto; padding: 1.5rem 16px 4rem; }
.prose h1 { font-size: 1.7rem; margin-bottom: 1rem; }
.prose h2 { font-size: 1.25rem; margin-top: 2rem; }
.prose h3 { font-size: 1.05rem; margin-top: 1.4rem; }
.prose p, .prose li { color: var(--text); }
.prose .formula { font-family: var(--mono); background: var(--surface-2); border-radius: 8px; padding: .6rem .8rem; overflow-x: auto; white-space: pre; font-size: .88rem; }
.prose table { margin: .8rem 0; }
.prose td { white-space: normal; }
.callout { border-left: 4px solid var(--s4); background: var(--warn-bg); color: var(--warn-ink); padding: .7rem .9rem; border-radius: 6px; margin: 1rem 0; }
.toc { columns: 2; font-size: .92rem; }

@media (max-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 16px; }
  .sidebar { position: static; max-height: none; order: 2; }
  .main { order: 1; }
  .chart-wrap.tall { height: 320px; }
  .chart-wrap { height: 260px; }
  .topbar, .scenario-bar { padding-left: 16px; padding-right: 16px; }
  .fields { grid-template-columns: minmax(0, 1fr); }
  .toc { columns: 1; }
}
