:root {
  --bg: #f6f7f9; --card: #fff; --text: #1c1f24; --muted: #6b7280; --line: #e3e6ea;
  --accent: #2e86ab; --danger: #c0392b; --sel: #dbeef6;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #121417; --card: #1c1f24; --text: #eceff3; --muted: #9aa3ad; --line: #2c3138; --sel: #1d3a47; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button {
  border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 10px 14px; cursor: pointer;
}
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--danger); }
button.icon { border: none; background: none; font-size: 26px; padding: 4px 12px; }
button.small { padding: 6px 10px; font-size: 14px; }
input, select, textarea {
  width: 100%; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
}
input[type=checkbox] { width: auto; }
label { display: block; margin: 10px 0; font-size: 14px; color: var(--muted); }
label input, label select, label textarea { margin-top: 4px; color: var(--text); }
label.row { display: flex; gap: 8px; align-items: center; color: var(--text); }
.error { color: var(--danger); min-height: 1em; }
.meta { color: var(--muted); font-size: 13px; }

.card-view { max-width: 380px; margin: 12vh auto 0; padding: 24px; background: var(--card); border-radius: 16px; }
.card-view h1 { margin-top: 0; font-size: 24px; }
.card-view button { width: 100%; margin-top: 8px; }

#view-cal { max-width: 900px; margin: 0 auto; padding: 0 8px 96px; }
.top { display: flex; align-items: center; gap: 4px; padding: 8px 0; }
.top h2 { flex: 1; text-align: center; margin: 0; font-size: 20px; }
.weekdays, .grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.weekdays span { text-align: center; font-size: 12px; color: var(--muted); padding: 4px 0; }
.grid { gap: 2px; }
.cell {
  min-height: 64px; padding: 4px; border-radius: 8px; border: none; background: var(--card);
  display: flex; flex-direction: column; align-items: stretch; text-align: left; overflow: hidden;
}
.cell.other { opacity: .45; }
.cell.selected { background: var(--sel); }
.cell .num { font-size: 13px; font-weight: 600; width: 24px; height: 24px; line-height: 24px; text-align: center; border-radius: 12px; }
.cell.today .num { background: var(--accent); color: #fff; }
.dots { display: flex; flex-direction: column; gap: 2px; margin-top: 2px; }
.chip {
  font-size: 11px; color: #fff; border-radius: 4px; padding: 0 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
@media (max-width: 480px) {
  .cell { min-height: 52px; }
  .chip { font-size: 0; height: 6px; padding: 0; }
}

.day-panel { margin-top: 12px; }
.day-panel h3 { margin: 8px 4px; font-size: 16px; }
.ev-list { list-style: none; margin: 0; padding: 0; }
.ev-list li {
  display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center;
  background: var(--card); margin-bottom: 6px; padding: 12px; border-radius: 10px; border-left: 5px solid var(--accent); cursor: pointer;
}
.ev-list li.empty { display: block; color: var(--muted); border-left-color: transparent; cursor: default; }
.ev-list .time { font-size: 13px; color: var(--muted); min-width: 84px; }
.ev-list .who { font-size: 12px; color: var(--muted); }

.fab {
  position: fixed; right: 20px; bottom: calc(20px + env(safe-area-inset-bottom));
  width: 60px; height: 60px; border-radius: 30px; font-size: 32px; line-height: 1;
  background: var(--accent); color: #fff; border: none; box-shadow: 0 4px 14px rgba(0,0,0,.25);
}

dialog {
  border: none; border-radius: 16px; padding: 20px; width: min(460px, calc(100vw - 24px));
  background: var(--card); color: var(--text); max-height: 90vh; overflow: auto;
}
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog h3 { margin-top: 0; }
.two { display: flex; gap: 10px; }
.two label { flex: 1; }
.actions { display: flex; gap: 8px; align-items: center; margin-top: 12px; }
.spacer { flex: 1; }
#menu-form > button { display: block; width: 100%; margin: 6px 0; }
details { margin: 12px 0; }
summary { cursor: pointer; }

/* ---------- Uebersicht ---------- */
#view-cal { padding-bottom: calc(150px + env(safe-area-inset-bottom)); }
.hero { display: flex; justify-content: space-between; align-items: center; padding: 20px 4px 12px; }
.hero h1 { margin: 0; font-size: 26px; }
.hello { margin: 0; color: var(--muted); font-size: 15px; }
.avatar {
  width: 44px; height: 44px; border-radius: 22px; border: none; color: #fff; font-weight: 700; font-size: 18px; padding: 0;
}
.now-card {
  display: flex; flex-direction: column; gap: 2px; color: #fff; border-radius: 16px; padding: 16px 18px; margin: 4px 0 12px;
  cursor: pointer; box-shadow: 0 4px 14px rgba(0,0,0,.12);
}
.now-card strong { font-size: 20px; }
.now-card .label { font-size: 13px; opacity: .9; }
.agenda-day h3 { margin: 18px 4px 8px; font-size: 17px; }
.agenda-day h3 small { color: var(--muted); font-weight: 400; font-size: 14px; }
.agenda-day.is-today h3 { font-size: 20px; }
.ev-list li { grid-template-columns: 84px 1fr auto; }
.ev-list .time { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--text); }
.ev-list .body { display: flex; flex-direction: column; min-width: 0; }
.ev-list .title { font-weight: 500; overflow-wrap: anywhere; }
.ev-list .note { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev-list .who { color: #fff; border-radius: 999px; padding: 2px 8px; font-size: 12px; }
.ev-list.compact li { padding: 10px 12px; }
.ev-list.compact .time { font-weight: 500; color: var(--muted); }
.legend { display: flex; flex-wrap: wrap; gap: 12px; margin: 20px 4px; font-size: 13px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 5px; display: inline-block; }

/* ---------- Tableiste ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: center; gap: 8px;
  background: var(--card); border-top: 1px solid var(--line);
  padding: 6px 12px calc(6px + env(safe-area-inset-bottom));
}
.tabbar button {
  flex: 1; max-width: 220px; border: none; background: none; display: flex; flex-direction: column; align-items: center;
  font-size: 12px; color: var(--muted); padding: 6px;
}
.tabbar button .ti { font-size: 20px; line-height: 1.2; }
.tabbar button.active { color: var(--accent); font-weight: 600; }
.fab { bottom: calc(80px + env(safe-area-inset-bottom)); }

/* ---------- Fuer wen ---------- */
.field { margin: 10px 0; }
.field-label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 6px; }
.person-picker { display: flex; flex-wrap: wrap; gap: 8px; }
.person {
  border: 2px solid var(--c); color: var(--c); background: transparent; border-radius: 999px;
  padding: 8px 16px; font-weight: 600; min-height: 44px;
}
.person.on { background: var(--c); color: #fff; }
.person.on::before { content: '✓ '; }
.ev-list .whos { display: flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; max-width: 120px; }
.install-hint {
  margin: 12px 0 0; padding: 12px 14px; border-radius: 12px; background: var(--sel); font-size: 15px;
}

/* ---------- iPhone: kein Auto-Zoom, kein seitliches Verrutschen ---------- */
html, body { overflow-x: hidden; }
input, select, textarea { font-size: 16px; min-width: 0; max-width: 100%; }
input[type=date], input[type=time] { -webkit-appearance: none; appearance: none; min-height: 44px; display: block; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.two label { min-width: 0; }
.two label[hidden] + label, .two label:only-child { grid-column: 1 / -1; }

/* ---------- Eintrage-Fenster als Blatt ---------- */
#ev-dialog { padding: 0; overflow: hidden; display: none; }
#ev-dialog[open] { display: flex; }
#ev-form { display: flex; flex-direction: column; width: 100%; max-height: inherit; }
.sheet-head {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--card);
}
.sheet-head h3 { margin: 0; font-size: 17px; }
.sheet-head .link { border: none; background: none; color: var(--accent); padding: 8px 4px; justify-self: start; }
.sheet-head .link.strong { font-weight: 700; justify-self: end; }
.sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 12px 16px 24px; overscroll-behavior: contain; }
button.big { display: block; width: 100%; padding: 14px; font-size: 17px; margin-top: 10px; }
@media (max-width: 600px) {
  #ev-dialog {
    width: 100%; max-width: 100%; height: 100%; max-height: 100%; margin: 0; border-radius: 0;
    padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom);
  }
}

.segmented { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg); border-radius: 12px; padding: 3px; margin-bottom: 6px; }
.segmented label { margin: 0; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: block; text-align: center; padding: 10px; border-radius: 10px; color: var(--text); font-size: 15px; font-weight: 600; }
.segmented input:checked + span { background: var(--card); box-shadow: 0 1px 4px rgba(0,0,0,.15); }
#ev-form[data-kind=presence] .only-event { display: none; }
#ev-form[data-kind=event] .only-presence { display: none; }

.suggestions { display: flex; flex-wrap: wrap; gap: 6px; margin: -2px 0 6px; }
.suggestions:empty { display: none; }
.sugg {
  --c: var(--accent);
  border: 1px solid var(--line); border-left: 4px solid var(--c); border-radius: 8px;
  padding: 8px 12px; font-size: 15px; background: var(--card);
}

/* ---------- Anwesenheit ---------- */
.presence { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.presence-row {
  text-align: left; border: 2px dashed var(--c); background: var(--card); color: var(--text);
  border-radius: 12px; padding: 10px 14px; font-size: 15px;
}
.presence-row.here { border-style: solid; background: var(--c); color: #fff; font-weight: 600; }
.pres-bars { display: flex; gap: 2px; margin-top: auto; }
.pres-bars i { flex: 1; height: 5px; border-radius: 3px; }
.ev-list li.presence-item { background: transparent; border: 2px dashed var(--line); border-left: 5px solid var(--accent); }
.sugg small { color: var(--muted); font-size: 13px; }

/* ---------- Feiertage & Ferien ---------- */
.cell.school-holiday { background: linear-gradient(to bottom, #fff4d6 0, #fff4d6 100%); }
.cell.school-holiday.selected { background: var(--sel); }
.cell.public-holiday .num { color: #d62828; }
.cell.today.public-holiday .num { color: #fff; }
.hol-name { font-size: 9px; line-height: 1.1; color: #d62828; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (prefers-color-scheme: dark) { .cell.school-holiday { background: #3a3220; } }
.school { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.school:empty { display: none; }
.school-row { background: var(--card); border-radius: 12px; padding: 10px 14px; font-size: 15px; }
.school-row.now { background: #fff4d6; color: #5b4500; font-weight: 600; }
.ev-list li.holiday-item { cursor: default; border-left-color: #f0a202; background: #fff8e6; color: #5b4500; }
.ev-list li.holiday-item.public { border-left-color: #d62828; background: #fdecec; color: #7a1414; }
.ev-list li.holiday-item .time { color: inherit; }
@media (prefers-color-scheme: dark) {
  .school-row.now, .ev-list li.holiday-item { background: #3a3220; color: #f5deb0; }
  .ev-list li.holiday-item.public { background: #3d1f1f; color: #f3c0c0; }
}
.repeat-extra { background: var(--bg); border-radius: 12px; padding: 2px 12px; margin: -4px 0 8px; }
.month-legend { display: flex; gap: 16px; margin: 8px 4px 0; font-size: 13px; color: var(--muted); }
.month-legend span { display: inline-flex; align-items: center; gap: 6px; }
.month-legend i { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }
.lg-school { background: #fff4d6; border: 1px solid #f0d58a; }
.lg-public { background: #d62828; }
@media (prefers-color-scheme: dark) { .lg-school { background: #3a3220; border-color: #5b4a20; } }
