:root {
  --bg: #f2f5f7;
  --text: #1f2933;
  --muted: #52606d;
  --accent: #0b7285;
  --accent-2: #177e9a;
  --error: #b42318;
  --border: #d9e2ec;
}

* {
  box-sizing: border-box;
}

body {
  background: radial-gradient(circle at top right, #dff7fb, var(--bg) 42%);
  color: var(--text);
}

.app {
  max-width: 1060px;
}

.card {
  border-color: #cfdce8;
  border-radius: 14px;
}

.card.shadow-sm {
  box-shadow: 0 3px 10px rgba(16, 24, 40, 0.04) !important;
}

.top-card {
  overflow: hidden;
}

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

.input-modes {
  display: flex;
  flex-wrap: nowrap;
  border: 0;
  border-bottom: 1px solid var(--border);
  gap: 6px;
}

.custom-tabs .nav-item {
  flex: 1 1 0;
  min-width: 0;
  margin-bottom: 0;
}

.mode-btn {
  width: 100%;
  border: 1px solid #cbd7e3 !important;
  border-bottom: 0 !important;
  border-radius: 10px 10px 0 0 !important;
  background: #edf2f7 !important;
  color: #334155;
  font-weight: 600;
  text-align: center;
  white-space: normal;
  line-height: 1.2;
  padding: 11px 14px;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.mode-btn.active {
  border-color: #b8c9da !important;
  background: #fff !important;
  color: var(--accent-2) !important;
  font-weight: 700;
}

.mode-btn:hover {
  background: #e6edf5 !important;
  color: #1f3347;
}

.mode-btn.active:hover {
  background: #fff !important;
  color: var(--accent-2) !important;
}

.mode-section {
  display: none;
}

.mode-section.active {
  display: block;
}

.mode-note {
  color: var(--muted);
  font-size: 13px;
}

.image-preview-wrap {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  padding: 10px;
}

.image-preview-label {
  margin: 0 0 8px;
  color: #263645;
  font-weight: 600;
  font-size: 13px;
}

.image-preview-img {
  display: block;
  width: 100%;
  max-width: 420px;
  max-height: 680px;
  border-radius: 8px;
  border: 1px solid #c6d4e1;
  object-fit: contain;
  background: #f8fbfd;
}

.options-header {
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}

.options-title {
  color: #1f3347;
  font-weight: 700;
}

.options .field {
  min-width: 0;
}

.form-label {
  font-weight: 600;
  color: #263645;
}

.workout-label {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 10px;
}

.label-main {
  font-weight: 700;
  color: #263645;
}

.label-hint {
  color: var(--muted);
  font-weight: 500;
  font-size: 0.92rem;
}

.form-control {
  border-color: #c6d4e1;
}

.form-control:focus {
  border-color: #94c2d1;
  box-shadow: 0 0 0 0.2rem rgba(11, 114, 133, 0.15);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  border-radius: 10px;
  font-weight: 600;
  padding-inline: 16px;
}

.btn-primary:hover,
.btn-primary:focus {
  background: var(--accent-2);
  border-color: var(--accent-2);
}

.xml-toolbar {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
}

.xml-controls {
  margin: 0;
  width: min(260px, 100%);
}

.xml-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.unit-segment {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: min(260px, 100%);
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #edf2f7;
  overflow: hidden;
  min-height: 40px;
}

.unit-segment input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.unit-thumb {
  position: absolute;
  top: 2px;
  bottom: 2px;
  left: 2px;
  width: calc(50% - 2px);
  background: var(--accent);
  border-radius: 999px;
  transition: transform 0.2s ease;
}

.unit-segment label {
  position: relative;
  z-index: 1;
  margin: 0;
  display: grid;
  place-items: center;
  cursor: pointer;
  font-weight: 600;
  color: var(--text);
}

#unitMiles:checked ~ .unit-thumb,
#xmlUnitMiles:checked ~ .unit-thumb,
#buildInputSpeed:checked ~ .unit-thumb {
  transform: translateX(100%);
}

#unitKm:checked ~ label[for="unitKm"],
#unitMiles:checked ~ label[for="unitMiles"],
#xmlUnitKm:checked ~ label[for="xmlUnitKm"],
#xmlUnitMiles:checked ~ label[for="xmlUnitMiles"],
#buildInputPace:checked ~ label[for="buildInputPace"],
#buildInputSpeed:checked ~ label[for="buildInputSpeed"] {
  color: #fff;
}

.rows-output {
  display: grid;
  gap: 8px;
}

.builder-wrap {
  display: grid;
  gap: 10px;
}

.builder-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.builder-list,
.builder-children {
  display: grid;
  gap: 8px;
  min-height: 20px;
}

.builder-empty {
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 10px;
  color: var(--muted);
  font-size: 13px;
  background: #fff;
}

.builder-header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  cursor: grab;
  user-select: none;
}

.builder-header-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.builder-type-select {
  max-width: 180px;
  border: 1px solid rgba(15, 23, 42, 0.2);
  border-radius: 8px;
  padding: 5px 8px;
  font-size: 13px;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.9);
  color: #1f2933;
  cursor: pointer;
}

.builder-remove {
  font-weight: 600;
  margin-left: auto;
  cursor: pointer;
}

.builder-drag-indicator {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 14px;
  height: 2px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.95);
  color: #475569;
  box-shadow:
    0 4px 0 rgba(255, 255, 255, 0.95),
    0 8px 0 rgba(255, 255, 255, 0.95);
  pointer-events: none;
}

.builder-header:active {
  cursor: grabbing;
}

.builder-body {
  background: rgba(255, 255, 255, 0.7);
}

.builder-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}

.builder-field {
  display: grid;
  gap: 5px;
  font-size: 13px;
  font-weight: 600;
  color: #334155;
}

.builder-field input,
.builder-field select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 14px;
  background: #fff;
}

.builder-children {
  border-left: 3px solid rgba(15, 23, 42, 0.15);
  margin-left: 6px;
  padding-left: 8px;
}

.section-title {
  margin: 0;
  font-weight: 700;
}

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

.repeat-block {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: #f8fbfd;
}

.repeat-block-repeat {
  border-color: #ff7b5a;
}

.repeat-block-warm-up {
  border-color: #f4a261;
}

.repeat-block-rest {
  border-color: #76c7c0;
}

.repeat-block-run {
  border-color: #38b000;
}

.repeat-block-cool-down {
  border-color: #4ea8de;
}

.repeat-header {
  color: #1f2933;
  font-weight: 700;
  padding: 8px 10px;
}

.repeat-header-repeat {
  background: linear-gradient(90deg, #ff9f1c, #ff5d5d);
}

.repeat-header-warm-up {
  background: linear-gradient(90deg, #ffd166, #f4a261);
}

.repeat-header-rest {
  background: linear-gradient(90deg, #a8dadc, #76c7c0);
  color: #16323a;
}

.repeat-header-run {
  background: linear-gradient(90deg, #80ed99, #38b000);
  color: #102a14;
}

.repeat-header-cool-down {
  background: linear-gradient(90deg, #90e0ef, #4ea8de);
  color: #0d2b45;
}

.repeat-body {
  padding: 8px;
  display: grid;
  gap: 8px;
}

.rows-output[data-view="parsed-text"] .repeat-block-repeat > .repeat-body {
  position: relative;
  padding-left: 14px;
}

.rows-output[data-view="parsed-text"] .repeat-block-repeat > .repeat-body::before {
  content: "";
  position: absolute;
  left: 6px;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.2);
}

.row-item {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 14px;
  background: #fff;
}

.row-source {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 12px;
}

.status {
  margin: 10px 0 0;
  color: var(--muted);
}

.status.error {
  color: var(--error);
}

.app-footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.95rem;
}

.app-footer a {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

.app-footer a:hover,
.app-footer a:focus {
  color: var(--accent-2);
  text-decoration: underline;
}

.xml-output {
  font-family: Consolas, "Courier New", monospace;
}

@media (max-width: 680px) {
  .custom-tabs .nav-item {
    display: flex;
  }

  .mode-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 104px;
    font-size: 0.95rem;
    padding: 9px 8px;
  }

  .xml-toolbar {
    width: 100%;
  }

  .xml-actions {
    width: 100%;
  }

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