:root {
  --bg: #0b1220;
  --bg-elev: #131c30;
  --bg-elev2: #1b2540;
  --border: #243152;
  --text: #e6ecff;
  --text-dim: #94a3c4;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --danger: #ef4444;
  --success: #10b981;
  --warning: #f59e0b;
  --today-bg: rgba(99, 102, 241, 0.15);
  --hover: rgba(255,255,255,0.06);
  --shadow: 0 12px 40px rgba(0,0,0,0.4);
  --radius: 14px;
  --radius-sm: 8px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}
/* Hell erzwungen (Einstellungen → Darstellung → Hell) */
:root.theme-light {
  --bg: #f7f8fc;
  --bg-elev: #ffffff;
  --bg-elev2: #f0f3fb;
  --border: #d8dee9;
  --text: #1a2233;
  --text-dim: #5b6582;
  --today-bg: rgba(99, 102, 241, 0.12);
  --hover: rgba(0,0,0,0.04);
  --shadow: 0 8px 30px rgba(20,30,60,0.12);
  color-scheme: light;
}
/* System-Modus folgt dem Gerät (native Steuerelemente via color-scheme) */
:root.theme-auto { color-scheme: light dark; }
@media (prefers-color-scheme: light) {
  :root.theme-auto {
    --bg: #f7f8fc;
    --bg-elev: #ffffff;
    --bg-elev2: #f0f3fb;
    --border: #d8dee9;
    --text: #1a2233;
    --text-dim: #5b6582;
    --today-bg: rgba(99, 102, 241, 0.12);
    --hover: rgba(0,0,0,0.04);
    --shadow: 0 8px 30px rgba(20,30,60,0.12);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  height: 100dvh;
  user-select: none;
}
button { font: inherit; color: inherit; background: transparent; border: 0; cursor: pointer; }
input, textarea, select {
  font: inherit; color: inherit; background: var(--bg-elev2);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px 12px; outline: none;
  width: 100%;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { resize: none; overflow: hidden; min-height: 60px; }

.app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  /* Single column capped at the viewport width. Without this the implicit
     'auto' column sizes to max-content, so a long nowrap title (e.g.
     "23.–29. November 2026") widens the whole app past the viewport and the
     Sunday column of the week grid gets clipped on the right. */
  grid-template-columns: minmax(0, 1fr);
  height: 100dvh;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

/* ===== Top bar ===== */
.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 5;
}
.topbar .menu, .topbar .icon-btn {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 10px;
}
.topbar .icon-btn:hover { background: var(--hover); }
.topbar .title {
  flex: 1; font-weight: 600; font-size: 18px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar .title small { color: var(--text-dim); font-weight: 400; }

.view-switch {
  display: flex; gap: 4px; background: var(--bg-elev2); padding: 4px; border-radius: 10px;
}
.view-switch button {
  padding: 6px 12px; border-radius: 7px; font-size: 13px; color: var(--text-dim);
  white-space: nowrap;
}
.view-switch button.active {
  background: var(--accent); color: white;
}
/* Theme-Umschalter in den Einstellungen (gleiche Segment-Optik, gleichmäßige Breite) */
.theme-switch { display: flex; width: 100%; }
.theme-switch button { flex: 1; text-align: center; }
/* Im Drawer (5 Buttons in 280px) als Grid statt Flexbox — sonst überlaufen die Labels. */
.drawer-section .view-switch {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
}
.drawer-section .view-switch button {
  padding: 8px 4px;
  font-size: 12px;
  text-align: center;
  border-radius: 7px;
  min-width: 0;
}

/* ===== Sidebar / Drawer ===== */
.drawer {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  opacity: 0; pointer-events: none;
  transition: opacity .2s;
  /* muss über der Bottom-Bar (z-index 60) liegen, sonst verdeckt diese im
     Overlay-Modus die unteren Drawer-Links (Suchen/Wecker/Einstellungen/Export) */
  z-index: 80;
}
.drawer.open { opacity: 1; pointer-events: auto; }
.drawer-inner {
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 86%; max-width: 320px;
  background: var(--bg-elev);
  transform: translateX(-100%); transition: transform .25s;
  display: flex; flex-direction: column;
  padding-top: var(--safe-top);
  /* lange Inhalte (viele Kalender) bleiben erreichbar statt unten abgeschnitten */
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-bottom: var(--safe-bottom);
}
.drawer.open .drawer-inner { transform: translateX(0); }
.drawer-header { padding: 18px 18px 8px; border-bottom: 1px solid var(--border); }
.drawer-header h2 { margin: 0; font-size: 20px; }
.drawer-header small { color: var(--text-dim); }
.drawer-section { padding: 12px 14px; }
.drawer-section h3 { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px; margin: 0 0 8px; padding: 0 4px; }
.cal-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px; cursor: pointer;
}
.cal-item:hover { background: var(--hover); }
.cal-item .dot {
  width: 16px; height: 16px; border-radius: 4px;
  position: relative;
}
.cal-item .dot.off { opacity: .25; }
.cal-item .dot.off::after { content: ""; position: absolute; inset: 0; border: 2px solid var(--text); border-radius: 4px; }
.cal-item .label { flex: 1; font-size: 14px; }
.cal-item .edit {
  color: var(--text-dim);
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border-radius: 6px;
  flex: 0 0 auto;
}
.cal-item .edit:hover { color: var(--text); background: var(--hover); }
.cal-item .edit svg { width: 14px; height: 14px; display: block; }

.drawer-section .link {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 10px; border-radius: 8px; cursor: pointer; font-size: 14px;
}
.drawer-section .link:hover { background: var(--hover); }
.drawer-section .link svg { width: 18px; height: 18px; }

/* ===== Layout ===== */
.layout {
  display: flex;
  flex: 1;
  min-height: 0;
}
.main {
  position: relative;
  overflow: hidden;
  background: var(--bg);
  flex: 1;
  min-width: 0;
  min-height: 0;
}

/* === Month view === */
.month {
  display: grid; grid-template-rows: auto 1fr;
  height: 100%;
}
.month .weekdays {
  display: grid; grid-template-columns: repeat(7, 1fr);
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
}
.month .weekdays div {
  text-align: center; padding: 8px 0;
  font-size: 11px; color: var(--text-dim); text-transform: uppercase; font-weight: 600;
}
.month .grid {
  display: grid; grid-template-columns: repeat(7, 1fr);
  grid-auto-rows: 1fr;
  overflow: hidden;
}
.month .cell {
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 4px 5px;
  min-height: 0;
  overflow: hidden;
  position: relative;
  cursor: pointer;
  display: flex; flex-direction: column;
}
.month .cell:hover { background: var(--hover); }
.month .cell.other { opacity: .35; }
.month .cell .daynum {
  font-size: 13px; font-weight: 500;
  margin-bottom: 2px;
}
.month .cell.today .daynum {
  background: var(--accent); color: white;
  width: 26px; height: 26px; line-height: 26px;
  text-align: center; border-radius: 50%; font-weight: 600;
}
.month .cell .evts { display: flex; flex-direction: column; gap: 2px; min-height: 0; overflow: hidden; }
.month .cell .ev {
  font-size: 11px;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--accent);
  color: white;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  border-left: 3px solid rgba(0,0,0,.25);
}
.month .cell .more { font-size: 10px; color: var(--text-dim); padding-left: 4px; }

/* === Week / Day / 3-day views === */
.week, .day, .multi {
  display: grid; grid-template-rows: auto auto 1fr;
  height: 100%;
  min-height: 0;
}
.week .head, .day .head, .multi .head {
  display: grid;
  background: var(--bg-elev); border-bottom: 1px solid var(--border);
}
.week .head .col, .day .head .col, .multi .head .col {
  text-align: center;
  padding: 8px 4px;
  cursor: pointer;
}
.week .head .col .wday, .day .head .col .wday, .multi .head .col .wday { font-size: 10px; color: var(--text-dim); text-transform: uppercase; }
.week .head .col .num, .day .head .col .num, .multi .head .col .num { font-size: 20px; font-weight: 600; line-height: 1.2; }
.week .head .col.today .num, .day .head .col.today .num, .multi .head .col.today .num {
  background: var(--accent); color: white; border-radius: 50%;
  width: 32px; height: 32px; line-height: 32px; margin: 0 auto;
  font-size: 14px;
}

.timegrid-scroll {
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.timegrid {
  --hour-h: 56px;
  position: relative;
  display: grid;
}
.timegrid .hour-col {
  border-right: 1px solid var(--border);
}
.timegrid .hour-col .hour-label {
  height: var(--hour-h);
  text-align: right;
  padding: 0 6px;
  font-size: 10px;
  color: var(--text-dim);
  position: relative;
  top: -7px;
}
.timegrid .day-col {
  position: relative;
  border-right: 1px solid var(--border);
}
.timegrid .day-col .slot {
  height: var(--hour-h);
  border-bottom: 1px solid var(--border);
}
.timegrid .day-col.today { background: var(--today-bg); }
.timegrid .ev-block {
  position: absolute;
  left: 1px; right: 1px;
  background: var(--accent); color: white;
  border-radius: 6px;
  padding: 2px 5px;
  font-size: 12px;
  overflow: hidden;
  cursor: grab;
  border-left: 2px solid rgba(0,0,0,.3);
  z-index: 2;
  /* none statt manipulation: verhindert dass iOS den Touch klaut, sobald Scrollen erkannt wird.
     Folge: man scrollt das Raster nicht mehr, indem man auf einem Termin startet — sondern nur
     auf freien Slots. Im Gegenzug: Long-Press-Drag funktioniert zuverlässig. */
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  transition: box-shadow .15s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}
@media (hover: none) and (pointer: coarse) {
  .timegrid .ev-block { cursor: pointer; }
}
.timegrid .ev-block.pressing {
  animation: evPress 400ms ease-out forwards;
}
@keyframes evPress {
  0%   { transform: scale(1); box-shadow: none; }
  100% { transform: scale(1.04); box-shadow: 0 6px 18px rgba(0,0,0,0.3); }
}
.timegrid .ev-block.dragging {
  opacity: 0.94;
  box-shadow: 0 14px 32px rgba(0,0,0,0.45);
  z-index: 20;
  cursor: grabbing;
  transition: none;
  animation: none;
  transform: scale(1.04);
}
.timegrid .ev-block.ghost {
  background: var(--accent);
  opacity: 0.55;
  border: 2px dashed rgba(255,255,255,0.85);
  border-left-width: 3px;
  pointer-events: none;
  z-index: 18;
  cursor: ns-resize;
}
.timegrid .day-col .slot { cursor: cell; }
/* Uhrzeit standardmäßig ausgeblendet — links steht ja schon die Stundenachse.
   Während des Drags wird sie kurz eingeblendet als Feedback wohin man zieht. */
.timegrid .ev-block .t { display: none; opacity: .85; font-size: 10px; }
.timegrid .ev-block.dragging .t,
.timegrid .ev-block.pressing .t { display: block; }
.timegrid .ev-block .title {
  font-weight: 500;
  line-height: 1.15;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  word-break: normal;
  overflow-wrap: break-word;
  -webkit-hyphens: none;
  hyphens: none;
}
.alarm-tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent-hover, var(--accent));
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  border-radius: 999px;
  padding: 1px 8px;
  margin-left: 4px;
  vertical-align: middle;
  white-space: nowrap;
}
.timegrid .ev-block .ev-alarm {
  position: absolute;
  top: 1px; right: 3px;
  font-size: 11px;
  line-height: 1;
  pointer-events: none;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,.4));
}
.timegrid .now-line {
  position: absolute; left: 0; right: 0;
  height: 2px; background: var(--danger);
  z-index: 5;
}
.timegrid .now-line::before {
  content: ""; position: absolute; left: -4px; top: -3px;
  width: 8px; height: 8px; border-radius: 50%; background: var(--danger);
}

/* All-day row in week/day */
.allday-row {
  display: grid;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev2);
  min-height: 24px;
}
.allday-row .label { font-size: 10px; color: var(--text-dim); padding: 4px 6px; text-align: right; }
.allday-row .cell-wrap { padding: 3px; display: flex; flex-direction: column; gap: 2px; }
.allday-row .ev {
  font-size: 11px; background: var(--accent); color: white;
  border-radius: 4px; padding: 2px 6px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  cursor: pointer;
}

/* === Agenda === */
.agenda { overflow-y: auto; padding: 14px 16px; height: 100%; }
.agenda .grp { margin-bottom: 18px; }
.agenda .grp h4 {
  margin: 0 0 8px; font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px;
  position: sticky; top: 0; background: var(--bg); padding: 6px 0;
}
.agenda .item {
  display: flex; gap: 10px; padding: 12px;
  border-radius: var(--radius-sm); background: var(--bg-elev); margin-bottom: 8px;
  cursor: pointer; border-left: 4px solid var(--accent);
}
.agenda .item:hover { background: var(--bg-elev2); }
.agenda .item .time { font-size: 12px; color: var(--text-dim); min-width: 90px; }
.agenda .item .body { flex: 1; }
.agenda .item .title { font-weight: 500; }
.agenda .item .loc { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

/* === FAB === */
.fab {
  position: fixed; right: 18px;
  bottom: calc(18px + var(--safe-bottom));
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--accent); color: white;
  display: grid; place-items: center;
  box-shadow: var(--shadow);
  z-index: 30;
  font-size: 28px; line-height: 1;
  transition: transform .15s;
}
.fab:active { transform: scale(.95); }

/* === Modal === */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  display: none;
  z-index: 100;
}
.modal-backdrop.open { display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal {
  background: var(--bg-elev); border-radius: var(--radius);
  width: 100%; max-width: 480px;
  max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
}
.modal-header {
  display: flex; align-items: center; gap: 8px; padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; flex: 1; font-size: 17px; }
.modal-header .x { width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center; }
.modal-header .x:hover { background: var(--hover); }
.modal-body { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.modal-body label { font-size: 12px; color: var(--text-dim); display: block; margin-bottom: 4px; }
.modal-body .row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.modal-body .row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.dt-row { display: grid; grid-template-columns: 2fr 1fr; gap: 8px; }
.time-input { text-align: center; font-variant-numeric: tabular-nums; letter-spacing: 1px; }
input[type="time"].time-input {
  font-size: 16px;
  cursor: pointer;
  padding: 12px 10px;
  background: var(--bg-elev2);
}
input[type="time"].time-input::-webkit-calendar-picker-indicator {
  filter: invert(0.7);
  cursor: pointer;
  opacity: 0.7;
  margin-left: 6px;
}
:root.theme-light input[type="time"].time-input::-webkit-calendar-picker-indicator {
  filter: none;
}
@media (prefers-color-scheme: light) {
  :root.theme-auto input[type="time"].time-input::-webkit-calendar-picker-indicator {
    filter: none;
  }
}
input[type="time"].time-input::-webkit-datetime-edit { padding: 0; }
input[type="time"].time-input::-webkit-inner-spin-button { display: none; }
input[type="time"].time-input::-webkit-clear-button { display: none; }
.date-field { position: relative; }
.date-field .date-display {
  display: block;
  background: var(--bg-elev2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font: inherit;
  min-height: 42px;
  box-sizing: border-box;
  line-height: 1.4;
}
.date-field input[type="date"] {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  opacity: 0;
  border: 0; padding: 0; margin: 0;
  cursor: pointer;
  z-index: 1;
  color: transparent;
}
.date-field input[type="date"]::-webkit-calendar-picker-indicator {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  cursor: pointer;
  opacity: 0;
}
.autocomplete-wrap { position: relative; }
.loc-row { display: flex; gap: 8px; align-items: stretch; }
.loc-row #f-location { flex: 1; }
.loc-nav-btn {
  flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px;
  background: var(--accent, #3b82f6);
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}
.loc-nav-btn svg { width: 20px; height: 20px; }
.loc-nav-btn:disabled { opacity: .4; cursor: default; }
/* Event-Detail-Karte */
.detail-card { max-width: 440px; }
.detail-top { display: flex; justify-content: flex-end; align-items: center; gap: 2px; padding: 8px 8px 0; }
.detail-head { display: flex; align-items: flex-start; gap: 12px; padding: 4px 20px 14px; }
.detail-color { flex: 0 0 auto; width: 16px; height: 16px; border-radius: 4px; margin-top: 5px; background: var(--accent, #3b82f6); }
.detail-title { margin: 0; font-size: 21px; line-height: 1.3; word-break: break-word; }
.detail-rows { padding: 0 20px 8px; display: flex; flex-direction: column; gap: 16px; }
.detail-row { display: flex; gap: 14px; align-items: flex-start; }
.detail-ic { flex: 0 0 auto; width: 20px; height: 20px; color: var(--text-dim); margin-top: 1px; }
.detail-row > div { flex: 1; min-width: 0; word-break: break-word; white-space: pre-wrap; line-height: 1.45; }
.detail-row a { color: var(--accent, #3b82f6); }
.detail-loc { display: flex; align-items: center; gap: 10px; }
.detail-loc #d-loc { flex: 1; }
.detail-loc .loc-nav-btn { width: 38px; height: 34px; }
.detail-footer { padding: 10px 20px 18px; display: flex; justify-content: flex-end; }
.autocomplete-list {
  position: absolute;
  top: 100%; left: 0; right: 0;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-top: 4px;
  z-index: 10;
  max-height: 240px;
  overflow-y: auto;
  display: none;
  box-shadow: var(--shadow);
}
.autocomplete-list.open { display: block; }
.autocomplete-item {
  padding: 10px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: flex-start; gap: 10px;
}
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover, .autocomplete-item.active { background: var(--hover); }
.autocomplete-item .pin {
  width: 18px; height: 18px; flex: 0 0 18px;
  color: var(--accent); margin-top: 1px;
}
.autocomplete-item .text { flex: 1; min-width: 0; }
.autocomplete-item .main { font-size: 14px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.autocomplete-item .secondary { font-size: 12px; color: var(--text-dim); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.autocomplete-empty { padding: 12px; font-size: 13px; color: var(--text-dim); text-align: center; }

.modal-body .check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.modal-body .check input { width: auto; }
.modal-footer { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); }
.modal-footer button {
  flex: 1; padding: 12px; border-radius: 10px; font-weight: 500;
  background: var(--bg-elev2); color: var(--text);
}
.modal-footer button.primary { background: var(--accent); color: white; }
.modal-footer button.danger { background: var(--danger); color: white; flex: 0 0 auto; padding: 12px 14px; }

.color-picker { display: flex; gap: 8px; flex-wrap: wrap; }
.color-picker .swatch {
  width: 28px; height: 28px; border-radius: 50%; cursor: pointer;
  border: 2px solid transparent;
}
.color-picker .swatch.active { border-color: var(--text); }

/* === Quick add (command) === */
.quickbar {
  display: none;
  position: fixed; top: 0; left: 0; right: 0;
  padding: calc(12px + var(--safe-top)) 14px 12px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  z-index: 90;
  align-items: center; gap: 8px;
}
.quickbar.open { display: flex; }
.quickbar input { background: var(--bg-elev2); }
.quickbar .preview {
  position: fixed; top: calc(60px + var(--safe-top)); left: 14px; right: 14px;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 12px; font-size: 13px; color: var(--text-dim);
  z-index: 90;
  display: none;
}
.quickbar.open + .preview { display: block; }

/* === Settings page === */
.settings { padding: 16px; overflow-y: auto; height: 100%; }
.settings h3 { margin-top: 18px; margin-bottom: 8px; font-size: 14px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px; }
.settings .card {
  background: var(--bg-elev); border-radius: var(--radius); padding: 14px; margin-bottom: 10px;
}
.settings code { background: var(--bg-elev2); padding: 2px 6px; border-radius: 4px; font-size: 12px; word-break: break-all; }
.settings pre { background: var(--bg-elev2); padding: 10px; border-radius: 8px; overflow-x: auto; font-size: 12px; }
.settings .key-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: 13px; }
.settings .key-row code { flex: 1; }
.settings .btn {
  background: var(--accent); color: white; padding: 8px 14px; border-radius: 8px; font-size: 13px; font-weight: 500;
}
.settings .btn.secondary { background: var(--bg-elev2); color: var(--text); }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(90px + var(--safe-bottom));
  background: var(--bg-elev); border: 1px solid var(--border);
  padding: 10px 16px; border-radius: 24px; font-size: 13px;
  box-shadow: var(--shadow); z-index: 200;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Mini-month navigator inside drawer */
.mini-month { padding: 0 14px 14px; }
.mini-month .mini-head { display: flex; justify-content: space-between; align-items: center; padding: 6px 4px; }
.mini-month .mini-head .lbl { font-size: 13px; font-weight: 600; }
.mini-month .mini-head button { padding: 4px 8px; border-radius: 6px; }
.mini-month .grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; font-size: 12px; }
.mini-month .grid .wd { color: var(--text-dim); text-align: center; padding: 4px 0; font-size: 10px; }
.mini-month .grid .d { text-align: center; padding: 5px 0; border-radius: 50%; cursor: pointer; }
.mini-month .grid .d:hover { background: var(--hover); }
.mini-month .grid .d.other { opacity: .3; }
.mini-month .grid .d.today { background: var(--accent); color: white; font-weight: 600; }
.mini-month .grid .d.has::after {
  content: ""; display: block; width: 4px; height: 4px; border-radius: 50%;
  background: var(--accent); margin: 0 auto;
}

/* ===== Quick-Create Popup (Google-Calendar-Style bottom sheet) ===== */
.qc {
  display: none;
  position: fixed; left: 0; right: 0; bottom: 0;
  z-index: 150;
  pointer-events: none; /* let upper grid receive events; panel re-enables */
}
.qc.open { display: block; }

.qc-panel {
  pointer-events: auto;
  background: var(--bg-elev);
  border-radius: 24px 24px 0 0;
  padding: 8px 20px calc(16px + var(--safe-bottom));
  box-shadow: 0 -10px 30px rgba(0,0,0,0.4);
  display: flex; flex-direction: column; gap: 10px;
  animation: qcSlideUp .2s ease-out;
  max-width: 680px;
  margin: 0 auto;
}
@keyframes qcSlideUp {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}
.qc-handle {
  width: 80px; height: 4px;
  background: var(--border);
  background-clip: content-box;
  border-radius: 2px;
  margin: 0 auto;
  padding: 14px 30px;
  box-sizing: content-box;
  cursor: ns-resize;
  touch-action: none;
}
.qc-bar {
  display: flex; justify-content: space-between; align-items: center;
}
.qc-x {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 50%;
  color: var(--text);
}
.qc-x:hover { background: var(--hover); }
.qc-x svg { width: 22px; height: 22px; }
.qc-save-btn {
  background: var(--accent); color: white;
  padding: 10px 22px;
  border-radius: 24px;
  font-weight: 600;
  font-size: 15px;
}
.qc-save-btn:active { transform: scale(0.97); }
#qc-title {
  background: transparent;
  border: 0;
  padding: 6px 0;
  font-size: 22px;
  font-weight: 400;
  width: 100%;
  outline: none;
}
#qc-title::placeholder { color: var(--text-dim); }
.qc-when-line {
  font-size: 15px;
  color: var(--text-dim);
  display: flex; gap: 6px; align-items: center; flex-wrap: wrap;
}
.qc-when-line .qc-dot { color: var(--text-dim); }
.qc-when-line .qc-dash { color: var(--text-dim); }
.qc-time-inline {
  background: transparent !important;
  border: 0 !important;
  padding: 2px 4px !important;
  width: auto !important;
  font-size: 15px;
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
  letter-spacing: 0 !important;
  text-align: left !important;
  border-radius: 6px !important;
}
.qc-time-inline:hover { background: var(--hover) !important; }
.qc-time-inline::-webkit-calendar-picker-indicator { display: none; }
.qc-time-inline::-webkit-inner-spin-button { display: none; }
.qc-details-btn {
  align-self: flex-start;
  font-size: 13px;
  color: var(--accent);
  padding: 6px 0;
  margin-top: -2px;
}

/* === Ghost rectangle (drag-create preview on time grid) === */
.qc-ghost {
  position: absolute;
  left: 4px; right: 4px;
  background: rgba(99, 102, 241, 0.15);
  border: 2px solid var(--accent);
  border-radius: 8px;
  z-index: 60;
  touch-action: none;
  cursor: grab;
  box-sizing: border-box;
}
.qc-ghost-handle {
  position: absolute;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--bg);
  z-index: 61;
  touch-action: none;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}
.qc-h-start { top: -10px; left: -10px; cursor: nw-resize; }
.qc-h-end   { bottom: -10px; right: -10px; cursor: se-resize; }

@media (max-width: 919px) {
  /* keep bottom-bar visible underneath (or hide while qc open) */
  .qc.open ~ .bottombar,
  body:has(.qc.open) .bottombar { display: none; }
}

/* ===== Bottom bar (mobile) ===== */
.bottombar {
  display: none;
  position: fixed; left: 0; right: 0; bottom: 0;
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
  padding: 4px 4px calc(4px + var(--safe-bottom));
  z-index: 60;
}
.bottombar button {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  padding: 6px 4px;
  border-radius: 10px;
  color: var(--text-dim);
  min-height: 48px;
}
.bottombar button svg { width: 22px; height: 22px; stroke-width: 1.8; }
.bottombar button span { font-size: 10px; font-weight: 500; }
.bottombar button.active { color: var(--accent); }
.bottombar button.active svg { color: var(--accent); }

/* ===== Auth overlay ===== */
.auth-overlay {
  position: fixed; inset: 0;
  background: var(--bg);
  display: none;
  align-items: center; justify-content: center;
  z-index: 300;
  padding: 20px;
  padding-top: calc(20px + var(--safe-top));
  padding-bottom: calc(20px + var(--safe-bottom));
}
.auth-overlay.open { display: flex; }
.auth-card {
  width: 100%; max-width: 380px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 10px;
}
.auth-card .auth-logo {
  align-self: center;
  width: 64px; height: 64px;
  background: var(--accent); color: white;
  border-radius: 16px;
  display: grid; place-items: center;
  margin-bottom: 6px;
}
.auth-card .auth-logo svg { width: 32px; height: 32px; }
.auth-card h2 { margin: 0; text-align: center; font-size: 20px; }
.auth-card .auth-sub { margin: 0 0 6px; text-align: center; font-size: 13px; color: var(--text-dim); }
.auth-card label { font-size: 12px; color: var(--text-dim); margin-bottom: 4px; display: block; }
.auth-card .auth-row { display: flex; flex-direction: column; }
.auth-card .auth-err { color: var(--danger); font-size: 13px; min-height: 18px; }
.auth-card .auth-submit {
  background: var(--accent); color: white;
  padding: 12px; border-radius: 10px; font-weight: 600;
  margin-top: 4px;
}
.auth-card .auth-submit:active { background: var(--accent-hover); }
.auth-card .auth-hint { font-size: 12px; color: var(--text-dim); margin: 6px 0 0; }

.form-grid { display: flex; flex-direction: column; gap: 8px; }

@media (max-width: 720px) {
  .topbar .view-switch button { padding: 6px 8px; font-size: 12px; }
  .topbar .title { font-size: 16px; }
  .week .head .col .num, .day .head .col .num { font-size: 16px; }
  .month .cell .ev { font-size: 10px; }

  /* show bottom bar */
  .bottombar { display: flex; }
  .app { padding-bottom: calc(var(--safe-bottom) + 64px); }
  .fab {
    bottom: calc(78px + var(--safe-bottom));
  }
  .toast {
    bottom: calc(110px + var(--safe-bottom));
  }

  /* mobile: ganze "Ansicht"-Sektion ausblenden — Bottom-Bar erfüllt diesen Zweck */
  .drawer-views { display: none; }

  /* full-screen modal on phones */
  .modal-backdrop.open { padding: 0; align-items: stretch; }
  .modal {
    max-width: none;
    max-height: 100dvh;
    height: 100dvh;
    width: 100%;
    border-radius: 0;
    padding-top: var(--safe-top);
    padding-bottom: var(--safe-bottom);
  }
  .modal-body { flex: 1; overflow-y: auto; }
  .modal-footer { padding: 14px 16px calc(14px + var(--safe-bottom)); }
  .modal-footer button { padding: 14px; font-size: 15px; }

  /* time grid: kompakteres Stundenraster, mehr Überblick */
  .timegrid { --hour-h: 32px; }
  .timegrid .ev-block {
    font-size: 10px;
    padding: 1px 3px;
    line-height: 1.1;
    border-left-width: 2px;
  }
  .timegrid .ev-block .t { font-size: 9px; }
  .timegrid .ev-block .title {
    font-size: 9px;
    line-height: 1.1;
    -webkit-line-clamp: 4;
  }
  .timegrid .hour-col .hour-label { font-size: 10px; top: -6px; }

  /* visual feedback for long-press */
  .timegrid .day-col.lp-active { background: var(--today-bg); }

  /* allday row taller on mobile */
  .allday-row { min-height: 30px; }
  .allday-row .ev { font-size: 12px; padding: 4px 6px; }

  /* hide quick search button on mobile topbar - in drawer instead */
  .topbar #btn-quick { display: grid; }
  .topbar #btn-today { display: grid; }
}

/* ===== Tablet / iPad portrait (721–919px) =====
   Vorher eine "tote Zone": die Bottom-Bar (≤720) war weg, die feste Seitenleiste
   (≥920) noch nicht da — Ansichtswechsel ging nur umständlich über den Drawer.
   iPad-Hochformat (768–834px) bekommt jetzt die Bottom-Navigation wie am Handy,
   aber mit den großzügigen, zentrierten Desktop-Modals. Querformat & 12,9" (≥920)
   behalten die feste Seitenleiste. */
@media (min-width: 721px) and (max-width: 919px) {
  .bottombar { display: flex; justify-content: center; }
  .bottombar button { flex: 0 1 132px; }
  .app { padding-bottom: calc(var(--safe-bottom) + 68px); }
  .fab { bottom: calc(82px + var(--safe-bottom)); }
  .toast { bottom: calc(120px + var(--safe-bottom)); }

  /* Ansichtswechsel übernimmt die Bottom-Bar -> doppelte Drawer-Sektion raus */
  .drawer-views { display: none; }

  /* Der Drawer hat hier mehr Platz */
  .drawer-inner { width: 60%; max-width: 360px; }

  /* Etwas größere Tap-Ziele in der Top-Leiste auf dem Tablet */
  .topbar .menu, .topbar .icon-btn { width: 42px; height: 42px; }
}

@media (min-width: 920px) {
  .drawer-inner { transform: none !important; }
  .drawer { position: relative; opacity: 1; pointer-events: auto; background: transparent; width: 280px; flex-shrink: 0; }
  .topbar .menu { display: none; }
  .bottombar { display: none !important; }
}

/* ===== Aufgaben (Tasks) ===== */
.qc-typeswitch { display: flex; gap: 6px; margin-bottom: 10px; }
.qc-typeswitch button {
  flex: 1; padding: 7px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: transparent;
  color: var(--text-dim); font-size: 14px; cursor: pointer;
}
.qc-typeswitch button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.qc-allday { display: none; align-items: center; gap: 8px; margin: 8px 0 2px; font-size: 14px; color: var(--text); }
.qc.task-mode .qc-allday { display: flex; }
.qc.task-mode #qc-end, .qc.task-mode .qc-dash { display: none; }
.qc.task-mode.allday .qc-dot,
.qc.task-mode.allday #qc-start,
.qc.task-mode.allday .qc-uhr { display: none; }

/* Checkbox auf Aufgaben-Kacheln */
.task-check {
  width: 13px; height: 13px;
  border: 1.5px solid currentColor; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 10px; line-height: 1; cursor: pointer;
  margin-right: 3px; vertical-align: -2px;
  background: rgba(255,255,255,.18);
}
.task-done { opacity: .55; }
.task-done .title { text-decoration: line-through; }
.task-done .task-check { background: rgba(255,255,255,.9); color: var(--accent); }
/* Liste: größere Checkbox als eigene Spalte */
.task-check-lg {
  width: 22px; height: 22px; font-size: 14px;
  margin-right: 0; vertical-align: 0; align-self: center;
  border-color: var(--text-dim);
}
.agenda .item.task-done { opacity: .55; }

/* ---------- Terminwecker (Alarm) ---------- */
.alarm-overlay {
  position: fixed; inset: 0; z-index: 4000;
  display: none; align-items: center; justify-content: center;
  background: rgba(8, 12, 24, 0.92);
  backdrop-filter: blur(6px);
  padding: 24px;
}
.alarm-overlay.open { display: flex; animation: alarm-fade .25s ease; }
@keyframes alarm-fade { from { opacity: 0; } to { opacity: 1; } }
.alarm-card {
  width: 100%; max-width: 420px; text-align: center;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 22px; padding: 34px 26px 26px;
  box-shadow: 0 24px 80px rgba(0,0,0,.55);
}
.alarm-bell {
  font-size: 64px; line-height: 1;
  animation: alarm-shake .9s ease-in-out infinite;
  transform-origin: 50% 10%;
}
@keyframes alarm-shake {
  0%, 100% { transform: rotate(0); }
  20% { transform: rotate(16deg); }
  40% { transform: rotate(-14deg); }
  60% { transform: rotate(10deg); }
  80% { transform: rotate(-8deg); }
}
.alarm-label {
  margin-top: 10px; font-size: 13px; letter-spacing: .12em;
  text-transform: uppercase; color: var(--accent-hover); font-weight: 700;
}
.alarm-title { margin: 8px 0 4px; font-size: 26px; word-break: break-word; }
.alarm-time { font-size: 18px; color: var(--text-dim); }
.alarm-sound { margin-top: 6px; font-size: 13px; color: var(--text-dim); }
.alarm-stop {
  display: block; width: 100%; margin-top: 26px;
  padding: 16px; border: none; border-radius: 14px;
  background: var(--danger); color: #fff; font-size: 18px; font-weight: 700;
  cursor: pointer;
}
.alarm-stop:active { transform: scale(.98); }
.alarm-snooze {
  display: block; width: 100%; margin-top: 10px;
  padding: 13px; border: 1px solid var(--border); border-radius: 14px;
  background: var(--bg-elev2); color: var(--text); font-size: 15px; cursor: pointer;
}

/* ---------- Wecker-Tab: Toggle-Switch ---------- */
.switch { position: relative; display: inline-block; width: 46px; height: 26px; flex: none; cursor: pointer; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span {
  position: absolute; inset: 0; border-radius: 26px;
  background: var(--bg-elev2); border: 1px solid var(--border); transition: background .15s;
}
.switch span::before {
  content: ''; position: absolute; left: 3px; top: 50%; transform: translateY(-50%);
  width: 18px; height: 18px; border-radius: 50%; background: var(--text-dim); transition: transform .15s, background .15s;
}
.switch input:checked + span { background: var(--accent); border-color: var(--accent); }
.switch input:checked + span::before { transform: translate(20px, -50%); background: #fff; }
