/* =============================================
   Family Challenge — iOS Design System
   ============================================= */

:root {
  --bg:          #000000;
  --surface:     #1C1C1E;
  --surface-2:   #2C2C2E;
  --border:      #3A3A3C;
  --text:        #FFFFFF;
  --text-muted:  #8E8E93;
  --accent:      #FF3B30;
  --accent-dim:  #CC2A20;
  --danger:      #FF3B30;
  --success:     #34C759;
  --accent-warm: #FF6B30;
  --radius:      14px;
  --font:        -apple-system, 'SF Pro Display', system-ui, sans-serif;
}

/* Reset */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background-color: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
}

/* ---- Main content (unauthenticated) ---- */
main {
  position: relative;
  z-index: 1;
  padding: 32px 40px;
  max-width: 1280px;
  margin: 0 auto;
}

/* ---- Messages ---- */
.messages {
  list-style: none;
  margin-bottom: 20px;
}

.messages li {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  margin-bottom: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
}

.messages li.error {
  border-color: rgba(255, 59, 48, 0.4);
  color: #FF6961;
}

/* ---- Auth page layout ---- */
.auth-body {
  background-color: var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

/* ---- Card ---- */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 40px 36px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 4px 32px rgba(0, 0, 0, 0.6);
  animation: fadeUp 0.35s ease both;
}

.card-wide { max-width: 440px; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---- Auth card header ---- */
.auth-logo {
  font-weight: 800;
  font-size: 26px;
  color: var(--accent);
  text-align: center;
  margin-bottom: 4px;
  letter-spacing: -0.01em;
}

.auth-tagline {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 32px;
}

/* ---- Form fields ---- */
.field { margin-bottom: 20px; }

label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 6px;
}

input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
}

input:focus { border-color: var(--accent); }

.field-error {
  color: #FF6961;
  font-size: 12px;
  margin-top: 4px;
}

/* ---- Two-column row ---- */
.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

/* ---- Buttons ---- */
.btn-primary {
  display: inline-block;
  width: 100%;
  background: var(--accent);
  color: #FFFFFF;
  border: none;
  border-radius: 12px;
  padding: 13px;
  font-family: var(--font);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  margin-top: 8px;
  transition: background 0.15s, transform 0.1s;
}

.btn-primary:hover { background: var(--accent-dim); }
.btn-primary:active { transform: scale(0.98); }

.btn-link {
  display: inline-block;
  color: var(--accent);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  transition: opacity 0.15s;
}

.btn-link:hover { opacity: 0.75; }

/* ---- Alert messages ---- */
.error-msg {
  background: rgba(255, 59, 48, 0.1);
  border: 1px solid rgba(255, 59, 48, 0.35);
  color: #FF6961;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 20px;
}

.success-msg {
  background: rgba(52, 199, 89, 0.1);
  border: 1px solid rgba(52, 199, 89, 0.35);
  color: #34C759;
  border-radius: 10px;
  padding: 14px 16px;
  font-size: 14px;
  line-height: 1.5;
  text-align: center;
}

/* ---- Links section below auth forms ---- */
.links {
  margin-top: 24px;
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
}

.links a {
  color: var(--accent);
  text-decoration: none;
}

.links a:hover { text-decoration: underline; }

.divider {
  margin: 0 8px;
  color: var(--border);
}

/* ---- Utility classes ---- */
.pb-0 { padding-bottom: 0; }

.input-code {
  font-family: ui-monospace, monospace;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

/* ═══════════════════════════════════════════
   DASHBOARD + CHALLENGE DETAIL
═══════════════════════════════════════════ */

/* Page wrappers */

.detail-page {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 48px;
}

/* Cards */
.dash-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 22px 20px;
}


/* Section label (small caps heading inside a card) */
.card-section-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 14px;
}

/* ── Progress bars (shared by stats strip and other uses) ── */
.goal-bar-track {
  height: 4px;
  background: var(--bg);
  border-radius: 2px;
  overflow: hidden;
}

.goal-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent) 0%, var(--accent-warm) 100%);
  border-radius: 2px;
  transition: width 0.4s ease;
}

.goal-bar-fill--done { background: var(--success); }

/* ── Workout form ── */
.workout-form { display: flex; flex-direction: column; gap: 0; }

.form-row {
  display: flex;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.form-row:last-of-type { border-bottom: none; }

.form-row--space-between { justify-content: space-between; }

.form-col {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 0;
}

.form-field-label {
  font-size: 15px;
  color: var(--text);
  font-weight: 400;
}

.inline-select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  outline: none;
  max-width: 160px;
}

.inline-date {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  outline: none;
}

.notes-textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  resize: none;
  outline: none;
  box-sizing: border-box;
}

.notes-textarea:focus { border-color: var(--accent); }
.notes-textarea::placeholder { color: var(--text-muted); }

/* ── Stepper control ── */
.stepper {
  display: flex;
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.stepper--wide { width: 100%; }

.stepper-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 20px;
  font-weight: 300;
  cursor: pointer;
  padding: 6px 14px;
  font-family: var(--font);
  transition: background 0.1s, transform 0.1s;
  flex-shrink: 0;
  line-height: 1;
  user-select: none;
}

.stepper-btn:hover { background: rgba(255,59,48,0.08); }
.stepper-btn:active { transform: scale(0.92); }

.stepper input[type="number"] {
  flex: 1;
  text-align: center;
  border: none;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  font-weight: 700;
  padding: 8px 4px;
  -moz-appearance: textfield;
  cursor: default;
  min-width: 60px;
}

.stepper input[type="number"]::-webkit-outer-spin-button,
.stepper input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; }

/* ── Intensity toggle ── */
.intensity-toggle {
  display: flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  gap: 3px;
}

.toggle-opt {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

.toggle-opt.active { background: var(--accent); color: #fff; }

/* ── Steps section ── */
.steps-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.steps-display {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.steps-big-num {
  font-size: 42px;
  font-weight: 900;
  color: var(--text);
  letter-spacing: -0.03em;
  line-height: 1;
}

.steps-sub {
  font-size: 14px;
  color: var(--text-muted);
}

.steps-edit-form { margin-top: 12px; }

.steps-edit-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 3px 10px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.steps-edit-btn:hover { background: var(--border); color: var(--text); }

/* ── Challenge rows ── */
.challenge-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  transition: opacity 0.15s;
}

.challenge-row:last-child { border-bottom: none; }
.challenge-row:active { opacity: 0.6; }

.challenge-row-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}

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

.challenge-row-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.rank-badge {
  background: rgba(255,59,48,0.12);
  border: 0.5px solid rgba(255,59,48,0.4);
  border-radius: 8px;
  padding: 4px 8px;
  text-align: center;
}

.rank-num {
  display: block;
  font-size: 16px;
  font-weight: 900;
  color: var(--accent);
  letter-spacing: -0.01em;
  line-height: 1;
}

.rank-sub {
  display: block;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  opacity: 0.75;
  margin-top: 1px;
}

.row-chevron {
  font-size: 20px;
  color: var(--text-muted);
  line-height: 1;
}

/* ── Workout rows ── */
.workout-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

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

.workout-icon-badge {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 900;
  color: var(--accent);
  letter-spacing: -0.01em;
  flex-shrink: 0;
}

.workout-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}

.workout-meta { font-size: 12px; color: var(--text-muted); }

/* ── Challenge detail ── */
.detail-page { gap: 16px; }

.back-link {
  display: inline-block;
  color: var(--accent);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  margin-bottom: 4px;
}

.detail-title {
  font-size: 26px;
  font-weight: 900;
  color: var(--text);
  letter-spacing: -0.02em;
  margin: 0 0 2px;
}

.detail-sub { font-size: 13px; color: var(--text-muted); margin: 0 0 8px; }

/* ── Week pill selector ── */
.week-scroll-wrap {
  overflow-x: auto;
  margin: 0 -20px;
  padding: 0 20px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.week-scroll-wrap::-webkit-scrollbar { display: none; }

.week-pills { display: flex; gap: 8px; width: max-content; padding-bottom: 4px; }

.week-pill {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
}

.week-pill--active {
  background: var(--accent);
  border-color: var(--accent);
}

.week-pill-num {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.week-pill--active .week-pill-num { color: #fff; }

.week-pill-dates {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
  white-space: nowrap;
}

.week-pill--active .week-pill-dates { color: rgba(255,255,255,0.75); }

.week-pill--disabled {
  opacity: 0.35;
  cursor: default;
  pointer-events: none;
}

.week-pill--today .week-pill-dates::after {
  content: '';
  display: block;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
  margin: 2px auto 0;
}

/* ── Leaderboard tabs ── */
.lb-tabs {
  display: flex;
  background: var(--surface);
  border-radius: 10px;
  padding: 3px;
  gap: 3px;
}

.lb-tab {
  flex: 1;
  text-align: center;
  padding: 8px 0;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}

.lb-tab--active { background: var(--surface-2); color: var(--text); }

/* ── Leaderboard rows ── */
.leaderboard-list { display: flex; flex-direction: column; gap: 8px; }

.lb-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border-radius: 10px;
  padding: 12px 14px;
  border: 1px solid transparent;
}

.lb-row--me {
  border-color: rgba(255,59,48,0.35);
  background: rgba(255,59,48,0.04);
}

.lb-rank {
  width: 28px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  flex-shrink: 0;
}

.lb-row--me .lb-rank { color: var(--accent); }

.lb-name {
  flex: 1;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.lb-right { text-align: right; min-width: 90px; }

.lb-score {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 5px;
}

.lb-bar-track {
  height: 3px;
  background: var(--surface-2);
  border-radius: 2px;
  overflow: hidden;
  width: 80px;
  margin-left: auto;
}

.lb-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent) 0%, var(--accent-warm) 100%);
  border-radius: 2px;
}

/* ── Toast notifications ── */
.toast-container {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 13px 18px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  pointer-events: auto;
  animation: toastIn 0.3s ease both, toastOut 0.4s ease 3.2s both;
  max-width: 320px;
  border-left: 3px solid var(--border);
}

.toast--error {
  border-left-color: var(--accent);
  color: #FF6961;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toastOut {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(8px); }
}

/* ── Utilities ── */
.hidden { display: none !important; }
.empty-state {
  padding: 20px 0;
  text-align: center;
  font-size: 14px;
  color: var(--text-muted);
}

/* ═══════════════════════════════════════════
   APP SHELL & SIDEBAR
═══════════════════════════════════════════ */
.app-shell { min-height: 100vh; }
.app-sidebar {
  position: fixed; top: 0; left: 0; width: 240px; height: 100vh;
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; z-index: 100; overflow-y: auto;
}
.sidebar-brand {
  padding: 24px 20px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.sidebar-brand-logo { font-size: 22px; font-weight: 900; color: var(--accent); }
.sidebar-brand-name { font-size: 13px; font-weight: 600; color: var(--text); line-height: 1.3; }
.sidebar-nav { flex: 1; padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px;
  border-radius: 10px; color: var(--text-muted); text-decoration: none;
  font-size: 14px; font-weight: 500; transition: background 0.15s, color 0.15s;
  border-left: 3px solid transparent; cursor: pointer;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item--active { background: rgba(255,59,48,0.1); color: var(--accent); border-left-color: var(--accent); }
.nav-icon { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar-logout-form { padding: 0; margin: 0; }
.sidebar-logout-form .nav-item {
  width: 100%; background: none; border: none;
  font-family: var(--font); font-size: 14px; font-weight: 500; text-align: left;
}
.app-content { margin-left: 240px; min-height: 100vh; padding: 32px 32px 48px; }

/* ═══════════════════════════════════════════
   DASHBOARD LAYOUT
═══════════════════════════════════════════ */
.dash-layout { display: grid; grid-template-columns: 1fr 300px; gap: 24px; align-items: start; }
.dash-main-col { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.page-title { font-size: 28px; font-weight: 800; color: var(--text); letter-spacing: -0.02em; }
.page-subtitle { font-size: 13px; color: var(--text-muted); margin-top: 2px; margin-bottom: 4px; }

/* ── Stat cards with rings ── */
.stat-cards-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
.stat-card {
  background: var(--surface); border-radius: var(--radius); padding: 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.stat-card--streak { background: linear-gradient(135deg, #1a0a00 0%, #2C2C2E 100%); }
.stat-card-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--text-muted); margin-bottom: 6px;
}
.stat-card-value { font-size: 30px; font-weight: 900; letter-spacing: -0.03em; line-height: 1; margin-bottom: 4px; }
.stat-unit { font-size: 18px; font-weight: 500; }
.stat-card-sub { font-size: 12px; color: var(--text-muted); }
.stat-card-ring { position: relative; width: 64px; height: 64px; flex-shrink: 0; }
.ring-svg { width: 64px; height: 64px; }
.ring-track { fill: none; stroke: var(--surface-2); stroke-width: 3; }
.ring-fill {
  fill: none; stroke: var(--accent); stroke-width: 3;
  stroke-linecap: round; stroke-dashoffset: 0; transition: stroke-dasharray 0.4s ease;
}
.ring-fill--streak { stroke: #FF9F0A; }
.ring-pct {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
  font-size: 11px; font-weight: 700; color: var(--text);
}

/* ── Content row & right panel ── */
.content-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.dash-right-panel { display: flex; flex-direction: column; gap: 16px; }
.panel-card { background: var(--surface); border-radius: var(--radius); padding: 20px; }
.panel-card-title {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--text-muted); margin-bottom: 14px;
}
.panel-profile { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px; }
.panel-avatar {
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--surface-2); border: 2px solid var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 700; color: var(--accent); margin-bottom: 6px;
}
.panel-name { font-size: 16px; font-weight: 700; color: var(--text); }
.panel-username { font-size: 13px; color: var(--text-muted); }
.panel-divider { width: 100%; height: 1px; background: var(--border); margin: 12px 0; }
.inner-page { max-width: 800px; }
