/* ═══════════════════════════════════════════════════════════
   Verwalterei — Hell-/Dunkelmodus (Entscheid 103)
   Alle farbabhängigen Tokens stehen hier, je einmal für hell und dunkel.
   Die Datei ist eigenständig: Seiten, die nur Bootstrap laden (QR-Meldung,
   Revisor, Bewerbung), binden sie direkt nach bootstrap.min.css ein.

   Umschaltung: <html data-bs-theme="dark|light"> (Server aus Cookie
   «ui_theme», sonst js/theme.js nach prefers-color-scheme).
   Teilbereiche, die immer hell bleiben (Dokument-Vorschau, Karten,
   Unterschriftsfeld), tragen selbst data-bs-theme="light".
   Druck, PDF-Ansichten (Layout = null ohne Attribut) und E-Mails bleiben hell.
   ═══════════════════════════════════════════════════════════ */

/* ── Helle Werte (Standard) ───────────────────────────────── */
:root,
[data-bs-theme=light] {
  --color-primary-text: #5271FF;
  --color-primary-soft: #eef2ff;
  --color-text: #334155;
  --color-heading: #111827;
  --color-ink: #000000;
  --color-muted: #6b7280;
  --color-subtle: #9ca3af;
  --color-border: #e5e7eb;
  --color-border-strong: #d1d5db;
  --color-surface: #ffffff;
  --color-surface-subtle: #f9fafb;
  --color-success: #047857;
  --color-warning: #b45309;
  --color-danger: #b91c1c;
  --color-info: #1d4ed8;

  --topbar-bg: #ffffff;
  --topbar-border: #e5e7eb;
  --content-bg: #f5f6fa;
  --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);

  /* Neutrale Skala (ersetzt hart codierte Grautöne in CSS und Views) */
  --gray-0: #ffffff;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-150: #e9ecef;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;

  /* Farbige Flächen (Hinweise, Badges, Auswahlkarten) */
  --tint-blue-50: #eff6ff;
  --tint-blue-100: #dbeafe;
  --tint-indigo-100: #e0e7ff;
  --tint-violet-50: #f5f0ff;
  --tint-amber-50: #fffbeb;
  --tint-amber-100: #fef3c7;
  --tint-amber-200: #fde68a;
  --tint-red-50: #fef2f2;
  --tint-red-100: #fee2e2;
  --tint-red-200: #fecaca;
  --tint-green-50: #f0fdf4;
  --tint-green-100: #dcfce7;
  --tint-emerald-100: #d1fae5;
  --tint-pink-100: #fce7f3;
  --tint-orange-50: #fff7ed;
  --tint-orange-100: #ffedd5;
  --tint-orange-200: #fed7aa;
  --tint-violet-100: #ede9fe;
  --tint-fuchsia-100: #fae8ff;

  /* Farbige Schrift auf hellen bzw. getönten Flächen */
  --ink-blue: #1d4ed8;
  --ink-indigo: #4338ca;
  --ink-red: #b91c1c;
  --ink-red-dark: #991b1b;
  --ink-green: #047857;
  --ink-green-dark: #166534;
  --ink-emerald-dark: #065f46;
  --ink-amber: #b45309;
  --ink-amber-dark: #92400e;
  --ink-pink: #be185d;
  --ink-orange: #c2410c;
  --ink-violet: #6d28d9;
  --ink-fuchsia: #a21caf;
  --ink-slate: #475569;

  /* Diagramme (SVG) */
  --chart-grid: #e5e7eb;
  --chart-axis: #6b7280;
  --chart-text: #374151;
  --chart-soll: #9fb6cf;
  --chart-ertrag: #1a3a5c;

  --theme-umschalter-bg: rgba(255, 255, 255, 0.9);
}

/* ── Dunkle Werte ─────────────────────────────────────────── */
[data-bs-theme=dark] {
  color-scheme: dark;

  --color-primary-text: #9aadff;    /* Markenblau aufgehellt: 7.0:1 auf #172033 */
  --color-primary-soft: #1f2a52;
  --color-text: #d3d9e4;
  --color-heading: #f1f4f9;
  --color-ink: #f1f4f9;
  --color-muted: #9ba6b9;           /* 6.5:1 auf #172033 */
  --color-subtle: #8b96ab;          /* 5.5:1 auf #172033 */
  --color-border: #2e3a52;
  --color-border-strong: #3b4862;
  --color-surface: #172033;
  --color-surface-subtle: #1b2539;
  --color-success: #6ee7b7;
  --color-warning: #fcd34d;
  --color-danger: #fca5a5;
  --color-info: #93c5fd;

  --topbar-bg: #131c2e;
  --topbar-border: #26314a;
  --content-bg: #0f1729;
  --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.3);

  --gray-0: #172033;
  --gray-50: #1b2539;
  --gray-100: #222c42;
  --gray-150: #283349;
  --gray-200: #2e3a52;
  --gray-300: #3b4862;
  --gray-400: #8b96ab;
  --gray-500: #9ba6b9;
  --gray-600: #b6bfcd;
  --gray-700: #d3d9e4;
  --gray-800: #e3e8ef;
  --gray-900: #f1f4f9;

  --tint-blue-50: #17264a;
  --tint-blue-100: #1c3363;
  --tint-indigo-100: #262d5e;
  --tint-violet-50: #241f42;
  --tint-amber-50: #2a2312;
  --tint-amber-100: #3d3011;
  --tint-amber-200: #6b5313;
  --tint-red-50: #2b1b22;
  --tint-red-100: #3f1f26;
  --tint-red-200: #552630;
  --tint-green-50: #14291f;
  --tint-green-100: #173d2b;
  --tint-emerald-100: #153d30;
  --tint-pink-100: #3d1d33;
  --tint-orange-50: #2c2014;
  --tint-orange-100: #3f2614;
  --tint-orange-200: #4f2f16;
  --tint-violet-100: #2c2550;
  --tint-fuchsia-100: #3b1a40;

  --ink-blue: #93b4fd;
  --ink-indigo: #a5b4fc;
  --ink-red: #fca5a5;
  --ink-red-dark: #fca5a5;
  --ink-green: #6ee7b7;
  --ink-green-dark: #86efac;
  --ink-emerald-dark: #6ee7b7;
  --ink-amber: #fcd34d;
  --ink-amber-dark: #fcd34d;
  --ink-pink: #f9a8d4;
  --ink-orange: #fdba74;
  --ink-violet: #c4b5fd;
  --ink-fuchsia: #f0abfc;
  --ink-slate: #b6bfcd;

  --chart-grid: #2e3a52;
  --chart-axis: #9ba6b9;
  --chart-text: #d3d9e4;
  --chart-soll: #5d7899;
  --chart-ertrag: #8ea2ff;

  --theme-umschalter-bg: rgba(23, 32, 51, 0.9);

  /* Bootstrap 5.3 mitziehen */
  --bs-body-bg: #172033;
  --bs-body-bg-rgb: 23, 32, 51;
  --bs-body-color: #d3d9e4;
  --bs-body-color-rgb: 211, 217, 228;
  --bs-emphasis-color: #f1f4f9;
  --bs-emphasis-color-rgb: 241, 244, 249;
  --bs-heading-color: #f1f4f9;
  --bs-secondary-color: #9ba6b9;
  --bs-secondary-color-rgb: 155, 166, 185;
  --bs-secondary-bg: #222c42;
  --bs-secondary-bg-rgb: 34, 44, 66;
  --bs-tertiary-color: #8b96ab;
  --bs-tertiary-color-rgb: 139, 150, 171;
  --bs-tertiary-bg: #1b2539;
  --bs-tertiary-bg-rgb: 27, 37, 57;
  --bs-border-color: #2e3a52;
  --bs-border-color-translucent: rgba(255, 255, 255, 0.12);
  --bs-link-color: #9aadff;
  --bs-link-color-rgb: 154, 173, 255;
  --bs-link-hover-color: #c0ccff;
  --bs-link-hover-color-rgb: 192, 204, 255;
  --bs-primary-text-emphasis: #9aadff;
  --bs-code-color: #f9a8d4;
}

/* ── Bootstrap-Hilfsklassen, die in 5.3 im Dunkelmodus hell bleiben ──
   «:not([data-bs-theme=light], [data-bs-theme=light] *)» lässt Bereiche mit data-bs-theme="light" (Papier-Vorschau) unberührt. */
[data-bs-theme=dark] .bg-white:not([data-bs-theme=light], [data-bs-theme=light] *) { background-color: var(--bs-body-bg) !important; }
[data-bs-theme=dark] .bg-light:not([data-bs-theme=light], [data-bs-theme=light] *) { background-color: var(--bs-tertiary-bg) !important; }
[data-bs-theme=dark] .text-bg-light:not([data-bs-theme=light], [data-bs-theme=light] *) { color: var(--bs-body-color) !important; background-color: var(--bs-tertiary-bg) !important; }
[data-bs-theme=dark] .text-dark:not([data-bs-theme=light], [data-bs-theme=light] *) { color: var(--bs-emphasis-color) !important; }
/* Auf gelben/hellblauen Vollflächen bleibt die Schrift dunkel */
[data-bs-theme=dark] .text-dark:is(.bg-warning, .bg-info, .text-bg-warning, .text-bg-info, .btn-warning, .btn-info):not([class*="bg-opacity-"]),
[data-bs-theme=dark] :is(.bg-warning, .bg-info, .text-bg-warning, .text-bg-info):not([class*="bg-opacity-"]) .text-dark { color: #212529 !important; }
[data-bs-theme=dark] .text-primary:not([data-bs-theme=light], [data-bs-theme=light] *) { color: var(--color-primary-text) !important; }
[data-bs-theme=dark] .text-success:not([data-bs-theme=light], [data-bs-theme=light] *) { color: #75d1a1 !important; }
[data-bs-theme=dark] .text-danger:not([data-bs-theme=light], [data-bs-theme=light] *) { color: #f19aa3 !important; }
[data-bs-theme=dark] .text-secondary:not([data-bs-theme=light], [data-bs-theme=light] *) { color: var(--bs-secondary-color) !important; }
[data-bs-theme=dark] .link-primary:not([data-bs-theme=light], [data-bs-theme=light] *) { color: var(--color-primary-text) !important; }

[data-bs-theme=dark] .table-light:not([data-bs-theme=light], [data-bs-theme=light] *) {
  --bs-table-color: var(--bs-emphasis-color);
  --bs-table-bg: var(--bs-tertiary-bg);
  --bs-table-border-color: var(--bs-border-color);
  --bs-table-striped-bg: var(--bs-secondary-bg);
  --bs-table-striped-color: var(--bs-emphasis-color);
  --bs-table-active-bg: var(--bs-secondary-bg);
  --bs-table-active-color: var(--bs-emphasis-color);
  --bs-table-hover-bg: var(--bs-secondary-bg);
  --bs-table-hover-color: var(--bs-emphasis-color);
  color: var(--bs-table-color);
  border-color: var(--bs-table-border-color);
}
[data-bs-theme=dark] .btn-light:not([data-bs-theme=light], [data-bs-theme=light] *) {
  --bs-btn-color: var(--bs-body-color);
  --bs-btn-bg: var(--bs-secondary-bg);
  --bs-btn-border-color: var(--bs-border-color);
  --bs-btn-hover-color: var(--bs-emphasis-color);
  --bs-btn-hover-bg: #2e3a52;
  --bs-btn-hover-border-color: #3b4862;
  --bs-btn-active-color: var(--bs-emphasis-color);
  --bs-btn-active-bg: #2e3a52;
}
[data-bs-theme=dark] .btn-outline-dark:not([data-bs-theme=light], [data-bs-theme=light] *) {
  --bs-btn-color: var(--bs-body-color);
  --bs-btn-border-color: #3b4862;
  --bs-btn-hover-color: #0f1729;
  --bs-btn-hover-bg: var(--bs-body-color);
  --bs-btn-hover-border-color: var(--bs-body-color);
}
[data-bs-theme=dark] .border-dark:not([data-bs-theme=light], [data-bs-theme=light] *) { border-color: #3b4862 !important; }
[data-bs-theme=dark] :is(.form-control, .form-select):not([data-bs-theme=light], [data-bs-theme=light] *) { background-color: #121a2b; }
[data-bs-theme=dark] :is(.form-control:disabled, .form-control[readonly], .form-select:disabled):not([data-bs-theme=light], [data-bs-theme=light] *) { background-color: var(--bs-secondary-bg); }
[data-bs-theme=dark] mark:not([data-bs-theme=light], [data-bs-theme=light] *) { color: #111827; }

/* Helle Inseln (Papier-Vorschau) im Dunkelmodus: Schrift neu aus den hellen Werten */
[data-bs-theme=dark] [data-bs-theme=light] { color: var(--bs-body-color); }

/* Leaflet-Kacheln bleiben hell; nur der Rahmen passt sich an */
[data-bs-theme=dark] .leaflet-container { border: 1px solid var(--color-border-strong); }

/* ── Umschalter Mond/Sonne ────────────────────────────────── */
.theme-umschalter .theme-icon-hell { display: none; }
[data-bs-theme=dark] .theme-umschalter .theme-icon-dunkel { display: none; }
[data-bs-theme=dark] .theme-umschalter .theme-icon-hell { display: inline-block; }
.theme-umschalter svg { width: 1.1rem; height: 1.1rem; }

.theme-umschalter--schwebend {
  position: fixed;
  top: 0.75rem;
  right: 0.75rem;
  z-index: 1030;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--bs-border-color, #dee2e6);
  background: var(--theme-umschalter-bg);
  color: var(--bs-secondary-color, #6c757d);
  opacity: 0.85;
  cursor: pointer;
  transition: opacity 0.15s, color 0.15s;
}
.theme-umschalter--schwebend:hover,
.theme-umschalter--schwebend:focus-visible { opacity: 1; color: var(--bs-body-color, #212529); }
.theme-umschalter--inline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: none;
  color: var(--bs-secondary-color, #6c757d);
  cursor: pointer;
}
.theme-umschalter--inline:hover { color: var(--bs-body-color, #212529); background: var(--bs-secondary-bg, #e9ecef); }

/* ── Druck bleibt immer hell ─────────────────────────────── */
@media print {
  [data-bs-theme=dark] { color-scheme: light; }
  .theme-umschalter { display: none !important; }
}
