/* The activity profile panel and chart (profilePanel.js, profileChart.js). */

/* ---------- activity profile panel ---------- */

/* Overlays the bottom of the map instead of taking layout space, so the map
   never resizes (no re-zoom, no extra tile loads). Waits just below the
   map's bottom edge, clipped by #mapPanel, and slides up when opened. */
#profilePanel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1100;
  height: var(--profile-height);
  display: flex;
  flex-direction: column;
  background: var(--bg-elevated);
  backdrop-filter: var(--glass-filter);
  -webkit-backdrop-filter: var(--glass-filter);
  border-top: 1px solid var(--border-subtle);
  box-shadow: var(--glass-edge), 0 -12px 40px var(--shadow-color);
  transform: translateY(calc(100% + 40px));
  transition: transform var(--profile-transition);
  /* Keeps the panel on its own compositor layer ahead of time, so the first
     frames of the slide aren't spent promoting it (and its backdrop blur). */
  will-change: transform;
}

.app-shell.has-profile #profilePanel {
  transform: none;
}

/* Leaflet's bottom corners (the tile attribution) ride up with the panel so they stay visible. */
#mapPanel .leaflet-bottom {
  transition: transform var(--profile-transition);
}

.app-shell.has-profile #mapPanel .leaflet-bottom {
  transform: translateY(calc(-1 * var(--profile-height)));
}

.profile-show-button {
  position: absolute;
  left: 50%;
  bottom: var(--space-4);
  z-index: 1050;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0.4rem 0.9rem;
  border: none;
  border-radius: var(--radius-pill);
  background: var(--glass-bg);
  backdrop-filter: var(--glass-filter);
  -webkit-backdrop-filter: var(--glass-filter);
  box-shadow: var(--glass-edge), var(--glass-shadow);
  color: var(--text-primary);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
}

.profile-show-button[hidden] {
  display: none;
}

.profile-show-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.profile-panel-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2) var(--space-4);
  padding: var(--space-2) var(--space-3) 0 var(--space-4);
}

.profile-panel-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.profile-legend {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.profile-legend-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0.25rem 0.5rem;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
  transition: background var(--transition), opacity var(--transition);
}

.profile-legend-item:hover:not(:disabled) {
  background: var(--bg-elevated-2);
}

.profile-legend-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* The last visible series can't be hidden; it keeps its normal look, just not clickable. */
.profile-legend-item:disabled {
  cursor: default;
}

.profile-legend-item[aria-pressed="false"] {
  opacity: 0.45;
  text-decoration: line-through;
}

.profile-legend-swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
}

.profile-legend-swatch--speed {
  height: 3px;
  background: var(--accent);
}

.profile-legend-swatch--elevation {
  background: var(--chart-elevation-fill);
  border: 1px solid var(--chart-elevation-stroke);
}

.segmented--compact .segmented-option {
  padding: 0.25rem 0.75rem;
  font-size: 0.78rem;
  /* Otherwise a squeezed header wraps a label onto two lines, making that control taller than its neighbours. */
  white-space: nowrap;
}

.profile-chart-area {
  position: relative;
  flex: 1;
  min-height: 0;
}

.profile-chart svg {
  display: block;
  /* Keeps vertical page scrolling working on touch screens while a finger drags across the chart. */
  touch-action: pan-y;
}

.profile-grid line {
  stroke: var(--chart-grid);
  stroke-width: 1;
}

.profile-elevation-area {
  fill: var(--chart-elevation-fill);
}

.profile-elevation-line {
  fill: none;
  stroke: var(--chart-elevation-stroke);
  stroke-width: 1;
}

.profile-speed-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.75;
  stroke-linejoin: round;
  stroke-linecap: round;
}

/* The average moving speed: the speed line's own colour, thinner, dotted and
   faded, so it reads as a reference the series is measured against rather
   than a second series. */
.profile-average-line {
  stroke: var(--accent);
  stroke-width: 1;
  stroke-dasharray: 1 4;
  stroke-linecap: round;
  opacity: 0.55;
}

.profile-average-label {
  fill: var(--accent);
  font-family: var(--font-family);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  opacity: 0.7;
}

/* Stops: the same weight as the speed line, just amber and a little faded,
   so they read as "paused here" without adding a loud new colour. */
.profile-stop-line {
  stroke: var(--warning);
  stroke-width: 1.75;
  stroke-linecap: round;
  opacity: 0.8;
}

.profile-stop-dot {
  fill: var(--warning);
  opacity: 0.8;
}

.profile-axis-label {
  fill: var(--text-tertiary);
  font-family: var(--font-family);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.profile-axis-label--speed {
  fill: var(--accent);
}

.profile-crosshair {
  stroke: var(--text-tertiary);
  stroke-width: 1;
  stroke-dasharray: 3 3;
}

.profile-speed-dot {
  fill: var(--accent);
  stroke: var(--bg-base);
  stroke-width: 2;
}

.profile-speed-dot.is-stop {
  fill: var(--warning);
}

.profile-elevation-dot {
  fill: var(--chart-elevation-stroke);
  stroke: var(--bg-base);
  stroke-width: 1.5;
}

.profile-tooltip {
  position: absolute;
  z-index: 5;
  min-width: 150px;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  /* See-through enough to follow the curves underneath. The slight blur
     softens a line passing behind the text so it can't cross a digit, and
     the halo keeps the text off whatever shows through. */
  background: color-mix(in srgb, var(--bg-base) 62%, transparent);
  -webkit-backdrop-filter: blur(1.5px);
  backdrop-filter: blur(1.5px);
  box-shadow: var(--glass-edge), var(--glass-shadow);
  font-size: 0.76rem;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 3px var(--bg-base), 0 0 1px var(--bg-base);
  pointer-events: none;
}

.profile-tooltip-row {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
}

.profile-tooltip-label {
  color: var(--text-tertiary);
}

@media (prefers-reduced-motion: reduce) {
  .app-shell {
    --profile-transition: 0s;
  }
}
