:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --line: #e3e6eb;
  --line-strong: #cfd4db;
  --text: #1b1e23;
  --text-2: #5b6370;
  --text-3: #8a919c;
  --accent: #2f6fde;
  --accent-text: #ffffff;
  --accent-soft: #e6eefc;
  --now: #e0453a;
  --today-bg: #eef3fd;
  --danger: #c63a30;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg: 0 20px 50px rgba(16, 24, 40, .25);
  --radius: 10px;
  --hour: 52px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1c1f24;
    --surface-2: #23272d;
    --line: #2c3037;
    --line-strong: #3a3f47;
    --text: #e8eaed;
    --text-2: #a3aab5;
    --text-3: #747c88;
    --accent: #6c9cff;
    --accent-text: #0d1424;
    --accent-soft: #1f2b44;
    --now: #ff6b5f;
    --today-bg: #1b2333;
    --danger: #ff7b70;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-lg: 0 20px 50px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
button, input { font: inherit; color: inherit; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
[hidden] { display: none !important; }

/* ---------- Kopfzeile ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
  padding: 10px max(16px, env(safe-area-inset-left)) 10px max(16px, env(safe-area-inset-right));
}
.brand { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.brand h1 { font-size: 18px; margin: 0; font-weight: 650; letter-spacing: -.01em; }
.status { color: var(--text-3); font-size: 12.5px; }
.status.err { color: var(--danger); }
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.nav { display: flex; align-items: center; gap: 4px; }
.range-label { font-weight: 600; margin-left: 8px; white-space: nowrap; }
.actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }

.btn, .icon-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 12px; border-radius: 8px;
  border: 1px solid var(--line-strong); background: var(--surface);
  cursor: pointer; text-decoration: none; white-space: nowrap; font-weight: 500;
  transition: background .12s, border-color .12s;
}
a.btn { color: var(--text); }
.btn:hover, .icon-btn:hover { background: var(--surface-2); }
.btn.primary, a.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.07); }
.icon-btn { width: 34px; padding: 0; }
.badge { background: var(--accent); color: var(--accent-text); border-radius: 999px; font-size: 11px; font-weight: 700; padding: 1px 6px; }

.segmented { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 9px; padding: 2px; }
.segmented button { border: 0; background: transparent; height: 28px; padding: 0 12px; border-radius: 7px; cursor: pointer; color: var(--text-2); font-weight: 500; }
.segmented button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.search { display: flex; align-items: center; gap: 6px; height: 34px; padding: 0 10px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); color: var(--text-3); }
.search input { border: 0; outline: 0; background: transparent; width: 150px; color: var(--text); }
.search:focus-within { border-color: var(--accent); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

main { padding: 16px max(16px, env(safe-area-inset-left)) 48px; outline: none; }

/* ---------- Liste ---------- */
.agenda { max-width: 860px; margin: 0 auto; }
.week-sep { display: flex; align-items: center; gap: 10px; color: var(--text-3); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; margin: 22px 0 8px; }
.week-sep::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.week-sep:first-child { margin-top: 4px; }
.day { display: grid; grid-template-columns: 64px 1fr; gap: 12px; padding: 8px 0; }
.day-label { text-align: center; padding-top: 4px; }
.day-label .dow { display: block; font-size: 12px; color: var(--text-3); text-transform: uppercase; font-weight: 600; }
.day-label .dnum { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; font-size: 19px; font-weight: 650; }
.day.is-today .dnum { background: var(--accent); color: var(--accent-text); }
.day.is-past { opacity: .6; }
.day-events { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.empty-day { color: var(--text-3); font-size: 13px; padding: 10px 0; }

.card {
  display: grid; grid-template-columns: 4px 88px 1fr; align-items: stretch;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); cursor: pointer; text-align: left; padding: 0; overflow: hidden; width: 100%;
}
.card:hover { border-color: var(--line-strong); }
.card .bar { background: var(--c); }
.card .time { padding: 10px 0 10px 12px; font-variant-numeric: tabular-nums; font-weight: 600; font-size: 14px; }
.card .time small { display: block; color: var(--text-3); font-weight: 500; }
.card .body { padding: 10px 12px 10px 4px; min-width: 0; }
.card .title { font-weight: 600; overflow-wrap: anywhere; }
.card .meta { color: var(--text-2); font-size: 13px; margin-top: 2px; display: flex; flex-wrap: wrap; gap: 4px 12px; }
.card .meta span { display: inline-flex; align-items: flex-start; gap: 4px; }
.card .meta svg { margin-top: 2px; }
.card .meta svg { width: 14px; height: 14px; }
.card.now { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), var(--shadow); }
.pill { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); margin-top: 5px; overflow-wrap: anywhere; }
.pill.live { background: var(--accent); color: var(--accent-text); margin: 0 0 0 6px; vertical-align: 2px; }
.pill.warn { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
.cancelled .title { text-decoration: line-through; color: var(--text-3); }
.cancelled .bar { background: var(--text-3); }

/* ---------- Woche ---------- */
.week { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: auto; max-height: calc(100vh - 150px); }
.week-grid { display: grid; grid-template-columns: 52px repeat(var(--days), minmax(110px, 1fr)); min-width: calc(52px + var(--days) * 110px); }
.week-head { position: sticky; top: 0; z-index: 3; background: var(--surface); border-bottom: 1px solid var(--line); padding: 8px 6px; text-align: center; font-size: 13px; color: var(--text-2); }
.week-head b { display: block; font-size: 18px; color: var(--text); }
.week-head.is-today b { color: var(--accent); }
.week-head.corner { left: 0; z-index: 4; }
.hours { position: sticky; left: 0; z-index: 2; background: var(--surface); }
.hours div { height: var(--hour); font-size: 11px; color: var(--text-3); text-align: right; padding-right: 6px; transform: translateY(-7px); font-variant-numeric: tabular-nums; }
.hours div:first-child { transform: none; }
.col { position: relative; border-left: 1px solid var(--line); background-image: repeating-linear-gradient(to bottom, transparent 0, transparent calc(var(--hour) - 1px), var(--line) calc(var(--hour) - 1px), var(--line) var(--hour)); }
.col.is-today { background-color: var(--today-bg); }
.ev {
  position: absolute; border: 0; border-left: 3px solid var(--c); border-radius: 6px; padding: 3px 6px;
  background: color-mix(in srgb, var(--c) 18%, var(--surface)); color: var(--text);
  font-size: 12px; line-height: 1.3; text-align: left; overflow: hidden; cursor: pointer;
  display: flex; flex-direction: column; justify-content: flex-start; align-items: stretch;
}
.ev:hover { background: color-mix(in srgb, var(--c) 28%, var(--surface)); z-index: 2; }
.ev b { display: block; font-weight: 600; }
.ev .t { color: var(--text-2); font-variant-numeric: tabular-nums; }
.ev.cancelled { opacity: .55; }
.ev.group { background: var(--surface-2); border-left-color: var(--line-strong); gap: 1px; }
.ev.group:hover { background: color-mix(in srgb, var(--text) 8%, var(--surface)); }
.ev .gl { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-left: 9px; position: relative; color: var(--text-2); }
.ev .gl::before { content: ""; position: absolute; left: 0; top: .45em; width: 5px; height: 5px; border-radius: 50%; background: var(--c); }
.ev.cancelled b { text-decoration: line-through; }
.now-line { position: absolute; left: 0; right: 0; height: 2px; background: var(--now); z-index: 3; pointer-events: none; }
.now-line::before { content: ""; position: absolute; left: -5px; top: -4px; width: 10px; height: 10px; border-radius: 50%; background: var(--now); }
.allday-row { display: contents; }
.allday { border-left: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 3px; display: flex; flex-direction: column; gap: 2px; }
.allday .ev { position: static; }

/* ---------- Monat ---------- */
.month { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.month-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.month-dow { padding: 8px; font-size: 12px; font-weight: 600; color: var(--text-3); text-transform: uppercase; border-bottom: 1px solid var(--line); text-align: center; }
.mday { min-height: 112px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 4px; display: flex; flex-direction: column; gap: 2px; min-width: 0; cursor: pointer; }
.mday:nth-child(7n) { border-right: 0; }
.mday.other { background: var(--surface-2); color: var(--text-3); }
.mday .n { font-size: 13px; font-weight: 600; width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; margin-bottom: 2px; }
.mday.is-today .n { background: var(--accent); color: var(--accent-text); }
.chip { width: 100%; overflow: hidden; display: flex; gap: 4px; align-items: center; font-size: 11.5px; padding: 1px 4px; border-radius: 4px; border: 0; background: transparent; text-align: left; cursor: pointer; min-width: 0; }
.chip:hover { background: var(--surface-2); }
.chip i { width: 7px; height: 7px; border-radius: 50%; background: var(--c); flex: none; }
.chip span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip.cancelled span { text-decoration: line-through; color: var(--text-3); }
.mday .chips { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.more { font-size: 11.5px; color: var(--text-3); padding-left: 4px; }

/* ---------- Dialoge ---------- */
dialog.sheet { border: 0; padding: 0; border-radius: 14px; background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); width: min(520px, calc(100vw - 24px)); max-height: calc(100vh - 48px); }
dialog.sheet.wide { width: min(680px, calc(100vw - 24px)); }
dialog::backdrop { background: rgba(10, 14, 20, .45); }
.sheet-inner { padding: 18px 20px 20px; display: flex; flex-direction: column; gap: 12px; max-height: calc(100vh - 48px); }
.sheet-head { display: flex; align-items: flex-start; gap: 10px; }
.sheet-head h2 { margin: 0; font-size: 18px; flex: 1; line-height: 1.3; overflow-wrap: anywhere; }
.sheet-head .icon-btn { border: 0; }
.swatch { width: 12px; height: 12px; border-radius: 4px; background: var(--c); margin-top: 6px; flex: none; }
.hint { margin: 0; color: var(--text-2); font-size: 13.5px; }
.details { display: grid; grid-template-columns: 110px 1fr; gap: 8px 12px; margin: 0; }
.details dt { color: var(--text-3); font-size: 13px; }
.details dd { margin: 0; overflow-wrap: anywhere; }

.filter-tools { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.filter-tools input[type=search] { flex: 1; min-width: 180px; height: 34px; padding: 0 10px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); }
.toggle { display: inline-flex; gap: 6px; align-items: center; font-size: 14px; cursor: pointer; }
.filter-list { overflow: auto; border: 1px solid var(--line); border-radius: 10px; min-height: 120px; }
.fgroup + .fgroup { border-top: 1px solid var(--line); }
.fgroup-head { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--surface-2); position: sticky; top: 0; z-index: 1; font-weight: 600; font-size: 13.5px; }
.fgroup-head .swatch { margin: 0; }
.fgroup-head .spacer { flex: 1; }
.fgroup-head button { border: 0; background: none; color: var(--accent); cursor: pointer; font-size: 12.5px; padding: 2px 4px; }
.fitem { display: flex; align-items: center; gap: 10px; padding: 7px 12px; cursor: pointer; font-size: 14px; }
.fitem:hover { background: var(--surface-2); }
.fitem input { width: 16px; height: 16px; accent-color: var(--accent); flex: none; }
.fitem .name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.fitem .count { color: var(--text-3); font-size: 12px; font-variant-numeric: tabular-nums; }
.fitem.off .name { color: var(--text-3); }
.sheet-foot { display: flex; justify-content: space-between; gap: 8px; }

.copy-row { display: flex; gap: 8px; }
.copy-row input { flex: 1; min-width: 0; height: 34px; padding: 0 10px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface-2); font-size: 13px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.sub-links { display: flex; gap: 8px; flex-wrap: wrap; }
.howto { font-size: 13.5px; color: var(--text-2); }
.howto summary { cursor: pointer; color: var(--text); }
.howto ul { padding-left: 18px; margin: 8px 0 0; }
.howto li { margin-bottom: 4px; }

.week + .notice, .notice + .week, .notice + .month { margin-top: 16px; }
.notice { max-width: 860px; margin: 24px auto; text-align: center; color: var(--text-2); }
.notice h2 { color: var(--text); font-size: 18px; }

/* ---------- Mobil ---------- */
@media (max-width: 720px) {
  .brand { margin-bottom: 6px; }
  .toolbar { gap: 8px; }
  .actions { margin-left: 0; width: 100%; }
  .search { flex: 1; }
  .search input { width: 100%; }
  .btn span:not(.badge) { display: none; }
  .btn { padding: 0 10px; }
  .segmented { margin-left: auto; }
  .range-label { font-size: 14px; }
  .day { grid-template-columns: 44px 1fr; gap: 8px; }
  .day-label .dnum { width: 32px; height: 32px; font-size: 16px; }
  .card { grid-template-columns: 4px 68px 1fr; }
  .card .time { font-size: 13px; padding-left: 10px; }
  .mday { min-height: 64px; }
  .chip span { display: none; }
  .chip { padding: 2px; width: auto; }
  .mday .chips { flex-direction: row; flex-wrap: wrap; gap: 1px; }
  .details { grid-template-columns: 90px 1fr; }
  dialog.sheet { margin: auto auto 0; border-radius: 16px 16px 0 0; width: 100vw; max-width: 100vw; }
}
@media (max-width: 400px) {
  .range-label { display: none; }
}
