:root {
  color-scheme: light;
  --page:            #f9f9f7;
  --surface-1:       #fcfcfb;
  --text-primary:    #0b0b0b;
  --text-secondary:  #52514e;
  --muted:           #898781;
  --gridline:        #e1e0d9;
  --baseline:        #c3c2b7;
  --border:          rgba(11,11,11,0.10);
  --series-1:        #2a78d6;
  --series-1-fill:   rgba(42,120,214,0.10);
  --series-2:        #eb6834;
  --series-3:        #1baf7a;
  --series-4:        #eda100;
  --good:            #006300;
  --critical:        #d03b3b;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page:            #0d0d0d;
    --surface-1:       #1a1a19;
    --text-primary:    #ffffff;
    --text-secondary:  #c3c2b7;
    --muted:           #898781;
    --gridline:        #2c2c2a;
    --baseline:        #383835;
    --border:          rgba(255,255,255,0.10);
    --series-1:        #3987e5;
    --series-1-fill:   rgba(57,135,229,0.14);
    --series-2:        #d95926;
    --series-3:        #199e70;
    --series-4:        #c98500;
    --good:            #0ca30c;
    --critical:        #e66767;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page:            #0d0d0d;
  --surface-1:       #1a1a19;
  --text-primary:    #ffffff;
  --text-secondary:  #c3c2b7;
  --muted:           #898781;
  --gridline:        #2c2c2a;
  --baseline:        #383835;
  --border:          rgba(255,255,255,0.10);
  --series-1:        #3987e5;
  --series-1-fill:   rgba(57,135,229,0.14);
  --series-2:        #d95926;
  --series-3:        #199e70;
  --series-4:        #c98500;
  --good:            #0ca30c;
  --critical:        #e66767;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}
.wrap {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 16px 64px;
}
header.page-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}
header.page-head h1 {
  font-size: 20px;
  font-weight: 600;
  margin: 0;
  color: var(--text-secondary);
}
.updated {
  font-size: 13px;
  color: var(--muted);
}

/* Navigation */
nav.main-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px;
  margin-bottom: 20px;
}
nav.main-nav a {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 999px;
}
nav.main-nav a:hover { color: var(--text-primary); background: var(--series-1-fill); }
nav.main-nav a.active { color: #fff; background: var(--series-1); }
nav.main-nav .nav-spacer { flex: 1; }
nav.main-nav .nav-user {
  font-size: 13px;
  color: var(--muted);
  padding: 7px 10px;
  white-space: nowrap;
}
nav.main-nav .nav-user-btn {
  appearance: none;
  background: transparent;
  border: none;
  font: inherit;
  cursor: pointer;
  border-radius: 999px;
}
nav.main-nav .nav-user-btn:hover { color: var(--text-primary); background: var(--series-1-fill); }
nav.main-nav .nav-status {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
}
nav.main-nav .nav-status.running { background: rgba(12,163,12,0.15); color: var(--good); }
nav.main-nav .nav-status.stopped { background: rgba(208,59,59,0.15); color: var(--critical); }

.hero-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 24px;
  margin-bottom: 16px;
}
.hero-label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.hero-row {
  display: flex;
  align-items: baseline;
  gap: 14px;
  flex-wrap: wrap;
}
.hero-value {
  font-size: 48px;
  font-weight: 600;
  line-height: 1;
}
.hero-delta {
  font-size: 18px;
  font-weight: 600;
}
.hero-delta.up { color: var(--good); }
.hero-delta.down { color: var(--critical); }

/* Stat-Kacheln (Bar/Depot/Gesamt) */
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.stat-tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
}
.stat-tile .stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.stat-tile .stat-value {
  font-size: 26px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.stat-tile .stat-value.up { color: var(--good); }
.stat-tile .stat-value.down { color: var(--critical); }

.chart-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 20px 8px;
  margin-bottom: 16px;
  position: relative;
}
.chart-card h2 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-secondary);
  margin: 0 0 12px;
}
svg.chart { display: block; width: 100%; height: auto; }
.chart-line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-area { fill: var(--series-1-fill); stroke: none; }
.chart-grid { stroke: var(--gridline); stroke-width: 1; }
.chart-baseline { stroke: var(--baseline); stroke-width: 1; }
.chart-axis-label { fill: var(--muted); font-size: 11px; }
.chart-end-dot { fill: var(--series-1); stroke: var(--surface-1); stroke-width: 2; }
.chart-end-label { fill: var(--text-primary); font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.chart-crosshair { stroke: var(--baseline); stroke-width: 1; opacity: 0; pointer-events: none; }
.chart-hover-dot { fill: var(--series-1); stroke: var(--surface-1); stroke-width: 2; opacity: 0; pointer-events: none; }
.chart-overlay { fill: transparent; cursor: crosshair; }

.tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  opacity: 0;
  transform: translate(-50%, -110%);
  white-space: nowrap;
  z-index: 5;
}
.tooltip .tt-date { color: var(--text-secondary); margin-bottom: 2px; }
.tooltip .tt-value { color: var(--text-primary); font-weight: 600; font-variant-numeric: tabular-nums; }
.tooltip .tt-key { display:inline-block; width:10px; height:2px; background:var(--series-1); margin-right:6px; vertical-align:middle; }

details.data-table { margin: 4px 0 12px; }
details.data-table summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  padding: 4px 0 12px;
}
.scroll-table { overflow-x: auto; }

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
}
table.stocks { table-layout: fixed; }
th, td {
  padding: 8px 10px;
  text-align: right;
  border-bottom: 1px solid var(--gridline);
  white-space: nowrap;
}
th:first-child, td:first-child { text-align: left; }
th {
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
table.stocks th, table.sortable th {
  cursor: pointer;
  user-select: none;
  position: relative;
}
table.stocks th:hover, table.sortable th:hover { color: var(--text-secondary); }
table.stocks th.sort-asc::after, table.sortable th.sort-asc::after,
table.stocks th.sort-desc::after, table.sortable th.sort-desc::after {
  margin-left: 4px;
  font-size: 10px;
}
table.stocks th.sort-asc::after, table.sortable th.sort-asc::after { content: "▲"; }
table.stocks th.sort-desc::after, table.sortable th.sort-desc::after { content: "▼"; }
td { font-variant-numeric: tabular-nums; }
td.name-cell { font-variant-numeric: normal; white-space: normal; }
td.ts-cell { white-space: nowrap; }
td.ts-cell .ts-date { color: var(--text-primary); }
td.ts-cell .ts-time { color: var(--muted); font-size: 12px; margin-top: 1px; }
td.up { color: var(--good); }
td.down { color: var(--critical); }
td.na { color: var(--muted); font-variant-numeric: normal; }
.muted-hint { color: var(--muted); font-size: 12px; font-variant-numeric: normal; }

table.stocks tbody tr { cursor: pointer; }
table.stocks tbody tr:hover { background: var(--series-1-fill); }
table.stocks tbody tr.row-active { background: var(--series-1-fill); }
table.stocks tbody tr.row-active td:first-child { box-shadow: inset 3px 0 0 var(--series-1); }
td.row-index { font-weight: 600; }
table.stocks[hidden] { display: none; }

.tabs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.tab-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
}
.tab-btn:hover { color: var(--text-primary); background: var(--series-1-fill); }
.tab-btn.active {
  color: #fff;
  background: var(--series-1);
  border-color: var(--series-1);
}

.table-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 20px 12px;
  margin-bottom: 16px;
}
.table-card h2 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-secondary);
  margin: 0 0 4px;
}
.table-sub {
  font-size: 12px;
  color: var(--muted);
  margin: 0 0 14px;
}
.table-card p { line-height: 1.55; margin: 0 0 8px; }
.table-card p:last-child { margin-bottom: 0; }
.table-card ul, .table-card ol {
  margin: 0 0 8px;
  padding-left: 22px;
  line-height: 1.6;
}
.table-card li { margin-bottom: 4px; }

footer.page-foot {
  margin-top: 20px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

/* Formulare (Login, Handeln, Admin) */
.form-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  max-width: 360px;
  margin: 48px auto;
}
.form-card h1 { font-size: 18px; margin: 0 0 18px; }
.form-row { margin-bottom: 14px; }
.form-row label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}
.form-row input, .form-row select {
  width: 100%;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--page);
  color: var(--text-primary);
  font: inherit;
  font-size: 14px;
}
.password-field { position: relative; }
.password-field input { padding-right: 76px; }
.password-toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  appearance: none;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 8px;
}
.password-toggle:hover { color: var(--text-primary); }
.btn {
  appearance: none;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  background: var(--series-1);
  color: #fff;
}
.btn:hover { filter: brightness(1.08); }
.btn.btn-buy { background: var(--good); }
.btn.btn-sell { background: var(--critical); }
.btn.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-sm { padding: 5px 12px; font-size: 12px; }

.flash {
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 16px;
}
.flash.ok { background: rgba(12,163,12,0.12); color: var(--good); }
.flash.err { background: rgba(208,59,59,0.12); color: var(--critical); }

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
}
.badge.running { background: rgba(12,163,12,0.15); color: var(--good); }
.badge.stopped { background: rgba(208,59,59,0.15); color: var(--critical); }

.rank-medal { font-size: 15px; margin-right: 4px; }
tr.rank-you { background: var(--series-1-fill); }

/* Legende (Mehrlinien-Chart Rangliste) */
.chart-legend {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 10px;
  font-size: 13px;
  color: var(--text-secondary);
}
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-swatch {
  display: inline-block;
  width: 14px;
  height: 3px;
  border-radius: 2px;
}

/* Bestaetigungs-Dialog (Kauf/Verkauf) */
dialog {
  background: var(--surface-1);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  max-width: 400px;
  width: 90%;
}
dialog::backdrop { background: rgba(0,0,0,0.5); }
dialog h3 { margin: 0 0 14px; font-size: 17px; }
table.confirm-table { margin-bottom: 18px; }
table.confirm-table td {
  text-align: left;
  border-bottom: 1px solid var(--gridline);
  padding: 7px 4px;
}
table.confirm-table td:first-child { color: var(--text-secondary); }
table.confirm-table td:last-child { text-align: right; font-variant-numeric: tabular-nums; }

/* Konfetti-Animation (Gewinn-Verkauf / neuer Erfolg) */
.confetti-piece {
  position: fixed;
  top: -12px;
  width: 8px;
  height: 14px;
  opacity: 0.9;
  pointer-events: none;
  z-index: 999;
  border-radius: 2px;
  animation: confetti-fall 2.2s ease-in forwards;
}
@keyframes confetti-fall {
  to { transform: translateY(100vh) rotate(360deg); opacity: 0; }
}

/* Erfolge (Abzeichen) */
.achievements-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}
.achievement {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 10px;
  text-align: center;
  background: var(--page);
}
.achievement.unlocked { border-color: var(--good); background: rgba(12,163,12,0.08); }
.achievement.locked { opacity: 0.55; }
.achievement-icon {
  width: 32px;
  height: 32px;
  line-height: 32px;
  border-radius: 50%;
  margin: 0 auto 8px;
  font-weight: 700;
  font-size: 15px;
}
.achievement.unlocked .achievement-icon { background: var(--good); color: #fff; }
.achievement.locked .achievement-icon { background: var(--gridline); color: var(--muted); }
.achievement-label { font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.achievement-desc { font-size: 11px; color: var(--muted); line-height: 1.4; }

/* Avatar */
.avatar { font-size: 18px; margin-right: 6px; vertical-align: middle; }
.avatar-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.avatar-choice {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--page);
  border-radius: 8px;
  font-size: 20px;
  line-height: 1;
  padding: 8px;
  cursor: pointer;
}
.avatar-choice:hover { background: var(--series-1-fill); }
.avatar-choice.selected { border-color: var(--series-1); background: var(--series-1-fill); }
