:root {
  --blau: #1d4ed8; --blau-hell: #dbeafe; --text: #111827; --grau: #6b7280; --linie: #e5e7eb; --flaeche: #f9fafb;
  --weiss: #fff; --rot: #dc2626; --heute: #1d4ed8; --schatten: 0 4px 16px rgba(0,0,0,.12);
  --tabs-h: 60px; --kopf-h: 52px; --stunde: 48px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --text: #f3f4f6; --grau: #9ca3af; --linie: #374151; --flaeche: #111827; --weiss: #1f2937; --blau-hell: #1e3a8a;
    --heute: #60a5fa; color-scheme: dark; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--text); background: var(--weiss);
  -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; background: var(--weiss); border: 1px solid var(--linie); border-radius: 8px;
  padding: 9px 10px; width: 100%; min-width: 0; }
textarea { resize: vertical; min-height: 70px; }
input[type=checkbox] { width: auto; }
label { display: block; font-size: 13px; color: var(--grau); margin: 10px 0 4px; }
a { color: var(--blau); }
.klein { font-size: 13px; color: var(--grau); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--linie); background: var(--weiss);
  border-radius: 8px; padding: 9px 14px; text-decoration: none; color: inherit; white-space: nowrap; }
.btn.primaer { background: var(--blau); border-color: var(--blau); color: #fff; }
.btn.gefahr { color: var(--rot); border-color: var(--rot); }
.btn:disabled { opacity: .5; }
.klein-btn { padding: 5px 10px; font-size: 14px; }
.icon { border: 0; background: none; font-size: 24px; width: 40px; height: 40px; border-radius: 50%; line-height: 1; }
.icon:hover { background: var(--flaeche); }
.zeile { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.zeile > * { flex: 1; }
.zeile > .fest { flex: 0 0 auto; }
.knoepfe { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 16px; }
.knoepfe .links { margin-right: auto; }

/* Anmeldung */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; background: var(--flaeche); }
.login-box { background: var(--weiss); padding: 32px 24px; border-radius: 16px; box-shadow: var(--schatten); text-align: center; width: 100%; max-width: 340px; }
.login-box h1 { margin: 8px 0; }
.login-box form { display: grid; gap: 8px; margin-top: 12px; }

/* Grundgerüst */
#app { height: 100%; display: flex; flex-direction: column; }
.kopf { height: var(--kopf-h); flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; padding: 0 8px;
  border-bottom: 1px solid var(--linie); padding-top: env(safe-area-inset-top); box-sizing: content-box; }
.nav-zeit { display: flex; align-items: center; min-width: 0; }
.kopf h1 { font-size: 18px; margin: 0 0 0 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kopf-rechts { display: flex; gap: 8px; align-items: center; }
.badge-btn { border: 0; background: #fef3c7; color: #92400e; border-radius: 999px; padding: 5px 10px; font-weight: 600; }
.rumpf { flex: 1; display: flex; min-height: 0; }
.inhalt { flex: 1; overflow: auto; min-width: 0; padding-bottom: calc(var(--tabs-h) + 20px + env(safe-area-inset-bottom)); }
.seite { display: none; }
.tabs { position: fixed; left: 0; right: 0; bottom: 0; height: calc(var(--tabs-h) + env(safe-area-inset-bottom)); display: flex;
  background: var(--weiss); border-top: 1px solid var(--linie); padding-bottom: env(safe-area-inset-bottom); z-index: 20; }
.tabs button { flex: 1; border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 12px; color: var(--grau); gap: 2px; }
.tabs button span { font-size: 20px; line-height: 1; }
.tabs button.aktiv { color: var(--blau); font-weight: 600; }
.fab { position: fixed; right: 16px; bottom: calc(var(--tabs-h) + 16px + env(safe-area-inset-bottom)); width: 56px; height: 56px; border-radius: 50%;
  border: 0; background: var(--blau); color: #fff; font-size: 30px; box-shadow: var(--schatten); z-index: 21; }
.fab-menue { position: fixed; right: 16px; bottom: calc(var(--tabs-h) + 80px + env(safe-area-inset-bottom)); background: var(--weiss);
  border-radius: 12px; box-shadow: var(--schatten); overflow: hidden; z-index: 22; display: flex; flex-direction: column; }
.fab-menue button { border: 0; background: none; padding: 14px 18px; text-align: left; }
.fab-menue button + button { border-top: 1px solid var(--linie); }

@media (min-width: 900px) {
  :root { --tabs-h: 0px; }
  .seite { display: block; width: 260px; flex: 0 0 260px; border-right: 1px solid var(--linie); overflow: auto; padding: 8px 12px 24px; }
  /* Tab-Leiste wandert in die Mitte der Kopfzeile */
  .tabs { position: fixed; top: 8px; bottom: auto; left: 50%; right: auto; transform: translateX(-50%); height: 36px; border: 0; padding: 0;
    background: none; gap: 4px; }
  .tabs button { flex-direction: row; font-size: 14px; padding: 6px 12px; border-radius: 8px; gap: 6px; }
  .tabs button span { font-size: 15px; }
  .tabs button.aktiv { background: var(--blau-hell); }
  .nur-mobil { display: none !important; }
  .fab { bottom: 24px; right: 24px; }
  .fab-menue { bottom: 90px; right: 24px; }
  .inhalt { padding-bottom: 24px; }
}

/* Monat */
.monat { display: grid; grid-template-columns: repeat(7, 1fr); border-left: 1px solid var(--linie); }
.monat .wt { font-size: 12px; color: var(--grau); text-align: center; padding: 4px 0; border-right: 1px solid var(--linie); border-bottom: 1px solid var(--linie); }
.monat .tag { min-height: 64px; border-right: 1px solid var(--linie); border-bottom: 1px solid var(--linie); padding: 2px; overflow: hidden; cursor: pointer; min-width: 0; }
.monat .tag.fremd { background: var(--flaeche); }
.monat .tag.fremd .nr { color: var(--grau); }
.monat .tag.gewaehlt { box-shadow: inset 0 0 0 2px var(--blau); }
.monat .nr { font-size: 13px; width: 24px; height: 24px; line-height: 24px; text-align: center; border-radius: 50%; margin: 0 auto 2px; }
.monat .tag.heute .nr { background: var(--heute); color: #fff; font-weight: 700; }
.chip { font-size: 11px; line-height: 16px; border-radius: 4px; padding: 0 4px; margin-bottom: 1px; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; color: #fff; }
.chip.zeit { color: var(--text); background: none !important; padding-left: 0; }
.chip.zeit::before { content: ''; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--f); margin: 0 3px 1px 2px; }
.mehr-chip { font-size: 11px; color: var(--grau); padding-left: 3px; }
@media (min-width: 900px) { .monat .tag { min-height: 110px; } .monat .nr { margin: 0 0 2px 2px; } }
.tagesliste { padding: 8px 12px; }
.tagesliste h3 { font-size: 15px; margin: 8px 0; }

/* Liste */
.liste { padding: 4px 12px 12px; }
.liste .datum { position: sticky; top: 0; background: var(--weiss); font-weight: 600; padding: 10px 0 4px; border-bottom: 1px solid var(--linie); z-index: 1; }
.liste .datum.heute { color: var(--heute); }
.eintrag { display: flex; gap: 10px; padding: 9px 4px; border-bottom: 1px solid var(--linie); cursor: pointer; align-items: flex-start; }
.eintrag:hover { background: var(--flaeche); }
.eintrag .balken { width: 4px; align-self: stretch; border-radius: 2px; flex: 0 0 4px; }
.eintrag .zeit { flex: 0 0 82px; font-size: 13px; color: var(--grau); font-variant-numeric: tabular-nums; }
.eintrag .was { flex: 1; min-width: 0; }
.eintrag .was b { font-weight: 600; display: block; overflow-wrap: anywhere; }
.eintrag .was small { color: var(--grau); display: block; }
.leer { color: var(--grau); text-align: center; padding: 32px 12px; }

/* Woche */
.woche { display: grid; position: relative; }
.woche .wkopf { position: sticky; top: 0; z-index: 3; background: var(--weiss); }
.woche .ganztags .chip { margin: 0 0 1px; cursor: pointer; }
.woche .spaltenkopf { display: grid; border-bottom: 1px solid var(--linie); }
.woche .spaltenkopf div { text-align: center; font-size: 12px; color: var(--grau); padding: 4px 0; }
.woche .spaltenkopf div b { display: block; font-size: 18px; color: var(--text); font-weight: 500; }
.woche .spaltenkopf div.heute b { color: var(--heute); font-weight: 700; }
.woche .ganztags { display: grid; border-bottom: 1px solid var(--linie); min-height: 6px; }
.woche .ganztags > div { padding: 2px 1px; border-left: 1px solid var(--linie); min-width: 0; }
.woche .raster { display: grid; position: relative; }
.woche .stunden div { height: var(--stunde); font-size: 11px; color: var(--grau); text-align: right; padding-right: 4px; transform: translateY(-7px); }
.woche .spalte { position: relative; border-left: 1px solid var(--linie);
  background: repeating-linear-gradient(to bottom, var(--linie) 0 1px, transparent 1px var(--stunde)); height: calc(24 * var(--stunde)); }
.woche .spalte.heute { background-color: color-mix(in srgb, var(--blau-hell) 35%, transparent); }
.woche .block { position: absolute; border-radius: 4px; padding: 1px 4px; font-size: 11px; line-height: 14px; color: #fff; overflow: hidden;
  border: 1px solid var(--weiss); cursor: pointer; }
.woche .block b { font-weight: 600; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.woche .jetzt { position: absolute; left: 0; right: 0; height: 2px; background: var(--rot); z-index: 2; }

/* Kalender-Verwaltung */
.kalliste { padding: 4px 0; }
.kalliste h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--grau); margin: 16px 0 4px; display: flex; justify-content: space-between; align-items: center; }
.kalliste h3 button { border: 0; background: none; color: var(--blau); font-size: 12px; text-transform: none; letter-spacing: 0; }
.kal { display: flex; align-items: center; gap: 10px; padding: 7px 4px; border-radius: 8px; }
.kal:hover { background: var(--flaeche); }
.kal .punkt { width: 18px; height: 18px; border-radius: 5px; flex: 0 0 18px; border: 2px solid var(--f); background: var(--f); cursor: pointer; }
.kal .punkt.aus { background: transparent; }
.kal .name { flex: 1; min-width: 0; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kal .tags { font-size: 11px; color: var(--grau); }
.kal .bearb { border: 0; background: none; color: var(--grau); font-size: 16px; padding: 2px 6px; }
.seite-knoepfe { display: grid; gap: 6px; margin-top: 16px; }
.inhalt .kalliste, .inhalt .mehr { padding: 4px 16px; }

/* Mehr */
.mehr section { border-bottom: 1px solid var(--linie); padding: 12px 0; }
.mehr h3 { margin: 0 0 6px; font-size: 16px; }
.mehr p { margin: 4px 0 8px; }
.code { font-family: ui-monospace, Consolas, monospace; background: var(--flaeche); border: 1px solid var(--linie); border-radius: 6px; padding: 6px 8px;
  word-break: break-all; font-size: 13px; user-select: all; }
table.stat { border-collapse: collapse; font-size: 13px; width: 100%; max-width: 420px; }
table.stat td, table.stat th { padding: 3px 8px; border-bottom: 1px solid var(--linie); text-align: right; }
table.stat td:first-child, table.stat th:first-child { text-align: left; }

/* Dialog */
.dialog { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.dialog-box { background: var(--weiss); width: 100%; max-width: 560px; max-height: 92vh; border-radius: 16px 16px 0 0; display: flex; flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom); }
@media (min-width: 600px) { .dialog { align-items: center; } .dialog-box { border-radius: 16px; } }
.dialog-kopf { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 0 16px; }
.dialog-kopf h2 { font-size: 18px; margin: 0; }
.dialog-inhalt { overflow: auto; padding: 0 16px 16px; }
.detail .zeile-info { display: flex; gap: 10px; padding: 6px 0; align-items: flex-start; }
.detail .zeile-info > span:first-child { width: 22px; text-align: center; flex: 0 0 22px; }
.detail .beschr { white-space: pre-wrap; overflow-wrap: anywhere; }
.farben { display: flex; flex-wrap: wrap; gap: 8px; }
.farben button { width: 32px; height: 32px; border-radius: 50%; border: 3px solid transparent; }
.farben button.aktiv { border-color: var(--text); }
.schalter { display: flex; align-items: center; gap: 8px; margin: 10px 0; color: var(--text); font-size: 15px; }
.vorschlag-termin { border: 1px solid var(--linie); border-radius: 10px; padding: 8px 10px; margin: 8px 0; }
.vorschlag-termin.aus { opacity: .45; }
.vorschlag-termin .kopfzeile { display: flex; gap: 8px; align-items: center; }
.vorschlag-termin .kopfzeile input[type=text] { font-weight: 600; }
.vorschlag-termin label { margin-top: 6px; }
.lade { display: inline-block; width: 18px; height: 18px; border: 3px solid var(--linie); border-top-color: var(--blau); border-radius: 50%; animation: dreh 1s linear infinite; vertical-align: middle; }
@keyframes dreh { to { transform: rotate(360deg); } }
.hinweis { background: #fef3c7; color: #78350f; border-radius: 8px; padding: 8px 10px; font-size: 14px; margin: 8px 0; }
.fehler { background: #fee2e2; color: #7f1d1d; border-radius: 8px; padding: 8px 10px; font-size: 14px; margin: 8px 0; }
.meldung { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabs-h) + 84px + env(safe-area-inset-bottom)); background: #111827; color: #fff;
  padding: 10px 16px; border-radius: 10px; z-index: 60; box-shadow: var(--schatten); max-width: 90vw; }
.ablage { border: 2px dashed var(--linie); border-radius: 10px; padding: 16px; text-align: center; color: var(--grau); margin: 8px 0; }
.ablage.drueber { border-color: var(--blau); background: var(--blau-hell); }
.block-g { cursor: pointer; }
