/*
 * Simplified Leaderboard CSS
 * Optimizes desktop and mobile experience with cleaner layout
 * P3 UX Fix: Addresses leaderboard complexity issues
 */

/* Base Styles */
:root {
    --card-bg: #ffffff;
    --card-border: #e0e0e0;
    --primary: #0d6efd;
    --primary-dark: #0a58ca;
    --primary-light: #e7f1ff;
    --success: #28a745;
    --warning: #ffc107;
    --danger: #dc3545;
    --text-muted: #3a4047; /* Improved contrast ratio 8.41:1 for WCAG AAA */
    --gold: #FFD700;
    --silver: #C0C0C0;
    --bronze: #CD7F32;
}

/* Dark mode support - using html.dark-mode class (not system preference) */
html.dark-mode {
    --card-bg: #1a1a1a;
    --card-border: #333;
    --primary-light: #0a2540;
    --text-muted: #adb5bd; /* Lighter for dark mode while maintaining contrast */
}

/* Ensure text-muted uses our improved contrast colors */
.text-muted {
    color: var(--text-muted) !important;
}

html.dark-mode .text-muted,
[data-bs-theme="dark"] .text-muted {
    color: #adb5bd !important;
}

/* Desktop Leaderboard Styles */
.leaderboard-container {
    max-width: 1200px;
    margin: 0 auto;
}

.leaderboard-entry {
    display: flex;
    align-items: center;
    padding: 1rem;
    margin-bottom: 0.5rem;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    transition: all 0.3s ease;
    position: relative;
}

.leaderboard-entry:hover {
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    transform: translateY(-1px);
}

/* Rank Column */
.rank-column {
    flex: 0 0 80px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.rank-number {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--text-muted);
}

.rank-medal {
    font-size: 1.5rem;
}

/* Participant Column */
.participant-column {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 1rem;
    min-width: 0; /* Allow text truncation */
}

.participant-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
    background: var(--primary-light);
    flex-shrink: 0;
}

.participant-name {
    font-weight: 600;
    font-size: 1.1rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Points Column */
.points-column {
    flex: 0 0 150px;
    text-align: right;
    display: flex;
    align-items: baseline;
    justify-content: flex-end;
    gap: 0.25rem;
}

.points-large {
    font-size: 1.75rem;
    font-weight: bold;
    color: var(--primary);
}

.points-label {
    font-size: 0.875rem;
    color: var(--text-muted);
    font-weight: normal;
}

/* Catches Column */
.catches-column {
    flex: 0 0 120px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Actions Column */
.actions-column {
    flex: 0 0 50px;
    text-align: center;
}

.expand-btn {
    background: none;
    border: 1px solid var(--card-border);
    border-radius: 4px;
    padding: 0.25rem 0.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--text-muted);
}

.expand-btn:hover {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
}

.expand-btn i {
    transition: transform 0.3s ease;
}

.expand-btn.expanded i {
    transform: rotate(180deg);
}

/* Expandable Details */
.leaderboard-details {
    background: var(--primary-light);
    border-top: 1px solid var(--card-border);
    margin: 0 -1rem -1rem;
    padding: 1rem;
    border-radius: 0 0 8px 8px;
    display: none;
}

.leaderboard-details.show {
    display: block;
}

.detail-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.detail-label {
    font-weight: 600;
    color: var(--text-muted);
    min-width: 100px;
}

.detail-value {
    flex: 1;
}

/* Top 3 Special Styling */
.leaderboard-entry[data-rank="1"] {
    background: linear-gradient(135deg, rgba(255, 215, 0, 0.1) 0%, rgba(255, 165, 0, 0.1) 100%);
    border-color: var(--gold);
    border-width: 2px;
}

.leaderboard-entry[data-rank="2"] {
    background: linear-gradient(135deg, rgba(192, 192, 192, 0.1) 0%, rgba(168, 168, 168, 0.1) 100%);
    border-color: var(--silver);
    border-width: 2px;
}

.leaderboard-entry[data-rank="3"] {
    background: linear-gradient(135deg, rgba(205, 127, 50, 0.1) 0%, rgba(184, 115, 51, 0.1) 100%);
    border-color: var(--bronze);
    border-width: 2px;
}

/* Current User Highlighting */
.leaderboard-entry.current-user {
    border: 2px solid var(--primary);
    background: var(--primary-light);
    box-shadow: 0 2px 8px rgba(13, 110, 253, 0.15);
}

/* Sticky User Rank Badge */
.your-rank-sticky {
    position: sticky;
    top: 70px;
    z-index: 100;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    animation: slideDown 0.5s ease-out;
}

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

.rank-badge-content {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.rank-info {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
}

.rank-label {
    font-size: 0.875rem;
    opacity: 0.9;
}

.rank-number-badge {
    font-size: 1.5rem;
    font-weight: bold;
}

.rank-stats {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    text-align: right;
}

.rank-stats small {
    opacity: 0.9;
}

.jump-to-rank-btn {
    padding: 0.375rem 0.75rem;
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 4px;
    color: white;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    font-size: 0.875rem;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

.jump-to-rank-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-1px);
}

/* Filter Bar */
.leaderboard-filters {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1.5rem;
}

.filter-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
    justify-content: space-between;
}

.filter-group {
    display: flex;
    gap: 0.5rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none; /* Hide scrollbar for Firefox */
}

.filter-group::-webkit-scrollbar {
    display: none; /* Hide scrollbar for Chrome, Safari, Edge */
}

.filter-btn {
    padding: 0.5rem 1rem;
    background: white;
    border: 1px solid var(--card-border);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.9rem;
}

.filter-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.filter-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.filter-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    background: #f8f9fa;
}

.filter-btn:disabled:hover {
    border-color: var(--card-border);
    color: inherit;
}

.sort-select {
    padding: 0.5rem 1rem;
    border: 1px solid var(--card-border);
    border-radius: 6px;
    font-size: 0.9rem;
    min-width: 150px;
}

/* Load More Button */
.load-more-container {
    text-align: center;
    margin: 2rem 0;
}

.load-more-btn {
    padding: 0.75rem 2rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.load-more-btn:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

.load-more-btn.loading {
    opacity: 0.7;
    pointer-events: none;
}

.load-more-btn .spinner {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Mobile Styles */
@media (max-width: 767px) {
    /* Mobile Card Layout */
    .leaderboard-entry {
        flex-direction: row;
        padding: 0.75rem;
        margin-bottom: 0.75rem;
        position: relative;
    }

    .rank-column {
        flex: 0 0 50px;
        padding-right: 0.5rem;
        border-right: 2px solid var(--card-border);
    }

    .rank-number {
        font-size: 1.25rem;
    }

    .rank-medal {
        font-size: 1.25rem;
    }

    .participant-column {
        flex: 1;
        padding: 0 0.75rem;
        gap: 0.5rem;
    }

    .participant-avatar {
        width: 36px;
        height: 36px;
    }

    .participant-name {
        font-size: 0.95rem;
    }

    .points-column {
        flex: 0 0 auto;
        flex-direction: column;
        align-items: flex-end;
    }

    .points-large {
        font-size: 1.25rem;
    }

    .points-label {
        font-size: 0.75rem;
    }

    /* Hide catches column on mobile - show in expand */
    .catches-column {
        display: none;
    }

    /* Actions column smaller on mobile */
    .actions-column {
        flex: 0 0 40px;
    }

    .expand-btn {
        padding: 0.25rem;
        font-size: 0.875rem;
    }

    /* Mobile sticky badge - Fixed to avoid bottom nav conflict */
    .your-rank-sticky {
        top: 60px; /* Account for mobile header */
        z-index: 1030; /* Below modals but above content */
        padding: 0.75rem;
        margin-bottom: 1rem;
    }

    /* Push up if mobile nav exists */
    body:has(.mobile-bottom-nav) .your-rank-sticky,
    body.has-mobile-nav .your-rank-sticky {
        bottom: 70px; /* Above mobile nav */
        top: auto;
        position: fixed; /* Change from sticky to fixed */
    }

    .rank-badge-content {
        gap: 0.5rem;
    }

    .rank-number-badge {
        font-size: 1.25rem;
    }

    .rank-stats {
        font-size: 0.8rem;
    }

    .jump-to-rank-btn {
        padding: 0.25rem 0.5rem;
        font-size: 0.75rem;
        width: 100%;
        justify-content: center;
        margin-top: 0.5rem;
    }

    /* Mobile filter controls */
    .filter-controls {
        flex-direction: column;
        gap: 0.75rem;
    }

    .filter-group {
        width: 100%;
        overflow-x: auto;
        padding-bottom: 0.25rem;
    }

    .filter-btn {
        padding: 0.375rem 0.75rem;
        font-size: 0.875rem;
        white-space: nowrap;
        flex-shrink: 0; /* Prevent buttons from shrinking */
    }

    .sort-select {
        width: 100%;
        padding: 0.625rem;
    }

    /* Expandable details mobile */
    .leaderboard-details {
        padding: 0.75rem;
        margin: 0.5rem -0.75rem -0.75rem;
        font-size: 0.875rem;
    }

    .detail-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.25rem;
    }

    .detail-label {
        min-width: auto;
        font-size: 0.75rem;
    }
}

/* Tablet adjustments */
@media (min-width: 768px) and (max-width: 991px) {
    .rank-column {
        flex: 0 0 70px;
    }

    .participant-avatar {
        width: 42px;
        height: 42px;
    }

    .points-large {
        font-size: 1.5rem;
    }

    .catches-column {
        flex: 0 0 100px;
        font-size: 0.85rem;
    }
}

/* Animation for rank changes */
.rank-change-up {
    animation: rankUp 1s ease;
}

.rank-change-down {
    animation: rankDown 1s ease;
}

@keyframes rankUp {
    0% {
        background-color: transparent;
    }
    50% {
        background-color: rgba(40, 167, 69, 0.2);
        transform: translateX(5px);
    }
    100% {
        background-color: transparent;
        transform: translateX(0);
    }
}

@keyframes rankDown {
    0% {
        background-color: transparent;
    }
    50% {
        background-color: rgba(220, 53, 69, 0.2);
        transform: translateX(-5px);
    }
    100% {
        background-color: transparent;
        transform: translateX(0);
    }
}

/* Points update animation */
.points-update {
    animation: pointsPulse 0.6s ease;
}

@keyframes pointsPulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.15);
        color: var(--success);
    }
}

/* Loading skeleton */
.leaderboard-skeleton {
    display: flex;
    align-items: center;
    padding: 1rem;
    margin-bottom: 0.5rem;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 8px;
}

.skeleton-item {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
    border-radius: 4px;
}

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

.skeleton-rank {
    width: 40px;
    height: 40px;
    margin-right: 1rem;
}

.skeleton-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    margin-right: 1rem;
}

.skeleton-name {
    width: 150px;
    height: 20px;
    margin-right: auto;
}

.skeleton-points {
    width: 80px;
    height: 30px;
}