/* Dropdown Menu Fix - Ensure menus only show when clicked */

/* Base dropdown styles */
.dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    background: white;
    border-radius: 0.5rem;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    border: 1px solid rgba(0, 0, 0, 0.1);
    min-width: 200px;
    z-index: 1000;
    margin-top: 0.5rem;
}

.dropdown-menu.show {
    display: block;
    animation: fadeIn 0.2s ease-out;
}

/* User menu specific styles - HIDDEN BY DEFAULT */
#userMenu,
#mobileUserMenu {
    display: none !important;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s ease;
    pointer-events: none;
}

/* ONLY show when explicitly shown */
#userMenu.show,
#mobileUserMenu.show {
    display: block !important;
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    pointer-events: auto;
}

/* Dropdown menu items */
.dropdown-menu a,
.dropdown-menu button,
#userMenu a,
#userMenu button,
#mobileUserMenu a,
#mobileUserMenu button {
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.75rem 1rem;
    color: #374151;
    text-decoration: none;
    border: none;
    background: none;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s ease;
    border-bottom: 1px solid #f3f4f6;
}

.dropdown-menu a:last-child,
.dropdown-menu button:last-child,
#userMenu a:last-child,
#userMenu button:last-child,
#mobileUserMenu a:last-child,
#mobileUserMenu button:last-child {
    border-bottom: none;
}

.dropdown-menu a:hover,
.dropdown-menu button:hover,
#userMenu a:hover,
#userMenu button:hover,
#mobileUserMenu a:hover,
#mobileUserMenu button:hover {
    background-color: #f3f4f6;
    color: #1f2937;
}

/* Dropdown button styles */
.dropdown-btn {
    position: relative;
    cursor: pointer;
    user-select: none;
}

.dropdown-btn:focus {
    outline: none;
}

/* Dropdown arrow animation */
.dropdown-btn .fa-chevron-down {
    transition: transform 0.2s ease;
}

.dropdown-btn.active .fa-chevron-down {
    transform: rotate(180deg);
}

/* Mobile specific dropdown fixes */
@media (max-width: 768px) {
    #mobileUserMenu {
        position: fixed;
        top: 60px;
        right: 16px;
        left: 16px;
        width: auto;
        max-width: 300px;
        margin-left: auto;
        margin-right: 0;
        border-radius: 12px;
        box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
        border: 1px solid rgba(0, 0, 0, 0.1);
        background: white;
        z-index: 1001;
    }

    #mobileUserMenu a,
    #mobileUserMenu button {
        padding: 16px 20px;
        font-size: 16px;
        border-bottom: 1px solid #f3f4f6;
    }

    #mobileUserMenu a:last-child,
    #mobileUserMenu button:last-child {
        border-bottom: none;
    }

    #mobileUserMenu a:hover,
    #mobileUserMenu button:hover {
        background-color: #f9fafb;
    }

    /* Mobile menu button */
    #mobileUserMenuBtn {
        min-height: 48px;
        min-width: 48px;
        padding: 12px;
        border-radius: 8px;
    }

    #mobileUserMenuBtn:active {
        background-color: rgba(255, 255, 255, 0.2);
        transform: scale(0.95);
    }
}

/* Desktop dropdown fixes */
@media (min-width: 769px) {
    #userMenu {
        position: absolute;
        top: 100%;
        right: 0;
        margin-top: 0.5rem;
        min-width: 200px;
    }

    #userMenu a,
    #userMenu button {
        padding: 0.75rem 1rem;
        font-size: 0.875rem;
    }
}

/* Animation for dropdown */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(-10px);
    }
}

/* CRITICAL: Ensure dropdowns are hidden by default */
.dropdown-menu,
#userMenu,
#mobileUserMenu {
    display: none !important;
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

/* CRITICAL: Only show when explicitly shown */
.dropdown-menu.show,
#userMenu.show,
#mobileUserMenu.show {
    display: block !important;
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
}

/* Z-index management */
.dropdown-menu,
#userMenu,
#mobileUserMenu {
    z-index: 1000;
}

/* Backdrop for mobile dropdowns */
@media (max-width: 768px) {
    .dropdown-backdrop {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.3);
        z-index: 999;
        display: none;
    }

    .dropdown-backdrop.show {
        display: block;
    }
}

/* Focus management for accessibility */
.dropdown-menu:focus-within,
#userMenu:focus-within,
#mobileUserMenu:focus-within {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* Hover states for non-touch devices */
@media (hover: hover) and (pointer: fine) {
    .dropdown-menu a:hover,
    .dropdown-menu button:hover,
    #userMenu a:hover,
    #userMenu button:hover,
    #mobileUserMenu a:hover,
    #mobileUserMenu button:hover {
        background-color: #f3f4f6;
        color: #1f2937;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    .dropdown-menu a:active,
    .dropdown-menu button:active,
    #userMenu a:active,
    #userMenu button:active,
    #mobileUserMenu a:active,
    #mobileUserMenu button:active {
        background-color: #e5e7eb;
        color: #111827;
    }
}

/* Additional safety measures */
#userMenu:not(.show),
#mobileUserMenu:not(.show) {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
    position: absolute !important;
    left: -9999px !important;
    top: -9999px !important;
}
