:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface: #fcfcfb;
  --surface-2: #efeeea;
  --border: #e2e1dc;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7974;
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --pos: #1c5cab;      /* Plus: blau (Diverging-Paar blau/rot) */
  --neg: #c22e2e;      /* Minus: rot */
  --go: #0c8a0c;
  --stop: #d03b3b;
  --warn-bg: #fff4d6;
  --warn-ink: #7a5200;
  --grid: #e6e5e0;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 2px 10px rgba(0, 0, 0, .04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f0f0e;
    --surface: #1a1a19;
    --surface-2: #262624;
    --border: #2e2e2c;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #8f8e88;
    --accent: #3987e5;
    --accent-ink: #86b6ef;
    --pos: #6da7ec;
    --neg: #ef7b7b;
    --go: #17a317;
    --stop: #d94545;
    --warn-bg: #3a2e10;
    --warn-ink: #f5cf74;
    --grid: #2c2c2a;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f0f0e; --surface: #1a1a19; --surface-2: #262624; --border: #2e2e2c; --text: #f0efec; --text-2: #c3c2b7;
  --muted: #8f8e88; --accent: #3987e5; --accent-ink: #86b6ef; --pos: #6da7ec; --neg: #ef7b7b; --go: #17a317; --stop: #d94545;
  --warn-bg: #3a2e10; --warn-ink: #f5cf74; --grid: #2c2c2a; --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
button, input, select { font: inherit; color: inherit; }
h1, h2 { margin: 0; }
h2 { font-size: 1rem; font-weight: 650; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.center { text-align: center; display: block; margin-left: auto; margin-right: auto; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }

/* Kopfzeile */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.topbar h1 { font-size: 1.5rem; font-weight: 750; letter-spacing: -.01em; }
.sync { font-size: .75rem; color: var(--warn-ink); background: var(--warn-bg); padding: 2px 8px; border-radius: 99px; }
.konto-chip {
  margin-left: auto; border: 1px solid var(--border); background: var(--surface); border-radius: 99px;
  padding: 5px 12px; display: flex; gap: 6px; align-items: baseline; font-weight: 700; cursor: pointer;
}
.konto-chip-label { font-size: .72rem; font-weight: 500; color: var(--muted); }

main { max-width: 560px; margin: 0 auto; padding: 4px 16px 16px; }

/* Karten */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
  padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.card.flush { padding: 4px 0; }
.card.welcome { border-color: var(--accent); }
.card.welcome p { margin: 6px 0 12px; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.note { padding: 10px 12px; border-radius: 12px; background: var(--surface-2); margin: 10px 0 0; font-size: .9rem; }
.note.warn { background: var(--warn-bg); color: var(--warn-ink); margin-bottom: 12px; }

/* Buttons */
.btn {
  border: 0; border-radius: 14px; padding: 12px 18px; font-weight: 650; cursor: pointer;
  transition: transform .08s ease, filter .15s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.secondary { background: var(--surface-2); color: var(--text); }
.btn.full { width: 100%; margin-top: 12px; }
.btn.big { font-size: 1.25rem; padding: 18px; width: 100%; border-radius: 18px; color: #fff; }
.btn.go { background: var(--go); }
.btn.stop { background: var(--stop); }
.btn-col { display: grid; gap: 8px; }
.link { background: none; border: 0; color: var(--accent-ink); font-weight: 600; padding: 6px 0; cursor: pointer; font-size: .9rem; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 0; background: var(--surface-2); font-size: 1.4rem;
  line-height: 1; cursor: pointer; display: inline-grid; place-items: center; flex: none;
}
.icon-btn.small { width: 32px; height: 32px; font-size: 1.1rem; border-radius: 10px; }

/* Heute */
.status-line { display: flex; align-items: center; gap: 8px; font-size: .95rem; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.on { background: var(--go); box-shadow: 0 0 0 4px color-mix(in srgb, var(--go) 22%, transparent); animation: pulse 2s infinite; }
.dot.break { background: #fab219; }
@keyframes pulse { 50% { box-shadow: 0 0 0 7px color-mix(in srgb, var(--go) 6%, transparent); } }
.date-line { color: var(--muted); font-size: .85rem; margin: 2px 0 0 18px; }
.ring-wrap { position: relative; width: 210px; height: 210px; margin: 14px auto 16px; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 9; stroke-linecap: round; }
.ring-bg { stroke: var(--surface-2); }
.ring-fg { stroke: var(--accent); transition: stroke-dasharray .6s ease; }
.ring-over { stroke: var(--go); stroke-width: 9; transition: stroke-dasharray .6s ease; }
.ring-center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring-val { font-size: 2.1rem; font-weight: 750; letter-spacing: -.02em; }
.ring-sub { color: var(--muted); font-size: .85rem; }
.actions { display: grid; gap: 8px; }
.stats3 { display: grid; grid-template-columns: repeat(3, 1fr); margin-top: 14px; text-align: center; }
.stats3 > div { display: grid; gap: 2px; }
.stats3 > div + div { border-left: 1px solid var(--border); }
.stats3 span { font-size: .75rem; color: var(--muted); }
.stats3 b { font-size: 1.05rem; }
.konto-big { font-size: 2.4rem; font-weight: 800; letter-spacing: -.02em; margin: 4px 0 0; }
.progress { height: 10px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin: 12px 0 8px; }
.progress-bar { height: 100%; background: var(--accent); border-radius: 99px; transition: width .6s ease; }
.sessions { list-style: none; margin: 8px 0 0; padding: 0; }
.sessions li { display: flex; justify-content: space-between; padding: 8px 0; border-top: 1px solid var(--border); }
.sessions li:first-child { border-top: 0; }

/* Woche / Monat */
.pager { display: flex; align-items: center; gap: 10px; margin: 4px 0 8px; }
.pager-title { flex: 1; text-align: center; display: grid; }
.pager-title b { font-size: 1.1rem; }
.pager-title span { font-size: .8rem; color: var(--muted); }
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 8px 0 12px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 10px 12px; box-shadow: var(--shadow); }
.tile-label { font-size: .75rem; color: var(--muted); }
.tile-val { font-size: 1.3rem; font-weight: 750; }
.tile-sub { font-size: .7rem; color: var(--muted); }
.day-list { list-style: none; margin: 0; padding: 0; }
.day-row { display: flex; gap: 12px; align-items: center; padding: 11px 16px; cursor: pointer; }
.day-row + .day-row { border-top: 1px solid var(--border); }
.day-row.today { background: color-mix(in srgb, var(--accent) 7%, transparent); }
.day-row.dim .dr-date { color: var(--muted); }
.day-row:active { background: var(--surface-2); }
.dr-date { width: 46px; display: grid; flex: none; }
.dr-date span { font-size: .78rem; color: var(--muted); }
.dr-mid { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; font-size: .9rem; }
.dr-mid > span { overflow: hidden; text-overflow: ellipsis; }
.dr-num { text-align: right; display: grid; }
.badge { display: inline-block; width: fit-content; font-size: .72rem; font-weight: 650; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--text-2); }
.b-urlaub { background: color-mix(in srgb, #1baf7a 20%, var(--surface)); }
.b-elternzeit { background: color-mix(in srgb, #2a78d6 18%, var(--surface)); }
.b-krank { background: color-mix(in srgb, #e87ba4 24%, var(--surface)); }
.b-feiertag { background: color-mix(in srgb, #eda100 24%, var(--surface)); }
.b-gleittag { background: color-mix(in srgb, #6250d6 18%, var(--surface)); }
.b-run { background: color-mix(in srgb, var(--go) 20%, var(--surface)); }

/* ATOSS-Status: Symbol + Text, Farbe nur zusätzlich */
.atoss {
  display: inline-flex; align-items: center; gap: 4px; width: fit-content; font-size: .72rem; font-weight: 650;
  padding: 3px 9px; border-radius: 99px; border: 1px solid var(--border); background: transparent; color: var(--text-2);
  white-space: nowrap; line-height: 1.3;
}
button.atoss { cursor: pointer; min-height: 26px; }
button.atoss:active { transform: scale(.96); }
.atoss.a-offen { border-style: dashed; color: var(--muted); }
.atoss.a-beantragt { background: color-mix(in srgb, #fab219 26%, var(--surface)); border-color: color-mix(in srgb, #fab219 55%, var(--surface)); color: var(--text); }
.atoss.a-genehmigt { background: color-mix(in srgb, #0ca30c 18%, var(--surface)); border-color: color-mix(in srgb, #0ca30c 45%, var(--surface)); color: var(--text); }
.atoss-sum { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 12px; font-size: .85rem; }
.atoss-sum b { margin-right: 2px; }
.atoss-row { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); }
.atoss-note { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 0 0 12px; }
.atoss-note .link { white-space: nowrap; padding: 0; }
.cal-atoss { position: absolute; top: 3px; left: 5px; font-size: .62rem; font-weight: 800; line-height: 1; }
.cal-atoss.a-offen { color: var(--muted); }
.cal-atoss.a-beantragt { color: var(--warn-ink); }
.cal-atoss.a-genehmigt { color: var(--go); }

/* Diagramme */
.chart { position: relative; margin-top: 8px; touch-action: pan-y; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .zero { stroke: var(--muted); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 10px; }
.chart .axis.today { fill: var(--text); font-weight: 700; }
.chart .bar { fill: var(--accent); }
.chart .bar.running { fill: color-mix(in srgb, var(--accent) 60%, var(--surface)); }
.chart .soll { stroke: var(--text-2); stroke-width: 2; stroke-dasharray: 3 3; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .hit.active { fill: color-mix(in srgb, var(--text) 6%, transparent); }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dotm { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart .cross { stroke: var(--muted); stroke-width: 1; }
.tip {
  position: absolute; pointer-events: none; background: var(--text); color: var(--bg); border-radius: 10px;
  padding: 6px 10px; font-size: .78rem; display: grid; white-space: nowrap; z-index: 2;
}
.tip[hidden], .chart .cross[hidden] { display: none; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; font-size: .75rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { display: inline-block; flex: none; }
.lg-bar { width: 10px; height: 10px; border-radius: 3px; background: var(--accent); }
.lg-soll { width: 14px; border-top: 2px dashed var(--text-2); }
.sw { width: 12px; height: 12px; border-radius: 4px; }

/* Kalender */
.cal-head, .cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-head span { text-align: center; font-size: .72rem; color: var(--muted); padding-bottom: 4px; }
.cal-cell {
  position: relative; border: 0; border-radius: 10px; background: var(--surface-2); min-height: 54px; padding: 5px 2px 4px;
  display: flex; flex-direction: column; align-items: center; gap: 1px; cursor: pointer;
}
.cal-cell.empty { background: none; cursor: default; }
.cal-cell.future { background: none; outline: 1px solid var(--border); outline-offset: -1px; }
.cal-cell.today { outline: 2px solid var(--text); outline-offset: -2px; }
.cal-day { font-size: .85rem; font-weight: 650; }
.cal-val { font-size: .62rem; color: var(--text-2); letter-spacing: -.02em; }
.cal-type { position: absolute; top: 3px; right: 5px; font-size: .58rem; font-weight: 700; color: var(--text-2); }
.p1 { background: color-mix(in srgb, var(--accent) 16%, var(--surface)); }
.p2 { background: color-mix(in srgb, var(--accent) 32%, var(--surface)); }
.p3 { background: color-mix(in srgb, var(--accent) 50%, var(--surface)); }
.n1 { background: color-mix(in srgb, #e34948 14%, var(--surface)); }
.n2 { background: color-mix(in srgb, #e34948 28%, var(--surface)); }
.n3 { background: color-mix(in srgb, #e34948 44%, var(--surface)); }
.cal-cell.p3 .cal-val, .cal-cell.n3 .cal-val { color: var(--text); }

details summary { cursor: pointer; font-weight: 650; padding: 2px 0; }
.table-wrap { overflow-x: auto; margin-top: 8px; }
table { width: 100%; border-collapse: collapse; font-size: .8rem; }
th, td { text-align: left; padding: 6px 6px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; }

/* Formulare */
.field { display: grid; gap: 6px; margin: 12px 0 0; }
.field > span { font-size: .8rem; color: var(--muted); font-weight: 600; }
input[type="text"], input[type="date"], input[type="time"], input[type="number"], input[type="password"], select {
  width: 100%; border: 1px solid var(--border); background: var(--surface-2); border-radius: 12px; padding: 11px 12px;
  min-height: 46px; appearance: none; -webkit-appearance: none;
}
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; }
.chips { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span { display: block; text-align: center; padding: 10px 0; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); cursor: pointer; font-weight: 600; }
.chip input:checked + span { background: var(--accent); color: #fff; border-color: var(--accent); }
.chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.rule { display: flex; align-items: center; gap: 6px; margin-top: 10px; font-size: .88rem; }
.rule span { white-space: nowrap; }
.rule .w-s { width: 72px; text-align: center; padding: 8px; min-height: 40px; }
.rule .w-xs { width: 60px; text-align: center; padding: 8px; min-height: 40px; }
.rule .icon-btn { margin-left: auto; }
.model-list { list-style: none; padding: 0; margin: 14px 0 0; font-size: .85rem; }
.model-list li { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--border); }
.model-list li span:first-child { font-weight: 650; min-width: 98px; }
.model-list li span:nth-child(2) { flex: 1; color: var(--text-2); }
.check { display: flex; gap: 8px; align-items: center; margin-top: 10px; font-size: .9rem; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); flex: none; }
.check.nobreak { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); align-items: flex-start; cursor: pointer; }
.check.nobreak input { margin-top: 2px; }

/* Dialog (Tag bearbeiten) */
dialog {
  border: 0; padding: 0; background: transparent; color: var(--text); max-width: 560px; width: 100%;
  margin: auto auto 0; max-height: 92dvh;
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }
.sheet {
  background: var(--surface); border-radius: 22px 22px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  max-height: 92dvh; overflow-y: auto;
}
@media (min-width: 600px) { dialog { margin: auto; } .sheet { border-radius: 22px; } }
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.sheet-head h2 { font-size: 1.15rem; }
.ed-rows { display: grid; gap: 8px; }
.ed-row { display: flex; align-items: center; gap: 6px; }
.ed-row input { flex: 1; min-width: 0; }
.ed-sum { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; margin-top: 14px; background: var(--surface-2); border-radius: 14px; padding: 10px 6px; text-align: center; }
.ed-sum div { display: grid; }
.ed-sum span { font-size: .68rem; color: var(--muted); }
.ed-sum b { font-size: .95rem; }
.ed-err { color: var(--neg); font-weight: 600; min-height: 1.2em; margin: 8px 0 0; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.bulk-btn { margin: 0 0 12px; }
.sheet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }

/* Navigation unten */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 6; display: grid; grid-template-columns: repeat(4, 1fr);
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.tabbar button { background: none; border: 0; display: grid; justify-items: center; gap: 2px; padding: 4px 0; color: var(--muted); font-size: .7rem; font-weight: 600; cursor: pointer; }
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar button.active { color: var(--accent-ink); }

/* Login */
.login { position: fixed; inset: 0; z-index: 20; background: var(--bg); display: grid; place-items: center; padding: 16px; }
.login[hidden] { display: none; }
.login-card { width: 100%; max-width: 340px; display: grid; gap: 12px; text-align: center; justify-items: center; }
.login-card p { margin: 0; color: var(--muted); font-size: .9rem; }
.login-card input, .login-card .btn { width: 100%; }
.login-err { color: var(--neg) !important; font-weight: 600; min-height: 1.2em; }

/* Hinweis unten */
#toast {
  position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: .9rem; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 30; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
