:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface: #fcfcfb;
  --surface-2: #efeeea;
  --border: #e2e1dc;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7974;
  --accent: #1f8a70;
  --accent-ink: #146b56;
  --neg: #c22e2e;
  --go: #0c8a0c;
  --stop: #d03b3b;
  --abs: #8a5cd0;
  --warn-bg: #fff4d6;
  --warn-ink: #7a5200;
  --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: #2aa585;
    --accent-ink: #6fd3b6;
    --neg: #ef7b7b;
    --go: #17a317;
    --stop: #d94545;
    --abs: #a983e6;
    --warn-bg: #3a2e10;
    --warn-ink: #f5cf74;
    --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: #2aa585; --accent-ink: #6fd3b6; --neg: #ef7b7b; --go: #17a317; --stop: #d94545;
  --abs: #a983e6; --warn-bg: #3a2e10; --warn-ink: #f5cf74; --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, textarea { 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; }
.pad { padding: 16px; }
.neg { color: var(--neg); }
.print-only { display: none; }

/* 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); display: block; width: 100%; text-align: left;
}
.card.flush { padding: 4px 0; }
.card > h2 { margin-bottom: 4px; }
.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; }
.note.warn .link { color: inherit; text-decoration: underline; padding: 0; }

/* 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.go { background: var(--go); color: #fff; }
.btn.stop { background: var(--stop); color: #fff; }
.btn-col { display: grid; gap: 8px; margin-top: 8px; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.link { background: none; border: 0; color: var(--accent-ink); font-weight: 600; padding: 6px 0; cursor: pointer; font-size: .9rem; }
.link.danger { color: var(--neg); font-size: .8rem; }
.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 */
.today-head { margin: 4px 2px 12px; }
.status-line { display: flex; align-items: center; gap: 8px; font-size: 1rem; font-weight: 600; }
.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.abs { background: var(--abs); }
@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; }
.month-teaser { display: flex; justify-content: space-between; align-items: center; cursor: pointer; color: var(--text); }

/* Tagesformular */
.period { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 10px 0 4px; }
.period + .period { border-top: 1px solid var(--border); margin-top: 6px; }
.period-foot { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: center; min-height: 28px; }
.tf { display: grid; gap: 6px; min-width: 0; }
.tf-label { font-size: .8rem; color: var(--muted); font-weight: 600; }
.tf-row { display: grid; gap: 6px; }
.btn.now { padding: 12px 8px; font-size: 1.05rem; }
.day-sum { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; background: var(--surface-2); border-radius: 14px; padding: 10px; text-align: center; margin-bottom: 12px; }
.day-sum div { display: grid; }
.day-sum span { font-size: .75rem; color: var(--muted); }
.day-sum b { font-size: 1.15rem; }

/* Formulare */
.field { display: grid; gap: 6px; margin: 12px 0 0; font-size: .8rem; color: var(--muted); font-weight: 600; }
.field input, .field textarea { color: var(--text); font-weight: 400; font-size: 1rem; }
input[type="text"], input[type="date"], input[type="time"], input[type="password"], textarea {
  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;
}
input[type="time"] { font-size: 1.25rem; font-weight: 650; text-align: center; }
textarea { resize: vertical; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
  border: 1px solid var(--border); background: var(--surface-2); border-radius: 99px; padding: 8px 14px;
  font-weight: 600; font-size: .9rem; cursor: pointer;
}
.chip.on { background: var(--abs); border-color: var(--abs); color: #fff; }
.chip:first-child.on { background: var(--text-2); border-color: var(--text-2); color: var(--surface); }
.check { display: flex; gap: 8px; align-items: center; margin-top: 14px; font-size: .95rem; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); flex: none; }

/* Monat */
.month-nav { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 10px; }
.month-nav h2 { font-size: 1.15rem; }
.sum-grid { display: grid; grid-template-columns: repeat(3, 1fr); text-align: center; }
.sum-grid > div { display: grid; gap: 2px; padding: 0 4px; }
.sum-grid > div + div { border-left: 1px solid var(--border); }
.sum-grid span { font-size: .72rem; color: var(--muted); }
.sum-grid b { font-size: 1.05rem; }
.sum-grid small { font-size: .7rem; color: var(--muted); }
.pay-line { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.amount { font-size: 2rem; font-weight: 800; letter-spacing: -.02em; }
.abs-sum { margin: 6px 0 0; }
.paid-toggle {
  width: 100%; margin-top: 12px; border-radius: 12px; padding: 10px; cursor: pointer; font-weight: 650;
  border: 1px dashed var(--border); background: transparent; color: var(--text-2);
}
.paid-toggle.is-paid { border: 1px solid color-mix(in srgb, var(--go) 50%, var(--surface)); background: color-mix(in srgb, var(--go) 14%, var(--surface)); color: var(--text); }

.pay-diff { margin: 6px 0 0; }
.pay-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 10px; margin-top: 12px; padding-top: 2px; border-top: 1px solid var(--border); }
.pay-form .btn { margin-top: 12px; }
.pay-form .link { grid-column: 1 / -1; margin-top: 6px; }

/* Kalender */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-wd { text-align: center; font-size: .72rem; color: var(--muted); padding-bottom: 2px; }
.cal-day {
  position: relative; border: 0; border-radius: 10px; background: none; outline: 1px solid var(--border); outline-offset: -1px;
  min-height: 52px; padding: 5px 1px 4px; display: flex; flex-direction: column; align-items: center; gap: 1px; cursor: pointer; min-width: 0;
}
.cal-day.work { background: color-mix(in srgb, var(--accent) 22%, var(--surface)); outline: 0; }
.cal-day.absent { background: color-mix(in srgb, var(--abs) 20%, var(--surface)); outline: 0; }
.cal-day.today { outline: 2px solid var(--text); outline-offset: -2px; }
.cal-n { font-size: .85rem; font-weight: 650; }
.cal-h { font-size: .68rem; color: var(--text-2); }
.cal-abs { font-size: .55rem; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.cal-flag { position: absolute; top: 4px; right: 4px; width: 6px; height: 6px; border-radius: 50%; background: var(--abs); }
.cal p { margin: 10px 0 0; }

/* Liste */
.list-row {
  display: flex; gap: 12px; align-items: center; width: 100%; padding: 11px 16px; background: none; border: 0;
  text-align: left; cursor: pointer;
}
.list-row + .list-row { border-top: 1px solid var(--border); }
.list-row:active { background: var(--surface-2); }
.lr-date { width: 78px; flex: none; font-weight: 650; font-size: .9rem; white-space: nowrap; }
.lr-main { flex: 1; display: flex; flex-direction: column; gap: 3px; min-width: 0; font-size: .9rem; }
.lr-main > span { overflow: hidden; text-overflow: ellipsis; }
.lr-val { display: grid; text-align: right; }
.tag { display: inline-block; width: fit-content; font-size: .75rem; font-weight: 650; padding: 2px 8px; border-radius: 99px; background: color-mix(in srgb, var(--abs) 18%, var(--surface)); }

/* Einstellungen */
.rate-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.rate-row span { flex: 1; color: var(--text-2); }
.rate-form { display: grid; gap: 4px; }
.rate-form .btn { margin-top: 12px; }

/* 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(--bg); 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; margin-bottom: 12px; }
.sheet-head h2 { font-size: 1.15rem; }
.sheet .day-sum { margin-bottom: 0; }

/* Navigation unten */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 6; display: grid; grid-template-columns: repeat(3, 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); }

/* Drucken: nur die Monatsabrechnung */
@media print {
  :root { color-scheme: light; --bg: #fff; --surface: #fff; --surface-2: #fff; --text: #000; --text-2: #222; --muted: #555; --border: #bbb; --shadow: none; }
  body { padding: 0; background: #fff; }
  .topbar, .tabbar, .no-print, #toast { display: none !important; }
  .print-only { display: block; }
  .print-head { margin-bottom: 12px; }
  .print-head p { margin: 4px 0 0; font-size: 1.1rem; }
  main { max-width: none; }
  .card { break-inside: avoid; border-color: #bbb; }
  .list-row { break-inside: avoid; }
}

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