/* ---------- Farben & Grundwerte ---------- */
:root {
  color-scheme: light;
  --bg: #f6f6f4;
  --surface: #ffffff;
  --surface-2: #fafaf8;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7d7c75;
  --line: #e4e3de;
  --line-strong: #cfcec8;
  --accent: #990066;
  --accent-hover: #7a0052;
  --accent-weak: #f7e6f0;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --ref: #8a897f;
  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;
  --notice-bg: #fff6e0;
  --notice-line: #f0d48a;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #20201e;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #94938a;
    --line: #2f2f2c;
    --line-strong: #44443f;
    --accent: #e0559f;
    --accent-hover: #ee7ab6;
    --accent-weak: #3a1530;
    --series-1: #3987e5;
    --series-2: #d95926;
    --ref: #8f8e85;
    --notice-bg: #2e2510;
    --notice-line: #5c4a1a;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
a:hover { color: var(--accent-hover); }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.5rem; font-weight: 650; }
h2 { font-size: 1.1rem; font-weight: 600; }
h3 { font-size: .95rem; font-weight: 600; }
code { font-family: var(--mono); font-size: .9em; }
.muted { color: var(--text-2); }
.small { font-size: .85rem; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.error { color: var(--critical); }
[hidden] { display: none !important; }

/* ---------- Kopfzeile ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 24px;
  padding: 10px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); }
.brand-logo { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 8px; background: #fff; overflow: hidden; }
.brand-logo img { width: 34px; height: 34px; object-fit: contain; }
.brand-text { font-weight: 650; letter-spacing: .08em; text-transform: uppercase; font-size: .95rem; }
.mainnav { display: flex; gap: 4px; flex: 1; }
.mainnav a {
  padding: 6px 12px; border-radius: 6px; text-decoration: none; color: var(--text-2); font-weight: 500;
}
.mainnav a:hover { background: var(--surface-2); color: var(--text); }
.mainnav a.active { color: var(--accent); background: var(--accent-weak); }
body:not(.is-admin) .admin-only { display: none !important; }

main { max-width: 1440px; margin: 0 auto; padding: 24px; }

/* ---------- Bedienelemente ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: 6px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 500; cursor: pointer;
}
.btn:hover { border-color: var(--text-2); }
.btn:disabled { opacity: .55; cursor: progress; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--critical); }
.btn-danger:hover { border-color: var(--critical); }
input[type="text"], input[type="password"], input[type="number"], input[type="search"], select {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: 6px; padding: 6px 10px;
}
input:focus-visible, select:focus-visible, .btn:focus-visible, a:focus-visible, th button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
.check { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- Karten & Kacheln ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 20px;
}
.card + .card, .section { margin-top: 20px; }
.grid-2 > .card { margin-top: 0; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 20px; }
.tile {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
}
.tile-label { font-size: .8rem; color: var(--text-2); }
.tile-value { font-size: 1.6rem; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 2px; display: flex; align-items: center; gap: 8px; }
.tile-value small { font-size: .55em; font-weight: 500; color: var(--text-2); }
.tile-sub { font-size: .8rem; color: var(--muted); margin-top: 2px; }
.notice {
  background: var(--notice-bg); border: 1px solid var(--notice-line); border-radius: var(--radius);
  padding: 10px 14px; margin-bottom: 16px; white-space: pre-line; font-size: .9rem;
}

/* ---------- Steuerleiste Übersicht ---------- */
.controls {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 16px 20px;
  padding: 14px 18px; margin-bottom: 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.control { display: flex; flex-direction: column; gap: 4px; font-size: .8rem; color: var(--text-2); }
.control select, .control input[type="search"] { min-width: 180px; }
.weights { display: flex; gap: 14px; flex-wrap: wrap; }
.weight { display: flex; flex-direction: column; gap: 2px; font-size: .8rem; color: var(--text-2); min-width: 96px; }
.weight-head { display: flex; justify-content: space-between; }
.weight-head b { color: var(--text); font-variant-numeric: tabular-nums; }
input[type="range"] { accent-color: var(--accent); width: 100%; }

/* ---------- Tabellen ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { padding: 8px 9px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
thead th {
  position: sticky; top: 0; background: var(--surface-2); font-weight: 600; font-size: .8rem;
  color: var(--text-2); white-space: nowrap; z-index: 1;
}
th button {
  all: unset; cursor: pointer; display: inline-flex; align-items: center; gap: 4px;
}
th button:hover { color: var(--text); }
th .sort-ind { font-size: .7rem; color: var(--accent); width: .7em; }
th.num button { justify-content: flex-end; width: 100%; }
tbody tr:last-child td { border-bottom: none; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover td { background: var(--accent-weak); }
tr.group-row td {
  background: var(--surface-2); font-weight: 600; font-size: .78rem; text-transform: uppercase;
  letter-spacing: .05em; color: var(--text-2); padding-top: 10px;
}
.col-sticky { position: sticky; left: 0; background: var(--surface); z-index: 1; }
thead .col-sticky { background: var(--surface-2); z-index: 2; }
tbody tr.clickable:hover .col-sticky { background: var(--accent-weak); }
.stock-name { font-weight: 600; display: block; max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stock-ticker { font-size: .78rem; color: var(--muted); font-family: var(--mono); }
.stock-sector { font-size: .78rem; color: var(--muted); }
.rank { color: var(--muted); font-variant-numeric: tabular-nums; width: 2.5em; }
.empty { padding: 48px 20px; text-align: center; color: var(--text-2); }

/* Bewertungs-Markierung: Form + Farbe (nie Farbe allein) */
.rating { display: inline-flex; align-items: center; gap: 6px; justify-content: flex-end; }
.mark { width: 9px; height: 9px; flex: none; display: inline-block; }
.mark.good { background: var(--good); border-radius: 50%; }
.mark.warning { background: var(--warning); transform: rotate(45deg); width: 8px; height: 8px; }
.mark.critical { background: var(--critical); border-radius: 1px; }
.mark.none { border: 1px solid var(--line-strong); border-radius: 50%; }
.legend-inline { display: flex; gap: 16px; flex-wrap: wrap; font-size: .8rem; color: var(--text-2); }
.legend-inline span { display: inline-flex; align-items: center; gap: 6px; }

.scorebar { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.scorebar-track { width: 64px; height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.scorebar-fill { display: block; height: 100%; background: var(--series-1); border-radius: 0 3px 3px 0; }
.score-big { font-weight: 650; }

.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .75rem; font-weight: 500;
  border: 1px solid var(--line-strong); color: var(--text-2); white-space: nowrap;
}
.badge.warn { border-color: var(--notice-line); background: var(--notice-bg); color: var(--text); }
.badge.err { border-color: var(--critical); color: var(--critical); }

/* ---------- Detailansicht ---------- */
.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.detail-head .meta { margin-top: 6px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; color: var(--text-2); font-size: .9rem; }
.back { display: inline-block; margin-bottom: 10px; font-size: .9rem; text-decoration: none; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }
.chart-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px 8px; box-shadow: var(--shadow); }
.chart-card h3 { margin-bottom: 2px; }
.chart-sub { font-size: .78rem; color: var(--muted); margin-bottom: 6px; }
.chart { position: relative; width: 100%; height: 200px; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart-legend { display: flex; gap: 14px; font-size: .78rem; color: var(--text-2); margin: 2px 0 6px; flex-wrap: wrap; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch-line { width: 16px; height: 2px; border-radius: 1px; display: inline-block; }
.swatch-dash { width: 16px; height: 0; border-top: 2px dashed var(--ref); display: inline-block; }
.axis text { fill: var(--muted); font-size: 11px; }
.grid line { stroke: var(--line); stroke-width: 1; }
.info {
  display: inline-grid; place-items: center; width: 16px; height: 16px; border-radius: 50%;
  border: 1px solid var(--line-strong); color: var(--muted); font-size: 10px; font-weight: 700;
  cursor: help; margin-left: 6px; vertical-align: 1px;
}
td.editable { cursor: text; }
td.editable:hover { outline: 1px dashed var(--accent); outline-offset: -3px; }
td.manual { color: var(--accent); }
td.manual::after { content: " ✎"; font-size: .75em; }
td input.cell-input { width: 100%; min-width: 80px; padding: 2px 6px; text-align: right; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.tabs button {
  all: unset; cursor: pointer; padding: 8px 12px; color: var(--text-2); font-weight: 500;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
.buy-hit { font-weight: 650; }

/* ---------- Verwaltung ---------- */
.form-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.form-row input[type="text"] { min-width: 240px; }
.result { margin-top: 10px; font-size: .9rem; white-space: pre-line; }
table.thresholds input { width: 90px; text-align: right; }
table.thresholds .unit { display: inline-block; width: 1.2em; text-align: left; color: var(--text-2); }

/* ---------- Overlays ---------- */
dialog {
  border: 1px solid var(--line); border-radius: 12px; padding: 24px; width: min(420px, calc(100vw - 32px));
  background: var(--surface); color: var(--text);
}
dialog::backdrop { background: rgba(0,0,0,.35); }
dialog h2 { margin-bottom: 8px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--text-2); margin: 10px 0; }
.field input { width: 100%; }
dialog .notice { margin: 8px 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.tooltip {
  position: fixed; z-index: 50; pointer-events: none; max-width: 340px;
  background: var(--surface); color: var(--text); border: 1px solid var(--line-strong);
  border-radius: 6px; padding: 8px 10px; font-size: .8rem; box-shadow: 0 4px 16px rgba(0,0,0,.15);
}
.tooltip .tt-title { font-weight: 600; margin-bottom: 4px; }
.tooltip .tt-row { display: flex; align-items: center; gap: 6px; justify-content: space-between; }
.tooltip .tt-row span:first-child { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); }
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 60;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-size: .9rem;
  max-width: calc(100vw - 32px);
}
.spinner {
  width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; animation: spin .7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Schmale Bildschirme ---------- */
@media (max-width: 720px) {
  .topbar { padding: 8px 16px; gap: 12px; }
  .brand-text { display: none; }
  main { padding: 16px; }
  .controls { padding: 12px; }
  .control select, .control input[type="search"] { min-width: 0; width: 100%; }
  .control { flex: 1 1 140px; }
  .grid-2 { grid-template-columns: 1fr; }
  .tile-value { font-size: 1.3rem; }
  .stock-name { max-width: 150px; }
}
