/* ── Long Run Planner Styles ── */

body {
  line-height: 1.5;
  padding: var(--safeT) env(safe-area-inset-right) var(--safeB) env(safe-area-inset-left);
  min-height: 100dvh;
  overflow-x: hidden;
}

.app-container {
  max-width: 600px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: 40px;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}

.app-header svg { flex-shrink: 0; }

.app-header h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.app-header .subtitle {
  font-size: 13px;
  color: var(--muted);
  font-weight: 400;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radiusLg);
  margin-bottom: 16px;
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.card-header svg { color: var(--muted); flex-shrink: 0; }

.card-body { padding: 16px; }

/* Form inputs */
.form-group { margin-bottom: 16px; }
.form-group:last-child { margin-bottom: 0; }

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  padding: 10px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}

.form-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 111, 235, 0.2);
}

.form-input::placeholder { color: var(--muted2); }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s;
  width: 100%;
  -webkit-tap-highlight-color: transparent;
}

.btn-primary {
  background: var(--successEmph);
  color: #fff;
  border-color: rgba(240,246,252,0.1);
}

.btn-primary:hover { background: #2ea043; }
.btn-primary:active { background: #238636; transform: scale(0.98); }

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover { background: var(--borderMuted); }

/* Slider */
.slider-container { position: relative; }

.slider-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}

.slider-value {
  font-size: 22px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
}

.slider-value.safe { color: var(--success); }
.slider-value.caution { color: var(--warn); }
.slider-value.danger { color: var(--danger); }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  outline: none;
  background: var(--border);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  cursor: pointer;
  border: 2px solid var(--border);
  box-shadow: 0 1px 4px rgba(0,0,0,0.4);
}

.slider-labels {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted2);
  margin-top: 4px;
}

/* Risk bar */
.risk-bar {
  height: 8px;
  border-radius: 4px;
  background: linear-gradient(90deg,
    var(--success) 0%,
    var(--success) 10%,
    var(--warn) 30%,
    var(--danger) 70%,
    #ff2020 100%
  );
  position: relative;
  margin: 12px 0 4px;
}

.risk-bar-marker {
  position: absolute;
  top: -4px;
  width: 4px;
  height: 16px;
  background: #fff;
  border-radius: 2px;
  transform: translateX(-50%);
  transition: left 0.2s;
  box-shadow: 0 0 6px rgba(255,255,255,0.5);
}

/* Stats grid */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--border);
  border-radius: var(--radiusMd);
  overflow: hidden;
}

.stat-cell {
  background: var(--surface);
  padding: 14px;
  text-align: center;
}

.stat-cell.full-width { grid-column: 1 / -1; }

.stat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted2);
  font-weight: 600;
  margin-bottom: 4px;
}

.stat-value {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.stat-unit {
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}

.stat-value.accent { color: var(--accent); }
.stat-value.success { color: var(--success); }
.stat-value.attention { color: var(--warn); }
.stat-value.danger { color: var(--danger); }

/* Risk zones table */
.risk-zones {
  width: 100%;
  border-collapse: collapse;
}

.risk-zones td {
  padding: 8px 12px;
  font-size: 13px;
  border-bottom: 1px solid var(--borderMuted);
  vertical-align: middle;
}

.risk-zones tr:last-child td { border-bottom: none; }

.risk-zones .zone-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 8px;
}

.risk-zones .zone-range { color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.risk-zones .zone-hrr { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }

/* Timeline */
.timeline { padding: 4px 0; }

.timeline-controls {
  display: flex;
  justify-content: flex-end;
  align-items: flex-end;
  gap: 10px;
  margin-bottom: 10px;
}

.timeline-head {
  display: flex;
  gap: 12px;
  padding: 6px 0;
  border-bottom: 1px solid var(--borderMuted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted2);
}

.timeline-bar-label {
  flex: 1;
  min-width: 80px;
  text-align: left;
}

.timeline-head .timeline-date,
.timeline-head .timeline-dist,
.timeline-head .timeline-risk {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted2);
}

.timeline-item {
  display: flex;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--borderMuted);
  align-items: center;
}

.timeline-item:last-child { border-bottom: none; }

.timeline-date {
  font-size: 12px;
  color: var(--muted2);
  min-width: 70px;
  font-variant-numeric: tabular-nums;
}

.timeline-bar-wrap { flex: 1; position: relative; }

.timeline-bar {
  height: 20px;
  border-radius: 3px;
  min-width: 4px;
  transition: width 0.3s;
}

.timeline-dist {
  font-size: 12px;
  font-weight: 600;
  min-width: 70px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.timeline-bar.longest {
  box-shadow: 0 0 0 2px var(--accent);
}

.timeline-risk {
  font-size: 12px;
  font-weight: 700;
  min-width: 84px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--muted2);
}


.risk-actions {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
}

.risk-actions .btn {
  width: auto;
  flex: 1 1 0;
}

/* Callout */
.callout {
  display: flex;
  gap: 10px;
  padding: 12px;
  border-radius: var(--radiusMd);
  font-size: 13px;
  line-height: 1.45;
}

.callout svg { flex-shrink: 0; margin-top: 1px; }

.callout-success {
  background: rgba(63, 185, 80, 0.1);
  border: 1px solid rgba(63, 185, 80, 0.25);
  color: var(--success);
}

.callout-warning {
  background: rgba(210, 153, 34, 0.1);
  border: 1px solid rgba(210, 153, 34, 0.25);
  color: var(--warn);
}

.callout-danger {
  background: rgba(248, 81, 73, 0.1);
  border: 1px solid rgba(248, 81, 73, 0.25);
  color: var(--danger);
}

.callout-info {
  background: rgba(88, 166, 255, 0.1);
  border: 1px solid rgba(88, 166, 255, 0.25);
  color: var(--accent);
}

.callout a {
  color: inherit;
  text-decoration: underline;
}

/* Loading spinner */
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,0.2);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* State screens */
.state-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
}

.state-empty svg { margin-bottom: 12px; opacity: 0.4; }

.state-empty h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.state-empty p { font-size: 13px; }

/* Unit toggle */
.unit-toggle {
  display: inline-flex;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radiusMd);
  overflow: hidden;
}

.card-header-spacer { flex: 1; }

.input-with-unit {
  display: flex;
  align-items: center;
  gap: 8px;
}

.input-with-unit .form-input { flex: 1; }

.input-unit {
  min-width: 64px;
  text-align: center;
  padding: 6px 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radiusMd);
}

.fetch-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: end;
  gap: 10px;
}

.fetch-days { width: 100%; }
.risk-days { width: 140px; }
.fetch-row .btn { width: 100%; }

.unit-toggle button {
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  background: transparent;
  color: var(--muted);
  border: none;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.unit-toggle button.active {
  background: var(--accentEmph);
  color: #fff;
}

/* Paper citation */
.paper-ref {
  font-size: 12px;
  color: var(--muted2);
  padding: 12px 16px;
  border-top: 1px solid var(--borderMuted);
  line-height: 1.5;
}

.paper-ref a {
  color: var(--accent);
  text-decoration: none;
}

.paper-ref a:hover { text-decoration: underline; }

/* Transitions */
.fade-in {
  animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Badge */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}

.badge-success {
  background: rgba(63,185,80,0.15);
  color: var(--success);
}

.section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted2);
  font-weight: 700;
  margin-bottom: 12px;
  margin-top: 4px;
}

.divider {
  border: none;
  border-top: 1px solid var(--borderMuted);
  margin: 16px 0;
}

/* Estimated pace / time row */
.suggestion-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  font-size: 14px;
}

.suggestion-row .label { color: var(--muted); }
.suggestion-row .value { font-weight: 700; font-variant-numeric: tabular-nums; }

/* Workout modal */
textarea.form-input {
  resize: vertical;
  min-height: 80px;
}
