:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e2e1dc;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7974;
  --grid: #e8e7e3;
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --good: #0a7a3a;
  --bad: #c0332f;
  --warn-bg: #fff4d6;
  --warn-ink: #6b4a00;
  --err-bg: #fde6e5;
  --err-ink: #8a1f1c;
  /* Kategorien (Zahlarten), feste Reihenfolge */
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #a8a69e;
  /* Sequenziell (Tageswerte-Heatmap) */
  --q0: #ffffff; --q1: #cde2fb; --q2: #9ec5f4; --q3: #6da7ec; --q4: #3987e5; --q5: #256abf;
  --q-ink-dark: #ffffff;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --surface-2: #232321;
    --border: #2f2f2c;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #8f8e86;
    --grid: #2a2a28;
    --accent: #3987e5;
    --accent-ink: #86b6ef;
    --good: #4cc27c;
    --bad: #f07a76;
    --warn-bg: #3a2f10;
    --warn-ink: #f3d68a;
    --err-bg: #3d1716;
    --err-ink: #f6b4b1;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #6c6b65;
    --q0: #1a1a19; --q1: #184f95; --q2: #1c5cab; --q3: #256abf; --q4: #2a78d6; --q5: #5598e7;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110; --surface: #1a1a19; --surface-2: #232321; --border: #2f2f2c;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #8f8e86; --grid: #2a2a28;
  --accent: #3987e5; --accent-ink: #86b6ef; --good: #4cc27c; --bad: #f07a76;
  --warn-bg: #3a2f10; --warn-ink: #f3d68a; --err-bg: #3d1716; --err-ink: #f6b4b1;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #6c6b65;
  --q0: #1a1a19; --q1: #184f95; --q2: #1c5cab; --q3: #256abf; --q4: #2a78d6; --q5: #5598e7;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.num { font-variant-numeric: tabular-nums; }
button, input, select { font: inherit; color: inherit; }
.loading { padding: 40px; text-align: center; color: var(--muted); }

/* Kopfzeile */
.top {
  position: sticky; top: 0; z-index: 5;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.top-inner {
  max-width: 1240px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 17px; }
.brand img { width: 26px; height: 26px; }
.stand { color: var(--muted); font-size: 13px; }
.spacer { flex: 1; }
.langs { display: inline-flex; background: var(--surface-2); border-radius: 8px; padding: 2px; gap: 2px; }
.lang { border: 0; background: none; padding: 3px 8px; border-radius: 6px; font-size: 12px; font-weight: 600; color: var(--text-2); cursor: pointer; }
.lang[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.login-langs { display: flex; justify-content: flex-end; margin-bottom: 10px; }
.user { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--text-2); }

.btn {
  border: 1px solid var(--border); background: var(--surface); border-radius: 8px;
  padding: 6px 12px; cursor: pointer; font-size: 14px;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.small { padding: 3px 9px; font-size: 13px; }
.btn.link { border: 0; background: none; color: var(--accent-ink); padding: 4px 6px; }

/* Filter + Tabs */
.bar {
  max-width: 1240px; margin: 0 auto; padding: 12px 16px 0;
  display: flex; gap: 10px; align-items: end; flex-wrap: wrap;
}
.field { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.field select, .field input {
  border: 1px solid var(--border); background: var(--surface); border-radius: 8px;
  padding: 7px 10px; font-size: 14px; min-width: 170px;
}
.tabs { display: flex; gap: 2px; margin-left: auto; background: var(--surface-2); border-radius: 9px; padding: 3px; }
.tab { border: 0; background: none; padding: 6px 12px; border-radius: 7px; cursor: pointer; color: var(--text-2); font-size: 14px; }
.tab[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); font-weight: 550; }

main { max-width: 1240px; margin: 0 auto; padding: 14px 16px 40px; }

.banner { border-radius: 8px; padding: 9px 12px; margin-bottom: 12px; font-size: 14px; }
.banner.warn { background: var(--warn-bg); color: var(--warn-ink); }
.banner.err { background: var(--err-bg); color: var(--err-ink); }

/* Kennzahlen */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 14px; }
.kpis.five { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.kpi .label { color: var(--muted); font-size: 13px; }
.kpi .value { font-size: 26px; font-weight: 650; letter-spacing: -0.01em; margin: 2px 0; }
.kpi .sub { font-size: 13px; color: var(--text-2); }
.delta { font-weight: 600; white-space: nowrap; }
.delta.up { color: var(--good); }
.delta.down { color: var(--bad); }
.delta.flat { color: var(--muted); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; }
.card h2 { font-size: 15px; margin: 0 0 2px; font-weight: 620; }
.card .hint { color: var(--muted); font-size: 13px; margin: 0 0 10px; }
.card-head { display: flex; align-items: start; gap: 10px; }
.card-head > div { flex: 1; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; }
.grid2 > .card { margin-bottom: 0; }
.grid2 + .card, .grid2 { margin-bottom: 14px; }

/* Diagramme */
.chart { width: 100%; position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .axis.we { fill: var(--text-2); font-weight: 650; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--border); stroke-width: 1; }
.chart .bar { fill: var(--accent); }
.chart .bar.partial { fill: var(--q2); }
.chart .bar.ch { fill: var(--s2); }
.chart .bar.ch.partial { fill: var(--s2); opacity: 0.55; }
.banner.ok-banner { background: var(--surface-2); color: var(--text); }
.chart .bar.dim { opacity: 0.35; }
.chart .avg { stroke: var(--text-2); stroke-width: 1.5; stroke-dasharray: 4 4; }
.chart .avg-label { fill: var(--text-2); font-size: 11px; }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit.click { cursor: pointer; }
.chart .hit:hover + .hl, .chart .hl { pointer-events: none; }
.chart g.col:hover .bar { filter: brightness(0.88); }

.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--text-2); margin: 0 0 10px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

#tooltip {
  position: fixed; z-index: 50; pointer-events: none;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; font-size: 13px; box-shadow: 0 4px 16px rgb(0 0 0 / 0.12);
  max-width: 260px;
}
#tooltip .t { font-weight: 600; margin-bottom: 2px; }
#tooltip .r { display: flex; justify-content: space-between; gap: 14px; }
#tooltip .r span:first-child { color: var(--text-2); }

/* Tabellen */
.scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 7px 10px; text-align: right; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th { font-weight: 550; color: var(--text-2); font-size: 13px; background: var(--surface); }
th:first-child, td:first-child { text-align: left; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: var(--surface-2); }
tfoot td { font-weight: 650; border-top: 1px solid var(--border); border-bottom: 0; }
.sharecell { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.sharebar { width: 90px; height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.sharebar i { display: block; height: 100%; background: var(--accent); border-radius: 0 4px 4px 0; }
.muted { color: var(--muted); }

/* Tageswerte-Matrix */
.matrix th, .matrix td { padding: 5px 8px; font-size: 13px; }
.matrix thead th { position: sticky; top: 0; }
.matrix td.cell { position: relative; }
.matrix td.q0 { background: var(--q0); }
.matrix td.q1 { background: var(--q1); }
.matrix td.q2 { background: var(--q2); }
.matrix td.q3 { background: var(--q3); color: var(--q-ink-dark); }
.matrix td.q4 { background: var(--q4); color: var(--q-ink-dark); }
.matrix td.q5 { background: var(--q5); color: var(--q-ink-dark); }
.matrix tr.we td:first-child { font-weight: 650; }
.matrix td.corr::after { content: "*"; margin-left: 2px; font-weight: 700; }
.matrix td.total { font-weight: 600; background: var(--surface-2); }
.scale { display: inline-flex; gap: 2px; vertical-align: middle; margin: 0 6px; }
.scale i { width: 16px; height: 10px; display: inline-block; border-radius: 2px; }

/* Zahlarten */
.mix-row { display: grid; grid-template-columns: 150px 1fr 90px; gap: 10px; align-items: center; padding: 5px 0; }
.mix-name { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mix-bar { display: flex; height: 18px; gap: 2px; }
.mix-bar i { display: block; height: 100%; min-width: 0; }
.mix-bar i:first-child { border-radius: 4px 0 0 4px; }
.mix-bar i:last-child { border-radius: 0 4px 4px 0; }
.mix-total { text-align: right; font-size: 13px; color: var(--text-2); }

/* Formulare, Login, Dialog */
.login { max-width: 360px; margin: 12vh auto; padding: 0 16px; }
.login .card { padding: 22px; }
.login h1 { font-size: 20px; margin: 0 0 14px; display: flex; gap: 10px; align-items: center; }
.login h1 img { width: 28px; }
form .row { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; font-size: 13px; color: var(--text-2); }
form .row input, form .row select {
  border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 8px 10px; font-size: 15px; color: var(--text);
}
form .check { flex-direction: row; align-items: center; gap: 8px; }
.error { color: var(--bad); font-size: 14px; min-height: 1.4em; margin: 4px 0 8px; }
.ok { color: var(--good); font-size: 14px; }
.stores-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 4px 12px; }
.stores-pick label { display: flex; gap: 6px; align-items: center; font-size: 14px; color: var(--text); }
dialog { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text); padding: 20px; width: min(520px, calc(100vw - 32px)); }
dialog::backdrop { background: rgb(0 0 0 / 0.35); }
dialog h3 { margin: 0 0 14px; }
.actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }
.badge { font-size: 12px; padding: 1px 7px; border-radius: 10px; background: var(--surface-2); color: var(--text-2); }
.badge.ok { background: transparent; color: var(--good); }
.badge.err { background: var(--err-bg); color: var(--err-ink); }
.badge.warn { background: var(--warn-bg); color: var(--warn-ink); }
.empty { padding: 30px; text-align: center; color: var(--muted); }

@media (max-width: 900px) {
  .kpis, .kpis.five { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpis.five .kpi.wide { grid-column: span 2; }
  .grid2 { grid-template-columns: minmax(0, 1fr); }
  .grid2 > .card { margin-bottom: 0; }
  .tabs { margin-left: 0; width: 100%; overflow-x: auto; }
}
@media (max-width: 520px) {
  .kpi .value { font-size: 21px; }
  .field { flex: 1 1 140px; }
  .field select { min-width: 0; width: 100%; }
  .mix-row { grid-template-columns: 100px 1fr 70px; }
  .stand { width: 100%; order: 3; }
}
@media print {
  .top, .bar, #tooltip { display: none; }
  body { background: #fff; }
}
