:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #1a2233;
  --muted: #6b7488;
  --border: #e3e7ef;
  --primary: #1E88E5;
  --danger: #e53935;
  --shadow: 0 2px 10px rgba(20,30,60,.08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151c; --card: #1b212c; --text: #e7ecf5; --muted: #93a0b5;
    --border: #2a323f; --shadow: 0 2px 12px rgba(0,0,0,.4);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  display: flex; flex-direction: column; min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}
.topbar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 12px 16px; background: var(--card); border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow); position: sticky; top: 0; z-index: 10;
  padding-top: calc(12px + env(safe-area-inset-top));
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo { font-size: 22px; }
.topbar h1 { font-size: 18px; margin: 0; font-weight: 700; }
.nav { display: flex; align-items: center; gap: 6px; }
.views { display: flex; gap: 4px; margin-left: auto; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--card); color: var(--text); font-size: 20px; cursor: pointer; line-height: 1;
}
.pill, .view-btn, .btn {
  border: 1px solid var(--border); background: var(--card); color: var(--text);
  padding: 7px 14px; border-radius: 9px; cursor: pointer; font-size: 14px;
}
.view-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; padding: 10px 16px 0; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; padding: 5px 12px;
  border-radius: 999px; border: 1px solid var(--border); background: var(--card);
  cursor: pointer; font-size: 13px; user-select: none;
}
.chip .dot { width: 11px; height: 11px; border-radius: 50%; }
.chip.off { opacity: .35; }
.chip .x { color: var(--muted); font-weight: 700; margin-left: 2px; }

.calendar { flex: 1; padding: 12px 16px 90px; }

/* Month grid */
.weekdays { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-bottom: 6px; }
.weekdays div { text-align: center; font-size: 12px; color: var(--muted); font-weight: 600; }
.month-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.day-cell {
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  min-height: 96px; padding: 6px; display: flex; flex-direction: column; gap: 3px; cursor: pointer;
}
.day-cell.other { opacity: .45; }
.day-cell.today { border-color: var(--primary); border-width: 2px; }
.day-num { font-size: 13px; font-weight: 600; align-self: flex-end; }
.ev {
  font-size: 11px; color: #fff; border-radius: 5px; padding: 2px 5px;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis; cursor: pointer;
}
.more { font-size: 10px; color: var(--muted); }
.ev.pending { opacity: .5; }
.btn.ok { background: #43A047; color: #fff; border-color: #43A047; }
.pending-note { color: #FB8C00; font-weight: 600; }

/* Week */
.week-grid { display: flex; flex-direction: column; gap: 8px; }
.week-day {
  background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
}
.week-day.today { border-color: var(--primary); }
.week-day h3 { margin: 0 0 8px; font-size: 14px; }
.week-day h3 .wd-date { color: var(--muted); font-weight: 500; }

/* List */
.list { display: flex; flex-direction: column; gap: 8px; }
.list-item {
  display: flex; gap: 12px; align-items: stretch; background: var(--card);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; cursor: pointer;
}
.list-item .bar { width: 5px; border-radius: 3px; }
.list-item .time { color: var(--muted); font-size: 13px; min-width: 88px; }
.list-item .ttl { font-weight: 600; }
.list-item .meta { color: var(--muted); font-size: 12px; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

.ev-row { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 4px 0; cursor: pointer; }
.ev-row .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.ev-row .t { color: var(--muted); min-width: 78px; }

/* FAB */
.fab {
  position: fixed; right: 20px; bottom: calc(20px + env(safe-area-inset-bottom));
  width: 56px; height: 56px; border-radius: 50%; border: none; background: var(--primary);
  color: #fff; font-size: 30px; box-shadow: var(--shadow); cursor: pointer; z-index: 20;
}

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(10,15,25,.5); display: flex;
  align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal.hidden, .toast.hidden, .hidden { display: none; }
.modal-card {
  background: var(--card); border-radius: 16px; padding: 20px; width: 100%; max-width: 440px;
  box-shadow: var(--shadow); max-height: 90vh; overflow: auto;
}
.modal-card h2 { margin: 0 0 14px; font-size: 18px; }
#eventForm label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
#eventForm input, #eventForm select, #eventForm textarea {
  width: 100%; margin-top: 4px; padding: 9px 10px; border: 1px solid var(--border);
  border-radius: 9px; background: var(--bg); color: var(--text); font-size: 15px;
}
.row-check { display: flex !important; align-items: center; gap: 8px; }
.row-check input { width: auto !important; margin: 0 !important; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.modal-actions { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.modal-actions .spacer { flex: 1; }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }

.day-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.day-head h2 { margin: 0; font-size: 18px; }
#dayList { margin-bottom: 12px; max-height: 60vh; overflow: auto; }
.hint { color: var(--muted); font-size: 13px; margin: 0 0 12px; }
/* Login-Bildschirm */
.auth { position: fixed; inset: 0; z-index: 100; background: var(--bg); display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card { background: var(--card); border: 1px solid var(--border); border-radius: 16px; padding: 28px 24px; width: 100%; max-width: 360px; box-shadow: var(--shadow); text-align: center; }
.auth-logo { font-size: 40px; margin-bottom: 6px; }
.auth-card h2 { margin: 0 0 4px; }
.auth-card form { text-align: left; margin-top: 14px; }
.auth-card label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.auth-card input { width: 100%; margin-top: 4px; padding: 11px 12px; border: 1px solid var(--border); border-radius: 9px; background: var(--bg); color: var(--text); font-size: 16px; }
.auth-err { color: var(--danger); font-size: 13px; min-height: 18px; margin-bottom: 8px; }
/* Konto-Box in Einstellungen */
.acct-box { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin-bottom: 16px; font-size: 14px; }
.acct-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.acct-actions .btn { padding: 7px 12px; font-size: 13px; }
.cal-list { display: flex; flex-direction: column; gap: 2px; max-height: 60vh; overflow: auto; margin-bottom: 12px; }
.cal-row {
  display: flex; align-items: center; gap: 10px; padding: 9px 8px; border-radius: 9px; cursor: pointer;
}
.cal-row:hover { background: var(--bg); }
.cal-row .dot { width: 13px; height: 13px; border-radius: 50%; flex: none; }
.cal-row .nm { flex: 1; font-size: 15px; }
.cal-row input { width: 20px; height: 20px; accent-color: var(--primary); }
.cal-row.off .nm { color: var(--muted); }
.cal-row .del, .cal-row .opts { background: none; border: none; cursor: pointer; font-size: 16px; opacity: .55; padding: 2px 4px; }
.cal-row .del:hover, .cal-row .opts:hover { opacity: 1; }
.cal-new { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
.cal-new input[type=color] { width: 38px; height: 38px; padding: 0; border: 1px solid var(--border); border-radius: 9px; background: var(--bg); cursor: pointer; flex: none; }
.cal-new input[type=text] { flex: 1; padding: 9px 10px; border: 1px solid var(--border); border-radius: 9px; background: var(--bg); color: var(--text); font-size: 15px; }
.cal-new .btn { font-size: 20px; line-height: 1; padding: 8px 16px; }

/* Erinnerungs-Auswahl im Termin-Formular */
.reminder { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; }
.rem-head { font-size: 13px; font-weight: 600; margin-bottom: 8px; }
.rem-sub { font-size: 12px; color: var(--muted); margin: 8px 0 6px; }
.rem-row { display: flex; flex-wrap: wrap; gap: 8px; }
.rem-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 11px; border: 1px solid var(--border);
  border-radius: 999px; font-size: 13px; cursor: pointer; background: var(--bg); color: var(--text); margin: 0 !important;
}
.rem-chip input { width: auto !important; margin: 0 !important; accent-color: var(--primary); }
.rem-chip:has(input:checked) { background: var(--primary); color: #fff; border-color: var(--primary); }

.toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%);
  background: #1a2233; color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 14px; z-index: 60; box-shadow: var(--shadow);
}
/* Tablet */
@media (max-width: 1024px) {
  .calendar { padding: 10px 12px 90px; }
  .day-cell { min-height: 84px; }
}

/* Handy */
@media (max-width: 600px) {
  .topbar { gap: 8px; padding: 10px 12px; padding-top: calc(10px + env(safe-area-inset-top)); }
  .topbar h1 { font-size: 16px; }
  .brand { flex: 1; }
  .views { width: 100%; order: 3; justify-content: space-between; }
  .view-btn { flex: 1; text-align: center; padding: 8px 6px; }
  #settingsBtn { flex: 0 0 auto; }
  .nav .pill, .icon-btn { min-height: 38px; }

  /* Filter-Chips horizontal scrollen statt umbrechen */
  .filters { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px; }
  .chip { flex: 0 0 auto; }

  /* Monatsansicht: Termine als farbige Punkte statt Text (kompakt) */
  .calendar { padding: 8px 8px 90px; }
  .month-grid, .weekdays { gap: 3px; }
  .day-cell { min-height: 52px; padding: 3px; gap: 2px; }
  .day-num { font-size: 12px; }
  .day-cell .ev {
    font-size: 0; height: 8px; width: 8px; min-width: 8px; padding: 0; border-radius: 50%;
    display: inline-block; margin: 1px;
  }
  .day-cell .more { display: none; }

  .grid2 { grid-template-columns: 1fr; }
  .modal { padding: 0; align-items: flex-end; }
  .modal-card { max-width: 100%; border-radius: 18px 18px 0 0; max-height: 92vh; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }
  #eventForm input, #eventForm select, #eventForm textarea { font-size: 16px; } /* verhindert iOS-Zoom */
  .fab { width: 60px; height: 60px; font-size: 32px; }
}
