:root {
  color-scheme: light;
  --bg: #f6f7f5;
  --panel: #ffffff;
  --ink: #17201b;
  --muted: #69736d;
  --line: #d9dfd8;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --accent-soft: #d9f0ec;
  --danger: #b42318;
  --amber: #b7791f;
  --steel: #2f3b52;
  --shadow: 0 18px 55px rgba(33, 43, 38, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1220px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0 36px;
}

.topbar,
.workspace,
.ride-view {
  width: 100%;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent-dark);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(2rem, 4vw, 4rem);
  line-height: 0.98;
}

h2 {
  font-size: 1rem;
}

.device-strip {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.topbar-actions {
  display: grid;
  gap: 10px;
  justify-items: end;
}

.account-strip {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
  text-align: right;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.device-button,
.primary-button,
.secondary-button,
.danger-button,
.icon-button {
  border: 1px solid transparent;
  border-radius: 8px;
  min-height: 44px;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.device-button:active,
.primary-button:active,
.secondary-button:active,
.danger-button:active,
.icon-button:active {
  transform: translateY(1px);
}

.device-button {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 170px;
  padding: 9px 12px;
  background: var(--panel);
  border-color: var(--line);
  box-shadow: 0 8px 22px rgba(28, 35, 31, 0.06);
  color: var(--ink);
  text-align: left;
}

.device-button strong,
.device-button small {
  display: block;
}

.device-button small {
  color: var(--muted);
  margin-top: 2px;
}

.device-button.connected .device-dot {
  background: #16a34a;
  box-shadow: 0 0 0 5px rgba(22, 163, 74, 0.15);
}

.device-button.connecting .device-dot {
  background: var(--amber);
  box-shadow: 0 0 0 5px rgba(183, 121, 31, 0.16);
}

.device-dot {
  width: 12px;
  height: 12px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: #b9c1bc;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(330px, 0.8fr);
  gap: 18px;
  align-items: start;
}

.builder-panel,
.preview-panel,
.target-block,
.metric-board,
.timeline-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.builder-panel,
.preview-panel {
  padding: 18px;
}

.preview-panel {
  display: grid;
  gap: 14px;
  background: transparent;
  border: 0;
  box-shadow: none;
  padding: 0;
}

.preview-section,
.catalog-panel,
.history-panel {
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

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

.form-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(110px, 1fr));
  gap: 12px;
}

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

.field.wide {
  margin-bottom: 12px;
}

.field span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 750;
}

.field small {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 750;
}

.field input,
.interval-row input {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  color: var(--ink);
  padding: 11px 12px;
  outline: none;
}

.field input:focus,
.interval-row input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.interval-header {
  margin-top: 20px;
}

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

.interval-row {
  display: grid;
  grid-template-columns: minmax(150px, 1.3fr) minmax(90px, 0.55fr) minmax(90px, 0.55fr) 44px;
  gap: 9px;
  align-items: end;
  padding: 12px;
  background: #f8faf8;
  border: 1px solid var(--line);
  border-radius: 8px;
}

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

.row-field span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
}

.primary-button,
.secondary-button,
.danger-button,
.icon-button {
  padding: 0 15px;
  font-weight: 800;
}

.compact-button {
  min-height: 34px;
  padding: 0 10px;
}

.primary-button {
  background: var(--accent);
  color: #fff;
}

.primary-button:hover {
  background: var(--accent-dark);
  box-shadow: 0 12px 28px rgba(15, 118, 110, 0.22);
}

.secondary-button,
.icon-button {
  background: #fff;
  border-color: var(--line);
  color: var(--steel);
}

.secondary-button:hover,
.icon-button:hover {
  background: #f2f6f4;
}

.danger-button {
  background: #fff5f4;
  border-color: #ffd5d0;
  color: var(--danger);
}

.danger-button:hover {
  background: #ffe8e5;
}

.icon-button {
  width: 44px;
  padding: 0;
  font-size: 1.25rem;
}

.builder-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: flex-end;
  flex-wrap: wrap;
  margin-top: 18px;
}

.save-status {
  min-height: 20px;
  max-width: min(100%, 620px);
  margin-right: auto;
  color: var(--accent-dark);
  font-size: 0.86rem;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.auth-gate {
  margin-bottom: 18px;
}

.auth-card {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(280px, 1.1fr);
  gap: 18px;
  align-items: center;
  padding: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.auth-card p {
  margin: 8px 0 0;
  color: var(--muted);
  font-weight: 700;
  line-height: 1.45;
}

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

.auth-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.duration-pill {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-weight: 850;
}

.workout-profile {
  margin-bottom: 14px;
}

.profile-chart {
  position: relative;
  height: 220px;
  padding: 14px 0 0 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  overflow: hidden;
}

.profile-grid {
  position: absolute;
  inset: 14px 0 0 38px;
  pointer-events: none;
}

.profile-marker {
  position: absolute;
  left: 0;
  width: 100%;
  border-top: 1px dashed rgba(105, 115, 109, 0.28);
}

.profile-marker small {
  position: absolute;
  left: -32px;
  top: -9px;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
}

.profile-bars {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 100%;
  padding: 0 10px 12px 0;
}

.profile-segment {
  min-width: 4px;
  height: 100%;
  display: flex;
  align-items: flex-end;
}

.profile-bar {
  width: 100%;
  height: var(--bar-height);
  min-height: 6px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 6px;
  border-radius: 5px 5px 0 0;
  background: color-mix(in srgb, var(--accent) var(--bar-intensity), #d7e7e2);
  color: #0c3d39;
  font-size: 0.72rem;
  font-weight: 900;
  overflow: hidden;
}

.profile-bar span {
  white-space: nowrap;
}

.empty-profile {
  margin: 0 0 14px;
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-weight: 750;
}

.segment-preview {
  display: grid;
  gap: 8px;
  max-height: min(420px, calc(100vh - 320px));
  overflow: auto;
  padding-right: 4px;
}

.segment-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  background: #fbfcfb;
}

.segment-card small {
  color: var(--muted);
  font-weight: 750;
}

.segment-card strong {
  overflow-wrap: anywhere;
}

.segment-power {
  color: var(--accent-dark);
  font-weight: 900;
}

.catalog-panel,
.history-panel {
  margin-top: 0;
}

.workout-catalog {
  display: grid;
  gap: 10px;
}

.empty-catalog {
  margin: 0;
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-weight: 750;
}

.catalog-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 13px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--accent);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 8px 22px rgba(28, 35, 31, 0.06);
}

.catalog-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.catalog-main {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.catalog-main strong,
.catalog-main small {
  overflow-wrap: anywhere;
}

.catalog-main small {
  color: var(--muted);
  font-weight: 750;
}

.catalog-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.catalog-actions button {
  min-height: 38px;
  padding: 0 10px;
}

.history-detail {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

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

.history-detail-header h3 {
  margin: 0 0 4px;
  font-size: 1rem;
}

.history-detail-header small {
  color: var(--muted);
  font-weight: 750;
}

.history-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.history-stat {
  display: grid;
  gap: 2px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.history-stat span,
.history-stat small {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
}

.history-stat strong {
  color: var(--steel);
  font-size: 1.45rem;
  line-height: 1;
}

.sample-table-wrap {
  max-height: 260px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.sample-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.sample-table th,
.sample-table td {
  padding: 8px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
}

.sample-table th:first-child,
.sample-table td:first-child {
  text-align: left;
}

.sample-table th {
  position: sticky;
  top: 0;
  background: #fff;
  color: var(--muted);
  font-weight: 850;
}

.ride-view {
  display: grid;
  gap: 16px;
}

.ride-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(330px, 0.75fr);
  gap: 16px;
}

.target-block {
  min-height: 380px;
  padding: 28px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.target-block h2 {
  font-size: clamp(1.8rem, 5vw, 4.8rem);
  line-height: 0.98;
  overflow-wrap: anywhere;
}

.target-watts {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.target-watts span {
  font-size: clamp(5rem, 16vw, 11rem);
  line-height: 0.85;
  font-weight: 900;
  color: var(--accent-dark);
}

.target-watts small {
  color: var(--muted);
  font-weight: 850;
}

progress {
  width: 100%;
  height: 18px;
  border: 0;
  border-radius: 999px;
  overflow: hidden;
  background: #e4ebe7;
}

progress::-webkit-progress-bar {
  background: #e4ebe7;
}

progress::-webkit-progress-value {
  background: var(--accent);
}

progress::-moz-progress-bar {
  background: var(--accent);
}

.time-row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  color: var(--steel);
  font-size: 1.15rem;
  font-weight: 850;
}

.metric-board {
  display: grid;
  grid-template-rows: repeat(4, minmax(96px, 1fr));
  gap: 1px;
  overflow: hidden;
}

.metric-tile {
  display: grid;
  align-content: center;
  justify-items: start;
  gap: 2px;
  padding: 22px;
  background: #fbfcfb;
}

.metric-tile span,
.metric-tile small {
  color: var(--muted);
  font-weight: 800;
}

.metric-tile strong {
  color: var(--steel);
  font-size: clamp(2.4rem, 6vw, 4.6rem);
  line-height: 0.95;
}

.timeline-wrap {
  padding: 14px;
  overflow: hidden;
}

.ride-timeline {
  position: relative;
  display: flex;
  width: 100%;
  height: 120px;
  align-items: flex-end;
  gap: 2px;
  border-radius: 8px;
  overflow: hidden;
  background:
    linear-gradient(to top, transparent 24%, rgba(105, 115, 109, 0.18) 24%, transparent calc(24% + 1px)),
    linear-gradient(to top, transparent 49%, rgba(105, 115, 109, 0.18) 49%, transparent calc(49% + 1px)),
    linear-gradient(to top, transparent 74%, rgba(105, 115, 109, 0.18) 74%, transparent calc(74% + 1px)),
    #edf2ef;
  padding: 12px 10px 18px;
}

.ride-timeline::before {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  width: var(--workout-progress, 0%);
  height: 6px;
  background: var(--accent-dark);
  z-index: 3;
}

.ride-timeline::after {
  content: "";
  position: absolute;
  left: var(--workout-progress, 0%);
  top: 8px;
  bottom: 6px;
  width: 3px;
  transform: translateX(-50%);
  border-radius: 999px;
  background: var(--ink);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.82);
  z-index: 4;
}

.timeline-segment {
  min-width: 3px;
  height: var(--bar-height);
  min-height: 8px;
  align-self: flex-end;
  border-radius: 5px 5px 0 0;
  background: color-mix(in srgb, var(--accent) var(--bar-intensity), #dbe6e1);
  border-right: 1px solid rgba(255, 255, 255, 0.65);
  opacity: 0.65;
}

.timeline-segment.active {
  opacity: 1;
  box-shadow: inset 0 0 0 3px rgba(23, 32, 27, 0.28);
}

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

[hidden] {
  display: none !important;
}

@media (max-width: 900px) {
  .topbar,
  .workspace,
  .ride-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
  }

  .device-strip {
    justify-content: stretch;
  }

  .topbar-actions,
  .account-strip {
    justify-items: stretch;
    justify-content: stretch;
    text-align: left;
  }

  .device-button {
    flex: 1 1 190px;
  }

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

  .preview-panel {
    order: -1;
  }

  .auth-card {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100vw - 20px, 1220px);
    padding-top: 12px;
  }

  .form-grid,
  .interval-row {
    grid-template-columns: 1fr;
  }

  .target-block {
    min-height: 340px;
    padding: 20px;
  }

  .time-row,
  .ride-actions,
  .builder-actions,
  .catalog-actions,
  .history-detail-header {
    flex-direction: column;
  }

  .ride-actions button,
  .builder-actions button,
  .catalog-actions button,
  .history-detail-header button,
  .auth-actions button {
    width: 100%;
  }

  .save-status {
    width: 100%;
  }

  .catalog-card {
    grid-template-columns: 1fr;
  }

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