/**
 * Helical — Clases CSS globales
 * Estilos generales reutilizables en toda la app.
 */

/* --- Variables --- */
:root {
  --color-bg: #0f1419;
  --color-surface: #1a2332;
  --color-surface-hover: #243044;
  --color-border: #2d3a4d;
  --color-text: #e6edf3;
  --color-text-muted: #8b949e;
  --color-accent: #58a6ff;
  --color-accent-hover: #79b8ff;
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  --touch-min: 44px;
  --safe-top: env(safe-area-inset-top, 0);
  --safe-bottom: env(safe-area-inset-bottom, 0);
}

/* --- Reset básico --- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

/* --- Body --- */
.body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

/* --- Layout --- */
.main {
  position: relative;
  z-index: 1;
  flex: 1;
  padding: 1rem;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

@media (min-width: 640px) {
  .main { padding: 1.5rem; }
}

/* --- Header / Nav --- */
.header {
  position: relative;
  z-index: 99999;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding-top: var(--safe-top);
}

@media (max-width: 767px) {
  .header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 999999;
  }
  .body {
    padding-top: calc(var(--touch-min) + 12px + var(--safe-top));
  }
}

.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  padding-right: max(1rem, env(safe-area-inset-right));
  max-width: 1200px;
  margin: 0 auto;
}

@media (min-width: 640px) {
  .nav { padding: 0.75rem 1.5rem; }
}

.nav-brand {
  font-weight: 700;
  font-size: 1.125rem;
  color: var(--color-text);
  text-decoration: none;
  padding: 0.5rem 0;
}

@media (min-width: 640px) {
  .nav-brand { font-size: 1.25rem; }
}

.nav-toggle {
  position: relative;
  z-index: 100000;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  width: var(--touch-min);
  height: var(--touch-min);
  min-width: var(--touch-min);
  min-height: var(--touch-min);
  padding: 0;
  margin: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

@media (min-width: 768px) {
  .nav-toggle { display: none; }
}

.nav-toggle-bar {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--color-text);
  border-radius: 1px;
  transition: transform 0.3s, opacity 0.3s;
}

.nav-toggle.open .nav-toggle-bar:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

.nav-toggle.open .nav-toggle-bar:nth-child(2) {
  opacity: 0;
}

.nav-toggle.open .nav-toggle-bar:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

.nav-list {
  display: flex;
  gap: 1.5rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

@media (max-width: 767px) {
  .nav-list {
    position: fixed;
    top: calc(var(--touch-min) + 12px + var(--safe-top));
    left: 0;
    right: 0;
    bottom: 0;
    flex-direction: column;
    background: var(--color-bg);
    padding: calc(var(--touch-min) + 1rem + var(--safe-top)) 1.5rem 1.5rem;
    padding-left: max(1.5rem, env(safe-area-inset-left));
    gap: 0;
    z-index: 99998;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .nav-list.open {
    transform: translateX(0);
  }

  .nav-list li {
    border-bottom: 1px solid var(--color-border);
  }

  .nav-list .nav-link {
    display: block;
    padding: 1rem 0;
    min-height: var(--touch-min);
    font-size: 1.125rem;
  }
}

.nav-link {
  color: var(--color-text-muted);
  text-decoration: none;
}

.nav-link:hover {
  color: var(--color-accent);
}

.nav-link-active {
  color: var(--color-accent);
}

/* --- Footer --- */
.footer {
  padding: 1rem;
  padding-bottom: calc(1rem + var(--safe-bottom));
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
}

@media (min-width: 640px) {
  .footer { padding: 1rem 1.5rem; }
}

.footer-text {
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

/* --- Typography --- */
.heading-1 {
  font-size: clamp(1.5rem, 5vw, 2rem);
  font-weight: 700;
  margin: 0 0 0.5rem;
  color: var(--color-text);
  line-height: 1.25;
}

.heading-2 {
  font-size: clamp(1.125rem, 3vw, 1.25rem);
  font-weight: 600;
  margin: 0 0 0.75rem;
  color: var(--color-text);
}

.lead {
  font-size: clamp(0.9375rem, 2vw, 1.125rem);
  color: var(--color-text-muted);
  margin: 0 0 1.5rem;
}

.text-muted {
  color: var(--color-text-muted);
  margin: 0;
}

/* --- Sections --- */
.section {
  margin-bottom: 2rem;
}

.hero {
  text-align: center;
  padding: 2rem 0;
}

/* --- Cards --- */
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

@media (max-width: 480px) {
  .card-header {
    flex-direction: column;
    align-items: stretch;
  }
}

.card-header .heading-2 {
  margin: 0;
}

.card-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.card:hover {
  background: var(--color-surface-hover);
}

.card-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

@media (min-width: 480px) {
  .card-grid {
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  }
}

@media (min-width: 640px) {
  .card-grid {
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  }
}

.card-source {
  display: flex;
  flex-direction: column;
}

.card-source .card-title {
  font-size: 1.125rem;
  font-weight: 600;
  margin: 0 0 0.5rem;
}

.card-source .card-desc {
  font-size: 0.9375rem;
  color: var(--color-text-muted);
  line-height: 1.5;
  margin: 0 0 0.75rem;
  flex: 1;
}

.card-source .card-meta {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
}

/* Tarjeta como botón (listado jugadores) */
.card-player-btn {
  width: 100%;
  text-align: left;
  cursor: pointer;
  font: inherit;
  color: inherit;
  border: 1px solid var(--color-border);
}
.card-player-btn .card-title {
  color: var(--color-accent);
}
.card-player-btn:hover {
  border-color: var(--color-accent);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}
.card-player-btn:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 2px rgba(88, 166, 255, 0.3);
}

/* --- Modal detalle jugador (ancho completo para tablas) --- */
.player-modal {
  position: fixed;
  inset: 0;
  z-index: 10000;
  visibility: hidden;
  opacity: 0;
  transition: visibility 0.2s, opacity 0.2s;
}
.player-modal.player-modal-open {
  visibility: visible;
  opacity: 1;
}
.player-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  cursor: pointer;
}
.player-modal-dialog {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) scale(0.96);
  width: 92vw;
  max-width: 900px;
  max-height: 90vh;
  background: var(--color-bg);
  border-radius: var(--radius-lg, 12px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transition: transform 0.25s ease-out, opacity 0.25s ease-out;
}
.player-modal.player-modal-open .player-modal-dialog {
  transform: translate(-50%, -50%) scale(1);
  opacity: 1;
}
.player-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}
.player-modal-title {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--color-text);
}
.player-modal-close {
  width: 2.5rem;
  height: 2.5rem;
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  border-radius: var(--radius);
  transition: background 0.2s, color 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.player-modal-close:hover {
  background: var(--color-surface-hover);
  color: var(--color-text);
}
.player-modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
  padding-bottom: 2rem;
}
/* Tablas dentro del modal usan todo el ancho disponible */
.player-modal-body .table-wrap {
  width: 100%;
  overflow-x: auto;
}
.player-modal-body .table {
  min-width: 100%;
}

/* --- Empty state (cuando no hay datos) --- */
.empty-state {
  text-align: center;
  padding: 2rem 1.5rem;
  color: var(--color-text-muted);
}
.empty-state-icon {
  font-size: 2.5rem;
  display: block;
  margin-bottom: 0.75rem;
  opacity: 0.8;
}
.empty-state-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text);
  margin: 0 0 0.35rem;
}
.empty-state-desc {
  font-size: 0.875rem;
  margin: 0;
}

/* --- Buttons --- */
.btn {
  display: inline-block;
  padding: 0.75rem 1.25rem;
  min-height: var(--touch-min);
  font-size: 0.9375rem;
  font-weight: 500;
  text-align: center;
  text-decoration: none;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  -webkit-tap-highlight-color: transparent;
}

@media (min-width: 640px) {
  .btn { padding: 0.5rem 1rem; min-height: auto; }
}

.btn-primary {
  background: var(--color-accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--color-accent-hover);
}

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

.btn-secondary:hover {
  background: var(--color-surface-hover);
}

/* --- Search row (Jugadores list) --- */
.player-search-wrap {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: center;
}
.player-search-wrap .search-input {
  flex: 1;
  min-width: 200px;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-bg);
  color: var(--color-text);
}
.player-search-wrap .search-input::placeholder {
  color: var(--color-text-muted);
  opacity: 0.8;
}
.player-search-wrap .search-input:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 2px rgba(88, 166, 255, 0.2);
}

/* --- Filtros (La Liga y similares): selects con buen aspecto --- */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.filter-group {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.375rem 0.75rem;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.filter-group:hover {
  border-color: var(--color-surface-hover);
}
.filter-group:focus-within {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 2px rgba(88, 166, 255, 0.15);
}
.filter-group label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--color-text-muted);
  white-space: nowrap;
}
.filter-select {
  font-size: 0.9375rem;
  color: var(--color-text);
  background: transparent;
  border: none;
  padding: 0.25rem 1.75rem 0.25rem 0;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%238b949e' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.35rem center;
  min-width: 7rem;
}
.filter-select:focus {
  outline: none;
}
.filter-select option {
  background: var(--color-surface);
  color: var(--color-text);
}
.la-liga-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  justify-content: space-between;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  border: 0;
}

/* --- Jugadores list: cards as links --- */
.card-grid .card-source {
  text-decoration: none;
  color: inherit;
  transition: background 0.2s, border-color 0.2s, transform 0.15s;
}
.card-grid .card-source:hover {
  border-color: var(--color-accent);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}
.card-grid .card-source .card-title {
  color: var(--color-accent);
  font-size: 1.125rem;
}
.card-grid .card-source:hover .card-title {
  color: var(--color-accent-hover);
}

/* --- Jugador detalle --- */
.breadcrumb {
  font-size: 0.9375rem;
  color: var(--color-text-muted);
  margin-bottom: 1rem;
}
.breadcrumb a {
  color: var(--color-accent);
  text-decoration: none;
}
.breadcrumb a:hover {
  text-decoration: underline;
}
.player-name {
  margin-top: 0;
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text);
}
.card-section {
  padding: 1.25rem 1.5rem;
}
.card-section:hover {
  background: var(--color-surface);
}
.card-section .heading-2 {
  margin-bottom: 0.5rem;
}
.card-section .text-muted {
  margin-bottom: 0.75rem;
  font-size: 0.875rem;
}

/* --- Desplegables (details/summary) en ficha jugador --- */
.card-dropdown {
  padding: 0;
  overflow: hidden;
}
.card-dropdown .dropdown-summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  cursor: pointer;
  user-select: none;
  transition: background 0.2s;
}
.card-dropdown .dropdown-summary:hover {
  background: var(--color-surface-hover);
}
.card-dropdown .dropdown-summary::-webkit-details-marker,
.card-dropdown .dropdown-summary::marker {
  display: none;
}
.card-dropdown .dropdown-summary .heading-2 {
  margin: 0;
}
.dropdown-arrow {
  width: 0.5rem;
  height: 0.5rem;
  border-right: 2px solid var(--color-text-muted);
  border-bottom: 2px solid var(--color-text-muted);
  transform: rotate(45deg);
  margin-left: 0.5rem;
  transition: transform 0.2s;
}
.card-dropdown[open] .dropdown-arrow {
  transform: rotate(-135deg);
}
.card-dropdown .text-muted,
.card-dropdown .player-detail-grid,
.card-dropdown .table-wrap {
  padding: 0 1.5rem 1.25rem;
}
.card-dropdown .text-muted {
  padding-top: 0;
  margin-top: -0.5rem;
}

.player-detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem 1.5rem;
}
.player-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--color-border);
}
.player-field:last-child {
  border-bottom: none;
}
.player-field-label {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.player-field-value {
  font-weight: 500;
  font-size: 1rem;
}
.mb-2 { margin-bottom: 1rem; }

/* --- Tables --- */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9375rem;
}

.table th,
.table td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
}

.table th {
  font-weight: 600;
  color: var(--color-text-muted);
  font-size: 0.8125rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: var(--color-bg);
}

.table tbody tr:hover {
  background: var(--color-surface-hover);
}

.table tbody tr:last-child td {
  border-bottom: none;
}

/* --- Estado fuentes (Data Panel) --- */
.source-status {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius);
  font-size: 0.8125rem;
  font-weight: 500;
}
.source-status-ok {
  background: rgba(34, 197, 94, 0.15);
  color: #22c55e;
}
.source-status-empty {
  background: rgba(234, 179, 8, 0.2);
  color: #eab308;
}
.source-status-error {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
}

/* --- Utilities --- */
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }

.text-center { text-align: center; }
.text-right { text-align: right; }

/* --- Valor por año (chips) --- */
.value-by-year-wrap {
  margin-bottom: 0.75rem;
}
.value-by-year-title {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  margin-bottom: 0.5rem;
}
.value-by-year-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.value-chip {
  display: inline-block;
  padding: 0.35rem 0.65rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
}

/* --- Responsive tables --- */
@media (max-width: 640px) {
  .table th, .table td {
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
  }
}
