:root {
  --ink: #1e2938;
  --muted: #667085;
  --quiet: #98a2b3;
  --blue: #4da8f4;
  --blue-deep: #2f8df0;
  --mint: #82dabb;
  --mint-soft: #b9eadb;
  --coral: #ff796e;
  --yellow: #ffd45d;
  --panel: rgba(255, 255, 255, 0.9);
  --panel-soft: rgba(255, 255, 255, 0.68);
  --line: rgba(30, 41, 56, 0.08);
  --shadow: 0 28px 70px rgba(31, 41, 55, 0.16);
  --shadow-soft: 0 16px 38px rgba(31, 41, 55, 0.13);
  --swim: #4da8f4;
  --bike: #62b98f;
  --run: #ff796e;
  --brick: #8c7cf6;
  --rest: #98a2b3;
  --accent: #2f8df0;
  --warn: #b7791f;
  --good: #257a55;
  --bad: #b9443f;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html[data-theme="dark"] {
  --ink: #edf3fb;
  --muted: #aeb9c7;
  --quiet: #7f8ca0;
  --blue: #62b7ff;
  --blue-deep: #4b9df0;
  --mint: #70d6b5;
  --mint-soft: #9be3cf;
  --coral: #ff8a80;
  --yellow: #ffd96d;
  --panel: rgba(31, 42, 57, 0.92);
  --panel-soft: rgba(31, 42, 57, 0.66);
  --line: rgba(255, 255, 255, 0.12);
  --shadow: 0 28px 70px rgba(0, 0, 0, 0.42);
  --shadow-soft: 0 16px 38px rgba(0, 0, 0, 0.32);
  --good: #70d6b5;
  --bad: #ff8a80;
  --warn: #ffd96d;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100svh;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 22%, rgba(188, 236, 218, 0.55), transparent 18rem),
    radial-gradient(circle at 78% 82%, rgba(255, 128, 116, 0.22), transparent 18rem),
    linear-gradient(135deg, #fbfaf7 0%, #f6f4ef 48%, #fbfaf7 100%);
}

html[data-theme="dark"] body {
  background:
    radial-gradient(circle at 8% 22%, rgba(112, 214, 181, 0.2), transparent 18rem),
    radial-gradient(circle at 78% 82%, rgba(255, 138, 128, 0.18), transparent 18rem),
    linear-gradient(135deg, #121923 0%, #1c2531 48%, #141c27 100%);
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0.72rem 0.95rem;
  background: linear-gradient(135deg, var(--blue), var(--blue-deep));
  box-shadow: 0 12px 26px rgba(47, 141, 240, 0.18);
  color: white;
  cursor: pointer;
  font-weight: 800;
  transition: background 160ms ease, border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

button:hover,
button:focus-visible {
  box-shadow: 0 16px 34px rgba(47, 141, 240, 0.24);
  outline: none;
  transform: translateY(-1px);
}

button.ghost,
.icon-button {
  border-color: var(--line);
  background: var(--panel);
  box-shadow: var(--shadow-soft);
  color: var(--ink);
}

button.danger {
  color: var(--bad);
}

.icon-button {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  padding: 0;
  font-size: 1.2rem;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--ink);
  padding: 0.66rem 0.72rem;
}

html[data-theme="dark"] input,
html[data-theme="dark"] textarea,
html[data-theme="dark"] select {
  background: rgba(18, 25, 35, 0.72);
}

textarea {
  resize: vertical;
  line-height: 1.4;
}

ol {
  margin: 8px 0 14px;
  padding-left: 20px;
  color: var(--muted);
  line-height: 1.45;
}

.hidden {
  display: none !important;
}

.loading-scope {
  position: relative;
}

.loading-scope.is-loading > :not(.loading-overlay) {
  filter: blur(2px);
  pointer-events: none;
  user-select: none;
}

.loading-overlay {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: grid;
  place-items: center;
  gap: 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.54);
  color: var(--ink);
  font-size: 0.88rem;
  font-weight: 850;
  text-align: center;
  backdrop-filter: blur(2px);
}

html[data-theme="dark"] .loading-overlay {
  background: rgba(18, 25, 35, 0.52);
}

.loader {
  width: 34px;
  height: 34px;
  border: 3px solid rgba(77, 168, 244, 0.22);
  border-top-color: var(--blue-deep);
  border-radius: 50%;
  animation: spin 820ms linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.app-shell {
  display: grid;
  gap: 18px;
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: clamp(16px, 3vw, 34px);
}

.app-header {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 24px;
  align-items: end;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: clamp(16px, 3vw, 26px);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.brand-block {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.app-logo {
  width: 72px;
  height: 72px;
  border-radius: 18px;
  box-shadow: var(--shadow-soft);
}

.top-actions {
  display: flex;
  align-items: end;
  gap: 12px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  max-width: 860px;
  font-size: clamp(2rem, 5vw, 4.2rem);
  line-height: 0.98;
}

h2 {
  font-size: 1.12rem;
}

h3 {
  font-size: 0.98rem;
}

.eyebrow {
  margin-bottom: 6px;
  color: var(--blue-deep);
  font-size: 0.76rem;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
}

html[data-theme="dark"] .eyebrow {
  color: var(--mint);
}

.subtle,
.hint {
  margin-top: 10px;
  color: var(--muted);
  line-height: 1.45;
}

.hint.quiet {
  color: var(--quiet);
  font-size: 0.78rem;
}

.race-clock {
  display: grid;
  min-width: 132px;
  aspect-ratio: 1;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.race-clock span {
  display: block;
  font-size: 3rem;
  font-weight: 850;
}

.race-clock small {
  display: block;
  margin-top: -24px;
  color: var(--muted);
}

.toast-region {
  position: fixed;
  top: clamp(86px, 11vw, 120px);
  right: clamp(16px, 3vw, 34px);
  z-index: 60;
  display: grid;
  gap: 10px;
  width: min(360px, calc(100vw - 32px));
  pointer-events: none;
}

.toast {
  border: 1px solid var(--line);
  border-left: 5px solid var(--blue);
  border-radius: 8px;
  padding: 12px 14px;
  background: var(--panel);
  box-shadow: var(--shadow-soft);
  color: var(--ink);
  font-weight: 750;
  backdrop-filter: blur(18px);
}

.toast.success { border-left-color: var(--good); }
.toast.error { border-left-color: var(--bad); }
.toast.info { border-left-color: var(--blue); }

.onboarding {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(28, 33, 32, 0.42);
}

.onboarding-card,
.settings-panel,
.metric,
.detail-panel,
.coach-panel,
.calendar {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(18px);
}

.onboarding-card,
.settings-panel {
  width: min(980px, 100%);
  max-height: min(88vh, 900px);
  overflow: auto;
  padding: 22px;
  box-shadow: var(--shadow);
}

.stepper {
  display: flex;
  gap: 8px;
  margin-bottom: 18px;
}

.step-dot {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--muted);
  font-weight: 850;
}

.step-dot.active {
  border-color: transparent;
  background: var(--blue-deep);
  color: white;
}

.step-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.status-chip {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 10px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 850;
  white-space: nowrap;
}

.status-chip.success {
  border-color: rgba(37, 122, 85, 0.22);
  background: rgba(112, 214, 181, 0.16);
  color: var(--good);
}

.status-chip.error {
  border-color: rgba(185, 68, 63, 0.24);
  background: rgba(255, 121, 110, 0.14);
  color: var(--bad);
}

.status-chip.warning {
  border-color: rgba(183, 121, 31, 0.24);
  background: rgba(255, 212, 93, 0.16);
  color: var(--warn);
}

.setup-copy {
  margin: 10px 0 16px;
  color: var(--muted);
  line-height: 1.5;
}

.split-controls {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 14px;
}

.setup-box,
.settings-section,
.detail-card,
.session {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.setup-box,
.settings-section {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.strava-success {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  min-height: 148px;
  border: 1px solid rgba(37, 122, 85, 0.2);
  border-radius: 8px;
  padding: 18px;
  background: color-mix(in srgb, var(--mint) 18%, var(--panel));
  box-shadow: var(--shadow-soft);
}

.success-mark {
  display: grid;
  width: 74px;
  height: 74px;
  place-items: center;
  border-radius: 50%;
  background: var(--good);
  color: white;
  font-size: 2.3rem;
  font-weight: 900;
  box-shadow: 0 18px 36px rgba(37, 122, 85, 0.22);
}

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

label,
.wide-label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 750;
}

.inline-check {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 750;
}

.inline-check input {
  width: auto;
}

.wide-label {
  margin-top: 12px;
}

.onboarding-actions,
.settings-actions,
.coach-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.metric {
  min-height: 126px;
  padding: 16px;
}

.metric-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-weight: 750;
}

.metric strong {
  font-size: 2rem;
}

.metric small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  line-height: 1.35;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto auto;
  gap: 12px;
  align-items: end;
}

.control-group,
.api-row {
  display: grid;
  gap: 6px;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 18px;
  align-items: start;
}

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

.section-heading.compact {
  margin-bottom: 14px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 750;
}

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  margin-right: 5px;
}

.dot.swim { background: var(--swim); }
.dot.bike { background: var(--bike); }
.dot.run { background: var(--run); }
.dot.brick { background: var(--brick); }

.calendar {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  overflow: hidden;
}

.weekday,
.day {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.weekday {
  padding: 10px;
  background: rgba(77, 168, 244, 0.08);
  color: var(--muted);
  font-weight: 850;
  text-align: center;
}

.day {
  position: relative;
  min-height: 164px;
  padding: 10px;
  background: transparent;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.day:hover,
.day.selected {
  outline: 2px solid var(--blue);
  outline-offset: -2px;
}

.date-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-weight: 850;
}

.today-pill {
  border-radius: 999px;
  padding: 2px 7px;
  background: rgba(112, 214, 181, 0.22);
  color: var(--good);
  font-size: 0.72rem;
}

.session {
  display: grid;
  gap: 4px;
  margin-top: 8px;
  padding: 8px;
  border-left: 4px solid var(--rest);
}

.session.swim { border-left-color: var(--swim); }
.session.bike { border-left-color: var(--bike); }
.session.run { border-left-color: var(--run); }
.session.brick { border-left-color: var(--brick); }
.session.rest { border-left-color: var(--rest); }
.session.done { background: rgba(112, 214, 181, 0.14); }
.session.partial { background: rgba(255, 212, 93, 0.16); }

.session-title {
  font-weight: 850;
  line-height: 1.2;
}

.session-target {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.status {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 850;
}

.status.done { color: var(--good); }
.status.partial { color: var(--warn); }
.status.missed { color: var(--bad); }

.side-panel {
  position: sticky;
  top: 18px;
  display: grid;
  gap: 16px;
}

.detail-panel,
.coach-panel {
  padding: 16px;
}

.day-detail {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}

.detail-card {
  display: grid;
  gap: 8px;
  padding: 12px;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.detail-actions button {
  min-height: 36px;
  padding: 0.5rem 0.7rem;
}

.actual-list {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.45;
}

.coach-panel {
  display: grid;
  gap: 12px;
}

.coach-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin-top: 0;
}

.coach-output {
  min-height: 160px;
  max-height: 360px;
  overflow: auto;
  border-radius: 8px;
  padding: 12px;
  background: #172126;
  color: #e9f0eb;
  font-size: 0.88rem;
  line-height: 1.45;
  white-space: pre-wrap;
}

html[data-theme="dark"] .coach-output {
  background: #0b111b;
}

.settings-dialog {
  width: min(980px, calc(100vw - 28px));
  border: 0;
  padding: 0;
  background: transparent;
}

.settings-dialog::backdrop {
  background: rgba(28, 33, 32, 0.42);
}

.settings-panel {
  display: grid;
  width: 100%;
  gap: 14px;
}

@media (max-width: 1080px) {
  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .toolbar,
  .content-grid,
  .split-controls,
  .field-grid {
    grid-template-columns: 1fr;
  }

  .side-panel {
    position: static;
  }
}

@media (max-width: 720px) {
  .app-header {
    grid-template-columns: 1fr;
  }

  .brand-block {
    grid-template-columns: 54px minmax(0, 1fr);
  }

  .app-logo {
    width: 54px;
    height: 54px;
    border-radius: 14px;
  }

  .top-actions {
    align-items: center;
    justify-content: space-between;
  }

  .summary-grid,
  .toolbar {
    grid-template-columns: 1fr;
  }

  .calendar {
    display: block;
  }

  .weekday {
    display: none;
  }

  .day {
    min-height: auto;
  }
}
