/* ---------------------------------------------------------------------- */
/* Design-Tokens                                                          */
/* ---------------------------------------------------------------------- */

:root {
  --bg: #f5f4ee;
  --surface: #ffffff;
  --surface-hover: #f8f7f1;
  --surface-sunken: #eeece2;
  --border: #e4e0d4;
  --border-strong: #d3cdbb;

  --text-primary: #1d2420;
  --text-secondary: #5c655d;
  --text-tertiary: #959a8f;

  --accent: #367a59;
  --accent-hover: #234b37;
  --accent-soft: #e8f1eb;
  --accent-contrast: #ffffff;
  --accent-sand: #c9b89a;
  --accent-sand-soft: #f4efe5;

  --success: #2d7a4f;
  --success-soft: #e6f3ea;
  --danger: #b3413a;
  --danger-soft: #fbece9;
  --warning: #9c6b2e;
  --warning-soft: #f6ecd9;
  --avatar-blau: #3d6f94;
  --avatar-blau-soft: #e4edf3;
  --avatar-lila: #7a5ca8;
  --avatar-lila-soft: #efe9f6;

  --sidebar-bg: #234b37;
  --sidebar-fg: #d7e4dc;
  --sidebar-fg-muted: #9bb3a4;
  --sidebar-active-bg: rgba(255, 255, 255, 0.1);
  --sidebar-border: rgba(255, 255, 255, 0.08);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;

  --shadow-sm: 0 1px 2px rgba(29, 36, 32, 0.06), 0 4px 10px rgba(29, 36, 32, 0.04);
  --shadow-md: 0 2px 6px rgba(29, 36, 32, 0.06), 0 8px 24px rgba(29, 36, 32, 0.07);
  --shadow-lg: 0 12px 32px rgba(29, 36, 32, 0.16);

  --sidebar-width: 236px;
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  /* Heller Modus braucht einen kräftigeren Anteil, damit der
     Login-Verlauf gegen die ohnehin helle Fläche erkennbar bleibt. */
  --login-gradient-anteil: 32%;

  --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%235c655d'%3E%3Cpath fill-rule='evenodd' d='M5.23 7.21a.75.75 0 0 1 1.06.02L10 10.94l3.71-3.71a.75.75 0 1 1 1.06 1.06l-4.24 4.25a.75.75 0 0 1-1.06 0L5.21 8.29a.75.75 0 0 1 .02-1.08z' clip-rule='evenodd'/%3E%3C/svg%3E");

  color-scheme: light;
}

/* Dunkel wird immer explizit über data-theme gesetzt (ein Inline-Script im
   <head> entscheidet vor dem ersten Rendern anhand der Speicherung bzw. der
   Systemeinstellung) – so lässt sich der Wechsel zwischen den beiden
   Zuständen zuverlässig weich einblenden. */
:root[data-theme="dark"] {
  --bg: #11140f;
  --surface: #181c16;
  --surface-hover: #1e221c;
  --surface-sunken: #0d100b;
  --border: #2a2f25;
  --border-strong: #383e31;

  --text-primary: #f1f2ec;
  --text-secondary: #abb3a4;
  --text-tertiary: #767e70;

  --accent: #4f9d78;
  --accent-hover: #6cb692;
  --accent-soft: #1b3426;
  --accent-contrast: #ffffff;
  --accent-sand: #c9b89a;
  --accent-sand-soft: #2c2719;

  --success: #4f9d78;
  --success-soft: #16301f;
  --danger: #e28178;
  --danger-soft: #38201c;
  --warning: #d2a85c;
  --warning-soft: #352a16;
  --avatar-blau: #7fb4d9;
  --avatar-blau-soft: #1b2d38;
  --avatar-lila: #b79bdb;
  --avatar-lila-soft: #2a2235;

  --sidebar-bg: #0e1510;
  --sidebar-fg: #d7e4dc;
  --sidebar-fg-muted: #76856f;
  --sidebar-active-bg: rgba(255, 255, 255, 0.08);
  --sidebar-border: rgba(255, 255, 255, 0.06);

  --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%23abb3a4'%3E%3Cpath fill-rule='evenodd' d='M5.23 7.21a.75.75 0 0 1 1.06.02L10 10.94l3.71-3.71a.75.75 0 1 1 1.06 1.06l-4.24 4.25a.75.75 0 0 1-1.06 0L5.21 8.29a.75.75 0 0 1 .02-1.08z' clip-rule='evenodd'/%3E%3C/svg%3E");

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35), 0 4px 12px rgba(0, 0, 0, 0.22);
  --shadow-md: 0 2px 6px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);

  --login-gradient-anteil: 18%;

  color-scheme: dark;
}

/* ---------------------------------------------------------------------- */
/* Reset & Basis                                                          */
/* ---------------------------------------------------------------------- */

* {
  box-sizing: border-box;
}

/* Das hidden-Attribut gilt immer – sonst hebt etwa .btn { display: flex }
   es auf, und per JavaScript versteckte Knöpfe bleiben sichtbar. */
[hidden] {
  display: none !important;
}

/* Weicher Farbwechsel beim Umschalten zwischen Hell und Dunkel. Die
   Textfarbe wird bewusst NICHT mitgefadet: beim direkten Übergang von
   Schwarz nach Weiß (und zurück) entsteht in der Mitte ein unnatürlich
   heller Grauton, der wie ein Aufleuchten der Schrift wirkt. */
*,
*::before,
*::after {
  transition: background-color 0.35s ease, border-color 0.35s ease,
    box-shadow 0.35s ease, fill 0.35s ease;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text-primary);
  line-height: 1.5;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
}

.icon {
  width: 17px;
  height: 17px;
  flex-shrink: 0;
  display: inline-block;
  vertical-align: middle;
}

.icon-sm {
  width: 14px;
  height: 14px;
}

.icon-xs {
  width: 11px;
  height: 11px;
}

.icon-lg {
  width: 30px;
  height: 30px;
}

/* ---------------------------------------------------------------------- */
/* Layout: Sidebar + Content                                              */
/* ---------------------------------------------------------------------- */

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

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-fg);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  padding: 20px 20px 16px;
}

.sidebar-logo {
  display: block;
  height: 26px;
  width: auto;
}

.sidebar-logo-icon {
  display: none;
}

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

.sidebar-search {
  padding: 0 12px 8px;
}

.sidebar-search .filter-suche {
  font-size: 0.82rem;
}

.sidebar-nav .sidebar-search-link {
  display: none;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--sidebar-fg);
  text-decoration: none;
  font-size: 0.86rem;
  font-weight: 500;
  transition: background 0.12s ease, color 0.12s ease;
}

.sidebar-link .icon {
  color: var(--sidebar-fg-muted);
  transition: color 0.12s ease;
}

.sidebar-link:hover {
  background: var(--sidebar-active-bg);
  color: #fff;
}

.sidebar-link-hinweis .icon {
  color: var(--warning);
}

.sidebar-link:hover .icon {
  color: #fff;
}

.sidebar-link.active {
  background: var(--accent);
  color: #fff;
}

.sidebar-link.active .icon {
  color: #fff;
}

.sidebar-footer {
  margin-top: auto;
  padding: 14px 16px;
  border-top: 1px solid var(--sidebar-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  color: inherit;
  text-decoration: none;
  border-radius: var(--radius-sm);
}

.sidebar-user:hover {
  color: inherit;
}

.sidebar-user:hover .user-name {
  color: var(--accent);
}

.user-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--sidebar-active-bg);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 650;
  flex-shrink: 0;
}

.user-avatar.avatar-farbe-0 { background: var(--accent-soft); color: var(--accent); }
.user-avatar.avatar-farbe-1 { background: var(--avatar-blau-soft); color: var(--avatar-blau); }
.user-avatar.avatar-farbe-2 { background: var(--warning-soft); color: var(--warning); }
.user-avatar.avatar-farbe-3 { background: var(--avatar-lila-soft); color: var(--avatar-lila); }
.user-avatar.avatar-farbe-4 { background: var(--danger-soft); color: var(--danger); }

.user-name {
  font-size: 0.8rem;
  color: var(--sidebar-fg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-footer-aktionen {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.sidebar-icon-btn {
  padding: 7px;
  flex-shrink: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  font-family: inherit;
}

.theme-switch {
  position: relative;
  flex-shrink: 0;
  width: 46px;
  height: 25px;
  margin-right: 2px;
  padding: 0;
  border: none;
  border-radius: 999px;
  background: var(--sidebar-active-bg);
  cursor: pointer;
  font-family: inherit;
}

.theme-switch-icon {
  position: absolute;
  top: 50%;
  width: 13px;
  height: 13px;
  transform: translateY(-50%);
  color: var(--sidebar-fg-muted);
  display: flex;
  transition: color 0.35s ease;
}

.theme-switch-icon--sun {
  left: 6px;
}

.theme-switch-icon--moon {
  right: 6px;
}

.theme-switch-icon .icon {
  width: 100%;
  height: 100%;
}

.theme-switch-thumb {
  position: absolute;
  top: 2.5px;
  left: 2.5px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  transition: transform 0.3s cubic-bezier(0.65, 0, 0.35, 1), color 0.3s ease;
  transform: translateX(0);
}

.theme-switch-thumb .icon {
  width: 12px;
  height: 12px;
}

.theme-switch-thumb .theme-icon {
  position: absolute;
  display: flex;
  opacity: 0;
  transform: scale(0.5) rotate(-45deg);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.theme-switch-thumb .theme-icon.is-active {
  opacity: 1;
  transform: scale(1) rotate(0deg);
}

.theme-switch[data-theme-state="dark"] .theme-switch-thumb {
  transform: translateX(21px);
}

.theme-switch[data-theme-state="dark"] .theme-switch-icon--moon {
  color: var(--sidebar-fg);
}

.theme-switch[data-theme-state="light"] .theme-switch-icon--sun {
  color: #f2b53d;
}

.app-main {
  flex: 1;
  min-width: 0;
}

.app-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 36px 40px 80px;
}

@media (max-width: 860px) {
  .sidebar {
    width: 72px;
  }
  .user-name,
  .sidebar-link span:not(.icon) {
    display: none;
  }
  .sidebar-brand {
    justify-content: center;
    padding: 20px 0 16px;
  }
  .sidebar-logo-full {
    display: none;
  }
  .sidebar-logo-icon {
    display: block;
    height: 32px;
  }
  .sidebar-link {
    justify-content: center;
  }
  .sidebar-footer {
    justify-content: center;
  }
  .sidebar-user {
    display: none;
  }
  .sidebar-search {
    display: none;
  }
  .sidebar-nav .sidebar-search-link {
    display: flex;
  }
  .app-content {
    padding: 24px 20px 60px;
  }
  .bereich-karte > summary,
  .sammler-link,
  .seiten-kopf,
  .termin-toolbar {
    flex-wrap: wrap;
  }
  .aufgaben-tabelle th,
  .aufgaben-tabelle td {
    white-space: normal;
  }
}

/* ---------------------------------------------------------------------- */
/* Messages                                                                */
/* ---------------------------------------------------------------------- */

.messages {
  list-style: none;
  padding: 0;
  margin: 0 0 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.messages li {
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
}

.messages .success {
  background: var(--success-soft);
  color: var(--success);
}

.messages .error {
  background: var(--danger-soft);
  color: var(--danger);
}

.messages .warning {
  background: var(--warning-soft);
  color: var(--warning);
}

.messages .info {
  background: var(--accent-soft);
  color: var(--text-primary);
}

/* Dauerhafter Hinweis oben auf einer Seite (z. B. fehlender Kalender im
   Cockpit) – anders als Messages verschwindet er nicht nach einem Reload. */
.seiten-hinweis {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 16px;
  margin: 0 0 20px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
}

.seiten-hinweis > span {
  flex: 1 1 260px;
}

.seiten-hinweis.ist-warnung {
  background: var(--warning-soft);
  color: var(--warning);
}

.seiten-hinweis.ist-dringend {
  background: var(--danger-soft);
  color: var(--danger);
}

/* ---------------------------------------------------------------------- */
/* Buttons                                                                 */
/* ---------------------------------------------------------------------- */

.toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 20px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: none;
  border-radius: var(--radius-sm);
  padding: 9px 15px;
  font-size: 0.86rem;
  font-weight: 550;
  cursor: pointer;
  background: var(--accent);
  color: var(--accent-contrast);
  text-decoration: none;
  transition: background 0.12s ease, transform 0.05s ease;
  font-family: inherit;
}

.btn:hover {
  background: var(--accent-hover);
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.5;
  transform: none;
}

.btn:disabled:hover {
  background: var(--accent);
}

.btn-ghost:disabled:hover {
  background: transparent;
  color: var(--text-secondary);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-strong);
}

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

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

.btn-danger:hover {
  background: var(--danger);
  filter: brightness(0.9);
}

.btn-sm {
  padding: 6px 11px;
  font-size: 0.8rem;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  transition: background 0.12s ease, color 0.12s ease;
}

.btn-icon:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.btn-icon-badge {
  position: relative;
}

.icon-badge {
  position: absolute;
  top: 1px;
  right: 1px;
  min-width: 14px;
  height: 14px;
  padding: 0 3px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.6rem;
  font-weight: 700;
  line-height: 14px;
  text-align: center;
}

.icon-badge-warnung {
  min-width: 14px;
  padding: 1.5px;
  background: var(--warning);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-badge-warnung .icon {
  color: #fff;
}

/* ---------------------------------------------------------------------- */
/* Seiten-Kopf                                                             */
/* ---------------------------------------------------------------------- */

.seiten-kopf {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 16px;
}

.seiten-kopf-aktionen {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.zurueck-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-tertiary);
  text-decoration: none;
  font-size: 0.82rem;
  margin-bottom: 10px;
  transition: color 0.12s ease;
}

.zurueck-link:hover {
  color: var(--accent);
}

.seiten-titel {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  font-size: 1.3rem;
  letter-spacing: -0.01em;
}

.subtitle {
  color: var(--text-tertiary);
  font-size: 0.86rem;
  margin-top: 4px;
}
