:root {
  /* Akzent ist dunkel, nicht mehr das REWA-Gruen (#b0cb1f).
     Farbe traegt in CRM 11 nur noch Bedeutung - siehe OBERFLAECHE.md. */
  --rewa-red: #3d3a2e;
  --rewa-akzent-hell: #eceae3;   /* ruhige helle Flaeche statt Hellgruen */
  --avatar-neutral: #dcdad2;     /* Vorgabe fuer Kreise ohne eigene Farbe */
  --rewa-dark: #3d3a2e;
  --rewa-light: #eceae3;
  --rewa-gray: #f4f6f9;
  --rewa-border: #dee2e6;
}

body {
  background: #eeeeee;
  font-family: Arial, sans-serif;
  color: #222;
}

/* ── Sidebar ───────────────────────────────────────────────── */
:root {
  --sidebar-w: 220px;
  --sidebar-w-collapsed: 60px;
  --topbar-h: 52px;
}

#sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: #3d3a2e;
  border-right: 3px solid var(--rewa-red);
  display: flex;
  flex-direction: column;
  z-index: 1040;
  transition: width .22s ease, transform .22s ease;
  overflow: hidden;
}
#sidebar.collapsed { width: var(--sidebar-w-collapsed); }

/* Logo-Bereich */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 14px 10px;
  border-bottom: 1px solid rgba(255,255,255,.1);
  min-height: var(--topbar-h);
  flex-shrink: 0;
  overflow: hidden;
  white-space: nowrap;
}
.sidebar-brand img { height: 28px; width: auto; max-width: 140px; flex-shrink: 0; object-fit: contain; }
.sidebar-brand .brand-text { font-size: .8rem; color: rgba(255,255,255,.5); line-height: 1.2; overflow: hidden; }
.sidebar-brand .brand-text strong { display: block; color: #fff; font-size: .95rem; }

/* Nav-Einträge */
.sidebar-nav { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 8px 0; }
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 2px; }

.sidebar-item { position: relative; }
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 16px;
  color: rgba(255,255,255,.75);
  text-decoration: none;
  font-size: .88rem;
  white-space: nowrap;
  overflow: hidden;
  transition: background .15s, color .15s;
}
.sidebar-link:hover { background: rgba(255,255,255,.08); color: #fff; }
.sidebar-link.active { background: rgba(255,255,255,.16); color: #fff; font-weight: 600; }
.sidebar-link i { font-size: 1.1rem; flex-shrink: 0; width: 22px; text-align: center; }
.sidebar-link .link-label { overflow: hidden; }

/* Untermenü-Toggle */
.sidebar-link[data-bs-toggle="collapse"] .bi-chevron-down {
  margin-left: auto; font-size: .7rem; transition: transform .2s;
}
.sidebar-link[aria-expanded="true"] .bi-chevron-down { transform: rotate(-180deg); }
.sidebar-submenu { background: rgba(0,0,0,.15); }
.sidebar-submenu .sidebar-link {
  padding-left: 20px;
  padding-right: 8px;
  gap: 8px;
  font-size: .82rem;
  white-space: normal !important;
  line-height: 1.25;
}
.sidebar-submenu .sidebar-link i { width: 18px; font-size: 1rem; }
.sidebar-submenu .sidebar-link .link-label { overflow: visible; word-break: break-word; }

/* Beschrifteter Trenner innerhalb eines Untermenüs (z.B. „Personal" in Eventmanufaktur) */
.submenu-group-label {
  font-size: .62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: rgba(61,58,46,.75);
  padding: 9px 16px 4px 20px;
  margin-top: 3px;
  border-top: 1px solid rgba(255,255,255,.12);
}

/* Divider */
.sidebar-divider {
  height: 1px; background: rgba(255,255,255,.08);
  margin: 6px 12px;
}

.sidebar-section-label {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--rewa-red);
  padding: 10px 10px 5px;
  margin-top: 6px;
}
.sidebar-section-label::before,
.sidebar-section-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: rgba(61,58,46,.25);
}
#sidebar.collapsed .sidebar-section-label { display: none; }

/* Benutzer unten */
.sidebar-user {
  border-top: 1px solid rgba(255,255,255,.1);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
  overflow: hidden;
  flex-shrink: 0;
}
.sidebar-user .user-info { overflow: hidden; }
.sidebar-user .user-info small { display: block; color: rgba(255,255,255,.45); font-size: .72rem; }
.sidebar-user .user-info strong { display: block; color: #fff; font-size: .84rem; overflow: hidden; text-overflow: ellipsis; }

/* Tooltip im collapsed-Modus */
#sidebar.collapsed .sidebar-link { justify-content: center; padding: 10px 0; border-left: none; }
#sidebar.collapsed .link-label,
#sidebar.collapsed .sidebar-link .bi-chevron-down,
#sidebar.collapsed .sidebar-brand .brand-text,
#sidebar.collapsed .sidebar-brand .brand-logo,
#sidebar.collapsed .sidebar-user .user-info { display: none; }
#sidebar.collapsed .sidebar-brand { justify-content: center; padding: 14px 0 10px; }
#sidebar.collapsed .sidebar-submenu { display: none !important; }
#sidebar.collapsed .sidebar-user { justify-content: center; }

/* ── Topbar ────────────────────────────────────────────────── */
#topbar {
  position: fixed;
  top: 0;
  left: var(--sidebar-w);
  right: 0;
  height: var(--topbar-h);
  background: #fff;
  border-bottom: 2px solid var(--rewa-red);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  z-index: 1030;
  box-shadow: 0 2px 8px rgba(0,0,0,.06);
  transition: left .22s ease;
}
#topbar.sidebar-collapsed { left: var(--sidebar-w-collapsed); }
#sidebar-toggle {
  background: none; border: none; color: var(--rewa-dark);
  font-size: 1.25rem; cursor: pointer; padding: 4px 8px;
  border-radius: 6px; flex-shrink: 0;
}
#sidebar-toggle:hover { background: var(--rewa-light); }
.topbar-search { flex: 1; max-width: 280px; }
.topbar-search input {
  border-radius: 20px; font-size: .88rem;
  padding: 5px 14px; border-color: #ddd;
}
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }

/* ── Hauptinhalt ───────────────────────────────────────────── */
#main-content {
  margin-left: var(--sidebar-w);
  margin-top: var(--topbar-h);
  padding: 24px 20px;
  min-height: calc(100vh - var(--topbar-h));
  transition: margin-left .22s ease;
}
#main-content.sidebar-collapsed { margin-left: var(--sidebar-w-collapsed); }

/* ── Mobile Overlay ────────────────────────────────────────── */
#sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 1039;
}

/* Handy + Tablet/iPad: Sidebar als Overlay statt fest angedockt,
   damit der neu gewachsene, klappbare Menübaum (Kunden/Firma intern/
   Eventmanufaktur/Verwaltung) nicht den Platz für Tabellen & Formulare frisst */
@media (max-width: 1024px) {
  #sidebar { transform: translateX(-100%); width: var(--sidebar-w) !important; }
  #sidebar.mobile-open { transform: translateX(0); }
  #topbar { left: 0 !important; }
  #main-content { margin-left: 0 !important; }
  #sidebar-overlay.active { display: block; }
}

/* Navbar alt — nicht mehr benötigt, Kompatibilität */
.brand-rewa { color: var(--rewa-red); font-weight: 800; font-size: 1.2rem; }
.brand-marketing { color: #fff; font-weight: 300; font-size: 1.2rem; }

/* Login */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--rewa-dark) 0%, #2a2820 100%);
}
.login-card {
  background: #fff;
  border-radius: 10px;
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
  border-top: 4px solid var(--rewa-red);
}
.login-logo { text-align: center; margin-bottom: 1.5rem; }
.login-logo img { max-height: 80px; max-width: 260px; object-fit: contain; margin-bottom: 12px; }
.login-logo .brand-rewa { font-size: 2rem; color: #1a1a1a; }
.login-logo .brand-marketing { font-size: 2rem; color: var(--rewa-red); }
.login-logo p { color: #888; font-size: 0.85rem; margin-top: 4px; }

/* Cards */
.card { border: none; border-radius: 8px; box-shadow: 0 2px 12px rgba(0,0,0,0.07); }
.card-header {
  background: var(--rewa-dark);
  border-bottom: none;
  border-radius: 8px 8px 0 0 !important;
  font-weight: 700;
  padding: 0.85rem 1.25rem;
  color: #fff;
}
.card-header i { color: var(--rewa-red); }
.card-header .btn-outline-secondary {
  color: rgba(255,255,255,.75) !important;
  border-color: rgba(255,255,255,.3) !important;
}
.card-header .btn-outline-secondary:hover {
  background: rgba(255,255,255,.15) !important;
  color: #fff !important;
}

/* Page title */
.page-title {
  font-weight: 700;
  color: var(--rewa-dark);
}

/* Stats */
.stat-card {
  background: #fff;
  border-radius: 8px;
  padding: .9rem 1rem;
  border: 1px solid #e4e4dc;
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
  text-align: center;
  white-space: nowrap;
}
.stat-card .stat-num { font-size: 1.9rem; font-weight: 800; color: var(--rewa-dark); line-height: 1.1; }
.stat-card .stat-label { color: #888; font-size: 0.72rem; text-transform: uppercase; letter-spacing: .5px; margin-top: 2px; }

/* Buttons */
.btn-rewa { background: var(--rewa-red); color: #fff !important; border: none; font-weight: 700; }
.btn-rewa:hover { background: #55503f; color: #fff !important; }

/* Schreibfelder */
.form-control { background-color: #efefef; }

/* Form focus */
.form-control:focus, .form-select:focus {
  border-color: var(--rewa-red);
  box-shadow: 0 0 0 0.2rem rgba(61,58,46,0.25);
}

/* Badge status */
.badge-aktiv { background: #198754; }
.badge-interessent { background: #fd7e14; }
.badge-inaktiv { background: #6c757d; }

/* Customer table */
.table th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.5px; color: #888; }
.table tbody tr:hover { background: #f6f5f0; }
.customer-name { font-weight: 600; color: var(--rewa-dark); }
.customer-num { font-size: 0.8rem; color: #aaa; }

/* Document grid */
.doc-item {
  background: #fff;
  border: 1px solid var(--rewa-border);
  border-radius: 6px;
  padding: 1rem;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: box-shadow .2s;
}
.doc-item:hover { box-shadow: 0 4px 16px rgba(0,0,0,0.1); }
.doc-icon { font-size: 2rem; }
.doc-icon.pdf { color: #e30613; }
.doc-icon.img { color: #0d6efd; }
.doc-icon.word { color: #2b579a; }
.doc-icon.excel { color: #217346; }
.doc-icon.other { color: #888; }
.doc-name { font-weight: 600; font-size: 0.9rem; word-break: break-all; }
.doc-meta { font-size: 0.78rem; color: #aaa; }
.doc-type-badge { font-size: 0.7rem; }

/* Upload zone */
.upload-zone {
  border: 2px dashed #ccc;
  border-radius: 8px;
  padding: 2rem;
  text-align: center;
  color: #888;
  cursor: pointer;
  transition: border-color .2s, background .2s;
}
.upload-zone:hover { border-color: var(--rewa-red); background: var(--rewa-light); }

/* Search */
.search-bar input { border-radius: 20px; padding-left: 1rem; }

/* Alert */
.alert { border-radius: 6px; }
.alert-success { background: var(--rewa-light); border-color: var(--rewa-red); color: var(--rewa-dark); }

/* Tabs */
.nav-tabs .nav-link.active { border-bottom-color: #fff; color: var(--rewa-dark); font-weight: 700; }
.nav-tabs .nav-link:hover { color: var(--rewa-dark); }

/* Tabs auf dunklem Card-Header */
.card-header .nav-tabs {
  border-bottom: none;
}
.card-header .nav-tabs .nav-link {
  color: rgba(255,255,255,.65) !important;
  border-color: transparent;
  border-radius: 6px 6px 0 0;
}
.card-header .nav-tabs .nav-link:hover {
  color: #fff !important;
  background: rgba(255,255,255,.12);
  border-color: transparent;
}
.card-header .nav-tabs .nav-link.active {
  color: var(--rewa-dark) !important;
  background: #fff;
  border-color: rgba(255,255,255,.2) rgba(255,255,255,.2) #fff;
  font-weight: 700;
}
.card-header .nav-tabs .nav-link i {
  color: var(--rewa-red);
}

/* Quick actions bar */
.quick-actions {
  background: var(--rewa-light);
  border: 2px solid var(--rewa-red);
  border-radius: 8px;
  padding: .75rem 1rem;
}

/* Nav Avatar */
.nav-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: #222; font-weight: 700; font-size: .85rem;
  flex-shrink: 0;
}

/* Employee avatar */
.avatar-circle {
  width: 38px; height: 38px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #222; font-weight: 700; font-size: 1rem;
  flex-shrink: 0;
}
.avatar-circle-lg {
  width: 60px; height: 60px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #222; font-weight: 700; font-size: 1.5rem;
  flex-shrink: 0; box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
.avatar-circle-xl {
  width: 80px; height: 80px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #222; font-weight: 700; font-size: 2rem;
  box-shadow: 0 3px 12px rgba(0,0,0,.2);
}

/* Task card */
.task-card { box-shadow: 0 1px 4px rgba(0,0,0,.06); transition: box-shadow .15s; }
.task-card:hover { box-shadow: 0 3px 12px rgba(0,0,0,.12); }

/* Section title (in forms/cards) */
.section-lbl {
  font-size: 0.72rem; font-weight: 700; color: var(--rewa-red);
  text-transform: uppercase; letter-spacing: 1px;
  border-bottom: 2px solid var(--rewa-red);
  padding-bottom: 3px; margin-bottom: 8px;
}

/* ── Theme-Umschalter (helles/dunkles Menü) ───────────────────
   Additiv: Standardansicht (body ohne .theme-light) bleibt exakt
   wie bisher. body.theme-light überschreibt nur die Sidebar-Farben. */
.theme-toggle-link {
  display: block;
  text-align: center;
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 6px;
  color: rgba(255,255,255,.8);
  font-size: .75rem;
  padding: 5px 10px;
  text-decoration: none;
  transition: background .15s, color .15s;
}
.theme-toggle-link:hover { background: rgba(255,255,255,.15); color: #fff; }
.theme-toggle-link i { margin-right: 4px; }

body.theme-light #sidebar {
  background: #fff;
  border-right: 1px solid var(--rewa-border);
}
body.theme-light .sidebar-brand { border-bottom-color: var(--rewa-border); }
body.theme-light .sidebar-link { color: #5c5a4d; }
body.theme-light .sidebar-link i { opacity: .8; }
body.theme-light .sidebar-link:hover { background: var(--rewa-gray); color: var(--rewa-dark); }
body.theme-light .sidebar-link.active {
  background: var(--rewa-akzent-hell);
  color: var(--rewa-dark);
  font-weight: 600;
}
body.theme-light .sidebar-submenu { background: #fafaf7; }
body.theme-light .submenu-group-label {
  color: #7c8a19;
  border-top-color: var(--rewa-border);
}
body.theme-light .sidebar-section-label { color: #7c8a19; }
body.theme-light .sidebar-section-label::before,
body.theme-light .sidebar-section-label::after { background: rgba(61,58,46,.3); }
body.theme-light .sidebar-divider { background: var(--rewa-border); }
body.theme-light .sidebar-user { border-top-color: var(--rewa-border); }
body.theme-light .sidebar-user .user-info small { color: #9a9a8e; }
body.theme-light .sidebar-user .user-info strong { color: var(--rewa-dark); }
body.theme-light .sidebar-user a { color: #9a9a8e !important; }
body.theme-light #expand-all-btn {
  background: var(--rewa-gray) !important;
  border-color: var(--rewa-border) !important;
  color: #5c5a4d !important;
}
body.theme-light .theme-toggle-link {
  background: var(--rewa-gray);
  border-color: var(--rewa-border);
  color: #5c5a4d;
}
body.theme-light .theme-toggle-link:hover { background: var(--rewa-light); color: var(--rewa-dark); }

/* ── Verwaltung-Kacheln (Hub-Übersicht) ────────────────────── */
.admin-tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.admin-tile {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.07);
  padding: 16px 18px;
  text-decoration: none;
  color: inherit;
  display: block;
  border: 1px solid #e4e4dc;
  transition: transform .15s ease, box-shadow .15s ease;
}
.admin-tile:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0,0,0,0.12); color: inherit; }
.admin-tile .at-icon { color: var(--rewa-red); font-size: 1.3rem; margin-bottom: 6px; display: block; }
.admin-tile .at-title { font-weight: 700; color: var(--rewa-dark); margin-bottom: 2px; }
.admin-tile .at-desc { font-size: .8rem; color: #888; margin-bottom: 10px; min-height: 2.2em; }
.admin-tile .at-num { font-size: 1.15rem; font-weight: 800; color: var(--rewa-red); }

/* ── Rollen & Rechte: Rollenliste + Schieberegler ─────────────
   Ersetzt die frühere Matrix-Tabelle; Speicherlogik unverändert,
   nur die Darstellung (eine Rolle sichtbar, per Klick wechselbar). */
.role-list { display: flex; flex-direction: column; gap: 2px; padding: 8px; }
.role-item { padding: 10px 12px; border-radius: 8px; cursor: pointer; border: 1px solid transparent; }
.role-item:hover { background: var(--rewa-gray); }
.role-item.active { background: var(--rewa-light); border-color: rgba(61,58,46,.4); }
.role-item .rname { font-weight: 700; font-size: .9rem; color: var(--rewa-dark); }
.role-item.active .rname { color: #5c6a10; }
.role-item .rdesc { font-size: .76rem; color: #999; margin-top: 1px; }

.perm-group-label {
  font-size: .7rem; font-weight: 800; text-transform: uppercase; letter-spacing: .08em;
  color: #999; padding: 14px 18px 6px; background: #fafafa;
}
.perm-row {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 18px; border-bottom: 1px solid var(--rewa-border);
  margin: 0; cursor: pointer;
}
.perm-row:hover { background: #fbfcf7; }
.perm-row i { color: #999; width: 20px; text-align: center; flex-shrink: 0; }
.perm-row .info { flex: 1; }
.perm-row .plabel { font-weight: 600; font-size: .88rem; color: #333; }

.switch { position: relative; width: 42px; height: 24px; flex-shrink: 0; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch .track {
  position: absolute; inset: 0; background: #ccc; border-radius: 999px;
  transition: background .15s ease;
}
.switch .track::before {
  content: ''; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: transform .15s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.switch input:checked + .track { background: var(--rewa-red); }
.switch input:checked + .track::before { transform: translateX(18px); }
.switch input:focus-visible + .track { outline: 2px solid var(--rewa-red); outline-offset: 2px; }

/* ── Kundendetail: Reiter-Liste rechts (statt horizontaler Tabs oben) ── */
.cv-tab-rail { padding: 6px; }
.cv-tab-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border: 1px solid transparent !important; border-radius: 8px !important;
  color: #555; font-size: .87rem; font-weight: 600; background: transparent;
}
.cv-tab-item:hover { background: #f4f4f1; color: #555; }
.cv-tab-item.active {
  background: var(--rewa-light) !important; border-color: rgba(61,58,46,.4) !important;
  color: var(--rewa-dark) !important;
}
.cv-tab-item .cnt {
  margin-left: auto; background: #e4e4e0; color: #666; font-size: .7rem; font-weight: 700;
  padding: 2px 8px; border-radius: 999px;
}
.cv-tab-item.active .cnt { background: var(--rewa-red); color:#fff; }
.cv-tab-item .cnt.danger { background: #dc3545; color: #fff; }

/* Responsive */
@media (max-width: 767px) {
  .stat-card .stat-num { font-size: 1.8rem; }

  /* Kein horizontales Überlaufen */
  #main-content { padding: 14px 12px; overflow-x: hidden; }
  body { overflow-x: hidden; }

  /* Seitentitel */
  .page-title { font-size: 1.15rem; word-break: break-word; }

  /* Tabellen scrollen horizontal */
  .card-body table, .table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; width: 100%; }
  /* Ausnahme: FullCalendar (Kalender-Modul) baut intern eigene Tabellen -
     die generische Regel oben zerstört sonst das komplette Grid */
  .card-body .fc table { display: table; overflow: visible; width: 100%; }
  .card-body .fc tbody, .card-body .fc thead { display: table-row-group; }
  .card-body .fc tr { display: table-row; }
  .card-body .fc td, .card-body .fc th { display: table-cell; }

  /* Buttonreihen umbrechen */
  .d-flex.gap-2 { flex-wrap: wrap !important; }
  .btn { white-space: nowrap; }

  /* Formulare */
  .form-control, .form-select { font-size: .9rem; }
  input[type="date"], input[type="time"] { width: 100% !important; min-width: 0; }

  /* Tabs scrollen */
  .nav-tabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .nav-tabs .nav-link { white-space: nowrap; }
}
