/* ===========================================
   HIERARCHICAL CATEGORY SIDEBAR
   Modern Split-View Navigation System
   Parent Categories (Right) → Children/Grandchildren (Left)
   Mobile-First Responsive Design
   =========================================== */

/* ============================================
   VARIABLES & RESET - Aligned with Site Theme
   ============================================ */
:root {
    /* Base Colors - Matching site palette */
    --sidebar-bg: #ffffff;
    --sidebar-header-bg: linear-gradient(135deg, #2c3e50 0%, #3d566e 100%);
    --sidebar-header-text: #ffffff;
    --sidebar-border: #ecf0f1;
    
    /* Parent Card Colors */
    --parent-card-bg: #ffffff;
    --parent-card-hover: #f9f9f9;
    --parent-card-active: #2c3e50;
    --parent-card-active-gradient: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
    --parent-card-border: #e0e4e8;
    --parent-card-shadow: 0 2px 8px rgba(44, 62, 80, 0.08);
    --parent-card-shadow-hover: 0 4px 16px rgba(44, 62, 80, 0.15);
    
    /* Child & Grandchild Colors */
    --child-bg: #ffffff;
    --child-hover: #fafbfc;
    --child-active: #eef3f7;
    --child-accent: #e74c3c;
    --grandchild-bg: #ffffff;
    --grandchild-hover: #f8f9fa;
    --grandchild-border: #eaecee;
    
    /* Typography */
    --text-primary: #2c3e50;
    --text-secondary: #7f8c8d;
    --text-on-primary: #ffffff;
    --text-accent: #e74c3c;
    
    /* Overlay & Effects */
    --overlay-bg: rgba(44, 62, 80, 0.6);
    --transition-speed: 0.35s;
    --transition-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
    --transition-smooth: cubic-bezier(0.4, 0, 0.2, 1);
    
    /* Sizing */
    --sidebar-width-desktop: 800px;
    --sidebar-right-width: 240px;
    --border-radius-sm: 8px;
    --border-radius-md: 12px;
    --border-radius-lg: 16px;
}

/* ============================================
   OVERLAY - Enhanced blur effect
   ============================================ */
.category-sidebar__overlay {
    position: fixed;
    inset: 0;
    background: var(--overlay-bg);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 10001;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-speed) var(--transition-smooth),
                visibility var(--transition-speed) var(--transition-smooth);
}

.category-sidebar__overlay.is-visible {
    opacity: 1;
    visibility: visible;
}

/* ============================================
   SIDEBAR CONTAINER - Enhanced with shadows
   ============================================ */
.category-sidebar__container {
    position: fixed;
    top: 0;
    right: 0;
    height: 100vh;
    height: 100dvh;
    width: 100%;
    max-width: 100%;
    background: var(--sidebar-bg);
    z-index: 10002;
    transform: translateX(100%);
    transition: transform var(--transition-speed) var(--transition-smooth);
    display: flex;
    flex-direction: column;
    box-shadow: -8px 0 32px rgba(44, 62, 80, 0.2);
    direction: rtl;
    overflow: hidden;
}

.category-sidebar__container.is-open {
    transform: translateX(0);
}

/* Desktop: Fixed width - no rounded corners */
@media (min-width: 768px) {
    .category-sidebar__container {
        width: 380px;
        min-width: 360px;
        max-width: 420px;
        border-radius: 0;
    }
}

/* ============================================
   HEADER - Modern gradient design
   ============================================ */
.category-sidebar__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    background: var(--sidebar-header-bg);
    border-bottom: none;
    flex-shrink: 0;
    min-height: 68px;
    position: relative;
}

.category-sidebar__header::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, #e74c3c 0%, #c0392b 50%, #e74c3c 100%);
}

.category-sidebar__title {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--sidebar-header-text);
    margin: 0;
    letter-spacing: -0.02em;
}

.category-sidebar__close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.2);
    cursor: pointer;
    color: var(--sidebar-header-text);
    border-radius: 50%;
    transition: all 0.25s var(--transition-smooth);
    padding: 0;
    backdrop-filter: blur(4px);
}

.category-sidebar__close:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: rotate(90deg);
}

.category-sidebar__close:active {
    transform: rotate(90deg) scale(0.92);
}

/* ============================================
   CONTENT AREA (SPLIT LAYOUT)
   ============================================ */
.category-sidebar__content {
    display: flex;
    flex: 1;
    overflow: hidden;
    flex-direction: column;
    background: #f5f7fa;
}

/* Desktop: Side by side with right section on right */
@media (min-width: 768px) {
    .category-sidebar__content {
        flex-direction: row-reverse;
    }
}

/* ============================================
   LEFT SECTION (Children & Grandchildren)
   ============================================ */
.category-sidebar__left {
    flex: 1;
    background: var(--sidebar-bg);
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    position: relative;
    display: flex;
    flex-direction: column;
}

/* Desktop: Add right border */
@media (min-width: 768px) {
    .category-sidebar__left {
        border-right: 1px solid var(--sidebar-border);
    }
}

/* Placeholder when no parent selected - Full height centered */
.category-sidebar__placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem 1.5rem;
    text-align: center;
    color: var(--text-secondary);
    flex: 1;
    min-height: 100%;
    background: #f5f7fa;
}

.category-sidebar__placeholder svg {
    margin-bottom: 1.25rem;
    opacity: 0.35;
    color: var(--text-primary);
}

.category-sidebar__placeholder p {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 500;
}

/* ============================================
   RIGHT SECTION (Parent Categories)
   ============================================ */
.category-sidebar__right {
    background: linear-gradient(180deg, #f5f7fa 0%, #eef1f5 100%);
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 0.75rem;
    order: -1; /* Show first on mobile */
}

/* Desktop: Fixed width */
@media (min-width: 768px) {
    .category-sidebar__right {
        width: 110px;
        flex-shrink: 0;
        order: 1; /* Show on right */
        padding: 0.75rem 0.5rem;
    }
}

/* Mobile: Limit height */
@media (max-width: 767px) {
    .category-sidebar__right {
        max-height: 35vh;
        border-bottom: 2px solid var(--sidebar-border);
    }
}

/* Loading State */
.category-sidebar__loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    min-height: 200px;
}

.category-sidebar__spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--sidebar-border);
    border-top-color: var(--text-accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.category-sidebar__loading p {
    margin-top: 1rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* ============================================
   PARENT CATEGORIES GRID - Enhanced layout
   ============================================ */
.category-sidebar__parents-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 0.75rem;
    padding: 0.5rem;
}

@media (min-width: 768px) {
    .category-sidebar__parents-grid {
        grid-template-columns: 1fr;
        gap: 0.625rem;
    }
}

/* Parent Card - Modern elevated style */
.category-parent-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 0.5rem;
    background: var(--parent-card-bg);
    border: 1px solid var(--parent-card-border);
    border-radius: var(--border-radius-md);
    cursor: pointer;
    transition: all 0.25s var(--transition-smooth);
    text-decoration: none;
    aspect-ratio: 1 / 1;
    gap: 0.5rem;
    box-shadow: var(--parent-card-shadow);
    position: relative;
    overflow: hidden;
}

.category-parent-card::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, transparent 0%, rgba(44, 62, 80, 0.03) 100%);
    opacity: 0;
    transition: opacity 0.25s ease;
}

.category-parent-card:hover {
    background: var(--parent-card-hover);
    border-color: var(--parent-card-active);
    box-shadow: var(--parent-card-shadow-hover);
    transform: translateY(-2px);
}

.category-parent-card:hover::before {
    opacity: 1;
}

.category-parent-card.is-active {
    background: var(--parent-card-active-gradient);
    border-color: var(--parent-card-active);
    color: var(--text-on-primary);
    box-shadow: 0 4px 12px rgba(44, 62, 80, 0.3);
    transform: translateY(-1px);
}

.category-parent-card__icon {
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.25s var(--transition-bounce);
}

.category-parent-card:hover .category-parent-card__icon {
    transform: scale(1.1);
}

.category-parent-card__icon svg {
    width: 100%;
    height: 100%;
    stroke: currentColor;
    stroke-width: 1.5;
}

.category-parent-card.is-active .category-parent-card__icon svg {
    stroke: var(--text-on-primary);
}

.category-parent-card__name {
    font-size: 0.7rem;
    font-weight: 600;
    text-align: center;
    line-height: 1.3;
    color: inherit;
    word-break: break-word;
    max-width: 100%;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

@media (max-width: 767px) {
    .category-parent-card {
        padding: 0.58rem 0.42rem;
        gap: 0.34rem;
    }

    .category-parent-card__icon {
        width: 22px;
        height: 22px;
    }

    .category-parent-card__name {
        font-size: 0.66rem;
        line-height: 1.18;
    }
}

@media (min-width: 768px) {
    .category-parent-card {
        aspect-ratio: auto;
        padding: 0.875rem 0.5rem;
    }
    
    .category-parent-card__name {
        font-size: 0.75rem;
    }
    
    .category-parent-card__icon {
        width: 24px;
        height: 24px;
    }
}

/* ============================================
   CHILDREN LIST (ACCORDION) - Enhanced
   ============================================ */
.category-sidebar__children-list {
    display: flex;
    flex-direction: column;
    background: var(--sidebar-bg);
}

/* Child Item (Accordion Header) */
.category-child-item {
    border-bottom: 1px solid var(--sidebar-border);
    background: var(--child-bg);
}

.category-child-item:last-child {
    border-bottom: none;
}

.category-child-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.125rem;
    background: var(--child-bg);
    cursor: pointer;
    transition: all 0.2s var(--transition-smooth);
    width: 100%;
    border: none;
    text-align: right;
    gap: 0.875rem;
    position: relative;
}

.category-child-header::before {
    content: '';
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 0;
    background: var(--text-accent);
    transition: height 0.25s var(--transition-smooth);
    border-radius: 0 2px 2px 0;
}

.category-child-header:hover {
    background: var(--child-hover);
}

.category-child-header.is-active {
    background: var(--child-active);
}

.category-child-header.is-active::before {
    height: 60%;
}

.category-child-header__content {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    flex: 1;
    min-width: 0;
}

.category-child-header__icon {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: color 0.2s ease;
}

.category-child-header__icon svg {
    width: 100%;
    height: 100%;
    stroke: currentColor;
    stroke-width: 1.5;
}

.category-child-header.is-active .category-child-header__icon {
    color: var(--text-accent);
}

.category-child-header__text {
    flex: 1;
    min-width: 0;
}

.category-child-header__name {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 0.2rem 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.category-child-header__count {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin: 0;
    font-weight: 400;
}

.category-child-header__arrow {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
    color: var(--text-secondary);
    transition: transform 0.3s var(--transition-smooth), color 0.2s ease;
    background: rgba(0, 0, 0, 0.04);
    border-radius: 50%;
    padding: 3px;
}

.category-child-header__arrow svg {
    width: 100%;
    height: 100%;
    stroke: currentColor;
    stroke-width: 2;
}

.category-child-header.is-active .category-child-header__arrow {
    transform: rotate(180deg);
    color: var(--text-accent);
    background: rgba(231, 76, 60, 0.1);
}

/* ============================================
   GRANDCHILDREN GRID (ACCORDION CONTENT) - Enhanced
   ============================================ */
.category-grandchildren-content {
    position: relative;
    max-height: 0;
    overflow: hidden;
    pointer-events: none;
    transition: max-height 0.35s var(--transition-smooth);
    background: linear-gradient(180deg, #f5f7fa 0%, #eef1f5 100%);
    z-index: 1;
}

.category-grandchildren-content.is-open {
    max-height: 1000px; /* Large enough for content */
    pointer-events: auto;
}

.category-grandchildren-grid {
    position: relative;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(75px, 1fr));
    gap: 0.625rem;
    padding: 0.875rem;
    z-index: 2;
}

@media (min-width: 480px) {
    .category-grandchildren-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (min-width: 768px) {
    .category-grandchildren-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Grandchild Card - Enhanced */
.category-grandchild-card {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0.625rem 0.5rem;
    background: var(--grandchild-bg);
    border: 1px solid var(--grandchild-border);
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    transition: all 0.2s var(--transition-smooth);
    text-decoration: none;
    gap: 0.4rem;
    aspect-ratio: 1 / 1;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
    pointer-events: auto;
    z-index: 3;
}

.category-grandchild-card:hover {
    background: var(--grandchild-hover);
    border-color: var(--parent-card-active);
    box-shadow: 0 3px 8px rgba(44, 62, 80, 0.1);
    transform: translateY(-1px);
}

/* Special styling for "View All" item */
.category-grandchild-card.is-view-all {
    border: 2px dashed #bdc3c7;
    background: linear-gradient(135deg, #fdf2f8 0%, #eef2ff 100%);
}

.category-grandchild-card.is-view-all:hover {
    border-color: var(--text-accent);
    background: linear-gradient(135deg, #fce7f3 0%, #ddd6fe 100%);
}

.category-grandchild-card__icon {
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    flex-shrink: 0;
    transition: color 0.2s ease;
}

.category-grandchild-card:hover .category-grandchild-card__icon {
    color: var(--text-primary);
}

.category-grandchild-card__icon svg {
    width: 100%;
    height: 100%;
    stroke: currentColor;
    stroke-width: 1.5;
}

.category-grandchild-card.is-view-all .category-grandchild-card__icon {
    color: var(--text-accent);
}

.category-grandchild-card__name {
    font-size: 0.68rem;
    font-weight: 500;
    text-align: center;
    line-height: 1.35;
    color: var(--text-primary);
    word-break: break-word;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.category-grandchild-card__count {
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-top: 0.125rem;
}

/* ============================================
   UTILITIES - Enhanced scrollbars
   ============================================ */
.category-sidebar__children-list::-webkit-scrollbar,
.category-sidebar__left::-webkit-scrollbar,
.category-sidebar__right::-webkit-scrollbar {
    width: 5px;
    height: 5px;
}

.category-sidebar__children-list::-webkit-scrollbar-track,
.category-sidebar__left::-webkit-scrollbar-track,
.category-sidebar__right::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.02);
    border-radius: 3px;
}

.category-sidebar__children-list::-webkit-scrollbar-thumb,
.category-sidebar__left::-webkit-scrollbar-thumb,
.category-sidebar__right::-webkit-scrollbar-thumb {
    background: rgba(44, 62, 80, 0.2);
    border-radius: 3px;
    transition: background 0.2s ease;
}

.category-sidebar__children-list::-webkit-scrollbar-thumb:hover,
.category-sidebar__left::-webkit-scrollbar-thumb:hover,
.category-sidebar__right::-webkit-scrollbar-thumb:hover {
    background: rgba(44, 62, 80, 0.35);
}

/* Prevent body scroll when sidebar is open without layout shift */
body.sidebar-open {
    overflow: hidden;
    padding-right: 0;
    padding-inline-end: 0;
}

/* Prevent header shift when sidebar opens */
body.sidebar-open .main-header {
    padding-right: 0;
    padding-inline-end: 0;
}

/* ============================================
   ANIMATIONS - Smoother and more polished
   ============================================ */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(15px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.category-parent-card {
    animation: scaleIn 0.35s var(--transition-smooth) forwards;
    opacity: 0;
}

.category-child-item {
    animation: slideInRight 0.3s var(--transition-smooth) forwards;
    opacity: 0;
}

/* Stagger animation for parent cards */
.category-parent-card:nth-child(1) { animation-delay: 0.03s; }
.category-parent-card:nth-child(2) { animation-delay: 0.06s; }
.category-parent-card:nth-child(3) { animation-delay: 0.09s; }
.category-parent-card:nth-child(4) { animation-delay: 0.12s; }
.category-parent-card:nth-child(5) { animation-delay: 0.15s; }
.category-parent-card:nth-child(6) { animation-delay: 0.18s; }
.category-parent-card:nth-child(7) { animation-delay: 0.21s; }
.category-parent-card:nth-child(8) { animation-delay: 0.24s; }
.category-parent-card:nth-child(9) { animation-delay: 0.27s; }
.category-parent-card:nth-child(10) { animation-delay: 0.30s; }

/* Stagger animation for child items */
.category-child-item:nth-child(1) { animation-delay: 0.02s; }
.category-child-item:nth-child(2) { animation-delay: 0.04s; }
.category-child-item:nth-child(3) { animation-delay: 0.06s; }
.category-child-item:nth-child(4) { animation-delay: 0.08s; }
.category-child-item:nth-child(5) { animation-delay: 0.10s; }
.category-child-item:nth-child(6) { animation-delay: 0.12s; }

/* ============================================
   RESPONSIVE ADJUSTMENTS - Polished
   ============================================ */
@media (max-width: 374px) {
    .category-sidebar__parents-grid {
        grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
        gap: 0.5rem;
    }
    
    .category-parent-card {
        min-height: 78px;
        padding: 0.65rem 0.35rem;
    }
    
    .category-parent-card__icon {
        width: 24px;
        height: 24px;
    }
    
    .category-parent-card__name {
        font-size: 0.65rem;
    }
    
    .category-sidebar__header {
        min-height: 60px;
        padding: 0.875rem 1rem;
    }
    
    .category-sidebar__title {
        font-size: 1.05rem;
    }
}

@media (min-width: 1024px) {
    .category-sidebar__container {
        max-width: 420px;
        border-radius: 0;
    }
    
    .category-sidebar__right {
        width: 120px;
    }
    
    .category-sidebar__header {
        min-height: 72px;
    }
}

/* Hover effects only on devices that support it */
@media (hover: hover) {
    .category-parent-card:active {
        transform: translateY(0) scale(0.98);
    }
    
    .category-grandchild-card:active {
        transform: translateY(0) scale(0.97);
    }
}

/* Touch device optimizations */
@media (hover: none) {
    .category-parent-card:active {
        background: var(--parent-card-hover);
        box-shadow: var(--parent-card-shadow);
    }
    
    .category-child-header:active {
        background: var(--child-active);
    }
}
