:root {
  --primary: #4f8cff;
  --secondary: #232b3a;
  --dark-bg: #181c24;
  --light-text: #ffffff;
  --border: #e0e0e0;
  --error: #ff4444;
  --success: #44ff44;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: var(--dark-bg);
  color: #333;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

/* Header */
.header {
  text-align: center;
  margin-bottom: 40px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  padding: 40px 20px;
  border-radius: 12px;
  color: var(--light-text);
}

.header h1 {
  font-size: 2.5rem;
  margin-bottom: 8px;
  font-weight: 700;
}

.header .subtitle {
  font-size: 1.1rem;
  opacity: 0.9;
}

/* Search Section */
.search-section {
  margin-bottom: 40px;
  background: white;
  padding: 30px;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.search-form {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}

.input-field {
  flex: 1;
  min-width: 200px;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  transition: all 0.3s ease;
}

.input-field:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 140, 255, 0.1);
}

.btn {
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: #3d6acc;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(79, 140, 255, 0.3);
}

.btn-secondary {
  background: var(--secondary);
  color: white;
}

.btn-secondary:hover {
  background: #1a2233;
}

.error-message {
  color: var(--error);
  margin-top: 12px;
  font-weight: 500;
  display: none;
}

.error-message.show {
  display: block;
}

.loading {
  display: none;
  margin-top: 12px;
  color: var(--primary);
  font-weight: 500;
}

.loading.show {
  display: block;
}

.loading::after {
  content: '';
  animation: dots 1.4s infinite;
}

@keyframes dots {
  0%, 20% { content: '.'; }
  40% { content: '..'; }
  60%, 100% { content: '...'; }
}

/* Sections */
.standings-section,
.team-section,
.lineup-section,
.league-players-section,
.info-section {
  background: white;
  padding: 30px;
  border-radius: 12px;
  margin-bottom: 30px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.hidden {
  display: none !important;
}

/* League Name */
.league-title {
  color: var(--primary);
  margin-bottom: 20px;
  font-size: 1.8rem;
}

/* Table */
.table-responsive {
  overflow-x: auto;
}

.standings-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.standings-table thead {
  background: var(--secondary);
  color: white;
}

.standings-table th {
  padding: 16px;
  text-align: left;
  font-weight: 600;
}

.standings-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.standings-table tbody tr:hover {
  background: #f5f5f5;
}

.rank-1 { color: var(--primary); font-weight: 700; }
.rank-2 { color: #888; }
.rank-3 { color: #cc9966; }

/* Transfers Column */
.transfers-cell {
  font-size: 0.9rem;
  color: #666;
  text-align: center;
}

.transfers-cell:hover {
  background: rgba(79, 140, 255, 0.1);
  cursor: help;
}

.points-badge {
  background: #c82333;
  color: white;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.8rem;
  font-weight: 600;
}

/* Chips Column */
.chips-cell {
  font-size: 1.1rem;
  color: #666;
  text-align: center;
  font-family: monospace;
  letter-spacing: 0.2rem;
  font-weight: 600;
  min-width: 120px;
}
  font-size: 0.8rem;
  font-weight: bold;
  margin-left: 4px;
}

/* Team Details */
.team-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
  margin-top: 20px;
}

.team-card {
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: white;
  padding: 24px;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.team-card h3 {
  font-size: 1.5rem;
  margin-bottom: 20px;
}

.team-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-label {
  font-size: 0.9rem;
  opacity: 0.85;
  font-weight: 500;
}

.stat-value {
  font-size: 1.8rem;
  font-weight: 700;
}

/* Lineup Section */
.lineup-controls {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 20px;
  justify-content: center;
}

/* Gameweek History */
.history-section {
  margin-top: 20px;
  background: white;
  padding: 20px;
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.chart-wrapper {
  width: 100%;
  height: 220px;
  position: relative;
}

#historyChart {
  width: 100% !important;
  height: 220px !important;
}

/* Team Navigation */
.team-nav {
  display: flex;
  gap: 10px;
  margin: 20px 0;
  justify-content: center;
}

.team-nav .btn.active {
  background: var(--primary);
  color: white;
}

/* Transfer History */
.transfers-section {
  margin-top: 20px;
  background: white;
  padding: 20px;
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.transfers-container {
  max-height: 600px;
  overflow-y: auto;
}

.transfers-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.transfer-item {
  display: flex;
  align-items: center;
  padding: 16px;
  background: #f8f9fa;
  border-radius: 8px;
  border-left: 4px solid var(--primary);
}

.transfer-time {
  font-size: 0.85rem;
  color: #666;
  margin-bottom: 4px;
}

.transfer-players {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 1;
}

.transfer-player {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  min-width: 120px;
}

.transfer-player.in {
  color: #28a745;
}

.transfer-player.out {
  color: #dc3545;
}

.transfer-player .player-name {
  font-weight: 600;
  font-size: 0.9rem;
}

.transfer-player .player-web-name {
  font-size: 0.8rem;
  opacity: 0.8;
  margin-top: 2px;
}

.transfer-player .player-cost {
  font-size: 0.75rem;
  margin-top: 2px;
  padding: 2px 6px;
  background: rgba(0,0,0,0.1);
  border-radius: 4px;
}

.transfer-arrow {
  font-size: 1.2rem;
  color: var(--primary);
  margin: 0 8px;
}

.transfer-gw {
  font-size: 0.8rem;
  color: var(--primary);
  font-weight: 600;
  background: rgba(79, 140, 255, 0.1);
  padding: 4px 8px;
  border-radius: 12px;
  margin-left: 12px;
}

/* Chips Section */
.chips-section {
  margin-top: 20px;
  background: white;
  padding: 20px;
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.chips-container {
  max-height: 400px;
  overflow-y: auto;
}

.chips-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chip-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: #f8f9fa;
  border-radius: 8px;
  border-left: 4px solid var(--primary);
}

.chip-name {
  font-weight: 600;
  font-size: 0.95rem;
  color: #333;
  display: flex;
  align-items: center;
  gap: 6px;
}

.chip-meta {
  display: flex;
  gap: 12px;
  align-items: center;
}

.chip-gw {
  font-weight: 600;
  color: var(--primary);
  padding: 4px 8px;
  background: rgba(79, 140, 255, 0.1);
  border-radius: 4px;
  font-size: 0.85rem;
}

.chip-time {
  font-size: 0.8rem;
  color: #666;
}

#gwDisplay {
  font-weight: 600;
  color: var(--primary);
  min-width: 120px;
  text-align: center;
}

.lineup-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 16px;
  margin-top: 20px;
}

.player-card {
  background: linear-gradient(135deg, #f9f9f9, #ffffff);
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  text-align: center;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.player-card:hover {
  border-color: var(--primary);
  box-shadow: 0 4px 12px rgba(79, 140, 255, 0.2);
  transform: translateY(-4px);
}

.player-card.is-captain {
  border-color: #ffd700;
  background: linear-gradient(135deg, #fffacd, #ffffff);
}

.ownership-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(76, 175, 80, 0.3);
  z-index: 0;
  transition: height 0.3s ease;
}

.player-name {
  font-weight: 600;
  color: #333;
  margin-bottom: 4px;
  font-size: 0.95rem;
  position: relative;
  z-index: 1;
}

.player-position {
  font-size: 0.8rem;
  color: #666;
  margin-bottom: 8px;
  position: relative;
  z-index: 1;
}

.player-points {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--primary);
  position: relative;
  z-index: 1;
}

.captain-badge {
  display: inline-block;
  background: #ffd700;
  color: #333;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 700;
  margin-top: 8px;
  position: relative;
  z-index: 1;
}

/* Info Section */
.note {
  color: #666;
  font-size: 0.95rem;
  margin-bottom: 12px;
  line-height: 1.6;
}

.note code {
  background: #f5f5f5;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  color: var(--primary);
}

/* Ownership tooltip */
.ownership-tooltip {
  position: absolute;
  background: white;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  font-size: 0.85rem;
  max-width: 200px;
  z-index: 1000;
  display: none;
}

.ownership-row {
  padding: 2px 0;
}

.ownership-row.owned {
  font-weight: 600;
  color: #333;
}

.ownership-row:not(.owned) {
  color: #bbb;
}

/* league players section - inherits from main section styles */

.players-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
  background: white;
}

.players-table thead {
  background: var(--secondary);
  color: white;
  position: sticky;
  top: 0;
}

.players-table th {
  padding: 14px 16px;
  text-align: left;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  border-bottom: 2px solid var(--primary);
}

.players-table th:hover {
  background: #1e3a5f;
}

.players-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.players-table tbody tr {
  background: white;
}

.players-table tbody tr:hover {
  background: #f9f9f9;
}

.players-table tbody tr.missing-player {
  background: rgba(200, 35, 51, 0.08);
}

.players-table tbody tr.missing-player:hover {
  background: rgba(200, 35, 51, 0.12);
}

.players-table tbody tr.missing-player td {
  color: #c82333;
}

.ownership-col {
  font-weight: 600;
  color: var(--primary);
}

/* Responsive */
@media (max-width: 768px) {
  .container {
    padding: 12px;
  }

  .header h1 {
    font-size: 1.8rem;
  }

  .search-form {
    flex-direction: column;
  }

  .input-field,
  .btn {
    width: 100%;
  }

  .standings-table {
    font-size: 0.85rem;
  }

  .standings-table th,
  .standings-table td {
    padding: 8px;
  }

  .team-stats {
    grid-template-columns: 1fr;
  }

  .lineup-grid {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  }
}
