/* ============================================================
   AADS Stat Tracker — Dark Theme Stylesheet
   bg #222, text #eee, accent #ffcc00, header red #ff5555
   ============================================================ */

/* --- Loading Spinner --- */
#page-loader {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: #222;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.3s ease;
}
#page-loader.hidden {
  opacity: 0;
  pointer-events: none;
}
.spinner {
  width: 48px;
  height: 48px;
  border: 5px solid #444;
  border-top-color: #ffcc00;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* --- Base --- */
body {
  background: #222;
  color: #eee;
  font-family: Verdana, sans-serif;
  margin: 0;
  padding: 0;
}
a { color: #ffcc00; text-decoration: none; }

.header { text-align: center; margin: 20px 0; }

/* --- Form Box --- */
.form-box {
  background: #444;
  padding: 10px;
  margin: 10px auto 20px;
  width: 90%;
  border-radius: 6px;
  box-sizing: border-box;
}

/* --- Tables --- */
.table-wrap {
  position: relative;
  width: 95%;
  margin: 0 auto;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
/* Scroll fade indicator on right edge */
.table-wrap.can-scroll-right::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  width: 32px;
  height: 100%;
  background: linear-gradient(to right, transparent, rgba(34,34,34,0.85));
  pointer-events: none;
  z-index: 2;
}

table {
  border-collapse: collapse;
  margin: auto;
  width: 100%;
  background: #333;
}
th, td {
  padding: 6px 10px;
  border: 1px solid #555;
  text-align: left;
  white-space: nowrap;
}
th {
  background: #ff5555;
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 3;
}
th a { color: #fff; }

/* Sticky first column */
td:first-child {
  position: sticky;
  left: 0;
  z-index: 4;
  background: #333;
}
th:first-child {
  position: sticky;
  left: 0;
  z-index: 5;
  background: #ff5555;
}

/* --- Filter Toggles --- */
.filter-toggles {
  margin-left: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
}
.filter-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #eee;
  font-size: 0.95em;
}
.filter-toggle input[type="checkbox"] {
  accent-color: #ff5555;
}

/* --- Info Icon / Tooltip --- */
.info-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #777;
  color: #111;
  font-size: 0.75em;
  font-weight: bold;
  cursor: pointer;
  position: relative;
}
.info-icon .tooltip {
  position: absolute;
  bottom: 140%;
  left: 50%;
  transform: translateX(-50%);
  background: #111;
  color: #fff;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 0.8em;
  width: 210px;
  max-width: 240px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
  z-index: 10;
}
.info-icon .tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border-width: 6px;
  border-style: solid;
  border-color: #111 transparent transparent transparent;
}
.info-icon:hover .tooltip,
.info-icon:focus .tooltip,
.info-icon:focus-within .tooltip {
  opacity: 1;
}

/* --- System ID Badge --- */
.system-id-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  margin-left: 6px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2ecc71, #27ae60);
  color: #0b2d17;
  font-size: 0.85em;
  font-weight: 800;
  border: 1px solid #1f8e4d;
  box-shadow: 0 1px 3px rgba(0,0,0,0.5);
  vertical-align: middle;
}

/* --- Topbar --- */
.topbar {
  width: 90%;
  margin: 15px auto 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
  z-index: 3;
}
.topbar .left { display: flex; gap: 10px; align-items: center; }
.topbar .right { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.pill {
  display: inline-block;
  padding: 4px 10px;
  background: #444;
  border-radius: 999px;
  border: 1px solid #555;
}
.pill:hover { filter: brightness(1.1); }
.topbar .left .pill { background: #5865F2; border-color: #6b75f3; color: #fff; }

/* --- Filter Chips --- */
.chips {
  width: 90%;
  margin: 0 auto 10px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.chip {
  background: #2b2b2b;
  border: 1px solid #555;
  border-radius: 999px;
  padding: 3px 10px;
}
.chip a { color: #ffcc00; margin-left: 8px; }

/* --- Date Form --- */
.dateform {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
  flex-wrap: wrap;
}
.dateform label { color: #ddd; font-size: 14px; }
input[type="date"], select {
  background: #2a2a2a;
  color: #eee;
  border: 1px solid #555;
  padding: 4px 6px;
  border-radius: 4px;
}
mark { background: #ffd54a; color: #222; padding: 0 2px; border-radius: 2px; }

/* --- Collapsible Sections (player view) --- */
.section {
  background: #2a2a2a;
  margin: 15px auto;
  border-radius: 12px;
  width: 95%;
  box-shadow: 0 0 15px rgba(255,204,0,0.3);
  overflow: hidden;
  transition: box-shadow 0.2s ease-in-out;
}
.section:hover { box-shadow: 0 0 20px rgba(255,204,0,0.5); }
.section h3 {
  margin: 0;
  padding: 10px;
  background: #444;
  color: #fff;
  cursor: pointer;
  user-select: none;
  border-top-left-radius: 12px;
  border-top-right-radius: 12px;
}
.content {
  display: none;
  padding: 10px;
  border-bottom-left-radius: 12px;
  border-bottom-right-radius: 12px;
}
.section.open .content { display: block; }

/* --- Grid / Stat Cards --- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}
.stat {
  padding: 6px;
  background: #2a2a2a;
  border-left: 6px solid #ffcc00;
  border-radius: 4px;
  color: #eee;
}
.stat b { color: #ffcc00; }
sup { color: #ffcc00; font-size: 0.8em; }

/* --- Games / Match Detail --- */
.match-header {
  text-align: center;
  margin: 10px auto;
  font-size: 20px;
  font-weight: bold;
}
.teams-grid {
  width: 95%;
  margin: 10px auto 20px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.team-col {
  background: #2a2a2a;
  border: 1px solid #555;
  border-radius: 10px;
  padding: 10px;
}
.team-col h4 { margin: 0 0 8px 0; text-align: center; color: #ffcc00; }
.player-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 8px;
  border-bottom: 1px dashed #555;
}
.player-row:last-child { border-bottom: none; }
.btn {
  display: inline-block;
  padding: 4px 8px;
  border: 1px solid #666;
  border-radius: 6px;
  background: #444;
  color: #fff;
  text-decoration: none;
}

/* --- Scoreboard Tables (match detail) --- */
.scoreboard { width: 100%; border-collapse: collapse; }
.scoreboard th, .scoreboard td { padding: 6px 8px; border-bottom: 1px dashed #555; }
.scoreboard th { text-align: left; color: #c8b6ff; font-weight: 600; }
.scoreboard thead th { background: #b36b6b; color: #fff; }
.scoreboard td.num { text-align: right; font-variant-numeric: tabular-nums; }
.scoreboard tfoot td { font-weight: 700; border-top: 1px solid #666; }


/* ============================================================
   Responsive — Tablet (<=900px)
   ============================================================ */
@media (max-width: 900px) {
  th, td { padding: 4px 6px; }
  .pill { padding: 3px 8px; }
  .teams-grid { grid-template-columns: 1fr; }
}

/* ============================================================
   Responsive — Mobile (<=768px)
   ============================================================ */
@media (max-width: 768px) {
  body {
    font-size: 14px;
  }

  /* Topbar stacks vertically */
  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    width: 95%;
  }
  .topbar .left,
  .topbar .right {
    flex-wrap: wrap;
    justify-content: flex-start;
    width: 100%;
    gap: 8px;
  }

  /* 44px minimum touch targets */
  .topbar .pill,
  .topbar .right a,
  .topbar .left a,
  .pill,
  .btn,
  .chip a {
    min-height: 44px;
    padding: 8px 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* Chips stack */
  .chips {
    flex-direction: column;
    width: 95%;
  }
  .chip {
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  /* Form box full width */
  .form-box {
    width: 95%;
    padding: 15px 12px;
  }

  /* Stack form fields vertically */
  .form-box form > div:first-child {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }
  .form-box input[type="text"],
  .form-box input[type="date"],
  .form-box select,
  .form-box input[type="submit"],
  .form-box button {
    width: 100%;
    min-height: 44px;
    font-size: 1rem;
    box-sizing: border-box;
  }

  /* Date/filter form stacks */
  .dateform {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    gap: 12px;
  }
  .dateform label {
    font-size: 0.95rem;
  }

  /* Filter toggles stack */
  .filter-toggles {
    margin-left: 0;
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
  }
  .filter-toggle {
    justify-content: space-between;
    padding: 10px;
    background: #3a3a3a;
    border-radius: 8px;
    min-height: 44px;
  }
  .filter-toggle input[type="checkbox"] {
    width: 22px;
    height: 22px;
  }

  /* Sections full width */
  .section {
    width: 100%;
    border-radius: 8px;
  }
  .section h3 {
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
    padding: 12px;
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  .grid {
    grid-template-columns: 1fr;
  }
  .stat {
    min-height: 48px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
  }

  /* Tables scroll horizontally inside wrapper */
  .table-wrap {
    width: 100%;
  }
  th, td {
    white-space: nowrap;
    font-size: 0.9rem;
  }

  .match-header {
    font-size: 1.1rem;
  }

}

/* ============================================================
   Responsive — Small phone (<=480px)
   ============================================================ */
@media (max-width: 480px) {
  .topbar {
    width: 100%;
    padding: 0 8px;
    box-sizing: border-box;
  }
  .topbar .right {
    justify-content: center;
  }
  .form-box {
    width: 100%;
    border-radius: 0;
  }
  .chips {
    width: 100%;
    padding: 0 8px;
    box-sizing: border-box;
  }
  .table-wrap {
    width: 100%;
    border-radius: 0;
  }
  .section {
    border-radius: 0;
  }
  .section h3 {
    border-radius: 0;
  }
}
