/* ============ VARIABLES ============ */
:root {
  --primary: #feefb0;
  --primary-dark: #f0df6e;
  --primary-light: #fff8d6;
  --bg: #faf6e9;
  --text: #1a1a1a;
  --text-light: #555;
  --text-muted: #888;
  --white: #ffffff;
  --accent-blue: #5b9bd5;
  --accent-purple: #b4a7d6;
  --success: #4caf50;
  --success-bg: #e8f5e9;
  --error: #e74c3c;
  --error-bg: #fdecea;
  --border: #e8e3d0;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
  --radius: 14px;
  --radius-sm: 10px;
}

/* ============ RESET & BASE ============ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Poppins', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--text); text-decoration: none; }
img { max-width: 100%; }

/* ============ NAVBAR ============ */
.navbar {
  background: var(--primary);
  padding: 0.6rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.logo { display: flex; align-items: center; }
.logo-img { height: 36px; width: auto; }

.nav-links {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--primary);
  flex-direction: column;
  padding: 0.75rem 1rem;
  gap: 0.25rem;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.nav-links.open { display: flex; }

.nav-links a {
  font-weight: 600;
  font-size: 0.95rem;
  padding: 0.6rem 0;
  transition: opacity 0.2s;
}

.nav-links a:hover { opacity: 0.7; }

.menu-toggle {
  display: block;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.25rem;
}

@media (min-width: 640px) {
  .navbar { padding: 0.6rem 1.5rem; }
  .nav-links {
    display: flex;
    position: static;
    flex-direction: row;
    padding: 0;
    gap: 1.5rem;
    box-shadow: none;
  }
  .nav-links a { padding: 0; font-size: 0.9rem; }
  .menu-toggle { display: none; }
}

/* ============ CONTAINER ============ */
.container {
  max-width: 800px;
  margin: 0 auto;
  padding: 1rem;
}

@media (min-width: 640px) {
  .container { padding: 1.5rem; }
}

/* ============ CARDS ============ */
.card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 1.15rem;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}

@media (min-width: 640px) {
  .card { padding: 1.5rem; margin-bottom: 1.25rem; }
}

.card-header {
  font-weight: 700;
  font-size: 1.05rem;
  margin-bottom: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ============ HOME PAGE ============ */
.hero {
  text-align: center;
  padding: 2rem 0.5rem;
}

.hero-logo {
  height: 100px;
  width: auto;
  margin-bottom: 0.5rem;
}

.hero-subtitle {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-bottom: 1.5rem;
}

.hero-desc {
  font-size: 1rem;
  color: var(--text-light);
  max-width: 500px;
  margin: 0 auto 1.5rem;
}

.hero-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  flex-wrap: wrap;
}

@media (min-width: 640px) {
  .hero { padding: 3rem 1rem; }
  .hero-logo { height: 120px; }
}

/* ============ BUTTONS ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.7rem 1.5rem;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-weight: 700;
  font-size: 0.9rem;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  -webkit-appearance: none;
}

.btn:active { transform: scale(0.97); }

.btn-primary { background: var(--text); color: var(--primary); }
.btn-primary:hover { background: #333; color: var(--primary); }
.btn-secondary { background: var(--primary); color: var(--text); border: 2px solid var(--text); }
.btn-success { background: var(--success); color: var(--white); }
.btn-danger { background: var(--error); color: var(--white); }
.btn-small { padding: 0.4rem 0.85rem; font-size: 0.8rem; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ============ FORMS ============ */
.form-group {
  margin-bottom: 0.85rem;
}

.form-group label {
  display: block;
  font-weight: 600;
  font-size: 0.85rem;
  margin-bottom: 0.3rem;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 0.7rem 0.85rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 16px; /* prevents iOS zoom */
  background: var(--white);
  transition: border-color 0.2s;
  -webkit-appearance: none;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--text);
}

.form-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

/* ============ ALERTS ============ */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 0.88rem;
  margin-bottom: 1rem;
}

.alert-error { background: var(--error-bg); color: var(--error); border: 1px solid var(--error); }
.alert-success { background: var(--success-bg); color: #2e7d32; border: 1px solid var(--success); }
.alert-info { background: #e3f0fc; color: #1565c0; border: 1px solid var(--accent-blue); }

/* ============ STATS GRID ============ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.6rem;
  margin-bottom: 1rem;
}

.stat-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 0.85rem 0.5rem;
  text-align: center;
  box-shadow: var(--shadow);
}

.stat-number {
  font-size: 1.8rem;
  font-weight: 900;
  line-height: 1;
  margin-bottom: 0.2rem;
}

.stat-label {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.stat-card.highlight { background: var(--primary); }

@media (min-width: 640px) {
  .stats-grid { gap: 1rem; margin-bottom: 1.5rem; }
  .stat-card { padding: 1.25rem; }
  .stat-number { font-size: 2.5rem; }
  .stat-label { font-size: 0.8rem; }
}

/* ============ LEADERBOARD ============ */
/* ============ CALENDAR ============ */
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}

.cal-header {
  text-align: center;
  font-weight: 800;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 0.4rem 0;
  color: var(--text-light);
}

.cal-day {
  position: relative;
  min-height: 52px;
  padding: 0.2rem;
  border-radius: 6px;
  background: var(--white);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow: hidden;
}

.cal-empty {
  background: transparent;
  border-color: transparent;
}

.cal-date {
  font-weight: 700;
  font-size: 0.72rem;
}

.cal-event {
  font-size: 0.55rem;
  font-weight: 500;
  color: var(--text-light);
  line-height: 1.15;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cal-check {
  position: absolute;
  top: 1px;
  right: 3px;
  font-size: 0.6rem;
  color: var(--success);
  font-weight: 900;
}

.cal-today {
  border-color: var(--text) !important;
  border-width: 2px;
}

.cal-type-run.cal-has-session { background: var(--primary-light); }
.cal-type-swim.cal-has-session { background: #e8f4fd; }
.cal-type-bike.cal-has-session { background: #f0ebf8; }
.cal-type-special.cal-has-session { background: #e8dff5; }

.cal-attended {
  background: var(--success-bg) !important;
}

@media (min-width: 640px) {
  .cal-day { min-height: 68px; padding: 0.3rem; }
  .cal-date { font-size: 0.8rem; }
  .cal-event { font-size: 0.65rem; }
}

/* ============ FILTER BUTTONS ============ */
.filter-btn {
  background: #eee;
  border: 2px solid transparent;
  transition: all 0.15s;
}

.filter-btn.active {
  border-color: var(--text);
}

/* ============ LEADERBOARD ============ */
.leaderboard-list { list-style: none; }

.leaderboard-item {
  display: flex;
  align-items: center;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
  gap: 0.75rem;
}

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

.leaderboard-rank {
  font-size: 1rem;
  font-weight: 800;
  min-width: 2rem;
  text-align: center;
}

.leaderboard-rank.gold { color: #f5a623; font-size: 1.3rem; }
.leaderboard-rank.silver { color: #9e9e9e; font-size: 1.2rem; }
.leaderboard-rank.bronze { color: #cd7f32; font-size: 1.1rem; }

.leaderboard-name { flex: 1; font-weight: 600; font-size: 0.92rem; }
.leaderboard-name.is-you { color: var(--accent-blue); }
.leaderboard-points { font-weight: 800; font-size: 1rem; }
.leaderboard-breakdown { font-size: 0.72rem; color: var(--text-muted); }

/* ============ SESSION LIST ============ */
.session-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--border);
  gap: 0.75rem;
  flex-wrap: wrap;
}

.session-item:last-child { border-bottom: none; }
.session-info { flex: 1; min-width: 0; }
.session-title { font-weight: 700; font-size: 0.95rem; }

.session-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.15rem;
}

.session-actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.badge {
  display: inline-block;
  padding: 0.12rem 0.5rem;
  border-radius: 20px;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge-run { background: var(--primary); color: var(--text); }
.badge-swim { background: #d4ecfc; color: #1565c0; }
.badge-bike { background: #e8dff5; color: #6a3d9a; }
.badge-special { background: var(--accent-purple); color: var(--white); }
.badge-active { background: var(--success-bg); color: #2e7d32; }
.badge-closed { background: #eee; color: #888; }

/* ============ QR PAGE ============ */
.qr-container { text-align: center; padding: 0.5rem; }

.qr-container img {
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  max-width: 280px;
  width: 100%;
}

.qr-session-title { font-size: 1.3rem; font-weight: 800; margin: 0.85rem 0 0.2rem; }
.qr-session-date { color: var(--text-muted); font-weight: 500; margin-bottom: 1.25rem; }

/* ============ CHECK-IN PAGE ============ */
.checkin-hero { text-align: center; padding: 0.75rem 0 1rem; }
.checkin-icon { font-size: 2.5rem; margin-bottom: 0.35rem; }
.checkin-title { font-size: 1.3rem; font-weight: 800; }

.success-animation { text-align: center; padding: 1.5rem 0; }

.success-check {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--success);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 2.2rem;
  color: var(--white);
  margin-bottom: 0.85rem;
  animation: popIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
  0% { transform: scale(0); }
  100% { transform: scale(1); }
}

/* ============ AUTOCOMPLETE ============ */
.autocomplete-wrap {
  position: relative;
}

.autocomplete-wrap input {
  width: 100%;
  padding: 0.7rem 0.85rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 16px;
  background: var(--white);
  transition: border-color 0.2s;
}

.autocomplete-wrap input:focus {
  outline: none;
  border-color: var(--text);
}

.autocomplete-results {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--white);
  border: 2px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  max-height: 200px;
  overflow-y: auto;
  z-index: 50;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.autocomplete-results.open { display: block; }

.autocomplete-item {
  padding: 0.65rem 0.85rem;
  cursor: pointer;
  font-size: 0.92rem;
  font-weight: 500;
  transition: background 0.15s;
}

.autocomplete-item:hover,
.autocomplete-item:active {
  background: var(--primary-light);
}

.autocomplete-item.no-result {
  color: var(--text-muted);
  font-style: italic;
  cursor: default;
}

.autocomplete-item.no-result:hover { background: none; }

/* ============ CHIPS (SELECTED FRIENDS) ============ */
.selected-friends {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.5rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--primary);
  padding: 0.3rem 0.65rem;
  border-radius: 20px;
  font-size: 0.82rem;
  font-weight: 600;
}

.chip-remove {
  background: none;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  line-height: 1;
  padding: 0;
  color: var(--text-light);
}

.chip-remove:hover { color: var(--error); }

/* ============ ACTIVITY LOG ============ */
.activity-list { list-style: none; }

.activity-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}

.activity-item:last-child { border-bottom: none; }

.activity-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--primary-dark);
  flex-shrink: 0;
}

.activity-date {
  color: var(--text-muted);
  font-size: 0.78rem;
  margin-left: auto;
  white-space: nowrap;
}

/* ============ ADMIN TABLE ============ */
.members-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.members-table th,
.members-table td {
  padding: 0.55rem 0.5rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.members-table th {
  font-weight: 700;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

.members-table tr:last-child td { border-bottom: none; }

/* ============ ATTENDEE LIST ============ */
.attendee-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.attendee-item:last-child { border-bottom: none; }
.attendee-name { font-weight: 600; }
.attendee-time { font-size: 0.78rem; color: var(--text-muted); }

/* ============ TAB NAV (ADMIN) ============ */
.tab-nav {
  display: flex;
  gap: 0;
  margin-bottom: 1.25rem;
  border-bottom: 2px solid var(--border);
}

.tab-nav a {
  padding: 0.65rem 1rem;
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.2s;
}

.tab-nav a:hover { color: var(--text); }
.tab-nav a.active { color: var(--text); border-bottom-color: var(--text); }

/* ============ EMPTY STATE ============ */
.empty-state {
  text-align: center;
  padding: 1.5rem 0.5rem;
  color: var(--text-muted);
}

.empty-state-icon { font-size: 2.2rem; margin-bottom: 0.4rem; }

/* ============ SECTION TITLE ============ */
.section-title { font-size: 1.2rem; font-weight: 800; margin-bottom: 0.85rem; }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.page-header h1 { font-size: 1.25rem; font-weight: 900; }

/* ============ REFERRAL SECTION ============ */
.referral-section {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.referral-section h3 {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 0.4rem;
}

/* ============ FOOTER ============ */
.footer {
  text-align: center;
  padding: 1.5rem 1rem;
  color: var(--text-muted);
  font-size: 0.78rem;
}

/* ============ SOCIAL LINKS ============ */
.social-links {
  display: flex;
  gap: 1.25rem;
  justify-content: center;
  margin-bottom: 0.25rem;
}

.social-links a {
  color: var(--text-muted);
  transition: color 0.2s, transform 0.2s;
  display: flex;
}

.social-links a:hover {
  color: var(--text);
  transform: scale(1.15);
}

/* ============ EVENT MODAL ============ */
.event-modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.event-modal-overlay.open {
  display: flex;
}

.event-modal {
  background: var(--white);
  border-radius: var(--radius);
  padding: 1.25rem;
  max-width: 400px;
  width: 100%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  position: relative;
}

#event-modal-content {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1;
  min-height: 0;
}

.event-modal-close {
  position: absolute;
  top: 0.75rem;
  right: 1rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
}

/* ============ EVENT SLIDER (multi-event days) ============ */
.event-slider {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  gap: 0;
  scrollbar-width: none;
}

.event-slider::-webkit-scrollbar { display: none; }

.event-slide {
  flex: 0 0 100%;
  scroll-snap-align: start;
  min-width: 0;
  padding-right: 1rem;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

@media (min-width: 640px) {
  .event-slider {
    scroll-snap-type: none;
    overflow-x: visible;
    flex-wrap: nowrap;
  }
  .event-slide {
    flex: 1 1 0;
    scroll-snap-align: none;
    max-height: 65vh;
  }
  .event-modal {
    max-width: 640px;
  }
}

.event-dot-nav {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
  margin: 0 3px;
  cursor: pointer;
  transition: background 0.2s;
}

.event-dot-nav.active {
  background: var(--text);
}

/* ============ GOING / RSVP ============ */
.btn-going {
  background: #e8f5e9;
  color: #2e7d32;
  border: 1.5px solid #4caf50;
}

.btn-going:hover { background: #c8e6c9; }

.btn-going-active {
  background: #4caf50;
  color: #fff;
  border: 1.5px solid #4caf50;
}

.btn-going-active:hover { background: #43a047; }

.cal-rsvp {
  position: absolute;
  bottom: 1px;
  left: 3px;
  font-size: 0.45rem;
  color: #2e7d32;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.2px;
}

@media (min-width: 640px) {
  .cal-rsvp { font-size: 0.55rem; }
}

/* ============ UTILITIES ============ */
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
