:root {
  color-scheme: light;
  --bg: #f6f5f2;
  --surface: #fcfcfb;
  --surface-2: #efeee9;
  --border: #dddcd6;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #75746f;
  --accent: #1d6b3a;
  --accent-ink: #ffffff;
  --danger: #c0312f;
  --grid: #e6e5df;

  /* Diagrammfarben – validiert (CVD/Kontrast) in der Reihenfolge Rot, Sonstige, Gelb */
  --cat-red: #e34948;
  --cat-other: #4a3aa7;
  --cat-yellow: #eda100;
  /* Standorte – feste Reihenfolge laut config.yaml */
  --loc-1: #2a78d6;
  --loc-2: #eb6834;
  --loc-3: #1baf7a;
  --loc-4: #eda100;
  --loc-5: #e87ba4;
  --loc-6: #008300;
  --loc-7: #4a3aa7;
  --loc-8: #e34948;

  --radius: 14px;
  --tabbar-h: 64px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #262624;
    --border: #383835;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --muted: #9a998f;
    --accent: #3f9a5f;
    --accent-ink: #ffffff;
    --danger: #e66767;
    --grid: #2e2e2b;
    --cat-red: #e66767;
    --cat-other: #9085e9;
    --cat-yellow: #c98500;
    --loc-1: #3987e5;
    --loc-2: #d95926;
    --loc-3: #199e70;
    --loc-4: #c98500;
    --loc-5: #d55181;
    --loc-6: #008300;
    --loc-7: #9085e9;
    --loc-8: #e66767;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.error { color: var(--danger); margin: 0.5rem 0 0; }

/* --- Anmeldung --- */
.screen { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-box { width: 100%; max-width: 360px; text-align: center; }
.login-icon { width: 72px; height: 72px; }
.login-box h1 { margin: 0.5rem 0; font-size: 1.5rem; }
.login-box form { display: grid; gap: 12px; margin-top: 1.5rem; }
.login-box input {
  padding: 14px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); font-size: 1.1rem; text-align: center;
}

/* --- Layout --- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  background: var(--accent); color: var(--accent-ink);
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
}
.topbar h1 { margin: 0; font-size: 1.15rem; font-weight: 650; }

main {
  max-width: 640px; margin: 0 auto;
  padding: 8px 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
}

.section-label {
  font-size: 0.8rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-2); margin: 20px 0 8px;
}

/* --- Tabbar --- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  height: var(--tabbar-h); border: 0; background: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 0.8rem; color: var(--muted);
}
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }
.tabbar button.active { color: var(--accent); font-weight: 600; }

/* --- Erfassen --- */
.choice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.choice {
  min-height: 56px; padding: 10px 12px; text-align: left;
  border: 2px solid var(--border); border-radius: var(--radius); background: var(--surface);
  font-weight: 500; line-height: 1.25;
}
.choice[aria-checked="true"] { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--surface)); }

.date-row { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  min-height: 44px; padding: 0 16px; display: inline-flex; align-items: center;
  border: 2px solid var(--border); border-radius: 999px; background: var(--surface); font-weight: 500;
}
.chip[aria-checked="true"] { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--surface)); }
.chip-date { position: relative; overflow: hidden; }
.chip-date input { position: absolute; inset: 0; opacity: 0; width: 100%; cursor: pointer; }

.counters { display: grid; gap: 8px; }
.counter {
  display: grid; grid-template-columns: 1fr 56px 72px 56px; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 8px 8px 14px;
}
.counter-name { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.sw-red { background: var(--cat-red); }
.sw-yellow { background: var(--cat-yellow); }
.sw-other { background: var(--cat-other); }
.step {
  height: 56px; border-radius: 12px; border: 0; background: var(--surface-2);
  font-size: 1.75rem; font-weight: 500; touch-action: manipulation;
}
.step:active { background: var(--border); }
.counter input {
  width: 100%; height: 56px; text-align: center; font-size: 1.6rem; font-weight: 700;
  border: 0; background: none; font-variant-numeric: tabular-nums; -moz-appearance: textfield;
}
.counter input::-webkit-inner-spin-button, .counter input::-webkit-outer-spin-button { -webkit-appearance: none; }

.note { margin-top: 16px; }
.note summary { color: var(--text-2); cursor: pointer; padding: 6px 0; }
.note textarea {
  width: 100%; margin-top: 6px; padding: 10px; resize: vertical;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
}

.btn-primary {
  border: 0; border-radius: var(--radius); background: var(--accent); color: var(--accent-ink);
  padding: 14px; font-weight: 650; font-size: 1.05rem;
}
.btn-primary:disabled { opacity: 0.5; }
.btn-big { width: 100%; min-height: 60px; margin-top: 20px; font-size: 1.2rem; }
.btn-secondary {
  display: block; text-align: center; margin-top: 16px; padding: 14px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
  color: var(--text); text-decoration: none; font-weight: 500;
}

/* --- Statistik --- */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.segmented { display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; flex: 1 1 auto; }
.segmented button {
  flex: 1; min-height: 40px; border: 0; background: none; border-radius: 9px; font-weight: 500; color: var(--text-2);
}
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgb(0 0 0 / 0.12); }
.filters select {
  flex: 1 1 160px; min-height: 46px; padding: 0 10px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface);
}
#stats-range { margin: 8px 0 0; }

.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 12px 0; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 8px; display: flex; flex-direction: column; align-items: center; text-align: center;
}
.kpi-value { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi-label { font-size: 0.75rem; color: var(--text-2); }
@media (max-width: 380px) { .kpis { grid-template-columns: repeat(2, 1fr); } }

.card {
  margin: 0 0 12px; padding: 14px 12px 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.card figcaption { font-weight: 650; margin: 0 4px 8px; }
.chart-box { position: relative; height: 240px; }

.table-card summary { font-weight: 600; cursor: pointer; }
.table-wrap { overflow-x: auto; margin-top: 12px; }
table { border-collapse: collapse; width: 100%; font-size: 0.875rem; font-variant-numeric: tabular-nums; }
th, td { padding: 6px 8px; border-bottom: 1px solid var(--grid); text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--text-2); font-weight: 600; }

/* --- Verlauf --- */
.history { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.history li {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px;
}
.history .h-title { font-weight: 600; }
.history .h-meta { color: var(--text-2); font-size: 0.875rem; }
.history .h-counts { display: flex; gap: 12px; font-variant-numeric: tabular-nums; font-size: 0.9rem; }
.history .h-counts span { display: inline-flex; align-items: center; gap: 5px; }
.history .h-note { grid-column: 1 / -1; font-size: 0.875rem; color: var(--text-2); font-style: italic; }
.history .h-delete {
  grid-row: 1 / span 2; grid-column: 2;
  border: 1px solid var(--border); background: none; border-radius: 10px; padding: 8px 12px; color: var(--danger);
}

/* --- Toast --- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px); z-index: 10;
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 999px;
  font-weight: 500; max-width: calc(100% - 32px); box-shadow: 0 4px 16px rgb(0 0 0 / 0.2);
}
.toast.error { background: var(--danger); color: #fff; }
