:root {
  --ink: #18212f;
  --muted: #667085;
  --line: #d9dee8;
  --panel: #ffffff;
  --panel-soft: #f6f8fb;
  --brand: #254066;
  --brand-dark: #1b2f4d;
  --accent: #2d6cdf;
  --accent-soft: #eaf1ff;
  --warning: #946200;
  --danger: #a62b2b;
  --success: #18704f;
  --shadow: 0 18px 55px rgba(24, 33, 47, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: #f3f5f8;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background: var(--brand);
  color: white;
  padding: 0 16px;
  font-weight: 700;
  cursor: pointer;
}

button:hover {
  background: var(--brand-dark);
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(45, 108, 223, 0.18);
  outline-offset: 2px;
}

button.secondary {
  background: #eef2f7;
  color: var(--ink);
}

button.secondary:hover {
  background: #e2e8f0;
}

.app-shell {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 28px 22px;
  background: #ffffff;
  border-right: 1px solid var(--line);
  color: var(--ink);
}

.brand {
  display: grid;
  gap: 8px;
}

.brand h1 {
  margin: 0;
  font-size: 1.2rem;
  line-height: 1.2;
  letter-spacing: 0;
}

.brand p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.35;
}

.step-nav {
  display: grid;
  gap: 8px;
}

.step-nav button {
  justify-content: flex-start;
  width: 100%;
  background: transparent;
  color: var(--muted);
  text-align: left;
}

.step-nav button.is-active,
.step-nav button:hover {
  background: var(--accent-soft);
  color: var(--brand);
}

.sidebar-reset {
  margin-top: auto;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
}

.sidebar-reset:hover {
  background: #fff4f4;
  color: var(--danger);
}

.status {
  margin-top: 0;
  border-radius: 8px;
  padding: 14px;
  background: var(--panel-soft);
  line-height: 1.4;
}

.status[data-type="error"] {
  background: #ffe8e8;
  color: var(--danger);
}

.status[data-type="warning"] {
  background: #fff7df;
  color: var(--warning);
}

.status[data-type="success"] {
  background: #e9f7f0;
  color: var(--success);
}

.workspace {
  padding: 32px;
}

.intake-card,
.output {
  width: min(1180px, 100%);
  margin: 0 auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.step {
  padding: 30px;
}

.step-heading,
.output-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}

.eyebrow {
  display: block;
  color: var(--brand);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0;
}

h2,
h3 {
  margin: 4px 0 0;
  letter-spacing: 0;
}

.field-grid {
  display: grid;
  gap: 18px;
}

.field-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.field-grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

label,
fieldset {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.field-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.field-tag {
  display: inline-flex;
  align-items: center;
  width: max-content;
  min-height: 22px;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.68rem;
  font-weight: 900;
  line-height: 1;
  text-transform: uppercase;
}

.field-tag.required {
  background: #eaf1ff;
  color: #2356a8;
  border: 1px solid #bfd3ff;
}

.field-tag.optional {
  background: #f2f4f7;
  color: #667085;
  border: 1px solid #d9dee8;
}

.hint {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 650;
  line-height: 1.35;
}

.option-guide {
  display: grid;
  gap: 8px;
  margin-top: 2px;
  padding: 12px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #f8fafc;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 650;
  line-height: 1.35;
}

.option-guide span {
  display: block;
}

.option-guide strong {
  color: var(--ink);
  font-weight: 900;
}

.has-error {
  color: var(--danger);
}

.wide {
  grid-column: 1 / -1;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  padding: 12px;
  font-weight: 600;
}

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

input:focus,
select:focus,
textarea:focus {
  outline: 3px solid rgba(45, 108, 223, 0.14);
  border-color: var(--accent);
}

.is-invalid {
  border-color: var(--danger);
  background: #fff8f8;
}

fieldset {
  margin: 20px 0 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

legend {
  padding: 0 8px;
  color: var(--ink);
  font-weight: 800;
}

.day-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(70px, 1fr));
  gap: 8px;
}

.day-grid label {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--panel-soft);
}

.day-grid input {
  width: auto;
  accent-color: var(--accent);
}

.time-field {
  margin: 0;
}

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

.time-grid.compact {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.time-grid label {
  gap: 6px;
  font-size: 0.78rem;
}

.actions,
.output-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.actions {
  margin-top: 28px;
}

.return-top {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 20;
  border: 1px solid var(--line);
  box-shadow: 0 14px 40px rgba(24, 33, 47, 0.16);
  white-space: nowrap;
}

.review-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 18px;
}

.review-panel p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.review-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.review-summary div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 12px;
}

.review-summary span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.review-summary strong {
  display: block;
  margin-top: 6px;
  line-height: 1.35;
}

.output {
  margin-top: 28px;
  padding: 28px;
  padding-bottom: 86px;
}

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

.metric {
  min-height: 82px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 14px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.metric strong {
  display: block;
  margin-top: 8px;
  color: var(--ink);
  font-size: 1.05rem;
}

.plan-table {
  display: grid;
  gap: 16px;
}

.chart-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 18px;
  margin-bottom: 24px;
}

.chart-heading {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 12px;
}

.chart-heading h3 {
  margin: 0;
}

.chart-heading p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 650;
}

.chart-shell {
  width: 100%;
  min-height: 300px;
}

.chart-shell svg {
  display: block;
  width: 100%;
  height: 300px;
  overflow: visible;
}

.chart-phase-band {
  opacity: 0.45;
}

.chart-phase-band.base-build {
  fill: #eef6ff;
}

.chart-phase-band.marathon-build {
  fill: #f4f7fb;
}

.chart-phase-band.race-specific {
  fill: #fff7e8;
}

.chart-phase-band.taper {
  fill: #f2eefc;
}

.chart-axis {
  stroke: #9aa6b2;
  stroke-width: 1.1;
}

.chart-grid {
  stroke: #d6dce5;
  stroke-dasharray: 4 6;
  stroke-width: 1;
}

.chart-bar {
  fill: var(--brand);
  opacity: 0.22;
  rx: 5;
}

.chart-line {
  fill: none;
  stroke: var(--accent);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 4;
}

.chart-dot {
  fill: var(--accent);
  stroke: white;
  stroke-width: 3;
}

.chart-hit-area {
  fill: white;
  opacity: 0;
  pointer-events: all;
  cursor: crosshair;
}

.chart-hover {
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
}

.chart-crosshair {
  stroke: rgba(37, 64, 102, 0.45);
  stroke-dasharray: 4 5;
  stroke-width: 1.1;
}

.chart-crosshair-horizontal {
  opacity: 0.42;
}

.chart-hover-dot {
  fill: var(--brand);
  stroke: white;
  stroke-width: 3;
}

.chart-tooltip-bg {
  fill: #ffffff;
  stroke: #d3dae6;
  stroke-width: 1.1;
  filter: drop-shadow(0 12px 24px rgba(24, 33, 47, 0.16));
}

.chart-tooltip text {
  font-size: 0.68rem;
  font-weight: 800;
  dominant-baseline: middle;
}

.chart-tooltip-title {
  fill: var(--ink);
  font-size: 0.82rem;
  font-weight: 900;
}

.chart-tooltip-date,
.chart-tooltip-label {
  fill: var(--muted);
}

.chart-tooltip-divider {
  stroke: #e3e8f0;
  stroke-width: 1;
}

.chart-tooltip-phase {
  fill: #946200;
}

.chart-tooltip-total {
  fill: var(--brand);
  font-weight: 900;
}

.chart-tooltip-long-run {
  fill: var(--accent);
  font-weight: 900;
}

.tooltip-marker.total {
  fill: rgba(37, 64, 102, 0.42);
}

.tooltip-marker.long-run {
  fill: var(--accent);
}

.chart-label {
  fill: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px 16px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 850;
}

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

.legend-bar,
.legend-line {
  display: inline-block;
  flex: 0 0 auto;
}

.legend-bar {
  width: 18px;
  height: 10px;
  border-radius: 3px;
  background: rgba(37, 64, 102, 0.22);
}

.legend-line {
  width: 22px;
  height: 4px;
  border-radius: 999px;
  background: var(--accent);
}

.transfer-box {
  width: 100%;
  min-height: 150px;
  margin: 0 0 24px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: #f8fbff;
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem;
}

.week-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: white;
}

.week-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 16px;
  background: var(--brand);
  color: white;
}

.week-header .eyebrow {
  color: #d8e6ff;
}

.week-header strong {
  font-size: 1.25rem;
  white-space: nowrap;
}

.week-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(130px, 1fr));
  overflow-x: auto;
}

.session {
  min-height: 180px;
  border-right: 1px solid var(--line);
  padding: 12px;
}

.session:last-child {
  border-right: 0;
}

.session-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 900;
}

.session b {
  display: block;
  margin-top: 10px;
  color: var(--brand);
}

.session p {
  margin: 8px 0 0;
  color: var(--ink);
  font-size: 0.88rem;
  line-height: 1.4;
}

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

  .sidebar {
    position: static;
    height: auto;
  }

  .step-nav,
  .summary-grid,
  .review-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .field-grid.two,
  .field-grid.three {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .workspace,
  .step,
  .output {
    padding: 18px;
  }

  .step-nav,
  .summary-grid,
  .day-grid,
  .time-grid,
  .time-grid.compact {
    grid-template-columns: 1fr;
  }

  .step-heading,
  .output-header {
    display: grid;
  }

  .actions,
  .output-actions {
    justify-content: stretch;
  }

  .actions button,
  .output-actions button {
    width: 100%;
  }

  .output-actions .return-top {
    right: 14px;
    bottom: calc(14px + env(safe-area-inset-bottom, 0px));
    width: auto;
    min-height: 40px;
  }

  .output {
    padding-bottom: 78px;
  }
}
