:root {
  --bg: #f4f5f1;
  --surface: #ffffff;
  --text: #1d211c;
  --muted: #646b62;
  --border: #dfe2da;
  --accent: #3d7a2e;
  --accent-text: #ffffff;
  --krise: #c0392b;
  --normal: #6b7a8f;
  --boom: #2e8b3d;
  --up: #2e8b3d;
  --down: #c0392b;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141713;
    --surface: #1d211c;
    --text: #e8ebe5;
    --muted: #9aa197;
    --border: #2f352d;
    --accent: #6cb35a;
    --accent-text: #0f140e;
    --krise: #e5675a;
    --normal: #9aa8bb;
    --boom: #6cc27a;
    --up: #6cc27a;
    --down: #e5675a;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}

.top {
  display: flex; flex-wrap: wrap; gap: 12px;
  align-items: center; justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
h1 { margin: 0; font-size: 20px; }
h2 { margin: 0 0 12px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

main { max-width: 1200px; margin: 0 auto; padding: 24px; display: grid; gap: 16px; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 18px; min-width: 0; }
.card-head { display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.card-head h2 { margin: 0; }

button {
  font: inherit; cursor: pointer;
  border: 1px solid var(--accent); border-radius: 7px;
  background: var(--accent); color: var(--accent-text);
  padding: 8px 14px; font-weight: 600;
}
button.secondary { background: transparent; color: var(--accent); }
button.icon { border: none; background: none; color: var(--muted); padding: 4px 6px; font-weight: 400; }
button.icon:hover { color: var(--text); }
button:disabled { opacity: .5; cursor: wait; }
input {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 7px; padding: 7px 10px; min-width: 0;
}
.add-form { display: flex; gap: 8px; flex-wrap: wrap; }
.add-form input[name=name] { width: 160px; }
.add-form input[name=base_price] { width: 130px; }

/* Periode */
.period { border-top: 4px solid var(--period-color, var(--normal)); }
.period-name { font-size: 34px; font-weight: 700; color: var(--period-color, var(--normal)); margin-bottom: 10px; }
.kv { margin: 0; display: grid; gap: 6px; }
.kv div { display: flex; justify-content: space-between; gap: 12px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; font-weight: 600; }

.probs { display: grid; gap: 10px; }
.prob-row { display: grid; grid-template-columns: 70px 1fr 48px; align-items: center; gap: 10px; }
.prob-bar { height: 10px; border-radius: 5px; background: var(--border); overflow: hidden; }
.prob-bar span { display: block; height: 100%; border-radius: 5px; transition: width .3s; }
.prob-row .pct { text-align: right; font-variant-numeric: tabular-nums; }
.note { color: var(--muted); font-size: 13px; margin: 12px 0 0; }

.history { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; max-height: 190px; overflow: auto; }
.history li { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; }
.history time { color: var(--muted); font-variant-numeric: tabular-nums; }
.tag { font-weight: 600; }
.tag.krise { color: var(--krise); } .tag.normal { color: var(--normal); } .tag.boom { color: var(--boom); }

/* Tabelle */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
th { font-size: 12px; color: var(--muted); font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.price { font-weight: 700; }
.up { color: var(--up); } .down { color: var(--down); }
.hint { font-size: 13px; font-weight: 600; }
td input { width: 110px; }
svg.spark { display: block; }
svg.spark path { fill: none; stroke: var(--muted); stroke-width: 1.5; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-weight: 600;
}

@media (max-width: 600px) {
  .top, main { padding-left: 16px; padding-right: 16px; }
  .actions, .actions button { width: 100%; }
}

/* Trendlinie klickbar */
button.spark-btn { border: 1px solid transparent; background: none; padding: 2px 4px; border-radius: 6px; }
button.spark-btn:hover, button.spark-btn:focus-visible { border-color: var(--border); background: var(--bg); }
button.spark-btn:hover svg.spark path { stroke: var(--accent); }
button.link { border: none; background: none; padding: 0; color: inherit; font-weight: inherit; text-align: left; }
button.link:hover { color: var(--accent); text-decoration: underline; }

/* Modal */
.modal {
  width: min(960px, calc(100vw - 32px)); max-height: calc(100vh - 32px);
  padding: 20px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); color: var(--text);
}
.modal::backdrop { background: rgb(0 0 0 / .45); }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.modal-kicker { margin-bottom: 2px; }
.modal-title { font-size: 22px; font-weight: 700; }
.close { font-size: 18px; }
.stats { display: flex; flex-wrap: wrap; gap: 8px 28px; margin: 14px 0 10px; }
.stat dt { font-size: 12px; color: var(--muted); }
.stat dd { margin: 0; font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid line { stroke: var(--border); stroke-width: 1; }
.chart .axis text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .base { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 4 4; }
.chart .base-label { fill: var(--muted); font-size: 11px; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .band { opacity: .12; }
.chart .band-label { font-size: 11px; fill: var(--muted); }
.chart .cross { stroke: var(--muted); stroke-width: 1; }
.chart .dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart .empty { fill: var(--muted); font-size: 13px; }
.tooltip {
  position: absolute; pointer-events: none; z-index: 2;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; font-size: 13px; box-shadow: 0 4px 16px rgb(0 0 0 / .12);
  white-space: nowrap; font-variant-numeric: tabular-nums;
}
.tooltip .tt-price { font-weight: 700; font-size: 15px; }
.tooltip .tt-muted { color: var(--muted); }
.chart-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12px; color: var(--muted); margin: 6px 0 12px; }
.chart-legend .sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -2px; margin-right: 5px; }
.chart-legend .sw.line { height: 2px; vertical-align: 3px; background: var(--accent); }
.chart-legend .sw.dash { height: 0; border-top: 1px dashed var(--muted); vertical-align: 3px; }
.modal-table { max-height: 260px; overflow: auto; border-top: 1px solid var(--border); }
.modal-table thead th { position: sticky; top: 0; background: var(--surface); }
.modal-table tr.active td { background: var(--bg); }

/* Links als Button */
a.btn {
  display: inline-block; text-decoration: none; font-weight: 600;
  border: 1px solid var(--accent); border-radius: 7px; padding: 8px 14px;
  background: var(--accent); color: var(--accent-text);
}
a.btn.secondary { background: transparent; color: var(--accent); }

/* Einstellungen */
.settings { max-width: 900px; }
.settings .card p.lead { margin: -4px 0 14px; color: var(--muted); font-size: 14px; }
.settings input[type=number] { width: 84px; text-align: right; font-variant-numeric: tabular-nums; }
.settings td, .settings th { white-space: nowrap; }
.settings .sep { color: var(--muted); padding: 0 4px; }
.fields { display: grid; gap: 12px; }
.field { display: grid; grid-template-columns: 200px auto; align-items: center; gap: 4px 12px; }
.field label { font-weight: 600; }
.field .help { grid-column: 2; color: var(--muted); font-size: 13px; }
.unit { color: var(--muted); margin-left: 4px; }
.savebar {
  position: sticky; bottom: 0; display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  padding: 12px 0; background: var(--bg); border-top: 1px solid var(--border);
}
.savebar .status { color: var(--muted); font-size: 14px; margin-left: auto; }
.errors { white-space: pre-line; color: var(--down); font-weight: 600; margin: 0; }
.errors:empty { display: none; }
input.invalid { border-color: var(--down); }

/* Bandvorschau */
.bands { display: grid; gap: 10px; margin-top: 16px; }
.band-row { display: grid; grid-template-columns: 70px 1fr; gap: 10px; align-items: center; }
.track { position: relative; height: 18px; border-radius: 4px; background: var(--bg); border: 1px solid var(--border); }
.track .span { position: absolute; top: 7px; height: 2px; background: var(--muted); }
.track .seg { position: absolute; top: 2px; height: 12px; border-radius: 3px; opacity: .85; }
.track .one { position: absolute; top: -3px; bottom: -3px; width: 1px; background: var(--text); opacity: .4; }
.scale { display: grid; grid-template-columns: 70px 1fr; gap: 10px; }
.scale .ticks { position: relative; height: 16px; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.scale .ticks span { position: absolute; transform: translateX(-50%); }

@media (max-width: 600px) {
  .field { grid-template-columns: 1fr; }
  .field .help { grid-column: 1; }
}

/* Gefahrenbereich */
.card.danger { border-color: color-mix(in srgb, var(--down) 45%, var(--border)); }
button.danger-btn { background: transparent; color: var(--down); border-color: var(--down); }
button.danger-btn:hover { background: var(--down); color: var(--surface); }
