/* Leaderboard page styles */

/* Main leaderboard layout */
.leaderboard-content {
    animation: fadeIn 0.3s ease;
}

/* Filters */
.leaderboard-filters {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: var(--space-4);
    margin-bottom: var(--space-6);
    padding: var(--space-4);
    background-color: var(--bg-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.time-period-selector,
.category-selector {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.filter-select {
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius);
    font-size: var(--text-sm);
    background-color: var(--bg-white);
    color: var(--text-dark);
}

/* Winners Podium */
.winners-podium {
    display: flex;
    justify-content: center;
    align-items: flex-end;
    margin-bottom: var(--space-8);
    padding: var(--space-4) 0;
    position: relative;
}

.winner {
    background-color: var(--bg-white);
    border-radius: var(--radius-lg);
    padding: var(--space-4);
    text-align: center;
    position: relative;
    box-shadow: var(--shadow);
    transition: transform 0.3s ease;
    z-index: 1;
}

.winner:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-lg);
}

.winner-position {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: -15px;
    left: 50%;
    transform: translateX(-50%);
    font-weight: bold;
    box-shadow: var(--shadow-sm);
    z-index: 2;
}

.first-place {
    padding-top: var(--space-6);
    height: 240px;
    width: 180px;
    margin: 0 var(--space-3);
    z-index: 3;
    border: 2px solid gold;
}

.first-place .winner-position {
    background-color: gold;
    color: var(--text-dark);
    width: 40px;
    height: 40px;
    font-size: var(--text-lg);
}

.first-place .winner-crown {
    position: absolute;
    top: -28px;
    left: 50%;
    transform: translateX(-50%);
    color: gold;
    font-size: 32px;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
    z-index: 3;
}

.second-place {
    height: 220px;
    width: 160px;
    padding-top: var(--space-5);
    z-index: 2;
    border: 2px solid silver;
}

.second-place .winner-position {
    background-color: silver;
    color: var(--text-dark);
}

.third-place {
    height: 200px;
    width: 160px;
    padding-top: var(--space-5);
    z-index: 1;
    border: 2px solid #cd7f32; /* bronze */
}

.third-place .winner-position {
    background-color: #cd7f32;
    color: white;
}

.winner-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    overflow: hidden;
    margin: 0 auto var(--space-3);
    border: 2px solid white;
    box-shadow: var(--shadow-sm);
}

.first-place .winner-avatar {
    width: 100px;
    height: 100px;
}

.winner-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.winner-info h3 {
    margin-bottom: var(--space-1);
    font-size: var(--text-lg);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.first-place .winner-info h3 {
    font-size: var(--text-xl);
}

.winner-username {
    color: var(--text-medium);
    margin-bottom: var(--space-2);
    font-size: var(--text-sm);
}

.winner-points {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-1);
    font-weight: 600;
    color: var(--primary-color);
}

.first-place .winner-points {
    font-size: var(--text-lg);
}

/* Rankings Section */
.rankings-section {
    background-color: var(--bg-white);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    margin-bottom: var(--space-6);
    box-shadow: var(--shadow-sm);
}

.rankings-section h2 {
    margin-bottom: var(--space-4);
}

.rankings-table-container {
    overflow-x: auto;
    margin-bottom: var(--space-4);
}

.rankings-table {
    width: 100%;
    border-collapse: collapse;
}

.rankings-table th {
    text-align: left;
    padding: var(--space-3) var(--space-4);
    border-bottom: 2px solid var(--border-medium);
    font-weight: 600;
    color: var(--text-dark);
}

.rankings-table td {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border-light);
}

.rankings-table tr:last-child td {
    border-bottom: none;
}

.rankings-table tr:hover {
    background-color: var(--bg-light);
}

/* Current user row highlighting */
.rankings-table tr.current-user {
    background-color: var(--primary-light);
}

.rankings-table tr.current-user:hover {
    background-color: var(--primary-light);
}

/* User column styling */
.user-cell {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.user-cell .avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
}

.user-cell .user-details {
    display: flex;
    flex-direction: column;
}

.user-cell .username {
    font-size: var(--text-xs);
    color: var(--text-medium);
}

/* Rank styling */
.rank-cell {
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

/* Medal icons for top ranks */
.rank-medal {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: var(--text-xs);
}

.rank-1 {
    background-color: gold;
}

.rank-2 {
    background-color: silver;
}

.rank-3 {
    background-color: #cd7f32; /* bronze */
}

/* Points styling */
.points-cell {
    font-weight: 600;
    color: var(--primary-color);
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: var(--space-4);
    margin-top: var(--space-4);
}

.pagination-btn {
    padding: var(--space-2) var(--space-4);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius);
    background-color: var(--bg-white);
    color: var(--text-dark);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    transition: all 0.2s ease;
}

.pagination-btn:hover:not(:disabled) {
    background-color: var(--primary-light);
    border-color: var(--primary-color);
}

.pagination-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#page-info {
    color: var(--text-medium);
}

/* User Rank Section */
.user-rank-section {
    margin-bottom: var(--space-6);
}

.user-rank-card {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-4);
    background-color: var(--bg-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border-left: 4px solid var(--primary-color);
}

.user-rank-indicator {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background-color: var(--primary-color);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: var(--text-xl);
    font-weight: 600;
    flex-shrink: 0;
}

.user-rank-details {
    flex: 1;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: var(--space-4);
}

.user-info {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.user-info img {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
}

.user-info h3 {
    margin-bottom: var(--space-1);
}

.user-info p {
    color: var(--text-medium);
    font-size: var(--text-sm);
}

.user-stats {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-4);
}

.stat {
    display: flex;
    flex-direction: column;
    min-width: 110px;
}

.stat-label {
    font-size: var(--text-xs);
    color: var(--text-medium);
    margin-bottom: var(--space-1);
}

.stat-value {
    font-size: var(--text-lg);
    font-weight: 600;
    color: var(--text-dark);
}

.next-rank .stat-value {
    color: var(--primary-color);
}

/* Info Section */
.info-section {
    margin-bottom: var(--space-8);
}

.info-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: var(--space-4);
}

.info-card {
    background-color: var(--bg-white);
    padding: var(--space-4);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    display: flex;
    gap: var(--space-4);
}

.info-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius);
    background-color: var(--primary-light);
    color: var(--primary-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--text-xl);
    flex-shrink: 0;
}

.info-content h3 {
    margin-bottom: var(--space-2);
    font-size: var(--text-lg);
}

.info-content p {
    color: var(--text-medium);
    font-size: var(--text-sm);
    line-height: 1.5;
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-8);
    text-align: center;
    background-color: var(--bg-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.empty-state i {
    font-size: 64px;
    color: var(--text-light);
    margin-bottom: var(--space-4);
}

.empty-state h2 {
    margin-bottom: var(--space-3);
}

.empty-state p {
    margin-bottom: var(--space-6);
    color: var(--text-medium);
    max-width: 400px;
}

/* Login Required State */
.login-required {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-8);
    text-align: center;
    background-color: var(--bg-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.login-required i {
    font-size: 64px;
    color: var(--text-light);
    margin-bottom: var(--space-4);
}

.login-required h2 {
    margin-bottom: var(--space-3);
}

.login-required p {
    margin-bottom: var(--space-6);
    color: var(--text-medium);
    max-width: 500px;
}

.login-buttons {
    display: flex;
    gap: var(--space-3);
}

/* Loading Indicator */
.loading-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-8);
    text-align: center;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(0, 0, 0, 0.1);
    border-radius: 50%;
    border-top: 4px solid var(--primary-color);
    animation: spin 1s linear infinite;
    margin-bottom: var(--space-4);
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes fadeIn {
    0% { opacity: 0; }
    100% { opacity: 1; }
}

/* Permission Error Styling */
.permission-error {
    background-color: #FFF5F5;
    border-left: 4px solid var(--error);
}

.permission-error i {
    color: var(--error);
}

.error-instructions {
    background-color: rgba(0, 0, 0, 0.05);
    padding: var(--space-4);
    border-radius: var(--radius);
    text-align: left;
    margin: var(--space-4) 0;
    max-width: 600px;
}

.error-instructions ol {
    margin-left: var(--space-4);
    padding-left: var(--space-4);
}

.error-instructions li {
    margin-bottom: var(--space-2);
}

/* Responsive Adjustments */
@media (max-width: 900px) {
    .winners-podium {
        flex-direction: column;
        align-items: center;
        gap: var(--space-6);
    }
    
    .first-place, .second-place, .third-place {
        width: 180px;
        height: auto;
        order: unset;
    }
    
    .first-place {
        order: 1;
    }
    
    .second-place {
        order: 2;
    }
    
    .third-place {
        order: 3;
    }

    .user-rank-card {
        flex-direction: column;
        text-align: center;
    }
    
    .user-rank-details {
        flex-direction: column;
        align-items: center;
    }
    
    .user-stats {
        justify-content: center;
    }
}

@media (max-width: 768px) {
    .leaderboard-filters {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .info-cards {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .user-rank-details {
        flex-direction: column;
        gap: var(--space-4);
    }
    
    .pagination {
        flex-direction: column;
        gap: var(--space-2);
    }
}

/* --- TOGGLE SWITCH (Users vs Channels) --- */
.leaderboard-toggle-container {
    display: flex;
    justify-content: center;
    margin-bottom: 25px;
    gap: 15px;
}

.lb-toggle-btn {
    background: var(--bg-white, #fff);
    border: 1px solid var(--border-light, #ddd);
    color: var(--text-medium, #666);
    padding: 10px 24px;
    border-radius: 30px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

.lb-toggle-btn.active {
    background: var(--primary-color, #10B981);
    color: #fff;
    border-color: var(--primary-color, #10B981);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
    transform: translateY(-2px);
}

.lb-toggle-btn:hover:not(.active) {
    background: var(--bg-light, #f9fafb);
    transform: translateY(-1px);
}

/* --- CHANNEL SPECIFIC STYLES --- */
.channel-subs-badge {
    background-color: rgba(16, 185, 129, 0.1);
    color: var(--primary-color, #10B981);
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.join-channel-btn-sm {
    padding: 6px 14px;
    font-size: 0.8rem;
    border-radius: 20px;
    text-decoration: none;
    background: var(--channel-bg, #f3f4f6);
    color: var(--text-dark, #333);
    border: 1px solid var(--border-medium, #ddd);
    transition: 0.2s;
}

.join-channel-btn-sm:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* --- CHANNEL LEADERBOARD UPDATES --- */

/* 1. Row Hover Effects (Light & Dark Mode) */
#channel-rows tr {
    transition: all 0.2s ease-in-out;
    cursor: pointer;
    border-left: 3px solid transparent; /* Prepare for hover accent */
}

/* Light Mode Hover */
#channel-rows tr:hover {
    background-color: rgba(0, 0, 0, 0.04); /* Subtle gray tint */
    transform: translateX(4px); /* Slight movement to right */
    border-left-color: var(--primary-color);
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

/* Dark Mode Hover Override */
[data-theme="dark"] #channel-rows tr:hover {
    background-color: rgba(255, 255, 255, 0.08); /* Subtle white tint */
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

/* 2. Channel Podium Specifics */
.channel-subs-badge {
    margin-top: 5px;
    display: inline-block;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--primary-color);
    background: rgba(16, 185, 129, 0.1);
    padding: 2px 8px;
    border-radius: 10px;
}

/* Make Podium Cards Clickable */
#ch-first, #ch-second, #ch-third {
    cursor: pointer;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

#ch-first:hover, #ch-second:hover, #ch-third:hover {
    transform: translateY(-8px) scale(1.02);
}

/* Better Row Highlighting */
.channel-row-item {
    cursor: pointer;
    transition: background 0.2s;
}

.channel-row-item:hover {
    background-color: rgba(16, 185, 129, 0.08) !important; /* Primary color tint */
}

[data-theme="dark"] .channel-row-item:hover {
    background-color: rgba(255, 255, 255, 0.05) !important;
}

/* Action Button Style */
.join-channel-btn-sm {
    padding: 6px 12px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.8rem;
    cursor: pointer;
}

.join-channel-btn-sm:hover {
    filter: brightness(1.1);
}

.channel-subs-badge {
    font-size: 0.85rem;
    font-weight: bold;
    color: var(--primary-color);
    margin-top: 4px;
}

/* --- LEADERBOARD TOGGLE SWITCH --- */
.lb-toggle-container {
    display: flex; justify-content: center; margin: 20px 0;
}

.lb-toggle-wrapper {
    background: var(--surface-alt, #e5e7eb);
    padding: 5px;
    border-radius: 30px;
    display: flex;
    position: relative;
    width: 300px; /* Adjust width */
    height: 50px;
    box-shadow: inset 0 2px 5px rgba(0,0,0,0.05);
}

.lb-toggle-option {
    flex: 1;
    z-index: 2;
    text-align: center;
    line-height: 40px;
    font-weight: 600;
    cursor: pointer;
    color: var(--text-secondary);
    transition: color 0.3s ease;
    user-select: none;
}

.lb-toggle-option.active {
    color: var(--primary-color); /* Or White if slider is solid color */
    color: #fff;
}

.lb-toggle-slider {
    position: absolute;
    top: 5px; bottom: 5px; left: 5px;
    width: calc(50% - 5px);
    background: var(--primary-color, #10B981);
    border-radius: 25px;
    transition: transform 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
    z-index: 1;
    box-shadow: 0 2px 10px rgba(16, 185, 129, 0.3);
}

/* Sliding Logic */
.lb-toggle-wrapper[data-state="channels"] .lb-toggle-slider {
    transform: translateX(100%);
}
/* --- Leaderboard user modal --- */
.lb-modal { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; z-index: 9999; }
.lb-modal.show { display: flex; }
.lb-modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.55); backdrop-filter: blur(3px); }
.lb-modal-card { position: relative; z-index: 10; width: 92%; max-width: 420px; border-radius: 16px; padding: 22px; background: var(--surface-color); box-shadow: 0 20px 40px rgba(0,0,0,0.25); text-align: center; }
.lb-modal-close { position: absolute; top: 12px; right: 12px; background: transparent; border: none; font-size: 1.2rem; cursor:pointer; color: var(--text-secondary); }
.lb-modal-avatar { width: 96px; height: 96px; border-radius: 50%; object-fit: cover; border: 3px solid var(--primary-color); margin-bottom: 10px; }
.lb-stats { display: grid; grid-template-columns: repeat(3,1fr); gap: 12px; margin: 14px 0; }
.lb-stat { font-size: 0.9rem; }
.lb-stat > div:first-child { font-weight:600; opacity: .85; font-size: .75rem; text-transform:uppercase; }
.lb-stat > div:last-child { font-weight:700; font-size:1.1rem; margin-top:4px; }
.lb-modal-actions { margin-top: 12px; }


/* ADD TO styles/leaderboard.css */

.profile-popup {
    position: fixed;
    inset: 0;
    display: none; /* Hidden by default */
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.profile-popup.active {
    display: flex !important; /* Force flex when active */
}

.profile-popup-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
}

.profile-popup-card {
    position: relative;
    background: var(--surface-color, #fff); /* Fallback to white */
    width: 90%;
    max-width: 350px;
    border-radius: 24px;
    padding: 30px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    text-align: center;
    animation: popupPop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popupPop {
    from { transform: scale(0.9); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.profile-avatar {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    border: 4px solid #10B981; /* Primary color */
    margin-bottom: 15px;
    object-fit: cover;
}

.profile-name {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 5px;
}

.profile-meta {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 15px;
    font-size: 0.9rem;
    text-align: left;
    background: rgba(0,0,0,0.03);
    padding: 15px;
    border-radius: 12px;
}

.profile-bio {
    grid-column: 1 / -1;
    text-align: center;
    font-style: italic;
}

.profile-popup-close {
    position: absolute;
    top: 15px;
    right: 15px;
    background: transparent;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
}

#profile-bio-text{
    color: white;
    font-weight: 300;
    font-style: normal;
    font-size: 15px;
}

/* --- FIX: Custom Toggle Dark Mode Visibility --- */
[data-theme="dark"] .lb-toggle-wrapper {
    background-color: #1f2937 !important; /* Dark background for the pill */
    border: 1px solid #374151;
}

[data-theme="dark"] .lb-toggle-option {
    color: #9ca3af !important; /* Muted grey for unselected text */
}

[data-theme="dark"] .lb-toggle-option.active {
    color: #ffffff !important; /* Pure white for the selected text */
}

[data-theme="dark"] .lb-toggle-slider {
    background-color: #10B981; /* Ensure the moving green slider stays green */
}