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

:root {
  --orange:      #FC4C02;
  --orange-dark: #C93D00;
  --dark:        #0f0f1a;
  --card-bg:     #1a1a2e;
  --card-border: rgba(252, 76, 2, 0.25);
  --text:        #e8e8f0;
  --text-muted:  #888;
  --green:       #2ecc71;
  --radius:      16px;
  --shadow:      0 8px 32px rgba(0,0,0,0.4);
}

html { font-size: 16px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--dark);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }

/* ── Utility ─────────────────────────────────────────────────────────────── */
.orange { color: var(--orange); }
.green  { color: var(--green); }

.alert {
  padding: 0.875rem 1.25rem;
  border-radius: 10px;
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
}
.alert-warning {
  background: rgba(252, 76, 2, 0.12);
  border: 1px solid rgba(252, 76, 2, 0.35);
  color: #ffb399;
}

/* ── Login page ──────────────────────────────────────────────────────────── */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: radial-gradient(ellipse at 60% 20%, rgba(252,76,2,0.15) 0%, transparent 60%),
              radial-gradient(ellipse at 10% 80%, rgba(252,76,2,0.08) 0%, transparent 50%),
              var(--dark);
}

.login-container {
  width: 100%;
  max-width: 440px;
  padding: 1.5rem;
}

.login-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 24px;
  padding: 2.5rem 2rem;
  box-shadow: var(--shadow);
}

.login-hero {
  text-align: center;
  margin-bottom: 2rem;
}

.bike-icon {
  font-size: 3.5rem;
  margin-bottom: 0.75rem;
}

.login-hero h1 {
  font-size: 2rem;
  font-weight: 800;
  line-height: 1.2;
  margin-bottom: 0.75rem;
  color: var(--text);
}

.tagline {
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.6;
}

/* Strava button */
.btn-strava {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.625rem;
  width: 100%;
  padding: 0.875rem 1.5rem;
  background: var(--orange);
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  border-radius: 12px;
  transition: background 0.15s, transform 0.1s;
  border: none;
  cursor: pointer;
  letter-spacing: 0.01em;
  margin-bottom: 1.75rem;
}
.btn-strava:hover  { background: var(--orange-dark); transform: translateY(-1px); }
.btn-strava:active { transform: translateY(0); }

.strava-logo { width: 22px; height: 22px; }

/* Features list */
.features {
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  margin-bottom: 1.5rem;
}
.feature-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}
.feature-icon { font-size: 1.1rem; width: 1.5rem; text-align: center; }

.disclaimer {
  font-size: 0.75rem;
  color: #555;
  text-align: center;
  line-height: 1.6;
}
.disclaimer-link { color: var(--orange); text-decoration: none; }
.disclaimer-link:hover { text-decoration: underline; }

/* ── Navbar ──────────────────────────────────────────────────────────────── */
.navbar {
  background: rgba(26, 26, 46, 0.95);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--card-border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.nav-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.nav-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.05rem;
  font-weight: 700;
}
.bike-sm { font-size: 1.3rem; }
.nav-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid var(--orange);
  object-fit: cover;
}
.nav-name {
  font-size: 0.875rem;
  color: var(--text-muted);
}
.btn-logout {
  font-size: 0.8rem;
  padding: 0.375rem 0.875rem;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px;
  color: var(--text-muted);
  transition: border-color 0.15s, color 0.15s;
}
.btn-logout:hover { border-color: var(--orange); color: var(--orange); }

/* ── Dashboard ───────────────────────────────────────────────────────────── */
.dashboard-body { background: var(--dark); }

.main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 4rem;
}

.page-header { margin-bottom: 2rem; }
.page-header h1 {
  font-size: 1.75rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.badge {
  font-size: 0.7rem;
  font-weight: 600;
  background: rgba(252,76,2,0.15);
  border: 1px solid var(--card-border);
  color: var(--orange);
  padding: 0.25rem 0.625rem;
  border-radius: 20px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.sub {
  color: var(--text-muted);
  margin-top: 0.375rem;
  font-size: 0.9rem;
}

/* Segment cards grid */
.segments-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1.25rem;
}

.segment-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  transition: border-color 0.2s, transform 0.15s;
  position: relative;
  overflow: hidden;
}
.segment-card:hover {
  border-color: rgba(252,76,2,0.5);
  transform: translateY(-2px);
}
.segment-card.is-legend {
  border-color: gold;
  background: linear-gradient(135deg, #1a1a2e 0%, #1e1e12 100%);
}
.segment-card.is-legend::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at top right, rgba(255,215,0,0.06), transparent 60%);
  pointer-events: none;
}

.rank-badge {
  position: absolute;
  top: 1rem;
  right: 1rem;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.05em;
}

.legend-crown {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: gold;
  background: rgba(255, 215, 0, 0.1);
  border: 1px solid rgba(255,215,0,0.25);
  border-radius: 20px;
  padding: 0.25rem 0.75rem;
  display: inline-block;
  margin-bottom: 0.75rem;
  text-transform: uppercase;
}

.seg-name {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 1.25rem;
  padding-right: 2rem; /* make space for rank badge */
  line-height: 1.3;
  color: var(--text);
}

/* Stats row */
.stats-row {
  display: flex;
  align-items: center;
  justify-content: space-around;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
  background: rgba(255,255,255,0.04);
  border-radius: 12px;
  padding: 1rem 0.5rem;
}
.stat { text-align: center; flex: 1; }
.stat-label { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 0.25rem; }
.stat-value { font-size: 2rem; font-weight: 800; line-height: 1; margin-bottom: 0.25rem; }
.stat-name { font-size: 0.75rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 120px; margin: 0 auto; }
.stat-divider { color: var(--text-muted); font-weight: 700; font-size: 0.8rem; }

/* Progress bar */
.progress-container {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.progress-track {
  flex: 1;
  height: 10px;
  background: rgba(255,255,255,0.08);
  border-radius: 99px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--orange-dark), var(--orange));
  border-radius: 99px;
  transition: width 0.6s ease;
  min-width: 4px;
}
.progress-pct {
  font-size: 0.75rem;
  color: var(--text-muted);
  width: 2.5rem;
  text-align: right;
  flex-shrink: 0;
}

/* Stat value colour variants */
.stat-value.green { color: #2ecc71; }
.stat-value.blue  { color: #3498db; }
.stat-value.muted { color: var(--text-muted); }

/* Efforts message */
.efforts-msg {
  font-size: 0.875rem;
  margin-bottom: 1rem;
  min-height: 1.4em;
}
.msg-legend { color: gold; }
.msg-close  { color: var(--orange); }
.msg-normal { color: var(--text-muted); }

/* Goal label below progress bar */
.goal-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
  margin-top: -0.5rem;
}

/* Goal-setting collapsible */
.goal-details {
  margin-bottom: 1rem;
}
.goal-summary {
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--orange);
  font-weight: 600;
  user-select: none;
  list-style: none;
  outline: none;
}
.goal-summary::-webkit-details-marker { display: none; }
.goal-form {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.6rem;
  flex-wrap: wrap;
}
.goal-form label {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
}
.goal-input {
  width: 80px;
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.07);
  color: var(--text);
  font-size: 0.85rem;
  text-align: center;
}
.goal-input:focus { outline: none; border-color: var(--orange); }
.btn-set-goal, .btn-clear-goal {
  padding: 0.35rem 0.8rem;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background 0.15s;
}
.btn-set-goal {
  background: var(--orange);
  color: #fff;
}
.btn-set-goal:hover { background: var(--orange-dark); }
.btn-clear-goal {
  background: rgba(255,255,255,0.07);
  color: var(--text-muted);
  border: 1px solid rgba(255,255,255,0.12);
}
.btn-clear-goal:hover { background: rgba(255,255,255,0.12); }

/* Card actions */
.card-actions {
  display: flex;
  gap: 0.625rem;
  flex-wrap: wrap;
}
.btn-download, .btn-preview {
  flex: 1;
  padding: 0.625rem 0.75rem;
  border-radius: 10px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  text-align: center;
  border: none;
}
.btn-download {
  background: var(--orange);
  color: #fff;
  display: block;
}
.btn-download:hover { background: var(--orange-dark); transform: translateY(-1px); }
.btn-preview {
  background: rgba(255,255,255,0.07);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.1);
}
.btn-preview:hover { background: rgba(255,255,255,0.12); }
.btn-preview:disabled { opacity: 0.5; cursor: not-allowed; }

/* Inline preview */
.preview-area {
  margin-top: 1rem;
  border-top: 1px solid rgba(255,255,255,0.07);
  padding-top: 1rem;
}
.preview-img {
  width: 100%;
  border-radius: 10px;
  display: block;
}
.preview-hint {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
  text-align: center;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
}
.empty-icon { font-size: 4rem; margin-bottom: 1rem; }
.empty-state h2 { font-size: 1.5rem; margin-bottom: 0.5rem; }
.empty-state p { color: var(--text-muted); margin-bottom: 1.5rem; }
.btn-refresh {
  display: inline-block;
  padding: 0.75rem 1.5rem;
  background: var(--orange);
  color: #fff;
  border-radius: 10px;
  font-weight: 600;
  transition: background 0.15s;
}
.btn-refresh:hover { background: var(--orange-dark); }

/* Footer */
.footer {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 2rem 1rem;
  color: var(--text-muted);
  font-size: 0.8rem;
  border-top: 1px solid rgba(255,255,255,0.06);
}
.footer-divider { opacity: 0.4; }
.footer-link { color: var(--text-muted); text-decoration: none; }
.footer-link:hover { color: var(--orange); }

/* Powered by Strava badge — required by Strava API Terms */
.powered-by-strava {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: #FC4C02;
  font-weight: 700;
  font-size: 0.8rem;
  text-decoration: none;
  letter-spacing: 0.01em;
}
.powered-by-strava:hover { opacity: 0.85; }
.strava-badge-logo { width: 18px; height: 18px; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .segments-grid { grid-template-columns: 1fr; }
  .page-header h1 { font-size: 1.4rem; }
  .stat-value { font-size: 1.5rem; }
}
