/* Sync buttons are now visible - styled in tables.css */

/* Default table row styling for dark mode */
#seasonsTable tbody tr:not(.top-3-player) {
  background-color: #2a2e35 !important; /* Slightly lighter than the default dark background */
  transition: background-color 0.2s ease;
}

#seasonsTable tbody tr:not(.top-3-player):hover {
  background-color: #323840 !important; /* Slightly lighter on hover */
}

/* Top 3 Players Styling - Solo contorno */
.top-3-player {
  position: relative;
  transition: all 0.3s ease;
  z-index: 1; /* Ensure top 3 players stay above other rows */
  border: 3px solid transparent !important;
  border-radius: 4px;
}

.top-3-player td:first-child {
  position: relative;
}

/* Oro - Primera posición */
.top-1 {
  border-color: #FFD700 !important;
}

.top-1:hover {
  border-color: #FFC700 !important;
  box-shadow: 0 0 8px rgba(255, 215, 0, 0.4);
}

/* Plata - Segunda posición */
.top-2 {
  border-color: #C0C0C0 !important;
}

.top-2:hover {
  border-color: #B0B0B0 !important;
  box-shadow: 0 0 8px rgba(192, 192, 192, 0.4);
}

/* Bronce - Tercera posición */
.top-3 {
  border-color: #CD7F32 !important;
}

.top-3:hover {
  border-color: #BD6F22 !important;
  box-shadow: 0 0 8px rgba(205, 127, 50, 0.4);
}

/* Player links in tables */
.player-link {
  color: inherit; /* Hereda el color del texto del contenedor padre */
  text-decoration: none;
  font-weight: 500;
  transition: background-color 0.2s ease;
  cursor: pointer;
  display: inline-block;
  padding: 2px 4px;
  border-radius: 3px;
}

.player-link:hover {
  text-decoration: underline;
  background-color: rgba(0, 0, 0, 0.05);
}

/* Ensure the link takes up the full cell height */
td > .player-link {
  display: block;
  width: 100%;
  height: 100%;
  padding: 8px 12px;
  margin: -8px -12px;
}

/* Color legend styles */
.color-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0;
  padding: 8px;
  border-radius: 4px;
  background: var(--legend-bg);
}

.legend-title {
  font-weight: bold;
  margin-right: 5px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.85em;
  position: relative;
  cursor: help;
  padding: 2px 5px;
  border-radius: 3px;
  transition: background-color 0.2s;
}

.legend-item:hover {
  background-color: rgba(0, 0, 0, 0.05);
}

.tooltip-text {
  visibility: hidden;
  width: 220px;
  background-color: #333;
  color: #fff;
  text-align: center;
  border-radius: 4px;
  padding: 8px;
  position: absolute;
  z-index: 10000; /* Ensure above containers */
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  opacity: 0;
  transition: opacity 0.3s;
  font-size: 0.8em;
  box-shadow: 0 2px 5px rgba(0,0,0,0.2);
  white-space: normal;
  line-height: 1.4;
  pointer-events: none;
}

.tooltip-text::after {
  content: "";
  position: absolute;
  bottom: 100%;
  left: 50%;
  margin-left: -5px;
  border-width: 5px;
  border-style: solid;
  border-color: transparent transparent #333 transparent;
  pointer-events: none;
}

.legend-item:hover .tooltip-text {
  visibility: visible;
  opacity: 1;
}

.legend-color {
  display: inline-block;
  width: 16px;
  height: 16px;
  border-radius: 3px;
  border: 1px solid rgba(0, 0, 0, 0.1);
}

.legend-color.green { background-color: #28a745; }
.legend-color.yellow { background-color: #ffc107; }
.legend-color.orange { background-color: #fd7e14; }
.legend-color.red { background-color: #dc3545; }

/* Row highlight colors */
.highlight-green {
  background-color: #28a745 !important;
  color: white !important;
}

.highlight-yellow {
  background-color: #ffc107 !important;
  color: #000 !important;
}

.highlight-orange {
  background-color: #fd7e14 !important;
  color: white !important;
}

.highlight-red {
  background-color: #dc3545 !important;
  color: white !important;
}

/* Estilos generales */
body {
  font-family: Arial, sans-serif;
  margin: 0;
  padding: 0;
  line-height: 1.6;
  color: #333;
  background-color: #f5f5f5;
  overflow-x: hidden; /* Solo prevenir scroll horizontal */
  max-width: 100vw; /* Never exceed viewport width */
  box-sizing: border-box; /* Include margin and padding in width calculation */
}

html {
  overflow-x: hidden; /* Solo prevenir scroll horizontal */
  max-width: 100vw; /* Never exceed viewport width */
  box-sizing: border-box;
}

/* Desktop: permitir scroll de página natural */
@media (min-width: 769px) {
  body {
    height: auto;
    max-height: none;
    overflow-y: auto; /* Scroll vertical normal de la página */
    overflow-x: hidden;
    position: static;
    top: auto;
    left: auto;
    right: auto;
    bottom: auto;
  }
  
  html {
    height: auto;
    max-height: none;
    overflow-y: auto; /* Scroll vertical normal de la página */
    overflow-x: hidden;
    position: static;
    top: auto;
    left: auto;
    right: auto;
    bottom: auto;
  }
}

@media (min-width: 769px) {
  body.clan-welcome,
  html.clan-welcome {
    height: auto !important;
    max-height: none !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    position: static !important;
    top: auto !important;
    left: auto !important;
    right: auto !important;
    bottom: auto !important;
  }
}

/* Mobile: scroll natural */
@media (max-width: 768px) {
  body {
    height: auto !important;
    max-height: none !important;
    overflow-y: auto !important;
    position: static !important;
  }
  
  html {
    height: auto !important;
    max-height: none !important;
    overflow-y: auto !important;
    position: static !important;
  }
}

/* Mobile landscape: scroll natural con menú fijo */
@media (max-width: 768px) and (orientation: landscape) {
  body {
    height: auto !important;
    max-height: none !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    position: static !important;
    padding-top: 50px !important; /* Espacio para menú fijo */
    padding-bottom: 30px !important;
  }
  
  html {
    height: auto !important;
    max-height: none !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    position: static !important;
  }
  
  /* Contenedor principal con scroll natural */
  .container {
    height: auto !important;
    max-height: none !important;
    overflow-y: visible !important;
    display: block !important;
    padding-bottom: 30px !important;
  }

  /* Filtros y botoneras: sin scroll interno en paisaje móvil */
  .filters-container {
    overflow-x: visible !important;
    overflow-y: visible !important;
    -webkit-overflow-scrolling: auto !important;
    position: static !important;
    flex-wrap: wrap !important;
    width: 100% !important;
    margin: 0 0 10px 0 !important;
    z-index: auto !important;
  }
  .filters-container::-webkit-scrollbar { display: none !important; }
  
  /* Permitir que los subgrupos se ajusten sin desbordar */
  .date-filters { flex-shrink: 1 !important; min-width: 0 !important; }
  .filter-group { flex-wrap: wrap !important; }
}

/* Desktop short-height: page-level scroll, no internal scrollbars in filters or table */
@media (min-width: 769px) and (max-height: 860px) {
  html, body {
    height: auto !important;
    max-height: none !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    position: static !important;
    padding-top: 50px !important; /* space for fixed menu */
  }
  .container {
    height: auto !important;
    max-height: none !important;
    overflow-y: visible !important;
    display: block !important;
  }
  .filters-container {
    overflow: visible !important;
    position: static !important;
    flex-wrap: wrap !important;
    width: 100% !important;
    z-index: auto !important;
  }
  .table-container,
  .table-responsive,
  .table-wrapper {
    overflow: visible !important;
    overflow-x: auto !important;
    max-height: none !important;
    position: static !important;
  }
}

/* Extra mobile-landscape rule for devices wider than 768px but short height */
@media (orientation: landscape) and (max-height: 480px) {
  body {
    height: auto !important;
    max-height: none !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    position: static !important;
    padding-top: 50px !important; /* espacio para menú fijo */
    padding-bottom: 30px !important;
  }

  html {
    height: auto !important;
    max-height: none !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    position: static !important;
  }

  .container {
    height: auto !important;
    max-height: none !important;
    overflow-y: visible !important;
    display: block !important;
    padding-bottom: 30px !important;
  }

  /* Filtros/botoneras sin scroll interno */
  .filters-container {
    overflow: visible !important;
    -webkit-overflow-scrolling: auto !important;
    position: static !important;
    flex-wrap: wrap !important;
    width: 100% !important;
    z-index: auto !important;
  }
}

/* Main container should respect viewport bounds */
#main {
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
  box-sizing: border-box;
  position: relative;
}

/* Contenedor principal */
.container {
  width: 100%;
  max-width: min(1200px, 100vw); /* Never exceed viewport width */
  margin: 0 auto;
  padding: 0 15px;
  box-sizing: border-box;
  overflow-x: hidden; /* Solo prevenir scroll horizontal */
}

/* Desktop: contenedor con altura fija */
@media (min-width: 769px) {
  .container {
    overflow: visible; /* Allow tooltips to overflow outside container */
    height: calc(100vh - 50px); /* Account for menu height */
    max-height: calc(100vh - 50px);
    display: flex;
    flex-direction: column;
  }
}

/* Mobile: contenedor con scroll natural */
@media (max-width: 768px) {
  .container {
    height: auto !important;
    max-height: none !important;
    overflow-y: auto !important;
    display: block !important;
    padding-bottom: 50px !important;
  }
}

/* Contenedor de la tabla - Override para evitar conflictos */
.table-container {
  width: 100%;
  max-width: 100vw; /* Never exceed viewport width */
  margin: 0;
  box-shadow: none;
  border-radius: 0;
  background: transparent;
  overflow: auto; /* Allow scrolling within container */
  overflow-x: auto; /* Ensure horizontal scrolling works */
  box-sizing: border-box; /* Include border and padding in width calculation */
}

.table-wrapper {
  width: 100%;
  max-width: 100vw; /* Never exceed viewport width */
  overflow: visible;
  position: relative;
  box-sizing: border-box;
}

/* Estilos responsivos */
@media screen and (max-width: 768px) {
  html, body {
    overflow-x: auto;
    overflow-y: auto;
    max-width: 100%;
    height: auto;
    margin: 0;
    padding: 0;
  }
  
  body {
    overflow-y: auto; /* Allow vertical scrolling */
    position: static; /* Change from fixed to static */
    width: 100%;
    min-height: 100vh; /* Ensure minimum height */
  }
  
  .container {
    padding: 5px;
    margin: 0;
    width: 100%;
    min-height: 100vh; /* Ensure container takes full height */
    box-sizing: border-box;
    position: static; /* Change from fixed to static */
    top: auto; /* Remove fixed positioning */
    left: auto;
    right: auto;
    bottom: auto;
    height: auto; /* Remove fixed height */
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  
  th, td {
    padding: 6px 8px;
    font-size: 12px;
  }
  
  .table-wrapper {
    flex: 1;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 5px;
    display: flex;
    flex-direction: column;
    min-height: 0;
    /* Asegurar espacio para la barra de navegación */
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  
  .filters-container {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    margin-bottom: 5px;
    padding: 5px;
    flex-shrink: 0;
    overflow-x: auto;
    background: #fff;
    position: relative;
    z-index: 10;
    padding-top: env(safe-area-inset-top, 5px);
    margin: 0;
    width: 100%;
    box-sizing: border-box;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none; /* Hide scrollbar for Firefox */
  }
  
  .filters-container::-webkit-scrollbar {
    display: none; /* Hide scrollbar for Chrome/Safari */
  }
  
  /* Contenedor para año y mes en la misma línea */
  .date-filters {
    display: flex;
    gap: 10px;
    margin-bottom: 0;
    flex-shrink: 0;
  }
  
  .date-filters .filter-group {
    flex: 1;
    min-width: 0;
    margin-bottom: 0;
  }
  
  .filter-group {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-bottom: 0;
    white-space: nowrap;
  }
  
  .filter-group label {
    margin: 0;
    font-size: 0.9em;
    white-space: nowrap;
  }
  
  .filter-select {
    padding: 6px 8px;
    font-size: 0.9em;
    min-width: 80px;
    box-sizing: border-box;
  }
  
  #syncSeasonsBtn, #syncWarsBtn, #syncPlayersBtn {
    padding: 6px 10px;
    margin: 0;
    font-size: 0.9em;
    white-space: nowrap;
    flex-shrink: 0;
  }
  
  .color-legend {
    margin: 5px 0;
    padding: 6px;
    font-size: 0.75em;
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    align-items: center;
    background: #f8f9fa;
    border-radius: 4px;
    border: 1px solid #dee2e6;
    overflow: visible; /* ensure inner tooltips can overflow */
    position: relative; /* create stacking context above table */
    z-index: 10;
  }
  
  .legend-item {
    font-size: 0.75em;
    padding: 2px 4px;
    display: flex;
    align-items: center;
    white-space: nowrap;
  }
  
  /* Table container adjustments */
  .table-container {
    margin: 0;
    width: 100%;
    height: 100%;
    flex: 1;
    display: flex;
    flex-direction: column;
  }
  
  /* Adjust table header for mobile */
  th {
    padding: 6px 4px;
    font-size: 11px;
  }
  
  /* Make sure the table takes full width */
  table {
    width: 100%;
  }
}

/* Filtros y botones */
.filters-container {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 15px;
  margin-bottom: 20px;
  width: 100%;
  overflow: visible !important; /* allow legend tooltips to overflow */
  position: relative; /* create stacking context above table */
  z-index: 20;
}

.filters-container > div {
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

/* Botones */
.btn {
  padding: 8px 20px;
  font-size: 16px;
  cursor: pointer;
  border: 1px solid #007bff;
  background: #007bff;
  color: white;
  border-radius: 5px;
  margin: 0;
  transition: all 0.2s;
  font-weight: 500;
  white-space: nowrap;
}

.btn:disabled {
  background: #6c757d;
  border-color: #6c757d;
  color: #e9ecef;
  cursor: not-allowed;
}

.btn:hover:not(:disabled) {
  background-color: #0056b3;
  border-color: #0056b3;
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* Estilos para encabezados ordenables y íconos de ordenación */
th.sortable {
  position: relative;
  padding: 0 25px; /* Espacio para los íconos */
  text-align: center;
}

th.sortable:hover {
  background-color: #1a252f;
}

/* Estilos para los íconos de ordenación */
th .sort-icon {
  display: inline-block;
  margin-left: 8px;
  color: white;
  font-weight: bold;
  font-size: 0.9em;
  opacity: 0;
  transition: opacity 0.2s;
}

/* Mostrar solo el ícono de ordenación en la columna activa */
th.sort-asc .sort-icon,
th.sort-desc .sort-icon {
  opacity: 1;
}

/* Mostrar ícono en hover solo en columnas ordenables */
th.sortable:hover .sort-icon {
  opacity: 0.6;
}

/* Evitar que el fondo del header cambie al ordenar */
th.sort-asc,
th.sort-desc {
  background: #2c3e50 !important;
}

/* Mensajes de carga */
.loading {
  text-align: center;
  padding: 20px;
  font-style: italic;
  color: #666;
  width: 100%;
}

/* Estilos para el contenedor principal */
.container {
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  padding: 15px 10px;
  position: relative;
  box-sizing: border-box;
  box-sizing: border-box;
}

/* Media Queries para responsividad */
@media screen and (max-width: 768px) {
  .container {
    padding: 0 10px;
  }
  
  th, td {
    padding: 8px 10px;
    font-size: 0.9em;
  }
  
  .btn {
    padding: 8px 15px;
    font-size: 0.9em;
    width: 100%;
    margin: 5px 0;
  }
  
  .table-container {
    margin: 10px -10px;
    width: calc(100% + 20px);
  }
}

/* Scrollbar personalizada */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb {
  background: #888;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #555;
}
