:root {
  --bg: #0b0d10;
  --surface: #15181d;
  --surface-2: #1e2229;
  --line: #2a2f37;
  --text: #e9ebee;
  --muted: #9aa1ab;
  --accent: #5aa2ff;
  --accent-2: #2f7de1;
  --ok: #3ccf6e;
  --warn: #ffb020;
  --bad: #ff5a4f;
  --trend: #5aa2ff;
  --soll: #e9ebee;
  --radius: 14px;
  --tabbar-h: 58px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
h1, h2, h3 { margin: 0; font-weight: 650; }
h1 { font-size: 28px; letter-spacing: -0.02em; }
h2 { font-size: 18px; margin-bottom: 12px; }
h3 { font-size: 15px; margin-bottom: 8px; color: var(--muted); font-weight: 600; }
p { margin: 8px 0; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.center { text-align: center; }

/* Layout */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) calc(env(safe-area-inset-right) + 16px) 10px calc(env(safe-area-inset-left) + 16px);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
}
.content {
  max-width: 640px; margin: 0 auto;
  padding: 8px calc(env(safe-area-inset-right) + 12px) calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px) calc(env(safe-area-inset-left) + 12px);
}
[data-route="onboarding"] .content { padding-top: calc(env(safe-area-inset-top) + 32px); }
.view { display: flex; flex-direction: column; gap: 12px; }
.onboarding h1 { margin-bottom: 4px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; justify-content: space-around;
  padding: 6px env(safe-area-inset-right) calc(env(safe-area-inset-bottom) + 4px) env(safe-area-inset-left);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 4px 0; color: var(--muted); text-decoration: none; font-size: 11px; font-weight: 600;
}
.tabbar a.active { color: var(--accent); }
.tabbar svg, .icon-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.card {
  background: var(--surface); border-radius: var(--radius); padding: 16px;
  border: 1px solid var(--line);
}
.card.empty { text-align: center; }
.card.empty .btn { margin-top: 8px; }
.section { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--line); }

.banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 12px; border-radius: var(--radius);
  background: color-mix(in srgb, var(--warn) 14%, var(--surface)); border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent);
  font-size: 14px;
}

/* Buttons */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  font: inherit; font-weight: 600; padding: 12px 16px; border-radius: 12px; min-height: 46px;
  cursor: pointer; width: 100%;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
.btn.danger-outline { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 50%, transparent); background: transparent; }
.btn.small { width: auto; min-height: 34px; padding: 6px 12px; font-size: 14px; }
.btn:disabled { opacity: 0.45; }
.icon-btn {
  appearance: none; background: none; border: 0; color: var(--muted); font-size: 18px;
  width: 40px; height: 40px; display: inline-grid; place-items: center; border-radius: 10px; cursor: pointer;
}
.icon-btn.active { color: var(--accent); }
.link { background: none; border: 0; color: var(--accent); font: inherit; font-weight: 600; padding: 0 0 0 12px; cursor: pointer; }
.actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.actions .btn { flex: 1 1 0; }

/* Formulare */
.form { display: flex; flex-direction: column; gap: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label { font-size: 13px; color: var(--muted); font-weight: 600; }
.field-input {
  display: flex; align-items: center; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 12px; padding: 0 12px; min-height: 48px;
}
.field-input:focus-within { border-color: var(--accent); }
.field-input input {
  flex: 1; min-width: 0; background: none; border: 0; color: var(--text); outline: none;
  font: inherit; font-size: 18px; font-variant-numeric: tabular-nums; padding: 12px 0;
}
.field-input input[type="date"], .field-input input[type="datetime-local"] { font-size: 16px; color-scheme: dark; }
.unit { color: var(--muted); font-size: 14px; margin-left: 6px; }
.field-error { color: var(--bad); font-size: 13px; min-height: 0; }
.field-error:empty { display: none; }

.segmented {
  display: flex; background: var(--surface-2); border-radius: 11px; padding: 3px; gap: 2px; border: 1px solid var(--line);
}
.segmented button {
  flex: 1; appearance: none; border: 0; background: none; color: var(--muted); font: inherit; font-size: 14px; font-weight: 600;
  padding: 8px 10px; border-radius: 8px; cursor: pointer; white-space: nowrap;
}
.segmented button.active { background: var(--line); color: var(--text); }
.scroll-x { overflow-x: auto; margin: 0 -4px 12px; padding: 0 4px; scrollbar-width: none; }
.scroll-x::-webkit-scrollbar { display: none; }
.range { margin-top: 8px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  appearance: none; border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  font: inherit; font-size: 13px; padding: 6px 10px; border-radius: 999px; cursor: pointer;
}

/* Werte */
.preview { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.preview > .muted { grid-column: 1 / -1; }
.mini-stat { background: var(--surface-2); border-radius: 12px; padding: 10px; border: 1px solid var(--line); }
.mini-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.mini-value { font-size: 18px; font-weight: 650; font-variant-numeric: tabular-nums; }
.mini-sub { font-size: 11px; color: var(--muted); }

.headline { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; margin-bottom: 8px; }
.big { font-size: 40px; font-weight: 700; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; line-height: 1.05; }
.big-unit { font-size: 18px; color: var(--muted); font-weight: 600; }
.deltas { display: flex; gap: 14px; text-align: right; }
.delta-v { font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }

.pill {
  display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap;
  background: var(--surface-2); color: var(--muted);
}
.pill.ok { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.pill.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.pill.bad { background: color-mix(in srgb, var(--bad) 18%, transparent); color: var(--bad); }

.note { font-size: 14px; padding: 8px 10px; border-radius: 10px; background: var(--surface-2); }
.note.critical { color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, transparent); }
.note.info { color: var(--muted); }

.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0; font-size: 14px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; text-align: right; }

/* Listen */
.mlist { list-style: none; margin: 0; padding: 0; }
.mlist li + li { border-top: 1px solid var(--line); }
.mrow {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 2px;
  appearance: none; background: none; border: 0; color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.mrow.static { cursor: default; }
.mdate { flex: 1; font-size: 14px; color: var(--muted); }
.mvals { font-variant-numeric: tabular-nums; font-size: 15px; text-align: right; }
.chev { color: var(--muted); font-size: 20px; }

/* Plan */
.plan-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.plan-head h2 { margin-bottom: 2px; }
.plan-goal { display: flex; align-items: baseline; gap: 10px; font-size: 22px; margin: 12px 0 4px; font-variant-numeric: tabular-nums; }
.plan-goal .arrow { color: var(--muted); }
.progress-wrap { margin: 8px 0; }
.progress { position: relative; height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-bottom: 6px; }
.progress .bar { height: 100%; background: var(--accent); border-radius: 999px; }
.progress .bar.neg { background: var(--bad); width: 4px !important; }
.progress .tick { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--text); opacity: 0.6; }
.stones { list-style: none; margin: 0; padding: 0; font-size: 14px; }
.stones li { display: grid; grid-template-columns: 48px 1fr auto; gap: 8px; padding: 6px 0; font-variant-numeric: tabular-nums; }
.stones li.reached span:first-child { color: var(--ok); font-weight: 700; }
.eval { display: flex; flex-direction: column; gap: 4px; }

/* Diagramm */
.chart { width: 100%; height: auto; display: block; margin-top: 4px; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
.chart .pt { fill: var(--muted); opacity: 0.85; }
.chart .trend { fill: none; stroke: var(--trend); stroke-width: 2.4; stroke-linejoin: round; stroke-linecap: round; }
.chart .soll { fill: none; stroke: var(--soll); stroke-width: 1.4; stroke-dasharray: 5 4; opacity: 0.8; }
.chart .corridor { fill: var(--ok); opacity: 0.14; }
.chart .corridor-outer { fill: var(--warn); opacity: 0.07; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--muted); margin-top: 4px; }
.legend span::before { content: ""; display: inline-block; vertical-align: middle; margin-right: 5px; }
.lg-pt::before { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); }
.lg-trend::before { width: 14px; height: 3px; border-radius: 2px; background: var(--trend); }
.lg-soll::before { width: 14px; border-top: 2px dashed var(--soll); }
.lg-band::before { width: 12px; height: 10px; background: color-mix(in srgb, var(--ok) 30%, transparent); border-radius: 2px; }

/* Sheet & Toast */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 20; background: rgb(0 0 0 / 0); display: flex; align-items: flex-end; justify-content: center;
  transition: background 0.2s;
}
.sheet-backdrop.open { background: rgb(0 0 0 / 0.55); }
.sheet {
  width: 100%; max-width: 640px; max-height: 92dvh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--surface); border-radius: 18px 18px 0 0; border: 1px solid var(--line); border-bottom: 0;
  padding: 0 16px calc(env(safe-area-inset-bottom) + 20px);
  transform: translateY(100%); transition: transform 0.22s ease-out;
}
.sheet-backdrop.open .sheet { transform: none; }
.sheet-head {
  position: sticky; top: 0; z-index: 1; display: flex; justify-content: space-between; align-items: center;
  padding: 14px 0 10px; background: var(--surface);
}
.sheet-head h2 { margin: 0; }
.sheet-body > * + * { margin-top: 12px; }
.sheet-body .form .btn + .btn { margin-top: 0; }

#toast {
  position: fixed; left: 50%; z-index: 30; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 14px);
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  display: flex; align-items: center; max-width: calc(100% - 32px);
  background: var(--surface-2); border: 1px solid var(--line); color: var(--text);
  padding: 10px 14px; border-radius: 12px; font-size: 14px; box-shadow: 0 8px 30px rgb(0 0 0 / 0.4);
  transition: opacity 0.2s, transform 0.2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
