/* ==========================================================================
   Sidebar — ruhige, inhaltsorientierte Navigation

   Standard ist die schmale Icon-Leiste. Der Hamburger im Header klappt sie
   auf (.is-sidebar-expanded am .app-shell); ein Klick auf einen Nav-Punkt
   fährt sie wieder ein. Unter 640px liegt sie als Overlay über dem Inhalt.

   Die Sidebar hat ein eigenes, immer-dunkles Farbschema (--sb-*), das
   unabhängig vom Light/Dark-Theme der restlichen App bleibt — bewusster
   Kontrast zum hellen Content-Bereich, wie bei Linear/Vercel-Admin-UIs.
   ========================================================================== */

.sidebar {
    /* ── Eigene Palette, losgelöst von den globalen Theme-Tokens ────────── */
    --sb-bg: linear-gradient(180deg, #163869 0%, #0c2244 100%);
    --sb-border: rgba(255, 255, 255, 0.08);
    --sb-border-strong: rgba(255, 255, 255, 0.16);
    --sb-text: #f3f6fb;
    --sb-text-secondary: #b7c2d6;
    --sb-text-muted: #7c88a3;
    --sb-text-disabled: #565f75;
    --sb-hover-bg: rgba(255, 255, 255, 0.07);
    --sb-active-bg: rgba(82, 179, 55, 0.18);
    --sb-accent: #7ccf63;
    --sb-accent-strong: #a6e292;
    --sb-danger: #f87171;
    --sb-danger-bg: rgba(248, 113, 113, 0.14);

    /* Ein paar farbige Akzente für Section-Marker (zyklisch) */
    --sb-hue-1: #7ccf63;
    --sb-hue-2: #8eaad4;
    --sb-hue-3: #34d399;
    --sb-hue-4: #fbbf24;

    grid-column: 1;
    grid-row: 1 / -1;
    align-self: start;
    position: sticky;
    top: 0;
    z-index: var(--z-sidebar);
    display: flex;
    flex-direction: column;
    width: var(--sidebar-w-collapsed);
    height: 100vh;
    background: var(--sb-bg);
    border-right: 1px solid var(--sb-border);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    transition: width var(--duration-base) var(--ease-out);
}

.app-shell.is-sidebar-expanded .sidebar {
    width: var(--sidebar-w);
}

/* ── Kopf (Logo) ─────────────────────────────────────────────────────── */
.sidebar-header {
    position: relative;
    display: flex;
    align-items: center;
    flex-shrink: 0;
    height: var(--header-h);
    padding: 0 var(--space-4);
    border-bottom: 1px solid var(--sb-border);
}
/* Farbiger Verlaufsstreifen unter dem Logo-Bereich */
.sidebar-header::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: -1px;
    height: 2px;
    background: linear-gradient(90deg, var(--sb-hue-1), var(--sb-hue-2), var(--sb-hue-3));
    opacity: 0.7;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-width: 0;
    color: inherit;
    text-decoration: none;
}
.sidebar-brand:hover { text-decoration: none; }

.sidebar-logo {
    flex-shrink: 0;
    width: 30px;
    height: 30px;
    object-fit: contain;
    border-radius: var(--radius-sm);
    transition: transform var(--duration-base) var(--ease-out);
}
.sidebar-brand:hover .sidebar-logo { transform: scale(1.05); }

.sidebar-title {
    font-size: var(--fs-15);
    font-weight: var(--fw-bold);
    letter-spacing: -0.015em;
    color: var(--sb-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Navigation ──────────────────────────────────────────────────────── */
.sidebar-nav {
    flex: 1;
    padding: var(--space-4) var(--space-3);
    overflow-x: hidden;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--sb-border-strong) transparent;
}
.sidebar-nav::-webkit-scrollbar { width: 6px; }
.sidebar-nav::-webkit-scrollbar-thumb {
    background: var(--sb-border-strong);
    border-radius: var(--radius-pill);
}
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }

.nav-section + .nav-section {
    margin-top: var(--space-4);
    padding-top: var(--space-4);
    border-top: 1px solid var(--sb-border);
}

.nav-section-title {
    position: relative;
    padding-left: 12px;
    font-size: var(--fs-11);
    font-weight: var(--fw-bold);
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--sb-text-muted);
    white-space: nowrap;
    transition: color var(--duration-fast) var(--ease-out);
}
/* Farbiger Punkt vor dem Section-Titel, zyklisch durch die Akzentfarben */
.nav-section-title::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    width: 5px;
    height: 5px;
    border-radius: var(--radius-pill);
    background: var(--sb-hue-1);
    transform: translateY(-50%);
}
.nav-section:nth-of-type(4n+2) .nav-section-title::before { background: var(--sb-hue-2); }
.nav-section:nth-of-type(4n+3) .nav-section-title::before { background: var(--sb-hue-3); }
.nav-section:nth-of-type(4n+4) .nav-section-title::before { background: var(--sb-hue-4); }

.nav-section-toggle {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 0 var(--space-3) var(--space-2);
    border: 0;
    background: none;
    cursor: pointer;
    font: inherit;
    text-align: left;
}
.nav-section-toggle:hover .nav-section-title { color: var(--sb-text-secondary); }

.nav-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--space-3);
    height: 38px;
    padding: 0 var(--space-3);
    margin-bottom: 2px;
    border-radius: var(--radius-md);
    color: var(--sb-text-secondary);
    font-size: var(--fs-14);
    font-weight: var(--fw-medium);
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color var(--duration-fast) var(--ease-out),
                color var(--duration-fast) var(--ease-out),
                transform var(--duration-fast) var(--ease-out);
}

.nav-item-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 26px;
    height: 26px;
    border-radius: var(--radius-sm);
    color: var(--sb-text-muted);
    transition: background-color var(--duration-fast) var(--ease-out),
                color var(--duration-fast) var(--ease-out);
}
.nav-item-icon .icon { font-size: 18px; }
.nav-item-icon svg { stroke: currentColor; }

.nav-item-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nav-item:hover {
    background: var(--sb-hover-bg);
    color: var(--sb-text);
    text-decoration: none;
    transform: translateX(1px);
}
.nav-item:hover .nav-item-icon { color: var(--sb-text); }

.nav-item:focus-visible {
    outline: 2px solid var(--sb-accent);
    outline-offset: -2px;
}

.nav-item.active,
.nav-item.is-active {
    background: linear-gradient(90deg, var(--sb-active-bg), transparent);
    color: var(--sb-accent-strong);
    font-weight: var(--fw-semibold);
}
.nav-item.active .nav-item-icon,
.nav-item.is-active .nav-item-icon {
    background: linear-gradient(150deg, var(--sb-hue-1), var(--sb-hue-2));
    color: #0b1120;
    box-shadow: var(--shadow-xs);
}

.nav-item.active::before,
.nav-item.is-active::before {
    content: '';
    position: absolute;
    left: -3px;
    top: 7px;
    bottom: 7px;
    width: 3px;
    border-radius: var(--radius-pill);
    background: linear-gradient(180deg, var(--sb-hue-1), var(--sb-hue-2));
    box-shadow: 0 0 10px rgba(124, 207, 99, 0.55);
}

.nav-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    margin-left: auto;
    border-radius: var(--radius-pill);
    background: rgba(255, 255, 255, 0.08);
    color: var(--sb-text-secondary);
    font-size: var(--fs-11);
    font-weight: var(--fw-bold);
    line-height: 1;
    box-shadow: inset 0 0 0 1px var(--sb-border);
}
.nav-item.active .nav-badge,
.nav-item.is-active .nav-badge {
    background: var(--sb-accent);
    color: #0b1120;
}

/* ── Aufklappbare Gruppe ─────────────────────────────────────────────── */
.nav-group { margin-bottom: 2px; }

.nav-chevron {
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
    margin-left: auto;
    color: var(--sb-text-disabled);
    transition: transform var(--duration-base) var(--ease-out);
}
.nav-chevron .icon { font-size: 15px; }
.nav-group.open > .nav-group-toggle .nav-chevron { transform: rotate(90deg); }

.nav-group.open > .nav-group-toggle {
    color: var(--sb-text);
}
.nav-group.open > .nav-group-toggle .nav-item-icon { color: var(--sb-text-secondary); }

/* Die Höhe wird beim Auf-/Zuklappen per JS gesetzt, damit die Animation
   unabhängig von der Anzahl der Einträge sauber läuft. */
.nav-group-items {
    height: 0;
    overflow: hidden;
    transition: height var(--duration-base) var(--ease-out);
}
/* Eingerückte Optik nur für echte Untermenüs — die Hauptpunkte (.nav-section)
   behalten ihre normale Item-Größe, nur das Auf-/Zuklappen wird geteilt. */
.nav-group:not(.nav-section) > .nav-group-items {
    position: relative;
    margin-left: 12px;
    padding-left: var(--space-3);
}
.nav-group:not(.nav-section) > .nav-group-items::before {
    content: '';
    position: absolute;
    left: 0;
    top: 4px;
    bottom: 4px;
    width: 1px;
    background: var(--sb-border-strong);
}
.nav-group:not(.nav-section) > .nav-group-items > .nav-item {
    height: 34px;
    padding-left: var(--space-3);
    font-size: var(--fs-13);
}
.nav-group:not(.nav-section) > .nav-group-items > .nav-item .nav-item-icon { width: 18px; height: 18px; }
.nav-group:not(.nav-section) > .nav-group-items > .nav-item .nav-item-icon .icon { font-size: 16px; }
.nav-group:not(.nav-section) > .nav-group-items > .nav-item.active::before,
.nav-group:not(.nav-section) > .nav-group-items > .nav-item.is-active::before { left: calc(-1 * var(--space-3) - 4px); }

/* ── Fuß: Benutzerinfo + Abmelden ────────────────────────────────────── */
.sidebar-footer {
    flex-shrink: 0;
    padding: var(--space-3);
    border-top: 1px solid var(--sb-border);
    background: rgba(0, 0, 0, 0.15);
}

.sidebar-user-row {
    display: flex;
    align-items: center;
    gap: var(--space-1);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex: 1;
    min-width: 0;
    padding: var(--space-2);
    border-radius: var(--radius-md);
    color: inherit;
    text-decoration: none;
    transition: background-color var(--duration-fast) var(--ease-out);
}
.sidebar-user:hover {
    background: var(--sb-hover-bg);
    text-decoration: none;
    color: inherit;
}

.sidebar-user-avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    border-radius: var(--radius-pill);
    background: linear-gradient(150deg, var(--sb-hue-1), var(--sb-hue-2));
    color: #0b1120;
    font-size: var(--fs-12);
    font-weight: var(--fw-bold);
    text-transform: uppercase;
    letter-spacing: 0.02em;
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.2), 0 0 0 3px var(--sb-border-strong);
}

.sidebar-user-info {
    flex: 1;
    min-width: 0;
}

.sidebar-user-name {
    font-size: var(--fs-13);
    font-weight: var(--fw-semibold);
    line-height: 1.35;
    color: var(--sb-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-user-role,
.sidebar-user-company {
    font-size: var(--fs-11);
    line-height: 1.35;
    color: var(--sb-text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-logout {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: var(--radius-md);
    background: none;
    color: var(--sb-text-muted);
    cursor: pointer;
    text-decoration: none;
    transition: background-color var(--duration-fast) var(--ease-out),
                color var(--duration-fast) var(--ease-out);
}
.sidebar-logout:hover {
    background: var(--sb-danger-bg);
    color: var(--sb-danger);
    text-decoration: none;
}
.sidebar-logout .icon { font-size: 18px; }

/* ==========================================================================
   Eingeklappte Icon-Leiste (Desktop-Standard)
   ========================================================================== */
@media (min-width: 641px) {
    .app-shell:not(.is-sidebar-expanded) .sidebar-header {
        padding: 0;
        justify-content: center;
    }
    .app-shell:not(.is-sidebar-expanded) .sidebar-title,
    .app-shell:not(.is-sidebar-expanded) .nav-section-toggle,
    .app-shell:not(.is-sidebar-expanded) .nav-item-label,
    .app-shell:not(.is-sidebar-expanded) .nav-chevron,
    .app-shell:not(.is-sidebar-expanded) .nav-badge,
    .app-shell:not(.is-sidebar-expanded) .sidebar-user-info {
        display: none;
    }

    .app-shell:not(.is-sidebar-expanded) .sidebar-nav {
        padding: var(--space-4) var(--space-2);
    }
    .app-shell:not(.is-sidebar-expanded) .nav-item {
        justify-content: center;
        padding: 0;
        gap: 0;
    }
    .app-shell:not(.is-sidebar-expanded) .nav-item-icon { width: 22px; height: 22px; }
    .app-shell:not(.is-sidebar-expanded) .nav-item-icon .icon { font-size: 20px; }

    /* Der Ein-/Ausklapp-Zustand der Hauptpunkte betrifft nur die breite
       Sidebar — in der schmalen Icon-Leiste bleiben alle Icons sichtbar. */
    .app-shell:not(.is-sidebar-expanded) .nav-section > .nav-group-items {
        height: auto !important;
    }

    .app-shell:not(.is-sidebar-expanded) .sidebar-user-row { flex-direction: column; gap: var(--space-2); }
    .app-shell:not(.is-sidebar-expanded) .sidebar-user { justify-content: center; padding: var(--space-2) 0; }

    /* Tooltip in der schmalen Leiste */
    .app-shell:not(.is-sidebar-expanded) .nav-item[data-label]::after,
    .app-shell:not(.is-sidebar-expanded) .sidebar-logout[data-label]::after {
        content: attr(data-label);
        position: absolute;
        left: calc(100% + 10px);
        top: 50%;
        z-index: var(--z-tooltip);
        padding: 5px var(--space-2);
        border-radius: var(--radius-sm);
        background: #0b1120;
        color: var(--sb-text);
        font-size: var(--fs-12);
        font-weight: var(--fw-medium);
        white-space: nowrap;
        opacity: 0;
        transform: translate(-4px, -50%);
        pointer-events: none;
        box-shadow: var(--shadow-md);
        transition: opacity var(--duration-fast) var(--ease-out),
                    transform var(--duration-fast) var(--ease-out);
    }
    .app-shell:not(.is-sidebar-expanded) .sidebar-logout { position: relative; }
    .app-shell:not(.is-sidebar-expanded) .nav-item:hover[data-label]::after,
    .app-shell:not(.is-sidebar-expanded) .sidebar-logout:hover[data-label]::after {
        opacity: 1;
        transform: translate(0, -50%);
    }
}

/* ==========================================================================
   Mobile — Sidebar als Overlay
   ========================================================================== */
@media (max-width: 640px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        /* Über dem Header, sonst verdeckt dieser die oberen 60px der
           Schublade – und damit das Logo. */
        z-index: calc(var(--z-header) + 2);
        width: var(--sidebar-w);
        max-width: 84vw;
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
        transition: transform var(--duration-base) var(--ease-out);
    }
    .app-shell.is-sidebar-open .sidebar { transform: translateX(0); }
}

/* ── Overlay hinter der mobilen Sidebar ──────────────────────────────── */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: calc(var(--z-sidebar) - 1);
    background: var(--surface-overlay);
    opacity: 0;
    transition: opacity var(--duration-base) var(--ease-out);
}
@media (max-width: 640px) {
    .sidebar-overlay { z-index: calc(var(--z-header) + 1); }
    .app-shell.is-sidebar-open .sidebar-overlay {
        display: block;
        opacity: 1;
    }
}
