/* ============================================
   SIDEBAR CONTAINER & LAYOUT
   (Aligned with header mega menu styles)
   ============================================ */

:root {
    --sidebar-bg: rgba(255, 255, 255, 0.85);
    --sidebar-border-radius: 12px;
    --sidebar-shadow: 0 10px 40px rgba(0, 0, 0, 0.12);
    --sidebar-active-color: #003366;
    /* brand-blue from header */
    --sidebar-hover-bg: #f5f5f5;
    --sidebar-text-primary: #333;
    --sidebar-text-secondary: #555;
}

.category-navigation-sidebar {
    position: sticky;
    top: 100px;
    /* Account for fixed header */
    height: calc(100vh - 120px);
    background: var(--sidebar-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-radius: var(--sidebar-border-radius);
    padding: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: var(--sidebar-shadow);
}

.sidebar-scrollable {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px 0;
}

/* Custom scrollbar for main sidebar */
.sidebar-scrollable::-webkit-scrollbar {
    width: 6px;
}

.sidebar-scrollable::-webkit-scrollbar-thumb {
    background-color: rgba(0, 0, 0, 0.15);
    border-radius: 3px;
}

.sidebar-scrollable::-webkit-scrollbar-track {
    background-color: transparent;
}

/* ============================================
   PARENT CATEGORY NAVIGATION
   ============================================ */

.parent-category-item {
    margin-bottom: 2px;
}

.parent-category-link {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--sidebar-text-primary);
    text-decoration: none;
    border-left: 3px solid transparent;
    transition: all 0.2s ease;
    line-height: 1.4;
    min-height: 44px;
}

/* Parent category hover - matches mega-parent-link */
.parent-category-item:hover .parent-category-link {
    background: var(--sidebar-hover-bg);
    color: var(--sidebar-active-color);
    border-left-color: var(--sidebar-active-color);
}

/* Parent category active state */
.parent-category-item.active .parent-category-link {
    background: #fff;
    color: var(--sidebar-active-color);
    border-left-color: var(--sidebar-active-color);
    font-weight: 700;
}

/* ============================================
   CHILD CATEGORY EXPANSION SYSTEM
   ============================================ */

/* Child categories container */
.child-categories {
    margin-left: 0;
    margin-top: 0;
    padding-left: 0;
    border-left: none;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
    background: #fff;
}

/* Expanded child categories (active parent) */
.child-categories.expanded {
    max-height: 70vh;
    overflow-y: auto;
    overflow-x: hidden;
}

/* Scrollbar for expanded child categories */
.child-categories.expanded::-webkit-scrollbar {
    width: 4px;
}

.child-categories.expanded::-webkit-scrollbar-thumb {
    background-color: #ddd;
    border-radius: 2px;
}

.child-categories.expanded::-webkit-scrollbar-track {
    background-color: transparent;
}

/* Hover expansion for non-active parents */
.parent-category-item:hover .child-categories:not(.expanded) {
    max-height: 80vh;
    opacity: 0.8;
    overflow-y: auto;
    overflow-x: hidden;
}

/* Scrollbar for hover child categories */
.parent-category-item:hover .child-categories:not(.expanded)::-webkit-scrollbar {
    width: 4px;
}

.parent-category-item:hover .child-categories:not(.expanded)::-webkit-scrollbar-thumb {
    background-color: #ccc;
    border-radius: 2px;
}

.parent-category-item:hover .child-categories:not(.expanded)::-webkit-scrollbar-track {
    background-color: transparent;
}

/* ============================================
   CHILD CATEGORY LINKS
   ============================================ */

.child-category-item {
    margin-bottom: 0;
}

.child-category-link {
    display: block;
    padding: 10px 30px;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--sidebar-text-secondary);
    text-decoration: none;
    border-bottom: 1px solid #f0f0f0;
    transition: all 0.2s ease;
    line-height: 1.3;
}

/* Child category hover - matches mega-child-link */
.child-category-link:hover {
    color: var(--sidebar-active-color);
    padding-left: 38px;
    border-bottom-color: var(--sidebar-active-color);
}

/* Child category active state */
.child-category-item.active .child-category-link {
    color: var(--sidebar-active-color);
    font-weight: 600;
    border-bottom-color: var(--sidebar-active-color);
    background: rgba(0, 51, 102, 0.05);
}

/* ============================================
   MOBILE RESPONSIVE SIDEBAR
   ============================================ */

@media (max-width: 767px) {
    .category-navigation-sidebar {
        position: relative;
        height: auto;
        top: 0;
        margin-bottom: 20px;
    }

    .sidebar-scrollable {
        padding: 15px;
    }

    /* Categories Toggle - Secondary Outline Style */
    .mobile-menu-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        width: 100%;
        padding: 12px 16px;
        background: transparent;
        color: #007aff;
        border: 1.5px solid #007aff;
        font-size: 15px;
        font-weight: 600;
        letter-spacing: -0.1px;
        cursor: pointer;
        text-align: center;
        border-radius: 12px;
        transition:
            transform 0.15s ease,
            background 0.15s ease,
            color 0.15s ease;
        -webkit-tap-highlight-color: transparent;
    }

    .mobile-menu-toggle:active {
        transform: scale(0.97);
        background: #ffc500;
    }

    .sidebar-content {
        display: none;
        padding-top: 0;
    }
}

/* Body scroll lock when modal is open */
body.modal-open {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
}

/* ============================================
   MOBILE MODAL OVERLAY - Apple Frosted Glass
   ============================================ */

.mobile-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 99999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.35s ease, visibility 0.35s ease;
}

.mobile-modal-overlay.is-open {
    opacity: 1;
    visibility: visible;
}

/* ============================================
   MOBILE MODAL CONTAINER - Apple Sheet Style
   ============================================ */

.mobile-modal {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 85vh;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 24px 24px 0 0;
    display: flex;
    flex-direction: column;
    transform: translateY(100%);
    transition: transform 0.4s cubic-bezier(0.32, 0.72, 0, 1);
    box-shadow:
        0 -10px 40px rgba(0, 0, 0, 0.12),
        0 -2px 10px rgba(0, 0, 0, 0.08);
}

.mobile-modal-overlay.is-open .mobile-modal {
    transform: translateY(0);
}

/* Disable transition during drag */
.mobile-modal.is-dragging {
    transition: none;
}

/* ============================================
   MOBILE MODAL DRAG HANDLE - Apple Style
   ============================================ */

.mobile-modal-handle {
    padding: 12px 0 4px;
    text-align: center;
    cursor: grab;
    touch-action: none;
}

.mobile-modal-handle:active {
    cursor: grabbing;
}

.mobile-modal-handle .drag-handle-bar {
    display: inline-block;
    width: 36px;
    height: 5px;
    background: rgba(0, 0, 0, 0.15);
    border-radius: 3px;
    transition: background 0.2s, width 0.2s;
}

.mobile-modal-handle:active .drag-handle-bar {
    background: rgba(0, 0, 0, 0.3);
    width: 40px;
}

/* ============================================
   MOBILE MODAL HEADER - Apple Large Title
   ============================================ */

.mobile-modal-header {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 8px 20px 16px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    flex-shrink: 0;
}

.mobile-modal-title {
    font-size: 20px;
    font-weight: 700;
    color: #1c1c1e;
    letter-spacing: -0.4px;
    text-align: center;
}

/* Hide close button - Apple prefers gesture-based closing */
.mobile-modal-close {
    display: none;
}

/* ============================================
   MOBILE MODAL CONTENT - Smooth Scroll
   ============================================ */

.mobile-modal-content {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    /* Extra bottom padding for mobile browser URL bar */
    padding: 16px 20px calc(80px + env(safe-area-inset-bottom, 0px));
    overscroll-behavior-y: contain;
}

/* Hide scrollbar for cleaner look */
.mobile-modal-content::-webkit-scrollbar {
    width: 0;
    display: none;
}

/* ============================================
   MODAL CATEGORY ITEMS - Apple List Style
   ============================================ */

.mobile-modal-content .parent-category-item {
    margin-bottom: 6px;
}

.mobile-modal-content .parent-category-link {
    display: flex;
    align-items: center;
    padding: 16px 18px;
    min-height: 44px;
    /* iOS HIG minimum touch target */
    font-size: 17px;
    font-weight: 600;
    color: #1c1c1e;
    background: rgba(118, 118, 128, 0.08);
    border-radius: 12px;
    text-decoration: none;
    transition:
        background 0.15s ease,
        transform 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

.mobile-modal-content .parent-category-link:active {
    background: rgba(118, 118, 128, 0.16);
    transform: scale(0.98);
}

.mobile-modal-content .parent-category-item.active .parent-category-link {
    background: #007aff;
    color: #ffffff;
}

.mobile-modal-content .parent-category-item.active .parent-category-link:active {
    background: #0062cc;
}

/* Child Categories - Apple Grouped Style */
.mobile-modal-content .child-categories {
    margin-left: 0;
    margin-top: 4px;
    padding: 0;
    border-left: none;
}

.mobile-modal-content .child-categories.expanded {
    max-height: none;
    overflow: visible;
}

.mobile-modal-content .child-category-item {
    margin-bottom: 2px;
}

.mobile-modal-content .child-category-link {
    display: flex;
    align-items: center;
    padding: 14px 18px 14px 32px;
    min-height: 44px;
    /* iOS HIG minimum touch target */
    font-size: 16px;
    font-weight: 500;
    color: #3a3a3c;
    background: transparent;
    border-radius: 10px;
    text-decoration: none;
    transition:
        background 0.15s ease,
        transform 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

.mobile-modal-content .child-category-link:active {
    background: rgba(118, 118, 128, 0.12);
    transform: scale(0.98);
}

.mobile-modal-content .child-category-item.active .child-category-link {
    background: rgba(0, 122, 255, 0.12);
    color: #007aff;
    font-weight: 600;
}


@media (min-width: 768px) {
    .mobile-menu-toggle {
        display: none;
    }

    .sidebar-scrollable {
        display: block;
    }
}

/* ============================================
   SIDEBAR ACCESSIBILITY & INTERACTION
   ============================================ */

/* Focus states for keyboard navigation */
.parent-category-link:focus,
.child-category-link:focus {
    outline: 2px solid #007bff;
    outline-offset: 2px;
}


/* High contrast mode support */
@media (prefers-contrast: high) {
    .category-navigation-sidebar {
        border: 2px solid #000;
    }

    .parent-category-link,
    .child-category-link {
        border: 1px solid transparent;
    }

    .parent-category-link:hover,
    .child-category-link:hover {
        border-color: #000;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {

    .parent-category-link,
    .child-category-link,
    .child-categories {
        transition: none;
        transform: none;
    }
}

/* Sidebar Divider */
.sidebar-divider {
    height: 1px;
    background-color: #e0e0e0;
    margin: 10px 15px 15px;
    width: calc(100% - 30px);
}