/* ==========================================================================
   STUDIO FITNESS LIVE LEADERBOARD
   Brand: black background, Studio Fitness red, crisp white type, charcoal
   panels. High contrast, premium scoreboard feel. No flags/fireworks/stars.
   ========================================================================== */

:root {
  --sf-black: #0a0a0a;
  --sf-black-2: #050505;
  --sf-charcoal: #161616;
  --sf-charcoal-2: #1e1e1e;
  --sf-charcoal-3: #262626;
  --sf-border: #2a2a2a;
  --sf-border-soft: #202020;

  --sf-white: #ffffff;
  --sf-grey: #c7c7cc;
  --sf-grey-dim: #8a8a8f;
  --sf-grey-faint: #5c5c60;

  --sf-red: #e1122d;
  --sf-red-bright: #ff2745;
  --sf-red-dim: #7a2530;
  --sf-red-wash: rgba(225, 18, 45, 0.12);

  --sf-gold: #d9a94e;
  --sf-silver: #c7c9cc;
  --sf-bronze: #b97a4c;

  /* Sequential ordinal ramp (grey -> red -> gold) for tier rank 1-10.
     Tiers are now defined dynamically in the spreadsheet (Settings tab, up
     to 10), so color is assigned by ORDINAL POSITION, not by a fixed tier
     name -- this keeps colors correct even if tiers are renamed, reordered,
     added, or removed. Each badge/legend entry still shows the tier name
     as text, so color is never the sole identifier. */
  --tier-1: #6e6e72;
  --tier-2: #885a63;
  --tier-3: #a14553;
  --tier-4: #bb3144;
  --tier-5: #d41c35;
  --tier-6: #e02331;
  --tier-7: #de4438;
  --tier-8: #dd663f;
  --tier-9: #db8747;
  --tier-10: #d9a94e;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-pill: 999px;

  --shadow-panel: 0 1px 0 rgba(255, 255, 255, 0.03) inset, 0 8px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--sf-black);
  color: var(--sf-white);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, Helvetica, sans-serif;
  -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; display: block; }

button {
  font-family: inherit;
  cursor: pointer;
}

/* ---------------------------------------------------------------------- */
/* HEADER                                                                  */
/* ---------------------------------------------------------------------- */

.sf-header {
  background: linear-gradient(180deg, var(--sf-black-2), var(--sf-black) 70%);
  border-bottom: 3px solid var(--sf-red);
  padding: 20px 28px;
}

.sf-header__inner {
  max-width: 1440px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 20px;
}

.sf-header__logo {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  flex-shrink: 0;
}

.sf-header__brand {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 3px;
  color: var(--sf-grey);
}

.sf-header__challenge {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 1px;
  color: var(--sf-white);
  line-height: 1.15;
}

.sf-header__challenge::after {
  content: "";
}

.sf-header__dates {
  font-size: 14px;
  font-weight: 600;
  color: var(--sf-red-bright);
  letter-spacing: 0.5px;
  margin-top: 2px;
}

.sf-header__tagline {
  font-size: 13px;
  font-weight: 500;
  font-style: italic;
  color: var(--sf-grey-dim);
  letter-spacing: 0.2px;
  margin-top: 2px;
}

.sf-header__tagline[hidden] {
  display: none;
}

/* ---------------------------------------------------------------------- */
/* CONNECTION BANNER                                                       */
/* ---------------------------------------------------------------------- */

.sf-banner {
  max-width: 1440px;
  margin: 12px auto 0;
  padding: 8px 16px;
  background: var(--sf-charcoal-2);
  border: 1px solid var(--sf-border);
  border-left: 3px solid var(--sf-red);
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  color: var(--sf-grey);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* NOTE: this explicit override is required. The rule above sets its own
   `display`, which (per normal CSS cascade/origin rules) takes priority
   over the browser's built-in `[hidden] { display: none }` rule -- so
   without this line, setting the `hidden` attribute on the banner in
   JavaScript would NOT actually hide it visually. This was the root cause
   of the banner staying visible after a genuinely successful CSV fetch. */
.sf-banner[hidden] {
  display: none;
}

.sf-banner__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--sf-red-bright);
  flex-shrink: 0;
  animation: sf-pulse 1.6s ease-in-out infinite;
}

@keyframes sf-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* ---------------------------------------------------------------------- */
/* MAIN / LAYOUT                                                          */
/* ---------------------------------------------------------------------- */

.sf-main {
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px 28px 8px;
}

/* Stats row */

.sf-stats {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 14px;
  margin-bottom: 22px;
}

.sf-stat {
  background: var(--sf-charcoal);
  border: 1px solid var(--sf-border);
  border-radius: var(--radius-md);
  padding: 16px 14px;
  text-align: center;
  box-shadow: var(--shadow-panel);
}

.sf-stat__value {
  font-size: clamp(22px, 2.6vw, 34px);
  font-weight: 800;
  color: var(--sf-white);
  font-variant-numeric: tabular-nums;
}

.sf-stat__label {
  margin-top: 4px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--sf-grey-dim);
}

/* Board + side layout */

.sf-layout {
  display: grid;
  grid-template-columns: minmax(0, 2.4fr) minmax(280px, 1fr);
  gap: 18px;
  align-items: start;
}

.sf-board {
  background: var(--sf-charcoal);
  border: 1px solid var(--sf-border);
  border-radius: var(--radius-lg);
  padding: 18px 18px 8px;
  box-shadow: var(--shadow-panel);
  position: relative;
  min-height: 200px;
}

.sf-board__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.sf-board__title {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.5px;
  margin: 0;
  color: var(--sf-white);
}

.sf-board__controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sf-updated {
  font-size: 12px;
  color: var(--sf-grey-faint);
  font-variant-numeric: tabular-nums;
}

.sf-refresh {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--sf-charcoal-3);
  border: 1px solid var(--sf-border);
  color: var(--sf-grey);
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.3px;
  padding: 7px 12px;
  border-radius: var(--radius-pill);
  transition: border-color 0.15s ease, color 0.15s ease;
}

.sf-refresh:hover {
  border-color: var(--sf-red);
  color: var(--sf-white);
}

.sf-refresh svg {
  transition: transform 0.4s ease;
}

.sf-refresh.is-spinning svg {
  animation: sf-spin 0.7s linear infinite;
}

@keyframes sf-spin {
  to { transform: rotate(360deg); }
}

/* ---------------------------------------------------------------------- */
/* LEADERBOARD ROWS                                                        */
/* ---------------------------------------------------------------------- */

.sf-row {
  display: grid;
  grid-template-columns: 56px minmax(0, 1.4fr) 110px 150px minmax(140px, 220px) 90px;
  align-items: center;
  gap: 14px;
  padding: 12px 10px;
  border-bottom: 1px solid var(--sf-border-soft);
}

.sf-row--header {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--sf-grey-faint);
  border-bottom: 1px solid var(--sf-border);
  padding: 4px 10px 10px;
}

.sf-board__body .sf-row:last-child {
  border-bottom: none;
}

.sf-board__body .sf-row {
  transition: background-color 0.2s ease;
}

.sf-board__body .sf-row:hover {
  background: rgba(255, 255, 255, 0.02);
}

.sf-row--top1 { background: linear-gradient(90deg, rgba(217, 169, 78, 0.10), transparent 60%); }
.sf-row--top2 { background: linear-gradient(90deg, rgba(199, 201, 204, 0.07), transparent 60%); }
.sf-row--top3 { background: linear-gradient(90deg, rgba(185, 122, 76, 0.08), transparent 60%); }

.sf-col--rank { display: flex; align-items: center; justify-content: flex-start; }

.sf-rank-badge {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 14px;
  color: var(--sf-grey);
  background: var(--sf-charcoal-3);
  border: 1px solid var(--sf-border);
  font-variant-numeric: tabular-nums;
}

.sf-row--top1 .sf-rank-badge {
  background: var(--sf-gold);
  color: var(--sf-black);
  border-color: var(--sf-gold);
}
.sf-row--top2 .sf-rank-badge {
  background: var(--sf-silver);
  color: var(--sf-black);
  border-color: var(--sf-silver);
}
.sf-row--top3 .sf-rank-badge {
  background: var(--sf-bronze);
  color: var(--sf-black);
  border-color: var(--sf-bronze);
}

.sf-col--name {
  font-weight: 700;
  font-size: 15.5px;
  color: var(--sf-white);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.sf-col--points {
  font-weight: 800;
  font-size: 17px;
  color: var(--sf-white);
  font-variant-numeric: tabular-nums;
}

.sf-status-badge {
  display: inline-flex;
  align-items: center;
  padding: 5px 12px;
  border-radius: var(--radius-pill);
  font-size: 11.5px;
  font-weight: 800;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--sf-white);
  white-space: nowrap;
}

.sf-status-badge--tier1 { background: var(--tier-1); }
.sf-status-badge--tier2 { background: var(--tier-2); }
.sf-status-badge--tier3 { background: var(--tier-3); }
.sf-status-badge--tier4 { background: var(--tier-4); }
.sf-status-badge--tier5 { background: var(--tier-5); }
.sf-status-badge--tier6 { background: var(--tier-6); }
.sf-status-badge--tier7 { background: var(--tier-7); }
.sf-status-badge--tier8 { background: var(--tier-8); }
.sf-status-badge--tier9 { background: var(--tier-9); color: var(--sf-black); }
.sf-status-badge--tier10 { background: var(--tier-10); color: var(--sf-black); }
.sf-status-badge--unknown { background: var(--sf-charcoal-3); border: 1px solid var(--sf-border); color: var(--sf-grey); }

.sf-progress {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sf-progress__track {
  flex: 1;
  height: 8px;
  border-radius: var(--radius-pill);
  background: var(--sf-charcoal-3);
  overflow: hidden;
  min-width: 60px;
}

.sf-progress__fill {
  height: 100%;
  border-radius: var(--radius-pill);
  background: linear-gradient(90deg, var(--sf-red-dim), var(--sf-red-bright));
  transition: width 0.5s ease;
}

.sf-progress--complete .sf-progress__fill {
  background: linear-gradient(90deg, var(--sf-red), var(--sf-gold));
}

.sf-progress__pct {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--sf-grey);
  width: 38px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

.sf-qualified {
  font-size: 12.5px;
  font-weight: 800;
  letter-spacing: 0.5px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.sf-qualified--yes { color: var(--sf-white); }
.sf-qualified--no { color: var(--sf-grey-faint); }

.sf-qualified__icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

/* Loading / empty / error states */

.sf-board__loading,
.sf-board__error,
.sf-board__empty {
  padding: 40px 10px;
  text-align: center;
  color: var(--sf-grey-dim);
  font-size: 14px;
}

.sf-spinner {
  width: 26px;
  height: 26px;
  margin: 0 auto 12px;
  border-radius: 50%;
  border: 3px solid var(--sf-charcoal-3);
  border-top-color: var(--sf-red);
  animation: sf-spin 0.8s linear infinite;
}

.sf-refresh--retry {
  margin-top: 12px;
}

/* ---------------------------------------------------------------------- */
/* SIDE PANEL                                                              */
/* ---------------------------------------------------------------------- */

.sf-side {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.sf-panel {
  background: var(--sf-charcoal);
  border: 1px solid var(--sf-border);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-panel);
}

.sf-panel__title {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--sf-red-bright);
  margin: 0 0 14px;
}

.sf-prize {
  margin-bottom: 14px;
}

.sf-prize:last-of-type {
  margin-bottom: 10px;
}

.sf-prize__label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--sf-grey-dim);
  margin-bottom: 3px;
}

.sf-prize__value {
  font-size: 14.5px;
  font-weight: 700;
  color: var(--sf-white);
  line-height: 1.35;
}

.sf-winner-rule {
  font-size: 12px;
  color: var(--sf-grey-dim);
  line-height: 1.5;
  border-top: 1px solid var(--sf-border-soft);
  padding-top: 12px;
  margin: 10px 0 0;
}

.sf-legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sf-legend li {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}

.sf-legend__swatch {
  width: 12px;
  height: 12px;
  border-radius: 4px;
  flex-shrink: 0;
}

.sf-legend__swatch--tier1 { background: var(--tier-1); }
.sf-legend__swatch--tier2 { background: var(--tier-2); }
.sf-legend__swatch--tier3 { background: var(--tier-3); }
.sf-legend__swatch--tier4 { background: var(--tier-4); }
.sf-legend__swatch--tier5 { background: var(--tier-5); }
.sf-legend__swatch--tier6 { background: var(--tier-6); }
.sf-legend__swatch--tier7 { background: var(--tier-7); }
.sf-legend__swatch--tier8 { background: var(--tier-8); }
.sf-legend__swatch--tier9 { background: var(--tier-9); }
.sf-legend__swatch--tier10 { background: var(--tier-10); }

.sf-legend__name {
  font-weight: 700;
  color: var(--sf-white);
}

.sf-legend__range {
  color: var(--sf-grey-faint);
  font-size: 11.5px;
  margin-left: auto;
  font-variant-numeric: tabular-nums;
}

.sf-legend__unavailable {
  color: var(--sf-grey-dim);
  font-size: 12.5px;
  font-style: italic;
}

/* ---------------------------------------------------------------------- */
/* FOOTER                                                                  */
/* ---------------------------------------------------------------------- */

.sf-footer {
  max-width: 1440px;
  margin: 18px auto 0;
  padding: 16px 28px 30px;
  text-align: center;
}

.sf-footer p {
  font-size: 12px;
  color: var(--sf-grey-faint);
  letter-spacing: 0.3px;
  margin: 0;
}

/* ---------------------------------------------------------------------- */
/* RESPONSIVE                                                              */
/* ---------------------------------------------------------------------- */

@media (max-width: 1080px) {
  .sf-layout {
    grid-template-columns: 1fr;
  }
  .sf-stats {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 720px) {
  .sf-header { padding: 16px 16px; }
  .sf-header__inner { gap: 14px; }
  .sf-header__logo { width: 48px; height: 48px; }
  .sf-header__challenge { font-size: 20px; }
  .sf-header__brand { font-size: 12px; letter-spacing: 2px; }

  .sf-main { padding: 16px 14px 4px; }

  .sf-stats {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .sf-board { padding: 14px 12px 6px; border-radius: var(--radius-md); }

  /* Column header row hides on mobile -- each row becomes a stacked card. */
  .sf-row--header { display: none; }

  .sf-row {
    grid-template-columns: 40px 1fr auto;
    grid-template-areas:
      "rank name points"
      "rank status status"
      "rank progress progress"
      "rank qualified qualified";
    row-gap: 6px;
    padding: 14px 6px;
  }

  .sf-col--rank { grid-area: rank; align-self: start; }
  .sf-col--name { grid-area: name; white-space: normal; font-size: 16px; }
  .sf-col--points { grid-area: points; text-align: right; }
  .sf-col--status { grid-area: status; }
  .sf-col--progress { grid-area: progress; }
  .sf-col--qualified { grid-area: qualified; }

  .sf-progress__track { min-width: 0; }

  .sf-panel { padding: 15px; }
}

@media (max-width: 420px) {
  .sf-stats { grid-template-columns: 1fr 1fr; }
  .sf-stat__value { font-size: 22px; }
}

/* Respect reduced-motion preferences */
@media (prefers-reduced-motion: reduce) {
  .sf-progress__fill, .sf-refresh svg, .sf-banner__dot, .sf-spinner {
    animation: none !important;
    transition: none !important;
  }
}
