:root {
  color-scheme: light dark;
  --fg: #1b1b1f;
  --bg: #fafafa;
  --card: #ffffff;
  --border: #e2e2e6;
  --accent: #d1495b;
  --muted: #6b6b75;
  --highlight: #4062bb;
  --highlight-hover: #34519a;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fg: #e9e9ee;
    --bg: #17171b;
    --card: #1f1f24;
    --border: #303038;
    --muted: #9a9aa5;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
}

.topbar {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.topbar h1 { margin: 0; font-size: 1.25rem; }

.home-link {
  display: flex;
  align-items: center;
  gap: .55rem;
  color: inherit;
  text-decoration: none;
}
.home-link:hover .brand-caps { color: var(--highlight); }

.brand-logo { display: block; flex-shrink: 0; }

.brand-name { line-height: 1; }
.brand-caps { font-weight: 800; letter-spacing: .03em; }
.brand-lower { font-weight: 400; color: var(--muted); }

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.settings-link {
  font-size: .85rem;
  color: var(--muted);
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .3rem .7rem;
}

.settings-link:hover { color: var(--fg); border-color: var(--fg); }

.logout-form { margin: 0; }

button.settings-link {
  background: transparent;
  font-family: inherit;
  cursor: pointer;
}

.unit-toggle {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .85rem;
  color: var(--muted);
}

.unit-toggle select {
  background: var(--card);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .3rem .5rem;
  font-size: .85rem;
}

.forecast-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  margin-bottom: 1rem;
}

.forecast-summary .stat {
  display: flex;
  flex-direction: column;
}

.forecast-summary .stat .value { font-size: 1.5rem; font-weight: 600; }
.forecast-summary .stat .label { font-size: .8rem; color: var(--muted); }

.forecast-note {
  font-size: .8rem;
  color: var(--muted);
  margin-top: .75rem;
}

.chart-legend-note {
  font-size: .75rem;
  color: var(--muted);
  margin: .5rem 0 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  flex-wrap: wrap;
  text-align: center;
}

.legend-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-left: .4rem;
}

.legend-green { background: #2e9e5b; }
.legend-red { background: #d1495b; }
.legend-orange { background: #e0a458; }
.legend-strava { background: #fc4c02; } /* Strava's own brand orange */
.legend-blue { background: #4062bb; }
.legend-darkblue { background: #1a2f66; }
.legend-grey { background: #9a9aa5; }
.legend-darkgrey { background: #5a5a63; }
.legend-lightgrey { background: #b8b8c0; }

.plan-link {
  font-size: .75rem;
  text-transform: none;
  letter-spacing: normal;
  font-weight: 400;
  margin-left: .5rem;
  color: var(--muted);
}

.row-upcoming { font-style: italic; color: var(--muted); }

.row-bg-planned { background: rgba(150, 150, 160, 0.14); }
.row-bg-swim { background: rgba(64, 98, 187, 0.12); }
.row-bg-bike { background: rgba(155, 89, 182, 0.12); }
.row-bg-run { background: rgba(46, 158, 91, 0.12); }
.row-bg-other { background: rgba(224, 164, 88, 0.14); }

.legend-swatch {
  display: inline-block;
  width: 14px;
  height: 10px;
  border-radius: 3px;
  margin-left: .4rem;
  vertical-align: middle;
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem;
  display: grid;
  gap: 1.5rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem;
}

.card h2 { margin-top: 0; font-size: 1rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.sources {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
}

.source-pill {
  display: flex;
  align-items: center;
  gap: .5rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: .4rem .9rem;
  font-size: .85rem;
}

.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status-ok { background: #2e9e5b; }
.status-partial { background: #e0a458; }
.status-error { background: var(--accent); }
.status-auth-expired { background: var(--accent); animation: pulse-dot 1.6s ease-in-out infinite; }

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: .35; }
}

.auth-expired-banner {
  background: rgba(209, 73, 91, 0.12);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: .6rem .9rem;
  font-size: .85rem;
  margin: .5rem 0 0;
}

.auth-expired-banner a { color: inherit; font-weight: 600; }

.source-pill button {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  text-decoration: underline;
  font-size: .8rem;
  padding: 0;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

@media (max-width: 800px) {
  .grid-2 { grid-template-columns: 1fr; }
}

table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .5rem .4rem; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 500; }

.empty { color: var(--muted); font-size: .9rem; }

.settings-form h3 {
  font-size: .85rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin: 1.5rem 0 .75rem;
}

.settings-form h3:first-child { margin-top: 0; }

.settings-group {
  display: grid;
  gap: .9rem;
  grid-template-columns: 1fr;
}

.settings-field {
  display: flex;
  flex-direction: column;
  gap: .3rem;
  font-size: .85rem;
  color: var(--muted);
}

.settings-field input,
.settings-field select {
  background: var(--card);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .5rem .6rem;
  font-size: .9rem;
}

.settings-textarea {
  background: var(--card);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .6rem .7rem;
  font-size: .8rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  resize: vertical;
  width: 100%;
}

.settings-actions-top,
.settings-actions-bottom {
  display: flex;
  justify-content: flex-end;
}

.settings-actions-top { margin-bottom: 1rem; }
.settings-actions-bottom { margin-top: 2.5rem; }

.settings-actions-top button,
.settings-actions-bottom button {
  background: var(--highlight);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: .6rem 1.2rem;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
}

.settings-actions-top button:hover,
.settings-actions-bottom button:hover { background: var(--highlight-hover); }

.settings-saved {
  color: #2e9e5b;
  font-size: .85rem;
  font-weight: 600;
}

.login-card {
  max-width: 360px;
  margin: 3rem auto 0;
}

.login-error {
  color: var(--accent);
  font-size: .85rem;
  font-weight: 600;
}

.token-flash {
  background: rgba(46, 158, 91, 0.12);
  border: 1px solid #2e9e5b;
  border-radius: 6px;
  padding: .75rem 1rem;
  font-size: .85rem;
  margin: 1rem 0;
}

.token-flash code {
  display: block;
  margin-top: .4rem;
  font-size: .95rem;
  word-break: break-all;
}

.token-form {
  display: flex;
  gap: .6rem;
  align-items: flex-end;
  margin-top: 1rem;
}

.token-form .settings-field { flex: 1; margin: 0; }

.token-form button {
  margin: 0;
  background: var(--highlight);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: .55rem 1rem;
  font-size: .85rem;
  cursor: pointer;
}

.token-form button:hover { background: var(--highlight-hover); }

.revoke-form { margin: 0; }

.revoke-form button {
  background: transparent;
  border: none;
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
  font-size: .8rem;
  padding: 0;
}

.mfa-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 1000;
}

.mfa-modal {
  max-width: 420px;
  width: 100%;
}

.mfa-modal-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 2.5rem;
}

/* Same footprint as the Settings page's Save button for both, so Submit and
   Cancel line up -- Cancel just gets an outlined/secondary look instead of
   the filled highlight color. */
.mfa-modal-actions button {
  margin: 0;
  padding: .6rem 1.2rem;
  font-size: .9rem;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
}

.mfa-modal-actions button[type="submit"] {
  background: var(--highlight);
  color: #fff;
  border: none;
}

.mfa-modal-actions button[type="submit"]:hover {
  background: var(--highlight-hover);
}

.mfa-modal-cancel {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.mfa-modal-cancel:hover {
  color: var(--fg);
  border-color: var(--fg);
}

.weekly-volume-stats {
  display: flex;
  justify-content: center;
  gap: 2.5rem;
  margin-bottom: .75rem;
}

.weekly-volume-stats .stat {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.weekly-volume-stats .stat .value { font-size: 1.5rem; font-weight: 600; }
.weekly-volume-stats .stat .label { font-size: .8rem; color: var(--muted); }

.weekly-volume-wrap {
  position: relative;
  width: 100%;
  height: 90px;
}

.calendar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .75rem;
}

.calendar-nav {
  display: flex;
  align-items: center;
  gap: .5rem;
  text-transform: none;
  letter-spacing: normal;
}

.calendar-nav-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
}

.calendar-nav-btn:hover { color: var(--fg); border-color: var(--fg); }

.calendar-label {
  font-size: .85rem;
  font-weight: 600;
  color: var(--fg);
  min-width: 110px;
  text-align: center;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.calendar-head {
  background: var(--card);
  padding: .4rem;
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
  text-align: center;
}

.calendar-cell {
  background: var(--card);
  min-height: 108px;
  padding: .35rem;
}

.calendar-today { box-shadow: inset 0 0 0 2px var(--highlight); }

.calendar-day-num {
  font-size: .72rem;
  font-weight: 500;
  color: var(--muted);
  width: 20px;
  height: 20px;
  margin-left: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.calendar-day-num-today { font-weight: 700; color: #fff; background: var(--highlight); }

.calendar-workout {
  font-size: .68rem;
  line-height: 1.35;
  border-radius: 4px;
  padding: 3px 4px;
  margin-top: 3px;
}

.calendar-workout-line1 {
  display: flex;
  align-items: center;
  gap: 4px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.calendar-workout-line2 {
  padding-left: 10px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.calendar-workout-dot { margin-left: 0; }

@media (max-width: 700px) {
  .calendar-workout { font-size: .62rem; }
  .calendar-cell { min-height: 90px; }
}
