/**
 * main.css - St. Ignatius Church App
 * Modern, warm design with subtle depth
 */

/* ============================================================
   CSS VARIABLES
   ============================================================ */
:root {
  /* Primary - Deep Navy Blue */
  --color-primary: #1e3a5f;
  --color-primary-light: #2d5a87;
  --color-primary-dark: #152a45;
  --color-primary-rgb: 30, 58, 95;
  
  /* Accent - Warm Gold */
  --color-accent: #c9a227;
  --color-accent-light: #dbb94d;
  --color-accent-dark: var(--brand-dark);
  
  /* Background - Subtle warm grays */
  --color-bg: #f5f5f3;
  --color-bg-elevated: #ffffff;
  --color-bg-subtle: #eceae6;
  --color-bg-hover: rgba(30, 58, 95, 0.06);
  --color-bg-active: rgba(30, 58, 95, 0.1);
  
  /* Borders */
  --color-border: #e0ddd8;
  --color-border-light: #ebe9e5;
  --color-border-focus: var(--color-primary-light);
  
  /* Text */
  --color-text: #2c2c2c;
  --color-text-secondary: #5a5a5a;
  --color-text-muted: #8a8a8a;
  --color-text-inverse: #ffffff;
  
  /* Status Colors */
  --color-success: #2d8659;
  --color-success-bg: #e8f5e9;
  --color-error: #c53030;
  --color-error-bg: #fff5f5;
  --color-warning: #c47f17;
  --color-warning-bg: #fffbeb;
  --color-info: #2b6cb0;
  --color-info-bg: #ebf8ff;
  
  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;
  
  /* Border Radius */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  --radius-full: 9999px;
  
  /* Shadows - Warmer, more subtle */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08), 0 2px 4px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.12), 0 4px 12px rgba(0, 0, 0, 0.06);
  --shadow-xl: 0 24px 60px rgba(0, 0, 0, 0.16), 0 8px 20px rgba(0, 0, 0, 0.08);
  --shadow-inner: inset 0 2px 4px rgba(0, 0, 0, 0.04);
  
  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
  --transition-slow: 400ms ease;
}

/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 1rem;
  line-height: 1.6;
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body.modal-open {
  overflow: hidden;
  position: fixed;
  width: 100%;
}

/* ============================================================
   LOGIN PAGE
   ============================================================ */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: var(--space-md);
  background: 
    linear-gradient(135deg, rgba(30, 58, 95, 0.95) 0%, rgba(45, 90, 135, 0.9) 100%),
    url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.05'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
  background-attachment: fixed;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--color-bg-elevated);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  padding: var(--space-xl);
  animation: slideUp 0.5s ease-out;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.login-header {
  text-align: center;
  margin-bottom: var(--space-xl);
}

.login-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-primary);
  margin-bottom: var(--space-xs);
  letter-spacing: -0.02em;
}

.login-header .subtitle {
  color: var(--color-text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
}

/* ============================================================
   FORMS
   ============================================================ */
.login-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-text);
  letter-spacing: 0.01em;
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
input[type="date"],
input[type="search"],
textarea,
select {
  width: 100%;
  padding: 14px 16px;
  font-size: 1rem;
  color: var(--color-text);
  background: var(--color-bg);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
  -webkit-appearance: none;
  appearance: none;
}

input:hover,
textarea:hover,
select:hover {
  border-color: var(--color-border-focus);
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--color-primary);
  background: var(--color-bg-elevated);
  box-shadow: 0 0 0 4px rgba(var(--color-primary-rgb), 0.12);
}

input::placeholder {
  color: var(--color-text-muted);
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%235a5a5a' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 40px;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: 14px 24px;
  font-size: 0.95rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
  white-space: nowrap;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.btn:active {
  transform: scale(0.98);
}

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

.btn-primary {
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-light) 100%);
  color: var(--color-text-inverse);
  box-shadow: var(--shadow-md), inset 0 1px 0 rgba(255,255,255,0.1);
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--color-primary-dark) 0%, var(--color-primary) 100%);
  box-shadow: var(--shadow-lg), inset 0 1px 0 rgba(255,255,255,0.1);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--color-bg-elevated);
  color: var(--color-text);
  border: 2px solid var(--color-border);
  box-shadow: var(--shadow-sm);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--color-bg-hover);
  border-color: var(--color-primary-light);
  color: var(--color-primary);
}

.btn-ghost {
  background: transparent;
  color: var(--color-text-secondary);
  padding: 10px 16px;
}

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

/* Kompakt-Schreibweise `class="btn primary"` / `class="btn ghost"`. Die ist im
   Code weit verbreitet (Service-Modal, AI-Modale, Settings), war global aber nie
   definiert — der Look kam zufällig aus den Stylesheets in modale/styles, die ihre Klassen
   ungescopt gestreut haben. Hier als echte Variante, damit er nicht davon
   abhängt, welches Modal zuletzt geladen wurde. Modul-Regeln wie
   `.dynamic-layout-dialog .btn.primary` sind spezifischer und gewinnen weiter. */
.btn.primary {
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-light) 100%);
  color: var(--color-text-inverse);
  box-shadow: var(--shadow-md), inset 0 1px 0 rgba(255,255,255,0.1);
}

.btn.primary:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--color-primary-dark) 0%, var(--color-primary) 100%);
  box-shadow: var(--shadow-lg), inset 0 1px 0 rgba(255,255,255,0.1);
  transform: translateY(-1px);
}

.btn.ghost {
  background: transparent;
  color: var(--color-text-secondary);
  padding: 10px 16px;
}

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

.btn-danger {
  background: linear-gradient(135deg, var(--color-error) 0%, #d64545 100%);
  color: var(--color-text-inverse);
}

.btn-success {
  background: linear-gradient(135deg, var(--color-success) 0%, #3a9d6a 100%);
  color: var(--color-text-inverse);
}

.btn-logout {
  background: transparent;
  color: var(--color-text-secondary);
  padding: 10px 14px;
  font-size: 0.85rem;
  border-radius: var(--radius-md);
}

.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: var(--radius-md);
}

.btn-sm {
  padding: 8px 14px;
  font-size: 0.85rem;
}

.btn .btn-loader {
  display: none;
}

.btn.loading .btn-text {
  display: none;
}

.btn.loading .btn-loader {
  display: flex;
  align-items: center;
  justify-content: center;
}

.spinner {
  animation: spin 0.8s linear infinite;
  width: 20px;
  height: 20px;
}

.spinner circle {
  stroke-dasharray: 50;
  stroke-dashoffset: 20;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ============================================================
   ALERTS
   ============================================================ */
.alert {
  padding: var(--space-md);
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 500;
  margin-top: var(--space-md);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.alert-error {
  background: var(--color-error-bg);
  color: var(--color-error);
  border-left: 4px solid var(--color-error);
}

.alert-success {
  background: var(--color-success-bg);
  color: var(--color-success);
  border-left: 4px solid var(--color-success);
}

.alert-info {
  background: var(--color-info-bg);
  color: var(--color-info);
  border-left: 4px solid var(--color-info);
}

/* ============================================================
   LOADING OVERLAY
   ============================================================ */
.loading-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, rgba(30, 58, 95, 0.97) 0%, rgba(45, 90, 135, 0.95) 100%);
  z-index: 9999;
}

.loading-content {
  text-align: center;
  max-width: 320px;
  padding: var(--space-xl);
  color: var(--color-text-inverse);
}

.loading-spinner {
  width: 56px;
  height: 56px;
  border: 4px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto var(--space-lg);
}

.loading-content h2 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: var(--space-sm);
  color: var(--color-text-inverse);
}

.loading-content p {
  color: rgba(255, 255, 255, 0.8);
  font-size: 0.95rem;
}

.progress-container {
  margin-top: var(--space-lg);
}

.progress-bar {
  height: 6px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--color-accent), var(--color-accent-light));
  border-radius: var(--radius-full);
  transition: width var(--transition-normal);
}

.progress-text {
  display: block;
  margin-top: var(--space-sm);
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.7);
}

/* ============================================================
   APP LAYOUT
   ============================================================ */
.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-sm) var(--space-md);
  background: var(--color-primary);
  color: var(--color-text-inverse);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-md);
}

.header-icon {
  font-size: 28px;
  flex-shrink: 0;
}

/* Tab Navigation in der main.css */
.tab-nav-wrap {
  position: relative;
  flex: 1;                      /* Nimmt den mittleren Platz ein */
  min-width: 0;
  margin-left: var(--space-xl);
  display: flex;
  align-items: center;
}

.tab-navigation {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  justify-content: flex-start;  /* Tabs starten links */
  overflow-x: auto;
  scroll-behavior: smooth;
  scrollbar-width: none;        /* Firefox */
}

/* Fade hints at the edges when more tabs are scrollable */
.tab-nav-wrap::before,
.tab-nav-wrap::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  width: 24px;
  pointer-events: none;
  z-index: 1;
  opacity: 0;
  transition: opacity var(--transition-fast);
}
.tab-nav-wrap::before { left: 26px; background: linear-gradient(to right, var(--color-primary, #1e3a5f), transparent); }
.tab-nav-wrap::after { right: 26px; background: linear-gradient(to left, var(--color-primary, #1e3a5f), transparent); }
.tab-nav-wrap.can-left::before { opacity: 1; }
.tab-nav-wrap.can-right::after { opacity: 1; }

.header-actions {
  flex-shrink: 0;               /* Button darf nicht kleiner werden */
  margin-left: var(--space-md);
}


.tab-navigation::-webkit-scrollbar {
  display: none;
}

.tab-btn {
  padding: 8px 16px;
  font-size: 0.85rem;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.75);
  background: transparent;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  flex-shrink: 0;
}

.tab-btn:hover {
  color: var(--color-text-inverse);
  background: rgba(255, 255, 255, 0.1);
}

.tab-btn.active {
  color: var(--color-primary);
  background: var(--color-text-inverse);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-shrink: 0;
}

.btn-logout {
  color: rgba(255, 255, 255, 0.8);
  background: rgba(255, 255, 255, 0.1);
}

.btn-logout:hover {
  color: var(--color-text-inverse);
  background: rgba(255, 255, 255, 0.2);
}

.user-info {
  display: none;
}

/* Tab Content */
.tab-content {
  flex: 1;
  padding: var(--space-md);
  background: var(--color-bg);
  overflow-x: hidden;
}

.no-tabs-message,
.error-message {
  text-align: center;
  padding: var(--space-2xl) var(--space-lg);
  background: var(--color-bg-elevated);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.no-tabs-message h3,
.error-message h3 {
  color: var(--color-text);
  margin-bottom: var(--space-sm);
  font-size: 1.25rem;
}

.no-tabs-message p,
.error-message p {
  color: var(--color-text-secondary);
}

/* ============================================================
   CARDS
   ============================================================ */
.card {
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card-header {
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--color-border-light);
  background: var(--color-bg-subtle);
}

.card-header h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text);
}

.card-body {
  padding: var(--space-lg);
}

.card-footer {
  padding: var(--space-md) var(--space-lg);
  border-top: 1px solid var(--color-border-light);
  background: var(--color-bg-subtle);
}

/* ============================================================
   MODALS - Mobile First (Bottom Sheet)
   ============================================================ */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  /* KEINE eigene Abdunklung: die kommt vom Backdrop des modal-managers und deckt
     dann auch die Sidebar mit ab. Eine zweite Lage hier machte die Inhaltsfläche
     dunkler als das Menü links (Etikettendruck) bzw. war die einzige Lage und
     damit heller als überall sonst (Archiv-Detail). */
  background: transparent;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  z-index: 1000;
}

.modal.modal-active {
  display: flex;
}

.modal-content {
  background: var(--color-bg-elevated);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-height: 90vh;
  max-height: 90dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: slideUpModal 0.3s ease-out;
}

@keyframes slideUpModal {
  from {
    opacity: 0;
    transform: translateY(100%);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--color-border-light);
  background: var(--color-bg-subtle);
  position: sticky;
  top: 0;
}

.modal-header::before {
  content: '';
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: 40px;
  height: 4px;
  background: var(--color-border);
  border-radius: var(--radius-full);
}

.modal-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--color-text);
  padding-top: var(--space-sm);
}

.modal-close {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg-hover);
  border: none;
  border-radius: var(--radius-full);
  color: var(--color-text-secondary);
  cursor: pointer;
  font-size: 1.25rem;
  transition: all var(--transition-fast);
  margin-top: var(--space-sm);
}

.modal-close:hover {
  background: var(--color-bg-active);
  color: var(--color-text);
}

.modal-body {
  flex: 1;
  /* min-height:0 ist Pflicht: ohne das behält ein Flex-Kind seine Inhaltshöhe
     (min-height:auto) und schiebt die Box über den Viewport hinaus — der Body
     scrollt dann nie, das Modal wird stattdessen oben/unten abgeschnitten. */
  min-height: 0;
  padding: var(--space-lg);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.modal-footer {
  display: flex;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  border-top: 1px solid var(--color-border-light);
  background: var(--color-bg-subtle);
}

.modal-footer .btn {
  flex: 1;
}

/* ============================================================
   TABLES
   ============================================================ */
.table-container {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 calc(-1 * var(--space-lg));
  padding: 0 var(--space-lg);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 600px;
}

th, td {
  padding: var(--space-md);
  text-align: left;
  border-bottom: 1px solid var(--color-border-light);
}

th {
  font-weight: 600;
  color: var(--color-text-secondary);
  background: var(--color-bg-subtle);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  position: sticky;
  top: 0;
}

td {
  font-size: 0.95rem;
  color: var(--color-text);
}

tbody tr {
  transition: background-color var(--transition-fast);
}

tbody tr:hover {
  background-color: var(--color-bg-hover);
}

tbody tr:active {
  background-color: var(--color-bg-active);
}

/* ============================================================
   BADGES
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: var(--radius-full);
  letter-spacing: 0.02em;
}

/* ============================================================
   UTILITY CLASSES
   ============================================================ */
.text-muted { color: var(--color-text-muted); }

.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }

.hidden { display: none !important; }
.visible { display: block !important; }

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ============================================================
   RESPONSIVE - TABLET AND UP
   ============================================================ */
@media (min-width: 768px) {
  .login-card {
    padding: var(--space-2xl);
  }
  
  .app-header {
    padding: var(--space-md) var(--space-lg);
  }
  
  .tab-btn {
    padding: 10px 20px;
    font-size: 0.9rem;
  }
  
  .tab-content {
    padding: var(--space-lg);
  }
  
  /* Modal centered on tablet+ */
  .modal {
    align-items: center;
    padding: var(--space-lg);
  }
  
  .modal-content {
    border-radius: var(--radius-xl);
    max-width: 600px;
    max-height: 85vh;
    animation: fadeInScale 0.3s ease-out;
  }
  
  @keyframes fadeInScale {
    from {
      opacity: 0;
      transform: scale(0.95);
    }
    to {
      opacity: 1;
      transform: scale(1);
    }
  }
  
  .modal-header::before {
    display: none;
  }
  
  .modal-header h2 {
    padding-top: 0;
  }
  
  .modal-close {
    margin-top: 0;
  }
  
  .modal-footer .btn {
    flex: none;
  }
  
  .modal-xl .modal-content {
    max-width: 1100px;
  }
  
  .user-info {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-full);
    font-size: 0.85rem;
    color: var(--color-text-secondary);
    box-shadow: var(--shadow-sm);
    position: fixed;
    bottom: var(--space-md);
    right: var(--space-md);
    cursor: pointer;
    transition: background 0.2s, box-shadow 0.2s;
  }
  .user-info:hover {
    background: var(--color-bg-hover, #e2e8f0);
    box-shadow: var(--shadow-md);
  }
}

/* ============================================================
   RESPONSIVE - DESKTOP AND UP
   ============================================================ */
@media (min-width: 1024px) {
  .app-header {
    padding: var(--space-md) var(--space-xl);
  }
  
  .tab-content {
    padding: var(--space-xl);
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
  }
}

/* ============================================================
   SAFE AREA INSETS (for notched devices)
   ============================================================ */
@supports (padding: max(0px)) {
  .app-header {
    padding-left: max(var(--space-md), env(safe-area-inset-left));
    padding-right: max(var(--space-md), env(safe-area-inset-right));
    padding-top: max(var(--space-sm), env(safe-area-inset-top));
  }
  
  .tab-content {
    padding-left: max(var(--space-md), env(safe-area-inset-left));
    padding-right: max(var(--space-md), env(safe-area-inset-right));
    padding-bottom: max(var(--space-md), env(safe-area-inset-bottom));
  }
  
  .modal-content {
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* ============================================================
   ONLINE-PRESENCE BADGE (im Header)
   ============================================================ */
.presence-badge {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  margin-right: 12px;
  background: rgba(16, 185, 129, 0.1);
  color: #059669;
  border: 1px solid rgba(16, 185, 129, 0.25);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  cursor: default;
  transition: background 0.15s;
}
.presence-badge:hover {
  background: rgba(16, 185, 129, 0.18);
}
.presence-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #10b981;
  /* Static ring: an endless box-shadow pulse repaints every frame and keeps an idle tab busy. */
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
}
.presence-list {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 220px;
  max-height: 300px;
  overflow-y: auto;
  padding: 8px 0;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  font-size: 13px;
  font-weight: 400;
  color: #111827;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: opacity 0.15s, transform 0.15s, visibility 0.15s;
  z-index: 100;
}
.presence-badge:hover .presence-list {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}
.presence-list-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
}
.presence-list-item:hover {
  background: #f9fafb;
}
.presence-list-item .presence-list-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #10b981;
}
.presence-list-empty {
  padding: 12px;
  text-align: center;
  color: #9ca3af;
}

/* ============================================================
   DISMISSAL FIELD (Children's / OCIA)
   ============================================================ */
/* ============================================================
   AI-ASSISTANT SIDEBAR
   ============================================================ */
.ai-toggle {
  position: fixed;
  right: 18px;
  bottom: 18px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(102, 126, 234, 0.45);
  font-size: 24px;
  /* hoch genug, um auch über offenen Modalen (z-index ~1000+) klickbar zu bleiben */
  z-index: 100000;
  transition: transform 0.15s, box-shadow 0.15s;
}
.ai-toggle:hover { transform: scale(1.06); box-shadow: 0 6px 18px rgba(102,126,234,0.55); }
.ai-toggle .ai-toggle-icon { line-height: 1; }
body.ai-sidebar-open .ai-toggle { display: none !important; }

.ai-sidebar {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 420px;
  max-width: 95vw;
  background: #fff;
  border-left: 1px solid #e5e7eb;
  box-shadow: -8px 0 24px rgba(0,0,0,0.08);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  /* über offenen Modalen anzeigbar (modalManager: z-index ab 1010) */
  z-index: 100000;
}
body.ai-sidebar-open .ai-sidebar { transform: translateX(0); }

.ai-sidebar-header {
  padding: 16px 16px 0;
  border-bottom: 1px solid #e5e7eb;
  background: linear-gradient(135deg, #667eea08 0%, #764ba208 100%);
}
.ai-sidebar-header h3 {
  margin: 0 0 12px;
  font-size: 17px;
  font-weight: 600;
}
.ai-sidebar-tabs {
  display: flex;
  gap: 4px;
}
.ai-tab {
  padding: 8px 14px;
  background: transparent;
  border: none;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  font-weight: 500;
  font-size: 13px;
  color: #6b7280;
  transition: color 0.15s, border-color 0.15s;
}
.ai-tab:hover { color: #111827; }
.ai-tab.active {
  color: #4f46e5;
  border-bottom-color: #4f46e5;
}
.ai-sidebar-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 28px;
  height: 28px;
  background: transparent;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: #9ca3af;
  line-height: 1;
}
.ai-sidebar-close:hover { color: #111827; }

/* Float/Dock-Button (per JS in den Header injiziert) */
.ai-float-btn {
  position: absolute;
  top: 18px;
  right: 52px;
  width: 28px;
  height: 28px;
  padding: 0;
  background: transparent;
  border: none;
  font-size: 16px;
  cursor: pointer;
  color: #9ca3af;
  line-height: 1;
}
.ai-float-btn:hover { color: #111827; }

/* Floating-Modus: frei verschiebbares Fenster statt angedockter Sidebar.
   left/top werden ausschließlich per JS gesetzt (funktionale Drag-Position). */
.ai-sidebar.floating {
  top: 70px;
  left: auto;
  right: auto;
  bottom: auto;
  width: 420px;
  max-width: calc(100vw - 12px);
  height: min(640px, calc(100vh - 24px));
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.22);
  transform: none;
  transition: none;
  display: none;
}
body.ai-sidebar-open .ai-sidebar.floating { display: flex; }
.ai-sidebar.floating .ai-sidebar-header {
  cursor: grab;
  user-select: none;
  touch-action: none;
}
.ai-sidebar.floating.ai-dragging { user-select: none; }
.ai-sidebar.floating.ai-dragging .ai-sidebar-header { cursor: grabbing; }

/* Chat-Fehlerbubble + manueller Retry */
.ai-message-error .ai-message-bubble {
  background: #fef2f2;
  border: 1px solid #fca5a5;
  color: #991b1b;
}
.ai-retry-btn {
  display: block;
  margin-top: 8px;
  padding: 6px 12px;
  border: 1px solid #667eea;
  border-radius: 6px;
  background: #fff;
  color: #667eea;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.ai-retry-btn:hover { background: #eef2ff; }

.ai-sidebar-body {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.ai-pane {
  display: none;
  flex: 1;
  overflow: hidden;
  flex-direction: column;
}
.ai-pane.active { display: flex; }

/* Chat */
.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.ai-message { display: flex; }
.ai-message-user { justify-content: flex-end; }
.ai-message-bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.45;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.ai-message-bubble.ai-plain { white-space: pre-wrap; }
.ai-message-bot .ai-message-bubble {
  background: #f3f4f6;
  color: #111827;
  border-bottom-left-radius: 4px;
}
.ai-message-user .ai-message-bubble {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  border-bottom-right-radius: 4px;
}

/* ── Markdown-Rendering in Bot-Bubbles ── */
.ai-message-bubble.ai-markdown > *:first-child { margin-top: 0; }
.ai-message-bubble.ai-markdown > *:last-child  { margin-bottom: 0; }
.ai-md-p { margin: 0 0 8px 0; }
.ai-md-h1, .ai-md-h2, .ai-md-h3, .ai-md-h4, .ai-md-h5, .ai-md-h6 {
  margin: 12px 0 6px 0;
  font-weight: 700;
  line-height: 1.25;
}
.ai-md-h1 { font-size: 1.25rem; }
.ai-md-h2 { font-size: 1.15rem; }
.ai-md-h3 { font-size: 1.05rem; }
.ai-md-h4, .ai-md-h5, .ai-md-h6 { font-size: 1rem; }

.ai-md-list { margin: 4px 0 8px 0; padding-left: 20px; }
.ai-md-list li { margin: 2px 0; }
.ai-md-list .ai-md-list { margin: 2px 0 2px 0; }

.ai-md-quote {
  margin: 6px 0 8px 0;
  padding: 4px 10px;
  border-left: 3px solid #c7d2fe;
  color: #4b5563;
  background: rgba(199, 210, 254, 0.15);
  border-radius: 0 6px 6px 0;
}

.ai-md-hr {
  border: 0;
  border-top: 1px solid #e5e7eb;
  margin: 10px 0;
}

.ai-md-inline-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
  padding: 1px 5px;
  background: rgba(15, 23, 42, 0.08);
  border-radius: 4px;
}
.ai-md-code {
  margin: 6px 0 10px 0;
  padding: 10px 12px;
  background: #0f172a;
  color: #e5e7eb;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 12.5px;
  line-height: 1.5;
}
.ai-md-code code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: transparent;
  color: inherit;
  padding: 0;
}

.ai-md-table-wrap {
  margin: 6px 0 10px 0;
  overflow-x: auto;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
}
.ai-md-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
}
.ai-md-table th,
.ai-md-table td {
  padding: 6px 10px;
  border-bottom: 1px solid #e5e7eb;
  vertical-align: top;
}
.ai-md-table th {
  background: #f9fafb;
  font-weight: 600;
  border-bottom-color: #d1d5db;
}
.ai-md-table tr:last-child td { border-bottom: 0; }

.ai-message-bot .ai-message-bubble a {
  color: #4f46e5;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.ai-message-bot .ai-message-bubble a:hover { text-decoration: none; }
.ai-message-thinking .ai-message-bubble::after {
  content: '...';
  animation: ai-dots 1.4s infinite;
}
@keyframes ai-dots {
  0%, 20%   { content: '.'; }
  40%       { content: '..'; }
  60%, 100% { content: '...'; }
}
.ai-chat-input {
  padding: 12px;
  border-top: 1px solid #e5e7eb;
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.ai-chat-input textarea {
  flex: 1;
  min-height: 40px;
  max-height: 120px;
  padding: 8px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 14px;
  resize: none;
  font-family: inherit;
}
.ai-chat-input textarea:focus {
  outline: none;
  border-color: #667eea;
}
.ai-send-btn {
  padding: 8px 12px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  font-weight: 600;
}
.ai-send-btn:hover { opacity: 0.9; }
.ai-send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Search */
.ai-search-intro {
  padding: 16px;
  font-size: 13px;
  color: #6b7280;
  border-bottom: 1px solid #f3f4f6;
}
.ai-search-form {
  padding: 12px 16px;
  display: flex;
  gap: 8px;
}
.ai-search-form input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 14px;
}
.ai-search-results {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  font-size: 13px;
}
.ai-search-result-item {
  padding: 10px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  margin-bottom: 8px;
  background: #fff;
}
.ai-search-result-item:hover {
  background: #f9fafb;
}

/* Insights */
.ai-insights-loading {
  padding: 24px;
  text-align: center;
  color: #9ca3af;
  font-size: 13px;
}
.ai-insights-cards {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.ai-insight-card {
  padding: 14px;
  background: #f9fafb;
  border-left: 3px solid #667eea;
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.5;
}
.ai-insight-card .ai-insight-title {
  font-weight: 600;
  margin-bottom: 6px;
  color: #111827;
}

@media (max-width: 600px) {
  .ai-sidebar { width: 100vw; }
}

/* ============================================================
   AI-REPERTOIRE-MODAL
   ============================================================ */
.ai-rep-overlay {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 1500;
  padding: 16px;
  backdrop-filter: blur(4px);
}
.ai-rep-modal {
  background: #fff;
  width: 100%; max-width: 640px;
  max-height: 90vh;
  border-radius: 14px;
  display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  overflow: hidden;
}
.ai-rep-header {
  padding: 18px 22px;
  border-bottom: 1px solid #e5e7eb;
  background: linear-gradient(135deg, #667eea08 0%, #764ba208 100%);
  display: flex; align-items: center; justify-content: space-between;
}
.ai-rep-header h3 { margin: 0; font-size: 18px; }
.ai-rep-close { background: none; border: none; font-size: 28px; cursor: pointer; color: #6b7280; }
.ai-rep-body { flex: 1; overflow-y: auto; padding: 20px; }
.ai-rep-loading {
  text-align: center; color: #6b7280; padding: 40px 20px; font-size: 14px;
}
.ai-rep-error { color: #dc2626; padding: 16px; background: #fef2f2; border-radius: 6px; }
.ai-rep-suggestion { margin-bottom: 14px; }
.ai-rep-slot-label {
  font-size: 11px; font-weight: 600; color: #6b7280;
  text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 4px;
}
.ai-rep-card {
  padding: 14px; border: 2px solid #e5e7eb; border-radius: 10px;
  transition: border-color 0.15s, background 0.15s;
}
.ai-rep-suggestion.ai-rep-accepted .ai-rep-card { border-color: #10b981; background: #f0fdf4; }
.ai-rep-suggestion.ai-rep-rejected .ai-rep-card { border-color: #fca5a5; background: #fef2f2; opacity: 0.6; }
.ai-rep-title { font-weight: 600; font-size: 15px; margin-bottom: 6px; }
.ai-rep-reason { color: #4b5563; font-size: 13px; margin-bottom: 8px; line-height: 1.4; }
.ai-rep-meta { font-size: 11px; color: #9ca3af; margin-bottom: 10px; }
.ai-rep-actions { display: flex; gap: 8px; justify-content: flex-end; }
.ai-rep-footer {
  padding: 14px 20px; border-top: 1px solid #e5e7eb;
  display: flex; justify-content: flex-end; gap: 8px;
}

/* ============================================================
   REMINDERS BELL
   ============================================================ */
.reminders-bell {
  position: relative;
  background: transparent;
  border: 1px solid var(--color-border, #e5e7eb);
  border-radius: 999px;
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  margin-right: 8px;
  color: var(--color-text-soft, #6b7280);
}
.reminders-bell:hover { background: var(--color-bg-soft, #f9fafb); }
.reminders-bell.has-unread { color: #4f46e5; }
.reminders-bell-badge {
  position: absolute;
  top: -4px; right: -4px;
  background: #dc2626; color: #fff;
  font-size: 10px; font-weight: 700;
  min-width: 16px; height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  display: none;
  align-items: center; justify-content: center;
  line-height: 1;
}
.reminders-bell.has-unread .reminders-bell-badge { display: inline-flex; }
.reminders-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 320px;
  max-height: 400px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  display: none;
  z-index: 100;
  text-align: left;
  font-size: 13px;
  font-weight: normal;
  color: #111827;
}
.reminders-bell.open .reminders-dropdown { display: block; }
.reminder-item {
  padding: 10px 14px;
  border-bottom: 1px solid #f3f4f6;
  cursor: pointer;
}
.reminder-item:hover { background: #f9fafb; }
.reminder-item.is-read { opacity: 0.55; }
.reminder-item-title { font-weight: 600; margin-bottom: 4px; }
.reminder-item-body { color: #6b7280; font-size: 12px; }
.reminder-item-time { color: #9ca3af; font-size: 11px; margin-top: 4px; }
.reminders-empty { padding: 24px; text-align: center; color: #9ca3af; }

/* Dashboard Charts */
.dash-charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
  padding: 16px;
}
.dash-chart-card {
  background: var(--color-bg-card, #fff);
  border: 1px solid var(--color-border, #e5e7eb);
  border-radius: 10px;
  padding: 16px;
}
/* Feste Diagrammhoehe (Chart.js maintainAspectRatio:false) — sonst wachsen die Balken-
   diagramme mit der Breite und das Dashboard braucht Scrollen. */
.dash-chart-box { position: relative; height: 220px; }
.dash-chart-card h4 {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text, #111827);
}
.dash-error { color: #dc2626; padding: 16px; }

/* ============================================================
   FAB-STACK: Email + AI gleich groß, übereinander unten rechts
   ============================================================ */
#admin-email-btn,
#ai-toggle {
  position: fixed;
  right: 18px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(102, 126, 234, 0.35);
  transition: transform 0.15s, box-shadow 0.15s;
  padding: 0;
  /* über offenen Modalen (modalManager: z-index ab 1010) klickbar bleiben */
  z-index: 100000;
}
#admin-email-btn:hover,
#ai-toggle:hover {
  transform: scale(1.06);
  box-shadow: 0 6px 18px rgba(102, 126, 234, 0.55);
}

/* Untenanbau: Email zuerst, AI darüber */
#admin-email-btn { bottom: 18px; }
#ai-toggle       { bottom: 86px; }   /* 18 + 56 + 12 gap */

/* Email-Button: gleiches Gradient-Look wie AI */
#admin-email-btn {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: #fff;
  border: none;
}
#admin-email-btn span {
  font-size: 22px;
  line-height: 1;
}

/* AI-Toggle: ungeändert (bleibt purple) */
.ai-toggle .ai-toggle-icon { font-size: 22px; }

body.ai-sidebar-open #ai-toggle { display: none !important; }

/* ============================================================
   LITURGICAL SEASON BANDS
   ============================================================
   Dünner Farb-Strip am linken Rand der ersten Zelle jeder Service-Row
   — zeigt die liturgische Jahreszeit, ohne mit rowClass-Farben zu kollidieren.
   Farben folgen traditioneller Liturgie:
     Advent=Purple, Christmas=Gold, Lent=Violet, Easter=Gold, Ordinary=Green
   Ordinary wird bewusst nicht dekoriert (ist der Default-Zustand).
   ============================================================ */
tr[data-liturgical-season="ADVENT"] > td:first-child {
    box-shadow: inset 4px 0 0 #6b21a8;
}
tr[data-liturgical-season="CHRISTMAS"] > td:first-child {
    box-shadow: inset 4px 0 0 #d4a017;
}
tr[data-liturgical-season="LENT"] > td:first-child {
    box-shadow: inset 4px 0 0 #7c3aed;
}
tr[data-liturgical-season="EASTER"] > td:first-child {
    box-shadow: inset 4px 0 0 #eab308;
}
tr[data-liturgical-season="HOLY_WEEK"] > td:first-child {
    box-shadow: inset 4px 0 0 #b91c1c;
}

/* ============================================================
   MOBILE <= 480px (small phones)
   ============================================================
   Stellt sicher dass Header, Tabs, Forms und Modals auf schmalen
   Screens nicht überlaufen oder winzige Tap-Targets haben.
   Modul-spezifische Mobile-Anpassungen leben in den jeweiligen
   Modul-CSS-Dateien (z.B. AbsencesChoir.css, Services.css).
   ============================================================ */
@media (max-width: 480px) {
  /* Header: platzsparend */
  .app-header {
    padding: var(--space-xs) var(--space-sm);
    gap: var(--space-xs);
  }
  .header-icon { font-size: 22px; }
  .tab-navigation {
    margin-left: var(--space-sm);
    gap: 4px;
  }
  .tab-btn {
    padding: 8px 10px;
    font-size: 0.78rem;
  }
  .header-actions { margin-left: var(--space-sm); }
  .header-actions .btn { padding: 8px 12px; font-size: 0.8rem; }
  .btn-logout { padding: 8px 12px; font-size: 0.8rem; }

  /* Touch-Targets: min 44px Klickfläche (WCAG 2.5.5 AAA, Apple HIG) */
  .btn,
  .btn-primary,
  .btn-secondary,
  .btn-danger,
  .btn-success {
    min-height: 44px;
    padding: 12px 18px;
  }
  .btn-icon {
    min-width: 40px;
    min-height: 40px;
  }

  /* Inputs: verhindert iOS-Zoom bei 16px + voller Breite */
  input[type="text"],
  input[type="password"],
  input[type="email"],
  input[type="number"],
  input[type="date"],
  input[type="search"],
  input[type="tel"],
  textarea,
  select {
    font-size: 16px; /* verhindert iOS-Auto-Zoom auf Focus */
    padding: 12px 14px;
  }

  /* Forms stacken komplett */
  .form-group,
  .form-row,
  .form-grid {
    grid-template-columns: 1fr !important;
    flex-direction: column !important;
  }

  /* Modals: volle Bildschirmbreite, weniger Padding */
  .modal,
  .modal-content,
  .ai-rep-modal {
    margin: 0 !important;
    max-width: 100vw !important;
    border-radius: 0 !important;
  }
  .modal-body,
  .ai-rep-body { padding: 14px; }
  .modal-header,
  .ai-rep-header { padding: 14px 16px; }

  /* Tables: Scrollbar erlauben statt Überlauf */
  table,
  .items-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Container-Padding reduzieren */
  main,
  #main-content,
  .module-container {
    padding: var(--space-sm);
  }
}

