:root {
  --bg: #f6f2ff;
  --card: #fff;
  --ink: #2a2140;
  --muted: #7b7193;
  --line: #ebe4f7;
  --soft: #f1ebfc;
  --accent: #8b5cf6;
  --danger: #d23b5c;
  --rainbow: linear-gradient(90deg, #ff8fc8, #ffb38a, #ffe27a, #8fe3b8, #8cc8ff, #b39bff);
  --shadow: 0 1px 2px rgba(60, 30, 120, .06), 0 4px 16px rgba(60, 30, 120, .07);
  --r: 16px;
  --tabh: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  background-image:
    radial-gradient(1200px 500px at 10% -10%, #ffe3f3 0, transparent 60%),
    radial-gradient(900px 500px at 100% 0, #e3ecff 0, transparent 60%);
  background-attachment: fixed;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
h2, h3, p { margin: 0; }

/* ---- top bar ---- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: grid; grid-template-columns: 1fr auto;
  grid-template-areas: "brand me" "period period";
  align-items: center; gap: 8px 12px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 8px;
  background: rgba(246, 242, 255, .94);
  border-bottom: 1px solid var(--line);
}
.brand { grid-area: brand; display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 19px; letter-spacing: -.01em; }
.brand img { width: auto; height: 36px; }
.brand em { font-style: normal; font-weight: 500; color: var(--muted); margin-left: 5px; }
.avatar {
  grid-area: me; width: 38px; height: 38px; border-radius: 50%;
  border: 2px solid #fff; background: var(--c, #999); color: #fff; font-weight: 700;
  box-shadow: var(--shadow);
}
.period { grid-area: period; display: flex; align-items: center; gap: 6px; }
#period { flex: 1; text-align: center; font-weight: 650; font-size: 17px; }
.icon { width: 36px; height: 36px; border: 0; border-radius: 10px; background: var(--card); box-shadow: var(--shadow); font-size: 22px; line-height: 1; }
.today-btn { border: 0; border-radius: 10px; background: var(--card); box-shadow: var(--shadow); padding: 8px 12px; font-weight: 600; font-size: 14px; }
body[data-view="heute"] .period, body[data-view="liste"] .period { display: none; }

/* ---- tabs (bottom bar on phones) ---- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; padding: 6px 8px calc(6px + var(--safe-b));
  background: rgba(255, 255, 255, .97); border-top: 1px solid var(--line);
}
.tabs button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; border: 0; background: none; padding: 4px; border-radius: 12px; font-size: 12px; color: var(--muted); }
.tabs .ico { font-size: 20px; line-height: 1.1; filter: grayscale(1) opacity(.55); }
.tabs button.on { color: var(--ink); font-weight: 650; }
.tabs button.on .ico { filter: none; }

/* ---- filter chips ---- */
.filters { display: flex; gap: 8px; overflow-x: auto; max-width: 1200px; margin: 0 auto; padding: 10px 16px 2px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1.5px solid var(--c); border-radius: 999px; background: #fff; color: var(--c); padding: 5px 12px; font-weight: 600; font-size: 14px; }
.chip.on { background: var(--c); color: #fff; }
.chip.praxis:not(.on) { border-style: dashed; }
.chip.static { cursor: default; }

/* ---- layout ---- */
main { max-width: 1200px; margin: 0 auto; padding: 10px 16px calc(var(--tabh) + 96px + var(--safe-b)); }
.card { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); padding: 14px; }
.card h3, .agenda-day h3 { font-size: 12.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 8px; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.card-head h3 { margin: 0; }
.link { border: 0; background: none; color: var(--accent); font-weight: 650; padding: 4px; }
.list { display: grid; gap: 6px; }
.empty { color: var(--muted); }

/* ---- event row ---- */
.ev {
  display: grid; grid-template-columns: 4px 50px minmax(0, 1fr) auto;
  grid-template-areas: "bar time body who";
  align-items: center; gap: 10px;
  width: 100%; min-height: 50px; padding: 8px 10px 8px 0;
  border: 0; border-radius: 12px; overflow: hidden; text-align: left;
  background: color-mix(in srgb, var(--c) 9%, #fff);
}
.ev .bar { grid-area: bar; align-self: stretch; margin: -8px 0; background: var(--bar); }
.ev .time { grid-area: time; display: flex; flex-direction: column; font-weight: 600; font-size: 14px; font-variant-numeric: tabular-nums; }
.ev .time small { font-size: 12px; font-weight: 400; color: var(--muted); }
.ev .body { grid-area: body; display: flex; flex-direction: column; min-width: 0; }
.ev .title, .ev .sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev .title { font-weight: 600; }
.ev .sub { font-size: 12.5px; color: var(--muted); }
.k-praxis { background: repeating-linear-gradient(135deg, color-mix(in srgb, var(--c) 11%, #fff) 0 7px, #fff 7px 14px); }
.who {
  grid-area: who; display: grid; place-items: center;
  width: 24px; height: 24px; border-radius: 50%; border: 2px solid #fff;
  color: #fff; font-size: 11.5px; font-weight: 700; box-shadow: 0 1px 3px rgba(0, 0, 0, .18);
}

/* ---- today ---- */
.dash { display: grid; gap: 12px; }
.hero {
  position: relative; overflow: hidden; padding: 20px 18px; border-radius: 20px; box-shadow: var(--shadow);
  background: linear-gradient(120deg, #fff0f8, #f1ecff 50%, #e9f6ff);
}
.hero::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 5px; background: var(--rainbow); }
.hero img { position: absolute; right: 6px; bottom: -14px; height: 104px; opacity: .8; }
.hero .greet { font-size: 23px; font-weight: 750; letter-spacing: -.01em; }
.hero .date { color: var(--muted); margin-top: 2px; }
.hero .summary { margin-top: 12px; font-weight: 600; max-width: calc(100% - 100px); }
.bday { display: flex; align-items: center; gap: 12px; width: 100%; padding: 8px 0; border: 0; border-top: 1px solid var(--line); background: none; text-align: left; }
.bday:first-of-type { border-top: 0; }
.bday .cake { font-size: 22px; }
.bday .grow { flex: 1; }
.bday b { display: block; }
.bday small { color: var(--muted); }
.bday .in { font-size: 13px; font-weight: 600; color: var(--accent); white-space: nowrap; }
.day-label { font-size: 13px; font-weight: 650; margin: 10px 0 6px; }
.day-label:first-child { margin-top: 0; }

/* ---- month ---- */
.month-wrap { display: grid; gap: 12px; }
.month { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 3px; }
.wd { text-align: center; font-size: 12px; font-weight: 600; color: var(--muted); padding: 2px 0; }
.cell {
  display: flex; flex-direction: column; gap: 2px; min-width: 0; min-height: 70px; padding: 3px;
  border: 0; border-radius: 10px; background: #fff; text-align: left; overflow: hidden;
}
.cell.other { background: rgba(255, 255, 255, .45); color: var(--muted); }
.cell .num { align-self: center; display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; font-size: 13px; font-weight: 600; }
.cell.today .num { background: var(--accent); color: #fff; }
.cell.sel { box-shadow: inset 0 0 0 2px var(--accent); }
.pill {
  display: block; padding: 0 3px 0 6px; border-radius: 4px;
  font-size: 10px; line-height: 1.4; white-space: nowrap; overflow: hidden;
  background: var(--bar) left / 3px 100% no-repeat, color-mix(in srgb, var(--c) 16%, #fff);
}
.pill.k-praxis { background: var(--bar) left / 3px 100% no-repeat, repeating-linear-gradient(135deg, color-mix(in srgb, var(--c) 16%, #fff) 0 5px, #fff 5px 10px); }
.pill .t { display: none; color: var(--muted); margin-right: 3px; }
.more { padding-left: 4px; font-size: 10px; color: var(--muted); }

/* ---- week ---- */
.week { display: grid; gap: 10px; }
.wday { background: #fff; border-radius: var(--r); box-shadow: var(--shadow); padding: 10px; min-width: 0; }
.wday header { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; cursor: pointer; }
.wday header span:first-child { color: var(--muted); font-weight: 600; }
.wday header b { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; font-size: 17px; }
.wday.today header b { background: var(--accent); color: #fff; }
.wday header .add { margin-left: auto; color: var(--accent); font-weight: 700; font-size: 22px; line-height: 1; }

/* ---- list ---- */
.month-sep { font-size: 20px; margin: 18px 0 10px; }
.month-sep:first-child { margin-top: 4px; }
.agenda-day { margin-bottom: 14px; }
.more-btn { display: block; margin: 16px auto; border: 0; border-radius: 999px; background: #fff; box-shadow: var(--shadow); padding: 10px 18px; font-weight: 600; color: var(--accent); }

/* ---- add button ---- */
.fab {
  position: fixed; right: 18px; bottom: calc(var(--tabh) + 18px + var(--safe-b)); z-index: 15;
  width: 60px; height: 60px; border: 0; border-radius: 50%;
  color: #fff; font-size: 34px; line-height: 1;
  background: linear-gradient(135deg, #f472b6, #a78bfa 55%, #60a5fa);
  box-shadow: 0 8px 24px rgba(139, 92, 246, .45);
}

/* ---- sheets ---- */
dialog {
  width: 100%; max-width: 560px; max-height: 92dvh; margin: auto auto 0; padding: 0;
  border: 0; border-radius: 22px 22px 0 0; background: #fff; color: var(--ink);
  box-shadow: 0 -10px 40px rgba(40, 20, 80, .25);
}
dialog::backdrop { background: rgba(42, 24, 80, .35); }
.sheet { padding: 18px 18px calc(18px + var(--safe-b)); }
.sheet-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.sheet-head h2 { flex: 1; font-size: 20px; }
.close { width: 34px; height: 34px; flex: none; border: 0; border-radius: 50%; background: var(--soft); font-size: 15px; }
.seg { display: flex; gap: 3px; padding: 3px; border-radius: 12px; background: var(--soft); }
.seg button { flex: 1; border: 0; border-radius: 9px; background: none; padding: 8px 4px; font-weight: 600; font-size: 14px; color: var(--muted); }
.seg button.on { background: #fff; color: var(--ink); box-shadow: var(--shadow); }
.field { display: grid; gap: 4px; min-width: 0; margin-top: 12px; font-size: 13px; font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea {
  width: 100%; min-width: 0; min-height: 44px; padding: 10px 12px;
  border: 1.5px solid var(--line); border-radius: 12px; background: #fbf9ff;
  font: inherit; font-size: 16px; font-weight: 400; color: var(--ink);
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--accent); background: #fff; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.switch { display: flex; align-items: center; gap: 10px; margin-top: 12px; font-weight: 600; }
.switch input { width: 20px; height: 20px; accent-color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.actions { display: flex; align-items: center; gap: 8px; margin-top: 18px; }
.grow { flex: 1; }
.btn { border: 0; border-radius: 12px; background: var(--soft); padding: 11px 16px; font-weight: 650; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.danger { background: none; color: var(--danger); padding-left: 4px; }
.meta { margin-top: 14px; font-size: 12.5px; color: var(--muted); }
.meta:empty { display: none; }

/* which editor fields apply to which kind of entry */
#editorForm:not([data-kind="termin"]) .only-termin,
#editorForm:not([data-kind="termin"]) .only-multi,
#editorForm[data-allday="0"] .only-multi,
#editorForm[data-kind="geburtstag"] .only-timed,
#editorForm[data-kind="termin"][data-allday="1"] .only-timed,
#editorForm[data-kind="praxis"] .only-who,
#editorForm[data-kind="geburtstag"] .only-repeat { display: none; }

/* detail sheet */
.detail-head { display: flex; gap: 12px; align-items: stretch; }
.detail-head .bar { width: 6px; flex: none; border-radius: 3px; background: var(--bar); }
.detail-head h2 { font-size: 21px; }
.when { margin-top: 4px; font-weight: 600; }
.repeat { margin-top: 2px; color: var(--muted); }
.detail-chips { margin-top: 14px; }
.note { margin-top: 14px; padding: 10px 12px; border-radius: 12px; background: var(--soft); white-space: pre-wrap; }
.creator { display: grid; gap: 8px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); font-size: 14px; }
.creator div { display: flex; align-items: center; gap: 10px; }
.creator .who { width: 28px; height: 28px; font-size: 13px; }
.creator small { color: var(--muted); }

/* menu */
.menu-section { margin-top: 16px; }
.menu-section h3 { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.menu-section .btn { width: 100%; text-align: left; }
.fineprint { margin-top: 18px; font-size: 12.5px; color: var(--muted); }
.menu-section .btn + .btn { margin-top: 8px; }
a.btn { display: block; color: inherit; text-decoration: none; }

/* offline banner */
#offline { margin: 0; padding: 6px 16px; background: #fff4d6; color: #7a5a00; font-size: 13px; font-weight: 600; text-align: center; }
.err { color: var(--danger); font-weight: 600; }

/* login page */
.login-page { display: grid; grid-template-columns: minmax(0, 380px); place-content: center; padding: 24px 16px; }
.login-card {
  position: relative; overflow: hidden; width: 100%; max-width: 380px; padding: 28px 22px 24px;
  border-radius: 22px; background: #fff; box-shadow: var(--shadow); text-align: center;
}
.login-card::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 5px; background: var(--rainbow); }
.login-logo { height: 110px; }
.login-card h1 { margin: 6px 0 10px; font-size: 24px; letter-spacing: -.01em; }
.login-card h1 em { font-style: normal; font-weight: 500; color: var(--muted); margin-left: 6px; }
.login-card form { text-align: left; }
.login-card .btn { width: 100%; margin-top: 16px; padding: 13px; }
.login-card .btn:disabled { opacity: .6; }
.login-msg { min-height: 1.4em; margin-top: 10px; color: var(--danger); font-size: 14px; font-weight: 600; }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabh) + 30px + var(--safe-b)); z-index: 30;
  padding: 10px 16px; border-radius: 999px; background: var(--ink); color: #fff; font-weight: 600;
  opacity: 0; transform: translate(-50%, 20px); transition: .25s; pointer-events: none;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---- tablet / laptop ---- */
@media (min-width: 700px) {
  dialog { margin: auto; border-radius: 22px; }
}
@media (min-width: 900px) {
  .dash { grid-template-columns: 1fr 1fr; align-items: start; }
  .dash .hero { grid-column: 1 / -1; }
  .cell { min-height: 112px; padding: 6px; }
  .cell .num { align-self: flex-start; }
  .pill { font-size: 12px; padding: 1px 4px 1px 8px; }
  .pill .t { display: inline; }
  .more { font-size: 12px; }
  .week { grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
  .wday { min-height: 55vh; padding: 8px; }
  .week .ev { grid-template-columns: 4px minmax(0, 1fr) auto; grid-template-areas: "bar time who" "bar body body"; gap: 2px 8px; padding: 6px 8px 6px 0; }
  .week .ev .time { flex-direction: row; gap: 0; font-size: 12px; }
  .week .ev .time small::before { content: "–"; }
  .week .ev .sub { display: none; }
}
@media (min-width: 1100px) {
  .month-wrap { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }
  .month-wrap .card { position: sticky; top: 80px; }
}
@media (min-width: 1024px) {
  .topbar { grid-template-columns: auto 1fr auto auto; grid-template-areas: "brand . period me"; padding: 12px 24px; }
  #period { min-width: 210px; }
  .tabs {
    top: 12px; bottom: auto; left: 50%; right: auto; transform: translateX(-50%); z-index: 11;
    gap: 4px; padding: 4px; border: 0; border-radius: 14px; background: var(--soft);
  }
  .tabs button { flex-direction: row; gap: 6px; padding: 8px 14px; font-size: 14px; }
  .tabs button.on { background: #fff; box-shadow: var(--shadow); }
  .tabs .ico { font-size: 16px; }
  main { padding: 14px 24px 110px; }
  .filters { padding: 14px 24px 2px; }
  .fab { right: 28px; bottom: 28px; }
  #toast { bottom: 40px; }
}
