/* ===== CSS Variables ===== */
:root {
  --navy:   #003087;
  --red:    #C8102E;
  --gold:   #FFD700;
  --light:  #f4f7fc;
  --white:  #ffffff;
  --gray:   #6c757d;
  --dark:   #1a1a2e;
  --shadow: 0 2px 12px rgba(0,0,0,.12);
  --radius: 8px;
  --font:   'Segoe UI', Calibri, Arial, sans-serif;
}

/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--font);
  background: var(--light);
  color: var(--dark);
  min-height: 100vh;
  padding-top: 68px;
}
a { color: var(--navy); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }

/* ===== Data Freshness Bar ===== */
#data-freshness {
  position: fixed;
  top: 68px;
  left: 0; right: 0;
  z-index: 999;
  background: #f0f4ff;
  border-bottom: 1px solid #d0d8ee;
  text-align: center;
  font-size: .72rem;
  font-weight: 600;
  color: #4a5568;
  padding: 4px 0;
  letter-spacing: .2px;
}
body { padding-top: calc(68px + 25px); } /* nav + freshness bar */
.freshness-dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #94a3b8;
  margin-right: 5px;
  vertical-align: middle;
}
.freshness-dot.live {
  background: #22c55e;
  box-shadow: 0 0 0 2px #bbf7d0;
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 2px #bbf7d0; }
  50%       { box-shadow: 0 0 0 5px #bbf7d080; }
}

/* ===== Navigation ===== */
.nav {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 1000;
  background: var(--navy);
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
  height: 68px;
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 0;
}
.nav-brand {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--gold);
  letter-spacing: .5px;
  white-space: nowrap;
  margin-right: 28px;
  text-decoration: none;
}
.nav-links {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  list-style: none;
}
.nav-links a {
  color: #c8d8f0;
  font-size: .9rem;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: var(--radius);
  transition: background .2s, color .2s;
  text-decoration: none;
  white-space: nowrap;
}
.nav-links a:hover, .nav-links a.active {
  background: rgba(255,255,255,.15);
  color: var(--white);
}
/* Teams dropdown */
.nav-dropdown { position: relative; }
.nav-dropdown > a { cursor: pointer; user-select: none; }
.dropdown-menu {
  display: none;
  position: fixed;
  top: 93px;                 /* nav (68) + freshness bar (25) */
  left: auto;
  background: var(--white);
  border: 1px solid #dde;
  border-radius: var(--radius);
  box-shadow: 0 6px 24px rgba(0,0,0,.18);
  min-width: 230px;
  max-height: min(700px, calc(100vh - 110px));
  overflow-y: scroll;
  z-index: 2000;
  padding: 4px 0 6px;
  /* Always-visible scrollbar so users know all 12 groups are there */
  scrollbar-width: thin;
  scrollbar-color: #bbb #f4f4f4;
}
.dropdown-menu::-webkit-scrollbar       { width: 6px; }
.dropdown-menu::-webkit-scrollbar-track { background: #f4f4f4; }
.dropdown-menu::-webkit-scrollbar-thumb { background: #bbb; border-radius: 3px; }
.dropdown-menu::-webkit-scrollbar-thumb:hover { background: #999; }
/* open class toggled by JS click */
.nav-dropdown.open .dropdown-menu { display: block; }
.dropdown-menu a {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 14px;
  color: var(--dark);
  font-size: .83rem;
  transition: background .15s;
}
.dropdown-menu a:hover { background: var(--light); }
.dropdown-menu .flag-sm { width: 22px; height: 14px; object-fit: cover; border-radius: 2px; }
.dropdown-group-label {
  padding: 6px 14px 2px;
  font-size: .66rem;
  font-weight: 800;
  color: #888;
  text-transform: uppercase;
  letter-spacing: .6px;
  border-top: 1px solid #eee;
  margin-top: 2px;
}
.dropdown-group-label:first-child { border-top: none; margin-top: 0; }

/* ===== Page Header ===== */
.page-header {
  background: linear-gradient(135deg, var(--navy) 0%, #1a3a7a 100%);
  color: var(--white);
  padding: 36px 24px 28px;
  text-align: center;
}
.page-header h1 {
  font-size: 2rem;
  font-weight: 900;
  color: var(--gold);
  letter-spacing: 1px;
  margin-bottom: 6px;
}
.page-header p { color: #c8d8f0; font-size: .95rem; }

/* ===== Container ===== */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 16px;
}

/* ===== Cards ===== */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}
.card-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--navy);
  border-bottom: 2px solid var(--gold);
  padding-bottom: 8px;
  margin-bottom: 14px;
}

/* ===== Tables ===== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th {
  background: var(--navy);
  color: var(--white);
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
}
td {
  padding: 9px 12px;
  border-bottom: 1px solid #e8edf5;
  vertical-align: middle;
}
tr:hover td { background: #f0f5ff; }
.flag-icon { width: 28px; height: 19px; object-fit: cover; border-radius: 2px; vertical-align: middle; }
.flag-icon-sm { width: 22px; height: 14px; object-fit: cover; border-radius: 2px; vertical-align: middle; }

/* ===== Status Badges ===== */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .4px;
}
.badge-green  { background: #d4edda; color: #155724; }
.badge-yellow { background: #fff3cd; color: #856404; }
.badge-red    { background: #f8d7da; color: #721c24; }
.badge-blue   { background: #d1ecf1; color: #0c5460; }
.badge-gray   { background: #e2e3e5; color: #383d41; }

/* ===== Score / Match display ===== */
.score-cell { text-align: center; font-weight: 700; font-size: 1rem; }
.score-tbd  { color: var(--gray); font-style: italic; font-size: .8rem; }
.match-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 16px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.match-card .teams {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-weight: 700;
  font-size: .95rem;
}
.match-card .score {
  min-width: 60px;
  text-align: center;
  font-size: 1.1rem;
  font-weight: 900;
  color: var(--navy);
}
.match-card .meta { font-size: .78rem; color: var(--gray); }
.match-card .time-badge {
  background: var(--navy);
  color: var(--gold);
  padding: 4px 10px;
  border-radius: 4px;
  font-size: .75rem;
  font-weight: 700;
  white-space: nowrap;
}

/* ===== Modal ===== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 5000;
  overflow-y: auto;
  padding: 20px;
}
.modal-overlay.active { display: flex; align-items: flex-start; justify-content: center; }
.modal-box {
  background: var(--white);
  border-radius: 12px;
  width: 100%;
  max-width: 640px;
  margin: auto;
  box-shadow: 0 8px 40px rgba(0,0,0,.3);
  overflow: hidden;
  animation: modalIn .2s ease;
}
@keyframes modalIn { from { transform: translateY(-20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-header {
  background: var(--navy);
  padding: 20px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  position: relative;
}
.modal-header img { width: 56px; height: 38px; object-fit: cover; border-radius: 4px; border: 2px solid rgba(255,255,255,.3); }
.modal-header h2 { color: var(--white); font-size: 1.3rem; font-weight: 800; }
.modal-header .group-label { color: var(--gold); font-size: .85rem; font-weight: 600; margin-top: 2px; }
.modal-close {
  position: absolute;
  top: 14px; right: 16px;
  background: rgba(255,255,255,.2);
  border: none;
  color: var(--white);
  font-size: 1.2rem;
  width: 32px; height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .2s;
}
.modal-close:hover { background: rgba(255,255,255,.4); }
.modal-record {
  display: flex;
  gap: 0;
  background: var(--light);
  border-bottom: 1px solid #dde;
}
.modal-stat {
  flex: 1;
  text-align: center;
  padding: 14px 8px;
  border-right: 1px solid #dde;
}
.modal-stat:last-child { border-right: none; }
.modal-stat .val { font-size: 1.6rem; font-weight: 900; color: var(--navy); }
.modal-stat .lbl { font-size: .7rem; color: var(--gray); text-transform: uppercase; letter-spacing: .5px; }
.modal-body { padding: 0; }

/* Accordion inside modal */
.accordion-item { border-bottom: 1px solid #e8edf5; }
.accordion-header {
  width: 100%;
  background: none;
  border: none;
  text-align: left;
  padding: 14px 20px;
  font-size: .95rem;
  font-weight: 700;
  color: var(--navy);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: background .15s;
}
.accordion-header:hover { background: var(--light); }
.accordion-arrow { transition: transform .2s; font-size: .8rem; }
.accordion-header.open .accordion-arrow { transform: rotate(180deg); }
.accordion-content { display: none; padding: 0 20px 16px; }
.accordion-content.open { display: block; }
.accordion-content table th { font-size: .78rem; padding: 8px 10px; }
.accordion-content table td { font-size: .8rem; padding: 6px 10px; }

/* ===== Soccer Ball Pie Chart ===== */
#pie-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 0;
}
#pie-chart { cursor: pointer; }
#pie-chart .slice:hover path { opacity: .85; filter: brightness(1.1); }
#pie-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  justify-content: center;
  max-width: 800px;
  margin-top: 20px;
  font-size: .8rem;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 5px;
  transition: background .15s, box-shadow .15s;
  font-weight: 600;
}
.legend-item:hover { background: #eef2ff; }
.legend-item.active {
  background: #e4eaff;
  box-shadow: 0 0 0 2px var(--navy);
  color: var(--navy);
}
.legend-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ===== Group Panel (Home Page) ===== */
#group-panel {
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  animation: panelIn .25s ease;
}
@keyframes panelIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.gp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 18px;
  color: #fff;
}
.gp-title { font-size: 1.1rem; font-weight: 900; letter-spacing: .4px; }
.gp-sub   { font-size: .8rem; opacity: .85; font-weight: 600; }
.gp-list  { background: #fff; }
.gp-team-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 13px 18px;
  border-bottom: 1px solid #eef0f6;
  cursor: pointer;
  transition: background .15s;
}
.gp-team-row:last-child { border-bottom: none; }
.gp-team-row:hover { background: #f4f7ff; }
.gptr-rank  { font-size: 1.05rem; font-weight: 900; width: 22px; text-align: center; flex-shrink: 0; }
.gptr-flag  { width: 38px; height: 25px; object-fit: cover; border-radius: 3px; flex-shrink: 0; border: 1px solid #dde; }
.gptr-name  { font-weight: 700; font-size: .95rem; min-width: 130px; color: var(--dark); }
.gptr-stats {
  display: flex;
  gap: 14px;
  font-size: .82rem;
  color: var(--gray);
  flex: 1;
}
.gptr-stats b { color: var(--dark); }
.gptr-pts {
  font-size: 1.05rem;
  font-weight: 900;
  color: var(--navy);
  min-width: 52px;
  text-align: right;
  flex-shrink: 0;
}
.gptr-pts small { font-size: .65rem; font-weight: 600; color: var(--gray); margin-left: 2px; }
.gptr-arrow { font-size: 1.4rem; color: #bbc4d8; font-weight: 700; flex-shrink: 0; }
.gp-hint {
  background: #f8faff;
  border-top: 1px solid #eef0f6;
  padding: 9px 18px;
  font-size: .75rem;
  color: var(--gray);
  text-align: center;
  font-style: italic;
}
@media (max-width: 580px) {
  .gptr-stats { display: none; }
  .gptr-name  { flex: 1; }
}

/* ===== Calendar ===== */
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
  background: #dde;
  border: 1px solid #dde;
  border-radius: var(--radius);
  overflow: hidden;
}
.cal-header {
  background: var(--navy);
  color: var(--white);
  text-align: center;
  padding: 8px 4px;
  font-size: .8rem;
  font-weight: 700;
}
.cal-day {
  background: var(--white);
  min-height: 90px;
  padding: 6px;
  font-size: .75rem;
  vertical-align: top;
}
.cal-day.empty { background: #f8f9fa; }
.cal-day.today { background: #fffde7; border: 2px solid var(--gold); }
.cal-day.has-match { background: #f0f5ff; }
.cal-day-num {
  font-weight: 700;
  font-size: .85rem;
  color: var(--navy);
  margin-bottom: 4px;
}
.cal-day.today .cal-day-num { color: var(--red); }
.cal-match-chip {
  background: var(--navy);
  color: var(--white);
  border-radius: 3px;
  padding: 2px 4px;
  font-size: .65rem;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cal-match-chip.completed { background: #6c757d; }
.cal-match-chip.today-match { background: var(--red); }

/* ===== Bracket ===== */
.bracket-stage { margin-bottom: 32px; }
.bracket-stage-title {
  font-size: 1rem;
  font-weight: 800;
  color: var(--navy);
  background: var(--gold);
  display: inline-block;
  padding: 4px 14px;
  border-radius: 4px;
  margin-bottom: 12px;
}
.bracket-matches {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}
.bracket-match {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-width: 220px;
  overflow: hidden;
  border-left: 4px solid var(--navy);
}
.bracket-match.final-match { border-left-color: var(--gold); border-width: 6px; }
.bracket-team {
  padding: 9px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .88rem;
  border-bottom: 1px solid #eee;
}
.bracket-team:last-child { border-bottom: none; }
.bracket-team.winner { font-weight: 800; background: #f0f7ef; }
.bracket-team .score { margin-left: auto; font-weight: 700; min-width: 20px; text-align: right; }
.bracket-meta { padding: 4px 14px 8px; font-size: .72rem; color: var(--gray); }

/* ===== Welcome Section ===== */
.welcome-section {
  background: linear-gradient(135deg, var(--navy) 0%, #1a3a7a 100%);
  color: var(--white);
  padding: 40px 24px;
}
.welcome-section h1 {
  font-size: 2.2rem;
  font-weight: 900;
  color: var(--gold);
  margin-bottom: 4px;
}
.welcome-section .tagline {
  color: #aac8f0;
  font-size: 1rem;
  margin-bottom: 20px;
}
.welcome-section p {
  max-width: 800px;
  line-height: 1.8;
  font-size: .97rem;
  color: #dce8fb;
  margin-bottom: 12px;
}

/* ===== Email Signup ===== */
.signup-section {
  background: var(--white);
  border-top: 4px solid var(--gold);
  padding: 36px 24px;
}
.signup-section h2 {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--navy);
  margin-bottom: 6px;
}
.signup-section p { color: var(--gray); margin-bottom: 20px; }
.signup-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  max-width: 700px;
}
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label { font-size: .85rem; font-weight: 600; color: var(--navy); }
.form-group input,
.form-group select {
  padding: 10px 14px;
  border: 2px solid #ccd;
  border-radius: var(--radius);
  font-size: .9rem;
  font-family: var(--font);
  transition: border-color .2s;
}
.form-group input:focus,
.form-group select:focus { outline: none; border-color: var(--navy); }
.form-group.full { grid-column: 1 / -1; }
.btn {
  padding: 11px 28px;
  border: none;
  border-radius: var(--radius);
  font-size: .95rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity .2s, transform .1s;
}
.btn:hover { opacity: .9; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary { background: var(--red); color: var(--white); }
.btn-navy   { background: var(--navy); color: var(--white); }
.btn-gold   { background: var(--gold); color: var(--dark); }
.btn-sm     { padding: 6px 16px; font-size: .82rem; }
.signup-msg { margin-top: 14px; font-weight: 600; }
.signup-msg.success { color: #155724; }
.signup-msg.error   { color: #721c24; }

/* ===== Reference page ===== */
.ref-section { margin-bottom: 32px; }
.ref-section h2 {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--white);
  background: var(--navy);
  padding: 8px 16px;
  border-radius: var(--radius) var(--radius) 0 0;
  display: flex;
  align-items: center;
  gap: 8px;
}
.ref-section .ref-body {
  background: var(--white);
  border: 1px solid #dde;
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  padding: 16px;
  overflow-x: auto;
}
.group-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}
.group-card {
  border: 2px solid var(--navy);
  border-radius: var(--radius);
  overflow: hidden;
}
.group-card-header {
  background: var(--navy);
  color: var(--gold);
  font-weight: 800;
  font-size: 1rem;
  padding: 7px 14px;
}
.group-card table th { background: #e8edf5; color: var(--navy); padding: 7px 10px; font-size: .78rem; }
.group-card table td { padding: 7px 10px; font-size: .82rem; }

/* ===== Standings page ===== */
.standings-rank {
  font-weight: 800;
  font-size: 1rem;
  color: var(--navy);
  width: 32px;
  text-align: center;
}
.team-name-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.team-name-cell:hover { text-decoration: underline; color: var(--navy); }
.num-cell { text-align: center; }
.pts-cell { text-align: center; font-weight: 800; color: var(--navy); font-size: 1rem; }

/* ===== Admin ===== */
.admin-header {
  background: #1a1a2e;
  color: var(--gold);
  padding: 20px 24px;
  font-size: 1.4rem;
  font-weight: 900;
  display: flex;
  align-items: center;
  gap: 12px;
}
.admin-nav {
  background: #16213e;
  display: flex;
  gap: 0;
}
.admin-nav a {
  color: #99aac4;
  padding: 12px 20px;
  font-size: .9rem;
  font-weight: 500;
  text-decoration: none;
  transition: background .2s, color .2s;
}
.admin-nav a:hover, .admin-nav a.active { background: rgba(255,215,0,.15); color: var(--gold); }
.admin-panel { display: none; }
.admin-panel.active { display: block; }

/* ===== Utilities ===== */
.text-center { text-align: center; }
.text-navy   { color: var(--navy); }
.text-gold   { color: var(--gold); }
.text-red    { color: var(--red); }
.text-gray   { color: var(--gray); }
.fw-bold     { font-weight: 700; }
.fw-black    { font-weight: 900; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-2 { margin-bottom: 16px; }
.gap-2 { gap: 16px; }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.d-none { display: none !important; }
.spinner {
  display: inline-block;
  width: 28px; height: 28px;
  border: 3px solid rgba(0,48,135,.2);
  border-top-color: var(--navy);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .nav-brand { font-size: 1rem; margin-right: 12px; }
  .nav-links { gap: 0; }
  .nav-links a { padding: 6px 8px; font-size: .8rem; }
  .page-header h1 { font-size: 1.4rem; }
  .signup-form { grid-template-columns: 1fr; }
  .calendar-grid { grid-template-columns: repeat(7, 1fr); }
  .cal-day { min-height: 60px; padding: 3px; }
  .bracket-matches { flex-direction: column; }
  .group-grid { grid-template-columns: 1fr; }
  body { padding-top: 60px; }
  .nav { height: 60px; padding: 0 12px; }
}
@media (max-width: 480px) {
  .modal-box { max-width: 100%; }
  .modal-record { flex-wrap: wrap; }
  .modal-stat { min-width: 50%; }
}
