/* Dark theme variables */
:root {
  --bg-color: #121212;
  --card-color: #1e1e1e;
  --border-color: #2a2a2a;
  --text-color: #e5e7eb;
  --muted-text: #9aa0a6;
  --hover-color: #222a35;
  --row-hover: #1f2937;
  --row-odd: #181818;
  --row-even: #1b1b1b;
}

/* PREVENT HORIZONTAL OVERFLOW BUT ALLOW VERTICAL SCROLLING */
html, body {
  overflow-x: hidden !important;
  overflow-y: auto !important;
  max-width: 100vw !important;
  box-sizing: border-box !important;
  min-height: 100vh !important;
  margin: 0 !important;
  padding: 0 !important;
}

/* Space for fixed menu */
body {
  padding-top: 60px !important;
}

/* Main layout container - allow vertical scroll on mobile */
body > .container {
  max-width: 100vw !important;
  box-sizing: border-box !important;
  position: relative !important;
  overflow-x: hidden !important;
}

/* Desktop: fixed height layout with internal scrolling */
@media (min-width: 769px) {
  html, body {
    height: 100vh !important;
    max-height: 100vh !important;
    overflow: hidden !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
  }
  
  body > .container {
    max-height: calc(100vh - 50px) !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
  }
}

/* Mobile: allow natural page scroll */
@media (max-width: 768px) {
  html, body {
    position: static !important;
    height: auto !important;
    max-height: none !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    min-height: 100vh !important;
  }
  
  body {
    padding-bottom: 50px !important;
  }
  
  body > .container {
    max-height: none !important;
    overflow: visible !important;
    display: block !important;
    padding: 10px !important;
    min-height: calc(100vh - 50px) !important;
  }
  
  /* Forzar que todos los contenedores de tabla no tengan altura máxima */
  .table-container,
  .table-responsive,
  .table-wrapper {
    max-height: none !important;
    overflow-y: visible !important;
    overflow-x: auto !important;
  }
  
  /* Tablas principales sin altura máxima */
  #seasonsTable,
  #warsTable,
  #playersTable,
  #cwlTable {
    max-height: none !important;
  }
  
  /* Sobrescribir cualquier estilo inline que pueda estar aplicando altura máxima */
  *[style*="max-height"] {
    max-height: none !important;
  }
  
  /* Contenedor principal */
  #main,
  #content {
    max-height: none !important;
    overflow: visible !important;
    min-height: calc(100vh - 50px) !important;
  }
}

/* Desktop: table containers scroll internally */
@media (min-width: 769px) {
  .table-container, .table-responsive {
    overflow-x: auto !important;
    overflow-y: auto !important;
    max-width: 100vw !important;
    max-height: calc(100vh - 150px) !important;
    position: relative !important;
  }
}

/* Mobile: table containers with smooth touch scrolling */
@media (max-width: 768px) {
  .table-container, .table-responsive {
    overflow-x: auto !important;
    overflow-y: visible !important;
    max-width: 100vw !important;
    position: relative !important;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 20px;
  }
}

/* Allow table to be wider than container for horizontal scrolling */
table {
  max-width: none !important;
  width: max-content !important;
  min-width: 100% !important;
  box-sizing: border-box !important;
}

/* All table types can exceed container width for horizontal scroll */
.attack-table,
#cwlTable,
#playersTable,
#warsTable,
#seasonsTable,
.war-members-table {
  max-width: none !important;
  min-width: 100% !important;
  width: max-content !important;
  box-sizing: border-box !important;
}

/* Tables inside containers can exceed for scrolling */
div table,
.container table,
.card table,
.war-info table {
  max-width: none !important;
  min-width: 100% !important;
  width: max-content !important;
  box-sizing: border-box !important;
}

/* COMENTADO: Esta regla causaba problemas en móvil - Reemplazada por mobile-tables-fix.css */
/* *:not(table):not(.attack-table):not(#cwlTable):not(#playersTable):not(#warsTable):not(#seasonsTable):not(.war-members-table) {
  max-width: 100vw !important;
} */

/* Tooltip táctil para móviles */
.touch-tooltip {
  position: fixed;
  background: rgba(0, 0, 0, 0.95);
  color: white;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  z-index: 10000;
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  max-width: 80vw;
  text-align: center;
  animation: tooltipFadeIn 0.2s ease-out;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

@keyframes tooltipFadeIn {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* Base dark background */
html, body {
  background-color: var(--bg-color);
  color: var(--text-color);
}

/* Top menu container basic dark styling */
#menu {
  background-color: #111827; /* slate-900 */
  color: var(--text-color);
  padding: 10px 12px;
  display: flex;
  gap: 8px;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
}

#menu button {
  background: #1f2937;
  color: var(--text-color);
  border: 1px solid var(--border-color);
  padding: 6px 10px;
  border-radius: 6px;
}

#menu button.active {
  background: #374151; /* slate-700 */
  border-color: #4b5563; /* slate-600 */
}

/* Filters container styles */
.filters-container {
  display: flex;
  align-items: center;
  margin-bottom: 1rem;
  padding: 0.6rem 0.4rem; /* Reduced padding */
  width: 100%;
  max-width: 100vw; /* Never exceed viewport width */
  box-sizing: border-box;
  position: relative;
  background: var(--card-color);
  color: var(--text-color);
  border-radius: 6px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.35);
  gap: 0.75rem; /* Reduced gap for better space utilization */
  overflow-x: hidden; /* Prevent horizontal overflow */
  overflow-y: visible; /* Allow vertical expansion */
  flex-wrap: wrap; /* Allow wrapping to multiple rows */
  min-height: auto; /* Allow container to grow vertically */
  justify-content: flex-start; /* Better alignment */
}

/* Sync buttons */
#syncSeasonsBtn, #syncWarsBtn {
  white-space: nowrap;
  padding: 0.5rem 1rem;
  background-color: #0d6efd;
  color: white;
  border: 1px solid #0d6efd;
  border-radius: 6px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  width: fit-content;
  min-width: fit-content;
  max-width: fit-content;
}

#syncSeasonsBtn:hover:not(:disabled),
#syncWarsBtn:hover:not(:disabled) {
  background-color: #0b5ed7;
  border-color: #0a58ca;
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

#syncSeasonsBtn:disabled,
#syncWarsBtn:disabled {
  background-color: #6c757d;
  border-color: #6c757d;
  cursor: not-allowed;
  opacity: 0.65;
}

/* Date filters container */
.date-filters {
  display: flex;
  gap: 0.8rem;
  align-items: center;
  margin-left: 0; /* Elimina el margen izquierdo automático */
  border-left: 1px solid var(--border-color); /* Línea divisoria sutil */
  padding-left: 1.5rem; /* Espacio después de la línea */
}

/* Active-only filter container (to the right of date filters) */
.active-filter {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border-left: 1px solid var(--border-color); /* Same subtle divider */
  padding-left: 1.5rem; /* Space after the divider */
}
.active-filter .form-check-input {
  margin-left: 0.25rem;
}

/* Color legend */
.filters-container .color-legend {
  display: flex;
  flex-wrap: nowrap; /* Solo una línea */
  gap: 1rem;
  margin-left: 1rem;
  align-items: center;
  color: var(--muted-text);
  width: fit-content; /* Solo ocupa el ancho necesario */
  padding: 8px 12px;
  background: var(--card-color) !important; /* Fondo acorde a modo oscuro */
  border: 1px solid var(--border-color) !important;
  border-radius: 8px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.85em;
  position: relative;
}

.legend-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  font-size: 14px;
  line-height: 1;
  border-radius: 4px;
  background: transparent;
  border: 2px solid #ffffff;
}

.legend-color {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  display: inline-block;
}

/* Colors matching the table cells exactly */
.legend-color.green { background-color: #28a745; border: 1px solid #218838; }
.legend-color.yellow { background-color: #ffc107; border: 1px solid #e0a800; }
.legend-color.orange { background-color: #fd7e14; border: 1px solid #e06b00; }
.legend-color.red { background-color: #dc3545; border: 1px solid #c82333; }

/* ==== Precision bar base styles (apply in all modes) ==== */
#seasonsTable td .precision-bar-container {
  position: relative;
  width: 100%;
  height: 22px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-color);
  border-radius: 11px;
  overflow: hidden;
}

#seasonsTable td .precision-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #28a745 0%, #20c997 100%);
  border-radius: 10px;
  transition: width 0.3s ease;
}

#seasonsTable td .precision-text {
  position: absolute;
  left: 0; right: 0; top: 0; bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85em;
  color: var(--text-color);
  pointer-events: none;
}

/* Color variants for precision bar */
#seasonsTable td .precision-bar.excellent { background: linear-gradient(90deg, #28a745 0%, #20c997 100%); }
#seasonsTable td .precision-bar.good { background: linear-gradient(90deg, #20c997 0%, #17a2b8 100%); }
#seasonsTable td .precision-bar.average { background: linear-gradient(90deg, #ffc107 0%, #fd7e14 100%); }
#seasonsTable td .precision-bar.poor { background: linear-gradient(90deg, #fd7e14 0%, #dc3545 100%); }

/* Responsive adjustments */
@media (max-width: 992px) {
  .filters-container {
    gap: 0.5rem;
  }

/* ==== Precision bar base styles (apply in all modes) ==== */
#seasonsTable td .precision-bar-container {
  position: relative;
  width: 100%;
  height: 22px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-color);
  border-radius: 11px;
  overflow: hidden;
}

#seasonsTable td .precision-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #28a745 0%, #20c997 100%);
  border-radius: 10px;
  transition: width 0.3s ease;
}

#seasonsTable td .precision-text {
  position: absolute;
  left: 0; right: 0; top: 0; bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85em;
  color: var(--text-color);
  pointer-events: none;
}

/* Color variants for precision bar */
#seasonsTable td .precision-bar.excellent { background: linear-gradient(90deg, #28a745 0%, #20c997 100%); }
#seasonsTable td .precision-bar.good { background: linear-gradient(90deg, #20c997 0%, #17a2b8 100%); }
#seasonsTable td .precision-bar.average { background: linear-gradient(90deg, #ffc107 0%, #fd7e14 100%); }
#seasonsTable td .precision-bar.poor { background: linear-gradient(90deg, #fd7e14 0%, #dc3545 100%); }
  
  .date-filters {
    gap: 0.5rem;
  }
  
  .color-legend {
    gap: 0.5rem;
    margin-left: 0.5rem;
    flex-wrap: wrap; /* En móvil sí puede hacer wrap */
    padding-left: 1rem;
  }
  
  .legend-item {
    font-size: 0.8em;
  }
}

/* Mobile viewport adjustments - Compatible con MobileViewportDetector */
/* Variables CSS establecidas por mobile-viewport-detector.js */
:root {
  --mobile-bottom-nav-height: 0px;
  --mobile-keyboard-height: 0px;
  --mobile-total-bottom-space: 0px;
}

/* Mobile: scroll natural - ELIMINAR RESTRICCIONES */
@media screen and (max-width: 768px) {
  html {
    height: auto !important;
    max-height: none !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
  }
  
  body {
    height: auto !important;
    max-height: none !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    padding-bottom: var(--mobile-total-bottom-space) !important;
  }
  
  /* Permitir scroll natural en contenedores */
  .container,
  .table-container,
  .table-responsive,
  .table-wrapper {
    max-height: none !important;
    overflow-y: visible !important;
    overflow-x: auto !important;
  }
  
  /* Ajustes específicos cuando hay botonera - PERMITIR SCROLL */
  body.has-bottom-nav .container,
  body.has-bottom-nav .table-container,
  body.has-bottom-nav .table-responsive {
    max-height: none !important;
    overflow-y: visible !important;
    padding-bottom: calc(var(--mobile-bottom-nav-height) + 50px) !important;
  }
  
  /* Ajustes cuando el teclado está visible - PERMITIR SCROLL */
  body.keyboard-visible .container,
  body.keyboard-visible .table-container,
  body.keyboard-visible .table-responsive {
    max-height: none !important;
    overflow-y: visible !important;
    padding-bottom: calc(var(--mobile-keyboard-height) + 50px) !important;
  }
  
  /* Asegurar que los filtros no tengan scroll interno - parte del scroll de página */
  .filters-container {
    position: static !important;
    overflow: visible !important;
    max-height: none !important;
    background: var(--card-color) !important;
    margin-bottom: 10px !important;
  }
}

/* Mobile landscape: mantener menú fijo y permitir scroll */
@media screen and (max-width: 768px) and (orientation: landscape) {
  html {
    height: auto !important;
    max-height: none !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    position: static !important;
  }
  
  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;
  }
  
  /* Permitir scroll natural en contenedores principales */
  .container,
  .table-container,
  .table-responsive,
  .table-wrapper {
    max-height: none !important;
    overflow-y: visible !important;
    overflow-x: auto !important;
    position: static !important;
  }
  
  /* Ajustes específicos cuando hay botonera */
  body.has-bottom-nav .container,
  body.has-bottom-nav .table-container,
  body.has-bottom-nav .table-responsive {
    max-height: none !important;
    overflow-y: visible !important;
    padding-bottom: calc(var(--mobile-bottom-nav-height) + 30px) !important;
  }
  
  /* Ajustes cuando el teclado está visible */
  body.keyboard-visible .container,
  body.keyboard-visible .table-container,
  body.keyboard-visible .table-responsive {
    max-height: none !important;
    overflow-y: visible !important;
    padding-bottom: calc(var(--mobile-keyboard-height) + 30px) !important;
  }
  
  /* Filtros sin restricciones */
  .filters-container {
    position: static !important;
    overflow: visible !important;
    max-height: none !important;
    background: var(--card-color) !important;
    margin-bottom: 10px !important;
  }
}

/* Mobile: ajustes permisivos sin altura máxima */
body.has-bottom-nav .table-container,
body.has-bottom-nav .table-responsive {
  max-height: none !important;
  margin-bottom: 50px !important;
}

body.keyboard-visible .table-container,
body.keyboard-visible .table-responsive {
  max-height: none !important;
}

/* Ajustes específicos para dispositivos móviles */
body.mobile-device {
  padding-bottom: 50px !important;
}

body.mobile-device.has-bottom-nav {
  min-height: auto !important;
}

body.mobile-device.keyboard-visible {
  padding-bottom: 50px !important;
}

/* Contenedor principal sin restricciones de altura */
body.mobile-device .container {
  max-height: none !important;
  transition: none !important;
}

body.mobile-device.has-bottom-nav .container {
  max-height: none !important;
}

body.mobile-device.keyboard-visible .container {
  max-height: none !important;
}

/* Filtros container ajustado para móviles */
body.mobile-device.has-bottom-nav .filters-container {
  margin-bottom: 1rem;
}

body.mobile-device.keyboard-visible .filters-container {
  margin-bottom: 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

/* Tabla sin restricciones de altura en móviles */
body.mobile-device .table-wrapper {
  max-height: none !important;
  overflow-y: visible !important;
  overflow-x: auto !important;
}

body.mobile-device.keyboard-visible .table-wrapper {
  max-height: none !important;
}

/* Ajustes para inputs y formularios cuando el teclado está visible */
body.mobile-device.keyboard-visible input,
body.mobile-device.keyboard-visible textarea,
body.mobile-device.keyboard-visible select {
  font-size: 16px; /* Prevenir zoom en iOS */
}

/* Indicador visual de botonera detectada (para debugging) */
body.has-bottom-nav::after {
  content: '';
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--mobile-bottom-nav-height);
  background: linear-gradient(to top, rgba(0,0,0,0.1), transparent);
  pointer-events: none;
  z-index: 999;
}

/* Indicador visual de teclado visible (para debugging) */
body.keyboard-visible::before {
  content: '⌨️ Teclado: ' var(--mobile-keyboard-height);
  position: fixed;
  top: 50px;
  right: 10px;
  background: rgba(0,0,0,0.8);
  color: white;
  padding: 5px 10px;
  border-radius: 5px;
  font-size: 12px;
  z-index: 1001;
}

/* Mobile: permitir scroll natural en todos los navegadores */
@supports (-webkit-touch-callout: none) {
  /* iOS Safari */
  .container,
  .table-container,
  .table-responsive {
    max-height: none !important;
    padding-bottom: 50px !important;
  }
}

@supports (not (-webkit-touch-callout: none)) and (pointer: coarse) {
  /* Android Chrome */
  .container,
  .table-container,
  .table-responsive {
    max-height: none !important;
    padding-bottom: 50px !important;
  }
}

/* Ajustes específicos para móviles reales */
@supports (-webkit-touch-callout: none) {
  .table-container {
    max-height: none !important;
    height: auto !important;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  
  /* Asegurar que el contenedor use todo el espacio disponible */
  body {
    min-height: 100vh;
    min-height: -webkit-fill-available;
  }
}

/* Small icon appended next to highlighted cells in Seasons (admin mode) */
.cell-legend-icon {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  min-width: 22px !important;
  width: 22px !important;
  height: 22px !important;
  font-size: 16px !important;
  line-height: 1 !important;
  border-radius: 4px !important;
  background: transparent !important;
  border: 2px solid #ffffff !important;
  color: inherit !important;
  flex-shrink: 0 !important;
  box-sizing: border-box !important;
  text-align: center;
  vertical-align: middle;
}

/* Color only the glyph (icon) using currentColor */
.legend-icon.green, .cell-legend-icon.green { color: #28a745 !important; font-weight: bold !important; }
.legend-icon.yellow, .cell-legend-icon.yellow { color: #ffc107 !important; font-weight: bold !important; }
.legend-icon.orange, .cell-legend-icon.orange { color: #fd7e14 !important; font-weight: bold !important; }
.legend-icon.red, .cell-legend-icon.red { color: #dc3545 !important; font-weight: bold !important; }

/* Mantener el color de fondo de la fila en celdas con icono de leyenda (no transparentar) */
#seasonsTable td.highlight-green,
#seasonsTable td.highlight-yellow,
#seasonsTable td.highlight-orange,
#seasonsTable td.highlight-red {
  background-color: inherit !important; /* usa el fondo zebra de la fila */
  color: inherit !important;
  backdrop-filter: none !important;
}

/* Igualar exactamente el color de fondo de la fila (zebra) */
tbody tr:nth-child(odd) td.highlight-green,
tbody tr:nth-child(odd) td.highlight-yellow,
tbody tr:nth-child(odd) td.highlight-orange,
tbody tr:nth-child(odd) td.highlight-red {
  background-color: var(--row-odd) !important;
}

tbody tr:nth-child(even) td.highlight-green,
tbody tr:nth-child(even) td.highlight-yellow,
tbody tr:nth-child(even) td.highlight-orange,
tbody tr:nth-child(even) td.highlight-red {
  background-color: var(--row-even) !important;
}

/* Mantener el color azulado oscuro en columna Nombre SIEMPRE */
tbody tr td.player-name-cell,
tbody tr.top-3-player td.player-name-cell {
  background-color: #2c3e50 !important;
  color: #ffffff !important;
}

/* Allow flex items to shrink when needed for responsive layout */
.filters-container > * {
  flex-shrink: 1;
  min-width: fit-content; /* Don't shrink below content size */
}

/* Form controls in filters */
.filters-container .form-select {
  min-width: 70px; /* Even smaller for better space usage */
  max-width: 100px; /* Reduced max width */
  padding: 0.25rem 0.5rem; /* Smaller padding */
  font-size: 0.875rem; /* Slightly smaller font */
}

/* Filter buttons and controls */
.filters-container .btn {
  flex-shrink: 1;
  min-width: fit-content;
  white-space: nowrap; /* Keep button text on one line */
  padding: 0.375rem 0.75rem; /* Smaller padding */
  font-size: 0.875rem; /* Smaller font */
}

/* Ensure sync and toggle buttons specifically fit their content */
.filters-container #syncSeasonsBtn,
.filters-container #syncWarsBtn,
.filters-container .btn-toggle-details {
  width: fit-content !important;
  min-width: fit-content !important;
  max-width: fit-content !important;
  flex-shrink: 0 !important;
}

/* Filter groups */
.filters-container .date-filters,
.filters-container .btn-group,
.filters-container .active-filter {
  flex-shrink: 1;
  min-width: fit-content;
}

/* Labels in filters */
.filters-container label {
  white-space: nowrap; /* Keep labels readable */
  flex-shrink: 0;
  font-size: 0.875rem; /* Smaller font */
  margin: 0; /* Remove extra margin */
}

/* Estilos base consolidados para todas las tablas */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8em;
  table-layout: auto;
  margin-bottom: 0;
  color: var(--text-color);
  background: var(--card-color);
}

/* Encabezados de tabla */
th {
  background-color: var(--table-header-bg, #374151);
  color: var(--table-header-text, white);
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 10;
  padding: 8px 12px;
  text-align: center;
  border-bottom: 2px solid var(--table-header-border, #4b5563);
}

/* Celdas */
td {
  padding: 8px 12px;
  text-align: center;
  border-bottom: 1px solid var(--border-color);
}

/* Contenedores responsivos */
.table-container {
  width: 100%;
  max-width: 100vw;
  overflow-x: auto;
  margin: 10px 0;
  position: relative;
}

/* Media queries consolidados */
@media (max-width: 768px) {
  /* Estilos móviles */
  table {
    font-size: 0.9em;
  }
  
  .table-container {
    overflow-x: visible;
  }
}

@media (min-width: 769px) {
  /* Estilos desktop */
  .table-container {
    max-height: calc(100vh - 150px);
    overflow-y: auto;
  }
}

/* Zebra striping for all data rows */
tbody tr:nth-child(odd) {
  background-color: var(--row-odd);
}
tbody tr:nth-child(even) {
  background-color: var(--row-even);
}

/* Ajustar el padding para el tamaño de fuente reducido */
th, td {
  padding: 6px 8px;
  text-align: center;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-sizing: border-box;
  min-width: 0;
  width: auto;
}

th {
  background-color: #374151 !important; /* Color gris oscuro acorde al tema */
  color: white !important; /* Force white text */
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 10 !important;
  cursor: pointer;
  user-select: none;
  border-bottom: 2px solid #4b5563 !important;
  box-shadow: 0 2px 3px -1px rgba(0,0,0,0.1) !important;
  transition: none !important; /* Prevent any transitions that might override our styles */
}

/* Ensure sticky headers maintain their style when scrolled */
th[style*="position: sticky"] {
  background-color: #374151 !important;
  color: white !important;
  z-index: 110 !important;
}

/* Override any other styles that might affect our sticky headers */
.table-container th,
.table-wrapper th,
table th {
  background-color: #374151 !important;
  color: white !important;
}

th.sortable {
  position: relative;
  padding: 8px 25px 8px 8px; /* Add right padding for the arrow */
  text-align: center;
}

th.sortable::after {
  content: "⇅";
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.8em;
  opacity: 0.3;
  transition: opacity 0.2s;
  pointer-events: none; /* Prevent the arrow from interfering with clicks */
}

th.sortable:hover::after {
  opacity: 0.7;
}

/* Ensure sort icons are properly aligned */
th.sort-asc::after,
th.sort-desc::after {
  opacity: 1;
}

th.sort-asc::after {
  content: "↑";
}

th.sort-desc::after {
  content: "↓";
}

th:hover {
  background-color: #4b5563; /* Gris más claro en hover */
}

th.sort-asc, th.sort-desc {
  background-color: #4b5563; /* Gris más claro para orden activo */
}

tr:hover {
  background-color: var(--row-hover);
}

/* Make all header cells sticky when scrolling vertically and horizontally */
thead th {
  position: sticky;
  top: 0;
  z-index: 10;
  background-color: #374151; /* Color gris oscuro */
  color: white; /* White text */
  overflow: visible !important; /* allow header-icon tooltips to escape */
}

/* Wars table sticky cells */
#warsTable .sticky-cell {
  position: sticky;
  z-index: 4;
  background-color: #2c3e50;
  color: #ffffff;
  box-shadow: none;
}

#warsTable .sticky-cell:first-child {
  left: 0;
}

#warsTable .sticky-cell:nth-child(2) {
  left: 40px; /* Width of first sticky cell */
}

/* CWL table: make first two columns sticky */
/* Headers */
#cwlTable th.sticky-index {
  position: sticky;
  left: 0;
  top: 0; /* ensure vertical stickiness */
  z-index: 110; /* above body cells, below popup */
}

#cwlTable th.sticky-name {
  position: sticky;
  left: 40px; /* match index column width */
  top: 0;
  z-index: 110;
}

/* Body cells */
#cwlTable td.row-index {
  position: sticky;
  left: 0;
}

/* When CWL conditions popup is open, push headers behind it */
body.cwl-popup-open thead th,
body.cwl-popup-open #cwlTable th.sticky-index,
body.cwl-popup-open #cwlTable th.sticky-name {
  z-index: 1 !important;
}

/* CWL: Evaluation points visuals */
#cwlTable td.evaluation-cell {
  min-width: 140px;
}

#cwlTable td.evaluation-cell .points-visuals {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

/* Simple mode: show circular, hide bar */
#cwlTable.simple-mode td.evaluation-cell .points-circle { display: inline-block; }
#cwlTable.simple-mode td.evaluation-cell .points-bar-container { display: none; }

/* Detailed mode: show bar, hide circular */
#cwlTable.detailed-mode td.evaluation-cell .points-circle { display: none; }
#cwlTable.detailed-mode td.evaluation-cell .points-bar-container { display: block; width: 140px; }

/* Circular indicator */
#cwlTable td.evaluation-cell .points-circle svg { display: block; }
#cwlTable td.evaluation-cell .points-circle circle.bg {
  fill: none;
  stroke: rgba(255,255,255,0.12);
}
#cwlTable td.evaluation-cell .points-circle circle.progress {
  fill: none;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.4s ease;
}
#cwlTable td.evaluation-cell .points-circle circle.progress.excellent { stroke: #28a745; }
#cwlTable td.evaluation-cell .points-circle circle.progress.good { stroke: #20c997; }
#cwlTable td.evaluation-cell .points-circle circle.progress.average { stroke: #ffc107; }
#cwlTable td.evaluation-cell .points-circle circle.progress.poor { stroke: #dc3545; }
#cwlTable td.evaluation-cell .points-circle text {
  fill: #e6e8ea;
  font-weight: 700;
  font-size: 12px;
}

/* Horizontal bar */
#cwlTable td.evaluation-cell .points-bar-container {
  position: relative;
  height: 20px;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  overflow: hidden;
}
#cwlTable td.evaluation-cell .points-bar {
  height: 100%;
  width: 0%;
  border-radius: 10px;
  transition: width 0.4s ease;
}
#cwlTable td.evaluation-cell .points-bar.excellent { background: linear-gradient(90deg, #28a745, #20c997); }
#cwlTable td.evaluation-cell .points-bar.good { background: linear-gradient(90deg, #20c997, #17a2b8); }
#cwlTable td.evaluation-cell .points-bar.average { background: linear-gradient(90deg, #ffc107, #fd7e14); }
#cwlTable td.evaluation-cell .points-bar.poor { background: linear-gradient(90deg, #fd7e14, #dc3545); }
#cwlTable td.evaluation-cell .points-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 0.85em;
  text-shadow: 0 1px 2px rgba(0,0,0,0.6);
  pointer-events: none;
}

/* Iconos en headers con bordes y tooltips */
th .header-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 2px solid #ffffff;
  border-radius: 6px;
  background: #ffffff;
  color: #111827;
  font-size: 16px;
  cursor: help;
  position: relative;
  transition: all 0.2s ease;
}

th .header-icon:hover {
  background-color: #f3f4f6;
  transform: scale(1.05);
  box-shadow: 0 2px 8px rgba(255, 255, 255, 0.2);
}

/* Tooltip para iconos de headers */
th .header-icon::before {
  content: attr(data-tooltip);
  position: absolute;
  left: 50%;
  top: calc(100% + 8px);
  transform: translateX(-50%);
  background-color: rgba(0, 0, 0, 0.9);
  color: white;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  z-index: 10000;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

th .header-icon::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 100%;
  transform: translateX(-50%);
  border-width: 6px;
  border-style: solid;
  border-color: transparent transparent rgba(0, 0, 0, 0.9) transparent;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  z-index: 10000;
  margin-top: 2px;
}

th .header-icon:hover::before,
th .header-icon:hover::after {
  opacity: 1;
  visibility: visible;
}

/* Ajuste para headers con iconos y ordenamiento */
th.sortable .header-icon {
  margin-right: 15px; /* Espacio para la flecha de ordenamiento */
}

/* First column header needs special handling */
th:first-child {
  box-shadow: none;
}

/* Index column header */
th.sticky-index {
  width: 40px;
  min-width: 40px;
  max-width: 40px;
  text-align: right;
}

/* Index cells */
td.row-index {
  text-align: right;
  font-family: 'Courier New', monospace;
  color: #6c757d;
  width: 40px;
  min-width: 40px;
  max-width: 40px;
  padding-right: 6px;
}

td.numeric {
  text-align: center;
  font-family: 'Courier New', monospace;
  font-size: 0.95em;
  padding: 6px 4px;
}

/* Loading and error states */
.loading {
  padding: 10px;
  margin: 10px 0;
  background-color: var(--card-color);
  color: var(--text-color);
  border-radius: 6px;
  display: none;
  text-align: center;
}

/* Filters container */
.filters-container {
  background: var(--card-color);
  color: var(--text-color);
  padding: 10px;
  border-radius: 6px;
  margin-bottom: 15px;
  border: 1px solid var(--border-color);
}

/* Form controls */
.form-select {
  display: inline-block;
  width: auto;
  min-width: 100px;
}

/* Responsive adjustments */
@media screen and (max-width: 768px) {
  html, body {
    overflow-x: hidden;
    overflow-y: auto;
    max-width: 100vw;
    height: auto;
    min-height: 100vh;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
  }
  
  /* Adjust container for mobile */
  .container {
    width: 100%;
    max-width: 100vw;
    padding: 0; /* remove side padding in responsive to avoid right gap */
    margin: 0;
    box-sizing: border-box;
    min-height: 0;
    height: auto;
    display: flex;
    flex-direction: column;
  }
  
  /* Ensure table is scrollable on mobile and aligned to edges */
  .table-container {
    width: 100%;
    max-width: 100vw;
    overflow-x: auto;
    overflow-y: visible; /* Permitir scroll vertical natural */
    -webkit-overflow-scrolling: touch;
    scrollbar-gutter: auto; /* avoid reserving extra space on right */
    margin: 0; /* remove all margins for edge alignment */
    padding: 0; /* remove side padding */
    flex: 0 1 auto;
    max-height: none !important; /* SIN ALTURA MÁXIMA EN MÓVIL */
    box-sizing: border-box;
    border: 0 !important;         /* edge-to-edge */
    border-radius: 0 !important;  /* edge-to-edge */
    box-shadow: none !important;  /* remove outer shadow gap */
    border-left: 1px solid var(--border-color) !important; /* keep left border */
  }
  
  /* Make sure the table takes full width on mobile */
  table {
    min-width: 100%;
    max-width: 100vw;
    width: max-content;
    margin: 0;
    box-sizing: border-box;
  }

  /* Wrapper should not add any spacing on mobile */
  .table-wrapper {
    margin: 0 !important;
    padding: 0 !important;
    max-width: 100vw !important;
  }
  
  /* Improve touch targets for mobile */
  th, td {
    padding: 8px 10px;
  }
  
  
  .filters-container {
    padding: 6px; /* Further reduced padding for mobile */
    max-width: 100vw;
    box-sizing: border-box;
    flex-wrap: wrap; /* Ensure wrapping works on mobile */
    gap: 0.5rem; /* Smaller gap on mobile */
    min-height: auto; /* Allow vertical expansion */
  }
  .form-select {
    width: 100%;
    margin-bottom: 5px;
  }
  
  .btn {
    width: 100%;
    margin-top: 5px;
  }
  
  /* Keep sync and toggle buttons at fit-content width on mobile */
  #syncSeasonsBtn, #syncWarsBtn,
  .btn-toggle-details {
    width: fit-content !important;
    min-width: fit-content !important;
    max-width: fit-content !important;
  }
}

.error-message {
  color: #dc3545;
  margin-bottom: 15px;
  display: none;
}

/* Specific table overrides */
/* Reset all column widths to auto */
#playersTable th,
#playersTable td,
#warsTable th,
#warsTable td,
#seasonsTable th,
#seasonsTable td {
  width: 1%;
  white-space: nowrap;
}

/* COMENTADO: Estas reglas causaban que las celdas fueran muy pequeñas - Reemplazado por mobile-tables-fix.css */
/* @media screen and (max-width: 1024px) {
  #playersTable th,
  #playersTable td,
  #warsTable th, 
  #warsTable td,
  #seasonsTable th,
  #seasonsTable td {
    width: auto !important;
    min-width: 60px !important;
    max-width: 120px !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }
  
  .table-container {
    max-width: 100vw !important;
    overflow-x: auto !important;
    position: relative !important;
  }
  
  table {
    max-width: none !important;
    width: max-content !important;
    min-width: 100% !important;
  }
  
  #playersTable th,
  #playersTable td,
  #warsTable th,
  #warsTable td, 
  #seasonsTable th,
  #seasonsTable td {
    max-width: 150px !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }
} */

/* COMENTADO: Restricciones demasiado agresivas para móvil - Reemplazado por mobile-tables-fix.css */
/* @media screen and (max-width: 768px) {
  #playersTable th,
  #playersTable td,
  #warsTable th,
  #warsTable td, 
  #seasonsTable th,
  #seasonsTable td {
    width: auto !important;
    min-width: 50px !important;
    max-width: 80px !important;
    font-size: 0.65em !important;
    padding: 4px 6px !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }
  
  .table-container {
    max-width: 100vw !important;
    margin: 0 -10px !important;
    padding: 0 10px !important;
  }
} */

/* CRITICAL: UNIVERSAL TABLE OVERFLOW PREVENTION - Applies to ALL screen sizes */
/* This is the ultimate fallback to prevent any table from exceeding viewport */
.table-container {
  max-width: 100vw !important;
  overflow-x: auto !important;
  overflow-y: visible !important; /* Dejar que la altura la marque el contenido; el scroll será el de la página */
  position: relative !important;
  box-sizing: border-box !important;
  margin: 10px 0 0 0 !important; /* Remove left/right margins for edge alignment */
  padding: 0 !important; /* Remove padding */
  border: none !important; /* Remove border */
  border-radius: 0 !important; /* Remove border radius */
  background: transparent !important; /* Remove background */
  box-shadow: none !important; /* Remove shadow */
}

/* Ensure all table containers respect viewport constraints */
.table-responsive {
  max-width: 100vw !important;
  overflow-x: auto !important;
  box-sizing: border-box !important;
  margin: 0 !important; /* Remove margins */
  padding: 0 !important; /* Remove padding */
}

/* Force table to be scrollable within container */
table {
  max-width: none !important; /* Allow table content to determine width */
  width: max-content !important;
  min-width: 100% !important;
  margin: 0 !important; /* Remove table margin */
}

/* UNIVERSAL VIEWPORT CONSTRAINT - Apply to all screen sizes */
@media screen and (max-width: 1200px) {
  /* Ensure table container never exceeds viewport and aligns to edges */
  .table-container {
    max-width: 100vw !important;
    overflow-x: auto !important;
    overflow-y: auto !important;
    position: relative !important;
    box-sizing: border-box !important;
    margin: 10px 0 0 0 !important; /* Remove left/right margins */
    border: none !important; /* Remove border */
    border-left: 1px solid var(--border-color) !important; /* Keep left border */
    box-shadow: none !important; /* Remove shadow */
    border-radius: 0 !important; /* Remove radius */
  }
  
  /* Allow table to be wider but scrollable within container */
  table {
    width: max-content !important;
    min-width: 100% !important;
    max-width: none !important;
    margin: 0 !important; /* Remove table margin */
  }
  
  /* Override any fixed column widths that might cause overflow */
  #playersTable th,
  #playersTable td,
  #warsTable th,
  #warsTable td,
  #seasonsTable th,
  #seasonsTable td {
    max-width: 150px !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }
}

/* Specific column widths for seasons table (shifted by +1 due to index column) */
#seasonsTable th[data-sort="name"], #seasonsTable td:nth-child(2) { 
  width: 140px;
  padding-left: 12px;
}
#seasonsTable th[data-sort="player_tag"], #seasonsTable td:nth-child(3) { 
  width: 90px;
}
#seasonsTable th[data-sort="clan_tag"], #seasonsTable td:nth-child(4) { 
  width: 90px;
}

/* Numeric columns with centered content */
#seasonsTable th[data-sort="exp_lvl"], #seasonsTable td:nth-child(6),
#seasonsTable th[data-sort="trophies"], #seasonsTable td:nth-child(8),
#seasonsTable th[data-sort="clan_rank"], #seasonsTable td:nth-child(9),
#seasonsTable th[data-sort="previous_clan_rank"], #seasonsTable td:nth-child(10),
#seasonsTable th[data-sort="donations"], #seasonsTable td:nth-child(11),
#seasonsTable th[data-sort="donations_received"], #seasonsTable td:nth-child(12),
#seasonsTable th[data-sort="war_amount"], #seasonsTable td:nth-child(13),
#seasonsTable th[data-sort="war_attacks_amount"], #seasonsTable td:nth-child(14),
#seasonsTable th[data-sort="war_stars_obtained"], #seasonsTable td:nth-child(15),
#seasonsTable th[data-sort="war_stars_accuracy"], #seasonsTable td:nth-child(16),
#seasonsTable th[data-sort="id"], #seasonsTable td:nth-child(19) {
  text-align: center;
  padding: 6px 4px;
}

/* Column specific widths */
#seasonsTable th[data-sort="role"], #seasonsTable td:nth-child(5) { width: 70px; text-align: center; }
#seasonsTable th[data-sort="exp_lvl"], #seasonsTable td:nth-child(6) { width: 60px; }
#seasonsTable th[data-sort="league_name"], #seasonsTable td:nth-child(7) { width: 90px; text-align: center; }
#seasonsTable th[data-sort="trophies"], #seasonsTable td:nth-child(8) { width: 70px; }
#seasonsTable th[data-sort="clan_rank"], #seasonsTable td:nth-child(9) { width: 60px; }
#seasonsTable th[data-sort="previous_clan_rank"], #seasonsTable td:nth-child(10) { width: 70px; }
#seasonsTable th[data-sort="donations"], #seasonsTable td:nth-child(11) { width: 70px; }
#seasonsTable th[data-sort="donations_received"], #seasonsTable td:nth-child(12) { width: 80px; }
#seasonsTable th[data-sort="war_amount"], #seasonsTable td:nth-child(13) { width: 60px; }
#seasonsTable th[data-sort="war_attacks_amount"], #seasonsTable td:nth-child(14) { width: 80px; }
#seasonsTable th[data-sort="war_stars_obtained"], #seasonsTable td:nth-child(15) { width: 80px; }
#seasonsTable th[data-sort="war_stars_accuracy"], #seasonsTable td:nth-child(16) { width: 90px; }
#seasonsTable th[data-sort="modified_at"], #seasonsTable td:nth-child(17) { width: 120px; text-align: center; }
#seasonsTable th[data-sort="created_at"], #seasonsTable td:nth-child(18) { width: 120px; text-align: center; }
#seasonsTable th[data-sort="id"], #seasonsTable td:nth-child(19) { width: 50px; }
#seasonsTable th[data-sort="season_id"], #seasonsTable td:nth-child(20) { width: 90px; text-align: center; }

/* Style for empty cells */
#seasonsTable td:empty::before {
  content: '-';
  color: #999;
  display: inline-block;
  width: 100%;
  text-align: center;
}

/* Numeric cells use monospace font */
td.numeric {
  font-family: 'Courier New', monospace;
  font-size: 0.95em;
}

/* Players table specific (shifted by +1 due to index column) */
#playersTable th[data-column="name"], #playersTable td:nth-child(2) { min-width: 120px; }
#playersTable th[data-column="observations"], #playersTable td:nth-child(3) { min-width: 150px; width: 150px; max-width: 200px; word-wrap: break-word; }
#playersTable th[data-column="player_tag"], #playersTable td:nth-child(4) { min-width: 80px; }
#playersTable th[data-column="active"], #playersTable td:nth-child(5) { min-width: 60px; text-align: center; }
#playersTable th[data-column="role"], #playersTable td:nth-child(6) { min-width: 60px; }
#playersTable th[data-column="townhall_level"], #playersTable td:nth-child(7) { min-width: 40px; }
#playersTable th[data-column="exp_level"], #playersTable td:nth-child(8) { min-width: 40px; }
#playersTable th[data-column="league_name"], #playersTable td:nth-child(9) { min-width: 80px; }
#playersTable th[data-column="trophies"], #playersTable td:nth-child(10) { min-width: 60px; }
#playersTable th[data-column="donations"], #playersTable td:nth-child(11) { min-width: 60px; }
#playersTable th[data-column="donations_received"], #playersTable td:nth-child(12) { min-width: 60px; }
#playersTable th[data-column="last_updated_at"], #playersTable td:nth-child(13) { min-width: 100px; }

/* Wars table specific (shifted by +1 due to index column) */
#warsTable th:nth-child(2), #warsTable td:nth-child(2) { min-width: 80px; } /* Inicio */
#warsTable th:nth-child(3), #warsTable td:nth-child(3) { min-width: 120px; } /* Fin */
#warsTable th:nth-child(4), #warsTable td:nth-child(4) { min-width: 80px; } /* Clan Tag */
#warsTable th:nth-child(5), #warsTable td:nth-child(5) { min-width: 120px; } /* Clan Nombre */
#warsTable th:nth-child(6), #warsTable td:nth-child(6) { min-width: 40px; } /* Clan Nivel */
#warsTable th:nth-child(7), #warsTable td:nth-child(7) { min-width: 40px; } /* Clan Estrellas */
#warsTable th:nth-child(8), #warsTable td:nth-child(8) { min-width: 60px; } /* Clan % */
#warsTable th:nth-child(9), #warsTable td:nth-child(9) { min-width: 80px; } /* Oponente Tag */
#warsTable th:nth-child(10), #warsTable td:nth-child(10) { min-width: 120px; } /* Oponente Nombre */
#warsTable th:nth-child(11), #warsTable td:nth-child(11) { min-width: 40px; } /* Oponente Nivel */
#warsTable th:nth-child(12), #warsTable td:nth-child(12) { min-width: 40px; } /* Oponente Estrellas */
#warsTable th:nth-child(13), #warsTable td:nth-child(13) { min-width: 60px; } /* Oponente % */
#warsTable th:nth-child(14), #warsTable td:nth-child(14) { min-width: 60px; } /* Estado */
#warsTable th:nth-child(15), #warsTable td:nth-child(15) { min-width: 50px; } /* Tamaño Equipo */
#warsTable th:nth-child(16), #warsTable td:nth-child(16) { min-width: 80px; } /* A. x M. */
#warsTable th:nth-child(17), #warsTable td:nth-child(17) { min-width: 80px; } /* Id */

/* Seasons table specific (shifted by +1 due to index column) - min-widths */
#seasonsTable th[data-sort="name"], #seasonsTable td:nth-child(2) { min-width: 120px; }
#seasonsTable th[data-sort="player_tag"], #seasonsTable td:nth-child(3) { min-width: 80px; }
#seasonsTable th[data-sort="clan_tag"], #seasonsTable td:nth-child(4) { min-width: 80px; }
#seasonsTable th[data-sort="role"], #seasonsTable td:nth-child(5) { min-width: 60px; }
#seasonsTable th[data-sort="exp_lvl"], #seasonsTable td:nth-child(6) { min-width: 50px; }
#seasonsTable th[data-sort="league_name"], #seasonsTable td:nth-child(7) { min-width: 80px; }

/* Estilos para resaltado de guerras */
.war-victory {
  background-color: rgba(40, 167, 69, 0.1) !important; /* Verde claro para victorias */
}

.war-victory:hover {
  background-color: rgba(40, 167, 69, 0.15) !important;
}

.war-defeat {
  background-color: rgba(220, 53, 69, 0.1) !important; /* Rojo claro para derrotas */
}

.war-defeat:hover {
  background-color: rgba(220, 53, 69, 0.15) !important;
}

.war-draw {
  background-color: rgba(255, 193, 7, 0.1) !important; /* Amarillo claro para empates */
}

.war-draw:hover {
  background-color: rgba(255, 193, 7, 0.15) !important;
}

.war-in-progress {
  background-color: rgba(0, 123, 255, 0.1) !important; /* Azul claro para guerras en curso */
}

.war-in-progress:hover {
  background-color: rgba(0, 123, 255, 0.15) !important;
}

.top-stars-row {
  background-color: rgba(40, 167, 69, 0.08) !important; /* Subtle green for top stars */
}


.top-stars-row:hover {
  background-color: rgba(40, 167, 69, 0.15) !important;
}

/* Apply left indicator on the first cell to avoid border-collapse issues */
.top-stars-row td:first-child,
.top-stars-row-admin td:first-child {
  border-left: 4px solid #28a745 !important;
}

/* Admin mode: subtle background that doesn't interfere with cell color legend */
.top-stars-row-admin {
  background-color: rgba(40, 167, 69, 0.05) !important; /* Very subtle green for admin mode */
  border-left: 4px solid #28a745 !important;
}

.top-stars-row-admin:hover {
  background-color: rgba(40, 167, 69, 0.10) !important;
}

.war-stars {
  font-weight: bold;
  text-align: center !important;
}

.war-destruction {
  text-align: right !important;
  padding-right: 15px !important;
}

.war-state {
  text-transform: capitalize;
  font-weight: 500;
}

/* Estilos para resaltado de jugadores */
.highlight-leader {
  background-color: #ffd700 !important; /* Dorado sólido para líderes */
  color: #000 !important; /* Buen contraste sobre dorado */
  font-weight: 600;
  position: relative;
  z-index: 6;
}

.highlight-active {
  background-color: #28a745 !important; /* Verde sólido para activos */
  color: #fff !important; /* Buen contraste sobre verde */
  position: relative;
  z-index: 6;
}

.active-player {
  color: #198754; /* Verde para jugadores activos */
  font-weight: 500;
}

.inactive-player {
  color: #dc3545; /* Rojo para jugadores inactivos */
  font-style: italic;
}

.role-leader {
  color: #ffc107; /* Dorado para líder */
  font-weight: 600;
}

.role-coLeader {
  color: #20c997; /* Verde azulado para colíder */
  font-weight: 500;
}


/* Attack table specific styles for seasons player detail */
.attack-table {
  width: 100%;
  max-width: none !important;
  min-width: 100% !important;
  table-layout: auto !important;
  margin-bottom: 1.5rem;
  box-sizing: border-box !important;
  border-collapse: separate;
  border-spacing: 0;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.attack-table th {
  background: linear-gradient(135deg, #1e40af 0%, #1e3a8a 100%) !important;
  color: white !important;
  font-weight: 600;
  padding: 14px 16px;
  text-align: left;
  border: none;
  position: sticky;
  top: 0;
  z-index: 10;
  text-transform: none;
  font-size: 0.9rem;
  letter-spacing: 0.3px;
  border-right: 1px solid rgba(255, 255, 255, 0.1);
}

.attack-table th:last-child {
  border-right: none;
}

.attack-table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  color: var(--text-color);
  font-size: 0.95rem;
  transition: background-color 0.2s ease;
}

.attack-table tbody tr {
  transition: all 0.2s ease;
}

.attack-table tbody tr:nth-child(odd) { 
  background-color: rgba(30, 58, 138, 0.03);
}

.attack-table tbody tr:nth-child(even) { 
  background-color: rgba(30, 64, 175, 0.05);
}

.attack-table tbody tr:hover { 
  background-color: rgba(30, 64, 175, 0.1) !important;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Dark mode adjustments */
@media (prefers-color-scheme: dark) {
  .attack-table tbody tr:nth-child(odd) { 
    background-color: rgba(30, 58, 138, 0.15);
  }
  
  .attack-table tbody tr:nth-child(even) { 
    background-color: rgba(30, 64, 175, 0.2);
  }
  
  .attack-table tbody tr:hover { 
    background-color: rgba(30, 64, 175, 0.3) !important;
  }
  
  .attack-table td {
    border-bottom-color: rgba(255, 255, 255, 0.05);
  }
}

.attack-table .stars {
  color: #ffc107;
  font-weight: bold;
  text-align: center;
}

.attack-table .destruction {
  font-weight: bold;
  text-align: center;
}

/* Estilo para la posición del defensor en la tabla de ataques */
.attack-table .defender-position {
  color: var(--text-color) !important;
  font-weight: bold;
  text-align: center;
  background-color: rgba(0, 0, 0, 0.1);
  border-radius: 12px;
  padding: 2px 8px;
  display: inline-block;
  min-width: 24px;
  text-align: center;
}

/* Estilos para los botones de filtro de fuente de datos */
#dataSourceFilter {
  display: flex;
  gap: 0.25rem;
  align-items: center;
  margin-right: 0; /* Elimina el margen derecho automático */
}

/* Estilo para la etiqueta de fuente si se decide volver a mostrarla */
#dataSourceFilter::before {
  content: none; /* Elimina cualquier contenido generado */
}

#dataSourceFilter .btn {
  padding: 0.25rem 0.5rem;
  font-size: 0.875rem;
  line-height: 1.5;
  border-radius: 0.2rem;
  transition: all 0.2s ease-in-out;
  border: 1px solid transparent;
}

#dataSourceFilter .btn-primary {
  background-color: #0d6efd;
  border-color: #0d6efd;
  color: white;
}

  #dataSourceFilter .btn-outline-primary {
    color: #0d6efd;
    border-color: #0d6efd;
    background-color: transparent;
  }
  
  #dataSourceFilter .btn-outline-primary:hover,
  #dataSourceFilter .btn-outline-primary:focus {
    background-color: #0d6efd;
    color: white;
    border-color: #0d6efd;
  }

  /* Asegurarse de que el botón activo tenga el estilo correcto */
  #dataSourceFilter .btn.active {
    background-color: #0b5ed7;
    border-color: #0a58ca;
    box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.25);
  }

  /* Asegurar que los botones mantengan el mismo ancho */
  #dataSourceFilter .btn {
    min-width: 80px;
    text-align: center;
  }

/* Estilos para warTypeFilter (Wars) - Idénticos a dataSourceFilter */
#warTypeFilter::before {
  content: none;
}

#warTypeFilter .btn {
  padding: 0.25rem 0.5rem;
  font-size: 0.875rem;
  line-height: 1.5;
  border-radius: 0.2rem;
  transition: all 0.2s ease-in-out;
  border: 1px solid transparent;
}

#warTypeFilter .btn-primary {
  background-color: #0d6efd;
  border-color: #0d6efd;
  color: white;
}

#warTypeFilter .btn-outline-primary {
  color: #0d6efd;
  border-color: #0d6efd;
  background-color: transparent;
}

#warTypeFilter .btn-outline-primary:hover,
#warTypeFilter .btn-outline-primary:focus {
  background-color: #0d6efd;
  color: white;
  border-color: #0d6efd;
}

#warTypeFilter .btn.active {
  background-color: #0b5ed7;
  border-color: #0a58ca;
  box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.25);
}

#warTypeFilter .btn {
  min-width: 80px;
  text-align: center;
}


  /* --- Overrides específicos para showWarMembers (modo oscuro) --- */
  /* Evita hover claro que vuelve el texto ilegible */
  .war-members-table tr.member-row:hover {
    background-color: var(--row-hover) !important; /* Hover oscuro consistente */
    color: var(--text-color) !important;
  }
  .war-members-table tr.member-row:hover td,
  .war-members-table tr.member-row:hover th {
    color: var(--text-color) !important;
  }
  /* Mantener contraste cuando la fila tiene estado filler activo */
  .war-members-table tr.member-row.filler-active:hover {
    background-color: rgba(255, 180, 180, 0.18) !important; /* tono sutil en oscuro */
    color: var(--text-color) !important;
  }

/* CWL Group Colors */
#cwlTable tbody tr {
  border-left: 4px solid transparent;
  transition: background-color 0.2s ease;
}

/* Grupo A - Verde (mejor rendimiento) */
#cwlTable tbody tr[data-group="A"] {
  border-left-color: #28a745;
  background-color: rgba(40, 167, 69, 0.08);
}

#cwlTable tbody tr[data-group="A"]:hover {
  background-color: rgba(40, 167, 69, 0.15);
}

/* Grupo B - Amarillo (rendimiento medio-alto) */
#cwlTable tbody tr[data-group="B"] {
  border-left-color: #ffc107;
  background-color: rgba(255, 193, 7, 0.08);
}

#cwlTable tbody tr[data-group="B"]:hover {
  background-color: rgba(255, 193, 7, 0.15);
}

/* Grupo C - Naranja (rendimiento medio-bajo) */
#cwlTable tbody tr[data-group="C"] {
  border-left-color: #fd7e14;
  background-color: rgba(253, 126, 20, 0.08);
}

#cwlTable tbody tr[data-group="C"]:hover {
  background-color: rgba(253, 126, 20, 0.15);
}

/* Grupo D - Rojo (menor rendimiento) */
#cwlTable tbody tr[data-group="D"] {
  border-left-color: #dc3545;
  background-color: rgba(220, 53, 69, 0.08);
}

#cwlTable tbody tr[data-group="D"]:hover {
  background-color: rgba(220, 53, 69, 0.15);
}

/* CWL Table Headers - All sticky on vertical scroll */
#cwlTable thead th {
  position: sticky;
  top: 0;
  z-index: 15 !important;
  background-color: #374151 !important;
  color: white !important;
}

/* CWL Sticky Name Column - Also sticky horizontally */
#cwlTable th.sticky-name {
  position: sticky;
  left: 40px; /* After the index column */
  top: 0;
  z-index: 20 !important; /* Higher than regular headers */
  background-color: #374151 !important;
  color: white !important;
  box-shadow: 2px 0 3px -1px rgba(0,0,0,0.3);
}

/* Landscape: eliminar scroll interno COMPLETAMENTE - una sola página scrollable */
@media screen and (max-width: 768px) and (orientation: landscape) {
  /* FORZAR comportamiento de página completa */
  html, body {
    overflow-y: auto !important;
    overflow-x: hidden !important;
    height: auto !important;
    max-height: none !important;
    min-height: 100vh !important;
    position: static !important;
    width: 100vw !important;
  }
  
  body {
    padding-top: 60px !important;
    padding-bottom: 80px !important;
  }
  
  /* Container principal sin restricciones */
  body > .container,
  .container,
  #main,
  #content {
    overflow: visible !important;
    overflow-y: visible !important;
    overflow-x: hidden !important;
    max-height: none !important;
    min-height: auto !important;
    height: auto !important;
    display: block !important;
    position: static !important;
    flex: none !important;
  }
  
  /* Filtros y controles SIN scroll interno - ocupan el espacio que necesiten */
  .filters-container,
  #advancedControls,
  .color-legend,
  .btn-group,
  .date-filters,
  .active-filter {
    position: static !important;
    overflow: visible !important;
    overflow-y: visible !important;
    max-height: none !important;
    height: auto !important;
    flex-wrap: wrap !important;
    min-height: fit-content !important;
    padding: 15px !important;
    margin-bottom: 20px !important;
  }
  
  /* CRÍTICO: Tabla y contenedores SIN altura máxima NI scroll interno */
  .table-container,
  .table-responsive,
  .table-wrapper {
    max-height: none !important;
    overflow: visible !important;
    overflow-y: visible !important;
    overflow-x: auto !important;
    height: auto !important;
    position: static !important;
    display: block !important;
    flex: none !important;
    -webkit-overflow-scrolling: touch;
  }
  
  /* Permitir scroll horizontal SOLO en tabla, NO vertical */
  .table-container,
  .table-responsive {
    overflow-x: auto !important;
    overflow-y: visible !important;
    max-height: none !important;
  }
  
  /* Asegurar que las barras de progreso no se vean afectadas */
  .stars-bar-container,
  .precision-bar-container,
  .progress {
    overflow: hidden !important;
    max-height: unset !important;
  }
  
  
  /* Compactar tabla en modo simple */
  #seasonsTable.simple-mode td.simple-name {
    font-size: 0.34em !important;
    padding-left: 16px !important;
    padding-right: 10px !important;
    letter-spacing: 0.2px !important;
  }

  #seasonsTable.simple-mode td.simple-stars {
    min-width: 80px !important;
    width: auto !important;
    padding-top: 4px !important;
    padding-bottom: 4px !important;
    padding-left: 6px !important;
    padding-right: 6px !important;
  }
  #seasonsTable.simple-mode td.simple-stars .stars-bar-container {
    height: 16px !important;
    border-radius: 8px !important;
    border-width: 1px !important;
  }
  #seasonsTable.simple-mode td.simple-stars .stars-bar-layer.total,
  #seasonsTable.simple-mode td.simple-stars .stars-bar-layer.attacks,
  #seasonsTable.simple-mode td.simple-stars .stars-bar-layer.obtained {
    border-radius: 7px !important;
  }
  #seasonsTable.simple-mode td.simple-stars .stars-text {
    font-size: 0.65em !important;
    letter-spacing: 0.1px !important;
    font-weight: 700 !important;
  }

  #seasonsTable.simple-mode td.simple-precision {
    min-width: 90px !important;
    width: auto !important;
    padding-top: 4px !important;
    padding-bottom: 4px !important;
    padding-left: 6px !important;
    padding-right: 6px !important;
  }
  #seasonsTable.simple-mode td.simple-precision .precision-bar-container {
    height: 16px !important;
    border-radius: 8px !important;
    border-width: 1px !important;
  }
  #seasonsTable.simple-mode td.simple-precision .precision-bar {
    border-radius: 7px !important;
  }
  #seasonsTable.simple-mode td.simple-precision .precision-text {
    font-size: 0.65em !important;
  }

  #seasonsTable.simple-mode td.simple-league img {
    height: 48px !important;
    width: 48px !important;
    max-height: 48px !important;
    max-width: 48px !important;
  }

/* ... */

@media screen and (max-width: 768px) and (orientation: landscape) {
  /* ... */
  #seasonsTable.simple-mode td.simple-league img {
    height: 48px !important;
    width: 48px !important;
    max-height: 48px !important;
    max-width: 48px !important;
  }
  /* ... */
}

@media screen and (max-width: 480px) {
  /* ... */
  #seasonsTable.simple-mode td.simple-league img {
    height: 48px !important;
    width: 48px !important;
    max-height: 48px !important;
    max-width: 48px !important;
  }
  /* ... */
}

@media screen and (max-width: 768px) and (max-height: 480px) {
  /* ... */
  #seasonsTable.simple-mode td.simple-league img {
    height: 48px !important;
    width: 48px !important;
    max-height: 48px !important;
    max-width: 48px !important;
  }
  /* ... */
}

/* ... */

#seasonsTable.simple-mode .medal-badge {
  width: 18px !important;
  height: 18px !important;
  font-size: 12px !important;
  line-height: 18px !important;
  min-width: 18px !important;
  min-height: 18px !important;
}

/* ... */
  #seasonsTable.simple-mode th {
    font-size: 0.85em !important;
    padding: 10px 8px !important;
  }

  #seasonsTable.simple-mode .medal-badge {
    width: 18px !important;
    height: 18px !important;
    font-size: 12px !important;
    line-height: 18px !important;
    margin-left: 3px !important;
  }
}

/* Header de nombre alineado a la izquierda */
#seasonsTable.simple-mode th:nth-child(1) {
  text-align: left;
  padding-left: 32px;
  width: 1%; /* Ajustar al contenido */
  white-space: nowrap;
}

/* Filas en modo simple con más espaciado */
#seasonsTable.simple-mode tbody tr {
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  border-bottom: 2px solid var(--border-color);
  height: auto;
}

#seasonsTable.simple-mode tbody tr:hover {
  background-color: rgba(13, 110, 253, 0.1) !important;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* Resaltar top 3 en modo simple */
#seasonsTable.simple-mode .top-stars-row,
#seasonsTable.simple-mode .top-stars-row-admin {
  background: linear-gradient(90deg, rgba(40, 167, 69, 0.15) 0%, rgba(40, 167, 69, 0.05) 100%) !important;
  border-left: 5px solid #28a745 !important;
}

#seasonsTable.simple-mode .top-stars-row:hover,
#seasonsTable.simple-mode .top-stars-row-admin:hover {
  background: linear-gradient(90deg, rgba(40, 167, 69, 0.25) 0%, rgba(40, 167, 69, 0.1) 100%) !important;
}

/* Contenedor de tabla en modo simple */
.table-container:has(#seasonsTable.simple-mode) {
  /* Desktop: aplicar altura máxima */
  max-height: calc(100vh - 120px); /* Match main table container height */
}

/* Mobile: modo simple sin altura máxima */
@media (max-width: 768px) {
  .table-container:has(#seasonsTable.simple-mode) {
    max-height: none !important;
  }
}

/* Desktop short-height: force page-level scroll, no internal scrollbars */
@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;
  }
  .container,
  .table-container,
  .table-responsive,
  .table-wrapper {
    max-height: none !important;
    overflow-y: visible !important;
    position: static !important;
  }
  .table-container,
  .table-responsive {
    overflow-x: auto !important; /* keep horizontal scroll when needed */
  }
  .filters-container {
    overflow: visible !important;
    max-height: none !important;
    position: static !important;
  }
}

/* Responsive para modo simple */
@media (max-width: 768px) {
  #seasonsTable.simple-mode th,
  #seasonsTable.simple-mode td {
    padding: 12px 15px;
    font-size: 1em;
  }
  
  .btn-toggle-details {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
  }
  
  .advanced-controls {
    gap: 0.8rem;
    padding-left: 0.8rem;
    margin-left: 0.5rem;
  }
  
  /* Asegurar espaciado inferior en todas las páginas móviles */
  #content,
  #main,
  .content-wrapper {
    padding-bottom: 50px !important;
  }
  
  /* Contenedores principales en móvil */
  .container {
    margin-bottom: 30px !important;
  }
  
  /* Filtros y controles en móvil */
  .filters-container {
    padding: 10px !important;
    margin-bottom: 15px !important;
  }
  
  /* Tablas específicas en móvil */
  #seasonsTable,
  #warsTable,
  #playersTable,
  #cwlTable {
    margin-bottom: 30px !important;
  }
  
  /* Ajustar altura de contenedor de tabla en móvil */
  .table-container:has(#seasonsTable.simple-mode) {
    max-height: none !important;
  }
}

/* Mobile: ajustar tablas para usar espacio completo sin scroll */
@media (max-width: 768px) {
  .table-container, .table-responsive {
    overflow-x: visible !important;
    max-height: none !important;
  }
  
  /* Tablas en modo simple (menos detalles) */
  body.mobile-device.simple-mode table {
    width: 100% !important;
    min-width: auto !important;
  }
  
  /* Celdas permiten texto multilínea */
  body.mobile-device.simple-mode th,
  body.mobile-device.simple-mode td {
    white-space: normal !important;
  }
}
