/* ================================================
   SHARED DESIGN SYSTEM
   Gemeinsame Styles für alle Module
   ================================================ */

/* ================= CSS VARIABLES ================= */
:root {
    /* Layout */
    --top-bar-height: 64px;
    --sidebar-width: 260px;
    /* Content-Inset: Abstand unter TopBar, rechts neben Sidebar, unten (eine Quelle für alle Module) */
    --layout-content-inset-top: 20px;
    --layout-content-inset-x: 40px;
    --layout-content-inset-bottom: 40px;
    --layout-content-gap: var(--spacing-lg);
    /* Modal-Inset: Abstand Overlay → Dialog (eine Quelle für alle Module) */
    --layout-modal-overlay-inset: var(--spacing-md);
    --layout-modal-padding-x: var(--spacing-xl);
    --layout-modal-padding-y: var(--spacing-lg);
    --layout-modal-max-height: min(90dvh, 900px);
    
    /* Primary Colors */
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #dbeafe;
    
    /* Secondary Colors */
    --secondary-color: #64748b;
    --secondary-hover: #475569;
    
    /* Status Colors */
    --success-color: #22c55e;
    --success-light: #dcfce7;
    --warning-color: #f59e0b;
    --warning-light: #fef3c7;
    --danger-color: #ef4444;
    --danger-light: #fee2e2;
    --info-color: #3b82f6;
    --info-light: #dbeafe;
    
    /* Background & Surface */
    --bg-color: #e8edf3;
    --card-bg: #ffffff;
    --hover-bg: #dde4eb;
    
    /* Text Colors */
    --text-color: #1e293b;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    
    /* Border & Input */
    --border-color: #cbd5e1;
    --input-bg: #ffffff;
    --input-border: #cbd5e1;
    --input-focus: #2563eb;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.1);
    
    /* Spacing */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;
    --spacing-2xl: 48px;
    
    /* Border Radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-full: 9999px;
    
    /* Legacy Aliases für Kompatibilität */
    --bg-card: var(--card-bg);
    --bg-sidebar: var(--card-bg);
    --border-radius: var(--radius-md);
    --border-radius-lg: var(--radius-lg);
    --border-radius-sm: var(--radius-sm);

    /* Convenience-Aliases (Preview, Templates, externe Nutzung) */
    --bg-primary: var(--bg-color);       /* Seiten-Hintergrund */
    --bg-secondary: var(--hover-bg);     /* Sekundärer / subtiler Hintergrund */
    --topbar-bg: var(--card-bg);         /* TopBar-Hintergrund */
    --sidebar-bg: var(--card-bg);        /* Sidebar-Hintergrund */
    
    /* Typography */
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    --font-size-xs: 11px;
    --font-size-sm: 12px;
    --font-size-base: 14px;
    --font-size-lg: 16px;
    --font-size-xl: 18px;
    --font-size-2xl: 20px;
    --font-size-3xl: 24px;
    --font-size-4xl: 28px;
    
    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.2s ease;
    --transition-slow: 0.3s ease;
    
    /* Z-Index Scale */
    --z-dropdown: 100;
    --z-sticky: 200;
    --z-modal: 1000;
    --z-tooltip: 1100;
    --z-toast: 1200;
}

/* ================= DARK MODE ================= */
[data-theme="dark"] {
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --primary-light: #1e3a5f;
    
    --secondary-color: #94a3b8;
    --secondary-hover: #cbd5e1;
    
    --success-light: #14532d;
    --warning-light: #78350f;
    --danger-light: #7f1d1d;
    --info-light: #1e3a5f;
    
    --bg-color: #0f172a;
    --card-bg: #1e293b;
    --hover-bg: #334155;
    
    --text-color: #f1f5f9;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    
    --border-color: #334155;
    --input-bg: #334155;
    --input-border: #475569;
    
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.5);
}

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    height: 100%;       /* Expliziter Reset – Basis für 100dvh im app-shell */
    margin: 0;          /* Verhindert UA-Stylesheet-Margin */
}

body {
    font-family: var(--font-family);
    background: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    margin: 0;          /* Expliziter Reset – kein UA-Stylesheet-Margin */
}

/* ================= SCROLLBAR ================= */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-color);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--secondary-color);
}

/* Firefox */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) var(--bg-color);
}

[data-theme="dark"] ::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

[data-theme="dark"] ::-webkit-scrollbar-track {
    background: var(--card-bg);
}

[data-theme="dark"] ::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

[data-theme="dark"] ::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

[data-theme="dark"] * {
    scrollbar-color: var(--border-color) var(--card-bg);
}

/* App-Shell Layout: body → Flex-Column, #mainApp.active füllt den Platz.
   #loginPage (display:none) nimmt keinen Flex-Platz ein.
   Login-, Legal- und Error-Seiten NICHT mit dieser Klasse versehen. */
body.app-shell {
    display: flex;          /* Flex-Column: nur .page.active ist sichtbar    */
    flex-direction: column;
    height: 100dvh;         /* Exakt Viewport-Höhe – kein Pixel mehr/weniger  */
    overflow: hidden;       /* Kein Body-Scroll                              */
    margin: 0;
    /* Gleicher Hintergrund wie TopBar – verhindert sichtbare Farbdifferenz
       falls je ein Sub-Pixel-Gap zwischen Viewport-Edge und TopBar entsteht. */
    background: var(--card-bg);
}

/* Vite-Shell: App-Markup wird in #mw-app-root injiziert (nicht direktes body-Kind). */
#mw-app-root {
    display: flex;
    flex-direction: column;
    flex: 1 1 0%;
    min-height: 0;
    overflow: hidden;
    width: 100%;
}

/* Aktive Seite füllt den gesamten Body-Flex-Platz
   und ist selbst ein verschachtelter Flex-Column für TopBar/Content/Footer */
body.app-shell > .page.active,
body.app-shell > #mw-app-root > .page.active {
    display: flex !important;   /* Überschreibt .page.active { display: block } */
    flex-direction: column;
    flex: 1 1 0%;               /* Füllt 100% des body-Flex-Platzes             */
    min-height: 0;              /* Darf schrumpfen                             */
    overflow: hidden;
}

/* User-Dropdown darf nicht von .page.active overflow:hidden abgeschnitten werden */
body.app-shell > .page.active > .top-bar,
body.app-shell > #mw-app-root > .page.active > .top-bar {
    overflow: visible;
    z-index: calc(var(--z-sticky) + 1);
}

a {
    color: var(--primary-color);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* ================= PAGES ================= */
.page {
    display: none;
}

.page.active {
    display: block;
}

/* ================= LOGIN ================= */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: var(--spacing-lg);
    background: linear-gradient(135deg, var(--primary-color) 0%, #1e40af 100%);
}

.login-box {
    background: var(--card-bg);
    padding: var(--spacing-xl);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 400px;
}

.login-box h1 {
    text-align: center;
    margin-bottom: var(--spacing-lg);
    color: var(--primary-color);
    font-size: var(--font-size-4xl);
}

.login-box .subtitle {
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: var(--spacing-lg);
}

/* ================= TOP BAR ================= */
.top-bar {
    background: var(--topbar-bg, var(--card-bg));
    box-shadow: var(--shadow-sm);
    border-bottom: 1px solid var(--border-color);
    padding: 0 40px;
    height: var(--top-bar-height);
    min-height: var(--top-bar-height);
    display: flex;
    align-items: center;
    justify-content: flex-start;
    position: sticky;
    top: 0;
    z-index: var(--z-sticky);
    flex: 0 0 auto;         /* In body.app-shell: nie wachsen/schrumpfen     */
}

.top-bar { color: var(--text-color); }
.top-bar a,
.top-bar button { color: inherit; }
.top-bar a:hover,
.top-bar button:hover { color: var(--text-color); }

.brand-logo-link {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    line-height: 0;
}

.brand-logo-left {
    display: block;          /* avoid inline-img baseline quirks (logo looks "too high") */
    flex-shrink: 0;
    height: auto;
    max-height: 44px;
    width: 160px;
    min-width: 160px;
    max-width: none;
    object-fit: contain;
    align-self: center;
}

/* Header-Brand (Gateway-Seiten): feste Groesse, kein Schrumpfen */
.topbar-brand,
.brand {
    flex-shrink: 0;
}

.topbar-brand img,
.brand img {
    flex-shrink: 0;
    max-width: none;
}

/* Logo-Switch (Light/Dark) */
.mw-logo--dark { display: none; }
[data-theme="dark"] .mw-logo--light { display: none; }
[data-theme="dark"] .mw-logo--dark { display: inline-block; }

/* Logo: SVG mit Farbverlauf; kein Invert im Dark Mode (besser lesbar mit neuem Design) */
[data-theme="dark"] .brand-logo-left {
    filter: none;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    font-size: var(--font-size-xl);
    font-weight: bold;
    color: var(--text-color);
    margin-left: 40px;
    flex: 1 1 auto;      /* nimmt verfügbaren Platz ein */
    min-width: 0;        /* wichtig: erlaubt Scroll-Container zu schrumpfen */
}

/* Module Switcher */
.module-switcher {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: 20px;
    padding-left: 0;
    flex: 1 1 auto;
    min-width: 0;
    overflow-x: auto;          /* nur Modullinks scrollen */
    overflow-y: hidden;
    white-space: nowrap;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-gutter: stable both-edges;
}

.module-switcher-container {
    flex: 1 1 auto;
    min-width: 0;
}

.module-switcher::-webkit-scrollbar {
    height: 6px;
}

.module-switcher::-webkit-scrollbar-thumb {
    border-radius: 999px;
}

.module-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px 12px;
    border-radius: var(--radius-md);
    transition: all var(--transition-normal);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.module-btn:hover {
    background: var(--hover-bg);
    color: var(--text-color);
    border-color: color-mix(in srgb, var(--text-secondary) 55%, var(--border-color));
    text-decoration: none;
}

.module-btn.active {
    background: var(--card-bg);
    border-color: color-mix(in srgb, var(--primary-color) 65%, var(--border-color));
    color: var(--primary-color);
}

.module-btn .module-icon {
    font-size: 14px;
}

.brand-text-button {
    background: none;
    border: 2px solid var(--primary-color);
    font-size: var(--font-size-lg);
    font-weight: bold;
    color: var(--primary-color);
    cursor: pointer;
    padding: 6px var(--spacing-md);
    border-radius: var(--radius-md);
    transition: all var(--transition-normal);
}

.brand-text-button:hover {
    background-color: var(--primary-color);
    color: white;
}

.nav-user {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-left: auto;
    flex: 0 0 auto;      /* bleibt rechts fix, wird nicht zusammengedrückt */
}

/* Mandanten-Badge (Superuser) – lesbar in Light- und Dark-Mode */
.tenant-selector-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    margin-right: 4px;
    max-width: 220px;
    border-radius: 20px;
    border: 1px solid var(--primary-color, #2563eb);
    background: var(--primary-light, rgba(37, 99, 235, 0.12));
    color: var(--primary-color, #1d4ed8);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}

.tenant-selector-badge:hover {
    opacity: 0.92;
    background: color-mix(in srgb, var(--primary-color, #2563eb) 14%, var(--card-bg, #fff));
}

.tenant-selector-badge__name {
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 150px;
}

.tenant-selector-badge__caret {
    font-size: 0.7rem;
    opacity: 0.75;
    flex-shrink: 0;
}

[data-theme="dark"] .tenant-selector-badge {
    color: var(--text-primary, #f1f5f9);
    background: color-mix(in srgb, var(--primary-color, #3b82f6) 22%, transparent);
    border-color: color-mix(in srgb, var(--primary-color, #3b82f6) 50%, var(--border-color, #334155));
}

.tenant-selector-overlay {
    position: fixed;
    inset: 0;
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(4px);
}

.tenant-selector-card {
    background: var(--card-bg, #fff);
    color: var(--text-primary, #111);
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 14px;
    padding: 28px 24px 20px;
    min-width: 360px;
    max-width: 520px;
    width: 90%;
    box-shadow: var(--shadow-lg, 0 24px 48px rgba(0, 0, 0, 0.2));
}

.tenant-selector-card__title {
    margin: 0 0 8px;
    font-size: 1.2rem;
    text-align: center;
}

.tenant-selector-card__subtitle {
    margin: 0 0 20px;
    font-size: 0.88rem;
    color: var(--text-secondary, #6b7280);
    text-align: center;
}

.tenant-selector-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 380px;
    overflow-y: auto;
}

.tenant-selector-option {
    padding: 12px 14px;
    border: 2px solid var(--border-color, #e5e7eb);
    border-radius: 10px;
    background: var(--bg-primary, #f9fafb);
    color: var(--text-primary, #111);
    font-size: 0.93rem;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}

.tenant-selector-option:hover,
.tenant-selector-option.is-active {
    border-color: var(--primary-color, #2563eb);
    background: color-mix(in srgb, var(--primary-color, #2563eb) 14%, var(--card-bg));
    color: var(--primary-color, #2563eb);
}

@supports not (background: color-mix(in srgb, #000 10%, #fff)) {
    .tenant-selector-option:hover,
    .tenant-selector-option.is-active {
        background: var(--primary-light, rgba(37, 99, 235, 0.1));
    }
}

[data-theme="dark"] .tenant-selector-card {
    background: var(--card-bg);
    color: var(--text-color);
    border-color: var(--border-color);
}

[data-theme="dark"] .tenant-selector-card__subtitle {
    color: var(--text-secondary);
}

[data-theme="dark"] .tenant-selector-option {
    background: var(--card-bg);
}

[data-theme="dark"] .tenant-selector-option:hover,
[data-theme="dark"] .tenant-selector-option.is-active {
    background: color-mix(in srgb, var(--primary-color, #3b82f6) 24%, var(--card-bg));
    color: var(--text-primary);
    border-color: color-mix(in srgb, var(--primary-color, #3b82f6) 55%, var(--border-color));
}

.tenant-selector-cancel {
    margin-top: 14px;
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 8px;
    background: transparent;
    color: var(--text-secondary, #6b7280);
    cursor: pointer;
    font-size: 0.9rem;
}

/* ================= LAYOUT ================= */
.app-container {
    display: flex;
    flex: 1 1 auto;     /* Füllt den verbleibenden Body-Flex-Platz           */
    min-height: 0;      /* Nötig: Flex-Kind darf kleiner werden als Inhalt   */
    overflow: hidden;   /* Verhindert, dass Kind-Overflow den Body-Scroll auslöst */
}

/* ================= SIDEBAR ================= */
.sidebar {
    width: var(--sidebar-width);    /* Zentral via Variable – auch für Footer-Offset */
    position: relative;
    isolation: isolate; /* pseudo-layers sauber über dem bg stacken */
    background: var(--sidebar-bg, var(--card-bg));
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    overflow-x: hidden;
    flex-shrink: 0;
    min-height: 0;              /* Flex-Kind muss schrumpfen dürfen – für Scroll */
    padding-bottom: var(--spacing-lg);  /* Platz am Ende, damit letzte Links nicht abgeschnitten werden */
}

/* Sidebar: dezente Scrollbar (Scroll per Mausrad/Touch bleibt, Leiste kaum sichtbar) */
.sidebar {
    scrollbar-width: thin;
    scrollbar-color: transparent transparent;
}

.sidebar:hover {
    scrollbar-color: color-mix(in srgb, var(--border-color) 70%, transparent) transparent;
}

.sidebar::-webkit-scrollbar {
    width: 6px;
}

.sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
    background: transparent;
    border-radius: 3px;
}

.sidebar:hover::-webkit-scrollbar-thumb {
    background: var(--border-color);
}

@supports not (scrollbar-color: transparent transparent) {
    .sidebar {
        scrollbar-width: thin;
        scrollbar-color: var(--border-color) transparent;
    }
}

.sidebar::before {
    content: '';
    position: absolute;
    inset: 0 auto 0 0;
    width: 4px;
    background: transparent;
    z-index: 0;
    pointer-events: none;
}

/* Fallback ohne color-mix(): weiterhin neutral, aber aktiver Link bleibt akzentuiert */
@supports not (background: color-mix(in srgb, #000 10%, #fff)) {
    .sidebar {
        background: var(--sidebar-bg, var(--card-bg));
        border-right: 1px solid var(--border-color);
    }
}

.sidebar-section {
    padding: var(--spacing-lg) 0;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-section:first-child {
    padding-top: var(--spacing-lg); /* = 24px, wie alle anderen Sektionen – kein Extra-Gap */
}

.sidebar-section:last-child {
    border-bottom: none;
}

.sidebar-section-title {
    padding: 0 var(--spacing-lg) var(--spacing-sm) var(--spacing-lg);
    font-size: var(--font-size-sm);
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.5px;
}

.sidebar .nav-link {
    display: flex;
    align-items: center;
    padding: var(--spacing-md) var(--spacing-lg);
    color: var(--text-secondary);
    text-decoration: none;
    transition: all var(--transition-normal);
    border-left: 3px solid transparent;
}

.sidebar .nav-link:hover {
    background: var(--hover-bg);
    color: var(--text-color);
    text-decoration: none;
}

.sidebar .nav-link.active {
    background: color-mix(in srgb, var(--primary-light) 40%, transparent);
    border-left-color: var(--primary-color);
    color: var(--primary-color);
    font-weight: 500;
}

@supports not (background: color-mix(in srgb, #000 10%, #fff)) {
    .sidebar .nav-link.active {
        background: var(--primary-light);
    }
}

.sidebar .nav-link span:first-child {
    font-size: 18px;
    width: 32px;
    min-width: 32px;
    max-width: 32px;
    text-align: center;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
    margin-right: 12px;
}

/* ================================================================
   MODULE SWITCHER — pro Modul farbige Buttons (dezent)
   Voraussetzung: ModuleSwitcher setzt data-module am Link
   ================================================================ */
.module-btn[data-module] {
    --mw-module-btn-color: var(--primary-color);
    color: var(--mw-module-btn-color);
    border-color: color-mix(in srgb, var(--mw-module-btn-color) 55%, var(--border-color));
}
.module-btn[data-module]:hover {
    background: color-mix(in srgb, var(--mw-module-btn-color) 10%, transparent);
    border-color: color-mix(in srgb, var(--mw-module-btn-color) 70%, var(--border-color));
    color: var(--mw-module-btn-color);
}
.module-btn[data-module].active {
    background: color-mix(in srgb, var(--mw-module-btn-color) 14%, var(--card-bg));
    border-color: var(--mw-module-btn-color);
    color: var(--mw-module-btn-color);
}

@supports not (background: color-mix(in srgb, #000 10%, #fff)) {
    .module-btn[data-module] {
        border-color: var(--mw-module-btn-color);
    }
    .module-btn[data-module]:hover {
        background: var(--hover-bg);
    }
    .module-btn[data-module].active {
        background: var(--primary-light);
    }
}

/* Mapping: Switcher-ID → Token */
.module-btn[data-module="einkauf"] { --mw-module-btn-color: var(--module-color-einkauf); }
.module-btn[data-module="aufgaben"] { --mw-module-btn-color: var(--module-color-aufgaben); }
.module-btn[data-module="zeit"] { --mw-module-btn-color: var(--module-color-zeit); }
.module-btn[data-module="personal"] { --mw-module-btn-color: var(--module-color-personal); }
.module-btn[data-module="betriebsmittel"],
.module-btn[data-module="assets"] { --mw-module-btn-color: var(--module-color-betriebsmittel); }
.module-btn[data-module="vertrieb"] { --mw-module-btn-color: var(--module-color-vertrieb); }
.module-btn[data-module="planung"] { --mw-module-btn-color: var(--module-color-planung); }
.module-btn[data-module="monitoring"] { --mw-module-btn-color: var(--module-color-monitoring); }
.module-btn[data-module="system"],
.module-btn[data-module="admin"] { --mw-module-btn-color: var(--module-color-system); }

/* ================= MAIN CONTENT ================= */
.main-content {
    flex: 1;
    min-width: 0;               /* KRITISCH: Erlaubt Flex-Kind zu schrumpfen */
    display: flex;              /* WICHTIG: Flex-Container für Kinder */
    flex-direction: column;     /* Kinder untereinander */
    overflow-x: hidden;         /* Verhindert horizontales Überlaufen */
    overflow-y: auto;           /* Vertikales Scrollen bei Bedarf */
    padding: 0; /* Padding wird vom Container übernommen */
    background: var(--bg-color);
}

.content-page {
    display: none;
}

.content-page.active {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;               /* KRITISCH: Erlaubt Schrumpfen */
    min-height: 0;
    overflow-y: auto;           /* Inhalt scrollt innerhalb der Seite */
    align-items: stretch; /* WICHTIG: Kinder nehmen volle Breite ein */
    animation: fadeIn 0.2s ease;
}

.content-page.active > .container {
    width: 100%; /* Container nimmt volle Breite ein */
    flex: 0 1 auto; /* Kurze Seiten: kein Leerraum unter dem Inhalt */
    min-height: 0;
}

/* Fallback: Legacy-Seiten ohne direktes .container-Kind (sollte in keinem Modul mehr vorkommen) */
.main-content > .content-page.active:not(:has(> .container)) {
    padding: var(--layout-content-inset-top) var(--layout-content-inset-x) var(--layout-content-inset-bottom);
    box-sizing: border-box;
    gap: var(--layout-content-gap);
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.container {
    max-width: 100%;
    width: 100%;
    min-width: 0;               /* KRITISCH: Erlaubt Schrumpfen */
    padding: var(--layout-content-inset-top) var(--layout-content-inset-x) var(--layout-content-inset-bottom);
    box-sizing: border-box;     /* Padding wird in die Breite eingerechnet */
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    gap: var(--layout-content-gap);
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    /* Abstand zum Folgeblock: .container { gap } — kein extra margin */
    margin-bottom: 0;
    flex-shrink: 0;
}

.page-header h1,
.page-header h2 {
    font-size: var(--font-size-3xl);
    font-weight: 600;
    margin: 0;
}

.header-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

/* ================= CARDS ================= */
.card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

/* In .container übernimmt gap den Abstand — kein doppeltes margin */
.container > .card {
    margin-bottom: 0;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
}

.card-title {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
}

.card-link {
    font-size: 13px;
    color: var(--primary-color);
    text-decoration: none;
}

.card-link:hover {
    text-decoration: underline;
}

/* Dashboard Card */
.dashboard-card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--shadow);
}

.dashboard-card h3 {
    margin-bottom: 16px;
    font-size: 16px;
    font-weight: 600;
}

/* Dashboard Grids */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 24px;
    margin-bottom: 24px;
}

.dashboard-grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 24px;
}

.dashboard-grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 24px;
}

/* ================= STATS GRID ================= */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.stats-grid.stats-5 {
    grid-template-columns: repeat(5, 1fr);
}

.stat-card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 16px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.stat-card.stat-vertical {
    flex-direction: column;
    text-align: center;
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
}

.stat-icon.primary { background: var(--primary-light); color: var(--primary-color); }
.stat-icon.success { background: var(--success-light); color: var(--success-color); }
.stat-icon.warning { background: var(--warning-light); color: var(--warning-color); }
.stat-icon.danger { background: var(--danger-light); color: var(--danger-color); }
.stat-icon.info { background: var(--info-light); color: var(--info-color); }

.stat-content {
    flex: 1;
}

.stat-value,
.stat-number {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-color);
}

.stat-label {
    font-size: 14px;
    color: var(--text-muted);
    margin-top: 4px;
}

.stat-card.stat-success .stat-value,
.stat-card.stat-success .stat-number { color: var(--success-color); }
.stat-card.stat-warning .stat-value,
.stat-card.stat-warning .stat-number { color: var(--warning-color); }
.stat-card.stat-danger .stat-value,
.stat-card.stat-danger .stat-number { color: var(--danger-color); }
.stat-card.stat-info .stat-value,
.stat-card.stat-info .stat-number { color: var(--info-color); }

/* ================= FORMS ================= */
.form-group {
    margin-bottom: 16px;
}

.form-group label,
.form-group .form-label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-color);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 14px;
    background: var(--input-bg);
    color: var(--text-color);
    transition: border-color var(--transition-normal);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

.form-group input::placeholder,
.form-group textarea::placeholder {
    color: var(--text-muted);
}

/* Standalone controls (filter bars, modals, Vite shells using form-input/form-select) */
.form-input,
.form-select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 14px;
    min-height: 38px;
    background: var(--input-bg);
    color: var(--text-color);
    box-sizing: border-box;
    transition: border-color var(--transition-normal);
}

.form-input:focus,
.form-select:focus {
    outline: none;
    border-color: var(--primary-color);
}

.form-select {
    cursor: pointer;
    appearance: none;
    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='%236b7280' d='M2.5 4.5 6 8l3.5-3.5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

.form-row-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

.form-row-4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
}

/* Filter Bar */
.filter-bar {
    background: var(--card-bg);
    padding: 20px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    /* Abstand zum Folgeblock: .container { gap } */
    margin-bottom: 0;
    display: flex;
    gap: 15px;
    align-items: flex-end;
    flex-wrap: wrap;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.filter-group label {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
}

.filter-group select,
.filter-group input[type="text"],
.filter-group input[type="date"] {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 14px;
    min-width: 180px;
    background: var(--input-bg);
    color: var(--text-color);
    height: 38px;
}

.filter-group input[type="text"] {
    min-width: 250px;
}

/* Checkbox Label in Filter */
.filter-group .checkbox-label,
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-color);
    height: 38px;
    padding: 0 12px;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    white-space: nowrap;
}

.checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--primary-color);
}

.checkbox-label:hover {
    border-color: var(--primary-color);
    background: var(--primary-light);
}

/* Quick Actions */
.quick-actions {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.action-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 20px;
    background: var(--card-bg);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 14px;
    color: var(--text-color);
    text-align: center;
}

.action-btn:hover {
    border-color: var(--primary-color);
    background: var(--primary-light);
}

.action-btn span:first-child,
.action-btn .action-icon {
    font-size: 24px;
}

/* Active Filter Banner */
.active-filter-banner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    margin-bottom: 16px;
    background: var(--primary-light);
    border-left: 4px solid var(--primary-color);
    border-radius: var(--radius-md);
    font-size: 14px;
}

.active-filter-banner strong {
    color: var(--primary-color);
}

/* ================= BUTTONS ================= */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-normal);
    text-decoration: none;
}

.btn:hover {
    text-decoration: none;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--secondary-color);
    color: white;
}

.btn-secondary:hover {
    background: var(--secondary-hover);
}

.btn-success {
    background: var(--success-color);
    color: white;
}

.btn-warning {
    background: var(--warning-color);
    color: white;
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

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

.btn-outline:hover {
    background: var(--hover-bg);
}

.btn-ghost {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-muted);
}

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

.btn-sm {
    padding: 8px 16px;
    font-size: 13px;
}

.btn-lg {
    padding: 16px 32px;
    font-size: 16px;
}

.btn-icon {
    padding: 8px;
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 18px;
    border-radius: var(--radius-sm);
    min-width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-icon:hover {
    background: var(--hover-bg);
}

.btn-block {
    width: 100%;
}

/* ================= TABLES ================= */
.table-container {
    overflow-x: auto;
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 14px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    font-size: 14px;
}

th {
    background: var(--hover-bg);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
}

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

/* Clickable Table Rows */
.clickable-row {
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.clickable-row:hover {
    background-color: var(--primary-light) !important;
}

/* Data Table */
.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table thead {
    background: var(--hover-bg);
}

.data-table th {
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.data-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    font-size: 14px;
}

.data-table tr:hover {
    background: var(--hover-bg);
}

/* No Data State */
.no-data {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

/* ================= BADGES ================= */
.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: var(--radius-full);
    font-size: var(--font-size-sm);
    font-weight: 500;
}

.badge-primary {
    background: var(--primary-light);
    color: var(--primary-color);
}

.badge-success {
    background: var(--success-light);
    color: #166534;
}

.badge-warning {
    background: var(--warning-light);
    color: #b45309;
}

.badge-danger {
    background: var(--danger-light);
    color: #991b1b;
}

.badge-secondary {
    background: var(--hover-bg);
    color: var(--text-secondary);
}

/* Dark Mode overrides for badges */
[data-theme="dark"] .badge-primary {
    background: rgba(59, 130, 246, 0.2);
    color: #93c5fd;
}

[data-theme="dark"] .badge-success {
    background: rgba(34, 197, 94, 0.2);
    color: #86efac;
}

[data-theme="dark"] .badge-warning {
    background: rgba(245, 158, 11, 0.2);
    color: #fcd34d;
}

[data-theme="dark"] .badge-danger {
    background: rgba(239, 68, 68, 0.2);
    color: #fca5a5;
}

[data-theme="dark"] .badge-secondary {
    background: rgba(107, 114, 128, 0.2);
    color: #9ca3af;
}

.badge-info {
    background: var(--info-light);
    color: #1e40af;
}
[data-theme="dark"] .badge-info {
    background: rgba(59, 130, 246, 0.2);
    color: #93c5fd;
}

/* Status-specific badges */
.badge-open { background: #dbeafe; color: #1e40af; }
.badge-in-progress { background: #fef3c7; color: #b45309; }
.badge-completed { background: #dcfce7; color: #166534; }
.badge-cancelled { background: #e5e7eb; color: #4b5563; }
.badge-overdue { background: #fee2e2; color: #991b1b; }

[data-theme="dark"] .badge-open { background: #1e3a5f; color: #93c5fd; }
[data-theme="dark"] .badge-in-progress { background: #78350f; color: #fcd34d; }
[data-theme="dark"] .badge-completed { background: #14532d; color: #86efac; }
[data-theme="dark"] .badge-cancelled { background: #374151; color: #9ca3af; }
[data-theme="dark"] .badge-overdue { background: #7f1d1d; color: #fca5a5; }

/* ================= PRIORITY ================= */
.priority-high { color: var(--danger-color); }
.priority-medium { color: var(--warning-color); }
.priority-low { color: var(--success-color); }

/* ================= STAT CHANGE ================= */
.stat-change {
    font-size: var(--font-size-sm);
    font-weight: 600;
    margin-top: 4px;
}
.stat-change.positive { color: var(--success-color); }
.stat-change.negative { color: var(--danger-color); }

/* ================= STATUS BADGES ================= */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    font-size: var(--font-size-sm);
    font-weight: 600;
}
.status-active   { background: var(--success-light); color: #166534; }
.status-inactive { background: var(--danger-light);  color: #991b1b; }
.status-pending  { background: var(--warning-light); color: #b45309; }

[data-theme="dark"] .status-active   { background: rgba(20, 83, 45, 0.4);   color: #86efac; }
[data-theme="dark"] .status-inactive { background: rgba(127, 29, 29, 0.4);  color: #fca5a5; }
[data-theme="dark"] .status-pending  { background: rgba(120, 53, 15, 0.4);  color: #fcd34d; }

/* ================= MODALS ================= */
/* Basis-Modal: Versteckt bis .active gesetzt wird */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: var(--z-modal);
    justify-content: center;
    align-items: center;
}

.modal.active,
.modal.show {
    display: flex;
}

/* Legacy: Modal-Overlay Pattern (falls verwendet) */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    padding: var(--layout-modal-overlay-inset);
    background: rgba(0, 0, 0, 0.5);
    z-index: var(--z-modal);
    justify-content: center;
    align-items: center;
    box-sizing: border-box;
    overflow: hidden;
}

.modal-overlay.active,
.modal-overlay.show {
    display: flex;
}

/* .modal innerhalb .modal-overlay: als Content-Box darstellen, NICHT als zweites Overlay.
   align-items/justify-content von .modal (Overlay-Zentrierung) hier explizit zurücksetzen,
   sonst schrumpfen Header/Footer auf Inhaltsbreite und sitzen mittig. */
.modal-overlay .modal {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    position: relative;
    top: auto;
    left: auto;
    width: 100%;
    max-width: 700px;
    max-height: var(--layout-modal-max-height);
    overflow: hidden;
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    box-sizing: border-box;
}

/* Legacy-Modals ohne modal-header/body/footer: Innenabstand als Fallback */
.modal-overlay .modal:not(:has(.modal-header)) {
    overflow-y: auto;
    padding: var(--layout-modal-padding-y) var(--layout-modal-padding-x);
}

.modal-overlay .modal.modal-xs { max-width: 320px; }
.modal-overlay .modal.modal-sm { max-width: 400px; }
.modal-overlay .modal.modal-lg { max-width: 900px; }
.modal-overlay .modal.modal-xl { max-width: 1100px; }

/* Formular füllt Modal-Shell zwischen Header und Footer */
.modal-overlay .modal > .modal-form,
.modal-overlay .modal > form.modal-form {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    width: 100%;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    align-self: stretch;
    box-sizing: border-box;
}

.modal-content {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 700px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.modal-xs { max-width: 320px; }
.modal-sm { max-width: 400px; }
.modal-lg { max-width: 900px; }
.modal-xl { max-width: 1100px; }

.modal-header {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: var(--spacing-md);
    flex: 0 0 auto;
    flex-wrap: nowrap;
    position: relative;
    width: 100%;
    box-sizing: border-box;
    padding: var(--layout-modal-padding-y) var(--layout-modal-padding-x);
    /* Platz für absolut positioniertes X rechts oben */
    padding-right: calc(var(--layout-modal-padding-x) + 36px + var(--spacing-sm));
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2,
.modal-header h3 {
    margin: 0;
    flex: 1 1 auto;
    min-width: 0;
    font-size: var(--font-size-xl);
    font-weight: 600;
    line-height: 1.3;
    text-align: left;
}

.modal-close,
.modal-header .close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    margin: 0;
    padding: 0;
    background: none;
    border: none;
    border-radius: var(--radius-md);
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    color: var(--text-secondary);
    transition: color var(--transition-normal), background var(--transition-normal);
}

/* Schließen immer rechts oben im Header (nicht mittig / nicht umbrechen) */
.modal-header > .modal-close,
.modal-header > .close {
    position: absolute;
    top: var(--layout-modal-padding-y);
    right: var(--layout-modal-padding-x);
    z-index: 1;
}

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

.modal-body {
    flex: 1 1 auto;
    width: 100%;
    min-height: 0;
    min-width: 0;
    overflow-x: auto;
    overflow-y: auto;
    padding: var(--layout-modal-padding-y) var(--layout-modal-padding-x);
    -webkit-overflow-scrolling: touch;
    container-type: inline-size;
    box-sizing: border-box;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--spacing-md);
    flex-shrink: 0;
    padding: var(--layout-modal-padding-y) var(--layout-modal-padding-x);
    border-top: 1px solid var(--border-color);
    background: var(--card-bg);
}

.modal-footer .btn {
    min-height: 40px;
    max-width: 100%;
}

/* ================= SEARCH & FILTER ================= */
.search-bar {
    display: flex;
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-lg);
}

.search-input {
    flex: 1;
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 0 var(--spacing-md);
}

.search-input input {
    flex: 1;
    border: none;
    background: transparent;
    padding: var(--spacing-md) 0;
    font-size: var(--font-size-base);
    color: var(--text-color);
}

.search-input input:focus {
    outline: none;
}

.filter-select {
    padding: var(--spacing-md);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--input-bg);
    color: var(--text-color);
    min-width: 150px;
}

/* ================= USER MENU ================= */
.user-menu-container {
    position: relative;
}

.user-menu-button {
    display: flex;
    align-items: center;
    gap: 10px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--radius-md);
    color: var(--text-color);
    transition: background var(--transition-normal);
}

.user-menu-button:hover {
    background: var(--hover-bg);
}

.user-initials {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: var(--font-size-base);
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
}

.dropdown-arrow {
    display: inline-block;
    flex-shrink: 0;
    width: 0;
    height: 0;
    margin-left: 2px;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 5px solid var(--text-secondary);
    font-size: 0;
    line-height: 0;
    transition: transform var(--transition-normal);
}

.user-menu-button[aria-expanded="true"] .dropdown-arrow {
    transform: rotate(180deg);
}

.user-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    min-width: 220px;
    z-index: calc(var(--z-sticky) + 10);
}

.user-dropdown.is-open {
    display: block !important;
}

.user-dropdown-header {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    padding: var(--spacing-md);
}

.dropdown-initials {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
}

.dropdown-user-info {
    flex: 1;
}

.dropdown-user-name {
    font-weight: 600;
}

.dropdown-user-role {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
}

.user-dropdown-divider {
    height: 1px;
    background: var(--border-color);
}

.user-dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: var(--spacing-md) var(--spacing-md);
    text-decoration: none;
    color: var(--text-color);
    transition: background var(--transition-normal);
}

.user-dropdown-item:hover {
    background: var(--hover-bg);
    text-decoration: none;
}

.user-dropdown-item.logout {
    color: var(--danger-color);
}

/* ================= THEME TOGGLE (Schalter-Style) ================= */
.theme-toggle {
    background: var(--card-bg);
    border: 2px solid var(--border-color);
    border-radius: 20px;
    width: 50px;
    height: 28px;
    cursor: pointer;
    position: relative;
    transition: all 0.3s ease;
    padding: 0;
    flex-shrink: 0;
}

.theme-toggle:hover {
    border-color: var(--primary-color);
}

.theme-toggle::before {
    content: '☀️';
    position: absolute;
    left: 4px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 16px;
    transition: all 0.3s ease;
}

[data-theme="dark"] .theme-toggle::before {
    content: '🌙';
    left: 26px;
}

/* ================= LANGUAGE SWITCHER ================= */
.lang-switcher {
    position: relative;
    display: inline-flex;
    flex-shrink: 0;
}

.lang-switcher-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: var(--card-bg);
    border: 2px solid var(--border-color);
    border-radius: 20px;
    height: 32px;
    padding: 0 12px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-color);
    transition: all 0.2s ease;
    white-space: nowrap;
}

.lang-switcher-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.lang-globe {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.lang-switcher-btn .lang-code {
    text-transform: uppercase;
    font-size: 12px;
    letter-spacing: 0.5px;
    font-weight: 700;
}

.lang-switcher-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    min-width: 180px;
    z-index: 9999;
    padding: 4px 0;
    overflow: hidden;
}

.lang-switcher-dropdown.open {
    display: block;
}

.lang-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-color);
    transition: background 0.15s;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
}

.lang-option:hover {
    background: var(--hover-bg, rgba(0,0,0,0.04));
}

.lang-option.active {
    color: var(--primary-color);
    font-weight: 600;
}

.lang-option .lang-check {
    margin-left: auto;
    opacity: 0;
    font-size: 14px;
}

.lang-option.active .lang-check {
    opacity: 1;
}

.lang-code-label {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 20px;
    background: var(--primary-color);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.5px;
    border-radius: 4px;
    text-transform: uppercase;
    flex-shrink: 0;
}

.lang-option.active .lang-code-label {
    background: var(--primary-color);
}

/* ================= TABS ================= */
.tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: var(--spacing-lg);
    flex-wrap: wrap;
    gap: 2px;
}

.tab,
.tab-btn {
    padding: var(--spacing-md) var(--spacing-lg);
    background: none;
    border: none;
    cursor: pointer;
    font-size: var(--font-size-base);
    font-weight: 500;
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
    transition: all var(--transition-normal);
    margin-bottom: -1px; /* überlappt Border-Bottom der .tabs */
}

.tab:hover,
.tab-btn:hover {
    color: var(--text-color);
    background: var(--hover-bg);
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.tab.active,
.tab-btn.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
    background: var(--card-bg);
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

/* Variante D: Colorful Buttons */
.tabs-color {
    display: flex;
    gap: .4rem;
    flex-wrap: wrap;
    margin-bottom: var(--spacing-lg);
}

.tab-color {
    padding: 6px 20px;
    border-radius: var(--radius-full);
    border: 2px solid var(--tc, var(--border-color));
    background: transparent;
    color: var(--tc, var(--text-secondary));
    font-weight: 600;
    font-size: .8rem;
    cursor: pointer;
    transition: background .15s, color .15s, box-shadow .15s;
    white-space: nowrap;
}

.tab-color:hover {
    border-color: var(--tc, var(--primary-color));
    color: var(--tc, var(--primary-color));
    background: transparent;
}

.tab-color.active {
    background: var(--tc, var(--primary-color));
    border-color: var(--tc, var(--primary-color));
    color: #fff;
    box-shadow: 0 2px 10px rgba(0,0,0,.2);
}

[data-theme="dark"] .tab-color {
    background: transparent;
}

/* ================= ALERTS ================= */
.alert {
    padding: var(--spacing-md) var(--spacing-lg);
    border-radius: var(--radius-md);
    margin-bottom: var(--spacing-md);
}

.alert-success {
    background: var(--success-light);
    color: #166534;
    border: 1px solid var(--success-color);
}

.alert-warning {
    background: var(--warning-light);
    color: #b45309;
    border: 1px solid var(--warning-color);
}

.alert-danger {
    background: var(--danger-light);
    color: #991b1b;
    border: 1px solid var(--danger-color);
}

.alert-info {
    background: var(--info-light);
    color: #1e40af;
    border: 1px solid var(--info-color);
}

/* Dark Mode Alert Overrides — Textfarben für dunkle Hintergründe */
[data-theme="dark"] .alert-success {
    background: rgba(20, 83, 45, 0.45);
    color: #86efac;
    border-color: #22c55e;
}
[data-theme="dark"] .alert-warning {
    background: rgba(120, 53, 15, 0.45);
    color: #fcd34d;
    border-color: #f59e0b;
}
[data-theme="dark"] .alert-danger {
    background: rgba(127, 29, 29, 0.45);
    color: #fca5a5;
    border-color: #ef4444;
}
[data-theme="dark"] .alert-info {
    background: rgba(30, 58, 95, 0.45);
    color: #93c5fd;
    border-color: #3b82f6;
}

/* ================= ERROR MESSAGE ================= */
.error-message {
    color: var(--danger-color);
    margin-top: var(--spacing-sm);
    font-size: var(--font-size-base);
}

.success-message {
    color: var(--success-color);
    margin-top: var(--spacing-sm);
    font-size: var(--font-size-base);
}

/* ================= NOTIFICATION BADGE ================= */
.notification-badge {
    position: absolute;
    top: -8px;
    right: -8px;
    background: var(--danger-color);
    color: white;
    border-radius: 50%;
    padding: 2px 6px;
    font-size: 11px;
    font-weight: bold;
    min-width: 18px;
    text-align: center;
}

/* ================= LOADING ================= */
/* Wrapper: center one .spinner (module accent via --primary-color on data-module) */
.loading,
.loading-spinner:has(.spinner) {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: var(--spacing-2xl);
}

.spinner,
.loading-spinner:not(:has(*)) {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    flex-shrink: 0;
}

/* Legacy wrapper that contained a nested .spinner — no second ring */
.loading-spinner:has(.spinner) {
    width: auto;
    height: auto;
    border: none;
    border-radius: 0;
    animation: none;
}

.mw-loading-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: color-mix(in srgb, var(--bg-color, #fff) 88%, transparent);
    z-index: 100;
}

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

/* ================= EMPTY STATE ================= */
.empty-state {
    text-align: center;
    padding: var(--spacing-2xl);
    color: var(--text-secondary);
}

.empty-state-icon {
    font-size: 48px;
    margin-bottom: var(--spacing-md);
}

.empty-state-title {
    font-size: var(--font-size-lg);
    font-weight: 600;
    margin-bottom: var(--spacing-sm);
    color: var(--text-color);
}

/* ================= TOOLTIPS ================= */
[data-tooltip] {
    position: relative;
}

[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    padding: var(--spacing-xs) var(--spacing-sm);
    background: var(--text-color);
    color: var(--card-bg);
    font-size: var(--font-size-sm);
    border-radius: var(--radius-sm);
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-fast);
    z-index: var(--z-tooltip);
}

[data-tooltip]:hover::after {
    opacity: 1;
    visibility: visible;
}

/* ================= RESPONSIVE ================= */
@media (max-width: 1024px) {
    .sidebar {
        width: 220px;
    }
    /* Footer ist jetzt in .main-content – kein Sidebar-Offset noetig */
}

@media (max-width: 768px) {
    :root {
        --layout-content-inset-top: 16px;
        --layout-content-inset-x: 20px;
        --layout-content-inset-bottom: 32px;
        --layout-modal-overlay-inset: var(--spacing-sm);
        --layout-modal-padding-x: var(--spacing-md);
        --layout-modal-padding-y: var(--spacing-md);
        --layout-modal-max-height: calc(100dvh - (2 * var(--layout-modal-overlay-inset)));
    }

    .modal-overlay {
        align-items: flex-end;
        padding: var(--layout-modal-overlay-inset);
    }

    .modal-overlay .modal {
        width: 100%;
        max-width: none;
        max-height: var(--layout-modal-max-height);
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    }

    .modal-overlay .modal.modal-xs,
    .modal-overlay .modal.modal-sm,
    .modal-overlay .modal.modal-lg,
    .modal-overlay .modal.modal-xl {
        max-width: none;
    }

    .modal-header h2,
    .modal-header h3 {
        font-size: var(--font-size-lg);
    }

    .modal-footer {
        justify-content: stretch;
    }

    .modal-footer .btn {
        flex: 1 1 calc(50% - var(--spacing-md));
        min-width: 0;
        white-space: normal;
        text-align: center;
    }

    .modal-footer .btn:only-child,
    .modal-footer .btn.btn-primary {
        flex: 1 1 100%;
    }

    /* Viele Actions: untereinander statt abgeschnitten */
    .modal-footer:has(.btn:nth-child(3)) .btn {
        flex: 1 1 100%;
    }

    .sidebar {
        display: none;
    }

    /* Sidebar weg → Footer braucht keinen besonderen Offset */

    .app-container {
        flex-direction: column;
    }

    /* Insets nur über .container / .content-page — kein Doppel-Padding */
    .main-content {
        padding: 0;
    }

    .form-row,
    .form-row-3,
    .form-row-4 {
        grid-template-columns: 1fr;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .top-bar {
        padding: 15px 20px;
    }

    .nav-brand {
        margin-left: 20px;
    }

}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
}

/* ================= PRINT ================= */
@media print {
    .sidebar,
    .top-bar,
    .btn,
    .modal-overlay {
        display: none !important;
    }

    .main-content {
        padding: 0;
    }

    body {
        background: white;
        color: black;
    }
}

/* ================================================================
   LEGAL FOOTER  –  Impressum, Datenschutz, Copyright
   Automatisch in jede Seite eingebettet via shared-components.js
   ================================================================ */

.legal-footer {
    position: sticky;
    bottom: 0;
    width: 100%;
    flex-shrink: 0;             /* Nie von content-page verdrängen lassen */
    margin-top: auto;
    padding: 5px var(--spacing-xl);
    background: var(--card-bg);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    font-size: 11px;
    color: var(--text-muted);
    z-index: 10;
    box-sizing: border-box;
}

.legal-footer__links {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.legal-footer__links a {
    color: var(--text-muted);
    text-decoration: none;
    transition: color 0.15s;
    white-space: nowrap;
}

.legal-footer__links a:hover {
    color: var(--primary-color);
    text-decoration: underline;
}

.legal-footer__sep {
    color: var(--border-color);
    user-select: none;
}

.legal-footer__copy {
    white-space: nowrap;
    font-size: 11px;
}

/* Passt sich dem Sidebar-Layout an */
.has-sidebar .legal-footer {
    /* Sidebar-Breite wird automatisch durch flex-layout berücksichtigt */
    margin-left: 0;
}

/* Footer im App-Shell: immer in .main-content (rechts neben Sidebar).
   Sticky am unteren Rand – identisch fuer alle Module. */
body.app-shell .main-content > .legal-footer {
    flex: 0 0 auto;
    position: sticky;
    bottom: 0;
    margin-top: auto;
    margin-left: 0;
    width: 100%;
}

[data-theme="dark"] .legal-footer {
    background: var(--card-bg);
    border-top-color: var(--border-color);
}

/* Legal pages in overlay modal */
.legal-modal-overlay .legal-modal {
    max-width: 760px;
}

.legal-modal__loading,
.legal-modal__error {
    color: var(--text-muted);
    font-size: var(--font-size-sm);
}

.legal-modal__body h1 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.legal-modal__body h2 {
    font-size: 1rem;
    margin-top: 1.5rem;
    margin-bottom: 0.35rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}

.legal-modal__body p,
.legal-modal__body address,
.legal-modal__body li {
    margin: 0 0 0.5rem;
    line-height: 1.6;
}

.legal-modal__body hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 1.5rem 0;
}

.legal-modal__body .notice,
.legal-modal__body .highlight {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: var(--spacing-md);
    font-size: var(--font-size-sm);
    color: var(--text-muted);
    margin-top: var(--spacing-lg);
}

.legal-modal__body table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--font-size-sm);
    margin: var(--spacing-md) 0;
}

.legal-modal__body th,
.legal-modal__body td {
    border: 1px solid var(--border-color);
    padding: 0.5rem 0.75rem;
    vertical-align: top;
}

/* Kontaktformular im Legal-Modal */
.legal-contact-form__intro {
    margin: 0 0 var(--spacing-md);
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
}

.legal-contact-form__grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--spacing-md);
}

@media (max-width: 640px) {
    .legal-contact-form__grid {
        grid-template-columns: 1fr;
    }
}

.legal-contact-form .form-group {
    margin-bottom: var(--spacing-md);
}

.legal-contact-form label {
    display: block;
    font-size: var(--font-size-sm);
    font-weight: 500;
    margin-bottom: 4px;
    color: var(--text-color);
}

.legal-contact-form input,
.legal-contact-form select,
.legal-contact-form textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font: inherit;
    color: var(--text-color);
    background: var(--card-bg);
}

.legal-contact-form textarea {
    resize: vertical;
    min-height: 120px;
}

.legal-contact-form__hp {
    position: absolute;
    left: -9999px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

.legal-contact-form__consent {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    margin: var(--spacing-md) 0;
    cursor: pointer;
}

.legal-contact-form__consent input {
    margin-top: 3px;
    flex-shrink: 0;
}

.legal-contact-form__consent a {
    color: var(--primary-color);
}

.legal-contact-form__status {
    font-size: var(--font-size-sm);
    margin: 0 0 var(--spacing-md);
}

.legal-contact-form__status--ok {
    color: var(--success-color, #16a34a);
}

.legal-contact-form__status--error {
    color: var(--danger-color, #dc2626);
}

.legal-contact-form__actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--spacing-md);
    flex-wrap: wrap;
}

@media (max-width: 640px) {
    .legal-footer {
        flex-direction: column;
        align-items: flex-start;
        padding: 10px var(--spacing-md);
    }
    .legal-footer__links {
        gap: 10px;
    }
}

/* ================================================================
   TOKEN BRIDGE — Neue kanonische Namen (forward-compatibility)
   Bestehender Code mit --primary-color etc. funktioniert weiterhin.
   Neuer Code kann die neuen Namen verwenden.
   ================================================================ */
:root {
  /* Semantische Farb-Aliase */
  --color-primary:         var(--primary-color);
  --color-primary-dark:    var(--primary-hover);
  --color-primary-light:   var(--primary-light);
  --color-secondary:       var(--secondary-color);
  --color-success:         var(--success-color);
  --color-success-bg:      var(--success-light);
  --color-warning:         var(--warning-color);
  --color-warning-bg:      var(--warning-light);
  --color-danger:          var(--danger-color);
  --color-danger-bg:       var(--danger-light);
  --color-info:            var(--info-color);
  --color-info-bg:         var(--info-light);
  --color-surface:         var(--card-bg);
  --color-background:      var(--bg-color);
  --color-border:          var(--border-color);
  --color-text:            var(--text-color);
  --color-text-muted:      var(--text-muted);
  --color-text-secondary:  var(--text-secondary);

  /* Modul-Farb-Tokens (werden via [data-module] überschrieben) */
  --module-color-einkauf:        #2563eb;
  --module-color-zeit:  #7c3aed;
  --module-color-personal: #16a34a;
  --module-color-betriebsmittel: #ea580c;
  --module-color-aufgaben:       #0d9488;
  --module-color-vertrieb:       #be185d;
  --module-color-planung:        #0f766e;
  --module-color-system:         #475569;
  --module-color-admin:          #475569;
  --module-color-monitoring:     #dc2626;
}

/* ================================================================
   MODUL-AKZENTFARBEN
   Jedes Modul setzt nur eine Zeile im <body>:
   <body data-module="zeit">
   Alle Komponenten (Buttons, Links, Borders) passen sich
   automatisch an.
   ================================================================ */
[data-module="einkauf"] {
  --primary-color: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #dbeafe;
}
[data-module="zeit"] {
  --primary-color: #7c3aed;
  --primary-hover: #6d28d9;
  --primary-light: #ede9fe;
}
[data-module="personal"] {
  --primary-color: #16a34a;
  --primary-hover: #15803d;
  --primary-light: #dcfce7;
}
[data-module="betriebsmittel"] {
  --primary-color: #ea580c;
  --primary-hover: #c2410c;
  --primary-light: #ffedd5;
}
[data-module="assets"] {
  --primary-color: #ea580c;
  --primary-hover: #c2410c;
  --primary-light: #ffedd5;
}
[data-module="aufgaben"] {
  --primary-color: #0d9488;
  --primary-hover: #0f766e;
  --primary-light: #ccfbf1;
}
[data-module="vertrieb"] {
  --primary-color: #be185d;
  --primary-hover: #9d174d;
  --primary-light: #fce7f3;
}
[data-module="planung"] {
  --primary-color: #0f766e;
  --primary-hover: #115e59;
  --primary-light: #ccfbf1;
}
[data-module="system"] {
  --primary-color: #475569;
  --primary-hover: #334155;
  --primary-light: #f1f5f9;
}
[data-module="admin"] {
  --primary-color: #475569;
  --primary-hover: #334155;
  --primary-light: #f1f5f9;
}
[data-module="monitoring"] {
  --primary-color: #dc2626;
  --primary-hover: #b91c1c;
  --primary-light: #fee2e2;
}

/* Dark-Mode: Modul-Akzent — primary-light als dunkle Tönung (nicht Light-Mode-Pastell) */
[data-theme="dark"][data-module="einkauf"],
[data-theme="dark"] [data-module="einkauf"] {
  --primary-light: #1e3a5f;
}
[data-theme="dark"][data-module="betriebsmittel"],
[data-theme="dark"] [data-module="assets"],
[data-theme="dark"] [data-module="betriebsmittel"],
[data-theme="dark"] [data-module="assets"] {
  --primary-light: #431407;
}
[data-theme="dark"][data-module="aufgaben"],
[data-theme="dark"] [data-module="aufgaben"] {
  --primary-light: #134e4a;
}
[data-theme="dark"][data-module="vertrieb"],
[data-theme="dark"] [data-module="vertrieb"] {
  --primary-light: #500724;
}
[data-theme="dark"][data-module="planung"],
[data-theme="dark"] [data-module="planung"] {
  --primary-light: #134e4a;
}
[data-theme="dark"][data-module="system"],
[data-theme="dark"][data-module="admin"],
[data-theme="dark"] [data-module="system"],
[data-theme="dark"] [data-module="admin"] {
  --primary-light: #334155;
}
[data-theme="dark"][data-module="zeit"],
[data-theme="dark"] [data-module="zeit"] {
  --primary-light: #2e1065;
}
[data-theme="dark"][data-module="personal"],
[data-theme="dark"] [data-module="personal"] {
  --primary-light: #052e16;
}
[data-theme="dark"][data-module="monitoring"],
[data-theme="dark"] [data-module="monitoring"] {
  --primary-light: #450a0a;
}

/* ================================================================
   NOTIFICATION CENTER
   Bell-Icon · Drawer · Stack-Toasts (unten rechts) · Countdown-Bar
   Komponente: NotificationCenter (shared-components.js)
   ================================================================ */

/* ── Bell Button (im TopBar) ── */
.notif-bell-btn {
    position: relative;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 6px 8px;
    border-radius: var(--radius-md);
    color: var(--text-color);
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition-normal);
    flex-shrink: 0;
}
.notif-bell-btn:hover { background: var(--hover-bg); }
.notif-bell-btn.has-unread { animation: bell-ring 0.6s ease 0.2s 1; }

@keyframes bell-ring {
    0%,100% { transform: rotate(0); }
    20%      { transform: rotate(-15deg); }
    40%      { transform: rotate(15deg); }
    60%      { transform: rotate(-10deg); }
    80%      { transform: rotate(10deg); }
}

/* Unread Badge auf der Bell */
.notif-bell-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    min-width: 18px;
    height: 18px;
    background: var(--danger-color, #dc2626);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
    border-radius: 9999px;
    padding: 0 4px;
    pointer-events: none;
    display: none;
}
.notif-bell-badge.visible { display: block; }

/* ── Notification Drawer (rechts, slide-in) ── */
.notif-drawer-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1900;
    background: transparent;
    display: none;
}
.notif-drawer-backdrop.open { display: block; }

.notif-drawer {
    position: fixed;
    top: var(--top-bar-height, 60px);
    right: 0;
    width: 380px;
    max-width: calc(100vw - 1rem);
    height: calc(100vh - var(--top-bar-height, 60px));
    background: var(--card-bg);
    border-left: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.25s cubic-bezier(.4,0,.2,1);
}
.notif-drawer.open { transform: translateX(0); }

.notif-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}
.notif-drawer-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-color);
    display: flex;
    align-items: center;
    gap: .5rem;
}
.notif-drawer-actions {
    display: flex;
    align-items: center;
    gap: .5rem;
}
.notif-drawer-clear {
    font-size: .75rem;
    color: var(--text-secondary);
    background: none;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: .25rem .65rem;
    cursor: pointer;
    transition: all var(--transition-normal);
}
.notif-drawer-clear:hover { color: var(--danger-color); border-color: var(--danger-color); }
.notif-drawer-close {
    background: none;
    border: none;
    font-size: 1.25rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: .25rem;
    border-radius: var(--radius-md);
    transition: background var(--transition-normal);
    line-height: 1;
}
.notif-drawer-close:hover { background: var(--hover-bg); color: var(--text-color); }

.notif-drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: .5rem 0;
}
.notif-drawer-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-secondary);
    gap: .75rem;
    padding: 2rem;
    text-align: center;
}
.notif-drawer-empty-icon { font-size: 2.5rem; opacity: .5; }

/* ── Notification Item (im Drawer) ── */
.notif-item {
    display: flex;
    align-items: flex-start;
    gap: .75rem;
    padding: .85rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    cursor: default;
    transition: background var(--transition-normal);
    position: relative;
}
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: var(--hover-bg); }
.notif-item.unread { background: var(--primary-light, #eff6ff); }
.notif-item.unread::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--primary-color);
    border-radius: 0 2px 2px 0;
}
[data-theme="dark"] .notif-item.unread { background: rgba(255,255,255,.04); }

.notif-item-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
    margin-top: 2px;
}
/* Farben je Typ */
.notif-item-icon.type-success  { background: #dcfce7; color: #16a34a; }
.notif-item-icon.type-error    { background: #fee2e2; color: #dc2626; }
.notif-item-icon.type-warning  { background: #fef9c3; color: #d97706; }
.notif-item-icon.type-info     { background: #dbeafe; color: #2563eb; }
.notif-item-icon.type-chat     { background: #ede9fe; color: #7c3aed; }
.notif-item-icon.type-alarm    { background: #fee2e2; color: #dc2626; }
.notif-item-icon.type-system   { background: #f1f5f9; color: #475569; }
[data-theme="dark"] .notif-item-icon.type-success  { background: #052e16; color: #4ade80; }
[data-theme="dark"] .notif-item-icon.type-error    { background: #450a0a; color: #f87171; }
[data-theme="dark"] .notif-item-icon.type-warning  { background: #422006; color: #fbbf24; }
[data-theme="dark"] .notif-item-icon.type-info     { background: #1e3a5f; color: #60a5fa; }
[data-theme="dark"] .notif-item-icon.type-chat     { background: #2e1065; color: #a78bfa; }
[data-theme="dark"] .notif-item-icon.type-alarm    { background: #450a0a; color: #f87171; }
[data-theme="dark"] .notif-item-icon.type-system   { background: #1e293b; color: #94a3b8; }

.notif-item-content { flex: 1; min-width: 0; }
.notif-item-title {
    font-size: .875rem;
    font-weight: 600;
    color: var(--text-color);
    margin-bottom: .15rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.notif-item-message {
    font-size: .8rem;
    color: var(--text-secondary);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.notif-item-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: .3rem;
}
.notif-item-time {
    font-size: .7rem;
    color: var(--text-secondary);
}
.notif-item-dismiss {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: .85rem;
    padding: 2px 4px;
    border-radius: var(--radius-sm);
    opacity: 0;
    transition: opacity var(--transition-normal);
}
.notif-item:hover .notif-item-dismiss { opacity: 1; }
.notif-item-dismiss:hover { color: var(--danger-color); background: var(--hover-bg); }

/* Actions innerhalb eines Items */
.notif-item-actions {
    display: flex;
    gap: .4rem;
    margin-top: .5rem;
    flex-wrap: wrap;
}
.notif-item-action-btn {
    font-size: .75rem;
    padding: .2rem .6rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    color: var(--text-color);
    cursor: pointer;
    font-weight: 500;
    transition: all var(--transition-normal);
}
.notif-item-action-btn:hover { background: var(--primary-color); color: #fff; border-color: var(--primary-color); }
.notif-item-action-btn.primary { background: var(--primary-color); color: #fff; border-color: var(--primary-color); }
.notif-item-action-btn.danger  { background: var(--danger-color);  color: #fff; border-color: var(--danger-color); }

/* ── Stack-Toast (Popup unten rechts, flüchtig) ── */
.notif-stack {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 2100;
    display: flex;
    flex-direction: column-reverse;
    gap: .6rem;
    width: 340px;
    max-width: calc(100vw - 2rem);
    pointer-events: none;
}

.notif-toast {
    pointer-events: all;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: .85rem 1rem;
    display: flex;
    align-items: flex-start;
    gap: .65rem;
    transform: translateY(20px);
    opacity: 0;
    transition: transform .25s cubic-bezier(.4,0,.2,1), opacity .25s;
    overflow: hidden;
    position: relative;
}
.notif-toast.visible { transform: translateY(0); opacity: 1; }
.notif-toast.leaving { transform: translateY(10px); opacity: 0; }

/* Farbstreifen links */
.notif-toast::before {
    content: '';
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 4px;
}
.notif-toast.type-success::before { background: var(--success-color, #16a34a); }
.notif-toast.type-error::before   { background: var(--danger-color,  #dc2626); }
.notif-toast.type-warning::before { background: var(--warning-color, #d97706); }
.notif-toast.type-info::before    { background: var(--info-color,    #0ea5e9); }
.notif-toast.type-chat::before    { background: #7c3aed; }
.notif-toast.type-alarm::before   { background: var(--danger-color,  #dc2626); }
.notif-toast.type-system::before  { background: var(--text-secondary,#6b7280); }

.notif-toast-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .95rem;
    flex-shrink: 0;
}
/* Gleiche Farben wie im Drawer */
.notif-toast.type-success .notif-toast-icon { background: #dcfce7; color: #16a34a; }
.notif-toast.type-error   .notif-toast-icon { background: #fee2e2; color: #dc2626; }
.notif-toast.type-warning .notif-toast-icon { background: #fef9c3; color: #d97706; }
.notif-toast.type-info    .notif-toast-icon { background: #dbeafe; color: #2563eb; }
.notif-toast.type-chat    .notif-toast-icon { background: #ede9fe; color: #7c3aed; }
.notif-toast.type-alarm   .notif-toast-icon { background: #fee2e2; color: #dc2626; }
.notif-toast.type-system  .notif-toast-icon { background: #f1f5f9; color: #475569; }
[data-theme="dark"] .notif-toast.type-success .notif-toast-icon { background: #052e16; color: #4ade80; }
[data-theme="dark"] .notif-toast.type-error   .notif-toast-icon { background: #450a0a; color: #f87171; }
[data-theme="dark"] .notif-toast.type-warning .notif-toast-icon { background: #422006; color: #fbbf24; }
[data-theme="dark"] .notif-toast.type-info    .notif-toast-icon { background: #1e3a5f; color: #60a5fa; }
[data-theme="dark"] .notif-toast.type-chat    .notif-toast-icon { background: #2e1065; color: #a78bfa; }
[data-theme="dark"] .notif-toast.type-alarm   .notif-toast-icon { background: #450a0a; color: #f87171; }
[data-theme="dark"] .notif-toast.type-system  .notif-toast-icon { background: #1e293b; color: #94a3b8; }

.notif-toast-body { flex: 1; min-width: 0; }
.notif-toast-title {
    font-size: .85rem;
    font-weight: 700;
    color: var(--text-color);
    margin-bottom: .1rem;
}
.notif-toast-message {
    font-size: .8rem;
    color: var(--text-secondary);
    line-height: 1.4;
}
.notif-toast-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1rem;
    padding: 0;
    line-height: 1;
    flex-shrink: 0;
    margin-top: 1px;
}
.notif-toast-close:hover { color: var(--text-color); }
.notif-toast-actions {
    display: flex;
    gap: .4rem;
    margin-top: .5rem;
}

/* ── Countdown-Toast (Stiller Alarm) ── */
.notif-toast.type-alarm .notif-countdown-bar-wrap {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 4px;
    background: var(--border-color);
}
.notif-toast.type-alarm .notif-countdown-bar {
    height: 100%;
    background: var(--danger-color, #dc2626);
    width: 100%;
    transition: width linear;
}

/* ── Animations ── */
@keyframes notif-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(220,38,38,.4); }
    50%       { box-shadow: 0 0 0 6px rgba(220,38,38,0); }
}
.notif-toast.type-alarm { animation: notif-pulse 1.5s ease-in-out infinite; }

/* Toast-Komponente (Toast.show) — Slide-Animationen */
@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to   { transform: translateX(0);    opacity: 1; }
}
@keyframes slideOut {
    from { transform: translateX(0);    opacity: 1; }
    to   { transform: translateX(100%); opacity: 0; }
}

