/**
 * Unified Navigation Styles
 * Shared across all pages
 */

/* Disable transitions during initial state application */
.sidebar.no-transition,
.sidebar.no-transition * {
    transition: none;
}

:root {
    --sidebar-text: rgba(255, 255, 255, 0.7);
    --sidebar-text-strong: rgba(255, 255, 255, 0.9);
    --sidebar-text-muted: rgba(255, 255, 255, 0.5);
    --sidebar-hover-bg: rgba(255, 255, 255, 0.1);
    --sidebar-active-bg: rgba(99, 102, 241, 0.3);
    --sidebar-divider: rgba(255, 255, 255, 0.1);
    --sidebar-user-bg: rgba(0, 0, 0, 0.2);
}

@media (prefers-color-scheme: light) {
    :root {
        --sidebar-text: #1e293b;
        --sidebar-text-strong: #0f172a;
        --sidebar-text-muted: #475569;
        --sidebar-hover-bg: rgba(15, 23, 42, 0.08);
        --sidebar-active-bg: rgba(99, 102, 241, 0.15);
        --sidebar-divider: rgba(15, 23, 42, 0.1);
        --sidebar-user-bg: rgba(15, 23, 42, 0.05);
    }
}

body.no-transition {
    transition: none;
}

.sidebar.is-loading {
    opacity: 0.8;
    pointer-events: none;
    cursor: progress;
}

/* Sidebar Container */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    width: 60px;
    background: linear-gradient(180deg, var(--bg-secondary) 0%, var(--bg-primary) 100%);
    transition: width 0.3s ease;
    z-index: 1000;
    overflow: hidden;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
}

.sidebar.expanded {
    width: 280px;
}

/* Sidebar Header */
.sidebar-header {
    padding: 20px 15px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--sidebar-divider);
    min-height: 70px;
}

/* Center toggle button when sidebar is collapsed */
.sidebar:not(.expanded) .sidebar-header {
    justify-content: center;
    padding: 20px 5px;
}

/* Ensure toggle button fits in collapsed sidebar */
.sidebar:not(.expanded) .sidebar-toggle {
    margin: 0 auto;
}

.sidebar-header h2 {
    color: var(--text-primary);
    font-size: 1.2rem;
    font-weight: 600;
    margin: 0;
    opacity: 0;
    transition: opacity 0.2s ease;
    white-space: nowrap;
}

.sidebar.expanded .sidebar-header h2 {
    opacity: 1;
}

.sidebar-toggle {
    background: var(--sidebar-hover-bg);
    border: none;
    border-radius: var(--border-radius-sm);
    padding: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    color: var(--text-primary);
}

.sidebar-toggle:hover {
    background: var(--sidebar-hover-bg);
}

.sidebar.expanded .sidebar-toggle svg {
    transform: rotate(180deg);
}

/* Sidebar Menu */
.sidebar-menu {
    list-style: none;
    padding: 15px 10px;
    margin: 0;
    flex: 1;
    overflow-y: auto;
}

.sidebar-menu li {
    margin-bottom: 4px;
}

/* Section Labels */
.menu-section-label,
.sidebar-section-label {
    color: var(--sidebar-text-muted);
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    padding: 12px 15px 6px;
    opacity: 0;
    transition: opacity 0.2s ease;
    white-space: nowrap;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    user-select: none;
}

/* Hide section labels when sidebar is collapsed */
.sidebar:not(.expanded) .menu-section-label,
.sidebar:not(.expanded) .sidebar-section-label {
    display: none;
}

.menu-section-label:hover,
.sidebar-section-label:hover {
    color: var(--sidebar-text);
}

.sidebar.expanded .menu-section-label,
.sidebar.expanded .sidebar-section-label {
    opacity: 1;
}

/* Section Chevron */
.section-chevron {
    transition: transform 0.2s ease;
    opacity: 0.5;
    flex-shrink: 0;
}

.menu-section-label:hover .section-chevron {
    opacity: 0.8;
}

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

/* Menu Divider */
.menu-divider,
.sidebar-divider {
    height: 1px;
    background: var(--sidebar-divider);
    margin: 10px 15px;
}

/* Hide dividers when sidebar is collapsed */
.sidebar:not(.expanded) .menu-divider,
.sidebar:not(.expanded) .sidebar-divider {
    display: none;
}

/* Sidebar Links */
.sidebar-link {
    display: flex;
    align-items: center;
    padding: 12px 15px;
    color: var(--sidebar-text);
    text-decoration: none;
    border-radius: var(--border-radius-sm);
    transition: all 0.2s ease;
    gap: 12px;
    white-space: nowrap;
    background: transparent;
    border: none;
    width: 100%;
    text-align: left;
    cursor: pointer;
    font-size: 0.9rem;
}

/* Center icons when sidebar is collapsed */
.sidebar:not(.expanded) .sidebar-link {
    justify-content: center;
    padding: 12px 0;
    margin: 2px 5px;
    width: auto;
}

.sidebar:not(.expanded) .sidebar-menu {
    padding: 15px 5px;
}

/* Fix active state when collapsed */
.sidebar:not(.expanded) .sidebar-link.active {
    background: var(--sidebar-active-bg);
    border-radius: var(--border-radius-sm);
}

.sidebar-link:hover {
    background: var(--sidebar-hover-bg);
    color: var(--sidebar-text-strong);
}

.sidebar-link.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-text-strong);
}

.sidebar-link svg {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
}

.sidebar-link-text {
    opacity: 0;
    transition: opacity 0.2s ease;
    font-weight: 500;
}

.sidebar.expanded .sidebar-link-text {
    opacity: 1;
}

/* Hide link text completely when sidebar is collapsed */
.sidebar:not(.expanded) .sidebar-link-text {
    display: none;
}

/* Child Navigation Items */
.nav-child,
.sidebar-nav-child {
    margin-left: 20px;
}

/* Hide child items when sidebar is collapsed */
.sidebar:not(.expanded) .nav-child,
.sidebar:not(.expanded) .sidebar-nav-child {
    display: none;
}

.sidebar-link-child {
    padding: 8px 15px;
    font-size: 0.85rem;
}

.sidebar-link-child::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--sidebar-divider);
    margin-right: 10px;
}

.sidebar-link-child.active::before {
    background: var(--accent-primary);
}

/* Item Toggle Button (for parent items with children) */
.sidebar-menu li {
    position: relative;
}

.item-toggle {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    padding: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--sidebar-text-muted);
    border-radius: 4px;
    transition: all 0.2s ease;
    opacity: 0;
}

.sidebar.expanded .item-toggle {
    opacity: 1;
}

/* Hide item toggles when sidebar is collapsed */
.sidebar:not(.expanded) .item-toggle {
    display: none;
}

.item-toggle:hover {
    background: var(--sidebar-hover-bg);
    color: var(--sidebar-text-strong);
}

.item-toggle svg {
    transition: transform 0.2s ease;
}

.item-toggle.collapsed svg {
    transform: rotate(-90deg);
}

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

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

.sidebar::-webkit-scrollbar-thumb {
    background: var(--sidebar-hover-bg);
    border-radius: 2px;
}

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

/* Main Content Offset - handled by base.css using CSS variables */

/* Responsive Adjustments */
@media (max-width: 768px) {
    .sidebar {
        width: 0;
        transform: translateX(-100%);
    }

    .sidebar.expanded {
        width: 280px;
        transform: translateX(0);
    }

    body {
        margin-left: 0;
    }

    body.sidebar-expanded {
        margin-left: 0;
    }

    .sidebar.expanded ~ .main-content {
        opacity: 0.5;
    }
}

/* Survey Module Colors */
.sidebar-link[href*="portfolio"] .sidebar-link-text,
.sidebar-link[href*="portfolio"]:hover,
[data-parent-item="portfolio"] .sidebar-link .sidebar-link-text,
[data-parent-item="portfolio"] .sidebar-link:hover {
    color: var(--portfolio-primary);
}

.sidebar-link[href*="cis"] .sidebar-link-text,
.sidebar-link[href*="cis"]:hover,
[data-parent-item="cis"] .sidebar-link .sidebar-link-text,
[data-parent-item="cis"] .sidebar-link:hover {
    color: var(--cis-primary);
}

/* User Info Section at Bottom */
.sidebar-user-info {
    position: sticky;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 15px;
    background: var(--sidebar-user-bg);
    border-top: 1px solid var(--sidebar-divider);
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 60px;
}

.user-avatar {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(99, 102, 241, 0.3);
    border-radius: 50%;
    color: var(--sidebar-text-strong);
}

.user-avatar svg {
    width: 16px;
    height: 16px;
}

.user-details {
    flex: 1;
    min-width: 0;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.sidebar.expanded .user-details {
    opacity: 1;
}

.user-email {
    display: block;
    font-size: 0.75rem;
    color: var(--sidebar-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Hide user details when sidebar is collapsed */
.sidebar:not(.expanded) .user-details {
    display: none;
}

/* Center avatar when sidebar is collapsed */
.sidebar:not(.expanded) .sidebar-user-info {
    justify-content: center;
    padding: 15px 5px;
}

/* Adjust menu padding to account for user info section */
.sidebar-menu {
    padding-bottom: 110px;
}
