:root {
  /* Chart-Farben: geprüfte Standardpalette (Kurs, Kauf, Verkauf) */
  --series-1: #2a78d6;
  --buy: #1baf7a;
  --sell: #eb6834;
  --series-2: #eb6834;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --accent: #2563eb;
  --pos: #15803d;
  --neg: #b91c1c;
  --bar: #2563eb;
  --radius: 12px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --surface: #111a2e;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --border: #1e293b;
    --accent: #60a5fa;
    --pos: #4ade80;
    --neg: #f87171;
    --bar: #3b82f6;
    --series-1: #3987e5;
    --buy: #199e70;
    --sell: #d95926;
    --series-2: #d95926;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
a { color: var(--accent); text-decoration: none; }
.muted { color: var(--muted); }
.pos { color: var(--pos); }
.neg { color: var(--neg); }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px;
  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; color: var(--text); }
.topbar nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.topbar nav a { padding: 6px 10px; border-radius: 8px; color: var(--muted); white-space: nowrap; }
.topbar nav a.active { background: var(--bg); color: var(--text); font-weight: 600; }
.icon-btn { border: 0; background: none; font-size: 20px; color: var(--text); cursor: pointer; padding: 4px 8px; }
.icon-btn.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

main { max-width: 1100px; margin: 0 auto; padding: 16px; }
h1 { font-size: 22px; margin: 4px 0 16px; }
h2 { font-size: 17px; margin: 28px 0 10px; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.card .label { color: var(--muted); font-size: 13px; }
.card .value { font-size: 22px; font-weight: 650; margin-top: 2px; }
.card .sub { font-size: 13px; margin-top: 2px; }
.card.hero .value { font-size: 30px; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 4px 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }

.alloc-row { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.alloc-row:last-child { border-bottom: 0; }
.alloc-bar { grid-column: 1 / -1; height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
.alloc-bar span { display: block; height: 100%; background: var(--bar); }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 8px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
th:first-child, td:first-child { white-space: normal; }
td.actions { text-align: right; }
tr:last-child td { border-bottom: 0; }
td .name { font-weight: 600; }
td .meta { font-size: 12px; color: var(--muted); }
tr.link { cursor: pointer; }
tr.link:hover td { background: var(--bg); }

.warnings { background: color-mix(in srgb, #f59e0b 12%, var(--surface)); border: 1px solid color-mix(in srgb, #f59e0b 40%, var(--border)); border-radius: var(--radius); padding: 10px 14px; margin: 16px 0; font-size: 13px; }
.warnings summary { cursor: pointer; font-weight: 600; }
.error { color: var(--neg); }

form.stack { display: grid; gap: 12px; max-width: 520px; }
form.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; align-items: end; }
label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 10px; width: 100%;
}
button.primary, button.secondary, button.danger {
  font: inherit; font-weight: 600; border-radius: 8px; padding: 9px 14px; cursor: pointer; border: 1px solid transparent;
}
button.primary { background: var(--accent); color: #fff; }
button.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
button.danger { background: none; color: var(--neg); border-color: var(--border); padding: 4px 10px; }
button.small { padding: 4px 10px; font-weight: 500; }
td.actions { white-space: nowrap; }
tr.editor td { background: var(--bg); }
button:disabled { opacity: .6; cursor: default; }

.search-results { border: 1px solid var(--border); border-radius: 8px; background: var(--surface); max-height: 240px; overflow: auto; }
.search-results button { display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--border); background: none; padding: 8px 10px; color: var(--text); cursor: pointer; font: inherit; }
.search-results button:hover { background: var(--bg); }

.login { max-width: 340px; margin: 12vh auto; }
.login h1 { text-align: center; }

/* Schmale Bildschirme: unwichtige Spalten ausblenden */
@media (max-width: 700px) {
  main { padding: 12px; }
  .topbar { gap: 8px; }
  .brand { display: none; }
  .topbar nav a { padding: 6px 7px; }
  .hide-sm { display: none; }
  th, td { padding: 8px 4px; }
  table { font-size: 14px; }
  td .name { overflow-wrap: break-word; hyphens: auto; }
  .card .value { font-size: 19px; }
  .card.hero .value { font-size: clamp(18px, 5.6vw, 26px); }
  .card .value { overflow-wrap: anywhere; }
}

/* Sortierbare Tabellen */
.table-wrap { overflow-x: auto; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover, th.sorted { color: var(--text); }
td.num, th.num { text-align: right; }
tfoot td { border-top: 1px solid var(--border); border-bottom: 0; font-weight: 600; }

/* Klickbare Kacheln und Aufteilungszeilen */
a.card { color: inherit; display: block; }
a.card:hover, a.alloc-row.link:hover { border-color: var(--accent); }
a.alloc-row { color: inherit; }
a.alloc-row.link:hover span:first-child { color: var(--accent); }

/* Detailseite */
.quote-line { display: flex; gap: 12px; align-items: baseline; margin: -6px 0 16px; flex-wrap: wrap; }
.quote-price { font-size: 26px; font-weight: 650; }
.range-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.chart-panel { padding: 12px 14px; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.legend i { display: inline-block; width: 16px; height: 0; vertical-align: middle; margin-right: 4px; }
.key-line { border-top: 2px solid var(--series-1); }
.key-ref { border-top: 1px solid var(--muted); }
/* Text bleibt in Textfarbe, nur das Symbol trägt die Datenfarbe */
.k-buy b { color: var(--buy); font-weight: 400; }
.k-sell b { color: var(--sell); font-weight: 400; }
svg.chart { display: block; touch-action: pan-y; }
svg.chart .grid { stroke: var(--border); stroke-width: 1; }
svg.chart .axis { fill: var(--muted); font-size: 11px; }
svg.chart .line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
svg.chart .ref { stroke: var(--muted); stroke-width: 1; }
svg.chart .mark-buy { fill: var(--buy); stroke: var(--surface); stroke-width: 2; }
svg.chart .mark-sell { fill: var(--sell); stroke: var(--surface); stroke-width: 2; }
svg.chart .cross { stroke: var(--muted); stroke-width: 1; }
svg.chart .dot { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.chart-tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 9px; font-size: 12px; box-shadow: 0 2px 8px rgb(0 0 0 / 0.12); white-space: nowrap; z-index: 2; }
.link-row { display: flex; gap: 10px; flex-wrap: wrap; }
.secondary-link { border: 1px solid var(--border); border-radius: 8px; padding: 6px 12px; background: var(--surface); }

/* Auswertung */
.filter-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.filter-row .range-row { margin: 0; }
.filter-row select { width: auto; }
.key-bench { border-top: 2px solid var(--series-2); }
.key-invested { border-top: 1px solid var(--muted); }
svg.chart .line.bench { stroke: var(--series-2); }
svg.chart .line.invested { stroke: var(--muted); stroke-width: 1.25; }
svg.chart .dot.bench { fill: var(--series-2); }
svg.chart .dot.invested { fill: var(--muted); }
.chart-tip i { display: inline-block; width: 12px; height: 0; vertical-align: middle; }
.chart-tip .key- { border-top: 2px solid var(--series-1); }
.push-right { margin-left: auto; }
.small-note { font-size: 13px; }

svg.chart .bar { fill: var(--series-1); }
input.amount { width: 110px; text-align: right; padding: 5px 8px; }
.small-link { font-size: 13px; font-weight: 500; vertical-align: middle; margin-left: 8px; padding: 4px 10px; }
input.invalid { border-color: var(--neg); }
@media (max-width: 1100px) { .hide-md { display: none; } }

/* Jahresend-Check und Simulation */
.hint { padding: 8px 0; border-bottom: 1px solid var(--border); }
.hint:last-of-type { border-bottom: 0; }
.hint-head { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; align-items: baseline; }
.hint-list { margin: 6px 0 0; padding-left: 18px; }
.badge { font-size: 12px; font-weight: 600; border: 1px solid currentColor; border-radius: 999px; padding: 1px 8px; white-space: nowrap; }
.panel-accent { border-color: var(--accent); }
.sim-box { margin-top: 10px; }
.sim-box .cards { margin-bottom: 10px; }
