/**
 * ============================================
 * SIDEBAR - COLLAPSIBLE SIDEBAR
 * ============================================
 * Desktop: Fixed rechts, 2 States (Collapsed/Expanded)
 * Mobile: Slide-in Overlay von rechts
 *
 * Nutzt CSS Variablen aus eus.css:
 * - Colors: --primary, --success, --danger, --gray-*
 * - Backgrounds: --bg-card, --bg-light
 * - Spacing: --space-xs, --space-sm, --space-md, etc.
 * - Shadows: --shadow-sm, --shadow-md, --shadow-lg
 * - Transitions: --transition-base, --transition-fast
 * - Radius: --radius-sm, --radius-md, --radius-full
 */

/* ============================================
   SIDEBAR - CSS CUSTOM PROPERTIES
   ============================================ */
:root {
    /* Sidebar Widths - 2 States */
    --sidebar-width-expanded: 350px;
    --sidebar-width-collapsed: 80px;

    /* Sidebar Specific */
    --sidebar-transition-timing: cubic-bezier(0.4, 0, 0.2, 1);
    --sidebar-shadow: -2px 0 8px rgba(0, 0, 0, 0.1);

    /* Z-Index Layering */
    --sidebar-z-index: 1020;
    --sidebar-toggle-z-index: 1021;
    --sidebar-mobile-z-index: 1040;
}

/* ============================================
   REDUCED MOTION SUPPORT
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    .sidebar,
    .sidebar *,
    .sidebar-action-btn,
    .sidebar-section-content,
    .sidebar-section-toggle,
    .sidebar-badge,
    .content-with-sidebar {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ============================================
   SIDEBAR - DESKTOP (3 States)
   ============================================ */
@media (min-width: 992px) {
    /* Base Sidebar Container */
    .sidebar {
        position: fixed;
        right: 0;
        top: 0; /* Volle Höhe von oben */
        bottom: 0; /* Bis zum unteren Rand */
        width: var(--sidebar-width-collapsed); /* Default: collapsed */
        background: var(--bg-card);
        box-shadow: var(--sidebar-shadow);
        transition: width var(--transition-base) var(--sidebar-transition-timing);
        z-index: var(--sidebar-z-index);
        overflow-y: auto;
        overflow-x: hidden;
        padding: 0; /* Kein padding, Button bekommt volle Breite */
        display: flex;
        flex-direction: column;
        gap: 0;
    }

    /* State: Collapsed (80px) - Default */
    .sidebar[data-state="collapsed"] {
        width: var(--sidebar-width-collapsed);
    }

    /* State: Expanded (400px) */
    .sidebar[data-state="expanded"] {
        width: var(--sidebar-width-expanded);
    }

    /* Content Margin Adjustment - Via Klassen wie V2 */
    .content-with-sidebar {
        margin-right: var(--sidebar-width-expanded);
        transition: margin-right var(--transition-base) var(--sidebar-transition-timing);
        min-height: calc(100vh - 56px);
    }

    .content-with-sidebar.sidebar-collapsed {
        margin-right: var(--sidebar-width-collapsed);
    }

    /* Scrollbar Styling */
    .sidebar::-webkit-scrollbar {
        width: 6px;
    }

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

    .sidebar::-webkit-scrollbar-thumb {
        background: var(--gray-400);
        border-radius: var(--radius-full);
    }

    .sidebar::-webkit-scrollbar-thumb:hover {
        background: var(--gray-500);
    }
}

/* ============================================
   TOGGLE BUTTON - DESKTOP (Innerhalb Sidebar wie V2)
   ============================================ */
@media (min-width: 992px) {
    .sidebar-toggle-btn {
        width: 100%; /* Volle Breite der Sidebar */
        height: 40px; /* Flacher Button */
        background: var(--primary-light); /* Projekt-Farbe */
        color: var(--text-white);
        border: none;
        border-radius: 0; /* Keine Rundung, flach */
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        transition: all var(--transition-base);
        box-shadow: none;
        padding: 0;
        flex-shrink: 0; /* Button behält seine Höhe */
        order: -1; /* Ganz nach oben in der Flex-Sidebar */
    }

    .sidebar-toggle-btn:hover {
        background: var(--primary-dark);
        box-shadow: none;
    }

    .sidebar-toggle-btn i {
        font-size: 1rem;
        line-height: 1;
    }

    .sidebar-toggle-btn:focus-visible {
        outline: 2px solid var(--primary);
        outline-offset: 2px;
    }

}

/* ============================================
   ACTION BUTTONS - BASE
   ============================================ */
.sidebar-actions {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    padding: var(--space-sm);
    padding-top: var(--space-md); /* Abstand zum Button */
}

.sidebar-action-btn {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-md);
    border-radius: var(--radius-md);
    text-decoration: none;
    transition: all var(--transition-base);
    position: relative;
    border: none;
    white-space: nowrap;
    will-change: transform;
}

/* Button Colors (Bootstrap-Stil) */
.sidebar-action-btn.btn-success {
    background: linear-gradient(135deg, var(--success) 0%, #218838 100%);
    color: var(--text-white);
}

.sidebar-action-btn.btn-warning {
    background: linear-gradient(135deg, var(--accent-orange) 0%, #ff8c00 100%);
    color: var(--text-white);
}

.sidebar-action-btn.btn-secondary {
    background: linear-gradient(135deg, var(--secondary) 0%, #5a6268 100%);
    color: var(--text-white);
    opacity: 0.6;
}

.sidebar-action-btn:hover:not(.disabled) {
    transform: translateX(-5px);
    box-shadow: var(--shadow-md);
}

.sidebar-action-btn:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Icon */
.sidebar-icon {
    font-size: 1.25rem;
    min-width: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* Text */
.sidebar-text {
    flex: 1;
    opacity: 1;
    transition: opacity var(--transition-fast);
    overflow: hidden;
}

/* Badge */
.sidebar-badge {
    margin-left: auto;
    background: rgba(255, 255, 255, 0.9);
    color: #dc3545; /* Red text in expanded state */
    padding: 2px 8px;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 700;
    min-width: 20px;
    text-align: center;
    transition: all var(--transition-base);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

/* Check Icon */
.sidebar-check {
    margin-left: auto;
    font-size: 1rem;
    transition: all var(--transition-base);
}

/* ============================================
   ACTION BUTTONS - STATE: COLLAPSED (80px)
   ============================================ */
@media (min-width: 992px) {
    .sidebar[data-state="collapsed"] .sidebar-action-btn {
        justify-content: center;
        padding: var(--space-sm);
    }

    .sidebar[data-state="collapsed"] .sidebar-action-btn:hover {
        transform: scale(1.1);
    }

    .sidebar[data-state="collapsed"] .sidebar-icon {
        font-size: 1.1rem;
    }

    .sidebar[data-state="collapsed"] .sidebar-text {
        opacity: 0;
        width: 0;
        overflow: hidden;
    }

    .sidebar[data-state="collapsed"] .sidebar-badge {
        position: absolute;
        top: 2px;
        right: 2px;
        font-size: 0.7rem;
        min-width: 18px;
        height: 18px;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        background: #dc3545; /* Bootstrap danger red */
        color: var(--text-white);
        font-weight: 700;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
        border: 2px solid var(--text-white);
        line-height: 1;
    }

    .sidebar[data-state="collapsed"] .sidebar-check {
        position: absolute;
        bottom: 4px;
        right: 4px;
        font-size: 0.75rem;
    }

    /* Sections: Nur Content versteckt, Header bleibt als Button sichtbar */
    .sidebar[data-state="collapsed"] .sidebar-section-content {
        display: none !important;
        max-height: 0 !important;
    }

    /* Section Header im collapsed state: Button-Style */
    .sidebar[data-state="collapsed"] .sidebar-section-header {
        justify-content: center;
        gap: 4px;
        margin-bottom: 0;
        background-color: var(--primary);
        color: var(--text-white);
        padding: var(--space-sm);
        border-radius: var(--radius-md);
    }

    .sidebar[data-state="collapsed"] .sidebar-section-header:hover {
        background-color: var(--primary-dark);
        transform: scale(1.05);
        box-shadow: var(--shadow-md);
    }

    /* Text versteckt */
    .sidebar[data-state="collapsed"] .sidebar-section-title {
        opacity: 0;
        width: 0;
        overflow: hidden;
    }

    /* Toggle-Icon versteckt */
    .sidebar[data-state="collapsed"] .sidebar-section-toggle {
        opacity: 0;
        width: 0;
        overflow: hidden;
    }

    /* Badge sichtbar neben Icon */
    .sidebar[data-state="collapsed"] .sidebar-section-badge {
        position: static;
        background: transparent;
        color: var(--text-white);
        min-width: auto;
        height: auto;
        padding: 0 0 0 4px;
        font-size: 0.75rem;
        font-weight: 600;
    }

    /* Icon weiß */
    .sidebar[data-state="collapsed"] .sidebar-section-icon {
        color: var(--text-white);
    }

    /* Info-Cards versteckt im collapsed state */
    .sidebar[data-state="collapsed"] .sidebar-info-cards {
        display: none;
    }

    /* Vereinsinfo versteckt im collapsed state */
    .sidebar[data-state="collapsed"] .sidebar-info-section {
        display: none;
    }
}

/* ============================================
   COLLAPSIBLE SECTIONS
   ============================================ */
.sidebar-section {
    display: flex;
    flex-direction: column;
    border-top: 1px solid var(--gray-200);
    padding: var(--space-sm);
    padding-top: var(--space-md);
}

.sidebar-section-header {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) 0;
    background: transparent;
    border: none;
    cursor: pointer;
    transition: all var(--transition-base);
    color: var(--primary);
    font-weight: 600;
    font-size: 0.875rem;
    width: 100%;
    text-align: left;
}

.sidebar-section-header:hover {
    background: var(--bg-light);
    border-radius: var(--radius-sm);
}

.sidebar-section-header:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

.sidebar-section-icon {
    font-size: 1rem;
    min-width: 20px;
}

.sidebar-section-title {
    flex: 1;
}

.sidebar-section-badge {
    background: var(--primary);
    color: var(--text-white);
    padding: 2px 6px;
    border-radius: var(--radius-full);
    font-size: 0.65rem;
}

.sidebar-section-toggle {
    transition: transform var(--transition-base);
}

.sidebar-section-header[aria-expanded="false"] .sidebar-section-toggle {
    transform: rotate(-90deg);
}

/* Section Content */
.sidebar-section-content {
    max-height: 1000px;
    overflow: hidden;
    transition: max-height var(--transition-base) var(--sidebar-transition-timing);
}

.sidebar-section-header[aria-expanded="false"] + .sidebar-section-content {
    max-height: 0;
}

/* ============================================
   INFO CARDS
   ============================================ */
.sidebar-info-cards {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.sidebar-info-card {
    background: var(--bg-light);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    transition: all var(--transition-base);
}

.sidebar-info-card:hover {
    background: var(--gray-200);
}

.sidebar-info-icon {
    font-size: 1.5rem;
    display: flex;
    align-items: center;
}

.sidebar-info-details {
    display: flex;
    flex-direction: column;
}

/* ============================================
   GAMES SECTION
   ============================================ */
.sidebar-games-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.sidebar-game-card {
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    transition: all var(--transition-base);
}

.sidebar-game-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

/* Team Badges */
.team-badge-wrapper-sidebar {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.team-badge-sidebar {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.vs-divider-sidebar {
    padding: 0 var(--space-xs);
}

/* ============================================
   EMPTY STATE
   ============================================ */
.sidebar-empty {
    text-align: center;
    padding: var(--space-lg);
    color: var(--gray-400);
}

.sidebar-empty i {
    font-size: 2rem;
    margin-bottom: var(--space-sm);
}

.sidebar-empty p {
    margin: 0;
    font-size: 0.875rem;
}

/* ============================================
   SIDEBAR - MOBILE (Slide-in Overlay)
   ============================================ */
@media (max-width: 991.98px) {
    .sidebar {
        position: fixed;
        right: 0;
        top: 0;
        width: 100%;
        max-width: 400px;
        height: 100vh;
        background: var(--bg-card);
        transform: translateX(100%); /* Versteckt */
        transition: transform var(--transition-base) var(--sidebar-transition-timing);
        z-index: var(--sidebar-mobile-z-index);
        overflow-y: auto;
        padding: var(--space-md);
        box-shadow: -4px 0 16px rgba(0, 0, 0, 0.2);
    }

    .sidebar.show {
        transform: translateX(0); /* Sichtbar */
    }

    /* Overlay/Backdrop */
    .sidebar::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 400px;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        opacity: 0;
        pointer-events: none;
        transition: opacity var(--transition-base);
    }

    .sidebar.show::before {
        opacity: 1;
        pointer-events: auto;
    }

    /* Toggle Button - Fixed oben rechts */
    .sidebar-toggle-btn {
        position: fixed;
        top: 70px; /* Unter Navigation */
        right: 1rem;
        width: 50px;
        height: 50px;
        background: var(--primary);
        color: var(--text-white);
        border: none;
        border-radius: var(--radius-md);
        cursor: pointer;
        z-index: 1030;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 4px;
        box-shadow: var(--shadow-lg);
    }

    .sidebar-toggle-btn:active {
        transform: scale(0.95);
    }

    .sidebar-toggle-text {
        font-size: 0.625rem;
        font-weight: 600;
        text-transform: uppercase;
    }

    /* Kein State-Unterschied auf Mobile */
    .sidebar[data-state] {
        width: 100%;
        max-width: 400px;
    }

    /* Content hat kein Margin auf Mobile */
    .content-with-sidebar,
    .content-with-sidebar.sidebar-collapsed {
        margin-right: 0;
    }

    /* Sections immer voll */
    .sidebar-section-content {
        max-height: none;
    }

    /* Actions: Kein Sticky auf Mobile */
    .sidebar-actions {
        position: static;
    }
}
