/* =========================================================
   Design Tokens
   ========================================================= */
:root {
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI",
          Roboto, Helvetica, Arial, sans-serif;

  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --radius-xl: 24px;

  --transition: 160ms ease;

  /* Safe Areas */
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left:   env(safe-area-inset-left, 0px);
  --safe-right:  env(safe-area-inset-right, 0px);

  --tabbar-h: 62px;

  /* Dark (Standard) */
  --bg-app:      #0f1115;
  --bg-surface:  #161922;
  --bg-elevated: #1c2029;
  --bg-hover:    #222634;
  --bg-active:   #2a2f40;

  --border:      #262b38;
  --border-soft: #1e2230;

  --text-1: #eef0f5;
  --text-2: #9aa0b0;
  --text-3: #6a7082;

  --accent:       #7b8cff;
  --accent-hover: #8f9eff;
  --accent-soft:  rgba(123, 140, 255, 0.14);
  --accent-text:  #ffffff;

  --danger:       #ff6b7a;
  --danger-soft:  rgba(255, 107, 122, 0.12);

  --cal-private:  #7b8cff;
  --cal-work:     #a78bfa;
  --cal-reminder: #f472b6;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.5);
}

[data-theme="light"] {
  --bg-app:      #f4f5f8;
  --bg-surface:  #ffffff;
  --bg-elevated: #ffffff;
  --bg-hover:    #f0f1f5;
  --bg-active:   #e6e8ef;

  --border:      #e2e4ec;
  --border-soft: #ebedf3;

  --text-1: #14161c;
  --text-2: #5a6070;
  --text-3: #8b90a0;

  --accent-soft: rgba(123, 140, 255, 0.12);

  --shadow-sm: 0 1px 2px rgba(20, 30, 60, 0.06);
  --shadow-md: 0 4px 14px rgba(20, 30, 60, 0.08);
  --shadow-lg: 0 18px 48px rgba(20, 30, 60, 0.16);
}

/* =========================================================
   Reset & App-Grundverhalten
   ========================================================= */
* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;

  overscroll-behavior: none;
  -webkit-overflow-scrolling: auto;

  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;

  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;

  -webkit-tap-highlight-color: transparent;

  position: fixed;
  inset: 0;
  width: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font);
  color: var(--text-1);
  background: var(--bg-app);
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
input, textarea, select { outline: none; }

input, textarea, [contenteditable] {
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}

img, svg { -webkit-user-drag: none; user-select: none; }

button {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

::selection { background: var(--accent-soft); color: var(--text-1); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb {
  background: var(--border); border-radius: 999px;
  border: 2px solid var(--bg-app);
}
::-webkit-scrollbar-thumb:hover { background: var(--bg-active); }
::-webkit-scrollbar-track { background: transparent; }

/* iOS Edge-Swipe-Blocker – per JS nur im Standalone-Modus aktiviert */
.edge-block {
  position: fixed;
  top: 0; bottom: 0;
  width: 20px;
  z-index: 9999;
  background: transparent;
  pointer-events: auto;
}
.edge-block.left  { left: 0; }
.edge-block.right { right: 0; }

/* =========================================================
   Layout (Desktop)
   ========================================================= */
.app {
  display: grid;
  grid-template-columns: 248px 1fr;
  gap: 14px;
  padding: 14px;
  height: 100dvh;
}

/* =========================================================
   Sidebar
   ========================================================= */
.sidebar {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow-y: auto;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 2px 6px 0; }
.brand-logo {
  width: 24px; height: 24px; border-radius: 7px;
  background: linear-gradient(135deg, var(--accent), var(--cal-work));
}
.brand-name { font-weight: 600; font-size: 15px; letter-spacing: 0.1px; }

.btn-primary {
  padding: 11px 14px;
  border-radius: var(--radius-md);
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  font-size: 14px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: background var(--transition);
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { transform: scale(0.98); }
.icon-plus { font-size: 17px; line-height: 1; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-size: 13.5px;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.nav-item:hover { background: var(--bg-hover); color: var(--text-1); }
.nav-item.active { background: var(--bg-active); color: var(--text-1); font-weight: 500; }

.side-section { display: flex; flex-direction: column; gap: 4px; margin-top: 2px; }
.side-title {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 1.3px;
  color: var(--text-3); padding: 0 8px 6px; font-weight: 600;
}

.cal-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  font-size: 13.5px; color: var(--text-2);
  cursor: pointer; transition: background var(--transition);
}
.cal-item:hover { background: var(--bg-hover); }
.cal-item input { accent-color: var(--accent); }
.cal-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }

.side-footer { margin-top: auto; display: flex; justify-content: flex-end; padding-top: 8px; }

.btn-ghost {
  padding: 8px 13px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-2);
  font-size: 13px;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-1); border-color: var(--bg-active); }

.btn-icon {
  width: 34px; height: 34px; border-radius: var(--radius-sm);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 18px; color: var(--text-2);
  background: transparent;
  border: 1px solid var(--border);
  transition: background var(--transition), color var(--transition);
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text-1); }

/* =========================================================
   Main
   ========================================================= */
.main { display: flex; flex-direction: column; gap: 14px; min-width: 0; min-height: 0; }

.topbar {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 10px 14px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px;
}
.topbar-left  { display: flex; align-items: center; gap: 8px; min-width: 0; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.title {
  font-size: 17px; font-weight: 600; margin: 0 0 0 6px;
  letter-spacing: 0.1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.segmented {
  display: inline-flex; padding: 3px;
  background: var(--bg-app);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.segmented button {
  padding: 6px 12px;
  border-radius: calc(var(--radius-md) - 3px);
  font-size: 12.5px;
  color: var(--text-2);
  transition: background var(--transition), color var(--transition);
}
.segmented button:hover { color: var(--text-1); }
.segmented button.active {
  background: var(--bg-elevated);
  color: var(--text-1);
  box-shadow: var(--shadow-sm);
}

/* =========================================================
   View-Container
   ========================================================= */
.view {
  flex: 1; min-height: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  overflow: hidden;
  display: flex; flex-direction: column;
}

/* =========================================================
   Monatsansicht
   ========================================================= */
.month-head {
  display: grid; grid-template-columns: repeat(7, 1fr);
  padding: 14px 8px 10px;
  font-size: 11px; text-transform: uppercase; letter-spacing: 1.4px;
  color: var(--text-3); font-weight: 700;
  border-bottom: 1px solid var(--border-soft);
  background: var(--bg-surface);
}
.month-head span { text-align: center; }
.month-head span.is-weekend { color: var(--text-2); }

.month-grid {
  flex: 1; min-height: 0;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-template-rows: repeat(6, 1fr);
  overflow: hidden;
}

/* Ein Tag */
.day {
  position: relative;
  border-right: 1px solid var(--border-soft);
  border-bottom: 1px solid var(--border-soft);
  padding: 8px 8px 6px;
  display: flex; flex-direction: column; gap: 4px;
  cursor: pointer;
  transition: background var(--transition);
  overflow: hidden;
  min-height: 0;
}
.day:nth-child(7n) { border-right: none; }
.day:nth-last-child(-n+7) { border-bottom: none; }
.day:hover { background: var(--bg-hover); }
.day.other { background: rgba(0, 0, 0, 0.12); }
.day.other .day-num { color: var(--text-3); opacity: 0.6; }
.day.weekend { background: rgba(0, 0, 0, 0.08); }
.day.weekend.other { background: rgba(0, 0, 0, 0.16); }

/* Tagesnummer */
.day-num {
  align-self: flex-start;
  min-width: 24px; height: 24px; padding: 0 7px;
  border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12.5px; font-weight: 600;
  color: var(--text-2);
  transition: background var(--transition), color var(--transition);
}

.day.today .day-num {
  background: var(--accent);
  color: var(--accent-text);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* Ereignis-Container */
.day-events {
  display: flex; flex-direction: column; gap: 3px;
  overflow: hidden; min-height: 0;
}

/* Termin-Chip */
.event-chip {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px;
  padding: 3px 7px;
  border-radius: 6px;
  color: var(--text-1);
  background: var(--accent-soft);
  border-left: 2px solid var(--cal-private);
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
  overflow: hidden;
  white-space: nowrap;
}
.event-chip:hover {
  background: var(--bg-active);
  transform: translateX(1px);
}
.event-chip[data-cal="work"]     { border-left-color: var(--cal-work); }
.event-chip[data-cal="reminder"] { border-left-color: var(--cal-reminder); }

.event-chip-time {
  font-variant-numeric: tabular-nums;
  color: var(--text-2);
  font-weight: 600;
  flex-shrink: 0;
}
.event-chip-title {
  overflow: hidden; text-overflow: ellipsis;
  color: var(--text-1);
  font-weight: 500;
}
.event-chip.is-allday .event-chip-title {
  font-weight: 600;
}

/* "+N weitere" Chip */
.event-chip.is-more {
  background: transparent;
  border-left-color: transparent;
  color: var(--text-3);
  font-weight: 500;
  padding-left: 9px;
}
.event-chip.is-more:hover {
  color: var(--text-1);
  background: var(--bg-hover);
}

/* =========================================================
   Wochenansicht
   ========================================================= */
.week-grid {
  flex: 1; min-height: 0;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  overflow: hidden;
}

.week-col {
  display: flex; flex-direction: column;
  border-right: 1px solid var(--border-soft);
  min-width: 0;
  cursor: pointer;
  transition: background var(--transition);
}
.week-col:last-child { border-right: none; }
.week-col:hover { background: var(--bg-hover); }
.week-col.today { background: rgba(123, 140, 255, 0.035); }

.week-col-head {
  padding: 12px 12px 10px;
  border-bottom: 1px solid var(--border-soft);
  display: flex; flex-direction: column; gap: 2px;
}
.week-col-day {
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 1.1px;
  color: var(--text-3);
}
.week-col-date { font-size: 15px; font-weight: 600; color: var(--text-1); }
.week-col.today .week-col-date,
.week-col.today .week-col-day { color: var(--accent); }

.week-col-body {
  flex: 1; min-height: 0;
  padding: 10px;
  display: flex; flex-direction: column; gap: 6px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.week-empty {
  color: var(--text-3); font-size: 13px;
  text-align: center; padding: 12px 0; opacity: 0.5;
}

.week-card {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  border-left: 3px solid var(--cal-private);
  display: flex; flex-direction: column; gap: 3px;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
}
.week-card:hover { background: var(--bg-active); transform: translateX(2px); }
.week-card[data-cal="work"]     { border-left-color: var(--cal-work); }
.week-card[data-cal="reminder"] { border-left-color: var(--cal-reminder); }

.week-card-time {
  font-size: 10.5px; color: var(--text-3); font-weight: 500;
  letter-spacing: 0.2px;
}
.week-card-title {
  font-size: 13px; font-weight: 500; color: var(--text-1);
  overflow: hidden; text-overflow: ellipsis;
  display: -webkit-box; -webkit-box-orient: vertical;
}
.week-card-notes {
  font-size: 11.5px; color: var(--text-2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* =========================================================
   Tagesansicht
   ========================================================= */
.day-view { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.day-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border-soft);
  gap: 16px;
}
.day-header-info { min-width: 0; }
.day-header-weekday {
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 1.3px;
  color: var(--text-3);
}
.day-header-date {
  font-size: 20px; font-weight: 600;
  color: var(--text-1); margin-top: 3px;
}
.day-header.today .day-header-weekday,
.day-header.today .day-header-date { color: var(--accent); }

.day-body {
  flex: 1; min-height: 0;
  padding: 18px 22px 28px;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex; flex-direction: column; gap: 22px;
}

.day-group { display: flex; flex-direction: column; gap: 8px; }
.day-group-label {
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 1.2px;
  color: var(--text-3);
}
.day-group-items { display: flex; flex-direction: column; gap: 8px; }

.day-card {
  position: relative;
  display: grid;
  grid-template-columns: 130px 1fr 4px;
  gap: 16px;
  align-items: center;
  padding: 14px 16px 14px 18px;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  border-left: 3px solid transparent;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), transform var(--transition);
  overflow: hidden;
}
.day-card:hover {
  background: var(--bg-hover);
  border-color: var(--border);
  transform: translateY(-1px);
}
.day-card[data-cal="default"]  { border-left-color: var(--cal-private); }
.day-card[data-cal="work"]     { border-left-color: var(--cal-work); }
.day-card[data-cal="reminder"] { border-left-color: var(--cal-reminder); }

.day-card-time {
  display: flex; flex-direction: column; gap: 2px;
  font-size: 13px; color: var(--text-2);
}
.day-card-time-start { font-weight: 600; color: var(--text-1); }
.day-card-time-end   { font-size: 12px; }
.day-card-duration   { font-size: 11px; color: var(--text-3); letter-spacing: 0.2px; }
.day-card-allday {
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 1px;
  color: var(--accent);
}

.day-card-main { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.day-card-title {
  font-size: 14.5px; font-weight: 500;
  color: var(--text-1);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.day-card-notes {
  font-size: 12.5px; color: var(--text-2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.day-card-accent {
  width: 4px; height: 100%;
  border-radius: 999px;
  background: var(--cal-private);
  position: absolute; right: 12px; top: 12px; bottom: 12px;
}
.day-card-accent[data-cal="work"]     { background: var(--cal-work); }
.day-card-accent[data-cal="reminder"] { background: var(--cal-reminder); }

.day-empty {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 6px; color: var(--text-3);
  padding: 60px 20px;
  cursor: pointer; user-select: none;
}
.day-empty-icon { font-size: 32px; line-height: 1; opacity: 0.6; margin-bottom: 6px; }
.day-empty-text { font-size: 15px; color: var(--text-2); font-weight: 500; }
.day-empty-hint { font-size: 12.5px; color: var(--text-3); }

/* =========================================================
   Listenansicht (Termine)
   ========================================================= */
.list-view {
  flex: 1; min-height: 0;
  padding: 18px 22px 28px;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex; flex-direction: column; gap: 28px;
}

.list-bucket { display: flex; flex-direction: column; gap: 14px; }

.list-bucket-label {
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 1.4px;
  color: var(--accent);
  padding-left: 2px;
}

.list-bucket-days { display: flex; flex-direction: column; gap: 18px; }

.list-day { display: flex; flex-direction: column; gap: 8px; }

.list-day-head {
  display: flex; align-items: baseline; gap: 8px;
  padding-left: 2px;
}
.list-day-name {
  font-size: 13.5px; font-weight: 600;
  color: var(--text-2);
  letter-spacing: 0.1px;
}
.list-day.today .list-day-name { color: var(--accent); font-weight: 700; }

.list-day-count {
  font-size: 10.5px; color: var(--text-3);
  background: var(--bg-app);
  border: 1px solid var(--border-soft);
  padding: 1px 7px; border-radius: 999px;
  font-weight: 500;
}

.list-day-items {
  display: flex; flex-direction: column;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.list-event {
  position: relative;
  display: grid;
  grid-template-columns: 72px 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 14px 16px;
  cursor: pointer;
  transition: background var(--transition);
  border-bottom: 1px solid var(--border-soft);
}
.list-event:last-child { border-bottom: none; }
.list-event:active { background: var(--bg-hover); }
.list-event:hover  { background: var(--bg-hover); }

.list-event::before {
  content: "";
  position: absolute;
  left: 0; top: 12px; bottom: 12px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--cal-private);
}
.list-event[data-cal="work"]::before     { background: var(--cal-work); }
.list-event[data-cal="reminder"]::before { background: var(--cal-reminder); }

.list-event-time {
  font-size: 13px;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  padding-left: 4px;
}
.list-event-time.is-allday {
  font-size: 10.5px;
  color: var(--accent);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.list-event-main { min-width: 0; display: flex; flex-direction: column; }
.list-event-title {
  font-size: 14.5px;
  color: var(--text-1);
  font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.list-event-notes {
  font-size: 12.5px;
  color: var(--text-3);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  margin-top: 2px;
}

.list-event-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--cal-private);
}
.list-event-dot[data-cal="work"]     { background: var(--cal-work); }
.list-event-dot[data-cal="reminder"] { background: var(--cal-reminder); }

.list-empty {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 6px; color: var(--text-3);
  padding: 80px 20px; user-select: none;
}
.list-empty-icon { font-size: 36px; line-height: 1; opacity: 0.5; margin-bottom: 8px; }
.list-empty-text { font-size: 15px; color: var(--text-2); font-weight: 500; }
.list-empty-hint { font-size: 12.5px; color: var(--text-3); }

/* =========================================================
   Erinnerungen-Ansicht
   ========================================================= */
.reminders-view {
  flex: 1; min-height: 0;
  padding: 18px 22px 28px;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex; flex-direction: column; gap: 26px;
}

.reminders-bucket { display: flex; flex-direction: column; gap: 10px; }

.reminders-bucket-label {
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 1.4px;
  color: var(--accent);
  padding-left: 2px;
}

.reminders-items {
  display: flex; flex-direction: column;
  gap: 8px;
}

.reminder-row {
  display: grid;
  grid-template-columns: 24px 1fr;
  gap: 14px;
  align-items: center;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), transform var(--transition);
}
.reminder-row:hover {
  background: var(--bg-hover);
  border-color: var(--border);
}
.reminder-row:active { transform: scale(0.99); }

.reminder-check {
  width: 20px; height: 20px;
  border-radius: 50%;
  border: 2px solid var(--cal-reminder);
  background: transparent;
  position: relative;
  flex-shrink: 0;
}
.reminder-check::after {
  content: "";
  position: absolute;
  inset: 4px;
  border-radius: 50%;
  background: var(--cal-reminder);
  opacity: 0.25;
}

.reminder-main { min-width: 0; display: flex; flex-direction: column; gap: 3px; }

.reminder-title {
  font-size: 14.5px; color: var(--text-1); font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.reminder-time {
  font-size: 11.5px; color: var(--text-3);
  display: flex; align-items: center; gap: 6px;
}
.reminder-time::before {
  content: "";
  width: 4px; height: 4px;
  border-radius: 50%;
  background: var(--cal-reminder);
  flex-shrink: 0;
}

/* =========================================================
   Suche-Ansicht
   ========================================================= */
.search-view {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column;
}

.search-bar {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--bg-surface);
  position: relative;
}

.search-bar input {
  width: 100%;
  padding: 12px 16px 12px 40px;
  border-radius: var(--radius-md);
  background: var(--bg-app);
  border: 1px solid var(--border);
  color: var(--text-1);
  font-size: 15px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.search-bar::before {
  content: "";
  position: absolute;
  left: 30px; top: 50%;
  transform: translateY(-50%);
  width: 16px; height: 16px;
  background: var(--text-3);
  -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'><circle cx='11' cy='11' r='7'/><path d='m20 20-3.5-3.5'/></svg>") center/contain no-repeat;
          mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'><circle cx='11' cy='11' r='7'/><path d='m20 20-3.5-3.5'/></svg>") center/contain no-repeat;
  pointer-events: none;
}

.search-bar input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.search-bar input::-webkit-search-cancel-button { display: none; }

.search-results {
  flex: 1; min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 10px 14px 24px;
  display: flex; flex-direction: column; gap: 2px;
}

.search-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-3);
  font-size: 13.5px;
}

.search-hit {
  display: grid;
  grid-template-columns: 10px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 13px 14px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition);
}
.search-hit:active { background: var(--bg-hover); }
.search-hit:hover  { background: var(--bg-hover); }

.search-hit-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--cal-private);
  align-self: start;
  margin-top: 7px;
}
.search-hit-dot[data-cal="work"]     { background: var(--cal-work); }
.search-hit-dot[data-cal="reminder"] { background: var(--cal-reminder); }

.search-hit-main { min-width: 0; }
.search-hit-title {
  font-size: 14.5px; color: var(--text-1); font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.search-hit-notes {
  font-size: 12px; color: var(--text-2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  margin-top: 2px;
}
.search-hit-date {
  font-size: 11.5px; color: var(--text-3);
  white-space: nowrap;
  padding-top: 1px;
}

/* =========================================================
   Einstellungen-Ansicht
   ========================================================= */
.settings-view {
  flex: 1; min-height: 0;
  padding: 18px 22px 32px;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex; flex-direction: column; gap: 28px;
}

.settings-group { display: flex; flex-direction: column; gap: 8px; }

.settings-group-label {
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 1.4px;
  color: var(--text-3);
  padding-left: 4px;
}

.settings-items {
  display: flex; flex-direction: column;
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.settings-row {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-soft);
  text-align: left;
  cursor: pointer;
  transition: background var(--transition);
  width: 100%;
}
.settings-row:last-child { border-bottom: none; }
.settings-row:not(.is-static):hover  { background: var(--bg-hover); }
.settings-row:not(.is-static):active { background: var(--bg-hover); }
.settings-row.is-static { cursor: default; }

.settings-row-icon {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 15px;
  font-weight: 600;
}

.settings-row-main { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.settings-row-title {
  font-size: 14.5px; color: var(--text-1); font-weight: 500;
}
.settings-row-sub {
  font-size: 12px; color: var(--text-3);
}
.settings-row-value {
  font-size: 13px; color: var(--text-3);
}
.settings-row-chevron {
  font-size: 18px; color: var(--text-3);
  transition: transform var(--transition);
}
.settings-row:not(.is-static):hover .settings-row-chevron { transform: translateX(2px); }

.settings-row.is-danger .settings-row-title  { color: var(--danger); }
.settings-row.is-danger .settings-row-icon   { background: var(--danger-soft); color: var(--danger); }

/* =========================================================
   Modal (Desktop – zentriert)
   ========================================================= */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0, 0, 0, 0.55);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: fadeIn 140ms ease;
}
.modal-backdrop[hidden] { display: none; }
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }

.modal {
  width: 100%; max-width: 500px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: pop 180ms cubic-bezier(.22,.61,.36,1);
}
@keyframes pop {
  from { transform: translateY(10px) scale(0.985); opacity: 0; }
  to   { transform: translateY(0) scale(1); opacity: 1; }
}

.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border-soft);
}
.modal-head h2 { font-size: 15px; margin: 0; font-weight: 600; }

.modal-body { padding: 18px; display: flex; flex-direction: column; gap: 14px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-size: 11.5px; color: var(--text-3); letter-spacing: 0.3px; font-weight: 500; }
.field input, .field textarea, .field select {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-app);
  border: 1px solid var(--border);
  color: var(--text-1);
  font-size: 14px;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.field input:focus, .field textarea:focus, .field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.field textarea { resize: vertical; min-height: 70px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.modal-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 4px; }

.btn-danger {
  padding: 10px 16px; border-radius: var(--radius-sm);
  background: var(--danger-soft);
  border: 1px solid transparent;
  color: var(--danger); font-weight: 600; font-size: 13.5px;
  transition: background var(--transition);
}
.btn-danger:hover { background: rgba(255, 107, 122, 0.2); }

/* =========================================================
   Tabbar & FAB – Standard aus (Desktop)
   ========================================================= */
.tabbar, .fab { display: none; }

/* =========================================================
   MOBILE – iPhone / iPad (< 820px)
   ========================================================= */
@media (max-width: 820px) {

  /* ---------- Grundlayout ---------- */
  .app {
    grid-template-columns: 1fr;
    gap: 8px;

    padding:
      max(env(safe-area-inset-top, 0px), 8px)
      10px
      calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 10px)
      10px;

    height: 100dvh;
  }

  .sidebar { display: none; }

  /* ---------- Topbar ---------- */
  .topbar {
    padding: 8px 10px;
    border-radius: var(--radius-lg);
    gap: 6px;
    min-height: 48px;
  }
  .topbar-left  { gap: 6px; flex: 1; min-width: 0; }
  .topbar-right { display: flex; }

  .title {
    font-size: 16px;
    margin: 0 0 0 4px;
  }
  .btn-icon {
    width: 38px; height: 38px;
    font-size: 20px;
    border-radius: 11px;
    flex-shrink: 0;
  }
  .btn-ghost {
    padding: 8px 11px;
    font-size: 12.5px;
    flex-shrink: 0;
  }
  .segmented button {
    padding: 6px 10px;
    font-size: 12px;
  }

  /* ---------- View ---------- */
  .view {
    border-radius: var(--radius-lg);
    overflow: hidden;
    min-height: 0;
  }

  /* ---------- Monat ---------- */
  .month-head {
    padding: 8px 2px 6px;
    font-size: 10px;
    letter-spacing: 0.8px;
  }
  .month-grid { grid-auto-rows: minmax(72px, 1fr); }
  .day { min-height: 72px; padding: 5px 4px; gap: 3px; }
  .day-num { font-size: 11.5px; min-width: 20px; height: 20px; padding: 0 5px; }
  .event-chip { font-size: 10px; padding: 2px 5px; border-radius: 5px; border-left-width: 2px; }

  /* ---------- Woche ---------- */
  .week-grid {
    grid-template-columns: repeat(7, 130px);
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
  }
  .week-col { scroll-snap-align: start; }
  .week-col-head { padding: 10px 10px 8px; }
  .week-col-day  { font-size: 10px; }
  .week-col-date { font-size: 14px; }
  .week-col-body { padding: 8px; gap: 6px; }
  .week-card     { padding: 8px; }
  .week-card-title { font-size: 12.5px; }

  /* ---------- Tag ---------- */
  .day-header { padding: 12px 14px; gap: 10px; }
  .day-header-weekday { font-size: 10px; }
  .day-header-date    { font-size: 15px; }
  .day-header .btn-primary { padding: 8px 12px; font-size: 13px; }
  .day-body { padding: 14px 14px 22px; gap: 16px; }
  .day-card {
    grid-template-columns: 1fr;
    gap: 6px;
    padding: 12px 14px;
    padding-right: 20px;
  }
  .day-card-time {
    flex-direction: row; align-items: baseline; gap: 6px;
    font-size: 12px;
  }
  .day-card-duration { display: none; }
  .day-card-title { font-size: 14px; }
  .day-card-notes { font-size: 12px; }
  .day-card-accent { top: 10px; bottom: 10px; right: 8px; width: 3px; }

  /* ---------- Liste ---------- */
  .list-view { padding: 14px 12px 22px; gap: 20px; }
  .list-bucket-label { font-size: 10px; }
  .list-day-name     { font-size: 12.5px; }
  .list-day-count    { font-size: 10px; }
  .list-event {
    grid-template-columns: 60px 1fr auto;
    gap: 10px;
    padding: 12px 14px;
  }
  .list-event::before { top: 10px; bottom: 10px; }
  .list-event-time   { font-size: 12px; }
  .list-event-title  { font-size: 14px; }
  .list-event-notes  { font-size: 11.5px; }

  /* ---------- Erinnerungen ---------- */
  .reminders-view { padding: 14px 12px 22px; gap: 22px; }
  .reminders-bucket-label { font-size: 10px; }
  .reminder-row { padding: 12px 14px; }
  .reminder-title { font-size: 14px; }

  /* ---------- Suche ---------- */
  .search-bar { padding: 12px 12px; }
  .search-bar::before { left: 26px; }
  .search-results { padding: 8px 10px 20px; }

  /* ---------- Einstellungen ---------- */
  .settings-view { padding: 14px 12px 28px; gap: 24px; }
  .settings-group-label { font-size: 10px; }
  .settings-row {
    padding: 12px 14px;
    grid-template-columns: 32px 1fr auto;
    gap: 12px;
  }
  .settings-row-title { font-size: 14px; }

  /* =======================================================
     Bottom-Tabbar
     ======================================================= */
  .tabbar {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 60;

    padding:
      8px
      calc(var(--safe-right) + 4px)
      calc(var(--safe-bottom) + 8px)
      calc(var(--safe-left) + 4px);

    background: var(--bg-surface);
    border-top: 1px solid var(--border);
    gap: 0;
  }

  .tab {
    position: relative;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 3px;
    padding: 6px 2px 4px;
    border-radius: 12px;
    color: var(--text-3);
    transition: color var(--transition), background var(--transition);
    min-height: 46px;
    -webkit-tap-highlight-color: transparent;
  }

  .tab.active { color: var(--accent); }

  .tab.active::before {
    content: "";
    position: absolute;
    top: -9px;
    left: 50%;
    transform: translateX(-50%);
    width: 22px;
    height: 3px;
    border-radius: 999px;
    background: var(--accent);
    box-shadow: 0 0 10px var(--accent-soft);
  }

  .tab.active .tab-icon {
    background: var(--accent-soft);
    border-radius: 8px;
    padding: 3px;
    margin: -3px;
  }

  .tab:active { color: var(--accent); }

  .tab-icon {
    width: 22px; height: 22px;
    display: block;
    color: inherit;
    transition: background var(--transition), padding var(--transition);
  }

  .tab-label {
    font-size: 9.5px;
    letter-spacing: 0.1px;
    font-weight: 500;
    white-space: nowrap;
  }

  .tab.active .tab-label { font-weight: 600; }

  /* ---------- FAB ---------- */
  .fab {
    display: flex; align-items: center; justify-content: center;
    position: fixed;
    right: calc(var(--safe-right) + 16px);
    bottom: calc(var(--safe-bottom) + var(--tabbar-h) + 16px);
    width: 56px; height: 56px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--accent-text);
    font-size: 28px; font-weight: 300;
    box-shadow: 0 8px 24px rgba(123, 140, 255, 0.4);
    z-index: 55;
    transition: transform 120ms ease, background var(--transition);
  }
  .fab:active { transform: scale(0.92); background: var(--accent-hover); }

  /* ---------- Modal als Bottom-Sheet ---------- */
  .modal-backdrop {
    padding: 0;
    align-items: flex-end;
    background: rgba(0, 0, 0, 0.5);
    animation: none;
  }
  .modal {
    max-width: 100%; width: 100%;
    border-radius: 22px 22px 0 0;
    border-bottom: none;
    padding-bottom: calc(var(--safe-bottom) + 8px);
    max-height: 92dvh;
    overflow-y: auto;
    animation: sheetUp 260ms cubic-bezier(.22,.61,.36,1);
  }
  @keyframes sheetUp {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
  }
  .modal::before {
    content: "";
    display: block;
    width: 36px; height: 4px;
    background: var(--border);
    border-radius: 999px;
    margin: 8px auto 0;
  }
  .modal-head {
    padding: 14px 18px 12px;
    border-bottom: 1px solid var(--border-soft);
    position: sticky; top: 0;
    background: var(--bg-surface);
    z-index: 1;
  }
  .modal-body { padding: 16px 18px 20px; gap: 12px; }
  .field input, .field textarea, .field select {
    padding: 13px 14px;
    font-size: 16px;
  }
  .modal-actions {
    flex-direction: column-reverse;
    gap: 8px;
    margin-top: 8px;
  }
  .modal-actions .btn-primary,
  .modal-actions .btn-danger {
    width: 100%; padding: 14px; font-size: 15px;
  }
  .row { grid-template-columns: 1fr; }

  /* ---------- Body-Hintergrund unten angleichen ---------- */
  html, body { background: var(--bg-surface); }
}

/* =========================================================
   Kleine iPhones – extra kompakt
   ========================================================= */
@media (max-width: 380px) {
  .title { font-size: 15px; }
  .day-header-date { font-size: 15px; }
  .event-chip { font-size: 9.5px; }
  .tab-label { font-size: 9px; }
}

/* =========================================================
   Landscape iPhone – kompakter
   ========================================================= */
@media (max-width: 900px) and (orientation: landscape) {
  :root { --tabbar-h: 54px; }
  .tab-icon { width: 20px; height: 20px; }
  .tab-label { font-size: 9px; }
}

/* =========================================================
   Seiten-Übergänge (Tab-Wechsel)
   ========================================================= */

/* Standardmäßig kein Overflow-Problem */
.view {
  position: relative;
  will-change: transform, opacity;
}

/* Wenn ein Tab-Wechsel läuft, darf kurzzeitig nichts overflowen */
.app.is-transitioning .view {
  overflow: hidden;
}

/* Nach links wischen (nächster Tab) – neue Seite kommt von rechts */
@keyframes slideInFromRight {
  from { transform: translateX(28%); opacity: 0; }
  to   { transform: translateX(0);   opacity: 1; }
}
@keyframes slideOutToLeft {
  from { transform: translateX(0);    opacity: 1; }
  to   { transform: translateX(-18%); opacity: 0; }
}

/* Nach rechts wischen (voriger Tab) – neue Seite kommt von links */
@keyframes slideInFromLeft {
  from { transform: translateX(-28%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}
@keyframes slideOutToRight {
  from { transform: translateX(0);   opacity: 1; }
  to   { transform: translateX(18%); opacity: 0; }
}

/* Anwendung */
.view.slide-in-left  { animation: slideInFromLeft  220ms cubic-bezier(.22,.61,.36,1); }
.view.slide-in-right { animation: slideInFromRight 220ms cubic-bezier(.22,.61,.36,1); }

/* Nur relevant, wenn wir später echte Crossfades machen – aktuell reicht In-Animation */
.view.slide-out-left  { animation: slideOutToLeft  200ms cubic-bezier(.22,.61,.36,1); }
.view.slide-out-right { animation: slideOutToRight 200ms cubic-bezier(.22,.61,.36,1); }

/* Bei reduzierter Bewegung: keine Animation */
@media (prefers-reduced-motion: reduce) {
  .view.slide-in-left,
  .view.slide-in-right,
  .view.slide-out-left,
  .view.slide-out-right {
    animation: none;
  }
}

/* =========================================================
   Splash-Screen (Start-Animation)
   ========================================================= */
.splash {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: var(--bg-app);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 1;
  transition: opacity 400ms cubic-bezier(.22,.61,.36,1);
}

.splash.hidden {
  opacity: 0;
}

.splash-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  transform: translateY(0);
  animation: splashIn 700ms cubic-bezier(.22,.61,.36,1) both;
}

@keyframes splashIn {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.94);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.splash-logo {
  width: 88px;
  height: 88px;
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(0 12px 32px rgba(123, 140, 255, 0.35));
  animation: splashPulse 2000ms ease-in-out infinite;
}

.splash-logo svg {
  width: 100%;
  height: 100%;
}

@keyframes splashPulse {
  0%, 100% { transform: scale(1);    filter: drop-shadow(0 12px 32px rgba(123, 140, 255, 0.35)); }
  50%      { transform: scale(1.04); filter: drop-shadow(0 16px 40px rgba(123, 140, 255, 0.55)); }
}

.splash-title {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.4px;
  color: var(--text-1);
  opacity: 0.9;
}

.splash-loader {
  width: 120px;
  height: 3px;
  border-radius: 999px;
  background: rgba(123, 140, 255, 0.12);
  overflow: hidden;
  margin-top: 4px;
}

.splash-loader-bar {
  height: 100%;
  width: 40%;
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  animation: splashLoad 1100ms cubic-bezier(.4,0,.6,1) infinite;
}

@keyframes splashLoad {
  0%   { transform: translateX(-120%); }
  100% { transform: translateX(320%); }
}

/* Splash in reduzierter Bewegung: nur sanft einblenden, keine Pulsanimation */
@media (prefers-reduced-motion: reduce) {
  .splash-inner { animation: none; }
  .splash-logo  { animation: none; }
  .splash-loader-bar { animation: none; width: 100%; }
}

/* Titelbereich in der Topbar (Titel + Untertitel) */
.title-group {
  display: flex; flex-direction: column;
  min-width: 0; gap: 1px;
}
.title-group .title {
  margin: 0 0 0 4px;
}
.subtitle {
  font-size: 11.5px;
  color: var(--text-3);
  margin-left: 4px;
  letter-spacing: 0.1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-height: 14px;
}
@media (max-width: 820px) {
  .subtitle { font-size: 10.5px; }
}