/* ============================================================================
   3D ROUTE INSPECTOR — live GPX marker, elevation sync, timeline, playback,
   checkpoint popovers. Additive to the existing 3D map (route-map3d) and
   elevation profile (route-elev) — does not restyle either.
   ============================================================================ */

.route-inspector { margin-top: 12px; }

.route-inspector__grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
  padding: 12px;
  background: var(--surface, var(--bg));
  border: 1px solid var(--border);
  border-radius: 12px;
}

.route-inspector__item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 8px;
}

.route-inspector__label {
  font-size: 11.5px;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.route-inspector__v {
  font-size: 15px;
  font-weight: 800;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* Live marker (a MapLibre custom-element Marker) that follows the GPX line */
.route-inspector__marker {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fc4c02;
  border: 2.5px solid #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  display: none;
  position: relative;
}

.route-inspector__marker.is-active { display: block; animation: route-marker-glow 1.6s ease-in-out infinite; }

@keyframes route-marker-glow {
  0%, 100% { box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5), 0 0 0 0 rgba(252, 76, 2, 0.55); }
  50% { box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5), 0 0 0 8px rgba(252, 76, 2, 0); }
}

/* Optional direction-of-travel arrow, rotated via bearing between adjacent GPX points */
.route-inspector__marker-arrow {
  position: absolute;
  top: -13px;
  left: 50%;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 8px solid #fc4c02;
  transform-origin: 50% 18px;
  margin-left: -5px;
}

/* Interactive elevation strip (crosshair overlaid on the existing SVG) */
.route-inspector__elev {
  position: relative;
  margin-top: 10px;
  cursor: crosshair;
  color: var(--primary, #fc4c02);
  touch-action: none;
}

.route-inspector__elev svg { display: block; width: 100%; height: auto; }

.route-inspector__crosshair {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0%;
  width: 2px;
  background: var(--primary, #fc4c02);
  box-shadow: 0 0 6px rgba(252, 76, 2, 0.6);
  pointer-events: none;
}

/* Timeline slider */
.route-inspector__timeline {
  width: 100%;
  margin-top: 10px;
  accent-color: var(--primary, #fc4c02);
}

/* Live Route Progress */
.route-inspector__progress { margin-top: 10px; }

.route-inspector__progress-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-weight: 700;
  font-size: 13px;
  color: var(--text);
}

.route-inspector__progress-pct { font-size: 16px; font-weight: 800; color: var(--primary, #fc4c02); }

.route-inspector__progress-track {
  height: 8px;
  border-radius: 6px;
  background: var(--surface-2, var(--border));
  overflow: hidden;
  margin: 6px 0;
}

.route-inspector__progress-fill {
  height: 100%;
  width: 0%;
  background: var(--primary, #fc4c02);
  border-radius: 6px;
  transition: width 0.12s linear;
}

.route-inspector__progress-remaining { font-size: 12px; color: var(--muted); }

/* Analysis panel config (pace/weight ephemeral inputs) */
.route-inspector--analysis { margin-top: 14px; }

.route-inspector__config {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 8px;
}

.route-inspector__config-field {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--muted);
  font-weight: 600;
}

/* Checkpoint System popover */
.route-inspector__checkpoint {
  margin-top: 10px;
  padding: 12px 14px;
  border-radius: 12px;
  background: color-mix(in srgb, #f59e0b 12%, var(--surface, var(--bg)));
  border: 1px solid #f59e0b;
}

.route-inspector__checkpoint.is-pulsing { animation: route-cp-pulse 0.9s ease-out; }

@keyframes route-cp-pulse {
  0% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.55); }
  100% { box-shadow: 0 0 0 16px rgba(245, 158, 11, 0); }
}

.route-inspector__cp-title { margin: 0 0 4px; font-size: 15px; font-weight: 800; color: var(--text); }
.route-inspector__cp-meta { margin: 0 0 6px; font-size: 12.5px; color: var(--muted); }

.route-inspector__cp-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }

.route-inspector__cp-chip {
  font-size: 11.5px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  background: #fff;
  color: #92400e;
  border: 1px solid #f59e0b;
}

.route-inspector__cp-note { margin: 4px 0 0; font-size: 12.5px; color: var(--text); font-style: italic; }

.route-inspector__cp-photos { display: flex; gap: 6px; margin-top: 8px; }

.route-inspector__cp-photos img {
  width: 56px; height: 56px; object-fit: cover; border-radius: 8px; cursor: pointer;
}

/* Playback + camera mode controls */
.route-inspector__controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  margin-top: 10px;
}

.route-inspector__playback {
  display: flex;
  align-items: center;
  gap: 6px;
}

.route-inspector__camera {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--muted);
  font-weight: 600;
}

/* ============================================================================
   CHECKPOINT PLANNING SYSTEM (Race Director) — toolbar, map markers, live
   list, per-checkpoint analysis, summary, exports, print sheet. Additive to
   the blocks above; reuses the same var(--surface/--border/--muted/--primary)
   tokens as the rest of the 3D Route Inspector so it reads as one system.
   ============================================================================ */

.route-cpsys { margin-top: 16px; }

/* ── Toolbar: "➕ Προσθήκη Checkpoint" + drag-ghost readout ── */
.route-cp-toolbar { margin: 10px 0; }

.route-cp-toolbar .btn.is-active {
  background: var(--ink, #18181b);
  border-color: var(--ink, #18181b);
  color: #fff;
}

.route-cp-dragghost {
  margin-top: 8px;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px dashed var(--primary, #fc4c02);
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
}

/* ── 3D-map markers (draggable, snap-to-route) ── */
.route-cp-marker {
  width: 30px;
  height: 30px;
  border-radius: 50% 50% 50% 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  line-height: 1;
  color: #fff;
  border: 2px solid #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.route-cp-marker:hover,
.route-cp-marker.is-highlighted {
  transform: scale(1.2);
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.45), 0 4px 14px rgba(0, 0, 0, 0.4);
  z-index: 5;
}

/* ── Preview marker while placing a new checkpoint ── */
.route-cp-preview {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--primary, #fc4c02);
  border: 3px solid #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
  animation: route-cp-preview-pulse 1s ease-in-out infinite;
}

@keyframes route-cp-preview-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.35); opacity: 0.65; }
}

/* ── Checkpoint markers overlaid on the elevation-sync strip — centered
   exactly on the curve via inline left/top %, so margins here just offset
   by half the dot's own size to align its CENTER (not its top-left corner)
   with that computed point. ── */
.route-inspector__elev-cp {
  position: absolute;
  width: 13px;
  height: 13px;
  margin-left: -6.5px;
  margin-top: -6.5px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.45);
  cursor: pointer;
  z-index: 2;
  transition: transform 0.12s ease;
}

.route-inspector__elev-cp:hover,
.route-inspector__elev-cp.is-highlighted {
  transform: scale(1.5);
  z-index: 3;
}

.route-inspector__elev-cp-tip {
  position: absolute;
  bottom: 130%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink, #18181b);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 8px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s ease;
}

.route-inspector__elev-cp:hover .route-inspector__elev-cp-tip,
.route-inspector__elev-cp.is-highlighted .route-inspector__elev-cp-tip {
  opacity: 1;
}

/* ── Checkpoint Manager (live list) ── */
.route-cp-list { margin-top: 16px; }

.route-cp-list__table {
  display: flex;
  flex-direction: column;
  min-width: 1040px;
  font-size: 12.5px;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.route-cp-list__row {
  display: grid;
  grid-template-columns: 44px 1.3fr 1fr 84px 84px 68px 68px 84px 96px 76px 76px 160px 88px 118px;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}

.route-cp-list__row:last-child { border-bottom: none; }

.route-cp-list__row--head {
  font-weight: 800;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: var(--surface-2);
}

.route-cp-list__row:not(.route-cp-list__row--head):hover,
.route-cp-list__row.is-highlighted {
  background: color-mix(in srgb, var(--primary, #fc4c02) 8%, var(--surface, var(--bg)));
}

.route-cp-list__status { font-weight: 700; font-size: 11.5px; color: var(--muted); }

.route-cp-list__actions { display: flex; gap: 4px; justify-content: flex-end; }

/* ── Service badges (presets + unlimited custom) — used in the Checkpoint
   List column, CP Analysis cards, and the modal's live preview. Always
   wraps onto multiple lines rather than clipping or forcing a scrollbar. ── */
.route-cp-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 6px;
}

.route-cp-badges--compact { margin-top: 4px; }

.route-cp-badge {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.4;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  white-space: nowrap;
}

.route-cp-badge--custom {
  background: color-mix(in srgb, var(--primary, #fc4c02) 10%, var(--surface, var(--bg)));
  border-color: color-mix(in srgb, var(--primary, #fc4c02) 35%, var(--border));
}

/* ── Custom service editor (inside the checkpoint modal) ── */
.route-cp-service-add {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
}

.route-cp-service-add .input { flex: 1; min-width: 180px; }

.route-cp-service-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.route-cp-service-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 6px 4px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
}

.route-cp-service-chip__edit-input {
  width: 120px;
  font-size: 12px;
  padding: 2px 6px;
}

.route-cp-service-chip__btn {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 11px;
  line-height: 1;
  padding: 2px;
  color: var(--muted);
  border-radius: 6px;
}

.route-cp-service-chip__btn:hover {
  background: color-mix(in srgb, var(--primary, #fc4c02) 14%, transparent);
  color: var(--text);
}

/* ── Per-checkpoint analysis cards + automatic summary ── */
.route-cp-analysis { margin-top: 16px; }

.route-cp-analysis__cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 10px;
  margin-top: 8px;
}

.route-cp-analysis__card {
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--surface, var(--bg));
  border: 1px solid var(--border);
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.route-cp-analysis__card:hover,
.route-cp-analysis__card.is-highlighted {
  border-color: var(--primary, #fc4c02);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary, #fc4c02) 16%, transparent);
}

.route-cp-analysis__card h5 {
  margin: 0 0 6px;
  font-size: 13.5px;
  font-weight: 800;
  color: var(--text);
}

.route-cp-summary { margin-top: 16px; }

/* ── Exports ── */
.route-cp-exports { margin-top: 16px; }

/* ── Print sheet (PDF / Race Book) — hidden on screen, only rendered on print ── */
.route-print-sheet { display: none; }

@media print {
  body > *:not(.route-print-sheet) { display: none !important; }
  .route-print-sheet {
    display: block !important;
    padding: 24px;
    color: #000;
    background: #fff;
  }
  .route-print-sheet__table { width: 100%; border-collapse: collapse; font-size: 11px; }
  .route-print-sheet__table th,
  .route-print-sheet__table td { border: 1px solid #999; padding: 4px 6px; text-align: left; }
  .route-print-sheet__table th { background: #f1f1f1; }
}

/* ── Registration Form Builder — draggable field rows (reuses route-cp-list__row's grid/border, just adds the drag affordance) ── */
.regform-field-row { cursor: grab; }
.regform-field-row:active { cursor: grabbing; }

/* ============================================================================
   CHECKPOINT CONTROL CENTER (card-based redesign) — all additive/scoped.
   Nothing in .card/.stat/.btn/.collapse base rules is touched.
   ============================================================================ */

/* Header stat tiles — reuses .stat/.stat__icon/.stat__value/.stat__label as-is */
.route-cp-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; margin: 10px 0; }

/* Filter bar — structurally mirrors participants.js's toolbar (search + chips + selects), own prefix to avoid cross-feature class coupling */
.route-cp-filterbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.route-cp-filterbar__search { flex: 1; min-width: 200px; }
.route-cp-filterbar__group { display: flex; gap: 6px; flex-wrap: wrap; }
.route-cp-chip {
  font-size: 12.5px; font-weight: 700; padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer;
}
.route-cp-chip.is-active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* Card — no forced min-width (unlike the old 1040px table): cards reflow at any viewport width */
.route-cp-card { margin-top: 8px; }
.route-cp-card.is-highlighted { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 16%, transparent); }
.route-cp-card__head { position: relative; z-index: 1; background: var(--surface); touch-action: pan-y; width: 100%; text-align: left; }
.route-cp-card__icon { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; color: #fff; flex: none; font-size: 15px; }
.route-cp-card__title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.route-cp-card__meta { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.route-cp-card__status { font-size: 11px; font-weight: 700; color: var(--muted); white-space: nowrap; }
.route-cp-card__section { padding: 10px 0; border-top: 1px solid var(--border); }
.route-cp-card__section:first-child { border-top: none; }
.route-cp-card__section-title { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 6px; }
.route-cp-card__minimap-canvas { width: 100%; height: 220px; border-radius: 10px; overflow: hidden; }
.route-cp-card__drag-handle { cursor: grab; color: var(--muted); }

/* Smooth open/close via the grid-template-rows trick — cost is bounded to
   the one card whose class changes on any given click. */
.route-cp-card.collapse .collapse__body { display: grid; grid-template-rows: 0fr; padding: 0 12px; overflow: hidden; transition: grid-template-rows .22s ease, padding .22s ease; }
.route-cp-card.collapse .collapse__body > * { overflow: hidden; min-height: 0; }
.route-cp-card.collapse.is-open .collapse__body { grid-template-rows: 1fr; padding: 0 12px 12px; }

/* Filtered-out map markers/elevation dots stay visible but de-emphasized, never removed */
.route-cp-marker.is-filtered-out, .route-inspector__elev-cp.is-filtered-out { opacity: .32; filter: grayscale(40%); }

/* "Open in 3D Map" flash */
.route-map3d.is-flash { animation: route-map-flash 900ms ease-out; }
@keyframes route-map-flash { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--primary) 55%, transparent); } 100% { box-shadow: 0 0 0 18px color-mix(in srgb, var(--primary) 0%, transparent); } }

/* Swipe-to-reveal (mobile) — actions layer sits behind the head row */
.route-cp-card { position: relative; }
.route-cp-card__head { position: relative; }

/* Drag-reorder (mirrors workout-builder-premium.js's is-dragging/is-drag-over) */
.route-cp-card.is-dragging { opacity: .5; }
.route-cp-card.is-drag-over { outline: 2px dashed var(--primary); outline-offset: 2px; }

/* Volunteer editor rows (inside openCheckpointModal) */
.route-cp-volunteer-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--border); }
.route-cp-volunteer-row__field { flex: 1; min-width: 100px; }
