/* ==================== Navbar Switcher Base Styles ==================== */

.navbar-switcher-container {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.navbar-dropdown {
    position: relative;
}

.navbar-dropdown-trigger {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--pst-color-text-base);
    background: transparent;
    border: none;
    border-radius: 6px;
    transition: background 0.2s ease, color 0.2s ease;
    user-select: none;
    white-space: nowrap;
}

.navbar-dropdown-trigger:hover {
    background: var(--pst-color-surface);
    color: var(--pst-color-primary);
}

.switcher-icon {
    font-size: 1.1rem;
    line-height: 1;
    flex-shrink: 0;
}

.switcher-text {
    font-weight: 500;
    line-height: 1;
}

.dropdown-icon {
    font-size: 0.7rem;
    transition: transform 0.2s ease;
    flex-shrink: 0;
}

.navbar-dropdown.active .dropdown-icon {
    transform: rotate(180deg);
}

.navbar-dropdown-panel {
    position: absolute;
    top: calc(100% + 0.5rem);
    right: 0;
    min-width: 160px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: opacity 0.2s ease, visibility 0.2s ease, transform 0.2s ease;
    z-index: 1000;
}

/* Desktop: hover to open */
@media (hover: hover) and (pointer: fine) and (min-width: 768px) {
    .navbar-dropdown:hover .navbar-dropdown-panel {
        opacity: 1;
        visibility: visible;
        transform: translateY(0);
    }
    
    .navbar-dropdown:hover .dropdown-icon {
        transform: rotate(180deg);
    }
}

/* Mobile/Touch: click to open */
.navbar-dropdown.active .navbar-dropdown-panel {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.dropdown-content {
    background: var(--pst-color-background);
    border: 1px solid var(--pst-color-border);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    padding: 0.5rem;
    max-height: 320px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--pst-color-border) transparent;
}

.dropdown-content::-webkit-scrollbar {
    width: 6px;
}

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

.dropdown-content::-webkit-scrollbar-thumb {
    background: var(--pst-color-border);
    border-radius: 3px;
}

.dropdown-content::-webkit-scrollbar-thumb:hover {
    background: var(--pst-color-text-muted);
}

.dropdown-item {
    display: block;
    padding: 0.5rem 0.75rem;
    color: var(--pst-color-text-base);
    text-decoration: none;
    border-radius: 4px;
    transition: background 0.15s ease, color 0.15s ease;
    font-size: 0.875rem;
    white-space: nowrap;
}

.dropdown-item:hover {
    background: var(--pst-color-surface);
    color: var(--pst-color-primary);
}

.dropdown-item.active {
    background: var(--pst-color-primary);
    color: white;
    font-weight: 600;
}

/* ==================== Responsive Switchers ==================== */

@media (min-width: 768px) and (max-width: 959px) {
    .navbar-dropdown-trigger {
        padding: 0.4rem 0.6rem;
        font-size: 0.813rem;
    }
    
    .dropdown-icon {
        display: none;
    }
    
    .switcher-icon {
        font-size: 1rem;
    }
}

@media (max-width: 767px) {
    .switcher-text {
        display: none;
    }
    
    .dropdown-icon {
        display: none;
    }
    
    .navbar-dropdown-trigger {
        padding: 0.5rem;
        min-width: 40px;
        height: 40px;
        justify-content: center;
    }
    
    .switcher-icon {
        font-size: 1.25rem;
    }
    
    .navbar-switcher-container {
        gap: 0.25rem;
    }
    
    /* Mobile: center dropdown */
    .navbar-dropdown-panel {
        left: 50%;
        right: auto;
        transform: translateX(-50%) translateY(-10px);
        min-width: 200px;
        max-width: 90vw;
    }
    
    .navbar-dropdown.active .navbar-dropdown-panel {
        transform: translateX(-50%) translateY(0);
    }
}

/* ==================== Sidebar Collapse ==================== */

/* Align toggle button and breadcrumb in header */
.header-article-items__start {
    display: flex !important;
    align-items: center;
    gap: 0.5rem;
}

/* Sidebar collapse toggle button */
.sidebar-collapse-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    padding: 0;
    background: transparent;
    color: var(--pst-color-text-base, #666);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 18px;
    transition: all 0.2s ease;
    opacity: 0;
    pointer-events: none;
}

/* Show toggle only when primary sidebar is present */
body:has(.bd-sidebar-primary:not(.hide-on-wide)) .sidebar-collapse-toggle {
    opacity: 1;
    pointer-events: auto;
}

/* Hover effect for collapse toggle */
.sidebar-collapse-toggle:hover {
    background: var(--pst-color-surface, rgba(0, 0, 0, 0.05));
    color: var(--pst-color-primary, #0069d9);
}

/* Active press state */
.sidebar-collapse-toggle:active {
    transform: scale(0.95);
}

/* Icon rotation animation */
.sidebar-collapse-toggle i {
    transition: transform 0.2s ease;
}

/* Rotate icon when sidebar is collapsed */
body.sidebar-collapsed .sidebar-collapse-toggle i {
    transform: rotate(180deg);
}

/* Prevent breadcrumb wrapping */
.header-article-items__start .breadcrumb,
.header-article-items__start nav {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
}

/* Desktop styles */
@media (min-width: 960px) {
    /* Primary sidebar with responsive width */
    .bd-sidebar-primary {
        max-width: 20%;
        transition: max-width 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                    transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                    visibility 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                    opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    /* Hide sidebar when collapsed */
    body.sidebar-collapsed .bd-sidebar-primary {
        max-width: 0 !important;
        transform: translateX(-100%);
        visibility: hidden;
        opacity: 0;
        pointer-events: none;
    }

    /* Main content container with fluid max-width */
    .bd-main .bd-content .bd-article-container {
        max-width: 100%;
        transition: max-width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    /* Expand article width when sidebar is collapsed */
    body.sidebar-collapsed .bd-main .bd-content .bd-article-container,
    body.sidebar-collapsed .bd-content,
    body.sidebar-collapsed .bd-article {
        max-width: 100% !important;
    }

    /* Main layout transition */
    .bd-main {
        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    /* Grid layout transition for container */
    .bd-container__inner {
        transition: grid-template-columns 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    body.sidebar-collapsed .bd-container__inner {
        grid-template-columns: 0 1fr !important;
    }

    body.sidebar-collapsed .bd-main {
        max-width: 100% !important;
    }

    /* Only show toggle when primary sidebar exists and is not hidden */
    body:has(.bd-sidebar-primary:not(.hide-on-wide)) .sidebar-collapse-toggle {
        display: inline-flex;
    }
}

/* Mobile styles */
@media (max-width: 959px) {
    /* Burger menu hidden under narrow screen */
    .sidebar-collapse-toggle {
        display: none !important;
    }
}


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

html[data-theme="dark"] .dropdown-content,
html[data-mode="dark"] .dropdown-content {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

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

.navbar-dropdown-trigger:focus-visible,
.sidebar-collapse-toggle:focus-visible {
    outline: 2px solid var(--pst-color-primary);
    outline-offset: 2px;
}

.dropdown-item:focus-visible {
    outline: 2px solid var(--pst-color-primary);
    outline-offset: -2px;
}

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

@media print {
    .navbar-switcher-container,
    .sidebar-collapse-toggle {
        display: none !important;
    }
}

/* ==================== Reduced Motion ==================== */

@media (prefers-reduced-motion: reduce) {
    * {
        transition-duration: 0.01ms !important;
    }
}
