/* ==========================================================================
   MASTER STYLESHEET
   ========================================================================== */
/* ==========================================================================
   DESIGN TOKENS & CSS VARIABLES
   ========================================================================== */
:root {
  /* --- Dark Theme (Default) --- */
  --bg-primary: #0a0e17;
  --bg-secondary: #131b2e;
  --bg-card: #1a233a;
  --bg-hover: #24304f;

  --text-primary: #f1f5f9;
  --text-muted: #94a3b8;
  --border-color: #2e3a59;

  --accent-primary: #3b82f6;
  --accent-success: #10b981;
  --accent-warning: #f59e0b;
  --accent-danger: #ef4444;
  --accent-favorite: #f59e0b;

  /* --- Typography --- */
  --font-family: "Inter", system-ui, -apple-system, sans-serif;

  /* --- Elevation & Depth --- */
  --shadow-lg: 0 4px 20px rgba(0, 0, 0, 0.25);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.1);

  /* --- Sizing & Space --- */
  --radius-md: 12px;
  --radius-sm: 8px;

  /* --- Animation --- */
  --transition: all 0.25s ease-in-out;
}

/* --- Light Theme Overrides --- */
[data-theme="light"] {
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-hover: #f1f5f9;

  --text-primary: #0f172a;
  --text-muted: #64748b;
  --border-color: #e2e8f0;

  --shadow-lg: 0 4px 20px rgba(0, 0, 0, 0.05);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.02);
}

/* ==========================================================================
   RESET & BASE LAYOUT
   ========================================================================== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Base Accessibility: Smooth Scrolling & Motion Reduction */
html {
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

body {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-family);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Root Layout Container */
.dashboard-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: 1rem;
  gap: 1.25rem;
  max-width: 1600px;
  margin: 0 auto;
}

/* Visually Hidden Utility for Accessibility */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* Prevents CSS Grid / Flex children from expanding past parent cards on mobile */
.dashboard-grid,
.card,
.card-header,
.table-container,
.chart-wrapper {
  min-width: 0;
  width: 100%;
}

/* Ensure comparison controls stack vertically when screen space gets tight */
.comparison-controls {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.75rem;
  width: 100%;
}

.comparison-selectors {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
}

.comparison-selectors select {
  flex: 1;
  min-width: 0;
}

/* ==========================================================================
   MAIN DASHBOARD GRID & CARDS
   ========================================================================== */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
  flex: 1;
}

/* Shared Card Component */
.card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  content-visibility: auto;
  contain-intrinsic-size: 1px 300px;
}

/* Card Header Layout */
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-color);
  flex-wrap: wrap;
  gap: 0.75rem;
}

.card-header h2 {
  font-size: 1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-primary);
}

.header-action-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.filter-group input {
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  background-color: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  outline: none;
  font-family: inherit;
  font-size: 0.88rem;
}

/* Text Utilities */
.text-success {
  color: var(--accent-success);
}
.text-danger {
  color: var(--accent-danger);
}
.text-muted {
  color: var(--text-muted);
}

/* ==========================================================================
   HEADER & CONTROLS
   ========================================================================== */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: var(--bg-card);
  padding: 1rem 1.25rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-lg);
  flex-wrap: wrap;
  gap: 1rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-icon {
  font-size: 1.5rem;
  color: var(--accent-primary);
}

.brand h1 {
  font-size: 1.25rem;
  font-weight: 700;
}

.brand h1 span {
  color: var(--accent-primary);
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.control-select {
  background-color: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  padding: 0.5rem 0.85rem;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.88rem;
  outline: none;
  cursor: pointer;
  transition: var(--transition);
}

.control-select:hover {
  border-color: var(--accent-primary);
}

.btn-icon {
  background-color: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: var(--transition);
  flex-shrink: 0;
}

.btn-icon:hover {
  background-color: var(--bg-hover);
  border-color: var(--accent-primary);
}

/* ==========================================================================
   STANDINGS TABLE COMPONENT
   ========================================================================== */
.table-container {
  width: 100%;
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  -webkit-overflow-scrolling: touch;
}

/* Gridlines & Table Layout */
#standings-table,
.standings-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  table-layout: auto;
}

/* Header Cells with Vertical/Horizontal Gridlines */
#standings-table th,
.standings-table th {
  background-color: var(--bg-secondary);
  color: var(--text-muted);
  padding: 0.75rem 0.6rem;
  font-weight: 600;
  border-bottom: 2px solid var(--border-color);
  border-right: 1px solid var(--border-color);
  user-select: none;
  white-space: nowrap;
}

/* Data Cells with Vertical/Horizontal Gridlines */
#standings-table td,
.standings-table td {
  padding: 0.65rem 0.6rem;
  border-bottom: 1px solid var(--border-color);
  border-right: 1px solid var(--border-color);
  white-space: nowrap;
  transition: var(--transition);
}

/* Clean up outer right border */
#standings-table th:last-child,
#standings-table td:last-child,
.standings-table th:last-child,
.standings-table td:last-child {
  border-right: none;
}

/* Alternating Row Backgrounds */
#standings-table tbody tr:nth-child(even),
.standings-table tbody tr:nth-child(even) {
  background-color: rgba(255, 255, 255, 0.02);
}

[data-theme="light"] #standings-table tbody tr:nth-child(even),
[data-theme="light"] .standings-table tbody tr:nth-child(even) {
  background-color: rgba(0, 0, 0, 0.025);
}

/* Hover Row Highlight */
#standings-table tbody tr:hover,
.standings-table tbody tr:hover {
  background-color: var(--bg-hover) !important;
}

/* Table Column Alignments & Utilities */
.col-pin {
  text-align: center;
  width: 36px;
}
.col-rank {
  text-align: center;
  width: 40px;
}
.col-team {
  font-weight: 500;
  text-align: left;
  padding-right: 1.5rem !important;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.col-stat {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.col-goals {
  color: var(--text-muted);
}
.col-pts {
  font-weight: 700;
  color: var(--accent-primary);
}
.col-gd {
  font-weight: 600;
}
.col-form {
  text-align: center;
  width: 130px;
  min-width: 120px;
}

/* Pinned Row Styling */
#standings-table tr.pinned-row,
.standings-table tr.pinned-row {
  background-color: rgba(245, 158, 11, 0.08) !important;
}

#standings-table tr.pinned-row:hover,
.standings-table tr.pinned-row:hover {
  background-color: rgba(245, 158, 11, 0.14) !important;
}

/* Form Badges */
.form-group {
  display: flex;
  gap: 3px;
  justify-content: center;
}

.form-badge {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 700;
  color: #ffffff;
}

.badge-win {
  background-color: var(--accent-success);
}
.badge-draw {
  background-color: var(--accent-warning);
}
.badge-loss {
  background-color: var(--accent-danger);
}

/* Favorites Component */
.btn-pin {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 4px;
  transition:
    transform 0.15s ease,
    color 0.15s ease;
}

.btn-pin:hover,
.btn-pin.active {
  color: var(--accent-favorite);
}

.btn-pin:hover {
  transform: scale(1.2);
}

/* ==========================================================================
   CHART & ANALYTICS COMPONENT
   ========================================================================== */
.comparison-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.chart-type-toggle {
  display: flex;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
}

.btn-toggle {
  background: transparent;
  border: none;
  color: var(--text-muted);
  width: 32px;
  height: 30px;
  border-radius: 6px;
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 0.85rem;
  transition: var(--transition);
}

.btn-toggle:hover {
  color: var(--text-primary);
}

.btn-toggle.active {
  background-color: var(--accent-primary);
  color: #ffffff;
}

.comparison-selectors {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--accent-primary);
}

.comparison-selectors .versus {
  color: var(--text-muted);
  font-size: 0.75rem;
}

.chart-wrapper {
  position: relative;
  width: 100%;
  min-height: 280px;
  aspect-ratio: 16 / 9;
  margin-top: 1rem;
}

/* ==========================================================================
   UPCOMING MATCHES COMPONENT
   ========================================================================== */
.fixtures-container {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  /* Restrain height to align nicely with desktop grid layout */
  max-height: 480px;
  overflow-y: auto;
  padding-right: 0.25rem; /* Space for custom scrollbar */
}

/* Custom Scrollbar Styling for Fixtures Container */
.fixtures-container::-webkit-scrollbar {
  width: 6px;
}

.fixtures-container::-webkit-scrollbar-track {
  background: var(--bg-secondary);
  border-radius: 4px;
}

.fixtures-container::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

.fixtures-container::-webkit-scrollbar-thumb:hover {
  background: var(--accent-primary);
}

.fixture-card {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.85rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: var(--transition);
}

.fixture-card:hover {
  border-color: var(--accent-primary);
  transform: translateY(-2px);
}

.fixture-teams {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  flex: 1;
}

.team-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.88rem;
  font-weight: 500;
}

.team-score {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--accent-primary);
  min-width: 18px;
  text-align: right;
}

.fixture-meta {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.fixture-card.live-card {
  border-left: 3px solid var(--accent-danger);
  background-color: rgba(239, 68, 68, 0.05);
}

.fixture-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.badge-live {
  background-color: rgba(239, 68, 68, 0.15);
  color: var(--accent-danger);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.badge-finished {
  background-color: var(--bg-hover);
  color: var(--text-muted);
}

.pulse-dot {
  width: 6px;
  height: 6px;
  background-color: var(--accent-danger);
  border-radius: 50%;
  box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
  animation: pulse-ring 1.5s infinite cubic-bezier(0.66, 0, 0, 1);
}

@keyframes pulse-ring {
  0% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
  }
  70% {
    box-shadow: 0 0 0 6px rgba(239, 68, 68, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
  }
}

/* ==========================================================================
   FOOTER COMPONENT
   ========================================================================== */
.app-footer {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 1rem 0;
  border-top: 1px solid var(--border-color);
  margin-top: auto;
}

/* ==========================================================================
   MOBILE & RESPONSIVE LAYOUT
   ========================================================================== */

/* --- Desktop (>= 1025px) --- */
@media (min-width: 64.1em) {
  .dashboard-grid {
    grid-template-columns: 1.2fr 0.8fr;
    grid-template-areas:
      "standings analytics"
      "standings fixtures";
  }

  .standings-card {
    grid-area: standings;
  }
  .analytics-card {
    grid-area: analytics;
  }
  .fixtures-card {
    grid-area: fixtures;
  }
}

/* --- Tablet Breakpoint (<= 1024px) --- */
@media (max-width: 64em) {
  .dashboard-grid {
    grid-template-columns: 1fr;
    grid-template-areas: none;
  }

  .comparison-controls {
    justify-content: space-between;
    width: 100%;
  }
}

/* --- Mobile Breakpoint (<= 640px) --- */
@media (max-width: 40em) {
  .dashboard-container {
    padding: 0.5rem;
    gap: 0.85rem;
  }

  /* Header Controls Stacking */
  .app-header {
    flex-direction: column;
    align-items: stretch;
    padding: 0.85rem;
    gap: 0.75rem;
  }

  .brand h1 {
    font-size: 1.1rem;
  }

  .header-controls {
    width: 100%;
    display: flex;
    gap: 0.5rem;
  }

  .header-controls select {
    flex: 1;
    min-width: 0;
  }

  /* Card Header Mobile Tuning */
  .card {
    padding: 0.85rem;
  }

  .card-header {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }

  .header-action-group {
    width: 100%;
    display: flex;
    gap: 0.5rem;
  }

  .filter-group {
    flex: 1;
  }

  .filter-group input {
    width: 100%;
  }

  /* Chart & Analytics Responsive Scaling */
  .chart-wrapper {
    min-height: 220px;
    height: 260px;
  }

  /* Sticky Standings Table - Touch UX */
  .table-container {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--border-color);
  }

  #standings-table th,
  #standings-table td,
  .standings-table th,
  .standings-table td {
    padding: 0.5rem 0.35rem;
    font-size: 0.78rem;
  }

  /* Sticky Column Calculations */
  .col-pin-head,
  .col-pin {
    position: sticky;
    left: 0;
    width: 36px;
    min-width: 36px;
    max-width: 36px;
    background-color: var(--bg-card) !important;
    z-index: 3;
    border-right: 1px solid var(--border-color);
  }

  .col-rank-head,
  .col-rank {
    position: sticky;
    left: 36px;
    width: 36px;
    min-width: 36px;
    max-width: 36px;
    background-color: var(--bg-card) !important;
    z-index: 3;
    border-right: 1px solid var(--border-color);
  }

  .col-team-head,
  .col-team {
    position: sticky;
    left: 72px;
    max-width: 130px;
    background-color: var(--bg-card) !important;
    box-shadow: 3px 0 6px -1px rgba(0, 0, 0, 0.4);
    z-index: 3;
    border-right: 2px solid var(--border-color);
  }
}
