:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface: #fcfcfb;
  --surface-2: #efefec;
  --border: #e0dfda;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7974;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --grid: #e6e5e0;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --band: rgba(12, 163, 12, 0.10);
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --surface-2: #242422;
    --border: #2f2f2c;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #8f8e86;
    --accent: #3987e5;
    --grid: #2b2b28;
    --band: rgba(12, 163, 12, 0.16);
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110; --surface: #1a1a19; --surface-2: #242422; --border: #2f2f2c;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #8f8e86; --accent: #3987e5; --grid: #2b2b28;
  --band: rgba(12, 163, 12, 0.16); --shadow: none;
}

* { 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;
  font-variant-numeric: tabular-nums;
}
.hidden { display: none !important; }
a { color: var(--accent); }
h1 { font-size: 1.35rem; margin: 0 0 1rem; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
h3 { font-size: .95rem; margin: 0 0 .5rem; color: var(--text-2); font-weight: 600; }

/* ---------- Layout ---------- */
.topbar {
  display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap;
  padding: .7rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; }
nav { display: flex; gap: .25rem; flex-wrap: wrap; }
nav a { padding: .35rem .7rem; border-radius: 8px; text-decoration: none; color: var(--text-2); }
nav a.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
main { max-width: 1080px; margin: 0 auto; padding: 1.25rem 1rem 4rem; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 1rem; box-shadow: var(--shadow); }
.stack > * + * { margin-top: 1rem; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { color: var(--critical); min-height: 1.2em; margin: .25rem 0; font-size: .9rem; }

/* ---------- Formulare ---------- */
label { display: flex; flex-direction: column; gap: .25rem; font-size: .85rem; color: var(--text-2); min-width: 0; }
label > input, label > select, label > textarea { width: 100%; }
label > input[type="color"] { width: 42px; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: .45rem .6rem; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { min-height: 70px; resize: vertical; }
input[type="color"] { padding: 2px; width: 42px; height: 36px; }
.btn {
  font: inherit; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 8px; padding: .45rem .8rem; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--critical); }
.btn.small { padding: .25rem .55rem; font-size: .85rem; }
.btn.icon { padding: .35rem .6rem; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { font: inherit; border: 0; background: var(--surface); color: var(--text-2); padding: .35rem .7rem; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--surface-2); color: var(--text); font-weight: 600; }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: .8rem; }

/* ---------- Timerleiste ---------- */
.timerbar {
  display: flex; align-items: center; gap: .8rem; flex-wrap: wrap;
  padding: .6rem 1rem; background: var(--accent); color: var(--accent-ink);
  position: sticky; top: 0; z-index: 9;
}
.timerbar .pulse { width: 10px; height: 10px; border-radius: 50%; background: #fff; animation: pulse 1.4s infinite; }
.timerbar .elapsed { font-size: 1.15rem; font-weight: 700; }
.timerbar .btn { background: rgba(255,255,255,.95); color: #0b0b0b; border-color: transparent; }
.timerbar a { color: inherit; font-weight: 600; }
@keyframes pulse { 50% { opacity: .35; } }

/* ---------- Aufgaben ---------- */
.quickadd { display: grid; grid-template-columns: minmax(0,1fr) 180px 120px auto; gap: .6rem; align-items: end; }
@media (max-width: 720px) { .quickadd { grid-template-columns: minmax(0,1fr) minmax(0,1fr); } .quickadd .grow { grid-column: 1 / -1; } }
.tasklist { display: flex; flex-direction: column; gap: .5rem; }
.task {
  display: grid; grid-template-columns: auto 1fr minmax(160px, 260px) auto; gap: .9rem; align-items: center;
  padding: .7rem .9rem;
}
.task.done .title { color: var(--text-2); }
.task .title { font-weight: 600; text-decoration: none; color: var(--text); }
.task .title:hover { text-decoration: underline; }
.task .meta { font-size: .82rem; color: var(--muted); display: flex; gap: .6rem; flex-wrap: wrap; margin-top: 2px; }
.task.running { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; vertical-align: 0; }
@media (max-width: 720px) {
  .task { grid-template-columns: auto 1fr auto; }
  .task .progress-wrap { grid-column: 1 / -1; grid-row: 2; }
}
.playbtn {
  width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); cursor: pointer; font-size: 14px; display: grid; place-items: center;
}
.playbtn.on { background: var(--accent); border-color: var(--accent); color: #fff; }

.progress-wrap { display: flex; flex-direction: column; gap: 4px; }
.progress-label { display: flex; justify-content: space-between; font-size: .8rem; color: var(--text-2); gap: .5rem; }
.progress { position: relative; height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.progress .fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 4px; background: var(--accent); }
.progress .fill.warning { background: var(--warning); }
.progress .fill.critical { background: var(--critical); }
.progress .mark { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--text-2); }

.badge { display: inline-flex; align-items: center; gap: 4px; font-size: .78rem; font-weight: 600; padding: 1px 7px; border-radius: 999px; border: 1px solid var(--border); color: var(--text-2); white-space: nowrap; }
.badge .sw { width: 8px; height: 8px; border-radius: 50%; }

/* ---------- Detail ---------- */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
@media (max-width: 720px) { .grid2 { grid-template-columns: 1fr; } }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .45rem .4rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; }
td.num, th.num { text-align: right; }
.table-wrap { overflow-x: auto; }
td input { width: 100%; }
.entryform { display: grid; grid-template-columns: 150px 110px 110px 1fr auto; gap: .5rem; align-items: end; }
@media (max-width: 720px) { .entryform { grid-template-columns: minmax(0,1fr) minmax(0,1fr); } }

/* ---------- Auswertung ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: .8rem; }
@media (max-width: 820px) { .kpis { grid-template-columns: repeat(2, 1fr); } }
.kpi .label { font-size: .8rem; color: var(--text-2); }
.kpi .value { font-size: 1.8rem; font-weight: 700; line-height: 1.15; margin: .2rem 0; }
.kpi .hint { font-size: .78rem; color: var(--muted); }
.insight { border-left: 4px solid var(--accent); }
.charts { display: grid; grid-template-columns: 3fr 2fr; gap: .8rem; }
@media (max-width: 820px) { .charts { grid-template-columns: 1fr; } }
svg.chart { width: 100%; height: auto; display: block; overflow: visible; }
svg.chart text { fill: var(--muted); font-size: 11px; }
svg.chart .grid line { stroke: var(--grid); stroke-width: 1; }
svg.chart .axis { stroke: var(--border); }
svg.chart .band { fill: var(--band); }
svg.chart .ref { stroke: var(--text-2); stroke-dasharray: 4 4; stroke-width: 1; }
svg.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
svg.chart .pt { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
svg.chart .hit { fill: transparent; cursor: pointer; }
svg.chart .crosshair { stroke: var(--text-2); stroke-width: 1; }
.legend { display: flex; gap: 1rem; flex-wrap: wrap; font-size: .8rem; color: var(--text-2); margin-top: .4rem; }
.legend .sw { display: inline-block; width: 14px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.bar-mini { height: 6px; background: var(--surface-2); border-radius: 3px; position: relative; min-width: 80px; }
.bar-mini span { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 3px; background: var(--good); }
.empty { text-align: center; padding: 2rem 1rem; color: var(--muted); }

.tooltip {
  position: fixed; z-index: 50; pointer-events: none; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: .45rem .6rem; font-size: .82rem; box-shadow: 0 4px 16px rgba(0,0,0,.15);
  max-width: 260px;
}
.tooltip b { display: block; margin-bottom: 2px; }
.toast {
  position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); z-index: 60;
  background: var(--text); color: var(--bg); padding: .55rem 1rem; border-radius: 8px; font-size: .9rem;
}
.toast.err { background: var(--critical); color: #fff; }
