/* CSS Variables */
:root {
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.1);
  --border-color: #e0e0e0;
  --text-primary: #2c3e50;
  --primary-main: #1a237e;
}

/* Base Styles - These will apply regardless of context */
[class*="leaderboard"],
.leaderboard-main,
#affliatecontainer {
  position: relative;
  margin: 1rem 0 2rem;
  overflow-x: hidden; /* Prevent horizontal scroll on main container */
}

/* Remove box styles from main container */
#affliatecontainer {
  background: transparent;
  box-shadow: none;
  border-radius: 0;
  overflow: visible;
}

/* Add box styles to content container */
.leaderboard-content {
  background: white;
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
  margin-top: -2rem;
  position: relative;
  z-index: 1;
  width: 100%;
}

/* Table wrapper to handle scrolling */
.table-wrapper {
  overflow-x: auto;
  margin: 0;
  padding: 0;
  width: 100%;
  border-radius: 12px;
}

/* Sports Filter - Target by structure rather than just class */
[class*="sports-fliters"],
div:has(> #sportlist) {
  margin: 1.5rem 1.5rem 2rem;
  display: flex;
  align-items: center;
}

/* Ensure only one filter shows */
.leaderboard-content [class*="sports-fliters"],
#affliatecontainer [class*="sports-fliters"] {
  display: none;
}

/* Table Styles - Target any leaderboard table */
table[class*="leaderboard"],
table[class*="affliate"],
.leaderboard-main table,
#affliatecontainer table {
  width: 100% !important;
  border-collapse: collapse !important;
  margin: 0 !important;
  background: white !important;
  box-shadow: none !important;
}

/* Table Headers */
table[class*="leaderboard"] th,
table[class*="affliate"] th,
.leaderboard-main table th,
#affliatecontainer table th {
  background: #f8f9fa !important;
  padding: 12px !important;
  text-align: left !important;
  font-weight: 600 !important;
  border-bottom: 2px solid #dee2e6 !important;
  color: #495057 !important;
}

/* Table Cells */
table[class*="leaderboard"] td,
table[class*="affliate"] td,
.leaderboard-main table td,
#affliatecontainer table td {
  padding: 12px !important;
  border-bottom: 1px solid #e9ecef !important;
  color: #212529 !important;
}

/* Row Hover */
table[class*="leaderboard"] tr:hover,
table[class*="affliate"] tr:hover,
.leaderboard-main table tr:hover,
#affliatecontainer table tr:hover {
  background-color: #f8f9fa !important;
}

/* Profit Colors - More specific selectors */
[class*="green_b"],
.positive,
td:has(> [class*="green_b"]),
td:has(> .positive) {
  color: #28a745 !important;
  font-weight: 500 !important;
}

[class*="red_b"],
.negative,
td:has(> [class*="red_b"]),
td:has(> .negative) {
  color: #dc3545 !important;
  font-weight: 500 !important;
}

/* Modern Sports Filter Styles */
.sports-fliters {
  margin: 1.5rem 1.5rem 2rem;
  display: flex;
  align-items: center;
}

/* Hide the Sports label */
.sports-fliters span {
  display: none;
}

#sportlist {
  appearance: none;
  -webkit-appearance: none;
  padding: 0.75rem 2.5rem 0.75rem 1rem;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: white;
  color: var(--text-primary);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  min-width: 180px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%232c3e50' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 1rem center;
  background-size: 1em;
}

#sportlist:hover {
  border-color: var(--primary-main);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

#sportlist:focus {
  outline: none;
  border-color: var(--primary-main);
  box-shadow: 0 0 0 3px rgba(41, 128, 185, 0.1);
}

#sportlist option {
  padding: 0.5rem;
  font-size: 0.95rem;
}

/* Top Handicappers Container */
.top-handicappers-container {
  background: #f8f9fa;
  border-radius: 16px;
  padding: 2rem 1rem;
  margin: 0 0 4rem;
  width: 100%;
  box-sizing: border-box;
}

.top-handicappers-header {
  text-align: center;
  margin-bottom: 2rem;
}

.top-handicappers-header h2 {
  font-size: 1.8rem;
  color: var(--text-primary);
  margin: 0 0 0.5rem;
  font-weight: 700;
}

.top-handicappers-header p {
  color: #666;
  font-size: 1rem;
  max-width: 600px;
  margin: 0 auto;
}

/* Top Handicappers Section */
.top-handicappers {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5rem;
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.3s ease, transform 0.3s ease;
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.top-handicappers.loaded {
  opacity: 1;
  transform: translateY(0);
}

/* Scope all card styles to .top-handicappers */
.top-handicappers .top-card {
  background: white;
  border-radius: 12px;
  padding: 1.5rem 1.5rem 1.25rem;
  position: relative;
  overflow: visible;
  transition: all 0.3s ease;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  height: auto;
  cursor: pointer;
  margin: 0;
  border: 1px solid rgba(0, 0, 0, 0.1);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
  width: 100%;
  box-sizing: border-box;
  z-index: 1;
}

.top-handicappers .top-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
  border-color: rgba(0, 0, 0, 0.15);
  z-index: 2;
}

/* First Place Card */
.top-handicappers .top-card.first {
  background: white;
  color: var(--text-primary);
  padding: 1.75rem 1.75rem 1.5rem;
  border: none;
  box-shadow: 0 8px 24px rgba(26, 35, 126, 0.15);
  position: relative;
  overflow: hidden;
}

.top-handicappers .top-card.first::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, #FFD700, #FDB931);
}

/* Second Place Card */
.top-handicappers .top-card.second {
  background: white;
  color: var(--text-primary);
  border: 1px solid rgba(0, 0, 0, 0.1);
}

.top-handicappers .top-card.second::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, #C0C0C0, #A5A5A5);
}

/* Third Place Card */
.top-handicappers .top-card.third {
  background: white;
  color: var(--text-primary);
  border: 1px solid rgba(0, 0, 0, 0.1);
}

.top-handicappers .top-card.third::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, #CD7F32, #B36A2C);
}

/* Update rank badge styles */
.top-handicappers .rank-badge {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  font-weight: 600;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  background: white;
  border: 2px solid;
}

.top-handicappers .top-card.first .rank-badge {
  border-color: #FFD700;
  color: #FFD700;
  box-shadow: 0 2px 8px rgba(255, 215, 0, 0.2);
}

.top-handicappers .top-card.second .rank-badge {
  border-color: #C0C0C0;
  color: #C0C0C0;
  box-shadow: 0 2px 8px rgba(192, 192, 192, 0.2);
}

.top-handicappers .top-card.third .rank-badge {
  border-color: #CD7F32;
  color: #CD7F32;
  box-shadow: 0 2px 8px rgba(205, 127, 50, 0.2);
}

/* Update text colors for all cards */
.top-handicappers .handicapper-name {
  color: var(--text-primary);
  font-size: 1.4rem;
  margin: 0;
  padding-right: 2rem;
  font-weight: 700;
  text-decoration: none;
  display: block;
  margin-bottom: 0.25rem;
  transition: opacity 0.2s ease;
}

.top-handicappers .view-profile {
  color: #666;
  font-size: 0.9rem;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  transition: all 0.2s ease;
}

.top-handicappers .view-profile:hover {
  color: var(--primary-main);
}

.top-handicappers .stat-label {
  color: #666;
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.top-handicappers .stat-value {
  color: var(--text-primary);
  font-size: 1.2rem;
  font-weight: 600;
  font-family: 'Roboto Mono', monospace;
}

.top-handicappers .streak {
  background: #f8f9fa;
  border: 1px solid #e9ecef;
  color: #495057;
}

/* Custom streak backgrounds for each place */
.top-handicappers .top-card.first .streak {
  background: rgba(255, 215, 0, 0.08);
  border-color: rgba(255, 215, 0, 0.2);
  color: #000;
}

.top-handicappers .top-card.second .streak {
  background: rgba(192, 192, 192, 0.08);
  border-color: rgba(192, 192, 192, 0.2);
}

.top-handicappers .top-card.third .streak {
  background: rgba(205, 127, 50, 0.08);
  border-color: rgba(205, 127, 50, 0.2);
}

/* Table Cell Avatar Styles */
.handicapper-cell {
  padding: 8px 0;
}

.handicapper-cell .handicapper-content {
  display: flex;
  align-items: center;
  gap: 12px;
}

.handicapper-cell .avatar-wrapper {
  position: relative;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  border: 2px solid #fff;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.handicapper-cell .avatar-placeholder {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
}

.handicapper-cell .handicapper-avatar {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: opacity 0.3s ease;
}

.handicapper-cell .handicapper-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex-grow: 1;
  min-width: 0;
}

.handicapper-cell .handicapper-name {
  color: #2c3e50;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.95rem;
  transition: color 0.2s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
  line-height: 1.4;
}

.handicapper-cell .view-profile {
  font-size: 0.8rem;
  color: #7f8c8d;
  text-decoration: none;
  transition: color 0.2s ease;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Handicapper Profile Section - Scoped to top-handicappers */
.top-handicappers .handicapper-profile {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.25rem;
  position: relative;
  z-index: 1;
}

.top-handicappers .avatar-wrapper {
  position: relative;
  width: 64px;
  height: 64px;
  min-width: 64px;
  min-height: 64px;
  border-radius: 50%;
  overflow: hidden;
  border: 3px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.top-handicappers .avatar-placeholder {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, rgba(255,255,255,0.1) 25%, rgba(255,255,255,0.2) 50%, rgba(255,255,255,0.1) 75%);
  background-size: 200% 100%;
  animation: pulse 1.5s ease-in-out infinite;
}

.top-handicappers .handicapper-avatar {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  transition: opacity 0.3s ease;
}

.top-handicappers .handicapper-info {
  flex-grow: 1;
  min-width: 0;
}

.top-handicappers .handicapper-name:hover {
  opacity: 0.9;
}

.top-handicappers .view-profile i {
  font-size: 0.8rem;
  transition: transform 0.2s ease;
}

.top-handicappers .view-profile:hover i {
  transform: translateX(2px);
}

.top-handicappers .stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-top: 0;
  padding: 0.25rem 0;
  position: relative;
  z-index: 1;
}

.top-handicappers .stat-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.top-handicappers .stat-label i {
  font-size: 0.9rem;
  opacity: 0.9;
}

.top-handicappers .streak {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-size: 1rem;
  margin-top: 0.25rem;
  padding: 0.4rem 0.75rem;
  border-radius: 8px;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  text-align: center;
  position: relative;
  z-index: 1;
}

/* Loading Animation */
@keyframes pulse {
  0% { opacity: 0.6; }
  50% { opacity: 0.8; }
  100% { opacity: 0.6; }
}

.top-handicappers.loading .top-card {
  animation: pulse 1.5s ease-in-out infinite;
}

/* Responsive Styles */
@media (max-width: 1024px) {
  .top-handicappers-container {
    padding: 1.5rem 1rem;
    margin: 0 0 3rem;
  }
  
  .top-handicappers-header h2 {
    font-size: 1.6rem;
  }
}

@media (max-width: 768px) {
  .top-handicappers {
    grid-template-columns: 1fr;
    gap: 1.5rem;
    padding: 0;
  }

  .top-handicappers .top-card {
    width: 100%;
    margin: 0;
  }
  
  .top-handicappers-container {
    padding: 1.5rem 1rem;
    margin: 0 0 2.5rem;
  }
  
  .top-handicappers-header h2 {
    font-size: 1.4rem;
  }
  
  .top-handicappers-header p {
    font-size: 0.95rem;
    padding: 0 1rem;
  }

  /* Increase avatar size for better visibility */
  .top-handicappers .avatar-wrapper {
    width: 72px;
    height: 72px;
    min-width: 72px;
    min-height: 72px;
  }

  /* Adjust text sizes for better readability */
  .top-handicappers .handicapper-name {
    font-size: 1.5rem;
  }

  .top-handicappers .stat-value {
    font-size: 1.3rem;
  }

  .top-handicappers .stat-label {
    font-size: 0.85rem;
  }

  .top-handicappers .streak {
    font-size: 1.1rem;
    padding: 0.5rem 1rem;
  }

  /* Hide less important columns on mobile */
  table[class*="leaderboard"],
  table[class*="affliate"],
  .leaderboard-main table,
  #affliatecontainer table {
    & th:nth-child(3),
    & td:nth-child(3),
    & th:nth-child(4),
    & td:nth-child(4),
    & th:nth-child(7),
    & td:nth-child(7),
    & th:nth-child(8),
    & td:nth-child(8) {
      display: none;
    }
    
    /* Adjust remaining columns */
    & th,
    & td {
      padding: 8px !important;
    }
  }
}

@media (max-width: 480px) {
  .top-handicappers-container {
    padding: 1rem;
    margin: 0 0 2rem;
  }
  
  .top-handicappers .top-card {
    padding: 1.25rem;
  }

  .top-handicappers-header h2 {
    font-size: 1.3rem;
  }
  
  .top-handicappers-header p {
    font-size: 0.9rem;
    padding: 0 0.5rem;
  }

  /* Slightly reduce sizes for very small screens */
  .top-handicappers .avatar-wrapper {
    width: 64px;
    height: 64px;
    min-width: 64px;
    min-height: 64px;
  }

  .top-handicappers .handicapper-name {
    font-size: 1.3rem;
  }

  .top-handicappers .stat-value {
    font-size: 1.2rem;
  }
}

/* Add hover effect styles */
.top-handicappers .top-card::before {
  display: none;
}

/* Loading States */
.leaderboard-loading {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.95);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.loading-spinner {
  width: 50px;
  height: 50px;
  border: 3px solid #f3f3f3;
  border-top: 3px solid var(--primary-main);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 1rem;
}

.loading-text {
  color: var(--primary-main);
  font-size: 1.2rem;
  font-weight: 500;
}

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

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

/* Remove duplicate borders */
.leaderboard-content > div:not(:first-child) {
  border-top: none !important;
}

.leaderboard-content > div:not(:last-child) {
  border-bottom: none !important;
}

/* Clean up nested containers */
.leaderboard-content > div {
  border: none !important;
  box-shadow: none !important;
  background: transparent !important;
}

/* Remove the padding-top */
.leaderboard-content {
  margin-top: -2rem;
}
