:root {
  --bg: #ffffff;
  --bg-soft: #f5f6f8;
  --fg: #1d2330;
  --muted: #6b7280;
  --line: #e3e6ec;
  --accent: #3b6cf6;
  --today: #fff6d6;
  --danger: #c0392b;
  --on-accent: #ffffff;
  --radius: 10px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171f;
    --bg-soft: #1c212c;
    --fg: #e8eaf0;
    --muted: #98a0b0;
    --line: #2b3242;
    --accent: #7c9cff;
    --today: #3a3417;
    --danger: #ff7b6b;
    --on-accent: #0b1020;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button, input, a { font: inherit; color: inherit; }
button { cursor: pointer; }
.muted { color: var(--muted); }
.error { color: var(--danger); margin: 0 0 .75rem; }
[hidden] { display: none !important; }

/* ---------- Login / Admin ---------- */
body.center { display: grid; place-items: center; padding: 1rem; background: var(--bg-soft); }
.login-card {
  width: min(360px, 100%);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1.75rem;
  display: flex; flex-direction: column; gap: .5rem;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .06);
}
.login-card h1 { margin: 0; font-size: 1.4rem; }
.login-card p { margin: 0 0 .5rem; }
.login-card label { font-size: .85rem; color: var(--muted); }
input[type=password], input[type=text] {
  padding: .6rem .75rem; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); width: 100%;
}
input:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.primary {
  margin-top: .5rem; padding: .6rem .9rem; border: 0; border-radius: 8px;
  background: var(--accent); color: var(--on-accent); font-weight: 600; text-decoration: none; display: inline-block; text-align: center;
}
.primary:hover { filter: brightness(1.08); }
.btn {
  padding: .45rem .8rem; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); text-decoration: none; display: inline-block;
}
.btn:hover { background: var(--bg-soft); }
.btn.danger { color: var(--danger); }

.admin { max-width: 640px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
.admin h1 { margin-top: 0; }
.admin section { border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.25rem; margin: 1rem 0; }
.admin h2 { font-size: 1.05rem; margin: 0 0 .5rem; }
.admin code { background: var(--bg-soft); padding: .1rem .35rem; border-radius: 4px; word-break: break-all; }
.admin ol { padding-left: 1.2rem; }
.cal-pick { display: flex; align-items: center; gap: .6rem; padding: .35rem 0; }
.cal-pick .sw { width: 12px; height: 12px; border-radius: 3px; background: var(--c); flex: none; }
.ok { color: #1c8a4e; }
.row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-top: .75rem; }

/* ---------- Kalender ---------- */
.app { display: flex; flex-direction: column; height: 100dvh; }
.topbar {
  display: flex; align-items: center; gap: .75rem; flex-wrap: wrap;
  padding: .6rem 1rem; border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 1.15rem; margin: 0; flex: 1 1 auto; min-width: 8rem; text-transform: capitalize; }
.topbar .nav, .seg { display: flex; }
.topbar button, .topbar a.btn { padding: .4rem .7rem; border: 1px solid var(--line); background: var(--bg); border-radius: 8px; text-decoration: none; }
.topbar button:hover, .topbar a.btn:hover { background: var(--bg-soft); }
.nav button:not(:first-child) { margin-left: -1px; }
.nav button:first-child { border-radius: 8px 0 0 8px; }
.nav button:last-child { border-radius: 0 8px 8px 0; }
.nav button:not(:first-child):not(:last-child) { border-radius: 0; }
.seg button { border-radius: 0; margin-left: -1px; }
.seg button:first-child { border-radius: 8px 0 0 8px; margin-left: 0; }
.seg button:last-child { border-radius: 0 8px 8px 0; }
.seg button[aria-pressed=true] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); position: relative; }
.topbar .right { display: flex; gap: .5rem; align-items: center; }
.topbar form { margin: 0; }
.brand { font-weight: 700; color: var(--muted); }

.legend { display: flex; flex-wrap: wrap; gap: .4rem; padding: .5rem 1rem; border-bottom: 1px solid var(--line); }
.legend button {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .2rem .6rem; border-radius: 999px; border: 1px solid var(--line); background: var(--bg); font-size: .85rem;
}
.legend button::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--c); }
.legend button[aria-pressed=false] { opacity: .5; }
.legend button[aria-pressed=false]::before { background: transparent; box-shadow: inset 0 0 0 2px var(--c); }

.banner { padding: .5rem 1rem; background: #fff3cd; color: #5b4500; font-size: .9rem; border-bottom: 1px solid #f0d98a; }
.banner.err { background: #fde3e0; color: #7a1d12; border-color: #f2b8b0; }
@media (prefers-color-scheme: dark) {
  .banner { background: #3a3417; color: #f2dc8a; border-color: #5b4f1f; }
  .banner.err { background: #3d1f1b; color: #ffb3a8; border-color: #6d3028; }
}

#view { flex: 1 1 auto; min-height: 0; overflow: auto; position: relative; }
#view.loading::after { content: ""; position: absolute; inset: 0; background: color-mix(in srgb, var(--bg) 50%, transparent); pointer-events: none; }

/* Termin-Darstellung: getönter Hintergrund, farbiger Balken – gut lesbar bei jeder Kalenderfarbe */
.ev {
  --tint: color-mix(in srgb, var(--c) 20%, var(--bg));
  background: var(--tint);
  border-left: 3px solid var(--c);
  border-radius: 4px;
  color: var(--fg);
  text-align: left;
  border-top: 0; border-right: 0; border-bottom: 0;
  padding: 1px 5px;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  font-size: .8rem; line-height: 1.35;
  display: block; width: 100%;
}
.ev:hover { background: color-mix(in srgb, var(--c) 32%, var(--bg)); }
.ev .t { opacity: .75; margin-right: .3em; font-variant-numeric: tabular-nums; }
.ev.cont { border-left-style: dotted; }

/* Monat */
.month { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); grid-template-rows: auto repeat(6, minmax(5.5rem, 1fr)); min-height: 100%; }
.month .dow { padding: .35rem .5rem; font-size: .75rem; color: var(--muted); text-transform: uppercase; border-bottom: 1px solid var(--line); }
.cell { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 2px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.cell:nth-child(7n+7) { border-right: 0; }
.cell.dim { background: var(--bg-soft); }
.cell.dim .daynum { color: var(--muted); }
.cell.today { background: var(--today); }
.daynum { align-self: flex-start; border: 0; background: none; padding: 1px 6px; border-radius: 999px; font-size: .85rem; }
.daynum:hover { background: var(--line); }
.cell.today .daynum { background: var(--accent); color: var(--on-accent); }
.more { border: 0; background: none; color: var(--muted); font-size: .75rem; text-align: left; padding: 0 5px; }
.more:hover { text-decoration: underline; }

/* Zeitraster (Woche / Tag) */
.tg { min-width: 100%; }
.tg-cols { display: grid; grid-template-columns: 3.4rem repeat(var(--n), minmax(0, 1fr)); }
.tg-top { position: sticky; top: 0; z-index: 5; background: var(--bg); border-bottom: 1px solid var(--line); }
.tg.wide { min-width: 640px; }
.tg-head > div { padding: .4rem .25rem; text-align: center; font-size: .8rem; color: var(--muted); border-left: 1px solid var(--line); }
.tg-head > div:first-child { border-left: 0; }
.tg-head .n { display: block; font-size: 1.25rem; color: var(--fg); }
.tg-head .today .n { color: var(--on-accent); background: var(--accent); border-radius: 999px; width: 2rem; margin: 0 auto; }
.tg-head button { border: 0; background: none; width: 100%; }
.tg-allday > div { border-left: 1px solid var(--line); padding: 2px; display: flex; flex-direction: column; gap: 2px; min-height: 1.6rem; }
.tg-allday > div:first-child { border-left: 0; font-size: .7rem; color: var(--muted); padding: 4px 4px 0 0; text-align: right; }
.tg-body { position: relative; height: calc(24 * var(--hour)); }
.tg-body .hours { position: absolute; inset: 0 auto 0 0; width: 3.4rem; }
.tg-body .hours span { position: absolute; right: .4rem; transform: translateY(-50%); font-size: .7rem; color: var(--muted); }
.tg-body .lines { position: absolute; inset: 0 0 0 3.4rem; background-image: linear-gradient(var(--line) 1px, transparent 1px); background-size: 100% var(--hour); }
.tg-body .days { position: absolute; inset: 0 0 0 3.4rem; display: grid; grid-template-columns: repeat(var(--n), minmax(0, 1fr)); }
.tg-body .day { position: relative; border-left: 1px solid var(--line); }
.tg-body .day.today { background: color-mix(in srgb, var(--today) 45%, transparent); }
.tg-body .ev { position: absolute; width: auto; padding: 2px 5px; white-space: normal; border-radius: 5px; border: 1px solid color-mix(in srgb, var(--c) 40%, var(--bg)); border-left: 3px solid var(--c); }
.tg-body .ev .t { display: block; margin: 0; font-size: .7rem; }
.now { position: absolute; left: 0; right: 0; height: 2px; background: #e5483b; z-index: 3; pointer-events: none; }
.now::before { content: ""; position: absolute; left: -4px; top: -3px; width: 8px; height: 8px; border-radius: 50%; background: #e5483b; }

/* Liste */
.agenda { max-width: 760px; margin: 0 auto; padding: .5rem 1rem 2rem; }
.agenda .grp { display: grid; grid-template-columns: 4.2rem 1fr; gap: .75rem; padding: .75rem 0; border-bottom: 1px solid var(--line); }
.agenda .grp.past { opacity: .6; }
.agenda .date { text-align: center; line-height: 1.1; }
.agenda .date .n { font-size: 1.5rem; font-weight: 600; display: block; }
.agenda .date .w { font-size: .75rem; color: var(--muted); text-transform: uppercase; }
.agenda .grp.today .date .n { color: var(--accent); }
.agenda .items { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.agenda .ev { padding: .35rem .6rem; font-size: .92rem; white-space: normal; }
.agenda .ev .loc { display: block; color: var(--muted); font-size: .8rem; }
.empty { padding: 3rem 1rem; text-align: center; color: var(--muted); }

/* Detail-Dialog */
dialog { border: 1px solid var(--line); border-radius: 14px; padding: 0; width: min(520px, calc(100vw - 2rem)); background: var(--bg); color: var(--fg); }
dialog::backdrop { background: rgba(0, 0, 0, .4); }
.dlg { padding: 1.25rem 1.4rem 1.4rem; border-top: 6px solid var(--c); border-radius: 14px; max-height: 85dvh; overflow: auto; }
.dlg h2 { margin: 0 0 .25rem; font-size: 1.2rem; overflow-wrap: anywhere; }
.dlg .close { position: absolute; top: .5rem; right: .6rem; border: 0; background: none; font-size: 1.4rem; line-height: 1; padding: .2rem .5rem; }
.dlg dl { margin: .9rem 0 0; display: grid; grid-template-columns: 6.5rem 1fr; gap: .45rem .75rem; }
.dlg dt { color: var(--muted); font-size: .85rem; }
.dlg dd { margin: 0; overflow-wrap: anywhere; white-space: pre-wrap; }
.dlg dd a { color: var(--accent); }
.dlg ul { margin: 0; padding: 0; list-style: none; }

@media (max-width: 700px) {
  .topbar { padding: .5rem; gap: .5rem; }
  .topbar h1 { order: -1; flex-basis: 100%; }
  .brand { display: none; }
  .month { grid-template-rows: auto repeat(6, minmax(4.2rem, 1fr)); }
  .month .dow { padding: .25rem; text-align: center; }
  .cell .ev { font-size: .68rem; padding: 0 3px; }
  .cell .ev .t { display: none; }
  .daynum { font-size: .78rem; }
}
