:root {
  --bg: #f9fafb;
  --surface: #ffffff;
  --surface-muted: #f3f4f6;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #111827;
  --text-secondary: #4b5563;
  --muted: #6b7280;
  --accent: #fc4c02;
  --accent-hover: #e34402;
  --accent-light: #fff7ed;
  --success: #10b981;
  --error: #ef4444;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.container { max-width: 960px; margin: 0 auto; padding: 0 1.25rem; }

/* ===== HEADER ===== */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 56px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--accent);
  text-decoration: none;
  font-weight: 700;
  font-size: 0.9375rem;
}

.brand-icon { flex-shrink: 0; }
.brand-name { color: var(--text); }

nav { display: flex; align-items: center; gap: 0.25rem; }
nav a {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.375rem 0.75rem;
  border-radius: var(--radius-sm);
  transition: background 0.15s, color 0.15s;
}
nav a:hover { background: var(--surface-muted); color: var(--text); }
nav .nav-muted { color: var(--muted); }

/* ===== MAIN ===== */
.main-content { padding: 2rem 0 4rem; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.625rem 1.25rem;
  border-radius: var(--radius-sm);
  font: inherit;
  font-weight: 600;
  font-size: 0.875rem;
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-strava { background: var(--accent); color: #fff; }
.btn-strava:hover { background: var(--accent-hover); transform: translateY(-1px); box-shadow: var(--shadow); }

.btn-secondary {
  background: var(--surface);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--surface-muted); border-color: var(--border-strong); }

.btn-outline {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }

.btn-small { padding: 0.375rem 0.75rem; font-size: 0.8125rem; }
.btn-lg { padding: 0.875rem 1.5rem; font-size: 1rem; font-weight: 600; width: 100%; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== CARDS ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
}

/* ===== DASHBOARD ===== */
.dashboard-grid {
  display: grid;
  gap: 1.5rem;
}

.profile-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.5rem;
}

.profile-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border);
}

.profile-info h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.3;
}

.profile-info p {
  font-size: 0.875rem;
  color: var(--muted);
  margin-top: 0.125rem;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
}

.stat-item {
  text-align: center;
  padding: 1.25rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.stat-value {
  display: block;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

.stat-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 0.25rem;
}

.coach-cta {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 1.5rem;
  background: linear-gradient(135deg, var(--accent-light), var(--surface));
  border: 1px solid #fed7aa;
}

.coach-cta-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.coach-cta-text { flex: 1; }
.coach-cta-text h2 { font-size: 1rem; font-weight: 700; margin-bottom: 0.25rem; }
.coach-cta-text p { font-size: 0.875rem; color: var(--text-secondary); }

.coach-cta-disabled {
  opacity: 0.5;
  pointer-events: none;
  cursor: default;
  filter: grayscale(0.4);
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}
.section-header h2 { font-size: 1rem; font-weight: 700; }
.section-header a { font-size: 0.8125rem; color: var(--accent); text-decoration: none; font-weight: 500; }

/* ===== RIDES TABLE ===== */
.rides-list { display: flex; flex-direction: column; gap: 0; }

.ride-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.875rem 1.25rem;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  color: inherit;
  transition: background 0.1s;
}
.ride-row:last-child { border-bottom: none; }
.ride-row:hover { background: var(--surface-muted); }

.ride-row-info { flex: 1; min-width: 0; }
.ride-row-name {
  font-size: 0.875rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ride-row-meta { font-size: 0.8125rem; color: var(--muted); margin-top: 0.125rem; }

.ride-row-stats {
  display: flex;
  gap: 1rem;
  font-size: 0.8125rem;
  color: var(--text-secondary);
  flex-shrink: 0;
}
.ride-row-stats span { white-space: nowrap; }

/* ===== SYNC BANNER ===== */
.sync-banner {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
}

.sync-banner.sync-running { border-color: var(--accent); background: var(--accent-light); }
.sync-banner.sync-done { border-color: var(--success); background: #ecfdf5; }
.sync-banner.sync-error { border-color: var(--error); background: #fef2f2; }

.sync-banner-inner { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }

.sync-banner-text { flex: 1; min-width: 200px; }
.sync-banner-text strong { display: block; font-size: 0.875rem; font-weight: 600; }
.sync-banner-text p { font-size: 0.8125rem; color: var(--muted); margin-top: 0.125rem; }
.sync-banner-hint { font-size: 0.75rem !important; }

.sync-progress {
  flex: 1 1 180px;
  height: 4px;
  background: #ffe0d0;
  border-radius: 999px;
  overflow: hidden;
}
.sync-progress-bar {
  height: 100%;
  width: 35%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.3s ease;
}
.sync-progress-indeterminate { animation: sync-slide 1.2s ease-in-out infinite; }
@keyframes sync-slide {
  0% { transform: translateX(-100%); width: 40%; }
  50% { transform: translateX(80%); width: 55%; }
  100% { transform: translateX(220%); width: 40%; }
}

/* ===== AI COACH CHAT ===== */
.coach-chat-page { padding-bottom: 0; }

.coach-chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 120px);
  min-height: 500px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.coach-chat-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.coach-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.coach-avatar svg { fill: #fff; }

.coach-header-text { flex: 1; }
.coach-header-text strong { display: block; font-size: 0.875rem; }
.coach-status { font-size: 0.75rem; color: var(--success); }

.coach-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.chat-message { display: flex; max-width: 80%; }
.chat-message-coach { align-self: flex-start; }
.chat-message-athlete { align-self: flex-end; }

.chat-bubble {
  border-radius: 16px;
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  line-height: 1.6;
  word-break: break-word;
}

.chat-message-coach .chat-bubble {
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.chat-message-athlete .chat-bubble {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-bubble-content h3 {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--accent);
  margin: 0.75rem 0 0.25rem;
}
.chat-message-coach .chat-bubble-content h3:first-child { margin-top: 0; }
.chat-bubble-content ul { margin: 0.5rem 0; padding-left: 1.25rem; }
.chat-bubble-content li { margin-bottom: 0.25rem; }

.chat-loading {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0;
  color: var(--muted);
  font-size: 0.8125rem;
}

.typing-indicator { display: flex; gap: 3px; }
.typing-indicator span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.4;
  animation: typing-bounce 1.4s ease-in-out infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.coach-chat-input {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.coach-chat-input textarea {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 0.625rem 1rem;
  font: inherit;
  font-size: 0.875rem;
  resize: none;
  line-height: 1.5;
  max-height: 120px;
  outline: none;
  transition: border-color 0.15s;
}
.coach-chat-input textarea:focus { border-color: var(--accent); }

.btn-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* Ride selector */
.coach-ride-selector {
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin: 1rem 0;
  background: var(--accent-light);
  max-height: 480px;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.ride-selector-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}
.ride-selector-header strong { font-size: 1.125rem; font-weight: 700; color: var(--text); }
.ride-selector-hint { font-size: 0.875rem; color: var(--accent); font-weight: 500; }

.ride-selector-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.625rem;
  margin-bottom: 1rem;
}

.ride-card {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  padding: 0.875rem 1rem;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}
.ride-card:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.ride-card:has(input:checked) { border-color: var(--accent); background: #fff4ed; box-shadow: 0 0 0 1px var(--accent); }
.ride-card input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--accent); flex-shrink: 0; }
.ride-card-body { flex: 1; min-width: 0; }
.ride-card-body strong { display: block; font-size: 0.9375rem; font-weight: 600; margin-bottom: 0.125rem; }
.ride-card-meta { font-size: 0.8125rem; color: var(--text-secondary); }

/* ===== FORMS ===== */
.field { display: block; margin-bottom: 1.25rem; }
.field span { display: block; font-weight: 500; font-size: 0.875rem; margin-bottom: 0.375rem; color: var(--text-secondary); }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 0.625rem 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.875rem;
  background: var(--surface);
  transition: border-color 0.15s;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--accent); }

/* ===== ALERTS ===== */
.alert { padding: 0.75rem 1rem; border-radius: var(--radius-sm); font-size: 0.875rem; margin-bottom: 1rem; }
.alert-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }

/* ===== HERO (landing page) ===== */
.hero { text-align: center; padding: 4rem 0 2rem; }
.hero h1 { font-size: 2.25rem; font-weight: 700; letter-spacing: -0.03em; margin-bottom: 0.75rem; }
.hero p { color: var(--text-secondary); max-width: 480px; margin: 0 auto 2rem; font-size: 1.0625rem; }

/* ===== ONBOARDING ===== */
.panel { max-width: 560px; margin: 0 auto; }
.panel h1 { font-size: 1.5rem; font-weight: 700; margin-bottom: 0.5rem; }

.onboarding-page {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 2rem 0;
  min-height: calc(100vh - 120px);
}

.onboarding-card {
  width: 100%;
  max-width: 540px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  padding: 2.5rem;
}

.onboarding-header {
  text-align: center;
  margin-bottom: 2rem;
}

.onboarding-icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent-light);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1.25rem;
}

.onboarding-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 0.5rem;
}

.onboarding-subtitle {
  color: var(--text-secondary);
  font-size: 0.9375rem;
  line-height: 1.5;
}

.onboarding-options {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.option-card {
  display: block;
  cursor: pointer;
}

.option-card input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.option-card-content {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  transition: all 0.15s ease;
}

.option-card:hover .option-card-content {
  border-color: var(--border-strong);
  background: var(--surface-muted);
}

.option-card[data-selected] .option-card-content {
  border-color: var(--accent);
  background: var(--accent-light);
  box-shadow: 0 0 0 1px var(--accent);
}

.option-card-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--surface-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--text-secondary);
}

.option-card[data-selected] .option-card-icon {
  background: var(--accent);
  color: white;
}

.option-card-text {
  flex: 1;
  min-width: 0;
}

.option-card-text strong {
  display: block;
  font-size: 0.9375rem;
  font-weight: 600;
  margin-bottom: 0.125rem;
}

.option-card-text span {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

.option-badge {
  padding: 0.25rem 0.625rem;
  border-radius: 100px;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  flex-shrink: 0;
}

.option-badge-best {
  background: var(--accent);
  color: white;
}

.sport-types-panel {
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
}

.sport-types-label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
}

.sport-types-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.sport-chip {
  display: inline-flex;
  cursor: pointer;
}

.sport-chip input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.sport-chip span {
  padding: 0.375rem 0.875rem;
  border-radius: 100px;
  font-size: 0.8125rem;
  font-weight: 500;
  background: var(--surface);
  border: 1px solid var(--border);
  transition: all 0.15s;
}

.sport-chip input:checked + span {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.sport-chip:hover span {
  border-color: var(--accent);
}

.onboarding-footer {
  text-align: center;
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 1.5rem;
}

/* ===== ACTIVITY DETAIL ===== */
.breadcrumb { margin-bottom: 1.5rem; }
.breadcrumb a { color: var(--muted); text-decoration: none; font-size: 0.875rem; }
.breadcrumb a:hover { color: var(--accent); }

/* ===== COACH ERROR ===== */
.coach-error { color: var(--error); }
.coach-response.coach-error-box { background: #fef2f2; border-color: #fecaca; }

/* ===== RESPONSIVE ===== */
@media (max-width: 640px) {
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .ride-row-stats { display: none; }
  .coach-chat-container { height: calc(100vh - 100px); border-radius: 0; border-left: none; border-right: none; }
  .chat-message { max-width: 90%; }
}
