:root {
  --primary: #C084FC;
  --primary-dark: #7c5cbf;
  --bg: #09090B;
  --surface: #121214;
  --surface-var: #1E1E24;
  --outline: #27272A;
  --text: #F4F4F5;
  --text-dim: #A1A1AA;
  --text-faint: #71717A;
  --danger: #EF4444;
  --warn: #F59E0B;
  --ok: #10B981;
  --radius: 14px;
  --radius-sm: 10px;
}

[data-theme="light"] {
  --bg: #FFFFFF;
  --surface: #F9F9FB;
  --surface-var: #E4E4E7;
  --outline: #D4D4D8;
  --text: #18181B;
  --text-dim: #52525B;
  --text-faint: #71717A;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  overflow: hidden;
  overscroll-behavior: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* ========== TOP BAR ========== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--outline);
  flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--primary); flex-shrink: 0; }
.brand-name { font-weight: 700; font-size: 18px; }
.brand-sep { color: var(--text-dim); }
.brand-page { color: var(--text-dim); font-size: 14px; }
.topbar-actions { display: flex; align-items: center; gap: 6px; }

.btn-outline {
  background: transparent;
  border: 1px solid var(--outline);
  color: var(--primary);
  font-weight: 600;
  font-size: 13px;
  padding: 6px 14px;
  border-radius: 20px;
  cursor: pointer;
}
.btn-outline:active { background: var(--surface-var); }

.btn-text {
  background: transparent;
  border: none;
  color: var(--primary);
  font-weight: 600;
  font-size: 13px;
  padding: 6px 8px;
  cursor: pointer;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text);
  padding: 6px;
  cursor: pointer;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:active { background: var(--surface-var); }

/* ========== MAIN ========== */
#mainContent {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  padding-bottom: 100px;
  -webkit-overflow-scrolling: touch;
}

/* ========== BOTTOM NAV ========== */
.bottomnav {
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--outline);
  padding-bottom: env(safe-area-inset-bottom);
  flex-shrink: 0;
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 10px 4px;
  background: transparent;
  border: none;
  color: var(--text-faint);
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  transition: color .15s;
}
.tab.active { color: var(--primary); }
.tab.active svg { color: var(--primary); }

/* ========== FAB ========== */
.fab {
  position: fixed;
  bottom: calc(80px + env(safe-area-inset-bottom));
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 18px;
  background: var(--primary);
  color: var(--bg);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(0,0,0,.4), 0 2px 6px rgba(0,0,0,.3);
  cursor: pointer;
  z-index: 100;
}
.fab:active { transform: scale(.95); }

/* ========== DAY VIEW ========== */
.view-title {
  font-size: 20px;
  font-weight: 800;
  margin-bottom: 12px;
}

.day-scroller {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.day-scroller::-webkit-scrollbar { display: none; }

.day-chip {
  flex-shrink: 0;
  width: 58px;
  padding: 14px 0;
  border-radius: 16px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  scroll-snap-align: center;
  transition: background .15s;
}
.day-chip.today { background: var(--surface-var); }
.day-chip.selected { background: var(--primary); color: var(--bg); }
.day-chip .dname { font-size: 11px; font-weight: 700; opacity: .75; }
.day-chip .dnum { font-size: 18px; font-weight: 700; }

.divider {
  height: 1px;
  background: var(--outline);
  margin: 16px 0;
  opacity: .5;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.section-header .title { font-size: 14px; font-weight: 700; color: var(--text-dim); }
.section-header .count { font-size: 12px; color: var(--primary); font-weight: 600; }

/* ========== WEEK VIEW ========== */
.week-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.week-label {
  background: var(--surface-var);
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.week-nav { display: flex; gap: 4px; background: var(--surface-var); border-radius: 10px; padding: 2px; }
.week-nav button {
  background: transparent;
  border: none;
  color: var(--primary);
  padding: 6px 10px;
  cursor: pointer;
  border-radius: 8px;
  display: flex;
}
.week-nav button:active { background: var(--surface); }

.week-days {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 14px;
}
.week-day {
  padding: 8px 0;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
  transition: background .15s;
}
.week-day.today { background: var(--surface-var); }
.week-day.selected { background: var(--primary); color: var(--bg); }
.week-day .wname { font-size: 9px; font-weight: 700; opacity: .7; }
.week-day .wnum { font-size: 15px; font-weight: 700; }

/* ========== MONTH VIEW ========== */
.month-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.month-label {
  background: var(--surface-var);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
}
.month-nav { display: flex; gap: 4px; background: var(--surface-var); border-radius: 10px; padding: 2px; }
.month-nav button {
  background: transparent;
  border: none;
  color: var(--primary);
  padding: 6px 10px;
  cursor: pointer;
  border-radius: 8px;
  display: flex;
}

.month-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 6px;
}
.month-weekdays div {
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--primary);
  opacity: .8;
}
.month-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.month-cell {
  aspect-ratio: 1;
  border-radius: 10px;
  background: var(--surface-var);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  position: relative;
}
.month-cell.empty { background: transparent; cursor: default; }
.month-cell.has-event { background: color-mix(in srgb, var(--primary) 25%, var(--surface-var)); color: var(--primary); }
.month-cell.selected { background: var(--primary); color: var(--bg); }
.month-cell .dot { width: 4px; height: 4px; border-radius: 50%; background: var(--primary); }
.month-cell.selected .dot { background: var(--bg); }

/* ========== EVENT CARD ========== */
.event-card {
  display: flex;
  background: var(--surface-var);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 10px;
  cursor: pointer;
  transition: transform .1s;
}
.event-card:active { transform: scale(.99); }
.event-stripe { width: 4px; flex-shrink: 0; }
.event-body {
  flex: 1;
  padding: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.event-time {
  min-width: 95px;
  padding: 6px 4px;
  border-radius: 8px;
  text-align: center;
  font-size: 10px;
  font-weight: 700;
  flex-shrink: 0;
}
.event-info { flex: 1; min-width: 0; }
.event-info .title {
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.event-info .sub { font-size: 10px; font-weight: 500; }

/* ========== TASK CARD ========== */
.task-card {
  display: flex;
  background: var(--surface-var);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 10px;
  cursor: pointer;
}
.task-body {
  flex: 1;
  padding: 14px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.task-checkbox {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  margin-top: 2px;
  accent-color: var(--primary);
}
.task-info { flex: 1; min-width: 0; }
.task-head { display: flex; align-items: center; gap: 6px; margin-bottom: 2px; flex-wrap: wrap; }
.prio-badge {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}
.prio-A { background: var(--danger); }
.prio-B { background: var(--warn); }
.prio-C { background: #3B82F6; }
.task-subject { font-size: 12px; font-weight: 700; }
.task-title {
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 2px;
  word-break: break-word;
}
.task-title.done { text-decoration: line-through; color: var(--text-faint); }
.task-meta { font-size: 10px; color: var(--text-faint); }

/* ========== NOTE CARD ========== */
.note-card {
  background: var(--surface-var);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 10px;
  cursor: pointer;
  display: flex;
}
.note-body { flex: 1; padding: 14px; min-width: 0; }
.note-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
.note-title {
  font-size: 15px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.note-cat {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 6px;
  flex-shrink: 0;
}
.note-content {
  font-size: 13px;
  color: var(--text-dim);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 6px;
}
.note-date { font-size: 10px; color: var(--text-faint); }

/* ========== SECTION HEADER GROUP ========== */
.group-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 12px 0 6px;
}
.group-header .dot { width: 8px; height: 8px; border-radius: 50%; }
.group-header .label { font-size: 12px; font-weight: 700; }

/* ========== EMPTY STATE ========== */
.empty-state {
  text-align: center;
  padding: 40px 24px;
  color: var(--text-faint);
}
.empty-state .icon-circle {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--primary) 12%, transparent);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
  color: var(--primary);
  opacity: .8;
}
.empty-state h3 { font-size: 15px; font-weight: 600; margin-bottom: 4px; color: var(--text); }
.empty-state p { font-size: 12px; }

/* ========== MODAL ========== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 1000;
  animation: fadeIn .15s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--surface);
  border-radius: 18px;
  width: 100%;
  max-width: 520px;
  max-height: 85dvh;
  margin-bottom: env(safe-area-inset-bottom);
  display: flex;
  flex-direction: column;
  animation: slideUp .2s ease;
  overflow: hidden;
}
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.modal-header {
  padding: 20px 20px 12px;
  font-size: 18px;
  font-weight: 700;
  flex-shrink: 0;
}
.modal-body {
  padding: 0 20px 12px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  flex: 1;
  min-height: 0;
}

/* Sichtbarer "nach unten scrollen"-Hinweis */
.modal-body::after {
  content: '';
  display: block;
  height: 8px;
}
.modal-footer {
  padding: 12px 20px 20px;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-shrink: 0;
  flex-wrap: wrap;
}

/* ========== FORM ========== */
.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 14px;
}
.field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
}
.field input,
.field textarea,
.field select {
  background: var(--surface-var);
  border: 1px solid var(--outline);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  width: 100%;
  outline: none;
}
.field input:focus,
.field textarea:focus,
.field select:focus { border-color: var(--primary); }
.field textarea { resize: vertical; min-height: 80px; }

.field-row { display: flex; gap: 10px; }
.field-row > * { flex: 1; }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  font-size: 14px;
}
.checkbox-row input { width: auto; }

/* ========== BUTTONS ========== */
.btn {
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  font-family: inherit;
}
.btn-primary { background: var(--primary); color: var(--bg); }
.btn-primary:active { opacity: .85; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--outline);
  color: var(--text);
}
.btn-full { width: 100%; }

/* ========== CHIPS ========== */
.chip-group { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  padding: 6px 12px;
  border-radius: 20px;
  background: var(--surface-var);
  border: 1px solid transparent;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
}
.chip.selected { border-color: var(--primary); color: var(--primary); }

.color-swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  display: flex;
  align-items: center;
  justify-content: center;
}
.color-swatch.selected::after {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #fff;
}

/* ========== TOAST ========== */
.toast {
  position: fixed;
  bottom: calc(100px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-var);
  color: var(--text);
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(0,0,0,.3);
  z-index: 2000;
  animation: toastIn .2s ease;
  max-width: 90%;
  text-align: center;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 20px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ========== SEARCH ========== */
.search-box {
  position: relative;
  margin-bottom: 12px;
}
.search-box input {
  width: 100%;
  background: var(--surface-var);
  border: 1px solid var(--outline);
  border-radius: 10px;
  padding: 10px 12px 10px 38px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
}
.search-box svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-faint);
  pointer-events: none;
}

/* ========== MISC ========== */
.hidden { display: none !important; }
.text-dim { color: var(--text-dim); }
.text-faint { color: var(--text-faint); }

/* ========== RESPONSIVE ========== */
@media (min-width: 768px) {
  #mainContent { padding: 24px 32px 100px; max-width: 900px; margin: 0 auto; width: 100%; }
  .event-time { min-width: 110px; }
}

@media (max-height: 700px) {
  .modal-header { padding: 14px 20px 8px; font-size: 16px; }
  .field { margin-bottom: 10px; }
}