/* =============================================================================
   TORG AI SLIDING SIDEBAR MENU - PERPLEXITY.AI INSPIRED
   Independent CSS for Sidebar Menu System
   ============================================================================= */

/* ===== MATERIAL DESIGN 3 NAVIGATION RAIL - FIXED Z-INDEX ===== */
.sidebar-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 72px; /* Standard navigation rail width */
    height: 100vh;
    z-index: 1500; /* Below navbar (9999) but above content */
    display: flex;
    flex-direction: column;
    /* Single unified background - no layering */
    background: linear-gradient(180deg, 
        rgba(26, 26, 26, 0.98) 0%, 
        rgba(30, 30, 30, 0.98) 100%
    );
    backdrop-filter: blur(20px);
    border-right: 1px solid rgba(243, 159, 27, 0.15);
    pointer-events: auto;
    /* Enhanced shadow for proper depth */
    box-shadow: 2px 0 16px rgba(0, 0, 0, 0.2);
    /* FIXED: Transform3D for hardware acceleration */
    transform: translateZ(0);
    will-change: transform;
}

/* Remove complex pseudo-element backgrounds */
.sidebar-container::before {
    display: none;
}

/* ===== NAVIGATION RAIL CONTENT ===== */
.sidebar-collapsed {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 0 1rem 0; /* Start below navbar but no logo overlap */
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    margin-top: 20px; /* Proper spacing from top */
}

/* Remove complex pseudo-element */
.sidebar-collapsed::after {
    display: none;
}

/* SIDEBAR LOGO - NOW MAIN LOGO (navbar removed) */
.sidebar-logo {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 16px 8px;
    margin-bottom: 20px;
}

.sidebar-logo .torg-logo-svg {
    display: flex;
    justify-content: center;
    align-items: center;
}

.sidebar-logo .sidebar-logo-img {
    height: 32px !important;
    width: auto !important;
    max-width: 56px !important;
    filter: brightness(1.1) !important;
    transition: all 0.3s ease !important;
}

.sidebar-logo:hover .sidebar-logo-img {
    filter: brightness(1.3) drop-shadow(0 0 8px rgba(243, 159, 27, 0.4)) !important;
    transform: scale(1.05) !important;
}

/* New Thread Button */
.sidebar-new-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(243, 159, 27, 0.1);
    border: 1px solid rgba(243, 159, 27, 0.3);
    color: #F39F1B;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-bottom: 2rem;
}

.sidebar-new-btn:hover {
    background: #F39F1B;
    color: #FFFFFF;
    transform: scale(1.1);
    box-shadow: 0 0 20px rgba(243, 159, 27, 0.5);
}

/* Navigation Items */
.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    width: 100%;
}

.sidebar-nav-item {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.75rem;
    color: #8A8A8A;
    text-decoration: none;
    transition: all 0.3s ease;
    cursor: pointer;
}

.nav-item-bg {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    height: 90%;
    background: transparent;
    border-radius: 8px;
    transition: all 0.3s ease;
    z-index: -1;
}

.sidebar-nav-item:hover .nav-item-bg {
    background: transparent; /* No ugly background on hover either */
}

.sidebar-nav-item.active {
    color: #F39F1B;
}

.sidebar-nav-item.active .nav-item-bg {
    background: transparent; /* REMOVE the ugly orange square */
    border: none; /* Remove border too */
    border-radius: 8px;
}

.nav-icon {
    width: 24px;
    height: 24px;
    margin-bottom: 0.25rem;
    transition: all 0.3s ease;
}

.sidebar-nav-item:hover .nav-icon {
    transform: scale(1.1);
    fill: #F39F1B;
}

.nav-label {
    font-size: 0.625rem;
    font-weight: 500;
    text-align: center;
    line-height: 1.1;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Live Counter at Bottom */
.sidebar-counter {
    margin-top: auto;
    padding: 1rem;
    text-align: center;
    border-top: 1px solid rgba(243, 159, 27, 0.1);
}

.counter-pulse {
    width: 8px;
    height: 8px;
    background: #00FF00;
    border-radius: 50%;
    margin: 0 auto 0.5rem;
    animation: pulse-live 2s ease-in-out infinite;
}

@keyframes pulse-live {
    0%, 100% {
        opacity: 1;
        box-shadow: 0 0 0 0 rgba(0, 255, 0, 0.7);
    }
    50% {
        opacity: 0.7;
        box-shadow: 0 0 0 10px rgba(0, 255, 0, 0);
    }
}

.counter-number {
    font-size: 1.25rem;
    font-weight: 700;
    color: #F39F1B;
    display: block;
}

.counter-label {
    font-size: 0.625rem;
    color: #8A8A8A;
}

/* ===== EXPANDED MENU - FIXED TRANSFORM ANIMATION ===== */
.sidebar-menu {
    position: fixed;
    top: 0;
    left: 0; /* Start at viewport edge */
    width: 280px;
    height: 100vh;
    background: linear-gradient(180deg, rgba(30, 30, 30, 0.98) 0%, rgba(26, 26, 26, 0.98) 100%);
    backdrop-filter: blur(20px);
    border-right: 1px solid rgba(243, 159, 27, 0.15);
    /* FIXED: Hide menu by default */
    transform: translateX(-100%); /* Hide off-screen */
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    opacity: 0;
    visibility: hidden;
    z-index: 1990; /* High enough to be above navbar */
    /* Enhanced shadow */
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.25);
    /* Hardware acceleration */
    will-change: transform;
}

.sidebar-menu.active {
    /* FIXED: Slide next to rail */
    transform: translateX(72px); /* Show menu next to rail */
    opacity: 1;
    visibility: visible;
}

.sidebar-menu-inner {
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 0; /* Remove padding to control spacing precisely */
}

/* Menu Header */
.sidebar-menu-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 32px 20px 16px 20px; /* MORE top padding to avoid cut-off */
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    margin-bottom: 20px;
    position: relative;
    background: rgba(0, 0, 0, 0.1);
    margin-top: 8px; /* Push down from very top */
}

/* Context breadcrumb indicator */
.sidebar-menu-header::after {
    content: "Главная • Недвижимость";
    position: absolute;
    bottom: -8px;
    left: 0;
    font-size: 0.6rem;
    color: rgba(243, 159, 27, 0.6);
    font-weight: 400;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.menu-title {
    font-size: 13px;
    font-weight: 600;
    color: #FFFFFF;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.9;
}

.pin-sidebar-btn {
    width: 28px;
    height: 28px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    color: rgba(255, 255, 255, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.pin-sidebar-btn:hover {
    background: rgba(243, 159, 27, 0.1);
    border-color: rgba(243, 159, 27, 0.5);
    color: #F39F1B;
    transform: scale(1.05);
}

.pin-sidebar-btn.pinned {
    background: rgba(243, 159, 27, 0.15);
    border-color: #F39F1B;
    color: #F39F1B;
}

/* Menu Content */
.sidebar-menu-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding-top: 8px;
}

/* Custom Scrollbar */
.sidebar-menu-content::-webkit-scrollbar {
    width: 4px;
}

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

.sidebar-menu-content::-webkit-scrollbar-thumb {
    background: rgba(243, 159, 27, 0.3);
    border-radius: 2px;
}

.sidebar-menu-content::-webkit-scrollbar-thumb:hover {
    background: rgba(243, 159, 27, 0.5);
}

/* Search Section */
.menu-search-section {
    margin-bottom: 20px;
    padding: 0 20px;
}

.menu-search-input {
    width: 100%;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: #FFFFFF;
    font-size: 14px;
    transition: all 0.2s ease;
    font-family: inherit;
    box-sizing: border-box;
}

.menu-search-input::placeholder {
    color: rgba(255, 255, 255, 0.4);
    font-weight: 400;
}

.menu-search-input:focus {
    outline: none;
    border-color: rgba(243, 159, 27, 0.5);
    background: rgba(255, 255, 255, 0.08);
    box-shadow: 0 0 0 3px rgba(243, 159, 27, 0.1);
}

/* Menu Sections */
.menu-section {
    margin-bottom: 24px;
    padding: 0 20px;
}

.menu-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    cursor: pointer;
    padding: 8px 0;
    transition: all 0.2s ease;
}

.menu-section-header:hover {
    color: rgba(243, 159, 27, 0.8);
}

.menu-section-title {
    font-size: 11px;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.5);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.section-chevron {
    transition: transform 0.3s ease;
    color: #8A8A8A;
}

.menu-section.collapsed .section-chevron {
    transform: rotate(-90deg);
}

/* Menu Items */
.menu-item {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 12px; /* Consistent 12px gap */
    padding: 14px 20px; /* Better padding for touch targets */
    color: #E0E0E0;
    text-decoration: none;
    border-radius: 8px; /* Larger radius for modern look */
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    margin-bottom: 4px; /* Reduced margin for tighter layout */
    min-height: 44px; /* Standard touch target size */
    border-left: 3px solid transparent; /* Reserve space for active border */
    margin-left: 0; /* Ensure consistent left alignment */
}

.menu-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 0;
    background: #F39F1B;
    transition: height 0.3s ease;
    border-radius: 0 2px 2px 0;
}

.menu-item:hover {
    background: rgba(255, 255, 255, 0.02); /* Ultra-subtle hover background */
    color: #FFFFFF;
    border-left: 3px solid rgba(243, 159, 27, 0.6);
    transform: translateX(2px); /* Subtle slide effect */
}

.menu-item:hover .menu-icon {
    opacity: 1;
    color: #F39F1B;
    transform: scale(1.05); /* Subtle icon scale */
}

.menu-item.active {
    background: rgba(243, 159, 27, 0.08); /* Professional subtle background */
    color: #F39F1B;
    border-left: 3px solid #F39F1B;
    font-weight: 600; /* Emphasize active state */
}

.menu-item.active .menu-icon {
    opacity: 1;
    color: #F39F1B;
    transform: scale(1.1);
}

.menu-item.active::before {
    height: 0; /* Remove the additional indicator */
}

.menu-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.8; /* Slightly muted by default */
    transition: opacity 0.2s ease;
}

.menu-label {
    flex: 1;
    font-size: 14px; /* Exact pixel size for consistency */
    font-weight: 500;
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    letter-spacing: -0.01em; /* Slight negative for better readability */
}

.menu-chevron {
    margin-left: auto;
    transition: transform 0.3s ease;
}

.menu-item.expandable.expanded .menu-chevron {
    transform: rotate(90deg);
}

/* Submenu */
.menu-submenu {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
    margin-left: 1.5rem;
}

.menu-item-group.expanded .menu-submenu {
    max-height: 300px;
}

.submenu-item {
    display: flex;
    align-items: center;
    padding: 0.5rem 0.75rem;
    color: #8A8A8A;
    text-decoration: none;
    font-size: 0.8125rem;
    border-radius: 4px;
    transition: all 0.3s ease;
    margin-bottom: 0.125rem;
}

.submenu-item:hover {
    background: rgba(243, 159, 27, 0.1);
    color: #E0E0E0;
}

.submenu-item.active {
    color: #F39F1B;
}

/* Menu Divider */
.menu-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.08);
    margin: 20px 20px;
}

/* Create Thread Button */
.menu-create {
    background: linear-gradient(135deg, #F39F1B 0%, #FF8C00 100%);
    color: #FFFFFF;
    font-weight: 600;
    margin: 20px 20px 0 20px;
    border-left: 3px solid transparent; /* Override border */
    box-shadow: 0 2px 8px rgba(243, 159, 27, 0.2);
}

.menu-create:hover {
    background: linear-gradient(135deg, #FF8C00 0%, #F39F1B 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(243, 159, 27, 0.3);
    border-left: 3px solid transparent;
}

.menu-create .menu-icon {
    opacity: 1;
    color: #FFFFFF;
}

/* Main Content Adjustment */
.main-content-wrapper {
    margin-left: 72px;
    transition: margin-left 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    position: relative;
    z-index: 1;
    padding-top: 80px; /* Space for navbar */
}

.main-content-wrapper.menu-pinned {
    margin-left: 360px;
}

/* Backdrop for Mobile */
.sidebar-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 1001;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.sidebar-backdrop.active {
    opacity: 1;
    visibility: visible;
}

/* Mobile Responsive Design */
@media (max-width: 768px) {
    /* Mobile navigation rail */
    .sidebar-container {
        width: 60px; /* Smaller mobile rail */
        background: linear-gradient(180deg, 
            rgba(26, 26, 26, 0.98) 0%, 
            rgba(30, 30, 30, 0.98) 100%
        );
    }
    
    .sidebar-collapsed {
        padding: 20px 0 1rem 0; /* Start immediately, no top margin on mobile */
        margin-top: 20px; /* Consistent spacing on mobile */
    }
    
    /* Mobile drawer - FIXED with transform */
    .sidebar-menu {
        width: 100vw;
        max-width: 280px;
        left: 0; /* Start from viewport edge on mobile */
        transform: translateX(-100%); /* Hide off-screen */
        top: 0; /* Full height on mobile */
        height: 100vh;
    }
    
    .sidebar-menu.active {
        transform: translateX(0); /* Slide in completely on mobile */
        opacity: 1;
        visibility: visible;
    }
    
    .main-content-wrapper {
        margin-left: 60px;
    }
    
    /* Hide text labels in collapsed mobile rail */
    .nav-label {
        display: none;
    }
    
    .sidebar-counter {
        padding: 0.5rem;
    }
    
    .counter-label {
        display: none;
    }
    
    /* Mobile menu item optimization */
    .sidebar-nav-item {
        padding: 0.75rem 0.5rem;
    }
    
    .menu-icon {
        width: 16px;
        height: 16px;
    }
}

/* FIXED: Hover with correct transform */
.sidebar-container:hover .sidebar-menu:not(.pinned) {
    transform: translateX(72px); /* Show menu next to rail */
    opacity: 1;
    visibility: visible;
}

/* Close menu when clicking outside */
.sidebar-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: transparent;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.sidebar-backdrop.active {
    opacity: 1;
    visibility: visible;
    background: rgba(0, 0, 0, 0.3);
}

/* Performance optimization for animations */
.sidebar-container * {
    will-change: auto;
}

.sidebar-menu.active,
.sidebar-nav-item,
.menu-item {
    will-change: transform, opacity;
}

/* GPU acceleration for smooth animations */
.sidebar-menu,
.sidebar-collapsed,
.nav-item-bg,
.menu-item::before {
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* Animations */
@keyframes slideIn {
    from {
        transform: translateX(-100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Tooltip */
.sidebar-nav-item[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    margin-left: 0.5rem;
    padding: 0.25rem 0.5rem;
    background: rgba(0, 0, 0, 0.9);
    color: #FFFFFF;
    font-size: 0.75rem;
    border-radius: 4px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 10000;
}

.sidebar-nav-item:hover[data-tooltip]::after {
    opacity: 1;
    visibility: visible;
}

/* Focus States */
.menu-item:focus-visible,
.sidebar-nav-item:focus-visible {
    outline: 2px solid #F39F1B;
    outline-offset: 2px;
}

/* Loading State */
.menu-loading {
    display: flex;
    justify-content: center;
    padding: 2rem;
}

.menu-loading::after {
    content: '';
    width: 24px;
    height: 24px;
    border: 3px solid rgba(243, 159, 27, 0.2);
    border-top-color: #F39F1B;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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