/* --- Global User Profile Modal (Premium Source of Truth) --- */

/* Unified modal container: force identical look on every page. */
.password-modal,
.global-profile-modal {
    position: fixed !important;
    inset: 0 !important;
    z-index: 2147483647 !important;
    display: none;
    align-items: center !important;
    justify-content: center !important;
    background: var(--th-overlay) !important;
    backdrop-filter: blur(12px) !important;
    padding: 16px !important;
}

/* Modal Content Box */
.password-content.user-profile-content,
.global-profile-modal-content {
    width: 640px !important;
    max-width: 94vw !important;
    max-height: min(90vh, 800px) !important;
    padding: 32px !important;
    display: flex !important;
    flex-direction: column !important;
    box-sizing: border-box !important;
    text-align: left !important;
    border: 1px solid var(--th-modal-border) !important;
    background: var(--th-modal-bg) !important;
    border-radius: var(--radius-lg-global, 20px) !important;
    box-shadow: var(--th-modal-shadow) !important;
    color: var(--th-text) !important;
    overflow-y: auto !important;
    position: relative !important;
}

/* Custom Scrollbar for Modal (Thinner & Low Opacity) */
.password-content.user-profile-content,
.global-profile-modal-content {
    scrollbar-width: thin !important;
    scrollbar-color: var(--th-scrollbar) transparent !important;
}

.password-content.user-profile-content::-webkit-scrollbar,
.global-profile-modal-content::-webkit-scrollbar { 
    width: 5px !important; 
}
.password-content.user-profile-content::-webkit-scrollbar-track,
.global-profile-modal-content::-webkit-scrollbar-track { 
    background: transparent !important; 
}
.password-content.user-profile-content::-webkit-scrollbar-thumb,
.global-profile-modal-content::-webkit-scrollbar-thumb { 
    background: var(--th-scrollbar) !important; 
    border-radius: 10px !important; 
}
.password-content.user-profile-content::-webkit-scrollbar-thumb:hover,
.global-profile-modal-content::-webkit-scrollbar-thumb:hover { 
    background: var(--th-scrollbar-h) !important; 
}

/* Modal Headers */
.password-content h2,
.global-profile-modal-content h2 {
    font-size: 1.5rem;
    margin-bottom: 24px;
    font-weight: 800;
}

/* User Identity Section */
.user-profile-head,
.global-profile-head {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-bottom: 20px;
}

.user-profile-avatar,
.global-profile-avatar {
    width: 80px;
    height: 80px;
    border-radius: 20px;
    border: 2px solid var(--th-border) !important;
    object-fit: cover;
    box-shadow: var(--th-shadow) !important;
}

.user-profile-handle-row,
.user-profile-head-info,
.global-profile-head-info {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.user-profile-handle,
.global-profile-handle {
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: -0.02em;
}

/* Presence Status */
.user-presence,
.global-profile-presence {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    color: var(--muted-global, #94a3b8);
    margin-top: 4px;
}

.presence-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #94a3b8;
}

.status-active .presence-dot,
.status-online .presence-dot { 
    background: #22c55e; 
}

.status-active, .status-online { color: #22c55e; }

/* Stats Grid */
.user-profile-grid,
.global-profile-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 10px !important;
    margin-bottom: 16px !important;
}

.user-profile-item,
.global-profile-grid div {
    background: var(--th-input-bg) !important;
    padding: 12px !important;
    border-radius: 12px !important;
    border: 1px solid var(--th-border) !important;
}

.user-profile-item span,
.global-profile-grid span {
    display: block !important;
    font-size: 0.7rem !important;
    text-transform: uppercase !important;
    font-weight: 700 !important;
    color: var(--muted-global, #94a3b8) !important;
    margin-bottom: 4px !important;
}

.user-profile-item strong,
.global-profile-grid strong {
    font-size: 1rem !important;
    color: var(--text-global, #f1f5f9) !important;
}

/* Profile Action Links (CF, History, etc) */
.user-profile-links,
.global-profile-links {
    display: flex !important;
    gap: 12px !important;
    margin-bottom: 24px !important;
    flex-wrap: wrap !important;
}

.user-profile-links a,
.global-profile-links a {
    flex: 1 !important;
    min-width: 120px !important;
    text-align: center !important;
    padding: 10px 12px !important;
    background: rgba(59, 130, 246, 0.1) !important;
    color: #60a5fa !important;
    border-radius: 14px !important;
    text-decoration: none !important;
    font-weight: 700 !important;
    font-size: 0.85rem !important;
    border: 1px solid rgba(59, 130, 246, 0.2) !important;
    transition: all 0.2s ease !important;
}

.user-profile-links a:hover,
.global-profile-links a:hover {
    background: rgba(59, 130, 246, 0.2) !important;
    transform: translateY(-2px) !important;
    text-decoration: none !important;
}

/* Site-specific Stats Section */
.user-profile-site {
    border-top: 1px solid var(--th-border) !important;
    padding-top: 24px;
}

.user-profile-site h4 {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--muted-global, #94a3b8);
    margin-bottom: 16px;
    font-weight: 700;
}

/* Recent Matches Wrapper */
.user-recent-wrap,
.global-profile-recent-wrap {
    margin-top: 24px !important;
    background: var(--th-input-bg) !important;
    border-radius: 14px !important;
    padding: 16px !important;
    border: 1px solid var(--th-border) !important;
}

.user-recent-title,
.global-profile-recent-title {
    font-size: 0.8rem !important;
    font-weight: 700 !important;
    color: var(--muted-global, #94a3b8) !important;
    margin-bottom: 12px !important;
}

.user-recent-list,
.global-profile-recent-wrap ul {
    list-style: none !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 10px !important;
    padding: 0 !important;
    margin: 0 !important;
}

.user-recent-item,
.global-profile-recent-item {
    font-size: 0.85rem !important;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    padding: 10px !important;
    background: var(--th-subtle-bg) !important;
    border-radius: 14px !important;
    cursor: pointer !important;
    transition: all 0.2s ease !important;
    border: 1px solid transparent !important;
    gap: 12px !important;
}

.user-recent-item:hover,
.global-profile-recent-item:hover {
    background: var(--th-bg2) !important;
    border-color: var(--th-border) !important;
}

.user-recent-outcome {
    min-width: 32px !important;
    height: 32px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: 8px !important;
    font-weight: 800 !important;
    font-size: 0.8rem !important;
    background: var(--th-bg2) !important;
}

.user-recent-outcome.W { color: #22c55e !important; background: rgba(34, 197, 94, 0.1) !important; }
.user-recent-outcome.L { color: #ef4444 !important; background: rgba(239, 68, 68, 0.1) !important; }
.user-recent-outcome.T { color: #3b82f6 !important; background: rgba(59, 130, 246, 0.1) !important; }

.user-recent-main {
    flex: 1 !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 2px !important;
    min-width: 0 !important;
}

.user-recent-opponent {
    font-weight: 700 !important;
    color: var(--text-global, #f1f5f9) !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    display: block !important;
}

.user-recent-date {
    font-size: 0.75rem !important;
    color: var(--muted-global, #94a3b8) !important;
}

.user-recent-score {
    font-weight: 700 !important;
    font-family: monospace !important;
    font-size: 1rem !important;
    color: var(--text-global, #f1f5f9) !important;
    white-space: nowrap !important;
    flex-shrink: 0 !important;
}

.user-recent-rating {
    font-weight: 700 !important;
    font-size: 0.8rem !important;
    color: var(--muted-global, #94a3b8) !important;
}

.user-recent-provisional {
    position: absolute !important;
    top: 8px !important;
    right: 74px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 1px 5px !important;
    border-radius: 999px !important;
    background: rgba(34, 197, 94, 0.12) !important;
    border: 1px solid rgba(34, 197, 94, 0.22) !important;
    color: #22c55e !important;
    font-weight: 700 !important;
    font-size: 0.5rem !important;
    text-transform: uppercase !important;
    letter-spacing: 0.01em !important;
    line-height: 1 !important;
    white-space: nowrap !important;
}

/* Recent Match View Button */
.user-recent-link.view-btn {
    padding: 6px 12px !important;
    background: rgba(59, 130, 246, 0.1) !important;
    color: #60a5fa !important;
    border-radius: 6px !important;
    text-decoration: none !important;
    font-weight: 700 !important;
    font-size: 0.75rem !important;
    border: 1px solid rgba(59, 130, 246, 0.2) !important;
}

.user-recent-link.view-btn:hover {
    background: rgba(59, 130, 246, 0.2) !important;
}

.user-recent-empty,
.global-profile-recent-empty {
    text-align: center !important;
    padding: 20px !important;
    color: var(--muted-global, #94a3b8) !important;
    font-style: italic !important;
}

/* Bottom Action Buttons */
.user-profile-actions,
.global-profile-modal-actions,
.password-buttons {
    display: flex !important;
    gap: 12px !important;
    margin-top: 32px !important;
}

.password-btn,
.global-profile-modal-actions button {
    flex: 1 !important;
    padding: 12px !important;
    border-radius: 14px !important;
    font-weight: 700 !important;
    cursor: pointer !important;
    border: none !important;
    transition: all 0.2s ease !important;
    font-size: 0.9rem !important;
}

.user-profile-logout-btn,
.global-profile-modal-logout {
    background: #ff7d7d !important;
    color: #230505 !important;
}

.user-profile-logout-btn:hover,
.global-profile-modal-logout:hover { background: #ff6b6b !important; transform: translateY(-2px) !important; }

.cancel-btn,
.global-profile-modal-close,
.user-profile-change-password-btn,
.user-profile-settings-btn,
.global-profile-modal-actions .cancel-btn,
.global-profile-modal-actions .global-profile-modal-close,
.global-profile-modal-actions .user-profile-change-password-btn,
.global-profile-modal-actions .user-profile-settings-btn {
    background: var(--th-input-bg) !important;
    color: var(--th-text) !important;
    border: 1px solid var(--th-border) !important;
}

.cancel-btn:hover,
.global-profile-modal-close:hover,
.user-profile-change-password-btn:hover,
.user-profile-settings-btn:hover,
.global-profile-modal-actions .cancel-btn:hover,
.global-profile-modal-actions .global-profile-modal-close:hover,
.global-profile-modal-actions .user-profile-change-password-btn:hover,
.global-profile-modal-actions .user-profile-settings-btn:hover { 
    background: var(--th-bg2) !important; 
    border-color: var(--th-border-hover) !important;
    transform: translateY(-2px) !important; 
}

.confirm-btn:hover { opacity: 0.9 !important; transform: translateY(-2px) !important; }

/* Header Action Buttons Container (Top Right Corner) */
.global-profile-modal-header-actions {
    position: absolute !important;
    top: 24px !important;
    right: 24px !important;
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    z-index: 100 !important;
}

/* Header Buttons (Premium Interaction) */
.global-profile-modal-challenge,
.global-profile-modal-message {
    position: relative !important;
    top: auto !important;
    right: auto !important;
    left: auto !important;
    width: fit-content !important;
    display: inline-flex;
    align-items: center !important;
    justify-content: center !important;
    gap: 8px !important;
    border: none !important;
    padding: 8px 16px !important;
    border-radius: 12px !important;
    font-size: 0.85rem !important;
    font-weight: 800 !important;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1) !important;
    text-transform: uppercase !important;
    letter-spacing: 0.03em !important;
    cursor: pointer !important;
}

.global-profile-modal-challenge {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%) !important;
    color: white !important;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.2) !important;
}

.global-profile-modal-message {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%) !important;
    color: white !important;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.2) !important;
}

.global-profile-modal-challenge:hover,
.global-profile-modal-message:hover {
    transform: translateY(-2px) scale(1.02) !important;
    filter: brightness(1.1);
}

.global-profile-modal-challenge svg,
.global-profile-modal-message svg {
    width: 20px;
    height: 20px;
    stroke-width: 2.5;
}


/* Clickable handle in stats */
.user-stats-handle {
    color: #60a5fa !important;
    text-decoration: none !important;
    font-weight: 600 !important;
    cursor: pointer !important;
}

.user-stats-handle:hover {
    text-decoration: underline !important;
}

/* Opponents Grid and Chips */
.opponents-grid {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
    margin-top: 10px !important;
}

.password-content .opponents-grid,
.global-profile-modal-content .opponents-grid {
    grid-template-columns: repeat(3, 1fr) !important;
}

.opponent-chip {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 6px !important;
    padding: 6px 10px !important;
    background: var(--th-bg2) !important;
    border: 1px solid var(--th-border) !important;
    border-radius: 14px !important;
    font-size: 0.8rem !important;
    transition: all 0.2s ease !important;
    text-decoration: none !important;
    color: inherit !important;
}

.opponent-chip:hover {
    background: var(--th-bg2) !important;
    border-color: #60a5fa !important;
    transform: translateY(-1px) !important;
}

.opponent-chip .user-stats-handle {
    flex: 1 !important;
    min-width: 0 !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
}

.opponent-count {
    background: var(--th-bg2) !important;
    padding: 1px 6px !important;
    border-radius: 4px !important;
    font-size: 0.7rem !important;
    color: var(--muted-global, #94a3b8) !important;
    font-weight: 700 !important;
}

.opponent-more-wrap {
    grid-column: 1 / -1 !important;
    display: flex !important;
    justify-content: center !important;
    margin-top: 4px !important;
}

.opponent-more-link {
    display: inline-flex !important;
    align-items: center !important;
    padding: 6px 16px !important;
    color: #60a5fa !important;
    font-size: 0.85rem !important;
    font-weight: 700 !important;
    text-decoration: none !important;
    background: rgba(59, 130, 246, 0.1) !important;
    border: 1px solid rgba(59, 130, 246, 0.2) !important;
    border-radius: 20px !important;
    transition: all 0.2s ease !important;
}

.opponent-more-link:hover {
    background: rgba(59, 130, 246, 0.2) !important;
    transform: translateY(-1px) !important;
    text-decoration: none !important;
}

/* Skeleton Loading State (Premium Shimmer) */
.skeleton {
    background: linear-gradient(90deg, 
        var(--th-skeleton-bg) 25%, 
        var(--th-skeleton-pulse) 50%, 
        var(--th-skeleton-bg) 75%
    ) !important;
    background-size: 200% 100% !important;
    animation: skeleton-shimmer 1.8s infinite cubic-bezier(0.4, 0, 0.2, 1) !important;
    border: none !important;
    position: relative;
    overflow: hidden;
}

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

.global-profile-modal-error {
    padding: 60px 20px;
    text-align: center;
    color: #ef4444;
    font-weight: 600;
    font-style: italic;
    background: rgba(239, 68, 68, 0.05);
    border-radius: 12px;
    border: 1px solid rgba(239, 68, 68, 0.1);
}

/* ============================================================
   LIGHT THEME CONTRAST & LEGIBILITY OVERRIDES
   ============================================================ */
[data-theme="light"] .user-profile-links a,
[data-theme="light"] .global-profile-links a {
    background: rgba(37, 99, 235, 0.08) !important;
    color: #2563eb !important;
    border: 1px solid rgba(37, 99, 235, 0.18) !important;
}

[data-theme="light"] .user-profile-links a:hover,
[data-theme="light"] .global-profile-links a:hover {
    background: rgba(37, 99, 235, 0.15) !important;
    color: #1d4ed8 !important;
}

[data-theme="light"] .user-stats-handle {
    color: #2563eb !important;
}

[data-theme="light"] .opponent-more-link {
    color: #2563eb !important;
    background: rgba(37, 99, 235, 0.08) !important;
    border: 1px solid rgba(37, 99, 235, 0.18) !important;
}

[data-theme="light"] .opponent-more-link:hover {
    background: rgba(37, 99, 235, 0.15) !important;
    color: #1d4ed8 !important;
}

[data-theme="light"] .user-recent-link.view-btn {
    background: rgba(37, 99, 235, 0.08) !important;
    color: #2563eb !important;
    border: 1px solid rgba(37, 99, 235, 0.18) !important;
}

[data-theme="light"] .user-recent-link.view-btn:hover {
    background: rgba(37, 99, 235, 0.15) !important;
    color: #1d4ed8 !important;
}

[data-theme="light"] .user-recent-outcome.T {
    color: #2563eb !important;
    background: rgba(37, 99, 235, 0.08) !important;
}

[data-theme="light"] .user-profile-item span,
[data-theme="light"] .global-profile-grid span {
    color: #475569 !important;
}


/* ============================================================
   MOBILE RESPONSIVE LAYOUT OVERRIDES (Unified & Robust)
   ============================================================ */
@media (max-width: 767px) {
    .password-content.user-profile-content,
    .global-profile-modal-content {
        padding: 24px 16px 20px 16px !important;
        max-width: 96vw !important;
        max-height: 95vh !important;
        border-radius: 16px !important;
    }
    
    .user-profile-head,
    .global-profile-head {
        gap: 16px !important;
        margin-bottom: 16px !important;
        position: relative !important;
    }
    
    .user-profile-avatar,
    .global-profile-avatar {
        width: 60px !important;
        height: 60px !important;
        border-radius: 12px !important;
    }
    
    .user-profile-handle,
    .global-profile-handle {
        font-size: 1.25rem !important;
    }
    
    /* Ensure the action buttons stack gracefully on mobile and don't overlap details */
    .global-profile-modal-header-actions {
        position: relative !important;
        top: 0 !important;
        right: 0 !important;
        width: 100% !important;
        margin-bottom: 16px !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 8px !important;
    }
    
    .global-profile-modal-challenge,
    .global-profile-modal-message {
        width: 100% !important;
        margin-bottom: 0 !important;
        padding: 10px !important;
        box-sizing: border-box !important;
        justify-content: center !important;
    }
    
    .user-profile-grid,
    .global-profile-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px !important;
    }
    
    .password-content .opponents-grid,
    .global-profile-modal-content .opponents-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px !important;
    }
    
    .user-profile-links,
    .global-profile-links {
        gap: 8px !important;
    }
    
    .user-profile-links a,
    .global-profile-links a {
        min-width: 100px !important;
        font-size: 0.8rem !important;
        padding: 8px 10px !important;
        flex: 1 1 calc(50% - 4px) !important;
    }
}

@media (max-width: 480px) {
    .user-profile-grid,
    .global-profile-grid {
        grid-template-columns: 1fr !important;
    }
    
    .password-content .opponents-grid,
    .global-profile-modal-content .opponents-grid {
        grid-template-columns: 1fr !important;
    }
    
    .user-profile-links a,
    .global-profile-links a {
        flex: 1 1 100% !important;
    }
}


/* ─── Blitz Rating Badge (leaderboard table) ─────────────────────────────── */
.blitz-rating-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-weight: 800;
    font-size: 0.9rem;
    font-family: 'Inter', system-ui, sans-serif;
    white-space: nowrap;
    letter-spacing: -0.01em;
}

.br-rank-label {
    font-size: 0.7rem;
    font-weight: 600;
    opacity: 0.85;
    letter-spacing: 0.02em;
}

/* ─── Blitz Rating Hero Card (profile modal) ─────────────────────────────── */
.blitz-rating-hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 14px 20px;
    border-radius: 12px;
    border: 1px solid;
    margin-bottom: 12px;
    text-align: center;
    transition: all 0.2s ease;
}

.br-hero-rating {
    font-size: 2rem;
    font-weight: 900;
    letter-spacing: -0.04em;
    line-height: 1;
    font-family: 'Inter', system-ui, sans-serif;
}

.br-hero-rank {
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    opacity: 0.9;
}

.br-provisional {
    font-size: 0.72rem;
    font-weight: 500;
    opacity: 0.7;
    text-transform: none;
    letter-spacing: 0;
}
