:root {
  --bg: #0f1115;
  --bg2: #161a21;
  --card: #1b2029;
  --border: #272e3a;
  --text: #e8ecf1;
  --muted: #8b94a3;
  --accent: #fc4c02;
  --green: #25d366;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }

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

[hidden] { display: none !important; }

/* ---------- Onboarding ---------- */
.view { max-width: 1080px; margin: 0 auto; padding: 20px; }

#view-onboarding {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border: 1px solid var(--bg2);
  border-radius: 20px;
  padding: 36px 32px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .45);
}

.auth-logo { display: flex; align-items: center; gap: 12px; }
.auth-logo h1 { margin: 0; font-size: 26px; letter-spacing: -.5px; }
.auth-sub { color: var(--muted); margin: 8px 0 28px; }

form label { display: block; margin-bottom: 16px; }
form label span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
form input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--bg2);
  background: var(--bg2);
  color: var(--text);
  font-size: 15px;
  outline: none;
}
form input:focus { border-color: var(--accent); }

.btn {
  border: 0;
  border-radius: 10px;
  padding: 13px 18px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.btn-strava {
  width: 100%;
  background: var(--accent);
  color: #fff;
}
.btn-strava:hover { filter: brightness(1.1); }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--bg2);
  color: var(--muted);
  padding: 8px 14px;
  border-radius: 8px;
}
.btn-ghost:hover { color: var(--text); border-color: var(--muted); }

.auth-note { color: var(--muted); font-size: 12.5px; margin-top: 22px; line-height: 1.5; }
.error { color: #ff5a5f; font-size: 13px; margin-top: 10px; }

/* ---------- Dashboard ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 4px;
  border-bottom: 1px solid var(--bg2);
  margin-bottom: 20px;
}
.brand { font-weight: 700; }
.userbox { display: flex; align-items: center; gap: 12px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--accent); object-fit: cover; }

.content { display: grid; gap: 20px; }

.card {
  background: var(--card);
  border: 1px solid var(--bg2);
  border-radius: 16px;
  padding: 20px;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}
.card-head h2 { margin: 0; font-size: 18px; }
.muted { color: var(--muted); font-size: 14px; }

/* última sesión */
#last-body .grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
}
.metric {
  background: var(--bg2);
  border-radius: 12px;
  padding: 14px 16px;
}
.metric .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
.metric .value { font-family: var(--mono); font-size: 24px; margin-top: 4px; }
.metric .value small { font-size: 13px; color: var(--muted); }
.ride-headline { margin: 0 0 16px; font-size: 20px; }
.ride-headline span { color: var(--muted); }

.skeleton {
  height: 160px;
  border-radius: 12px;
  background: linear-gradient(90deg, var(--bg2) 25%, var(--card) 50%, var(--bg2) 75%);
  background-size: 400% 100%;
  animation: sh 1.2s infinite;
}
@keyframes sh { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

/* comparación últimas sesiones */
.compare-head {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 12px;
  align-items: end;
  margin-bottom: 14px;
  text-align: left;
}
.compare-head .right { text-align: right; }
.compare-head .versus {
  align-self: center;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.compare {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 18px;
  font-size: 14px;
}
.compare th {
  text-align: left;
  color: var(--muted);
  font-weight: 500;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .5px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--bg2);
}
.compare td { padding: 8px; border-bottom: 1px solid var(--bg2); }
.compare .c-label { color: var(--muted); width: 38%; }
.compare .c-last { font-family: var(--mono); font-weight: 600; }
.compare .c-prev { font-family: var(--mono); }
.compare .c-delta { text-align: right; width: 30%; }
.delta { font-family: var(--mono); font-size: 13px; font-weight: 600; text-align: right; }
.delta.up { color: var(--green); }
.delta.down { color: #ff5a5f; }
.delta.neutral { color: var(--muted); font-weight: 500; }

/* segmented */
.segmented { display: inline-flex; background: var(--bg2); border-radius: 10px; padding: 3px; gap: 2px; }
.segmented button {
  border: 0; background: transparent; color: var(--muted);
  padding: 7px 12px; border-radius: 8px; font-size: 13px; cursor: pointer;
}
.segmented button.active { background: var(--card); color: var(--text); box-shadow: 0 2px 6px rgba(0,0,0,.4); font-weight: 600; }

.chart-wrap { position: relative; height: 300px; }

/* historial */
.history { list-style: none; margin: 0; padding: 0; }
.history li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 10px;
  border-radius: 10px;
  cursor: pointer;
  transition: background .15s;
}
.history li:hover, .history li.active { background: var(--bg2); }
.history .h-name { font-weight: 600; }
.history .h-meta { color: var(--muted); font-size: 13px; font-family: var(--mono); }

/* modal */
.modal { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.6); }
.modal-panel {
  position: relative;
  width: 100%;
  max-width: 640px;
  max-height: 85vh;
  overflow: auto;
  background: var(--card);
  border: 1px solid var(--bg2);
  border-radius: 16px;
  padding: 24px;
}
.modal-close {
  position: absolute; top: 12px; right: 14px;
  background: transparent; border: 0; color: var(--muted);
  font-size: 26px; cursor: pointer; line-height: 1;
}
.modal-close:hover { color: var(--text); }

.loading {
  position: fixed; bottom: 18px; right: 18px;
  background: var(--bg2); color: var(--muted);
  border: 1px solid var(--bg2); border-radius: 20px; padding: 8px 14px; font-size: 13px;
}

@media (max-width: 520px) {
  .card-head { flex-direction: column; align-items: flex-start; }
}