:root {
  --bg: #f3f6f3;
  --surface: #fff;
  --surface-soft: #f8faf8;
  --ink: #17201a;
  --muted: #69736c;
  --line: #dfe5df;
  --green: #176b43;
  --green-dark: #0f4d31;
  --pale: #e7f3ec;
  --amber: #9a6100;
  --danger: #a43232;
  --blue: #3182ce;
  --heart: #e11d48;
  --shadow: 0 14px 40px rgb(20 37 27 / 7%);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
a { color: var(--green); text-decoration: none; }
header {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 8px max(20px, calc((100vw - 1240px) / 2));
  background: #14251b;
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 5;
  box-shadow: 0 5px 20px rgb(0 0 0 / 12%);
}
.brand { display: grid; flex: 0 0 28px; place-items: center; width: 28px; height: 28px; }
.brand img { width: 24px; height: 24px; }
nav { display: flex; gap: 17px; flex: 1; }
nav a, .link { color: #d9e9df; }
.link { background: none; border: 0; padding: 0; }
main { max-width: 1240px; margin: 0 auto; padding: 34px 20px 80px; }
.heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  margin-bottom: 25px;
}
.eyebrow {
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .09em;
  margin: 0 0 4px;
  text-transform: uppercase;
}
h1 { font-size: clamp(28px, 4vw, 38px); letter-spacing: -.03em; margin: 0 0 5px; }
h2 { font-size: 19px; margin: 0 0 15px; }
p { margin: 5px 0 15px; }
.count {
  display: inline-grid;
  place-items: center;
  min-width: 38px;
  height: 29px;
  padding: 0 9px;
  border-radius: 999px;
  background: var(--pale);
  color: var(--green);
  font-size: 16px;
  vertical-align: middle;
}
section, .metrics article, .cards article, .metadata {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px;
  box-shadow: var(--shadow);
}
.metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin: 24px 0;
}
.health-metrics { grid-template-columns: repeat(5, 1fr); }
.metrics strong { display: block; font-size: 25px; letter-spacing: -.02em; margin: 6px 0; }
.metrics span, .metrics small, small { display: block; color: var(--muted); }
.sync-summary {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px 10px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.sync-summary span { display: block; }
.sync-summary small { margin-top: 2px; }
.icon-button {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 9px;
  border-radius: 11px;
}
.icon-button svg {
  width: 23px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}
.icon-button.is-syncing svg { animation: sync-spin .8s linear infinite; }
.icon-button:disabled { cursor: wait; opacity: .82; }
@keyframes sync-spin {
  to { transform: rotate(360deg); }
}
.dashboard-grid {
  display: grid;
  grid-template-columns: 1.45fr .85fr;
  gap: 18px;
  margin: 18px 0;
}
.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 15px;
  margin-bottom: 14px;
}
.section-heading h2, .section-heading p { margin-bottom: 0; }
.recommendation-card {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(135deg, #153b28, #176b43);
}
.recommendation-card .eyebrow, .recommendation-card p { color: #d8efe1; }
.recommendation-card .badge { background: rgb(255 255 255 / 14%); color: #fff; }
.workout-steps {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 17px;
}
.workout-steps > div {
  min-height: 105px;
  padding: 13px;
  border: 1px solid rgb(255 255 255 / 18%);
  border-radius: 11px;
  background: rgb(255 255 255 / 9%);
}
.workout-steps strong, .workout-steps span, .workout-steps small { display: block; }
.workout-steps span { margin: 5px 0; font-size: 19px; font-weight: 800; }
.workout-steps small { color: #d8efe1; }
.alternative {
  display: grid;
  gap: 3px;
  margin-top: 13px;
  padding: 12px 14px;
  border-left: 3px solid #73e3a5;
  background: rgb(0 0 0 / 13%);
}
.alternative span { color: #d8efe1; }
.columns {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 18px;
}
.dashboard-columns { margin-top: 18px; }
.row, .event {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.row:last-child, .event:last-child { border: 0; }
.badge {
  display: inline-block;
  border-radius: 999px;
  background: #edf0ed;
  padding: 4px 9px;
  font-size: 12px;
}
.badge.ok { background: var(--pale); color: var(--green); }
.badge.warn { background: #fff2d8; color: var(--amber); }
.empty, .chart-note { color: var(--muted); }
.chart-note { font-size: 13px; }
.filters, .actions {
  display: flex;
  gap: 12px;
  align-items: end;
  margin-bottom: 20px;
}
.filters {
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}
label { display: grid; gap: 5px; color: var(--muted); }
input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #bac4bc;
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}
textarea { min-height: 120px; resize: vertical; }
button {
  border: 0;
  border-radius: 7px;
  padding: 10px 15px;
  background: var(--green);
  color: #fff;
  cursor: pointer;
  font-weight: 650;
}
button:hover { background: var(--green-dark); }
.danger { background: var(--danger); }
.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}
table { width: 100%; border-collapse: collapse; }
th, td { padding: 13px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; }
td small { white-space: normal; }
dl { display: grid; grid-template-columns: minmax(180px, 1fr) 3fr; margin: 0; }
dt, dd { margin: 0; padding: 8px; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
dt { color: var(--muted); }
.alert { padding: 12px; border: 1px solid #e6c77b; border-radius: 8px; background: #fff3d9; }
.login-card { max-width: 420px; margin: 10vh auto; }
.login-card form { display: grid; gap: 15px; }
.cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 15px; }
.event { gap: 12px; }
.event > span:nth-child(2) { flex: 1; }
.chart {
  position: relative;
  width: 100%;
  min-height: 350px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: linear-gradient(#fff, #f8faf8);
}
.chart.compact { min-height: 205px; border: 0; }
.chart svg { display: block; width: 100%; height: auto; }
.chart text { fill: var(--muted); font: 11px system-ui, sans-serif; }
.chart .grid-line { stroke: #e5eae6; stroke-width: 1; }
.chart .axis-line { stroke: #aeb8b0; stroke-width: 1; }
.chart .power-line { fill: none; stroke: #173b73; stroke-width: 1.4; }
.chart .heart-line { fill: none; stroke: var(--heart); stroke-width: 2.2; }
.chart .fitness-line { fill: none; stroke: #2563eb; stroke-width: 2.5; }
.chart .fatigue-line { fill: none; stroke: #e11d48; stroke-width: 2.5; }
.chart .form-line { fill: none; stroke: #16a34a; stroke-width: 2.5; }
.chart .fitness-area { fill: rgb(37 99 235 / 10%); }
.fitness-chart svg { cursor: crosshair; touch-action: pan-y; }
.chart .probe-guide {
  stroke: #7a857d;
  stroke-dasharray: 4 4;
  stroke-width: 1;
}
.chart .probe-dot {
  stroke: #fff;
  stroke-width: 2;
}
.chart .probe-tooltip-box {
  fill: rgb(20 37 27 / 94%);
  stroke: rgb(255 255 255 / 28%);
  stroke-width: 1;
}
.chart .probe-tooltip text { fill: #fff; }
.chart .probe-date { font-size: 10px; opacity: .75; }
.chart .probe-values { font-size: 11px; font-weight: 750; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 13px; color: var(--muted); font-size: 12px; }
.chart-legend span::before {
  content: "";
  display: inline-block;
  width: 18px;
  height: 3px;
  margin: 0 6px 3px 0;
  border-radius: 2px;
  background: currentColor;
}
.legend-power { color: #173b73; }
.legend-heart, .legend-fatigue { color: #e11d48; }
.legend-fitness { color: #2563eb; }
.legend-form { color: #16a34a; }
.segment-table { margin-top: 18px; }
.zone-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 7px;
  border-radius: 3px;
  background: var(--zone-color);
}
.metadata { margin-top: 20px; }
.metadata summary, .memory-editor summary {
  color: var(--green);
  cursor: pointer;
  font-weight: 750;
}
.memory-editor summary,
.memory-editor summary * { cursor: pointer; }
.memory-cards article {
  display: flex;
  min-width: 0;
  flex-direction: column;
}
.memory-cards h2 { margin: 12px 0 7px; }
.memory-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 7px;
}
.memory-tags span {
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--pale);
  color: var(--green);
  font-size: 11px;
  font-weight: 700;
}
.memory-tags .memory-type,
.memory-tags .memory-status {
  background: #edf0ed;
  color: var(--ink);
  font-weight: 500;
}
.memory-tags .memory-status.warn {
  background: #fff2d8;
  color: var(--amber);
}
.metadata dl { margin-top: 15px; }
.memory-editor {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.memory-editor form { display: grid !important; gap: 12px !important; }
.memory-save-button {
  justify-self: start;
  width: auto;
  padding: 8px 12px;
  font-size: 13px;
}
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.invalidate-form {
  display: flex;
  gap: 8px;
  margin-top: auto;
  padding-top: 18px;
}
.invalidate-form input { flex: 1; }
.sync-last { margin-bottom: 18px; border-left: 4px solid var(--green); }
.sync-date { font-size: 18px; }
.fitness-metrics { grid-template-columns: repeat(4, 1fr); }

@media (max-width: 950px) {
  .health-metrics { grid-template-columns: repeat(3, 1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
}
@media (max-width: 800px) {
  header {
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
  }
  .brand {
    flex-basis: 32px;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: rgb(255 255 255 / 8%);
  }
  .brand img { width: 22px; height: 22px; }
  .logout-form { display: none; }
  nav {
    min-width: 0;
    gap: 5px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    scroll-snap-type: x proximity;
  }
  nav::-webkit-scrollbar { display: none; }
  nav a {
    flex: 0 0 auto;
    padding: 8px 10px;
    border-radius: 9px;
    font-size: 13px;
    white-space: nowrap;
    scroll-snap-align: start;
  }
  nav a:hover, nav a:focus-visible { background: rgb(255 255 255 / 10%); }
  .metrics, .health-metrics, .fitness-metrics { grid-template-columns: repeat(2, 1fr); }
  .columns, .cards { grid-template-columns: 1fr; }
  .actions, .filters { align-items: stretch; flex-direction: column; }
  .filters label, .filters button { width: 100%; }
  .workout-steps { grid-template-columns: 1fr; }
  .workout-steps > div {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    min-height: 0;
  }
  .workout-steps small { grid-column: 1 / -1; }
  .sync-summary { width: 100%; justify-content: space-between; }
  .dashboard-heading { flex-direction: column; }
  .chart { min-height: 280px; }
}
@media (max-width: 520px) {
  body { font-size: 14px; }
  header { padding-inline: 8px; }
  nav a { padding-inline: 9px; }
  main { padding: 20px 12px 54px; }
  h1 { font-size: 29px; }
  h2 { font-size: 18px; }
  section, .metrics article, .cards article, .metadata { padding: 15px; border-radius: 12px; }
  .heading { margin-bottom: 18px; }
  .metrics, .health-metrics, .fitness-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
  }
  .metrics { margin: 16px 0; }
  .metrics article { min-width: 0; }
  .metrics strong { font-size: 21px; }
  .health-metrics article:last-child { grid-column: 1 / -1; }
  .form-grid { grid-template-columns: 1fr; }
  .heading { display: block; }
  .dashboard-heading .sync-summary { margin-top: 14px; }
  .sync-summary { padding-left: 13px; }
  .sync-summary strong { font-size: 13px; }
  .sync-summary small { font-size: 11px; }
  .dashboard-grid, .dashboard-columns { gap: 12px; margin: 12px 0; }
  .section-heading { flex-wrap: wrap; gap: 7px; }
  .section-heading h2 { margin-bottom: 0; }
  .row, .event { gap: 8px; padding: 12px 0; }
  .row > span:first-child, .event > span { min-width: 0; }
  .row strong { overflow-wrap: anywhere; }
  .workout-steps { gap: 7px; margin-top: 12px; }
  .workout-steps > div { padding: 10px 12px; }
  .workout-steps span { margin: 0; font-size: 17px; }
  .alternative { padding: 10px 12px; }
  .chart, .chart.compact { min-height: 220px; }
  .chart-legend { gap: 8px; }
  th, td { padding: 10px; }
  .filters, .actions { gap: 9px; }
  .invalidate-form {
    align-items: stretch;
    flex-direction: column;
    padding-top: 14px;
  }
  .invalidate-form button { align-self: flex-end; width: auto; }
  dl { grid-template-columns: 1fr; }
  dt { border-bottom: 0; padding-bottom: 0; }
}
