/* ============================================================
   EDV-CRM · Design System
   Kolping-Mainfranken GmbH
   Dark / Light Mode · Einheitlich auf allen Seiten
   ============================================================ */

/* --- Tokens: Light Mode --- */
:root {
  --bg-body:        #f1f5f9;
  --bg-surface:     #ffffff;
  --bg-surface-2:   #f8fafc;
  --bg-sidebar:     #1e3a5f;
  --bg-sidebar-h:   #2d5280;
  --bg-topbar:      #ffffff;
  --bg-input:       #ffffff;
  --bg-hover:       #f1f5f9;
  --bg-badge:       #e0f2fe;

  --text-primary:   #0f172a;
  --text-secondary: #475569;
  --text-muted:     #94a3b8;
  --text-sidebar:   #cbd5e1;
  --text-sidebar-a: #ffffff;
  --text-link:      #2563eb;
  --text-on-accent: #ffffff;

  --border:         #e2e8f0;
  --border-strong:  #cbd5e1;
  --border-input:   #d1d5db;
  --border-focus:   #2563eb;

  --accent:         #1e3a5f;
  --accent-h:       #2d5280;
  --accent-btn:     #2563eb;
  --accent-btn-h:   #1d4ed8;

  --success-bg:     #dcfce7;
  --success-text:   #166534;
  --success-border: #bbf7d0;
  --warning-bg:     #fef9c3;
  --warning-text:   #854d0e;
  --warning-border: #fde68a;
  --danger-bg:      #fee2e2;
  --danger-text:    #991b1b;
  --danger-border:  #fecaca;
  --info-bg:        #dbeafe;
  --info-text:      #1e40af;
  --info-border:    #bfdbfe;

  --shadow-sm:      0 1px 3px rgba(0,0,0,.08);
  --shadow-md:      0 4px 12px rgba(0,0,0,.10);
  --shadow-lg:      0 10px 30px rgba(0,0,0,.12);

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

  --sidebar-w:      240px;
  --topbar-h:       60px;
  --font:           -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono:      'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  --transition:     .18s ease;
}

/* --- Tokens: Dark Mode --- */
[data-theme="dark"] {
  --bg-body:        #0f172a;
  --bg-surface:     #1e293b;
  --bg-surface-2:   #263244;
  --bg-sidebar:     #0f1f35;
  --bg-sidebar-h:   #1e3a5f;
  --bg-topbar:      #1e293b;
  --bg-input:       #1e293b;
  --bg-hover:       #263244;
  --bg-badge:       #1e3a5f;

  --text-primary:   #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted:     #64748b;
  --text-sidebar:   #94a3b8;
  --text-sidebar-a: #ffffff;
  --text-link:      #60a5fa;

  --border:         #1e293b;
  --border-strong:  #334155;
  --border-input:   #334155;
  --border-focus:   #3b82f6;

  --accent:         #0f1f35;
  --accent-h:       #1e3a5f;
  --accent-btn:     #3b82f6;
  --accent-btn-h:   #2563eb;

  --success-bg:     #14532d;
  --success-text:   #86efac;
  --success-border: #166534;
  --warning-bg:     #713f12;
  --warning-text:   #fde68a;
  --warning-border: #854d0e;
  --danger-bg:      #7f1d1d;
  --danger-text:    #fca5a5;
  --danger-border:  #991b1b;
  --info-bg:        #1e3a5f;
  --info-text:      #93c5fd;
  --info-border:    #1d4ed8;

  --shadow-sm:      0 1px 3px rgba(0,0,0,.3);
  --shadow-md:      0 4px 12px rgba(0,0,0,.4);
  --shadow-lg:      0 10px 30px rgba(0,0,0,.5);
}

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

html { font-size: 15px; -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg-body);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
}

a { color: var(--text-link); text-decoration: none; }
a:hover { text-decoration: underline; }

img { max-width: 100%; height: auto; display: block; }

/* ============================================================
   Layout
   ============================================================ */
.layout {
  display: flex;
  min-height: 100vh;
}

/* --- Sidebar --- */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  z-index: 100;
  transition: width var(--transition), transform var(--transition);
  overflow: hidden;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 20px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  text-decoration: none;
  min-height: var(--topbar-h);
}
.sidebar-logo-icon {
  width: 32px; height: 32px;
  background: var(--accent-btn);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-weight: 700; color: #fff; font-size: 14px;
}
.sidebar-logo-text { display: flex; flex-direction: column; }
.sidebar-logo-text strong { color: #fff; font-size: 14px; font-weight: 600; line-height: 1.2; }
.sidebar-logo-text span   { color: var(--text-sidebar); font-size: 11px; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 12px 0; }
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); border-radius: 2px; }

.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 16px 20px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px;
  color: var(--text-sidebar);
  text-decoration: none;
  font-size: 14px;
  border-left: 3px solid transparent;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  cursor: pointer;
  white-space: nowrap;
}
.nav-item:hover { background: var(--bg-sidebar-h); color: #fff; text-decoration: none; }
.nav-item.active {
  background: var(--bg-sidebar-h);
  color: #fff;
  border-left-color: var(--accent-btn);
  font-weight: 500;
}
.nav-item .nav-icon { width: 18px; height: 18px; flex-shrink: 0; opacity: .8; }
.nav-item.active .nav-icon, .nav-item:hover .nav-icon { opacity: 1; }
.nav-item .badge {
  margin-left: auto;
  font-size: 11px;
  background: var(--accent-btn);
  color: #fff;
  padding: 1px 7px;
  border-radius: 99px;
  font-weight: 500;
}

.sidebar-footer {
  border-top: 1px solid rgba(255,255,255,.08);
  padding: 12px;
}
.sidebar-user {
  display: flex; align-items: center; gap: 10px;
  padding: 8px;
  border-radius: var(--radius-md);
  transition: background var(--transition);
}
.sidebar-user:hover { background: var(--bg-sidebar-h); }
.sidebar-avatar {
  width: 32px; height: 32px;
  background: var(--accent-btn);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600; color: #fff; flex-shrink: 0;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name  { font-size: 13px; font-weight: 500; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-role  { font-size: 11px; color: var(--text-sidebar); }

/* --- Main area --- */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-width: 0;
}

/* --- Topbar --- */
.topbar {
  height: var(--topbar-h);
  background: var(--bg-topbar);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow-sm);
}
.topbar-title { font-size: 16px; font-weight: 600; color: var(--text-primary); }
.topbar-breadcrumb {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--text-secondary);
}
.topbar-breadcrumb a { color: var(--text-secondary); }
.topbar-breadcrumb a:hover { color: var(--text-primary); text-decoration: none; }
.topbar-breadcrumb .sep { color: var(--text-muted); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

/* --- Content --- */
.content {
  flex: 1;
  padding: 28px 28px 40px;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.page-title { font-size: 22px; font-weight: 700; color: var(--text-primary); }
.page-subtitle { font-size: 14px; color: var(--text-secondary); margin-top: 2px; }

/* ============================================================
   Cards
   ============================================================ */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.card-title { font-size: 15px; font-weight: 600; color: var(--text-primary); }
.card-body  { padding: 20px; }
.card-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-surface-2);
  display: flex; align-items: center; gap: 8px;
}

/* Stat-Cards */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex; align-items: center; gap: 16px;
  box-shadow: var(--shadow-sm);
}
.stat-icon {
  width: 44px; height: 44px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.stat-icon.blue   { background: var(--info-bg);    color: var(--info-text); }
.stat-icon.green  { background: var(--success-bg); color: var(--success-text); }
.stat-icon.orange { background: var(--warning-bg); color: var(--warning-text); }
.stat-icon.red    { background: var(--danger-bg);  color: var(--danger-text); }
.stat-value { font-size: 26px; font-weight: 700; color: var(--text-primary); line-height: 1; }
.stat-label { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background var(--transition), color var(--transition), box-shadow var(--transition), border-color var(--transition);
  white-space: nowrap;
  font-family: inherit;
  line-height: 1.4;
}
.btn:hover { text-decoration: none; }
.btn:focus-visible { outline: 3px solid var(--border-focus); outline-offset: 2px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary   { background: var(--accent-btn);   color: #fff; }
.btn-primary:hover   { background: var(--accent-btn-h); }
.btn-secondary { background: var(--bg-surface);   color: var(--text-primary); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--bg-hover); }
.btn-danger    { background: var(--danger-bg);    color: var(--danger-text);  border-color: var(--danger-border); }
.btn-danger:hover    { background: var(--danger-border); }
.btn-success   { background: var(--success-bg);   color: var(--success-text); border-color: var(--success-border); }
.btn-ghost     { background: transparent;          color: var(--text-secondary); }
.btn-ghost:hover     { background: var(--bg-hover); color: var(--text-primary); }
.btn-icon      { padding: 8px; }
.btn-sm        { padding: 5px 12px; font-size: 13px; }
.btn-lg        { padding: 11px 22px; font-size: 15px; }

/* ============================================================
   Formulare
   ============================================================ */
.form-group { margin-bottom: 18px; }
.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 5px;
}
.form-label .required { color: var(--danger-text); margin-left: 2px; }

.form-control {
  width: 100%;
  padding: 9px 13px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: var(--radius-md);
  transition: border-color var(--transition), box-shadow var(--transition);
  appearance: none;
}
.form-control:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}
.form-control::placeholder { color: var(--text-muted); }
.form-control:disabled { opacity: .6; cursor: not-allowed; background: var(--bg-surface-2); }
.form-control.is-invalid { border-color: #ef4444; box-shadow: 0 0 0 3px rgba(239,68,68,.12); }

select.form-control { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 36px; }

textarea.form-control { resize: vertical; min-height: 90px; }

.form-hint   { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.form-error  { font-size: 12px; color: var(--danger-text); margin-top: 4px; }
.form-row    { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3  { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

/* Checkbox / Radio */
.form-check {
  display: flex; align-items: center; gap: 8px;
  cursor: pointer; font-size: 14px; color: var(--text-primary);
}
.form-check input[type="checkbox"],
.form-check input[type="radio"] {
  width: 16px; height: 16px; cursor: pointer;
  accent-color: var(--accent-btn);
}

/* ============================================================
   Tabellen
   ============================================================ */
.table-wrap { overflow-x: auto; border-radius: var(--radius-lg); }
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.table th {
  padding: 11px 14px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  background: var(--bg-surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
  vertical-align: middle;
}
.table tbody tr:hover { background: var(--bg-hover); }
.table tbody tr:last-child td { border-bottom: none; }
.table .actions { display: flex; gap: 4px; }

/* Editierbare Zelle */
.cell-editable {
  cursor: text;
  border-radius: var(--radius-sm);
  padding: 4px 6px;
  margin: -4px -6px;
  transition: background var(--transition);
  min-width: 80px;
}
.cell-editable:hover { background: var(--bg-hover); }
.cell-editable:focus {
  outline: 2px solid var(--border-focus);
  background: var(--bg-input);
}

/* ============================================================
   Badges / Chips
   ============================================================ */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 500;
  border-radius: 99px;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge-success { background: var(--success-bg); color: var(--success-text); border-color: var(--success-border); }
.badge-danger  { background: var(--danger-bg);  color: var(--danger-text);  border-color: var(--danger-border); }
.badge-warning { background: var(--warning-bg); color: var(--warning-text); border-color: var(--warning-border); }
.badge-info    { background: var(--info-bg);    color: var(--info-text);    border-color: var(--info-border); }
.badge-neutral { background: var(--bg-surface-2); color: var(--text-secondary); border-color: var(--border); }

/* ============================================================
   Alerts / Flash Messages
   ============================================================ */
.alert {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  border: 1px solid;
  font-size: 14px;
  margin-bottom: 16px;
}
.alert-success { background: var(--success-bg); color: var(--success-text); border-color: var(--success-border); }
.alert-danger  { background: var(--danger-bg);  color: var(--danger-text);  border-color: var(--danger-border); }
.alert-warning { background: var(--warning-bg); color: var(--warning-text); border-color: var(--warning-border); }
.alert-info    { background: var(--info-bg);    color: var(--info-text);    border-color: var(--info-border); }
.alert-icon    { flex-shrink: 0; margin-top: 1px; }
.alert-close   { margin-left: auto; cursor: pointer; opacity: .7; }
.alert-close:hover { opacity: 1; }

/* ============================================================
   Modal
   ============================================================ */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  backdrop-filter: blur(2px);
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: fadeIn .15s ease;
}
.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp .18s ease;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px 0;
}
.modal-title  { font-size: 18px; font-weight: 700; }
.modal-close  { cursor: pointer; color: var(--text-muted); padding: 4px; border-radius: var(--radius-sm); }
.modal-close:hover { background: var(--bg-hover); color: var(--text-primary); }
.modal-body   { padding: 20px 24px; }
.modal-footer { padding: 0 24px 24px; display: flex; gap: 8px; justify-content: flex-end; }

/* ============================================================
   Pagination
   ============================================================ */
.pagination { display: flex; align-items: center; gap: 4px; }
.page-link {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-size: 13px;
  text-decoration: none;
  transition: background var(--transition), color var(--transition);
}
.page-link:hover { background: var(--bg-hover); color: var(--text-primary); text-decoration: none; }
.page-link.active { background: var(--accent-btn); border-color: var(--accent-btn); color: #fff; font-weight: 600; }
.page-link.disabled { opacity: .4; pointer-events: none; }

/* ============================================================
   Dark Mode Toggle
   ============================================================ */
.theme-toggle {
  width: 40px; height: 22px;
  background: var(--border-strong);
  border-radius: 99px;
  cursor: pointer;
  position: relative;
  transition: background var(--transition);
  border: none;
  flex-shrink: 0;
}
.theme-toggle::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 16px; height: 16px;
  background: #fff;
  border-radius: 50%;
  transition: transform var(--transition);
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
[data-theme="dark"] .theme-toggle { background: var(--accent-btn); }
[data-theme="dark"] .theme-toggle::after { transform: translateX(18px); }

/* ============================================================
   Login-Seite (kein Sidebar-Layout)
   ============================================================ */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-body);
  padding: 20px;
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.auth-header {
  background: var(--accent);
  padding: 28px 32px 24px;
  text-align: center;
}
.auth-logo {
  display: inline-flex; align-items: center; gap: 10px;
  text-decoration: none; margin-bottom: 4px;
}
.auth-logo-icon {
  width: 40px; height: 40px;
  background: var(--accent-btn);
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 700; color: #fff;
}
.auth-logo-text { color: #fff; font-size: 20px; font-weight: 700; }
.auth-subtitle  { color: rgba(255,255,255,.6); font-size: 13px; margin-top: 4px; }
.auth-body      { padding: 28px 32px; }
.auth-footer    { padding: 0 32px 24px; font-size: 13px; color: var(--text-muted); text-align: center; }

/* ============================================================
   Utility
   ============================================================ */
.flex   { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2  { gap: 8px; }
.gap-3  { gap: 12px; }
.gap-4  { gap: 16px; }
.mt-1   { margin-top: 4px; }
.mt-2   { margin-top: 8px; }
.mt-3   { margin-top: 12px; }
.mt-4   { margin-top: 16px; }
.mb-3   { margin-bottom: 12px; }
.mb-4   { margin-bottom: 16px; }
.mb-6   { margin-bottom: 24px; }
.text-sm     { font-size: 13px; }
.text-xs     { font-size: 12px; }
.text-muted  { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-danger { color: var(--danger-text); }
.text-success { color: var(--success-text); }
.font-mono   { font-family: var(--font-mono); font-size: 13px; }
.d-none      { display: none !important; }
.w-full      { width: 100%; }
.text-center { text-align: center; }
.text-right  { text-align: right; }
.truncate    { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.separator   { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* ============================================================
   Animationen
   ============================================================ */
@keyframes fadeIn  { from { opacity: 0 } to { opacity: 1 } }
@keyframes slideUp { from { transform: translateY(12px); opacity: 0 } to { transform: translateY(0); opacity: 1 } }
@keyframes spin    { to { transform: rotate(360deg) } }
.spinner { animation: spin .8s linear infinite; }

/* Loading overlay */
.loading-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.3);
  backdrop-filter: blur(1px);
  z-index: 999;
  display: flex; align-items: center; justify-content: center;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .content { padding: 16px; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .topbar { padding: 0 16px; }
  .page-header { flex-direction: column; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 480px) {
  .stat-grid { grid-template-columns: 1fr; }
  .auth-body { padding: 20px; }
  .auth-header { padding: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
