:root {
  color-scheme: light;
  --bg: #f4f6f2;
  --surface: #ffffff;
  --ink: #17211d;
  --muted: #66716b;
  --line: #dce2dc;
  --green: #177251;
  --green-dark: #0f543d;
  --green-soft: #dcece4;
  --coral: #d96c4f;
  --yellow: #f0c44f;
  --focus: #0b65c2;
  --shadow: 0 8px 26px rgba(30, 43, 36, 0.08);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

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

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
}

button, select { font: inherit; }
button, select, a { -webkit-tap-highlight-color: transparent; }

:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--focus) 50%, transparent);
  outline-offset: 2px;
}

.topbar {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: var(--ink);
  font-weight: 750;
  font-size: 20px;
  text-decoration: none;
}

.brand-mark {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: end;
  gap: 3px;
  padding: 5px;
  background: var(--green);
  border-radius: 6px;
}

.brand-mark i { display: block; width: 4px; background: #fff; border-radius: 1px 1px 0 0; }
.brand-mark i:nth-child(1) { height: 8px; }
.brand-mark i:nth-child(2) { height: 16px; }
.brand-mark i:nth-child(3) { height: 12px; background: var(--yellow); }

.topbar-meta { display: flex; align-items: center; gap: 22px; }
.sync-status { color: var(--muted); font-size: 13px; }
.sync-status span { display: inline-block; width: 7px; height: 7px; margin-right: 7px; border-radius: 50%; background: var(--green); }

.icon-button {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--green-soft);
  color: var(--green-dark);
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  text-decoration: none;
}

.back-link { color: var(--green-dark); font-size: 14px; font-weight: 750; text-decoration: none; }
.back-link:hover { text-decoration: underline; }
.nav-link { color: var(--green-dark); font-size: 13px; font-weight: 750; text-decoration: none; white-space: nowrap; }
.nav-link:hover { text-decoration: underline; }

.page-shell { width: min(1180px, calc(100% - 48px)); margin: 0 auto; padding: 38px 0 72px; }

.control-row, .section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
}

.control-row { margin-bottom: 28px; }
.eyebrow { margin: 0 0 6px; color: var(--green); font-size: 12px; font-weight: 800; text-transform: uppercase; }
h1, h2 { margin: 0; letter-spacing: 0; line-height: 1.1; }
h1 { font-size: clamp(30px, 4vw, 44px); font-weight: 760; }
h2 { font-size: 23px; font-weight: 740; }

.sport-picker { display: grid; gap: 7px; min-width: 230px; color: var(--muted); font-size: 12px; font-weight: 750; }
.sport-picker select {
  width: 100%;
  min-height: 44px;
  padding: 0 42px 0 13px;
  border: 1px solid #bdc8c0;
  border-radius: 6px;
  background-color: var(--surface);
  color: var(--ink);
  font-weight: 700;
  cursor: pointer;
}

.metric-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  background: var(--ink);
  color: #fff;
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.metric-strip article { min-width: 0; padding: 22px 25px; position: relative; }
.metric-strip article + article::before { content: ""; position: absolute; left: 0; top: 22px; bottom: 22px; width: 1px; background: rgba(255,255,255,.16); }
.metric-strip span, .metric-strip small { display: block; color: #b9c4be; }
.metric-strip span { margin-bottom: 10px; font-size: 12px; font-weight: 700; text-transform: uppercase; }
.metric-strip strong { display: block; min-height: 40px; overflow-wrap: anywhere; font-size: clamp(25px, 3vw, 34px); line-height: 1.1; }
.metric-strip small { margin-top: 5px; font-size: 12px; }

.analytics-band, .recent-section { margin-top: 42px; }
.section-heading { margin-bottom: 20px; }

.segmented { display: inline-flex; padding: 3px; background: #e4e8e3; border-radius: 7px; }
.segmented button, .segmented a, .segmented .period-years-option { min-height: 34px; padding: 0 13px; border: 0; border-radius: 5px; background: transparent; color: var(--muted); font-size: 13px; font-weight: 700; cursor: pointer; }
.segmented a { display: grid; place-items: center; text-decoration: none; }
.segmented button.active, .segmented a.active, .segmented .period-years-option.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 4px rgba(23,33,29,.12); }
.period-years-option { display: inline-flex; align-items: center; gap: 4px; }
.period-years-option input { width: 38px; padding: 2px 1px 1px 3px; border: 0; border-bottom: 1px solid #aeb8b1; background: transparent; color: inherit; font: inherit; font-weight: 800; text-align: center; }

.chart-wrap {
  position: relative;
  min-height: 310px;
  padding: 20px 18px 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 3px 14px rgba(30, 43, 36, 0.04);
}

#trend-chart { display: block; width: 100%; height: 280px; overflow: visible; }
#trend-chart .grid-line { stroke: #e4e8e4; stroke-width: 1; }
#trend-chart .axis-label { fill: #78827c; font-size: 11px; }
#trend-chart .series-line { fill: none; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
#trend-chart .series-point { fill: #fff; stroke-width: 1.7; }
#trend-chart .series-hours { stroke: var(--green); }
#trend-chart .series-distance { stroke: #277bb5; }
#trend-chart .series-heart { stroke: var(--coral); }
#trend-chart .series-pace { stroke: #9a6a13; }

.chart-options { display: flex; flex-wrap: wrap; gap: 8px 18px; margin: -4px 0 14px; }
.chart-options label { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: 13px; cursor: pointer; }
.chart-options input { width: 16px; height: 16px; margin: 0; accent-color: var(--green); }
.chart-metric-option { display: inline-flex; align-items: center; gap: 6px; }
.chart-options .metric-color-input { width: 25px; height: 20px; padding: 1px; border: 1px solid var(--line); border-radius: 4px; background: var(--surface); cursor: pointer; }
.chart-options i, #chart-series-legend i { display: inline-block; width: 18px; height: 3px; }
.swatch-hours { background: var(--green); }
.swatch-distance { background: #277bb5; }
.swatch-heart { background: var(--coral); }
.swatch-pace { background: #9a6a13; }
.swatch-workouts { background: #7759a6; }
.swatch-max-heart { background: #b32f58; }
.swatch-speed { background: #00868a; }
.swatch-active-pace { background: #5c64c7; }
.swatch-energy { background: #c15f35; }

.chart-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  justify-content: space-between;
  gap: 18px 28px;
  margin: -4px 0 14px;
}
.chart-control { display: grid; gap: 7px; flex: 0 0 auto; }
.chart-control > span { color: var(--muted); font-size: 12px; font-weight: 750; }
.chart-toolbar .chart-options { justify-content: flex-end; margin: 0; }
.metric-chart-control { margin-left: auto; }
#right-axis-control { flex-basis: 100%; align-items: end; }
#right-axis-control[hidden] { display: none; }
#trend-chart .series-workouts { stroke: #7759a6; }
#trend-chart .series-max-heart { stroke: #b32f58; }
#trend-chart .series-speed { stroke: #00868a; }
#trend-chart .series-active-pace { stroke: #5c64c7; }
#trend-chart .series-energy { stroke: #c15f35; }
#trend-chart .axis-hours { fill: var(--green); }
#trend-chart .axis-distance_km { fill: #277bb5; }
#trend-chart .axis-workouts { fill: #6b7480; }
#trend-chart .axis-avg_heart_rate { fill: var(--coral); }
#trend-chart .axis-max_heart_rate { fill: #b94758; }
#trend-chart .axis-pace_100m_seconds { fill: #9a6a13; }
#trend-chart .axis-active_pace_100m_seconds { fill: #5c64c7; }
#trend-chart .axis-avg_speed_kmh { fill: #168a88; }
#trend-chart .axis-energy_kcal { fill: #a64b2a; }

.chart-tooltip {
  position: absolute;
  z-index: 3;
  min-width: 170px;
  max-width: 240px;
  padding: 9px 11px;
  transform: translateX(-50%);
  border: 1px solid #cfd7d1;
  border-radius: 5px;
  background: var(--ink);
  color: #fff;
  box-shadow: 0 7px 18px rgba(23, 33, 29, .2);
  pointer-events: none;
}
.chart-tooltip span, .chart-tooltip strong { display: block; }
.chart-tooltip span { color: #bdc8c1; font-size: 11px; }
.chart-tooltip strong { margin-top: 2px; font-size: 13px; }

.chart-legend { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; color: var(--muted); font-size: 13px; }
.chart-legend div { display: flex; flex-wrap: wrap; gap: 8px 18px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 7px; }
.chart-legend strong { color: var(--ink); font-size: 14px; }
.empty-state { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); }
.data-note { margin: 0; color: var(--muted); font-size: 13px; }
.table-notes { display: grid; gap: 3px; text-align: right; }

.composition-band { margin-top: 10px; }
.composition-controls { display: flex; align-items: end; justify-content: space-between; gap: 18px 28px; margin-bottom: 16px; }
.stack-chart-scroll { overflow-x: auto; padding-bottom: 4px; }
.stack-chart-wrap { min-width: 900px; min-height: 360px; padding-bottom: 4px; }
#composition-chart { display: block; height: 330px; }
#composition-chart .grid-line { stroke: #e4e8e4; stroke-width: 1; }
#composition-chart .axis-label { fill: #78827c; font-size: 11px; }
.stack-segment { stroke: rgba(255,255,255,.72); stroke-width: 1; }
.bar-swimming { fill: #277bb5; background: #277bb5; }
.bar-running { fill: var(--coral); background: var(--coral); }
.bar-walking { fill: var(--green); background: var(--green); }
.bar-cycling { fill: #9a6a13; background: #9a6a13; }
.sport-legend { display: flex; flex-wrap: wrap; gap: 10px 22px; margin-top: 10px; color: var(--muted); font-size: 13px; }
.sport-legend span { display: inline-flex; align-items: center; gap: 7px; }
.sport-legend i { width: 11px; height: 11px; border-radius: 2px; }

.table-scroll { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; min-width: 720px; }
th, td { padding: 15px 18px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); background: #fafbf9; font-size: 11px; font-weight: 800; text-transform: uppercase; }
td { font-size: 14px; font-variant-numeric: tabular-nums; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #f6faf7; }
.loading-cell { height: 96px; color: var(--muted); text-align: center !important; }
.detail-subtitle { margin: 8px 0 0; color: var(--muted); }
.detail-entry { margin: 8px 0 0; }
.back-link, .workout-detail-link { color: var(--green-dark); font-weight: 700; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.swim-detail-heading { margin-bottom: 28px; }
.swim-segment-table td:first-child { color: var(--green-dark); }
.analysis-note { margin: 14px 2px 0; color: var(--muted); font-size: 12px; }
.detail-actions { display: flex; align-items: center; gap: 20px; }
.comparison-picker { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) auto; align-items: end; gap: 14px; margin-top: 30px; padding: 20px 0; border-block: 1px solid var(--line); }
.comparison-picker label { min-width: 0; }
.comparison-picker label span { display: block; margin-bottom: 7px; color: var(--muted); font-size: 12px; font-weight: 700; }
.comparison-picker select { width: 100%; min-height: 42px; padding: 0 34px 0 11px; border: 1px solid #bfc8c1; border-radius: 5px; background: var(--surface); color: var(--ink); }
.comparison-workout { margin-top: 44px; }
.comparison-summary { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px 20px; color: var(--muted); font-size: 13px; }
.comparison-summary strong { color: var(--ink); }
.empty-comparison { padding: 32px 0; color: var(--muted); text-align: center; }
.comparison-chart-section { margin-top: 46px; }
.comparison-chart-legend { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px 18px; color: var(--muted); font-size: 13px; }
.comparison-chart-legend span { display: inline-flex; align-items: center; gap: 7px; }
.progress-legend { margin: -8px 0 12px; }
.compare-swatch { width: 18px; height: 4px; border-radius: 2px; }
.comparison-chart-wrap { position: relative; overflow-x: auto; min-height: 410px; padding: 14px 12px 4px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: 0 3px 14px rgba(30,43,36,.04); }
.progress-chart-wrap { min-height: 650px; }
#swim-efficiency-chart, #swim-progress-chart { display: block; width: 100%; min-width: 760px; overflow: visible; }
#swim-efficiency-chart { height: 410px; }
#swim-progress-chart { height: 650px; }
.comparison-chart-wrap .grid-line { stroke: #e4e8e4; stroke-width: 1; }
.comparison-chart-wrap .axis-label { fill: #78827c; font-size: 11px; }
.comparison-chart-wrap .axis-title { fill: #4f5b55; font-size: 12px; font-weight: 700; }
.comparison-chart-wrap .panel-title { fill: var(--ink); font-size: 12px; font-weight: 800; }
.compare-point { fill: #fff; stroke-width: 2; cursor: crosshair; }
.compare-trend { stroke-width: 2.2; stroke-dasharray: 7 5; opacity: .75; }
.compare-step { stroke-width: 5; stroke-linecap: butt; cursor: crosshair; }
.compare-connector { stroke-width: 1.5; opacity: .48; }
.compare-point:focus, .compare-step:focus { outline: none; stroke-width: 4; }
.compare-point.compare-series-0, .compare-trend.compare-series-0, .compare-step.compare-series-0, .compare-connector.compare-series-0 { stroke: #177251; }
.compare-point.compare-series-1, .compare-trend.compare-series-1, .compare-step.compare-series-1, .compare-connector.compare-series-1 { stroke: #277bb5; }
.compare-point.compare-series-2, .compare-trend.compare-series-2, .compare-step.compare-series-2, .compare-connector.compare-series-2 { stroke: #d96c4f; }
.compare-swatch.compare-series-0 { background: #177251; }
.compare-swatch.compare-series-1 { background: #277bb5; }
.compare-swatch.compare-series-2 { background: #d96c4f; }
.muted-value { color: #9aa39d; }
.workout-detail-link { color: var(--green-dark); font-weight: 750; text-underline-offset: 3px; }

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px 16px;
  background: var(--ink);
}

.auth-panel {
  width: min(100%, 430px);
  padding: 34px;
  background: var(--surface);
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .24);
}

.auth-copy { margin: 34px 0 24px; }
.auth-copy h1 { font-size: 34px; }
.auth-copy p:last-child { margin: 10px 0 0; color: var(--muted); }
.auth-form { display: grid; gap: 17px; }
.auth-form label, .inline-form label { display: grid; gap: 7px; color: var(--muted); font-size: 12px; font-weight: 750; }
.auth-form input, .inline-form input {
  min-width: 0;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid #bdc8c0;
  border-radius: 5px;
  background: #fff;
  color: var(--ink);
  font-size: 15px;
}

.primary-button, .secondary-button, .danger-button {
  min-height: 42px;
  padding: 0 17px;
  border-radius: 5px;
  font-weight: 760;
  cursor: pointer;
}
.primary-button { border: 1px solid var(--green); background: var(--green); color: #fff; }
.primary-button:hover { background: var(--green-dark); }
.secondary-button { border: 1px solid #bfc8c1; background: #fff; color: var(--ink); }
.danger-button { min-height: 34px; padding-inline: 11px; border: 1px solid #d5a295; background: #fff; color: #a13c26; font-size: 12px; }
.button-link { display: grid; place-items: center; text-decoration: none; }

.alert { margin: 0 0 18px; padding: 12px 14px; border: 1px solid; border-radius: 5px; font-size: 14px; }
.alert.error { border-color: #e2aa9c; background: #fff1ed; color: #8d311c; }
.alert.success { border-color: #a9cbb9; background: #edf8f1; color: #165c40; }

.account-heading { align-items: center; }
.settings-section { margin-top: 38px; padding-top: 32px; border-top: 1px solid var(--line); }
.settings-intro { margin-bottom: 18px; }
.settings-intro p { max-width: 680px; margin: 8px 0 0; color: var(--muted); }
.inline-form { display: grid; grid-template-columns: minmax(180px, 330px) auto; align-items: end; gap: 12px; margin-bottom: 22px; }
.compact-table th, .compact-table td { padding: 12px 14px; text-align: left; }
.compact-table form { margin: 0; }
.compact-table .diagnostic-detail { max-width: 520px; white-space: normal; line-height: 1.35; }
.token-reveal { display: grid; gap: 8px; margin: 22px 0; padding: 16px; border-left: 4px solid var(--coral); background: #fff3ef; }
.token-reveal span { color: #773321; font-weight: 750; }
.token-reveal code { overflow-wrap: anywhere; white-space: normal; font-size: 14px; }
.status { display: inline-block; min-width: 72px; padding: 4px 7px; border-radius: 4px; text-align: center; font-size: 11px; font-weight: 800; text-transform: uppercase; }
.status.ok { background: var(--green-soft); color: var(--green-dark); }
.status.failed { background: #f9e0da; color: #91351f; }

.filter-bar {
  display: flex;
  align-items: end;
  gap: 12px;
  margin: 24px 0 34px;
}
.filter-bar label { display: grid; flex: 1 1 420px; gap: 7px; color: var(--muted); font-size: 12px; font-weight: 750; }
.filter-bar input, .repair-form select {
  min-height: 40px;
  padding: 0 11px;
  border: 1px solid #bdc8c0;
  border-radius: 5px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}
.maintenance-heading { align-items: end; }
.maintenance-table table { min-width: 1180px; }
.maintenance-table td:last-child, .maintenance-table th:last-child { text-align: left; }
.workout-actions { display: flex; align-items: center; gap: 7px; }
.workout-actions form { margin: 0; }
.repair-form { display: flex; align-items: center; gap: 7px; }
.repair-form select { min-width: 155px; }
.compact-action { min-height: 40px; white-space: nowrap; }
.removed-row td { color: #7d8681; background: #f1f3f0; }
.removed-row td strong { color: #91351f; }
.pagination { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 18px; color: var(--muted); font-size: 13px; }
.pagination .secondary-button { min-width: 96px; }

@media (max-width: 820px) {
  .page-shell { width: min(100% - 30px, 680px); padding-top: 28px; }
  .metric-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric-strip article:nth-child(3)::before { display: none; }
  .metric-strip article:nth-child(n+3) { border-top: 1px solid rgba(255,255,255,.16); }
  .chart-toolbar { align-items: stretch; flex-direction: column; }
  .chart-toolbar .chart-options { justify-content: flex-start; }
  .metric-chart-control { margin-left: 0; }
  #right-axis-control { align-items: start; }
  .metric-color-input { display: none; }
  .composition-controls { align-items: stretch; flex-direction: column; }
  .comparison-picker { grid-template-columns: 1fr; }
  .comparison-summary { justify-content: flex-start; }
  .comparison-chart-legend { justify-content: flex-start; }
}

@media (max-width: 580px) {
  .topbar { min-height: 58px; padding: 0 16px; }
  .sync-status { display: none; }
  .topbar-meta { gap: 10px; }
  .nav-link { font-size: 12px; }
  .topbar .brand > span:last-child { display: none; }
  .control-row, .section-heading { align-items: stretch; flex-direction: column; gap: 16px; }
  .sport-picker { min-width: 0; width: 100%; }
  h1 { font-size: 32px; }
  h2 { font-size: 21px; }
  .metric-strip article { padding: 18px; }
  .metric-strip strong { font-size: 26px; }
  .segmented { width: 100%; }
  .segmented button { flex: 1; padding-inline: 8px; }
  .segmented .period-years-option { flex: 1; justify-content: center; padding-inline: 5px; }
  .chart-control .segmented { overflow-x: auto; }
  .chart-control .segmented button { min-width: max-content; }
  .chart-wrap { min-height: 270px; padding-inline: 8px; }
  #trend-chart { height: 245px; }
  .chart-legend { align-items: start; gap: 12px; }
  .recent-section { margin-top: 34px; }
  .auth-panel { padding: 26px 22px; }
  .inline-form { grid-template-columns: 1fr; }
  .filter-bar { align-items: stretch; flex-direction: column; }
  .filter-bar label { flex-basis: auto; }
  .account-heading { align-items: stretch; }
  .table-notes { text-align: left; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
