/**
 * Two-Level Mega Menu Component
 * Designed to work within the app-sidebar container (260px width)
 * Categories in sidebar, panels slide out from right
 */

/* ====================================
   Container & Layout
   ==================================== */

.mega-menu {
    display: block;
    width: 100%;
    height: 100%;
    padding: 0;
    margin: 0;
}

/* ====================================
   Level 1: Primary Navigation (Vertical in Sidebar)
   ==================================== */

.mega-menu-primary {
    width: 100%;
    padding: 0;
    margin: 0;
}

.mega-menu-categories {
    list-style: none !important;
    padding: 0 !important;
    margin: 0 !important;
    display: block !important;
    flex-direction: column !important; /* Force vertical layout */
}

.mega-menu-category {
    display: block !important;
    margin: 0 !important;
}

.mega-menu-trigger {
    width: 100%;
    padding: 0.625rem 1rem;
    background: transparent;
    border: none;
    border-left: 3px solid transparent;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--fg); /* Using CSS var */
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: 0;
    min-height: 38px;
}

.mega-menu-trigger:hover {
    background: var(--primary-tint);
    border-left-color: var(--primary);
    color: var(--primary);
}

.mega-menu-trigger:focus {
    outline: 2px solid var(--primary);
    outline-offset: -2px;
    z-index: 1; /* local stacking-context */
}

.mega-menu-trigger.active {
    background: var(--primary-tint);
    border-left-color: var(--primary);
    color: var(--primary);
}

.mega-menu-trigger i:first-child {
    font-size: 1.1rem;
    flex-shrink: 0;
    width: 1.25rem;
    text-align: center;
    color: var(--primary);
}

.mega-menu-trigger span {
    flex: 1;
}

.mega-menu-arrow {
    font-size: 0.75rem;
    transition: transform 0.2s ease;
    flex-shrink: 0;
    opacity: 0.6;
}

.mega-menu-trigger.active .mega-menu-arrow {
    transform: rotate(90deg);
}

/* Dark mode support for triggers */
[data-bs-theme="dark"] .mega-menu-trigger,
[data-theme="dark"] .mega-menu-trigger {
    color: var(--primary); /* Dark mode: primary cyan */
}

[data-bs-theme="dark"] .mega-menu-trigger:hover,
[data-bs-theme="dark"] .mega-menu-trigger.active,
[data-theme="dark"] .mega-menu-trigger:hover,
[data-theme="dark"] .mega-menu-trigger.active {
    color: var(--primary); /* Dark mode: Cyan-400 */
}

[data-bs-theme="dark"] .mega-menu-trigger i:first-child,
[data-theme="dark"] .mega-menu-trigger i:first-child {
    color: var(--primary); /* Dark mode: Cyan-400 */
}

/* ====================================
   Level 2: Secondary Panels (Slide-out from right)
   ==================================== */

.mega-menu-secondary {
    position: fixed !important; /* Force fixed positioning to create own stacking context */
    top: 0 !important; /* Start at viewport top */
    left: 100%; /* Start completely off-screen to the right */
    bottom: 0;
    width: 600px;
    background: var(--surface);
    border-left: 1px solid var(--border);
    box-shadow: -4px 0 20px rgb(0, 0, 0, 0.1); /* design-spec: mega-menu lateral drop shadow light-mode */
    z-index: var(--z-overlay);
    transform: translateX(0);
    transition: transform 0.3s ease, left 0s;
    overflow: hidden;
    pointer-events: none;
    display: none; /* Hidden by default */
}

.mega-menu-secondary.panel-visible {
    display: block; /* Show when panel is visible */
    left: 260px !important; /* Position next to sidebar - need !important */
    pointer-events: all;
}

.mega-menu-panel {
    display: none;
    height: 100%;
    padding: 2rem;
    overflow-y: auto;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.mega-menu-panel.active {
    display: block;
    opacity: 1;
}

.mega-menu-panel-content {
    display: grid;
    grid-template-columns: 1fr;
    gap: 2rem;
    max-width: 100%;
}

/* Dark mode panel */
[data-bs-theme="dark"] .mega-menu-secondary,
[data-theme="dark"] .mega-menu-secondary {
    background: var(--surface);
    border-left-color: var(--border);
    box-shadow: -4px 0 30px rgb(0, 0, 0, 0.5); /* design-spec: mega-menu lateral drop shadow dark-mode heavy */
}

/* ====================================
   Sections & Links
   ==================================== */

.mega-menu-section {
    margin-bottom: 2rem;
}

.mega-menu-section:last-child {
    margin-bottom: 0;
}

.mega-menu-section-title {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--fg-3);
    margin-bottom: 0.875rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--border);
}

.mega-menu-links {
    list-style: none;
    padding: 0;
    margin: 0;
}

.mega-menu-links li {
    margin-bottom: 0.375rem;
}

.mega-menu-links a {
    display: flex;
    align-items: flex-start;
    gap: 0.875rem;
    padding: 0.75rem 0.875rem;
    border-radius: var(--r-sm);
    text-decoration: none;
    color: var(--fg);
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
}

.mega-menu-links a:hover {
    background: var(--primary-tint);
    border-left-color: var(--primary);
    transform: translateX(2px);
}

.mega-menu-links a:focus {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.mega-menu-links a.active {
    background: var(--primary-tint);
    border-left-color: var(--primary);
    color: var(--primary);
    font-weight: 600;
}

.mega-menu-links a i {
    font-size: 1.25rem;
    margin-top: 0.125rem;
    flex-shrink: 0;
    width: 1.5rem;
    text-align: center;
    color: var(--primary);
}

.mega-menu-link-content {
    flex: 1;
    min-width: 0;
}

.mega-menu-link-title {
    display: block;
    font-weight: 600;
    margin-bottom: 0.25rem;
    font-size: 0.95rem;
}

.mega-menu-link-desc {
    display: block;
    font-size: 0.8125rem;
    color: var(--fg-3);
    line-height: 1.5;
}

.mega-menu-links a:hover .mega-menu-link-desc {
    color: var(--fg);
}

.mega-menu-links a.active .mega-menu-link-desc {
    color: var(--fg);
}

/* Dark mode is always on for panels - no override needed */

/* ====================================
   Dark Mode Support
   ==================================== */

[data-bs-theme="dark"] .mega-menu-primary {
    background: var(--fg);
}

[data-bs-theme="dark"] .mega-menu-trigger:hover {
    background: rgb(var(--bs-primary-rgb), 0.15);
}

[data-bs-theme="dark"] .mega-menu-trigger.active {
    background: rgb(var(--bs-primary-rgb), 0.2);
}

[data-bs-theme="dark"] .mega-menu-links a:hover {
    background: rgb(var(--bs-primary-rgb), 0.15);
}

[data-bs-theme="dark"] .mega-menu-links a.active {
    background: rgb(var(--bs-primary-rgb), 0.2);
}

/* ====================================
   Responsive Design
   ==================================== */

/* Tablet - adjust panel width */
@media (max-width: 991px) {
    .mega-menu-secondary {
        width: 100%;
        max-width: 500px;
    }
}

/* Mobile - Panel overlays sidebar as fullscreen */
@media (max-width: 767px) {
    .mega-menu-secondary {
        left: 0 !important;
        width: 100vw !important;
        border-left: none;
        box-shadow: none;
    }

    .mega-menu-secondary.panel-visible {
        left: 0 !important;  /* Override the 260px positioning */
    }

    .mega-menu-panel {
        padding: 1rem;
        padding-top: 3.5rem;  /* Space for back button */
    }

    /* Mobile back button for panel navigation */
    .mega-menu-panel::before {
        content: "← Zurück";
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        padding: 1rem;
        background: var(--surface-2);
        border-bottom: 1px solid var(--border);
        font-weight: 600;
        color: var(--primary);
        z-index: 1; /* local stacking-context */
    }

    .mega-menu-section-title {
        font-size: 0.85rem;
    }

    .mega-menu-links a {
        padding: 0.875rem;  /* Increased for touch targets */
        min-height: 44px;   /* Apple/Google recommended touch target */
    }
}

/* Dark mode mobile panel */
@media (max-width: 767px) {
    [data-theme="dark"] .mega-menu-panel::before,
    [data-bs-theme="dark"] .mega-menu-panel::before {
        background: var(--bg);
        border-bottom-color: var(--border);
        color: var(--primary);
    }
}

/* ====================================
   Accessibility Enhancements
   ==================================== */

/* Focus visible for keyboard navigation */
.mega-menu-trigger:focus-visible,
.mega-menu-links a:focus-visible {
    outline: 3px solid var(--primary);
    outline-offset: 2px;
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .mega-menu-trigger,
    .mega-menu-arrow,
    .mega-menu-links a {
        transition: none;
    }

    .mega-menu-panel {
        animation: none;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .mega-menu {
        border: 2px solid var(--border);
    }

    .mega-menu-trigger:hover,
    .mega-menu-trigger.active,
    .mega-menu-links a:hover,
    .mega-menu-links a.active {
        border: 2px solid var(--primary);
    }
}

/* ====================================
   Print Styles
   ==================================== */

@media print {
    .mega-menu {
        display: none;
    }
}
