:root {
  --bg: #faf9f7;
  --card-bg: #ffffff;
  --border: #e3e1de;
  --text: #202124;
  --muted: #6b6d72;
  --primary: #33363a;
  --primary-dark: #1c1d1f;
  --danger: #d64545;
  --green: #22a55d;
  --orange: #e8823c;
  --recurring: #2f7fc1;
  --sidebar-w: 240px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

body.app-shell {
  display: flex;
  align-items: stretch;
  min-height: 100vh;
}

/* Topbar: nur für den ausgeloggten Zustand (Login-Seite) — eingeloggt übernimmt die
   Sidebar (siehe unten) die Markenkennung. */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.5rem;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
}

.brand-link {
  text-decoration: none;
  color: var(--text);
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
}

.brand-logo {
  display: block;
  height: 44px;
  width: auto;
  border-radius: 6px;
}

.brand-sub {
  font-size: 0.65rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.brand-mark-lg { flex-direction: column; gap: 0.85rem; }
.brand-mark-lg .brand-logo { height: 84px; }
.brand-mark-lg .brand-sub { font-size: 0.8rem; }

/* Logo hat einen opaken weißen Hintergrund (kein Transparenz-PNG mit dunklem Rahmen) —
   braucht daher eine helle Karte, um auf der dunklen Sidebar nicht als weißer Klotz zu
   wirken bzw. mit der Sidebar-Farbe zu kollidieren. */
.brand-mark-sidebar { flex-direction: column; align-items: flex-start; gap: 0.7rem; }
.brand-mark-sidebar .brand-logo {
  height: 68px;
  background: #fff;
  padding: 10px;
  border-radius: 10px;
  box-sizing: content-box;
}
.brand-mark-sidebar .brand-sub { font-size: 0.7rem; }

/* ── Sidebar (eingeloggter Zustand) ───────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--primary);
  color: rgba(255, 255, 255, 0.85);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  padding: 1.5rem 1.25rem 1.25rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}

.sidebar-brand .brand-link { color: #fff; }
.sidebar-brand .brand-sub { color: rgba(255, 255, 255, 0.45); }

.sidebar-nav {
  flex: 1;
  padding: 0.75rem 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.sidebar-section {
  font-size: 0.625rem;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.35);
  padding: 0.85rem 0.7rem 0.4rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.65);
  font-size: 0.85rem;
  font-weight: 500;
  text-decoration: none;
}

.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; opacity: 0.8; }
.nav-item:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.nav-item.active { background: rgba(255, 255, 255, 0.14); color: #fff; font-weight: 600; }

.sidebar-user {
  position: relative;
  padding: 0.75rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}

.user-menu-button {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  background: none;
  border: none;
  padding: 0.4rem;
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
  text-align: left;
}

.user-menu-button:hover { background: rgba(255, 255, 255, 0.08); }

.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 700;
  flex-shrink: 0;
  letter-spacing: 0.02em;
}

.user-name {
  font-size: 0.85rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-menu-dropdown {
  display: none;
  position: absolute;
  left: 0.75rem;
  right: 0.75rem;
  bottom: calc(100% + 0.4rem);
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.18);
  padding: 0.3rem;
  z-index: 1000;
}

.user-menu-dropdown.open { display: block; }

.user-menu-dropdown a {
  display: block;
  padding: 0.45rem 0.6rem;
  border-radius: 4px;
  font-size: 0.85rem;
  color: var(--text);
  text-decoration: none;
}

.user-menu-dropdown a:hover { background: var(--bg); color: var(--text); }

.content {
  flex: 1;
  min-width: 0;
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.5rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05), 0 1px 2px rgba(0, 0, 0, 0.03);
}

body.login-page {
  background: radial-gradient(circle at 50% -10%, #eceded 0%, var(--bg) 60%);
  min-height: 100vh;
}

body.login-page .content {
  max-width: none;
  padding: 0;
}

.login-wrap {
  min-height: calc(100vh - 57px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.login-card {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 2.5rem 2rem;
  box-shadow: 0 20px 45px rgba(31, 36, 48, 0.08);
  border-radius: 14px;
}

.login-card h1 {
  margin: 1.25rem 0 0.25rem;
  font-size: 1.3rem;
}

.login-hint {
  margin: 0 0 1.5rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.login-card form {
  width: 100%;
  text-align: left;
}

.login-card label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.login-card input {
  width: 100%;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  margin-bottom: 1.1rem;
}

.login-card input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(51, 54, 58, 0.15);
}

.login-card button {
  width: 100%;
  padding: 0.65rem;
  font-size: 0.95rem;
}

.alert-error {
  width: 100%;
  background: #fdecec;
  color: #b3261e;
  border: 1px solid #f6c8c5;
  border-radius: 8px;
  padding: 0.6rem 0.8rem;
  font-size: 0.85rem;
  margin-bottom: 1.1rem;
}

.flash-messages { margin-bottom: 1rem; }

.alert-warning {
  background: #fdf3e3;
  color: #8a5a12;
  border: 1px solid #f3ddb0;
  border-radius: 8px;
  padding: 0.6rem 0.9rem;
  font-size: 0.85rem;
  margin-bottom: 0.6rem;
}

.alert-success {
  background: #e6f4ea;
  color: #1e7b3c;
  border: 1px solid #bfe3cb;
  border-radius: 8px;
  padding: 0.6rem 0.9rem;
  font-size: 0.85rem;
  margin-bottom: 0.6rem;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  gap: 1rem;
}

.page-header h1 { margin: 0; font-size: 1.4rem; }

.button, button {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  text-decoration: none;
  cursor: pointer;
}

.button:hover, button:hover { background: var(--primary-dark); }

.header-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.section-title {
  margin: 2rem 0 1rem;
  font-size: 1.1rem;
}

.inline-user-form {
  display: inline-flex;
  gap: 0.5rem;
  align-items: center;
  margin-right: 0.75rem;
}

.inline-user-form select,
.inline-user-form input {
  padding: 0.3rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.8rem;
}

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

.link-button {
  background: none;
  border: none;
  color: var(--danger);
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
  font-size: 0.85rem;
}

.inline-form { display: inline; }

.mailbox-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05), 0 1px 2px rgba(0, 0, 0, 0.03);
}

.mailbox-table th, .mailbox-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-size: 0.9rem;
  vertical-align: middle;
}

.mailbox-table th { background: #fafbfc; color: var(--muted); font-weight: 600; }

.actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }

.action-button {
  display: inline-block;
  font-size: 0.8rem;
  padding: 0.3rem 0.65rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  line-height: 1.2;
}
.action-button:hover { background: var(--bg); }
.action-button.danger { color: var(--danger); border-color: var(--danger); }

.muted { color: var(--muted); font-size: 0.85rem; }

.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}

.badge-enabled { background: #fde8dc; color: #b3541e; }
.badge-disabled { background: #e6f4ea; color: #1e7b3c; }
.badge-config { background: #e9e9ea; color: var(--primary); }
.badge-error { background: #fdecec; color: #b3261e; }
.badge-manual { background: #ede7f6; color: #5e35b1; }
.badge-login { background: #e3f2fd; color: #1565c0; }

.guide-content h2 { margin: 2rem 0 0.75rem; font-size: 1.15rem; }
.guide-content h2:first-child { margin-top: 0; }
.guide-content h3 { margin: 1.25rem 0 0.5rem; font-size: 1rem; }
.guide-content p { margin: 0 0 0.75rem; line-height: 1.6; }
.guide-content ul { margin: 0 0 0.75rem; padding-left: 1.25rem; }
.guide-content li { margin-bottom: 0.4rem; line-height: 1.55; }
.guide-content .hint-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.85rem 1rem;
  margin: 0 0 1rem;
  font-size: 0.88rem;
}

.filter-form {
  display: flex;
  gap: 1.5rem;
  margin-bottom: 1rem;
  padding: 1rem 1.5rem;
}

.filter-form label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}

.filter-form select {
  padding: 0.4rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
}

.error { color: var(--danger); }
.error.small { font-size: 0.8rem; margin-top: 0.25rem; }

.empty { color: var(--muted); }

.form label {
  display: block;
  margin-top: 1rem;
  margin-bottom: 0.25rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.form input[type="text"],
.form input[type="email"],
.form input[type="password"],
.form input[type="date"],
.form textarea,
.form select {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 400;
}

.form-actions {
  margin-top: 1.5rem;
  display: flex;
  gap: 0.75rem;
}

.legend {
  display: flex;
  gap: 1.5rem;
  margin-bottom: 1rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 0.35rem;
}

.dot-recurring { background: var(--recurring); }
.dot-add { background: var(--green); }
.dot-suppress { background: var(--orange); }

/* Kompaktere Zeitleiste (stündliche Slots statt der FullCalendar-Standardhöhe), damit
   ein ganzer Tag ohne Scrollen sichtbar ist. */
.fc .fc-timegrid-slot { height: 1.75em; }

/* Zeit-Achse: tabular-nums verhindert das leichte Springen der Beschriftung, das
   entsteht, weil Ziffern wie "1" in proportionalen Schriften schmaler sind als "0". */
.fc .fc-timegrid-axis-cushion,
.fc .fc-timegrid-slot-label-cushion {
  font-variant-numeric: tabular-nums;
}

.toolbar {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

#calendar {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
}

dialog {
  border: none;
  border-radius: 8px;
  padding: 0;
  max-width: 360px;
  width: 90%;
}

dialog::backdrop { background: rgba(0, 0, 0, 0.4); }

dialog form { padding: 1.5rem; }

dialog h2 { margin-top: 0; font-size: 1.1rem; }

dialog label {
  display: block;
  margin-top: 0.75rem;
  font-size: 0.85rem;
  color: var(--muted);
}

dialog input, dialog select {
  width: 100%;
  padding: 0.4rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-top: 0.2rem;
}

dialog .checkbox-label input { width: auto; }

.hint { font-size: 0.75rem; color: var(--muted); }

dialog .form-actions button[type="button"] {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

dialog .form-actions .link-button {
  border: none;
  color: var(--danger);
}

dialog.wide { max-width: 480px; }

.weekday-checkboxes {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 0.3rem;
}

.weekday-checkboxes label {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  margin-top: 0;
  font-size: 0.85rem;
}

.weekday-checkboxes input { width: auto; margin-top: 0; }

.view-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  margin-left: auto;
}

.view-toggle-btn {
  background: var(--card-bg);
  color: var(--muted);
  border: none;
  border-radius: 0;
  padding: 0.4rem 0.9rem;
  font-size: 0.85rem;
}

.view-toggle-btn.active {
  background: var(--primary);
  color: #fff;
}

.context-menu {
  position: absolute;
  z-index: 1000;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.15);
  padding: 0.3rem;
  min-width: 170px;
}

.context-menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  color: var(--text);
  border: none;
  border-radius: 4px;
  padding: 0.45rem 0.6rem;
  font-size: 0.85rem;
}

.context-menu button:hover { background: var(--bg); }
.context-menu button[data-action="delete"],
.context-menu button[data-action="delete-series"] { color: var(--danger); }
