:root {
  --orange: #fc4c02;
  --orange-dark: #d63d00;
  --text: #161616;
  --muted: #71717a;
  --soft: #f6f6f7;
  --surface: #ffffff;
  --line: #e8e8ec;
  --green: #1f9d55;
  --red: #c8372d;
  --shadow: 0 10px 28px rgba(16, 16, 16, 0.07);
  --radius: 18px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  color: var(--text);
  background: #ffffff;
  letter-spacing: 0;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: #ffffff;
}

body {
  min-height: 100%;
  margin: 0;
  background: #ffffff;
  color: var(--text);
  font-size: 15px;
  line-height: 1.35;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
  letter-spacing: 0;
}

button {
  border: 0;
}

.app-root {
  min-height: 100vh;
}

.app-shell {
  width: min(100%, 520px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 14px calc(88px + env(safe-area-inset-bottom));
}

.loading-shell {
  display: grid;
  align-items: center;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin: 2px 2px 14px;
}

.title-wrap {
  min-width: 0;
}

.app-title {
  margin: 0;
  font-size: 25px;
  line-height: 1.08;
  font-weight: 800;
}

.period {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.status-dot {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.status-dot::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
}

.status-dot.connected {
  color: var(--green);
  background: #edf8f1;
}

.status-dot.connected::before {
  background: var(--green);
}

.view {
  display: grid;
  gap: 12px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}

.card.flat {
  box-shadow: none;
  background: #fafafa;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.card-title {
  margin: 0;
  font-size: 16px;
  font-weight: 800;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--orange);
  font-size: 12px;
  font-weight: 800;
}

.muted {
  color: var(--muted);
}

.compact-copy {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.progress-card {
  display: grid;
  grid-template-columns: 92px 1fr;
  align-items: center;
  gap: 14px;
  padding: 14px;
}

.progress-ring {
  --progress: 0deg;
  width: 88px;
  height: 88px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: conic-gradient(var(--orange) var(--progress), #ededf1 0);
  position: relative;
  flex: 0 0 auto;
}

.progress-ring::after {
  content: "";
  position: absolute;
  inset: 9px;
  border-radius: 50%;
  background: #ffffff;
}

.progress-ring span {
  position: relative;
  z-index: 1;
  font-size: 18px;
  font-weight: 850;
}

.progress-copy {
  min-width: 0;
}

.progress-copy h2 {
  margin: 0;
  font-size: 28px;
  line-height: 1;
  font-weight: 850;
}

.progress-copy p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.goal-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 5px 9px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--text);
  font-size: 12px;
  font-weight: 750;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.stats-grid.dense .stat-card {
  min-height: 70px;
}

.stat-card {
  min-height: 76px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #ffffff;
}

.stat-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.stat-card strong {
  display: block;
  margin-top: 7px;
  font-size: 18px;
  line-height: 1.1;
  font-weight: 850;
}

.run-list {
  display: grid;
  gap: 8px;
}

.run-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  min-height: 58px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #ffffff;
}

.run-main {
  min-width: 0;
}

.run-title {
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  font-weight: 800;
}

.run-meta {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.run-distance {
  text-align: right;
  white-space: nowrap;
}

.run-distance strong {
  display: block;
  font-size: 16px;
  font-weight: 850;
}

.source {
  display: inline-flex;
  align-items: center;
  margin-top: 4px;
  padding: 3px 7px;
  border-radius: 999px;
  background: #f0f0f2;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.source.strava {
  background: #fff0e8;
  color: var(--orange-dark);
}

.empty {
  padding: 14px;
  border: 1px dashed #d8d8de;
  border-radius: 16px;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
}

.form-grid {
  display: grid;
  gap: 10px;
}

.field-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.field {
  display: grid;
  gap: 6px;
}

.field label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.field input {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #ffffff;
  color: var(--text);
  outline: none;
}

.field input:focus {
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(252, 76, 2, 0.12);
}

.button-row {
  display: flex;
  gap: 9px;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 42px;
  padding: 0 14px;
  border-radius: 14px;
  background: var(--soft);
  color: var(--text);
  font-size: 14px;
  font-weight: 850;
  cursor: pointer;
}

.btn svg {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
}

.btn.primary {
  background: var(--orange);
  color: #ffffff;
}

.btn.primary:active {
  background: var(--orange-dark);
}

.btn.ghost {
  background: #f2f2f4;
  color: var(--text);
}

.btn.danger {
  background: #fff0ef;
  color: var(--red);
}

.btn.small {
  min-height: 32px;
  padding: 0 10px;
  border-radius: 11px;
  font-size: 12px;
}

.btn.full {
  width: 100%;
}

.strava-panel {
  display: grid;
  gap: 10px;
}

.strava-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.stat-hero {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
}

.stat-hero h2 {
  margin: 0;
  font-size: 30px;
  line-height: 1;
  font-weight: 850;
}

.stat-hero p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.mini-score {
  width: 76px;
  height: 76px;
  display: grid;
  place-items: center;
  align-content: center;
  border-radius: 50%;
  background: #fff0e8;
  color: var(--orange-dark);
}

.mini-score strong,
.mini-score span {
  display: block;
}

.mini-score strong {
  font-size: 19px;
  line-height: 1;
  font-weight: 850;
}

.mini-score span {
  margin-top: 5px;
  font-size: 10px;
  font-weight: 800;
}

.chart-card {
  overflow: hidden;
}

.chart-topline {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.chart-topline strong {
  font-size: 20px;
  font-weight: 850;
}

.chart-topline span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.line-chart {
  width: 100%;
  height: auto;
  display: block;
}

.line-chart line {
  stroke: #ededf1;
  stroke-width: 1.5;
}

.line-chart path {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.line-chart path.actual {
  stroke: var(--orange);
  stroke-width: 4;
}

.line-chart path.target {
  stroke: #a1a1aa;
  stroke-width: 2;
  stroke-dasharray: 5 6;
}

.line-chart circle {
  fill: #ffffff;
  stroke: var(--orange);
  stroke-width: 2;
}

.bar-list {
  display: grid;
  gap: 10px;
}

.bar-row {
  display: grid;
  grid-template-columns: 52px 1fr 58px;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  font-size: 12px;
}

.bar-row span {
  color: var(--muted);
  font-weight: 800;
}

.bar-row strong {
  text-align: right;
  font-size: 12px;
  font-weight: 850;
}

.bar-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #f0f0f2;
}

.bar-track i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--orange);
}

.weekday-bars {
  height: 142px;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  align-items: end;
  gap: 7px;
  padding-top: 8px;
}

.weekday-bar {
  height: 100%;
  display: grid;
  grid-template-rows: 1fr auto auto;
  gap: 5px;
  text-align: center;
}

.weekday-bar div {
  width: 100%;
  align-self: end;
  border-radius: 999px 999px 6px 6px;
  background: var(--orange);
}

.weekday-bar span,
.weekday-bar strong {
  font-size: 11px;
}

.weekday-bar span {
  color: var(--muted);
  font-weight: 800;
}

.weekday-bar strong {
  font-weight: 850;
}

.source-meter {
  height: 14px;
  overflow: hidden;
  border-radius: 999px;
  background: #eeeeef;
}

.source-meter span {
  display: block;
  width: var(--strava);
  height: 100%;
  border-radius: inherit;
  background: var(--orange);
}

.legend-row {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.legend-row span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

.legend.manual {
  background: #a1a1aa;
}

.legend.strava {
  background: var(--orange);
}

.record-list {
  display: grid;
  gap: 8px;
}

.record-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 36px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

.record-row:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.record-row span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.record-row strong {
  text-align: right;
  font-size: 13px;
  font-weight: 850;
}

.toast {
  position: sticky;
  top: max(8px, env(safe-area-inset-top));
  z-index: 4;
  margin-bottom: 10px;
  padding: 10px 12px;
  border-radius: 14px;
  background: #161616;
  color: #ffffff;
  font-size: 13px;
  font-weight: 700;
}

.toast.error {
  background: var(--red);
}

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 8;
  width: min(100%, 520px);
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.94);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(16px);
}

.nav-btn {
  display: grid;
  place-items: center;
  gap: 3px;
  min-height: 50px;
  border-radius: 15px;
  background: transparent;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  cursor: pointer;
}

.nav-btn svg {
  width: 20px;
  height: 20px;
}

.nav-btn.active {
  background: #fff0e8;
  color: var(--orange);
}

.hidden {
  display: none !important;
}

@media (min-width: 560px) {
  body {
    background: #f7f7f8;
  }

  .app-shell {
    background: #ffffff;
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
  }
}

@media (max-width: 360px) {
  .progress-card {
    grid-template-columns: 78px 1fr;
  }

  .progress-ring {
    width: 76px;
    height: 76px;
  }

  .progress-ring span {
    font-size: 16px;
  }

  .progress-copy h2 {
    font-size: 24px;
  }

  .field-row {
    grid-template-columns: 1fr;
  }

  .stat-hero {
    grid-template-columns: 1fr;
  }

  .mini-score {
    width: 64px;
    height: 64px;
  }

  .bar-row {
    grid-template-columns: 46px 1fr 50px;
  }

  .nav-btn {
    font-size: 9px;
  }
}
