:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --text: #1d1f23;
  --muted: #6b6f76;
  --line: #e2ded5;
  --accent: #2f6f62;
  --accent-text: #ffffff;
  --danger: #b3412f;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1d21;
    --surface: #25282d;
    --text: #eceae4;
    --muted: #9da1a8;
    --line: #363a40;
    --accent: #6cbfa9;
    --accent-text: #10201c;
    --danger: #f08a75;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1b1d21; --surface: #25282d; --text: #eceae4; --muted: #9da1a8;
  --line: #363a40; --accent: #6cbfa9; --accent-text: #10201c; --danger: #f08a75;
  color-scheme: dark;
}

* { 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;
  padding: env(safe-area-inset-top) 0 calc(64px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
main { max-width: 640px; margin: 0 auto; padding: 0 16px 24px; }
h1 { font-size: 1.15rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 20px 0 8px; }
p { margin: 6px 0; }
.muted { color: var(--muted); font-size: .9rem; }

.top {
  max-width: 640px; margin: 0 auto; padding: 14px 16px 8px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 5px 12px; font: inherit; font-size: .9rem; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
}
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.chip .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); }

button, input, select, textarea { font: inherit; color: inherit; }
.btn {
  border: 0; border-radius: 10px; padding: 10px 16px; cursor: pointer;
  background: var(--accent); color: var(--accent-text); font-weight: 600;
}
.btn.ghost { background: transparent; color: var(--accent); border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--line); }
.btn:disabled { opacity: .5; cursor: default; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin: 10px 0;
}
label.field { display: block; margin: 10px 0; }
label.field span { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=date], input[type=time], select, textarea {
  width: 100%; padding: 10px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg);
}
textarea { min-height: 60px; resize: vertical; }
.colors { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch {
  width: 34px; height: 34px; border-radius: 50%; border: 3px solid transparent;
  background: var(--c); cursor: pointer;
}
.swatch[aria-pressed="true"] { border-color: var(--text); }

/* Kalender */
.month-head { display: flex; align-items: center; justify-content: space-between; margin: 8px 0; }
.month-head h2 { margin: 0; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; font-size: 1.1rem;
}
.grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.wd { text-align: center; font-size: .75rem; color: var(--muted); padding: 2px 0; }
.day {
  position: relative; aspect-ratio: 1 / 1.15; border: 0; border-radius: 10px; padding: 4px;
  background: var(--surface); text-align: left; cursor: pointer; overflow: hidden;
  display: flex; flex-direction: column; justify-content: space-between;
}
.day.has { background: color-mix(in srgb, var(--c) 28%, var(--surface)); }
.day::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 5px;
  background: var(--bar, var(--c, transparent));
}
.day.out { opacity: .4; }
.day .n { font-size: .9rem; font-weight: 600; }
.day.today .n {
  background: var(--text); color: var(--bg); border-radius: 999px; padding: 0 6px; align-self: flex-start;
}
.day .flag { font-size: .62rem; color: var(--muted); white-space: nowrap; overflow: hidden; }
.day.pending::before {
  content: ""; position: absolute; top: 0; right: 0; width: 18px; height: 18px;
  background: repeating-linear-gradient(45deg, var(--alt) 0 3px, transparent 3px 6px);
  border-bottom-left-radius: 8px;
}
.day.selected { outline: 3px solid var(--text); outline-offset: -3px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; margin: 12px 0; font-size: .9rem; }
.legend .dot { display: inline-block; width: 12px; height: 12px; border-radius: 4px; background: var(--c); margin-right: 6px; vertical-align: -1px; }
.hint { font-size: .85rem; color: var(--muted); margin: 8px 0; }

.sheet {
  position: fixed; left: 0; right: 0; bottom: calc(56px + env(safe-area-inset-bottom)); z-index: 5;
  background: var(--surface); border-top: 1px solid var(--line);
  box-shadow: 0 -8px 24px rgb(0 0 0 / .12); padding: 12px 16px; max-height: 60vh; overflow: auto;
}
.sheet-inner { max-width: 640px; margin: 0 auto; }
.sel-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }

.sel-row .time { font-size: .85rem; color: var(--muted); white-space: nowrap; }
.sel-row .time input { width: auto; padding: 4px 6px; }
.sel-row { flex-wrap: wrap; }

/* Verteilung */
.range { margin: 8px 0; }
.range input { width: auto; flex: 1; min-width: 130px; }
.bar { display: flex; height: 10px; border-radius: 999px; overflow: hidden; margin: 8px 0; background: var(--line); }
.bar span { background: var(--c); flex-basis: 0; }
table.stats { width: 100%; border-collapse: collapse; font-size: .9rem; font-variant-numeric: tabular-nums; }
table.stats th { text-align: right; font-weight: 500; color: var(--muted); font-size: .8rem; padding: 4px 0; }
table.stats td { text-align: right; padding: 6px 0; border-top: 1px solid var(--line); }
table.stats td:first-child, table.stats th:first-child { text-align: left; }
table.stats .dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--c); margin-right: 6px; }

/* Regel-Editor */
.rule-grid { display: grid; grid-template-columns: 64px repeat(7, 1fr); gap: 4px; align-items: center; }
.rule-grid .lbl { font-size: .8rem; color: var(--muted); }
.slot {
  position: relative; height: 46px; border: 0; border-radius: 8px; cursor: pointer; font-size: .68rem; font-weight: 600;
  background: color-mix(in srgb, var(--c) 40%, var(--surface)); color: var(--text);
  overflow: hidden; white-space: nowrap; padding: 0 2px 4px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.slot > span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.slot::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: var(--bar, var(--c));
}
.slot.selected { outline: 3px solid var(--text); outline-offset: -3px; }
.slot:disabled { cursor: default; }

.status { font-size: .8rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); }
.status.open { color: var(--accent); }
.status.rejected, .status.withdrawn { color: var(--danger); }
.votes { display: flex; gap: 10px; flex-wrap: wrap; font-size: .85rem; margin: 6px 0; }
ul.plain { list-style: none; padding: 0; margin: 6px 0; }
ul.plain li { padding: 2px 0; }
.link-box { word-break: break-all; font-size: .8rem; background: var(--bg); padding: 8px; border-radius: 8px; border: 1px solid var(--line); }

.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex;
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav button {
  position: relative; flex: 1; height: 56px; border: 0; background: none; cursor: pointer; color: var(--muted);
  font-size: .7rem; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.nav svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav button[aria-current="page"] { color: var(--accent); font-weight: 700; }
.badge {
  display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 999px;
  background: var(--danger); color: #fff; font-size: .7rem; line-height: 18px;
}
.nav .badge { position: absolute; top: 4px; left: calc(50% + 6px); min-width: 16px; line-height: 16px; font-size: .62rem; }
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(72px + env(safe-area-inset-bottom)); z-index: 10;
  max-width: 480px; margin: 0 auto; background: var(--text); color: var(--bg);
  padding: 10px 14px; border-radius: 10px; text-align: center;
}
[hidden] { display: none !important; }
label.field input[type=time] { width: auto; min-width: 140px; }

.small { font-size: .75rem; }
.muted.small { margin: 8px 0 4px; }
.row.mode { margin-top: 4px; }

/* Abschnitte eines Tages */
.day-editor, .sel-day { border-top: 1px solid var(--line); margin-top: 12px; padding-top: 10px; }
.sel-day .row { justify-content: space-between; }
.seg-editor .chips { align-items: center; margin: 6px 0; }
.seg-preview { display: flex; height: 12px; border-radius: 6px; overflow: hidden; margin: 8px 0 2px; background: var(--line); }
.seg-preview span { background: var(--c); flex-basis: 0; }
.seg-row { display: flex; gap: 6px; align-items: center; margin: 4px 0; flex-wrap: wrap; }
.seg-row input[type=time] { width: auto; padding: 6px; }
.seg-row select.person-sel { width: auto; padding: 6px; }
.seg-row.window { margin-top: 8px; }
.icon-btn.small { width: 32px; height: 32px; font-size: 1rem; }

/* Wochenansicht mit Stunden */
.week { --wk-h: 540px; }
.wk-head, .wk-body { display: grid; grid-template-columns: 22px repeat(7, 1fr); gap: 3px; }
.wk-day {
  position: relative; border: 0; background: var(--surface); border-radius: 8px; padding: 4px 0; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; line-height: 1.2; overflow: hidden;
}
.wk-day.today strong { background: var(--text); color: var(--bg); border-radius: 999px; padding: 0 6px; }
.wk-day.selected { outline: 3px solid var(--text); outline-offset: -3px; }
.wk-day.pending::before {
  content: ""; position: absolute; top: 0; right: 0; width: 14px; height: 14px;
  background: repeating-linear-gradient(45deg, var(--alt) 0 3px, transparent 3px 6px);
}
.wk-day .flag { font-size: .6rem; color: var(--muted); }
.wk-body { margin-top: 4px; height: var(--wk-h); }
.wk-axis { position: relative; }
.wk-axis span { position: absolute; right: 2px; font-size: .65rem; color: var(--muted); transform: translateY(-1px); }
.wk-col {
  position: relative; border-radius: 8px; cursor: pointer; overflow: hidden; background-color: var(--surface);
  background-image: repeating-linear-gradient(to bottom, var(--line) 0 1px, transparent 1px calc(var(--wk-h) / 8));
}
.wk-col.selected { outline: 3px solid var(--text); outline-offset: -3px; }
.wk-seg {
  position: absolute; left: 0; right: 0; background: color-mix(in srgb, var(--c) 55%, var(--surface));
  border-top: 2px solid var(--c); padding: 2px; font-size: .62rem; font-weight: 600;
  display: flex; flex-direction: column; overflow: hidden; word-break: break-word;
}
.win-row { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.win-row .dot { width: 10px; height: 10px; border-radius: 3px; background: var(--c); }
.win-row span:nth-child(2) { flex: 1; }
.seg-row .chip { padding: 4px 10px; }
.range-row { display: flex; align-items: center; gap: 6px; margin: 4px 0; }
.range-row .dot { width: 10px; height: 10px; border-radius: 3px; background: var(--c); flex: none; }
.range-row input[type=time], .range-row .fixed { flex: 1 1 0; min-width: 0; padding: 6px; }
.range-row .fixed { color: var(--muted); text-align: center; }
.range-row select.person-sel { flex: 1 1 0; min-width: 0; padding: 6px; }
.seg-row.add { margin-top: 10px; }
.seg-row.add input[type=time] { flex: 1 1 90px; min-width: 0; }
.collapse-head {
  width: 100%; display: flex; justify-content: space-between; align-items: center;
  background: none; border: 0; padding: 0; cursor: pointer; text-align: left;
}
.stats-modes { margin: 10px 0 4px; }

/* Ferien */
.day.hol { box-shadow: inset 0 3px 0 var(--muted); }
.wk-day.hol { box-shadow: inset 0 3px 0 var(--muted); }
.hol-type { border-top: 1px solid var(--line); padding: 8px 0; }
.hol-type .row { justify-content: space-between; }
.hol-type select { width: auto; padding: 6px; }
label.check { display: flex; gap: 8px; align-items: flex-start; margin: 8px 0; font-size: .9rem; }
label.check.small { font-size: .8rem; color: var(--muted); }
.hol-preview li { padding: 6px 0; border-bottom: 1px solid var(--line); }
.hol-preview .dot { display: inline-block; width: 9px; height: 9px; border-radius: 3px; background: var(--c); margin-right: 6px; }
ul.plain.small { font-size: .85rem; }

/* Anmeldung */
.btn.wide { width: 100%; padding: 14px; }
details.card summary { cursor: pointer; list-style: none; }
details.card summary::-webkit-details-marker { display: none; }
details.card summary::after { content: " ▾"; color: var(--muted); }
details.card[open] summary::after { content: " ▴"; }
ul.codes { columns: 2; list-style: none; padding: 0; font: 600 1rem/1.9 ui-monospace, SFMono-Regular, Menlo, monospace; }
.code-box { font: 700 1.25rem ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .05em; text-align: center;
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px; user-select: all; }
.dev-list li { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: .9rem;
  border-bottom: 1px solid var(--line); padding: 4px 0; }
a.btn { text-decoration: none; display: inline-block; }

/* Umschalter Liste | Woche | Monat */
.seg { display: flex; background: var(--line); border-radius: 10px; padding: 2px; margin: 4px 0 8px; }
.seg button { flex: 1; border: 0; background: none; padding: 7px; border-radius: 8px; color: var(--muted); cursor: pointer; font-size: .9rem; }
.seg button[aria-selected="true"] { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgb(0 0 0 / .12); }
.month-head h2 { display: flex; align-items: center; gap: 8px; font-size: 1rem; }
.today-btn { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 2px 10px; font-size: .8rem; cursor: pointer; color: var(--accent); font-weight: 600; }

/* Liste */
.agenda { margin: 0 -16px; }
.agenda-wk { font-size: .75rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 14px 16px 6px; }
.agenda-row {
  display: grid; grid-template-columns: 44px 1fr; gap: 12px; align-items: center; width: 100%;
  padding: 8px 16px; border: 0; border-bottom: 1px solid var(--line); background: var(--surface); text-align: left; cursor: pointer;
}
.agenda-row.today { background: color-mix(in srgb, #f2cc8f 22%, var(--surface)); }
.agenda-row.selected { outline: 3px solid var(--text); outline-offset: -3px; }
.agenda-date { text-align: center; line-height: 1.15; }
.agenda-date small { display: block; font-size: .75rem; color: var(--muted); }
.agenda-date b { font-size: 1.2rem; }
.agenda-row.today .agenda-date b { background: var(--text); color: var(--bg); border-radius: 999px; padding: 0 7px; }
.agenda-main { display: block; min-width: 0; }
.agenda-bar { display: block; position: relative; height: 22px; border-radius: 6px; overflow: hidden; }
.agenda-bar.pending::after {
  content: ""; position: absolute; top: 0; right: 0; bottom: 0; width: 22px;
  background: repeating-linear-gradient(45deg, var(--alt) 0 3px, var(--surface) 3px 6px);
}
.agenda-text { display: block; font-size: .82rem; color: var(--muted); margin-top: 4px; }
.agenda-text b { color: var(--text); font-weight: 600; }
.tag { display: inline-block; font-size: .62rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em;
  padding: 1px 6px; border-radius: 4px; background: var(--line); color: var(--muted); margin-left: 6px; vertical-align: 1px; }
.tag.pend { background: color-mix(in srgb, var(--c) 25%, var(--surface)); color: var(--text); }
