:root {
  --bg: #f4f7ff52;
  --surface: #ffffff08;
  --surface-sidebar: #ffffff;
  --surface-2: #f8faff;
  --primary: #2f6df640;
  --primary-bright: #2f6ef6;
  --primary-dark: #1f56cfba;
  --text: #1b2233;
  --text-modal: #ffffff;
  --muted: #6e7788;
  --danger: #dd3d3d61;
  --border: #e6ebf43b;
}

/* NEU: Globale Variablen-Zuweisung für den Dark Mode */
:root.dark-mode {
  --bg: #0b0f19;
  --surface: #141b2d;
  --surface-sidebar: #141b2d;
  --surface-2: #1f2942;
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --text: #f3f4f6;
  --muted: #9ca3af;
  --danger: #ef4444;
  --border: #2d3748;
}

* {
  box-sizing: border-box;
}

.anta-regular {
  font-family: "Anta", sans-serif;
  font-weight: 400;
  font-style: normal;
}

body {
  margin: 0;
  font-family: "Segoe UI", Arial, sans-serif;
  background:
    radial-gradient(circle at 15% 0%, #ffffff 0%, transparent 40%),
    radial-gradient(circle at 90% 10%, #eef4ff 0%, transparent 35%),
    var(--bg);
  color: var(--text);
  transition: background 0.3s ease, color 0.3s ease;
}

/* NEU: Angepasste Hintergrund-Glows für den Dark Mode */
:root.dark-mode body {
  background:
    radial-gradient(circle at 15% 0%, #1e293b 0%, transparent 40%),
    radial-gradient(circle at 90% 10%, #0f172a 0%, transparent 35%),
    var(--bg);
}

h1, h2, h3, h4, p {
  margin: 0;
}

button {
  cursor: pointer;
  border: none;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 600;
  transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-primary {
  color: #fff;
  background: linear-gradient(135deg, var(--primary), #5d90ff);
}

.btn-primary:hover {
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  transform: translateY(-1px);
}

.btn-ghost {
  color: var(--text-modal);
  background: var(--surface);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  background: var(--surface-2);
  color: var(--text);
}


.btn-ghost-bl {
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
}

.btn-danger {
  color: #fff;
  background: var(--danger);
}

.btn-danger:hover {
  filter: brightness(0.95);
}

.btn-icon {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
  transition: 0.2s;
}

.btn-icon:hover {
  background: var(--surface-2);
  border-color: var(--primary);
  color: var(--primary);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 12px 30px rgba(20, 30, 60, 0.06), 0 2px 8px rgba(20, 30, 60, 0.04);
}

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 430px;
  padding: 28px;
  border: 1px solid var(--border);
  box-shadow: 0 16px 34px rgba(22, 39, 73, 0.12);
  background: linear-gradient(170deg, var(--surface), var(--surface-2));
}

.muted {
  color: var(--text-modal);
}

.muted-login {
  color: var(--text);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 14px;
}

input, select {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  outline: none;
  background: var(--surface);
  color: var(--text-modal);
  transition: 0.2s ease;
  overflow: hidden;
  font-size: 16px;
  appearance: none;
  -webkit-appearance: none;
  box-sizing: border-box;
  height: fit-content;
}

input:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(47, 109, 246, 0.1);
}

input:disabled {
  background: var(--bg);
  color: var(--muted);
  cursor: not-allowed;
  border-color: var(--border);
}

/* Suchfeld spezifisches Styling */
#eventSearchInput {
  background: var(--surface-2);
  border: 1px solid var(--border);
}
#eventSearchInput:focus {
  background: var(--surface);
  border-color: var(--primary);
}

.app-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 280px;
  background: var(--surface-sidebar);
  opacity: 0.98;
  border-right: 1px solid var(--border);
  backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
  transition: width 0.25s ease;
}

.sidebar.collapsed {
  width: 0;
  overflow: hidden;
}

.side-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px;
  border-bottom: 1px solid var(--border);
}

.nav {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.nav button {
  text-align: left;
  background: transparent;
  border-radius: 10px;
  color: var(--text);
}

.nav button.active {
  background: #ecf2ff;
  color: var(--primary-dark);
}

:root.dark-mode .nav button.active {
  background: #1e3a8a;
  color: #e0f2fe;
}

.side-foot {
  margin-top: auto;
  border-top: 1px solid var(--border);
  padding: 12px;
}

.profile-nav-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgba(30, 50, 90, 0.08);
}

.main {
  flex: 1;
  padding: 18px;
}

.main-inner {
  max-width: 980px;
  margin: 0 auto;
}

.main-inner.main-inner-wide { max-width: 1180px; }
.main-inner.main-inner-calendar { max-width: 680px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 4px;
  min-height: 52px;
}

.topbar h3, .topbar-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.menu-float {
  position: fixed;
  top: 16px;
  left: 24px;
  z-index: 40;
  width: 42px;
  height: 42px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 19px;
  font-weight: 500;
  border-radius: 12px;
  box-shadow: 0 10px 18px rgba(27, 34, 51, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  padding: 0;
}

.panel {
  margin-top: 16px;
  padding: 22px;
}

.calendar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 580px;
  margin: 0 auto 16px auto;
}

.calendar-header h2 {
  margin: 0;
  font-size: 20px;
}

.calendar-wrap {
  width: 100%;
  padding-bottom: 4px;
  overflow: hidden; 
}

.calendar {
  margin: 14px auto 0 auto;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 12px;
  max-width: 580px;
}

.day {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 50%;
  aspect-ratio: 1 / 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 4px;
  transition: 0.15s ease;
}

.day.empty-day {
  background: transparent;
  border: none;
}

.day-clickable {
  text-align: center;
  font-weight: 500;
}

.day-clickable:hover {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(47, 109, 246, 0.12);
  background: var(--surface);
}

.day-number {
  display: block;
}

.day-has-note {
  background: #edf3ff;
  border-color: #dbe5fb;
}
:root.dark-mode .day-has-note {
  background: #1e3a8a;
  border-color: #2563eb;
}

.day-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #e03434;
  position: absolute;
  left: 48%;
  bottom: 10px;
}

.day.head {
  background: transparent;
  border: none;
  min-height: auto;
  aspect-ratio: auto;
  font-weight: 700;
  text-align: center;
  border-radius: 0;
  padding: 8px 0;
}

.users-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 14px;
}

th, td {
  border-bottom: 1px solid var(--border);
  text-align: left;
  padding: 10px 8px;
}

.users-table .col-user { width: 34%; }
.users-table .col-class { width: 24%; }
.users-table .col-role { width: 18%; }
.users-table .col-actions { width: 24%; }

.users-table-wrap { overflow-x: auto; }

.row-actions {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  gap: 8px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(12, 20, 35, 0.5);
  display: grid;
  place-items: center;
  padding: 18px;
  z-index: 100;
}

.modal {
  width: 100%;
  max-width: 480px;
  margin: auto;
  background: var(--surface);
  color: var(--text-modal);
  border-radius: 18px;
  border: 1px solid var(--border);
  padding: 20px;
  box-shadow: 0 20px 40px rgba(12, 20, 35, 0.2);
  box-sizing: border-box;
  overflow: hidden;
  backdrop-filter: blur(3px);
}

.profile-avatar-section {
  margin-top: 14px;
  padding: 14px;
  border-radius: 12px;
}

.profile-avatar {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  background: linear-gradient(140deg, #e7eeff, #f4f7ff);
  color: var(--primary-dark);
  display: grid;
  place-items: center;
  font-size: 30px;
  font-weight: 700;
  margin: 0 auto;
  border: 2px solid #dbe5fb;
  overflow: hidden;
  position: relative;
}

:root.dark-mode .profile-avatar {
  background: linear-gradient(140deg, #1e2942, #141b2d);
  color: #fff;
  border-color: var(--border);
}

.profile-avatar.has-image { background: var(--surface); }
.profile-avatar img { width: 100%; height: 100%; object-fit: cover; }
.events-list { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 14px; }

.events-heading {
  display: flex;
  justify-content: center;
  font-size: 17px;
  font-weight: 500;
  color: var(--text-modal);
  margin-bottom: 12px;
  letter-spacing: -0.01em;
}

.event-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  width: 100%;
  background: var(--surface);
}

.events-row { display: flex; flex-direction: column; gap: 10px; }

.modal-actions {
  margin-top: 16px;
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.modal-actions.modal-actions-stack { display: flex; flex-direction: column; align-items: stretch; }
.modal-actions.modal-actions-stack button { width: 100%; }
.time-row { display: flex; gap: 12px; margin-bottom: 12px; }
.time-row .field { flex: 1; margin-bottom: 0; }

.event-time-badge {
  display: inline-block;
  background: #ecf2ff;
  color: var(--primary-dark);
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 8px;
  margin-top: 4px;
  font-size: 12px;
}

/* --- Freie Tage Styling (Adaptive für beide Themes) --- */
.day.day-free::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 70px;
    height: 70px;
    background-color: #bceec8;
    border-radius: 50%;
    z-index: 0;
}

:root.dark-mode .day.day-free::before {
    background-color: #064e3b;
}

.day.day-free.free-mid::after,
.day.day-free.free-start::after,
.day.day-free.free-end::after {
    content: "";
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    height: 32px;
    background-color: #bceec8;
    z-index: -1;
}

:root.dark-mode .day.day-free.free-mid::after,
:root.dark-mode .day.day-free.free-start::after,
:root.dark-mode .day.day-free.free-end::after {
    background-color: #064e3b;
}

.day.day-free.free-start::after { left: 50%; width: 50%; }
.day.day-free.free-end::after { right: 50%; width: 50%; }
.day.day-free.free-mid::after { left: -50%; width: 200%; }

@media (max-width: 900px) {
  .main { padding: 12px; }
  .main-inner { max-width: 100%; }
  .panel { padding: 14px; }
}

@media (max-width: 720px) {
  .app-layout { position: relative; }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    height: 100dvh; 
    z-index: 50;
    width: min(82vw, 330px);
    border-radius: 0 20px 20px 0;
    overflow-y: auto;
    box-shadow: 0 16px 32px rgba(10, 20, 40, 0.18);
    display: flex;
    flex-direction: column;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .sidebar.collapsed {
    width: 0;
    height: 100vh;
    border: 0;
    overflow: hidden;
  }

  .calendar { gap: 6px; max-width: 100%; }
  .day { padding: 2px; font-size: 13px; }
  .day-dot { bottom: 10%; left: 45%; }
  .users-head { flex-direction: column; align-items: flex-start; }
  .users-table, .users-table thead, .users-table tbody, .users-table tr, .users-table td { display: block; }
  .users-table thead { display: none; }

  .users-table tr {
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 10px;
    margin-bottom: 10px;
    background: var(--surface);
  }

  .users-table td {
    border: 0;
    padding: 6px 0;
    display: flex;
    justify-content: space-between;
    gap: 10px;
  }

  .users-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 600;
  }

  .users-table td[data-label="Aktionen"] { display: block; padding-top: 10px; }
  .users-table td[data-label="Aktionen"]::before { display: none; }

  .nav button {
    text-align: left;
    background: transparent;
    border-radius: 12px;
    padding: 12px 16px;
    font-weight: 500;
    transition: all 0.2s;
    color: var(--text);
    border: 1px solid transparent;
  }

  .nav button:hover { background: var(--surface-2); border-color: var(--border); }
  .nav button.active { background: #ecf2ff; color: var(--primary-dark); font-weight: 600; }
  :root.dark-mode .nav button.active { background: #1e3a8a; color: #e0f2fe; }

  .side-foot {
    margin-top: auto;
    border-top: 1px solid var(--border);
    padding: 16px;
    background: var(--surface-2);
  }

  .profile-nav-btn {
    background: var(--surface) !important;
    border: 1px solid var(--border) !important;
    color: var(--text) !important;
    font-weight: 600;
  }

  .profile-nav-btn:hover {
    border-color: var(--primary) !important;
    color: var(--primary) !important;
  }

  .users-create-btn { width: 100%; }
  .day.day-free::before { width: 40px; height: 40px; }
}