/**
 * WooCommerce Profile Menu Styles
 * Responsive design for desktop and mobile
 */

/* Base Styles */
.wc-profile-menu {
    position: relative;
    display: inline-flex;
    align-items: center;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    z-index: 1000;
    flex-shrink: 0;
    align-self: center;
    vertical-align: middle;
    max-width: 100%;
    box-sizing: border-box;
}

/* Loading state */
.wc-profile-menu[data-loading="true"] {
    min-width: 120px;
    min-height: 48px;
    background: #f9fafb;
    border: 1px solid #e1e5e9;
    border-radius: 8px;
    position: relative;
    overflow: hidden;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.wc-profile-menu[data-loading="true"]::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
    animation: loading-shimmer 1.5s infinite;
}

@keyframes loading-shimmer {
    0% {
        left: -100%;
    }
    100% {
        left: 100%;
    }
}

/* Loading placeholder */
.profile-loading-placeholder {
    display: flex;
    align-items: center;
    gap: 8px;
}

.loading-icon {
    width: 24px;
    height: 24px;
    background: #e5e7eb;
    border-radius: 50%;
    animation: loading-pulse 1.5s ease-in-out infinite;
}

.loading-text {
    width: 60px;
    height: 16px;
    background: #e5e7eb;
    border-radius: 4px;
    animation: loading-pulse 1.5s ease-in-out infinite;
}

@keyframes loading-pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

/* Ensure vertical centering in different contexts */
.header .wc-profile-menu,
.navbar .wc-profile-menu,
.navigation .wc-profile-menu {
    align-self: center;
    vertical-align: middle;
    max-width: 100%;
    width: auto;
}

/* Container constraints */
.container .wc-profile-menu,
.wrapper .wc-profile-menu,
.site-header .wc-profile-menu,
.header-container .wc-profile-menu {
    max-width: 100%;
    width: auto;
    flex-shrink: 1;
}

/* Flex container centering */
.flex-container .wc-profile-menu {
    align-self: center;
}

/* Grid container centering */
.grid-container .wc-profile-menu {
    align-self: center;
}

/* Profile Menu Trigger */
.profile-menu-trigger {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    background: #ffffff;
    border: 1px solid #e1e5e9;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    color: #000000;
    font-size: 14px;
    font-weight: 500;
    height: 48px !important;
    min-height: 48px;
    max-height: 48px;
    max-width: 100%;
    box-sizing: border-box;
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    flex-shrink: 0;
}

.profile-menu-trigger:hover {
    background: #f9fafb;
    border-color: #d1d5db;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.profile-menu-trigger.active {
    background: #f3f4f6;
    border-color: #9ca3af;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.profile-menu-trigger.logged-out {
    background: #f8fafc;
    border-color: #e2e8f0;
}

.profile-menu-trigger.logged-out:hover {
    background: #f1f5f9;
    border-color: #cbd5e1;
}

/* Profile Avatar */
.profile-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    margin-right: 8px;
    object-fit: cover;
    border: 2px solid #e5e7eb;
    border-radius: 50% !important;
}

.profile-avatar-initials {
    width: 32px;
    height: 32px;
    border-radius: 50% !important;
    margin-right: 8px;
    background: #3b82f6;
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
    border: 2px solid #e5e7eb;
}

.profile-icon {
    width: 24px;
    height: 24px;
    margin-right: 8px;
    color: #000000;
}

.profile-name {
    margin-right: 8px;
    white-space: nowrap;
    max-width: 90px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dropdown-arrow {
    transition: transform 0.2s ease;
    color: #000000;
    flex-shrink: 0;
}

.profile-menu-trigger.active .dropdown-arrow {
    transform: rotate(180deg);
}

/* Profile Dropdown */
.profile-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    background: #ffffff !important;
    border: 1px solid #e1e5e9;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1), 0 4px 6px rgba(0, 0, 0, 0.05);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: all 0.2s ease;
    z-index: 99999;
    min-width: 280px;
    max-width: 320px;
    overflow: hidden;
    margin-top: 8px;
}

/* Ensure dropdown stays within website container */
.wc-profile-menu {
    position: relative;
}

/* Smart positioning for dropdown */
.profile-dropdown {
    position: absolute;
    right: 0;
    left: auto;
    min-width: 280px;
    max-width: 320px;
}

/* If dropdown would go off-screen, position it to the left */
.profile-dropdown.dropdown-left {
    right: auto;
    left: 0;
}

/* Ensure dropdown is positioned correctly when JavaScript positioning is applied */
.profile-dropdown[style*="position: fixed"] {
    position: fixed !important;
}

.profile-dropdown.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    display: block !important;
}

.profile-dropdown.dropdown-up {
    top: auto;
    bottom: 100%;
    transform: translateY(8px);
}

.profile-dropdown.dropdown-up.active {
    transform: translateY(0);
}

/* Dropdown Content */
.dropdown-content {
    padding: 0;
}

/* User Info Section */
.user-info {
    padding: 16px;
    border-bottom: 1px solid #f3f4f6;
    display: flex;
    align-items: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #ffffff;
}

.user-avatar {
    margin-right: 12px;
}

.user-avatar img {
    width: 40px;
    height: 40px;
    border-radius: 50% !important;
    object-fit: cover;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.user-avatar .avatar-initials {
    width: 40px;
    height: 40px;
    border-radius: 50% !important;
    background: rgba(255, 255, 255, 0.2);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.user-details {
    flex: 1;
    min-width: 0;
}

.user-name {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

.user-email {
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 220px;
    opacity: 0.9;
}

/* Menu Items */
.menu-items {
    padding: 8px 0;
}

.menu-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    color: #000000;
    text-decoration: none;
    transition: all 0.15s ease;
    font-size: 14px;
    font-weight: 500;
}

.menu-item:hover {
    background: #f9fafb;
    color: #000000;
    text-decoration: none;
}

.menu-item.logout {
    color: #dc2626;
}

.menu-item.logout:hover {
    background: #fef2f2;
    color: #b91c1c;
}

.menu-icon {
    width: 16px;
    height: 16px;
    margin-right: 12px;
    color: #000000;
    flex-shrink: 0;
}

.menu-item.logout .menu-icon {
    color: #dc2626;
}

.menu-divider {
    height: 1px;
    background: #f3f4f6;
    margin: 8px 0;
}

/* Mobile Styles */
@media (max-width: 768px) {
    .wc-profile-menu {
        width: 100%;
        max-width: 100%;
        min-width: 0;
    }
    
    .profile-menu-trigger {
        width: 100%;
        max-width: 100%;
        justify-content: center;
        padding: 12px 16px;
        height: 56px !important;
        min-height: 56px;
        max-height: 56px;
        border-radius: 12px;
        box-sizing: border-box;
        overflow: hidden;
    }
    
    .profile-name {
        max-width: none;
        flex: 1;
        text-align: center;
    }
    
    .profile-dropdown {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-width: none;
        min-width: auto;
        border-radius: 16px 16px 0 0;
        transform: translateY(100%);
        max-height: 70vh;
        overflow-y: auto;
    }
    
    .profile-dropdown.active {
        transform: translateY(0);
    }
    
    .profile-dropdown.dropdown-up {
        top: 0;
        bottom: auto;
        border-radius: 0 0 16px 16px;
        transform: translateY(-100%);
    }
    
    .profile-dropdown.dropdown-up.active {
        transform: translateY(0);
    }
    
    .user-info {
        padding: 20px;
        border-radius: 16px 16px 0 0;
    }
    
    .user-avatar img,
    .user-avatar .avatar-initials {
        width: 48px;
        height: 48px;
    }
    
    .user-name {
        font-size: 16px;
    }
    
    .user-email {
        font-size: 14px;
    }
    
    .menu-item {
        padding: 16px 20px;
        font-size: 16px;
        min-height: 56px;
    }
    
    .menu-icon {
        width: 20px;
        height: 20px;
        margin-right: 16px;
    }
    
    /* Prevent body scroll when dropdown is open on mobile */
    body.profile-menu-open {
        overflow: hidden;
    }
    
    /* Mobile backdrop */
    .profile-dropdown::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: -1;
        opacity: 0;
        transition: opacity 0.2s ease;
    }
    
    .profile-dropdown.active::before {
        opacity: 1;
    }
}

/* Tablet Styles */
@media (min-width: 769px) and (max-width: 1024px) {
    .profile-dropdown {
        min-width: 260px;
    }
    
    .profile-name {
        max-width: 80px;
    }
}

/* High DPI Displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .profile-avatar,
    .user-avatar img {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* Override dark mode to force black text on white background */
@media (prefers-color-scheme: dark) {
    .wc-profile-menu .profile-menu-trigger {
        background: #ffffff !important;
        border-color: #e1e5e9 !important;
        color: #000000 !important;
    }
    
    .wc-profile-menu .profile-menu-trigger:hover {
        background: #f9fafb !important;
        border-color: #d1d5db !important;
    }
    
    .wc-profile-menu .profile-menu-trigger.active {
        background: #f3f4f6 !important;
        border-color: #9ca3af !important;
    }
    
    .wc-profile-menu .profile-dropdown {
        background: #ffffff !important;
        border-color: #e1e5e9 !important;
        box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1), 0 4px 6px rgba(0, 0, 0, 0.05) !important;
    }
    
    .wc-profile-menu .user-info {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
        color: #ffffff !important;
    }
    
    .wc-profile-menu .menu-item {
        color: #000000 !important;
    }
    
    .wc-profile-menu .menu-item:hover {
        background: #f9fafb !important;
        color: #000000 !important;
    }
    
    .wc-profile-menu .menu-item.logout:hover {
        background: #fef2f2 !important;
        color: #b91c1c !important;
    }
    
    .wc-profile-menu .menu-divider {
        background: #f3f4f6 !important;
    }
    
    .wc-profile-menu .profile-icon,
    .wc-profile-menu .menu-icon,
    .wc-profile-menu .dropdown-arrow {
        color: #000000 !important;
    }
    
    .wc-profile-menu .menu-item.logout .menu-icon {
        color: #dc2626 !important;
    }
}

/* Accessibility Improvements */
.profile-menu-trigger:focus {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

.menu-item:focus {
    outline: 2px solid #3b82f6;
    outline-offset: -2px;
}

/* Animation for smooth transitions */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.profile-dropdown.active .dropdown-content {
    animation: fadeInUp 0.2s ease;
}

/* RTL Support */
[dir="rtl"] .profile-menu-trigger {
    direction: rtl;
}

[dir="rtl"] .profile-avatar,
[dir="rtl"] .profile-avatar-initials,
[dir="rtl"] .profile-icon {
    margin-right: 0;
    margin-left: 8px;
}

[dir="rtl"] .profile-name {
    margin-right: 0;
    margin-left: 8px;
}

[dir="rtl"] .user-avatar {
    margin-right: 0;
    margin-left: 12px;
}

[dir="rtl"] .menu-icon {
    margin-right: 0;
    margin-left: 12px;
}

/* Print Styles */
@media print {
    .wc-profile-menu {
        display: none;
    }
}
