/* FinHub: mobil zuerst, helles und dunkles Schema.
   Chart-Farben: blau (Bedarf), orange (Vermögen), grün (Vermögen + Sparpläne). Geprüft mit dem Palette-Validator
   (alle Paare, Farbfehlsichtigkeit): hell #257de0/#f47230/#006c10, dunkel #338ced/#bf4d16/#3cb850.
   Zusätzlich unterscheiden Linienart (gestrichelt/durchgezogen/dick + Fläche), Legende und Beschriftung. */

/* hidden muss auch gegen display-Regeln (z. B. .form label) gewinnen */
[hidden] { display: none !important; }

:root {
  color-scheme: light;
  --page: #f9f9f9;
  --surface: #ffffff;
  --text: #191919;
  --text-2: #666666;
  --grid: #e7e7e7;
  --axis: #c2c2c2;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #257de0;
  --accent-text: #1b64be;
  --series-need: #257de0;
  --series-wealth: #f47230;
  --series-total: #006c10;
  --series-total-band: rgba(0, 108, 16, 0.10);
  --series-ist: #191919;
  --good: #0aac23;
  --good-text: #006c10;
  --warning: #fbb315;
  --critical: #dc3c3d;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0b0b0b;
    --surface: #191919;
    --text: #efefef;
    --text-2: #9c9c9c;
    --grid: #303030;
    --axis: #474747;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #338ced;
    --accent-text: #6aabf1;
    --series-need: #338ced;
    --series-wealth: #bf4d16;
    --series-total: #3cb850;
    --series-total-band: rgba(60, 184, 80, 0.14);
    --series-ist: #efefef;
    --good-text: #53c556;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--page);
  color: var(--text);
}
a { color: var(--accent-text); }
h1 { font-size: 1.5rem; margin: 0.25rem 0 0.75rem; }
h2 { font-size: 1.1rem; margin: 0 0 0.5rem; }
.container { max-width: 760px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--text-2); }
.small, small { font-size: 0.85rem; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.head { margin-top: 8px; }
.back { display: inline-block; margin: 12px 0 4px; text-decoration: none; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 4px 12px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 1.15rem; color: var(--text); text-decoration: none; }
.nav { display: flex; gap: 2px; overflow-x: auto; max-width: 100%; }
.nav a { padding: 8px 10px; border-radius: 8px; text-decoration: none; color: var(--text-2); white-space: nowrap; min-height: 40px; display: inline-flex; align-items: center; }
.nav a.active { color: var(--text); background: var(--page); }

.card {
  display: block; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin: 12px 0; color: inherit;
}
.goal-card { text-decoration: none; }
.goal-card h2, .goal-card h3 { margin: 0; }
.goal-card h3 { font-size: 1.05rem; display: flex; align-items: center; gap: 8px; }
.goal-card .meter { margin: 6px 0; }
.goal-card p { margin: 6px 0 0; }
.nr {
  display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; flex: none;
  font-size: 0.75rem; font-weight: 700; color: var(--series-need); border: 2px solid var(--series-need);
}
.big { font-size: 1.6rem; font-weight: 700; margin: 8px 0 6px; }
.big small { font-size: 0.9rem; font-weight: 400; color: var(--text-2); }

/* Deckungsbalken je Ziel: orange = aus dem Vermögen, grün = zusätzlich aus Sparplänen, Rest = Lücke. */
.meter { height: 10px; border-radius: 5px; background: var(--grid); overflow: hidden; display: flex; gap: 2px; }
.meter > .m-wealth { height: 100%; background: var(--series-wealth); }
.meter > .m-plans { height: 100%; background: var(--series-total); }
.meter-legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 0.8rem; color: var(--text-2); }
.meter-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
.meter-legend .k-wealth { background: var(--series-wealth); }
.meter-legend .k-plans { background: var(--series-total); }
.meter-legend .k-gap { background: var(--grid); }
.gap-line { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.gap-line b { font-variant-numeric: tabular-nums; }
.plan-card .row h3 { margin: 0; font-size: 1.05rem; }
.suggest { display: flex; flex-direction: column; gap: 8px; }
.suggest .btn { align-self: flex-start; }

.badge {
  display: inline-flex; align-items: center; gap: 4px; white-space: nowrap;
  font-size: 0.85rem; font-weight: 600; padding: 3px 10px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--page);
}
.badge span { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; color: #fff; font-size: 0.75rem; }
.badge.good span { background: var(--good); }
.badge.warning span { background: var(--warning); color: #0b0b0b; }
.badge.critical span { background: var(--critical); }
.badge.neutral span { background: var(--text-2); }
.status-card { border-left: 5px solid var(--text-2); }
.status-card.good { border-left-color: var(--good); }
.status-card.warning { border-left-color: var(--warning); }
.status-card.critical { border-left-color: var(--critical); }
.status-card p { margin: 0; }

.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; }
.kpi span { font-size: 0.8rem; color: var(--text-2); }
.kpi strong { font-size: 1.25rem; margin: 2px 0; }
.kpi small { color: var(--text-2); }
.kpi.accent { border-color: var(--accent); }
.hint { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; }
.warn-text { color: var(--critical); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 16px;
  border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--critical); }
.actions { justify-content: flex-start; margin: 12px 0; }
.actions.center { justify-content: center; }
.icon-btn { border: 0; background: none; color: var(--text-2); font-size: 1.3rem; min-width: 44px; min-height: 36px; cursor: pointer; }

.form { display: flex; flex-direction: column; gap: 14px; }
.form label, .inline-form label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 0.95rem; }
.form label small { font-weight: 400; color: var(--text-2); }
input[type="text"], input:not([type]), input[type="number"], input[type="date"], input[type="month"], select {
  font: inherit; min-height: 44px; padding: 8px 10px; border-radius: 10px;
  border: 1px solid var(--axis); background: var(--surface); color: var(--text); width: 100%;
}
input:focus-visible, .btn:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.seg { border: 0; padding: 0; margin: 0; display: flex; gap: 16px; flex-wrap: wrap; }
.seg legend { font-weight: 600; font-size: 0.95rem; margin-bottom: 4px; padding: 0; }
.seg label { flex-direction: row; align-items: center; gap: 6px; font-weight: 400; }
.seg input { width: 20px; height: 20px; }
.preview { background: var(--page); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; min-height: 1em; }
.preview:empty { display: none; }
.preview span { font-size: 0.8rem; color: var(--text-2); }
.preview strong { font-size: 1.3rem; }
.inline-form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: end; margin-bottom: 12px; }
.inline-form .btn { grid-column: 1 / -1; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { padding: 8px 6px; border-bottom: 1px solid var(--grid); text-align: left; white-space: nowrap; }
th { color: var(--text-2); font-weight: 600; font-size: 0.8rem; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
td.neg { color: var(--critical); }
td.pos { color: var(--good-text); }

/* Chart */
.chart { min-height: 260px; }
.chart-wrap { position: relative; }
.chart svg.plot { display: block; width: 100%; height: auto; touch-action: pan-y; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 0.85rem; color: var(--text-2); margin-bottom: 6px; }
.key { display: inline-block; vertical-align: middle; margin-right: 6px; }
svg.key { overflow: visible; }
.key-ist { width: 8px; height: 8px; border-radius: 50%; background: var(--series-ist); }
.key-goal { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--series-need); background: var(--surface); }
.grid { stroke: var(--grid); stroke-width: 1; }
.axis { stroke: var(--axis); stroke-width: 1; }
.tick { fill: var(--text-2); font-size: 11px; }
.need-line { fill: none; stroke: var(--series-need); stroke-width: 2; stroke-dasharray: 6 4; stroke-linejoin: round; }
.wealth-line { fill: none; stroke: var(--series-wealth); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.total-line { fill: none; stroke: var(--series-total); stroke-width: 3; stroke-linejoin: round; stroke-linecap: round; }
.total-band { fill: var(--series-total-band); stroke: none; }
.end-label { fill: var(--text); font-size: 11px; font-weight: 600; paint-order: stroke; stroke: var(--surface); stroke-width: 3px; }
.ist-line { fill: none; stroke: var(--series-ist); stroke-width: 1; stroke-dasharray: 1 3; }
.ist-dot { fill: var(--series-ist); stroke: var(--surface); stroke-width: 2; }
.goal-line { stroke: var(--axis); stroke-width: 1; stroke-dasharray: 2 3; }
.goal-mark circle { fill: var(--surface); stroke: var(--series-need); stroke-width: 2; }
.goal-mark text { fill: var(--text); font-size: 11px; font-weight: 700; }
.crosshair { stroke: var(--axis); stroke-width: 1; }
.hover-dot { fill: var(--series-wealth); stroke: var(--surface); stroke-width: 2; }
.hover-dot.ist { fill: var(--series-ist); }
.hover-dot.goal { fill: var(--series-need); }
.tip-row { display: inline-flex; align-items: center; gap: 2px; }
.table-view summary { cursor: pointer; font-size: 0.9rem; color: var(--text-2); min-height: 32px; }

.rechenweg summary { cursor: pointer; font-weight: 600; min-height: 32px; }
.rechenweg ul { margin: 8px 0 0; padding-left: 1.2em; }
.rechenweg li { margin: 4px 0; }
.tooltip {
  position: absolute; top: 4px; transform: translateX(-50%); pointer-events: none;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12); border-radius: 8px; padding: 6px 10px; font-size: 0.82rem; white-space: nowrap; z-index: 2;
}

.empty { text-align: center; padding: 24px 0; }
.empty p { max-width: 36em; margin: 0.75rem auto; }
.disclaimer { color: var(--text-2); font-size: 0.8rem; padding-top: 16px; padding-bottom: max(24px, env(safe-area-inset-bottom)); border-top: 1px solid var(--border); margin-top: 24px; }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 140%);
  max-width: calc(100% - 32px); background: var(--text); color: var(--surface);
  padding: 10px 16px; border-radius: 10px; font-size: 0.92rem; transition: transform 0.2s ease; z-index: 10;
}
.toast.show { transform: translate(-50%, 0); }
.toast.error { background: var(--critical); color: #fff; }

@media (min-width: 640px) {
  .kpis { grid-template-columns: repeat(3, 1fr); }
  .inline-form { grid-template-columns: 1fr 1fr auto; }
  .inline-form .btn { grid-column: auto; }
}
