:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --ink: #1d2433;
  --muted: #6b7690;
  --line: #e6e9f2;
  --accent: #5b6cf0;
  --accent-2: #7c5cf0;
  --accent-soft: #eceefe;
  --danger: #d9534f;
  --radius: 16px;
  --rail-w: 76px;
  --hour-h: 52px;
  --gutter-w: 52px;
  --shadow: 0 1px 2px rgba(20, 30, 60, 0.06), 0 8px 28px rgba(20, 30, 60, 0.07);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
body { overflow: hidden; -webkit-tap-highlight-color: transparent; }
#root { height: 100%; }
button { font: inherit; color: inherit; cursor: pointer; }
h1, h2, h3 { margin: 0; }

/* ---------- Anmeldung ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; overflow: auto; }
.login .card { width: min(380px, 100%); background: var(--panel); border-radius: 24px; padding: 32px 28px; box-shadow: var(--shadow); display: grid; gap: 14px; }
.login .logo { width: 72px; height: 72px; border-radius: 18px; justify-self: center; }
.login h1 { text-align: center; font-size: 24px; }
.login .sub { text-align: center; color: var(--muted); margin: -8px 0 6px; font-size: 14px; }
.error { color: var(--danger); font-size: 14px; min-height: 1.2em; margin: 0; }

/* ---------- Formularelemente ---------- */
label.field { display: grid; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
input, select, textarea {
  font: inherit; font-size: 16px; color: var(--ink); width: 100%; padding: 10px 12px; background: #fff;
  border: 1px solid var(--line); border-radius: 10px; min-height: 44px; appearance: none; -webkit-appearance: none;
}
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 55%, calc(100% - 13px) 55%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 34px; }
textarea { min-height: 64px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input[type='color'] { padding: 3px; min-height: 44px; width: 52px; }
input[type='checkbox'] { width: 22px; height: 22px; min-height: 0; padding: 0; accent-color: var(--accent); appearance: auto; -webkit-appearance: checkbox; }

.btn { border: 1px solid var(--line); background: #fff; border-radius: 12px; padding: 0 16px; min-height: 44px; font-weight: 600; font-size: 15px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; white-space: nowrap; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn[disabled] { opacity: 0.5; pointer-events: none; }
.icon-btn { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: #fff; display: grid; place-items: center; padding: 0; }
.icon { display: block; }

/* ---------- Grundgerüst ---------- */
.shell { display: grid; grid-template-columns: var(--rail-w) minmax(0, 1fr); height: 100dvh; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
.rail { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; padding: 14px 0; gap: 6px; }
.rail .brand { width: 44px; height: 44px; border-radius: 12px; margin-bottom: 10px; }
.rail .spacer { flex: 1; }
.rail-btn { width: 60px; border: 0; background: none; border-radius: 14px; padding: 8px 0 6px; display: grid; justify-items: center; gap: 3px; color: var(--muted); font-size: 11px; font-weight: 600; }
.rail-btn.active { background: var(--accent-soft); color: var(--accent); }
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; padding: 14px 16px 16px; gap: 12px; }
.page { overflow: auto; flex: 1; min-height: 0; padding: 4px; margin: -4px; }

/* ---------- Kalender: Kopfzeile ---------- */
.topbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }
.topbar .title { display: grid; gap: 2px; min-width: 0; margin-right: auto; }
.topbar h2 { font-size: 22px; letter-spacing: -0.01em; white-space: nowrap; }
.topbar .kw { font-size: 13px; color: var(--muted); font-weight: 600; }
.navgroup { display: flex; gap: 8px; align-items: center; }
.seg { display: inline-flex; background: #e9ecf6; border-radius: 12px; padding: 3px; }
.seg button { border: 0; background: none; padding: 0 14px; min-height: 38px; border-radius: 10px; font-weight: 600; font-size: 14px; color: var(--muted); }
.seg button.active { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(20, 30, 60, 0.12); }
.people { display: flex; gap: 8px; flex-wrap: wrap; }
.person-chip { --c: #7a8aa6; display: inline-flex; align-items: center; gap: 6px; border: 2px solid var(--c); background: #fff; border-radius: 999px; padding: 0 12px 0 6px; min-height: 38px; font-weight: 600; font-size: 14px; }
.person-chip .dot { width: 26px; height: 26px; border-radius: 50%; background: var(--c); color: #fff; display: grid; place-items: center; font-size: 14px; }
.person-chip.off { opacity: 0.4; border-color: var(--line); }
.person-chip.off .dot { background: #c3cada; }

.fab { position: fixed; right: calc(24px + env(safe-area-inset-right)); bottom: calc(24px + env(safe-area-inset-bottom)); width: 62px; height: 62px; border-radius: 50%; border: 0; color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent-2)); box-shadow: 0 8px 24px rgba(91, 108, 240, 0.45); display: grid; place-items: center; z-index: 5; }

/* ---------- Wochenansicht ---------- */
.view { flex: 1; min-height: 0; background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column; }
.wk-head, .wk-allday { display: grid; grid-template-columns: var(--gutter-w) minmax(0, 1fr); flex: none; }
.wk-head-days { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.wk-dayhead { padding: 8px 4px 6px; text-align: center; border-left: 1px solid var(--line); display: grid; gap: 2px; justify-items: center; }
.wk-dayhead .dow { font-size: 12px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
.wk-dayhead .dnum { font-size: 20px; font-weight: 700; width: 36px; height: 36px; display: grid; place-items: center; border-radius: 50%; }
.wk-dayhead.is-today .dnum { background: var(--accent); color: #fff; }
.wk-dayhead.is-today .dow { color: var(--accent); }
.wk-allday { border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.wk-allday .lbl { font-size: 10px; color: var(--muted); display: grid; place-items: center; text-align: center; font-weight: 600; }
.wk-allday-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 2px 0; padding: 3px 0; min-height: 12px; background-image: repeating-linear-gradient(to right, transparent 0, transparent calc(100% / 7 - 1px), var(--line) calc(100% / 7 - 1px), var(--line) calc(100% / 7)); }
.bar { margin: 0 3px; border: 0; border-radius: 7px; padding: 3px 8px; font-size: 12.5px; font-weight: 600; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink); }
.wk-scroll { flex: 1; min-height: 0; overflow-y: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.wk-scroll::-webkit-scrollbar { display: none; }
.wk-body { display: grid; grid-template-columns: var(--gutter-w) repeat(7, minmax(0, 1fr)); height: calc(24 * var(--hour-h)); position: relative; }
.wk-times { position: relative; }
.wk-times span { position: absolute; right: 8px; transform: translateY(-50%); font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.wk-col { position: relative; border-left: 1px solid var(--line); background-image: repeating-linear-gradient(to bottom, transparent 0, transparent calc(var(--hour-h) - 1px), var(--line) calc(var(--hour-h) - 1px), var(--line) var(--hour-h)); }
.wk-col.is-today { background-color: #f8f9ff; }
.ev { position: absolute; border: 0; border-left: 4px solid var(--c); border-radius: 8px; padding: 3px 6px; text-align: left; overflow: hidden; color: var(--ink); font-size: 12.5px; line-height: 1.25; box-shadow: 0 0 0 1px #fff; }
.ev b { display: block; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev span { color: #4a5570; font-size: 11.5px; }
.now-line { position: absolute; left: 0; right: 0; height: 2px; background: #e5484d; z-index: 2; pointer-events: none; }
.now-line::before { content: ''; position: absolute; left: -5px; top: -4px; width: 10px; height: 10px; border-radius: 50%; background: #e5484d; }

/* ---------- Monatsansicht ---------- */
.mo { display: flex; flex-direction: column; height: 100%; }
.mo-head { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-bottom: 1px solid var(--line); flex: none; }
.mo-head div { padding: 8px 6px; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; text-align: center; }
.mo-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); flex: 1; min-height: 0; }
.mo-cell { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 4px; min-height: 0; overflow: hidden; display: flex; flex-direction: column; gap: 2px; }
.mo-cell:nth-child(7n) { border-right: 0; }
.mo-cell.dim { background: #fafbfd; }
.mo-cell.dim .mo-num { color: #aab2c5; }
.mo-num { border: 0; background: none; width: 30px; height: 30px; border-radius: 50%; font-weight: 700; font-size: 14px; flex: none; }
.mo-cell.is-today .mo-num { background: var(--accent); color: #fff; }
.chip { border: 0; border-left: 3px solid var(--c); border-radius: 5px; padding: 2px 6px; font-size: 11.5px; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink); flex: none; }
.more { border: 0; background: none; color: var(--muted); font-size: 11.5px; font-weight: 600; text-align: left; padding: 0 4px; }

/* ---------- Listenansicht ---------- */
.list { overflow: auto; padding: 8px 16px 90px; height: 100%; }
.list-day { padding: 14px 0 4px; font-weight: 700; display: flex; gap: 8px; align-items: baseline; }
.list-day.is-today { color: var(--accent); }
.list-day small { color: var(--muted); font-weight: 600; font-size: 13px; }
.row { display: grid; grid-template-columns: 92px 4px minmax(0, 1fr); gap: 12px; align-items: stretch; width: 100%; text-align: left; border: 0; background: none; padding: 8px 0; border-bottom: 1px solid var(--line); }
.row .t { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; padding-top: 2px; }
.row .stripe { background: var(--c); border-radius: 4px; }
.row .what b { display: block; font-size: 16px; }
.row .what span { color: var(--muted); font-size: 13.5px; }
.empty { color: var(--muted); text-align: center; padding: 60px 20px; }

/* ---------- Dialoge ---------- */
dialog.dlg { border: 0; border-radius: 22px; padding: 0; width: min(560px, 94vw); max-height: 92dvh; box-shadow: 0 20px 60px rgba(10, 15, 40, 0.35); color: var(--ink); }
dialog.dlg::backdrop { background: rgba(20, 25, 45, 0.45); }
.dlg-body { padding: 22px 22px 18px; display: grid; gap: 14px; max-height: 92dvh; overflow: auto; }
.dlg-body h3 { font-size: 20px; }
.dlg-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; position: sticky; bottom: -18px; background: #fff; padding: 12px 0 18px; margin-bottom: -18px; }
.dlg-actions .left { margin-right: auto; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.pick { --c: #7a8aa6; border: 2px solid var(--line); background: #fff; border-radius: 999px; min-height: 38px; padding: 0 14px; font-weight: 600; font-size: 14px; display: inline-flex; align-items: center; gap: 6px; }
.pick.on { border-color: var(--c); background: color-mix(in srgb, var(--c) 16%, #fff); }
.pick.day { min-width: 46px; justify-content: center; padding: 0 10px; }
.switch { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.note { color: var(--muted); font-size: 13px; margin: 0; }
.kv { display: grid; grid-template-columns: 90px 1fr; gap: 6px 12px; font-size: 15px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.url-box { display: flex; gap: 8px; }
.url-box input { font-size: 13px; }

/* ---------- Einstellungen ---------- */
.settings { display: grid; gap: 18px; max-width: 880px; padding-bottom: 40px; }
.panel { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; display: grid; gap: 12px; }
.panel h3 { font-size: 18px; }
.srow { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 10px 0; border-top: 1px solid var(--line); }
.srow:first-of-type { border-top: 0; }
.srow input[type='text'] { flex: 1 1 140px; min-width: 120px; width: auto; }
.srow select { width: auto; min-width: 130px; }
.srow input.emoji { flex: 0 0 64px; min-width: 64px; width: 64px; text-align: center; }

/* ---------- Hinweise ---------- */
#toasts { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); display: grid; gap: 8px; z-index: 100; pointer-events: none; }
.toast { background: #1d2433; color: #fff; padding: 12px 18px; border-radius: 12px; font-size: 15px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25); max-width: 90vw; }
.toast.err { background: #b3302c; }

/* ---------- Schmale Bildschirme (Handy) ---------- */
@media (max-width: 699px) {
  .shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
  .rail { order: 2; flex-direction: row; justify-content: space-around; border-right: 0; border-top: 1px solid var(--line); padding: 6px 8px; }
  .rail .brand, .rail .spacer { display: none; }
  .main { padding: 10px 10px 10px; }
  .topbar { gap: 8px 10px; }
  .topbar h2 { font-size: 18px; }
  .topbar .title { flex: 1 0 100%; }
  .topbar .navgroup { margin-right: auto; }
  .icon-btn { width: 40px; height: 40px; }
  .navgroup .btn { min-height: 40px; }
  .seg button { padding: 0 10px; min-height: 34px; }
  .people { flex-wrap: nowrap; overflow-x: auto; flex: 1 0 100%; scrollbar-width: none; padding-bottom: 2px; }
  .people::-webkit-scrollbar { display: none; }
  .person-chip { min-height: 34px; flex: none; font-size: 13px; padding-right: 10px; }
  .person-chip .dot { width: 22px; height: 22px; font-size: 12px; }
  .fab { bottom: calc(86px + env(safe-area-inset-bottom)); right: 16px; }
  .row { grid-template-columns: 70px 4px minmax(0, 1fr); }
  .grid2 { grid-template-columns: 1fr; }
}

@media (min-width: 1100px) {
  :root { --hour-h: 56px; }
}
