/* ==========================================================================
   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 900px liegt sie als Overlay über dem Inhalt.
   ========================================================================== */

.sidebar {
    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(--surface-raised);
    border-right: 1px solid var(--border-subtle);
    overflow: hidden;
    transition: width var(--duration-base) var(--ease-out);
}

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

/* ── Kopf (Logo) ─────────────────────────────────────────────────────── */
.sidebar-header {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    height: var(--header-h);
    padding: 0 var(--space-4);
    border-bottom: 1px solid var(--border-subtle);
}

.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;
}

.sidebar-title {
    font-size: var(--fs-15);
    font-weight: var(--fw-semibold);
    letter-spacing: -0.01em;
    color: var(--text-primary);
    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;
}

.nav-section + .nav-section { margin-top: var(--space-4); }

.nav-section-title {
    padding: 0 var(--space-3) var(--space-2);
    font-size: var(--fs-11);
    font-weight: var(--fw-semibold);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    white-space: nowrap;
}

.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-sm);
    color: var(--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);
}

.nav-item-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    color: var(--text-muted);
    transition: 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(--surface-sunken);
    color: var(--text-primary);
    text-decoration: none;
}
.nav-item:hover .nav-item-icon { color: var(--text-secondary); }

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

.nav-item.active,
.nav-item.is-active {
    background: var(--brand-soft);
    color: var(--brand);
    font-weight: var(--fw-semibold);
}
.nav-item.active .nav-item-icon,
.nav-item.is-active .nav-item-icon { color: var(--brand); }

.nav-item.active::before,
.nav-item.is-active::before {
    content: '';
    position: absolute;
    left: -3px;
    top: 9px;
    bottom: 9px;
    width: 3px;
    border-radius: var(--radius-pill);
    background: var(--brand);
}

.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: var(--surface-sunken);
    color: var(--text-secondary);
    font-size: var(--fs-11);
    font-weight: var(--fw-semibold);
    line-height: 1;
}
.nav-item.active .nav-badge,
.nav-item.is-active .nav-badge {
    background: var(--brand);
    color: var(--text-on-brand);
}

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

.nav-chevron {
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
    margin-left: auto;
    color: var(--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(--text-primary);
}
.nav-group.open > .nav-group-toggle .nav-item-icon { color: var(--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);
}
.nav-group-items > .nav-item {
    height: 34px;
    padding-left: var(--space-5);
    font-size: var(--fs-13);
}
.nav-group-items > .nav-item .nav-item-icon { width: 18px; height: 18px; }
.nav-group-items > .nav-item .nav-item-icon .icon { font-size: 16px; }

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

.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-sm);
    color: inherit;
    text-decoration: none;
    transition: background-color var(--duration-fast) var(--ease-out);
}
.sidebar-user:hover {
    background: var(--surface-sunken);
    text-decoration: none;
    color: inherit;
}

.sidebar-user-avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-pill);
    background: var(--brand-soft);
    color: var(--brand);
    font-size: var(--fs-12);
    font-weight: var(--fw-semibold);
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.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(--text-primary);
    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(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-logout {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: var(--radius-sm);
    background: none;
    color: var(--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(--danger-bg);
    color: var(--danger);
    text-decoration: none;
}
.sidebar-logout .icon { font-size: 18px; }

/* ==========================================================================
   Eingeklappte Icon-Leiste (Desktop-Standard)
   ========================================================================== */
@media (min-width: 901px) {
    .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-title,
    .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; }

    /* Untermenüs bleiben in der Leiste zu — ein Klick auf die Gruppe
       klappt zuerst die Sidebar auf (siehe shell.js). */
    .app-shell:not(.is-sidebar-expanded) .nav-group-items {
        height: 0 !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%;
        transform: translateY(-50%);
        z-index: var(--z-tooltip);
        padding: 5px var(--space-2);
        border-radius: var(--radius-sm);
        background: var(--neutral-900);
        color: var(--neutral-0);
        font-size: var(--fs-12);
        font-weight: var(--fw-medium);
        white-space: nowrap;
        opacity: 0;
        pointer-events: none;
        box-shadow: var(--shadow-md);
        transition: opacity 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;
    }
}

/* ==========================================================================
   Mobile — Sidebar als Overlay
   ========================================================================== */
@media (max-width: 900px) {
    .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: 900px) {
    .sidebar-overlay { z-index: calc(var(--z-header) + 1); }
    .app-shell.is-sidebar-open .sidebar-overlay {
        display: block;
        opacity: 1;
    }
}
