/**
 * Collapsible Menu Styles
 *
 * Provides icon-only collapsed state for the sidebar menu on desktop.
 * Menu collapses to 60px width, expands on hover or via toggle.
 */

/* ===== Toggle Button ===== */
.menu-collapse-toggle {
    position: fixed;
    top: 77px; /* 65px header + 12px offset */
    left: 286px; /* 300px menu width - 14px to overlap */
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 50%;
    cursor: pointer;
    color: #4a5568;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1001;
}

.menu-collapse-toggle:hover {
    background: #f8fafc;
    color: #368BC1;
    box-shadow: 0 2px 12px rgba(54, 139, 193, 0.2);
}

.menu-collapse-toggle svg {
    width: 16px;
    height: 16px;
    transition: transform 0.3s ease;
}

/* Rotate icon when collapsed */
.menu-collapse-toggle.collapsed svg {
    transform: rotate(180deg);
}

/* ===== Collapsed State (Desktop Only) ===== */
@media screen and (min-width: 1001px) {

    /* Make menu position relative for toggle positioning */
    .left {
        position: fixed;
        transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1),
                    box-shadow 0.25s ease;
    }

    /* Base collapsed styles - use !important to override
       Support both .left.collapsed (JS applied) and html.menu-collapsed .left (early init) */
    .left.collapsed,
    html.menu-collapsed .left {
        width: 60px !important;
        overflow: visible;
        display: flex;
        flex-direction: column;
        align-items: center;
        padding: 8px 0 !important;
    }

    /* Hide the <br> tag */
    .left.collapsed br,
    html.menu-collapsed .left br {
        display: none;
    }

    /* Move toggle to collapsed menu edge */
    .left.collapsed ~ .menu-collapse-toggle,
    .menu-collapse-toggle.collapsed,
    html.menu-collapsed .menu-collapse-toggle {
        left: 46px; /* 60px menu width - 14px to overlap */
    }

    /* Move toggle back when menu is hovered */
    .left.collapsed:hover ~ .menu-collapse-toggle,
    html.menu-collapsed .left:hover ~ .menu-collapse-toggle {
        left: 286px; /* Back to expanded position */
    }

    /* Hide text labels in collapsed state (not on hover) */
    /* Exclude .menu-chat-item which should always be hidden on desktop */
    .left.collapsed:not(:hover) > a:not(.menu-chat-item),
    .left.collapsed:not(:hover) > .has-submenu,
    html.menu-collapsed .left:not(:hover) > a:not(.menu-chat-item),
    html.menu-collapsed .left:not(:hover) > .has-submenu {
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
        width: 44px !important;
        height: 44px !important;
        padding: 0 !important;
        margin: 2px 0 !important;
        overflow: visible;
        font-size: 0 !important;
        border-radius: 8px;
        position: relative;
        border-left: none !important;
    }

    /* Center icons perfectly (not on hover) */
    .left.collapsed:not(:hover) > a .menu-icon,
    .left.collapsed:not(:hover) > .has-submenu .menu-icon,
    html.menu-collapsed .left:not(:hover) > a .menu-icon,
    html.menu-collapsed .left:not(:hover) > .has-submenu .menu-icon {
        margin: 0 !important;
        flex-shrink: 0;
    }

    /* Style badges in collapsed state (not on hover) */
    .left.collapsed:not(:hover) .menu-count,
    html.menu-collapsed .left:not(:hover) .menu-count {
        position: absolute;
        top: -4px;
        right: -4px;
        padding: 2px 5px;
        font-size: 0.6rem;
        min-width: 14px;
        height: auto;
        line-height: 1;
    }

    /* Hide submenu chevron (not on hover) */
    .left.collapsed:not(:hover) .has-submenu:after,
    html.menu-collapsed .left:not(:hover) .has-submenu:after {
        display: none !important;
    }

    /* Hide lock icons in collapsed (not on hover) */
    .left.collapsed:not(:hover) .menu-lock-icon,
    html.menu-collapsed .left:not(:hover) .menu-lock-icon {
        display: none !important;
    }

    /* Hide all submenus in collapsed state (not on hover) */
    .left.collapsed:not(:hover) .submenu,
    html.menu-collapsed .left:not(:hover) .submenu {
        display: none !important;
    }

    /* When collapsed, also hide submenus that aren't open */
    .left.collapsed .submenu,
    html.menu-collapsed .left .submenu {
        display: none;
    }

    /* Only show submenus that are open (via JS toggle) */
    .left.collapsed .has-submenu.open + .submenu,
    html.menu-collapsed .left .has-submenu.open + .submenu {
        display: block;
    }

    /* Content area adjustment */
    .content.menu-collapsed,
    html.menu-collapsed .content {
        padding-left: 5rem !important;
    }

    /* ===== Hover Expansion ===== */
    .left.collapsed:hover,
    html.menu-collapsed .left:hover {
        width: 300px !important;
        display: block !important;
        padding: 8px 0 !important;
        box-shadow: 0 4px 30px rgba(54, 139, 193, 0.15);
        overflow-y: auto !important;
        overflow-x: hidden !important;
        overscroll-behavior: contain;
    }

    /* Push content when menu expands on hover */
    html:has(.left.collapsed:hover) .content,
    html.menu-collapsed:has(.left:hover) .content {
        padding-left: 19rem !important; /* 300px menu + 4px gap */
    }

    /* Reset styles on hover to normal menu */
    /* Exclude .menu-chat-item which should always be hidden on desktop */
    .left.collapsed:hover > a:not(.menu-chat-item),
    .left.collapsed:hover > .has-submenu,
    html.menu-collapsed .left:hover > a:not(.menu-chat-item),
    html.menu-collapsed .left:hover > .has-submenu {
        display: flex !important;
        justify-content: flex-start !important;
        align-items: center !important;
        width: auto !important;
        height: auto !important;
        padding: 12px 16px !important;
        margin: 4px 12px !important;
        font-size: 0.9rem !important;
        border-left: 3px solid transparent !important;
    }

    .left.collapsed:hover > a .menu-icon,
    .left.collapsed:hover > .has-submenu .menu-icon,
    html.menu-collapsed .left:hover > a .menu-icon,
    html.menu-collapsed .left:hover > .has-submenu .menu-icon {
        margin-right: 12px !important;
    }

    .left.collapsed:hover .menu-lock-icon,
    html.menu-collapsed .left:hover .menu-lock-icon {
        display: inline-block !important;
    }

    .left.collapsed:hover .menu-count,
    html.menu-collapsed .left:hover .menu-count {
        position: static !important;
        padding: 2px 8px !important;
        font-size: 0.75rem !important;
        min-width: 20px !important;
    }

    .left.collapsed:hover .has-submenu:after,
    html.menu-collapsed .left:hover .has-submenu:after {
        display: block !important;
    }

    /* Only show open submenus on hover - let JS control open/close state */
    .left.collapsed:hover .has-submenu.open + .submenu,
    html.menu-collapsed .left:hover .has-submenu.open + .submenu {
        display: block !important;
    }

    /* Smooth transitions */
    .left a,
    .left .has-submenu {
        transition: all 0.2s ease;
    }

    .content {
        transition: padding-left 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    }
}

/* ===== Hide toggle on mobile ===== */
@media screen and (max-width: 1000px) {
    .menu-collapse-toggle {
        display: none !important;
    }
}

/* ===== Dark Mode Support ===== */
.dark-mode .menu-collapse-toggle,
html.dark-mode .menu-collapse-toggle {
    background: #1e293b;
    border-color: #334155;
    color: #94a3b8;
}

.dark-mode .menu-collapse-toggle:hover,
html.dark-mode .menu-collapse-toggle:hover {
    background: #334155;
    color: #60a5fa;
    box-shadow: 0 2px 12px rgba(96, 165, 250, 0.2);
}

@media (prefers-color-scheme: dark) {
    .dark-mode-auto .menu-collapse-toggle,
    html.dark-mode-auto .menu-collapse-toggle {
        background: #1e293b;
        border-color: #334155;
        color: #94a3b8;
    }

    .dark-mode-auto .menu-collapse-toggle:hover,
    html.dark-mode-auto .menu-collapse-toggle:hover {
        background: #334155;
        color: #60a5fa;
        box-shadow: 0 2px 12px rgba(96, 165, 250, 0.2);
    }
}
