:root {
  --bg: #f4f5f2;
  --surface: #ffffff;
  --surface-2: #eceee8;
  --text: #16201c;
  --muted: #66716b;
  --line: #dde1da;
  --accent: #1f6f5c;
  --accent-ink: #ffffff;
  --pos: #1f7a4d;
  --neg: #b4382f;
  --warn: #a8660b;
  --r-sicher: #3b7c9e;
  --r-maessig: #c08a2e;
  --r-unsicher: #b4553f;
  --radius: 12px;
  --gap: 16px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1720;
    --surface: #17212b;
    --surface-2: #1e2a36;
    --text: #e6ebe8;
    --muted: #93a09a;
    --line: #2a3744;
    --accent: #5cc0a2;
    --accent-ink: #0f1720;
    --pos: #5cc08a;
    --neg: #ef7b70;
    --warn: #e0a64a;
    --r-sicher: #6fb3d6;
    --r-maessig: #e0b45f;
    --r-unsicher: #e3836d;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: .02em; }
.top-actions { display: flex; align-items: center; gap: 8px; }

main { max-width: 980px; margin: 0 auto; padding: 16px; }

.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  text-align: center; padding: 14px 4px; color: var(--muted);
  text-decoration: none; font-size: 13px; font-weight: 600;
}
.tabs a.active { color: var(--accent); box-shadow: inset 0 2px 0 var(--accent); }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.warn { color: var(--warn); }
.err { color: var(--neg); }
.banner { background: var(--surface); border: 1px solid var(--neg); border-radius: var(--radius); padding: 12px; }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; margin-bottom: var(--gap);
}
.card h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 12px; font-weight: 700; }

.grid { display: grid; gap: var(--gap); }
@media (min-width: 760px) { .grid.two { grid-template-columns: 1fr 1fr; } }

.hero { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 16px; }
.hero .big { font-size: 34px; font-weight: 750; letter-spacing: -.01em; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin-top: 12px; }
.kpi { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.kpi .l { font-size: 12px; color: var(--muted); }
.kpi .v { font-size: 17px; font-weight: 650; white-space: nowrap; }

.bars { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 84px 1fr auto; gap: 10px; align-items: center; font-size: 14px; }
.bar { height: 10px; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 6px; background: var(--accent); }
.bar-row .num { text-align: right; white-space: nowrap; }
.stack { display: flex; height: 14px; border-radius: 7px; overflow: hidden; margin-bottom: 12px; }
.stack span { display: block; height: 100%; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 8px 0; border-bottom: 1px solid var(--line); display: flex; gap: 8px; }
.list li:last-child { border-bottom: 0; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
td:not(:first-child) { white-space: nowrap; }
th, td { padding: 9px 6px; border-bottom: 1px solid var(--line); text-align: right; vertical-align: top; }
th:first-child, td:first-child { text-align: left; }
th { font-size: 12px; color: var(--muted); font-weight: 600; }
tr.group td { background: var(--surface-2); font-weight: 650; }
td .sub { display: block; font-size: 12px; color: var(--muted); }
.table-wrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
@media (max-width: 560px) { .hide-sm { display: none; } }

.seg { display: inline-flex; background: var(--surface-2); border-radius: 9px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; color: var(--muted); padding: 6px 10px; border-radius: 7px; font: inherit; font-size: 13px; cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); font-weight: 650; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.chart-box { position: relative; height: 280px; }

form { display: grid; gap: 12px; }
.fields { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 600; }
input, select, textarea {
  font: inherit; font-size: 16px; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 9px; padding: 9px 10px; width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

button.primary, button.secondary {
  font: inherit; font-weight: 650; border-radius: 10px; padding: 11px 16px; cursor: pointer; border: 1px solid transparent;
}
button.primary { background: var(--accent); color: var(--accent-ink); }
button.secondary { background: transparent; color: var(--text); border-color: var(--line); }
button:disabled { opacity: .5; cursor: default; }
.icon-btn { background: transparent; border: 1px solid var(--line); color: var(--text); width: 34px; height: 34px; border-radius: 9px; cursor: pointer; font-size: 16px; }

.login { max-width: 420px; margin: 12vh auto 0; text-align: center; }
.login h1 { font-size: 28px; margin: 0 0 8px; }

.toast {
  position: fixed; left: 50%; bottom: calc(76px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 10;
}
.skeleton { color: var(--muted); padding: 40px 0; text-align: center; }

/* Zerlegung Kursgewinne / Sparen */
.zerl { margin: 8px 0 12px; border-top: 1px solid var(--line); }
.zr { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.zr > span:last-child { white-space: nowrap; text-align: right; }
.zr .sub { display: block; font-size: 12px; color: var(--muted); margin-left: 15px; }
.zr.gesamt { font-size: 15px; }
.zr.muted, .zr.muted .pos, .zr.muted .neg { color: var(--muted); }
.sub-h { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 14px 0 4px; }
.list.compact li { padding: 5px 0; font-size: 14px; }
.hide-lg { display: none; }
@media (max-width: 560px) { .hide-lg { display: block; } }

/* Globaler Zeitraum oben (ersetzt Header) */
.range-bar {
  position: sticky; top: 0; z-index: 5;
  padding: 8px 16px; padding-top: calc(8px + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.range-row { display: flex; align-items: center; gap: 8px; max-width: 948px; margin: 0 auto; }
.seg-full { display: flex; flex: 1; min-width: 0; }
.seg-full button { flex: 1; padding: 8px 4px; font-weight: 600; }
.privat-btn { flex: none; width: 44px; height: 38px; display: inline-flex; align-items: center; justify-content: center; }
.privat-btn .strich { display: none; }
html.privat .privat-btn { color: var(--accent); border-color: var(--accent); }
html.privat .privat-btn .strich { display: inline; }

/* Inkognito: Beträge und Mengen verwischt, Kurse und Prozente bleiben lesbar */
html.privat .geld { filter: blur(7px); -webkit-user-select: none; user-select: none; }

/* App-Sperre: deckt alles ab */
.lock { position: fixed; inset: 0; z-index: 50; background: var(--bg);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 24px; text-align: center; }
.lock[hidden] { display: none; }
.lock h1 { font-size: 24px; margin: 0; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
/* Ohne Header braucht der Inhalt oben Luft für die iOS-Statusleiste, wenn die Leiste ausgeblendet ist */
body:has(#range-bar[hidden]) main { padding-top: calc(16px + env(safe-area-inset-top)); }
.hero { flex-direction: column; align-items: flex-start; gap: 2px; }
.hero-delta { font-size: 18px; font-weight: 650; }
.hero-delta .muted { font-weight: 500; font-size: 15px; margin-left: 4px; }
.bar-row { align-items: start; }
.bar-row .bar { margin-top: 6px; }
.bar-row .num .delta { display: block; font-size: 12px; font-weight: 600; }
.bar-row .num .delta:not(.pos):not(.neg) { color: var(--muted); font-weight: 500; }

/* Klickbare Zeilen */
[data-detail] { cursor: pointer; }
tr[data-detail]:hover td, .bar-row[data-detail]:hover, li[data-detail]:hover { background: color-mix(in srgb, var(--accent) 7%, transparent); }
tr[data-detail]:active td, .bar-row[data-detail]:active, li[data-detail]:active { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.bar-row[data-detail] { border-radius: 8px; margin: 0 -6px; padding: 2px 6px; }

/* Detail-Popup: Bottom-Sheet am Handy, Modal am Desktop */
body.modal-open { overflow: hidden; }
dialog.sheet {
  border: 0; padding: 0; color: var(--text); background: var(--surface);
  width: min(720px, calc(100% - 32px)); max-width: none; max-height: 88vh; max-height: 88dvh;
  border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.35);
  display: none; flex-direction: column; overflow: hidden;
}
dialog.sheet[open] { display: flex; }
dialog.sheet::backdrop { background: rgba(0, 0, 0, .5); }
@media (max-width: 560px) {
  dialog.sheet { width: 100%; margin: auto 0 0 0; border-radius: 18px 18px 0 0; max-height: 92vh; max-height: 92dvh;
    padding-bottom: env(safe-area-inset-bottom); }
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px; border-bottom: 1px solid var(--line); flex: none; }
.sheet-head h2 { margin: 0; font-size: 17px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding: 4px 16px 24px; }
.det, .det-sum { padding: 14px 0; border-bottom: 1px solid var(--line); }
.det:last-child { border-bottom: 0; }
.det-titel { margin: 0 0 4px; font-size: 15px; font-weight: 700; }
.det-wert { display: flex; flex-direction: column; gap: 2px; margin-bottom: 8px; }
.big2 { font-size: 26px; font-weight: 750; letter-spacing: -.01em; }
.det-delta { font-size: 15px; font-weight: 650; }
.det-delta .muted { font-weight: 500; }
.chart-box.sm { height: 200px; margin: 4px 0; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; margin: 12px 0 4px; }
.stats dt { font-size: 12px; color: var(--muted); }
.stats dd { margin: 2px 0 0; font-size: 15px; font-weight: 600; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
table.tx td, table.tx th { padding: 7px 4px; font-size: 13px; }

/* Positionen nach Typ, aufklappbar */
.pos-tab .tw { display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; margin: -2px 6px -2px -4px;
  vertical-align: middle; border: 0; background: transparent; color: var(--muted); font-size: 18px; line-height: 1; padding: 0; border-radius: 6px; cursor: pointer; transition: transform .15s; }
.pos-tab span.tw { cursor: inherit; }
.pos-tab button.tw:hover { background: var(--surface-2); color: var(--text); }
.pos-tab tr.offen button.tw { transform: rotate(90deg); }
.pos-tab .sub.ein { margin-left: 22px; }
.pos-tab tr.ort td { font-size: 13px; color: var(--muted); border-bottom-style: dashed; }
.pos-tab tr.ort td:first-child { padding-left: 28px; }
td .sub.hide-lg { display: none; }
@media (max-width: 560px) { td .sub.hide-lg { display: block; } }
