/* ============================================================
   Familienkalender — Mobile-First Stylesheet
   Defaults gelten für Smartphones; Desktop-Overrides ab 768px.
   ============================================================ */

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: #f5f5f7;
  color: #1d1d1f;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;          /* mobile: berücksichtigt Browser-Chrome */
  -webkit-tap-highlight-color: transparent;
}

/* ============================================================
   TOPBAR — Mobile: zwei Reihen (Titel+Burger / Aktionen-Drawer)
   ============================================================ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: white;
  border-bottom: 1px solid #e5e5ea;
  padding: 0.6rem 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.topbar h1 {
  font-size: 1.1rem;
  margin: 0;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#menu-toggle {
  /* Burger-Button: nur mobil sichtbar */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 1px solid #d1d1d6;
  background: white;
  border-radius: 10px;
  cursor: pointer;
  font-size: 1.2rem;
  margin-left: auto;
}

.user-area {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.85rem;
  background: white;
  border-bottom: 1px solid #e5e5ea;
}
.user-area.collapsed { display: none; }
.user-area label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.85rem;
  color: #6e6e73;
}
.user-area select,
.user-area input,
.user-area button {
  font-family: inherit;
  font-size: 1rem;
  padding: 0.7rem 0.85rem;
  border-radius: 10px;
  border: 1px solid #d1d1d6;
  background: white;
  min-height: 44px;             /* WCAG-Touch-Target */
  cursor: pointer;
}
.user-area input { cursor: text; }
.user-area .button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}
.user-area .button-row.three { grid-template-columns: 1fr 1fr 1fr; }

/* ============================================================
   MAIN — Mobile: Legend ist eingeklappt, Calendar volle Breite
   ============================================================ */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
#legend {
  background: white;
  border-bottom: 1px solid #e5e5ea;
  padding: 0.5rem 0.85rem 0.85rem;
  max-height: 40vh;
  overflow-y: auto;
}
#legend.collapsed { display: none; }
#legend h3 {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: #6e6e73;
  margin: 0.6rem 0 0.35rem;
  letter-spacing: .03em;
}
#legend h3:first-child { margin-top: 0; }
.legend-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.35rem 0;
  font-size: 0.95rem;
}
.legend-dot {
  width: 18px;
  height: 18px;
  border-radius: 5px;
  flex-shrink: 0;
}
.legend-item.feed { padding-left: 1.2rem; font-size: 0.85rem; color: #3a3a3c; }

#calendar {
  flex: 1;
  padding: 0.5rem;
  min-width: 0;
  min-height: 0;
}

/* ============================================================
   DIALOGS — Mobile: Bottom-Sheet, Desktop: zentriertes Modal
   ============================================================ */
dialog {
  border: none;
  padding: 0;
  background: white;
  margin: 0;
  width: 100%;
  max-width: 100%;
  max-height: 92dvh;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -10px 40px rgba(0,0,0,.2);
  overflow-y: auto;
}
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog form {
  padding: 1.25rem;
  padding-bottom: max(1.25rem, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}
dialog h2 { margin: 0 0 0.25rem; font-size: 1.15rem; }
dialog h3 { margin: 0.5rem 0 0.25rem; font-size: 1rem; }
dialog label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.85rem;
  color: #3a3a3c;
}
dialog label.row {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.95rem;
}
dialog input,
dialog textarea,
dialog select {
  font-family: inherit;
  font-size: 1rem;
  padding: 0.75rem 0.85rem;
  border: 1px solid #d1d1d6;
  border-radius: 10px;
  background: white;
  min-height: 44px;
}
dialog textarea { min-height: 80px; resize: vertical; }
dialog menu {
  display: flex;
  gap: 0.5rem;
  padding: 0;
  margin: 0.5rem 0 0;
  flex-wrap: wrap;
}
dialog button {
  font-family: inherit;
  font-size: 1rem;
  padding: 0.75rem 1.1rem;
  border-radius: 10px;
  border: 1px solid #d1d1d6;
  background: white;
  min-height: 44px;
  cursor: pointer;
  flex: 1;                      /* Mobile: Buttons füllen Reihe */
}
dialog button.primary { background: #007aff; color: white; border-color: #007aff; }
dialog button.danger  { background: #ff3b30; color: white; border-color: #ff3b30; flex: 0 0 auto; }
dialog button:active { filter: brightness(.92); }
dialog hr { width: 100%; border: none; border-top: 1px solid #e5e5ea; margin: 0.25rem 0; }
dialog ul { list-style: none; padding: 0; margin: 0; }
dialog ul li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid #e5e5ea;
}
dialog ul li:last-child { border-bottom: none; }
dialog ul li .grow { flex: 1; min-width: 0; }
dialog ul li .grow strong { display: block; font-size: 0.95rem; }
dialog ul li .grow small { color: #6e6e73; word-break: break-all; font-size: 0.8rem; }
dialog ul li button { padding: 0.4rem 0.8rem; font-size: 0.85rem; flex: 0 0 auto; }
.hint { font-size: 0.85rem; color: #6e6e73; margin: 0; line-height: 1.4; }
.meta { font-size: 0.8rem; color: #6e6e73; margin: 0; }

/* ============================================================
   FAB — Floating Action Button (neuer Termin)
   ============================================================ */
.fab-new {
  position: fixed;
  bottom: max(1rem, env(safe-area-inset-bottom));
  right: max(1rem, env(safe-area-inset-right));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: #007aff;
  color: white;
  font-size: 2rem;
  line-height: 1;
  font-weight: 300;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,122,255,.4), 0 2px 4px rgba(0,0,0,.1);
  z-index: 9000;
  transition: transform .15s ease, box-shadow .15s ease;
  -webkit-tap-highlight-color: transparent;
}
.fab-new:active { transform: scale(.92); box-shadow: 0 2px 8px rgba(0,122,255,.3); }
.fab-new:hover { background: #0066d6; }

/* ============================================================
   TOAST
   ============================================================ */
.toast {
  position: fixed;
  bottom: max(1rem, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: #1d1d1f;
  color: white;
  padding: 0.7rem 1.1rem;
  border-radius: 10px;
  font-size: 0.9rem;
  z-index: 9999;
  max-width: 92vw;
  text-align: center;
  box-shadow: 0 8px 30px rgba(0,0,0,.3);
}
.toast.hidden { display: none; }
.toast.error { background: #ff3b30; }

/* ============================================================
   FULLCALENDAR — Mobile-Anpassungen
   ============================================================ */
.fc { font-size: 0.9rem; }
.fc .fc-toolbar { flex-wrap: wrap; gap: 0.4rem; }
.fc .fc-toolbar-title { font-size: 1rem; }
.fc .fc-button {
  padding: 0.45rem 0.7rem;
  font-size: 0.85rem;
  min-height: 38px;
}
.fc .fc-button-primary {
  background: white;
  color: #1d1d1f;
  border-color: #d1d1d6;
}
.fc .fc-button-primary:hover,
.fc .fc-button-primary:not(:disabled).fc-button-active {
  background: #007aff;
  color: white;
  border-color: #007aff;
}
.fc-event { cursor: pointer; border: none !important; padding: 2px 4px; }
.fc-event-readonly { opacity: .85; }
.fc-event-readonly::after { content: " 🔒"; font-size: .8em; }
.fc-list-event-time { white-space: nowrap; }

/* ============================================================
   DESKTOP-OVERRIDES (≥ 768px)
   ============================================================ */
@media (min-width: 768px) {
  .topbar {
    flex-wrap: wrap;
    padding: 0.75rem 1.25rem;
  }
  .topbar h1 { font-size: 1.25rem; flex: 0 0 auto; }
  #menu-toggle { display: none; }

  .user-area {
    display: flex !important;
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
    padding: 0;
    margin-left: auto;
    background: transparent;
    border: none;
    flex-wrap: wrap;
  }
  .user-area label { flex-direction: row; align-items: center; gap: 0.4rem; font-size: 0.9rem; }
  .user-area select,
  .user-area input,
  .user-area button {
    padding: 0.4rem 0.7rem;
    font-size: 0.9rem;
    min-height: 36px;
  }
  .user-area input { min-width: 90px; }
  .user-area .button-row { display: contents; }

  main {
    flex-direction: row;
  }
  #legend {
    display: block !important;
    width: 240px;
    flex-shrink: 0;
    border-bottom: none;
    border-right: 1px solid #e5e5ea;
    padding: 1rem;
    max-height: none;
  }
  #calendar { padding: 1rem; }

  /* Dialoge: zentriertes Modal, nicht Bottom-Sheet */
  dialog {
    position: fixed;
    top: 50%;
    left: 50%;
    right: auto;
    bottom: auto;
    transform: translate(-50%, -50%);
    max-width: 480px;
    width: 90vw;
    border-radius: 14px;
    max-height: 85vh;
    box-shadow: 0 20px 60px rgba(0,0,0,.25);
  }
  dialog button { flex: 0 0 auto; min-height: 38px; }
  dialog button.primary { padding: 0.5rem 1.2rem; }
  dialog menu { justify-content: flex-end; }
  dialog button.danger { margin-right: auto; }   /* Löschen links, Save/Cancel rechts */

  .fc { font-size: 1rem; }
  .fc .fc-toolbar-title { font-size: 1.2rem; }
}
