/* Admin dashboard redesign (light theme, sidebar nav) - see the ticket's Part A. Same plain-CSS,
   no-build-step convention as before; only the visual language changed. */
:root {
  color-scheme: light;
  --bg: #f5f6fa;
  --panel: #ffffff;
  --border: #e6e8f0;
  --text: #1b1e27;
  --muted: #8a8f9e;
  --accent: #5b6cff;
  --accent-soft: #eef0ff;
  --error: #d64550;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 6px rgba(16, 24, 40, 0.05);
  --radius: 12px;
  --sidebar-width: 216px;

  /* Semantic color system (founder addition to Part A) - four meanings, applied consistently:
     blue = primary/neutral data (the default - charts, primary stat accents, plain links);
     green = positive/healthy signals (completed, most-used, growth, active/healthy state);
     orange = this codebase's own existing brand accent (RefereeColors.Accent #FF7A00 in the
     Android app) - emphasis/actionable UI (the Create button, the active sidebar nav item);
     red = attention/low signals, always paired with a text label, never used for a destructive
     action (there is none in this dashboard). Colors mark specific meaningful values, not
     backgrounds/theme - the page stays the light neutral palette above. */
  --color-blue: #5b6cff;
  --color-green: #1f9d6f;
  --color-orange: #ff7a00;
  --color-red: #d64550;
  --color-blue-soft: #eef0ff;
  --color-green-soft: #e6f6ef;
  --color-orange-soft: #fff1e2;
  --color-red-soft: #fbe9ea;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

h1, h2, h3 {
  margin: 0 0 4px;
}

/* ---- App shell / sidebar ---- */

.app-shell {
  display: flex;
  align-items: stretch;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  font-weight: 700;
  font-size: 16px;
  padding: 6px 10px 22px;
  color: var(--text);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
}

.nav-link svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.nav-link:hover {
  background: var(--accent-soft);
  color: var(--text);
}

.nav-link.active {
  /* Orange = this dashboard's emphasis/actionable accent (see the :root comment) - the active
     sidebar item is the one place a user's current location is "the actionable one". */
  background: var(--color-orange-soft);
  color: var(--color-orange);
  font-weight: 600;
}

.sidebar-divider {
  height: 1px;
  background: var(--border);
  margin: 16px 6px;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 8px;
}

.logout-btn {
  width: 100%;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
  cursor: pointer;
}

.logout-btn:hover {
  background: var(--bg);
  color: var(--text);
}

.main-area {
  flex: 1;
  min-width: 0;
}

main {
  max-width: 1240px;
  margin: 0 auto;
  padding: 28px 32px 60px;
}

.page-title {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 20px;
}

/* ---- Buttons / inputs (shared) ---- */

button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 14px;
  cursor: pointer;
}

button:hover {
  opacity: 0.9;
}

/* Orange = emphasis/actionable (see :root comment) - the one primary call-to-action button on the
   dashboard (Create Competition). Every other button stays the default blue/neutral. */
.btn-cta {
  background: var(--color-orange);
}

input, select, textarea {
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 14px;
}

/* Step 4 (admin announcements): the first textarea this dashboard has needed - inherits the shared
   input/select look above, plus its own resize/font behavior (never a fixed-width monospace box). */
textarea {
  font-family: inherit;
  resize: vertical;
}

a {
  color: var(--accent);
}

.error {
  color: var(--error);
  font-size: 13px;
}

/* ---- Cards ---- */

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

.card h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 14px;
}

.card + .card {
  margin-top: 20px;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 20px;
  margin-top: 20px;
}

/* ---- Stat cards ---- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
}

.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-top: 3px solid var(--color-blue);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
}

/* Per-card semantic accent (top border) - blue is the default set inline above; a card can
   override to green/orange/red when the number it shows carries that meaning (e.g. Completed
   Competitions = green, a zero-installs-last-30-days card = red). */
.stat-accent-green { border-top-color: var(--color-green); }
.stat-accent-orange { border-top-color: var(--color-orange); }
.stat-accent-red { border-top-color: var(--color-red); }

.stat-accent-green .stat-value { color: var(--color-green); }
.stat-accent-orange .stat-value { color: var(--color-orange); }
.stat-accent-red .stat-value { color: var(--color-red); }

.stat-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
}

.stat-label {
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

/* ---- Tables ---- */

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
  margin-bottom: 24px;
}

th, td {
  text-align: left;
  padding: 10px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

th {
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

/* Status/badge coloring (competitions list + detail): DRAFT is orange (needs admin action to
   publish it - "actionable"), ACTIVE/COMPLETED are green ("healthy/active" and positive outcomes
   respectively), UPCOMING/OPEN are blue (neutral - in the pipeline), CANCELLED is red (a terminal,
   attention-worthy outcome - never destructive, this dashboard has no delete/cancel action of its
   own). Always paired with the status's own text, per row - color is never the only signal. */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.badge-blue { background: var(--color-blue-soft); color: var(--color-blue); }
.badge-green { background: var(--color-green-soft); color: var(--color-green); }
.badge-orange { background: var(--color-orange-soft); color: var(--color-orange); }
.badge-red { background: var(--color-red-soft); color: var(--color-red); }

/* A short red note next to a timestamp (e.g. "ending soon") - always rendered alongside its own
   text, never a bare color swatch. */
.text-attention {
  color: var(--color-red);
  font-weight: 600;
  font-size: 12px;
}

.toolbar {
  margin-bottom: 12px;
}

.toolbar label, .form-grid label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  max-width: 900px;
}

/* ---- Progress-bar list (Exercises breakdown, Created By breakdown, Installs by platform) ---- */

.progress-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.progress-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.progress-row .progress-label {
  width: 150px;
  flex-shrink: 0;
  font-size: 13px;
  color: var(--text);
  font-weight: 500;
}

.progress-track {
  flex: 1;
  height: 8px;
  border-radius: 4px;
  background: var(--bg);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 4px;
  /* Blue = default "just data" color for a bar with no specific meaning attached. */
  background: linear-gradient(90deg, #8a9bff, var(--color-blue));
}

/* Green = positive/healthy (e.g. the most-used movement); red = attention (e.g. a movement with
   zero performances yet) - always paired with the row's own text label, never color alone. */
.progress-fill-green {
  background: linear-gradient(90deg, #57c79b, var(--color-green));
}

.progress-fill-red {
  background: linear-gradient(90deg, #e6868d, var(--color-red));
}

/* Orange = actionable/pending (this ticket's Challenge invites breakdown - an ACTIVE invite is
   still waiting to be redeemed), matching the same meaning as .stat-accent-orange/.badge-orange. */
.progress-fill-orange {
  background: linear-gradient(90deg, #ffb066, var(--color-orange));
}

.progress-count {
  width: 60px;
  text-align: right;
  font-size: 13px;
  color: var(--muted);
  flex-shrink: 0;
}

/* ---- Bar chart (Activity card) ---- */

.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 18px;
  height: 180px;
  padding-top: 10px;
}

.bar-chart .bar-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  flex: 1;
  height: 100%;
}

.bar-chart .bar {
  width: 100%;
  max-width: 44px;
  min-height: 3px;
  /* Blue = default data color for the Activity chart. */
  background: linear-gradient(180deg, #8a9bff, var(--color-blue));
  border-radius: 6px 6px 0 0;
}

/* Same green/red meanings as .progress-fill-green/-red above, applied to a bar instead of a
   horizontal track - the most-performed movement vs. one with zero performances. */
.bar-chart .bar.bar-green {
  background: linear-gradient(180deg, #57c79b, var(--color-green));
}

.bar-chart .bar.bar-red {
  background: linear-gradient(180deg, #e6868d, var(--color-red));
}

.bar-chart .bar-value {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 4px;
}

.bar-chart .bar-label {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
}

/* Thin variant (this ticket, Trends section) - a 30-daily-bar chart needs much narrower bars/gaps
   than the 4-6-bar Activity/Challenges charts to stay readable at the same card width; each bar's
   full label+value still lives in its `title` tooltip (see admin.js's barChartHtml doc comment). */
.bar-chart-thin {
  gap: 3px;
}

.bar-chart-thin .bar-col {
  min-width: 0;
}

.bar-chart-thin .bar {
  max-width: 12px;
}

.bar-chart-thin .bar-value {
  font-size: 9px;
}

.bar-chart-thin .bar-label {
  margin-top: 6px;
  font-size: 10px;
  white-space: nowrap;
}

/* ---- Leaderboard list (Most Active Athletes) ---- */

.leaderboard-list {
  display: flex;
  flex-direction: column;
}

.leaderboard-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 2px;
  border-bottom: 1px solid var(--border);
}

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

.leaderboard-row .rank {
  width: 20px;
  flex-shrink: 0;
  font-weight: 700;
  color: var(--muted);
  font-size: 13px;
}

.leaderboard-row .who {
  flex: 1;
  min-width: 0;
}

.leaderboard-row .who .name {
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-row .who .meta {
  font-size: 12px;
  color: var(--muted);
}

.leaderboard-row .metric {
  font-weight: 700;
  font-size: 14px;
  color: var(--text);
  flex-shrink: 0;
}

/* ---- Placeholder card (Invites) ---- */

.placeholder-card {
  text-align: center;
  padding: 56px 24px;
  max-width: 560px;
  margin: 0 auto;
}

.placeholder-card h2 {
  font-size: 20px;
  margin-bottom: 10px;
}

.placeholder-card p {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

/* ---- Login page (no sidebar) ---- */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-box {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
}

.login-box form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
