:root {
  --bg: #f4f6f7;
  --surface: #ffffff;
  --surface-2: #eef2f3;
  --text: #11181c;
  --muted: #5f6b72;
  --border: #dde3e6;
  --accent: #0f766e;
  --accent-contrast: #ffffff;
  --in: #15803d;
  --in-soft: #dcfce7;
  --out: #b91c1c;
  --out-soft: #fee2e2;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --shadow: 0 1px 2px rgb(0 0 0 / .05), 0 4px 16px rgb(0 0 0 / .05);
  --radius: 16px;
  color-scheme: light;
}

/* Dunkel: nach Systemeinstellung (ausser "Hell" ist gewählt) oder ausdrücklich gewählt */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1416;
    --surface: #131f22;
    --surface-2: #1b2a2e;
    --text: #e8eef0;
    --muted: #93a3a9;
    --border: #26383d;
    --accent: #2dd4bf;
    --accent-contrast: #062925;
    --in: #4ade80;
    --in-soft: #12351f;
    --out: #f87171;
    --out-soft: #3b1515;
    --warn: #fbbf24;
    --warn-soft: #3a2b0c;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1416;
  --surface: #131f22;
  --surface-2: #1b2a2e;
  --text: #e8eef0;
  --muted: #93a3a9;
  --border: #26383d;
  --accent: #2dd4bf;
  --accent-contrast: #062925;
  --in: #4ade80;
  --in-soft: #12351f;
  --out: #f87171;
  --out-soft: #3b1515;
  --warn: #fbbf24;
  --warn-soft: #3a2b0c;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
button, input, select, textarea { font: inherit; color: inherit; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.sync { font-size: 13px; color: var(--muted); }
.icon-btn {
  width: 40px; height: 40px; display: grid; place-items: center;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface); cursor: pointer;
}
.icon-btn:disabled svg { animation: spin .8s linear infinite; }
.sync.error { color: var(--out); }

main {
  max-width: 560px; margin: 0 auto; padding: 4px 16px 32px;
  display: grid; gap: 14px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.card h2 { font-size: 15px; margin: 0 0 12px; color: var(--muted); font-weight: 600; letter-spacing: .02em; }
.skeleton { color: var(--muted); text-align: center; padding: 40px 16px; }

/* Status ----------------------------------------------------------------- */
.status { display: grid; gap: 12px; transition: background-color .3s, border-color .3s; }
/* Ganze Kachel leicht eingefärbt, damit der Status auf einen Blick erkennbar ist */
.status.in { background: color-mix(in srgb, var(--in-soft) 75%, var(--surface)); border-color: color-mix(in srgb, var(--in) 45%, var(--border)); }
.status.out { background: color-mix(in srgb, var(--out-soft) 75%, var(--surface)); border-color: color-mix(in srgb, var(--out) 45%, var(--border)); }
.status.in .status-title { color: var(--in); }
.status.out .status-title { color: var(--out); }
.status.in .stat, .status.out .stat { background: color-mix(in srgb, var(--surface) 65%, transparent); }
.status-main { display: flex; align-items: center; gap: 12px; }
.dot { width: 14px; height: 14px; border-radius: 50%; flex: none; background: var(--muted); }
.dot.in { background: var(--in); box-shadow: 0 0 0 5px var(--in-soft); }
.dot.out { background: var(--out); box-shadow: 0 0 0 5px var(--out-soft); }
.status-title { font-size: 22px; font-weight: 700; line-height: 1.2; }
.status-sub { color: var(--muted); font-size: 14px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 8px; }
.stat { background: var(--surface-2); border-radius: 12px; padding: 8px 12px; }
.stat-label { font-size: 12px; color: var(--muted); }
.stat-value { font-size: 18px; font-weight: 650; font-variant-numeric: tabular-nums; }

/* Formular --------------------------------------------------------------- */
.field { display: grid; gap: 6px; margin-bottom: 12px; }
.field label { font-size: 13px; color: var(--muted); font-weight: 600; }
select, textarea, input[type=time], input[type=date], input[type=password], input[type=text] {
  width: 100%; min-height: 46px;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  outline: none;
}
select:focus, textarea:focus, input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
textarea { min-height: 64px; resize: vertical; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--border); background: var(--surface); border-radius: 999px;
  padding: 5px 12px; font-size: 13px; cursor: pointer; max-width: 100%;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chip.active { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 420px) { .row { grid-template-columns: 1fr; } }
details.more summary { cursor: pointer; color: var(--muted); font-size: 14px; margin: 4px 0 12px; }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 4px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 10px 16px;
  border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface-2); cursor: pointer; font-weight: 600;
}
.btn:disabled { opacity: .55; cursor: progress; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn.big { min-height: 64px; font-size: 19px; border-radius: 14px; }
.btn.in { background: var(--in); border-color: var(--in); color: #fff; }
.btn.out { background: var(--out); border-color: var(--out); color: #fff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn.in, :root:not([data-theme="light"]) .btn.out { color: #0b1416; } }
:root[data-theme="dark"] .btn.in, :root[data-theme="dark"] .btn.out { color: #0b1416; }
.btn.suggested { box-shadow: 0 0 0 3px var(--bg), 0 0 0 5px color-mix(in srgb, var(--text) 35%, transparent); }
.btn .spinner { width: 18px; height: 18px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Einträge --------------------------------------------------------------- */
.day + .day { margin-top: 14px; }
.day-title { font-size: 13px; font-weight: 700; color: var(--muted); margin: 0 0 6px; }
.entries { list-style: none; margin: 0; padding: 0; }
.entry {
  display: grid; grid-template-columns: 54px auto 1fr auto; align-items: center; gap: 10px;
  padding: 10px 0; border-top: 1px solid var(--border);
}
.entry:first-child { border-top: 0; }
.entry-time { font-weight: 700; font-variant-numeric: tabular-nums; font-size: 17px; }
.badge { font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 999px; background: var(--surface-2); }
.badge.B { background: var(--in-soft); color: var(--in); }
.badge.G { background: var(--out-soft); color: var(--out); }
.entry-text { min-width: 0; font-size: 14px; }
.entry-text .task { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry-text .code { color: var(--muted); font-size: 13px; }
.entry-del {
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--border);
  background: transparent; color: var(--out); cursor: pointer; display: grid; place-items: center;
}
.entry-del:hover { background: var(--out-soft); }
.entry .locked { width: 38px; text-align: center; color: var(--muted); opacity: .5; font-size: 13px; }
.empty { color: var(--muted); font-size: 14px; }
.hint { color: var(--muted); font-size: 13px; margin-top: 10px; }

/* Einstellungen ---------------------------------------------------------- */
.settings summary { cursor: pointer; font-weight: 600; list-style: none; display: flex; justify-content: space-between; }
.settings summary::after { content: "▾"; color: var(--muted); }
.settings[open] summary::after { content: "▴"; }
.settings-body { display: grid; gap: 14px; margin-top: 14px; }
.rule { border: 1px solid var(--border); border-radius: 12px; padding: 12px; display: grid; gap: 10px; }
.rule-head { display: flex; justify-content: space-between; gap: 10px; align-items: start; }
.rule-title { font-weight: 600; }
.rule-desc { color: var(--muted); font-size: 13px; }
.days { display: flex; gap: 4px; flex-wrap: wrap; }
.days .chip { padding: 4px 9px; }
.switch { position: relative; width: 46px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--border); border-radius: 999px; transition: .15s; cursor: pointer; }
.switch span::before { content: ""; position: absolute; width: 22px; height: 22px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(18px); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row .btn { flex: 1 1 auto; }

.group { display: grid; gap: 12px; padding-top: 14px; border-top: 1px solid var(--border); }
.group:first-child { border-top: 0; padding-top: 0; }
.group h3 { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1.3fr; gap: 8px; }
.row3 .field { margin: 0; }
@media (max-width: 420px) { .row3 { grid-template-columns: 1fr 1fr; } .row3 .field:last-child { grid-column: 1 / -1; } }
.devices { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.device { display: flex; justify-content: space-between; align-items: center; gap: 10px; border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; }
.tag { display: inline-block; margin-left: 6px; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--muted); vertical-align: middle; }
.pair { display: grid; grid-template-columns: 170px 1fr; gap: 14px; align-items: center; }
@media (max-width: 420px) { .pair { grid-template-columns: 1fr; justify-items: center; text-align: center; } }
.qr { width: 170px; background: #fff; border-radius: 12px; padding: 6px; }
.qr svg { display: block; width: 100%; height: auto; }
.paircode { font: 700 26px/1.2 ui-monospace, "Cascadia Mono", Consolas, monospace; letter-spacing: .12em; margin: 6px 0; }
.btn.danger { color: var(--out); }

/* Zeitwahl -------------------------------------------------------------- */
.timepick, .segmented { display: flex; gap: 0; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--surface-2); }
.seg { flex: 1 1 0; min-height: 46px; border: 0; background: transparent; padding: 8px 14px; cursor: pointer; font-weight: 600; color: var(--muted); }
.seg.active { background: var(--accent); color: var(--accent-contrast); }
.timepick .seg { flex: 0 0 auto; padding: 8px 18px; }
.timepick .seg-input { flex: 1 1 auto; border: 0; border-left: 1px solid var(--border); border-radius: 0; background: transparent; color: var(--muted); font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; min-width: 0; }
.timepick .seg-input.active { color: var(--text); background: var(--surface); box-shadow: inset 0 0 0 2px var(--accent); }
.timepick .seg-input:focus { box-shadow: inset 0 0 0 2px var(--accent); }
.time-hint { font-size: 12px; color: var(--muted); min-height: 1em; }
.time-hint.warn { color: var(--warn, #b26a00); font-weight: 600; }
.daypick { margin-top: 6px; }
.daypick .seg { min-height: 40px; font-variant-numeric: tabular-nums; }
.seg:disabled { opacity: .35; cursor: not-allowed; text-decoration: line-through; }
.remark { font-size: 13px; color: var(--text); opacity: .85; margin-top: 2px; overflow-wrap: anywhere; white-space: pre-line; }

/* Anmeldung -------------------------------------------------------------- */
.onboarding h1 { margin: 0 0 6px; font-size: 24px; }
.onboarding p { margin: 0 0 14px; }
.onboarding form .btn { width: 100%; }
.form-error { color: var(--out); font-size: 14px; margin: 0 0 10px; min-height: 0; }
.form-error:empty { display: none; }
.help { margin: 0 0 8px; padding-left: 20px; color: var(--muted); font-size: 14px; }
form.inline { display: flex; gap: 8px; margin-top: 10px; }
form.inline input { flex: 1; text-transform: uppercase; letter-spacing: .1em; }

/* Toasts & Dialog -------------------------------------------------------- */
.toasts { position: fixed; left: 0; right: 0; bottom: calc(16px + env(safe-area-inset-bottom)); display: grid; justify-items: center; gap: 8px; z-index: 20; pointer-events: none; padding: 0 16px; }
.toast {
  pointer-events: auto; max-width: 520px; width: 100%;
  background: var(--text); color: var(--bg); padding: 12px 16px; border-radius: 12px;
  box-shadow: 0 8px 24px rgb(0 0 0 / .25); font-size: 15px;
  animation: pop .18s ease-out;
}
.toast.ok { background: var(--in); color: #fff; }
.toast.warn { background: var(--warn); color: #fff; }
.toast.error { background: var(--out); color: #fff; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }
.banner { background: var(--warn-soft); color: var(--warn); border-radius: 12px; padding: 10px 14px; font-size: 14px; }

.dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 20px; width: min(420px, calc(100% - 32px)); }
.dialog::backdrop { background: rgb(0 0 0 / .45); }
.dialog h2 { margin: 0 0 8px; font-size: 18px; }
.dialog p { color: var(--muted); font-size: 14px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

/* Pausieren -------------------------------------------------------------- */
.snooze-note { display: block; font-size: 14px; color: var(--warn); background: var(--warn-soft); border-radius: 10px; padding: 8px 12px; text-decoration: none; font-weight: 600; }
.rule.snooze.active { background: var(--warn-soft); border-color: transparent; }
.rule.snooze.active .rule-title { color: var(--warn); }
.snooze-date { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px; }
.snooze-date label { font-size: 13px; color: var(--muted); font-weight: 600; }
@media (max-width: 420px) { .snooze-date { grid-template-columns: 1fr auto; } .snooze-date label { grid-column: 1 / -1; } }
.group h3 .tag { text-transform: none; letter-spacing: 0; font-weight: 500; }

/* Anordnung: schmal alles untereinander, breit nebeneinander ---------------- */
.cols, .col { display: contents; }
@media (min-width: 980px) {
  :root:not([data-layout="single"]) main { max-width: 1180px; }
  :root:not([data-layout="single"]) .cols {
    display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 14px; align-items: start;
  }
  :root:not([data-layout="single"]) .col { display: grid; gap: 14px; align-content: start; }
  /* Einstellungen in zwei Spalten */
  :root:not([data-layout="single"]) .settings-body { display: block; columns: 2; column-gap: 36px; }
  :root:not([data-layout="single"]) .settings-body > .group {
    break-inside: avoid; border-top: 0; padding-top: 0; margin-bottom: 26px;
  }
}
.rule-head > .btn { white-space: nowrap; flex: none; }

/* Zeit- & Datumsfeld (PC: eigene Felder, Touch: System-Dialoge) ----------- */
.picker {
  position: relative; display: flex; align-items: center; min-height: 46px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px;
}
.picker:focus-within, .picker.open { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.picker .picker-text {
  flex: 1 1 auto; width: 100%; min-width: 0; min-height: 44px;
  padding: 10px 4px 10px 12px; border: 0; background: transparent; box-shadow: none;
  font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: .02em;
}
.picker .picker-text:focus { border: 0; box-shadow: none; }
.picker .picker-text::placeholder { color: var(--muted); font-weight: 400; }
.picker-btn {
  flex: none; align-self: stretch; width: 44px; display: grid; place-items: center;
  border: 0; background: transparent; color: var(--muted); cursor: pointer; border-radius: 0 11px 11px 0;
}
.picker-btn:hover, .picker.open .picker-btn { color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }

/* … im Stempel-Block als Teil von [Jetzt | Zeit] */
.timepick .picker { flex: 1 1 auto; min-width: 0; border: 0; border-left: 1px solid var(--border); border-radius: 0; background: transparent; }
.timepick .picker.active { background: var(--surface); }
.timepick .picker:focus-within, .timepick .picker.open, .timepick .picker.active { box-shadow: inset 0 0 0 2px var(--accent); }
.timepick .picker-btn { border-radius: 0; }

.picker-pop {
  position: fixed; z-index: 50; max-width: calc(100vw - 16px);
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 16px;
  box-shadow: 0 16px 40px rgb(0 0 0 / .24);
}

/* Digitaluhr: zwei Rädchen nebeneinander, Zahlen oben/unten verblassen */
.tw { width: 252px; padding: 10px 12px 12px; }
.tw-wheels { position: relative; display: flex; align-items: center; justify-content: center; gap: 2px; }
.tw-wheels::before { /* Markierung der gewählten Zeile */
  content: ""; position: absolute; left: 6px; right: 6px; top: 50%; height: 44px; transform: translateY(-50%);
  background: color-mix(in srgb, var(--accent) 14%, var(--surface-2)); border-radius: 12px; pointer-events: none;
}
.tw-col { position: relative; }
.tw-list {
  height: 200px; width: 76px; overflow-y: auto; padding: 80px 0; box-sizing: border-box;
  scroll-snap-type: y mandatory; scrollbar-width: none; outline: none; cursor: ns-resize; user-select: none;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 38%, #000 62%, transparent 100%);
  mask-image: linear-gradient(to bottom, transparent 0, #000 38%, #000 62%, transparent 100%);
}
.tw-list::-webkit-scrollbar { display: none; }
/* Fokus (Tastatur): gewählte Zahl in Akzentfarbe statt Rahmen, damit das Verblassen bleibt */
.tw-list:focus-visible .tw-item.active { color: var(--accent); }
.tw-item {
  height: 40px; display: grid; place-items: center; scroll-snap-align: center;
  font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--muted);
  transition: color .12s, font-size .12s;
}
.tw-item.active { color: var(--text); font-size: 32px; font-weight: 700; }
.tw-colon { position: relative; font-size: 30px; font-weight: 700; color: var(--text); padding-bottom: 4px; }
.tw-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; }
.tw-hint { font-size: 11px; color: var(--muted); white-space: nowrap; }
.tw-ok { min-height: 36px; padding: 6px 14px; font-size: 14px; }

/* Kalender */
.cal { width: 300px; padding: 10px 12px 12px; }
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.cal-title { font-weight: 700; }
.cal-nav { width: 34px; height: 34px; display: grid; place-items: center; border: 0; border-radius: 10px; background: transparent; color: var(--text); cursor: pointer; }
.cal-nav:hover { background: var(--surface-2); }
.cal-nav:disabled { opacity: .3; cursor: default; background: transparent; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-wd { font-size: 11px; font-weight: 600; color: var(--muted); text-align: center; padding: 4px 0; }
.cal-day {
  height: 36px; border: 0; border-radius: 10px; background: transparent; cursor: pointer;
  font-variant-numeric: tabular-nums; font-weight: 500;
}
.cal-day:hover:not(:disabled) { background: var(--surface-2); }
.cal-day.today { box-shadow: inset 0 0 0 1.5px var(--accent); font-weight: 700; }
.cal-day.active { background: var(--accent); color: var(--accent-contrast); font-weight: 700; }
/* Hover auf dem gewählten Tag: Akzentfarbe behalten (nur leicht abgedunkelt), Zahl bleibt gut lesbar */
.cal-day.active:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 82%, #000); color: #fff; }
.cal-day:disabled { color: var(--muted); opacity: .4; cursor: default; }
.cal-day:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
