/**
 * User Authentication & Menu Styles for Eyes of Azrael
 * Modern, responsive styling for user display, dropdown menus, and auth components
 */

/* ============================================
   CSS CUSTOM PROPERTIES
   ============================================ */

:root {
    --user-avatar-size: 36px;
    --user-avatar-size-sm: 32px;
    --user-avatar-size-lg: 48px;
    --dropdown-width: 260px;
    --dropdown-bg: rgba(var(--color-bg-card-rgb, 26, 31, 58), 0.98);
    --dropdown-border: rgba(139, 127, 255, 0.2);
    --dropdown-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
}

/* ============================================
   USER INFO CONTAINER (Header)
   ============================================ */

.user-info {
    display: none;
    align-items: center;
    gap: 0.5rem;
    position: relative;
}

.user-info.show,
body.authenticated .user-info {
    display: flex;
}

/* ============================================
   USER MENU TRIGGER (Avatar + Name button)
   ============================================ */

.user-menu-trigger {
    display: inline-flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.375rem 0.75rem 0.375rem 0.375rem;
    background: rgba(139, 127, 255, 0.1);
    border: 1px solid rgba(139, 127, 255, 0.2);
    border-radius: var(--auth-radius-full, 9999px);
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--color-text-primary, #f8f9fa);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
}

.user-menu-trigger:hover {
    background: rgba(139, 127, 255, 0.2);
    border-color: rgba(139, 127, 255, 0.4);
    transform: translateY(-1px);
}

.user-menu-trigger:focus-visible {
    outline: 2px solid var(--color-primary, #8b7fff);
    outline-offset: 2px;
}

.user-menu-trigger[aria-expanded="true"] {
    background: rgba(139, 127, 255, 0.25);
    border-color: rgba(139, 127, 255, 0.5);
}

.user-menu-trigger img {
    width: var(--user-avatar-size-sm);
    height: var(--user-avatar-size-sm);
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(139, 127, 255, 0.4);
    transition: border-color 0.2s ease;
}

.user-menu-trigger:hover img {
    border-color: rgba(139, 127, 255, 0.7);
}

.user-menu-trigger span:not(.dropdown-indicator) {
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dropdown-indicator {
    display: flex;
    align-items: center;
    margin-left: 0.25rem;
    transition: transform 0.2s ease;
    color: var(--color-text-secondary, #adb5bd);
}

.user-menu-trigger[aria-expanded="true"] .dropdown-indicator {
    transform: rotate(180deg);
}

/* ============================================
   USER AVATAR (Standalone - Polished)
   ============================================ */

.user-avatar {
    width: var(--user-avatar-size);
    height: var(--user-avatar-size);
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(139, 127, 255, 0.4);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    background: var(--color-surface, #1a1f3a);
    position: relative;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.user-avatar::after {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    background: conic-gradient(
        from 0deg,
        var(--color-primary, #8b7fff),
        var(--color-secondary, #ff7eb6),
        var(--color-accent, #ffd93d),
        var(--color-primary, #8b7fff)
    );
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: -1;
    filter: blur(4px);
}

.user-avatar:hover {
    border-color: rgba(139, 127, 255, 0.8);
    transform: scale(1.08);
    box-shadow: 0 4px 16px rgba(139, 127, 255, 0.3);
}

.user-avatar:hover::after {
    opacity: 0.5;
}

.user-avatar.large {
    width: var(--user-avatar-size-lg);
    height: var(--user-avatar-size-lg);
}

/* Online status indicator */
.user-avatar-wrapper {
    position: relative;
    display: inline-block;
}

.user-avatar-status {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 12px;
    height: 12px;
    background: #22c55e;
    border: 2px solid var(--color-surface, #1a1f3a);
    border-radius: 50%;
    z-index: 1;
}

.user-avatar-status.offline {
    background: #6b7280;
}

.user-avatar-status.away {
    background: #f59e0b;
}

/* ============================================
   USER DROPDOWN MENU
   ============================================ */

.user-dropdown-menu {
    position: absolute;
    top: calc(100% + 0.5rem);
    right: 0;
    width: var(--dropdown-width);
    background: var(--dropdown-bg);
    backdrop-filter: blur(20px) saturate(180%);
    border: 1px solid var(--dropdown-border);
    border-radius: 16px;
    padding: 0.5rem;
    box-shadow: var(--dropdown-shadow);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px) scale(0.95);
    transform-origin: top right;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
}

.user-dropdown-menu.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* ============================================
   DROPDOWN HEADER (User Info)
   ============================================ */

.user-dropdown-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    border-radius: 12px;
    background: rgba(139, 127, 255, 0.05);
    margin-bottom: 0.25rem;
    cursor: default;
}

.dropdown-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(139, 127, 255, 0.3);
    flex-shrink: 0;
}

.dropdown-user-details {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
    min-width: 0;
    flex: 1;
}

.dropdown-user-name {
    font-weight: 600;
    color: var(--color-text-primary, #f8f9fa);
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dropdown-user-email {
    font-size: 0.8rem;
    color: var(--color-text-secondary, #adb5bd);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ============================================
   DROPDOWN DIVIDER
   ============================================ */

.user-dropdown-divider {
    height: 1px;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(139, 127, 255, 0.2) 20%,
        rgba(139, 127, 255, 0.2) 80%,
        transparent
    );
    margin: 0.5rem 0;
}

/* ============================================
   DROPDOWN MENU ITEMS
   ============================================ */

.user-dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    border-radius: 10px;
    color: var(--color-text-primary, #f8f9fa);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    border: none;
    background: transparent;
    width: 100%;
    text-align: left;
    font-family: inherit;
}

.user-dropdown-item:hover {
    background: rgba(139, 127, 255, 0.15);
    color: var(--color-text-primary, #f8f9fa);
}

.user-dropdown-item:focus-visible {
    outline: 2px solid var(--color-primary, #8b7fff);
    outline-offset: -2px;
    background: rgba(139, 127, 255, 0.15);
}

.user-dropdown-item svg {
    flex-shrink: 0;
    color: var(--color-text-secondary, #adb5bd);
    transition: color 0.15s ease;
}

.user-dropdown-item:hover svg {
    color: var(--color-primary, #8b7fff);
}

/* Sign Out Item - Special styling */
.user-dropdown-signout {
    color: #fca5a5;
    margin-top: 0.25rem;
}

.user-dropdown-signout:hover {
    background: rgba(239, 68, 68, 0.15);
    color: #fca5a5;
}

.user-dropdown-signout svg {
    color: #f87171;
}

.user-dropdown-signout:hover svg {
    color: #ef4444;
}

.user-dropdown-signout .spinner {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ============================================
   AUTHENTICATION MODAL
   ============================================ */

.auth-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    z-index: 10000;
    justify-content: center;
    align-items: center;
    padding: 1rem;
}

.auth-modal.show {
    display: flex;
}

.auth-modal-content {
    background: var(--color-surface, #1a1a2e);
    border: 1px solid rgba(139, 127, 255, 0.3);
    border-radius: 20px;
    padding: 2rem;
    max-width: 450px;
    width: 100%;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5);
    position: relative;
    animation: modal-enter 0.3s ease-out;
}

@keyframes modal-enter {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.auth-modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--color-text-secondary, #999);
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s;
}

.auth-modal-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--color-text-primary, #fff);
    transform: rotate(90deg);
}

.auth-modal-title {
    font-size: 1.75rem;
    color: var(--color-text-primary, #fff);
    margin: 0 0 1.5rem 0;
    text-align: center;
}

/* ============================================
   AUTH FORM ELEMENTS
   ============================================ */

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.auth-form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.auth-form-group label {
    color: var(--color-text-secondary, #999);
    font-size: 0.9rem;
    font-weight: 500;
}

.auth-form-group input {
    padding: 0.75rem 1rem;
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid rgba(139, 127, 255, 0.2);
    border-radius: 12px;
    color: var(--color-text-primary, #fff);
    font-size: 1rem;
    transition: all 0.2s;
}

.auth-form-group input:focus {
    outline: none;
    border-color: var(--color-primary, #8b7fff);
    box-shadow: 0 0 0 3px rgba(139, 127, 255, 0.15);
}

.auth-form-group input::placeholder {
    color: var(--color-text-muted, #6c757d);
}

/* ============================================
   AUTH MESSAGES
   ============================================ */

.auth-message {
    padding: 0.75rem 1rem;
    border-radius: 10px;
    font-size: 0.9rem;
    display: none;
    align-items: center;
    gap: 0.5rem;
}

.auth-message.show {
    display: flex;
}

.auth-message-error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #fca5a5;
}

.auth-message-success {
    background: rgba(34, 197, 94, 0.1);
    border: 1px solid rgba(34, 197, 94, 0.3);
    color: #86efac;
}

/* ============================================
   AUTH BUTTONS
   ============================================ */

.auth-submit-btn {
    padding: 0.875rem 1.5rem;
    background: linear-gradient(135deg, var(--color-primary, #8b7fff), #9d8fff);
    border: none;
    border-radius: 12px;
    color: white;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 0.5rem;
}

.auth-submit-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(139, 127, 255, 0.35);
}

.auth-submit-btn:active {
    transform: translateY(0);
}

.auth-submit-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.auth-switch {
    text-align: center;
    margin-top: 1.5rem;
    color: var(--color-text-secondary, #999);
    font-size: 0.9rem;
}

.auth-switch-link {
    color: var(--color-primary, #8b7fff);
    cursor: pointer;
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s;
}

.auth-switch-link:hover {
    color: var(--color-secondary, #ff7eb6);
    text-decoration: underline;
}

/* ============================================
   USER DISPLAY (Legacy/Inline)
   ============================================ */

.user-display {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 1rem;
    background: rgba(139, 127, 255, 0.1);
    border: 1px solid rgba(139, 127, 255, 0.2);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.user-display:hover {
    background: rgba(139, 127, 255, 0.2);
    border-color: rgba(139, 127, 255, 0.4);
}

.user-username {
    color: var(--color-text-primary, #fff);
    font-weight: 500;
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ============================================
   LEGACY DROPDOWN (Keep for compatibility)
   ============================================ */

.user-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 0.5rem;
    background: var(--dropdown-bg);
    border: 1px solid var(--dropdown-border);
    border-radius: 12px;
    padding: 0.5rem;
    min-width: 200px;
    box-shadow: var(--dropdown-shadow);
    display: none;
    z-index: 1000;
}

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

.user-dropdown-item {
    padding: 0.75rem 1rem;
    color: var(--color-text-primary, #fff);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border-radius: 8px;
    transition: background 0.2s;
}

.user-dropdown-item:hover {
    background: rgba(139, 127, 255, 0.15);
}

.user-logout-btn {
    width: 100%;
    padding: 0.75rem 1rem;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 8px;
    color: #fca5a5;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 0.5rem;
    font-family: inherit;
    font-size: 0.9rem;
}

.user-logout-btn:hover {
    background: rgba(239, 68, 68, 0.2);
}

/* ============================================
   THEORY WIDGET STYLES
   ============================================ */

.theory-widget-button {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    background: linear-gradient(135deg, rgba(139, 127, 255, 0.15), rgba(157, 143, 255, 0.15));
    border: 1px solid rgba(139, 127, 255, 0.3);
    border-radius: 12px;
    color: var(--color-text-primary, #fff);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.theory-widget-button:hover {
    background: linear-gradient(135deg, rgba(139, 127, 255, 0.25), rgba(157, 143, 255, 0.25));
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(139, 127, 255, 0.25);
}

.theory-icon {
    font-size: 1.25rem;
}

.theory-count {
    background: var(--color-primary, #8b7fff);
    padding: 0.125rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.875rem;
    font-weight: 600;
    color: white;
}

/* ============================================
   THEORY LOGIN BUTTON
   ============================================ */

.theory-login-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    background: rgba(139, 127, 255, 0.15);
    border: 1px solid rgba(139, 127, 255, 0.3);
    border-radius: 10px;
    color: var(--color-text-primary, #fff);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.theory-login-btn:hover {
    background: rgba(139, 127, 255, 0.25);
    border-color: rgba(139, 127, 255, 0.5);
}

.theory-login-link {
    color: var(--color-primary, #8b7fff);
    background: none;
    border: none;
    cursor: pointer;
    text-decoration: underline;
    font-size: inherit;
    padding: 0;
    font-family: inherit;
}

.theory-login-link:hover {
    color: var(--color-secondary, #ff7eb6);
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */

@media (max-width: 768px) {
    .user-menu-trigger {
        padding: 0.25rem 0.5rem 0.25rem 0.25rem;
    }

    .user-menu-trigger span:not(.dropdown-indicator) {
        display: none;
    }

    .user-menu-trigger img {
        width: 32px;
        height: 32px;
    }

    .dropdown-indicator {
        margin-left: 0.125rem;
    }

    .user-dropdown-menu {
        width: calc(100vw - 2rem);
        max-width: var(--dropdown-width);
        right: -0.5rem;
    }

    .auth-modal-content {
        padding: 1.5rem;
    }

    .auth-modal-title {
        font-size: 1.5rem;
    }
}

@media (max-width: 480px) {
    .user-dropdown-menu {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-width: none;
        border-radius: 20px 20px 0 0;
        transform-origin: bottom center;
        padding: 1rem;
    }

    .user-dropdown-menu.show {
        transform: translateY(0);
    }

    .user-dropdown-header {
        padding: 1rem;
    }

    .dropdown-avatar {
        width: 52px;
        height: 52px;
    }

    .user-dropdown-item {
        padding: 1rem;
    }
}

/* ============================================
   ACCESSIBILITY
   ============================================ */

@media (prefers-reduced-motion: reduce) {
    .user-menu-trigger,
    .user-dropdown-menu,
    .user-dropdown-item,
    .auth-modal-content,
    .dropdown-indicator {
        transition: none;
    }
}

/* Focus styles for keyboard navigation */
.user-menu-trigger:focus-visible,
.user-dropdown-item:focus-visible,
button:focus-visible,
a:focus-visible,
input:focus-visible {
    outline: 3px solid var(--color-primary, #8b7fff);
    outline-offset: 2px;
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .user-menu-trigger {
        border: 2px solid var(--color-text-primary, #f8f9fa);
    }

    .user-dropdown-menu {
        border: 2px solid var(--color-text-primary, #f8f9fa);
    }

    .user-dropdown-item:hover {
        outline: 2px solid var(--color-text-primary, #f8f9fa);
        outline-offset: -2px;
    }
}

/* ============================================
   LOADING STATES
   ============================================ */

.user-menu-trigger.loading,
.user-dropdown-signout.loading {
    opacity: 0.7;
    cursor: wait;
}

.user-dropdown-signout.loading svg {
    animation: spin 1s linear infinite;
}

/* ============================================
   SKELETON LOADING (When user data loads)
   ============================================ */

.user-info.loading .user-menu-trigger {
    pointer-events: none;
}

.user-info.loading .user-menu-trigger img,
.user-info.loading .user-menu-trigger span:not(.dropdown-indicator) {
    background: linear-gradient(
        90deg,
        rgba(139, 127, 255, 0.1) 0%,
        rgba(139, 127, 255, 0.2) 50%,
        rgba(139, 127, 255, 0.1) 100%
    );
    background-size: 200% 100%;
    animation: skeleton-pulse 1.5s ease-in-out infinite;
}

@keyframes skeleton-pulse {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}
