/* css/style.css */

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-deep: #12121f;
  --bg-panel: #1a1a2e;
  --bg-card: #16213e;
  --bg-hover: #0f3460;
  --accent: #e94560;
  --accent2: #1a73e8;
  --text-primary: #e0e0e0;
  --text-secondary: #a0a0b0;
  --text-dim: #606075;
  --border: #2a2a4a;
  --sidebar-width: 280px;
}

html,
body {
  height: 100%;
  background: var(--bg-deep);
  color: var(--text-primary);
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 13px;
  overflow: hidden;
}

/* ─── Loading Overlay ─── */
#loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-deep);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.3s;
}

#loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-inner {
  text-align: center;
  color: var(--text-secondary);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent2);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 12px;
}

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

/* ─── App Layout ─── */
#app {
  display: flex;
  height: 100vh;
  width: 100vw;
}

/* ─── Sidebar ─── */
#sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  transition:
    width 0.25s ease,
    min-width 0.25s ease,
    border-color 0.25s ease;
}

#sidebar.collapsed {
  width: 0;
  min-width: 0;
  border-right-color: transparent;
}

#sidebar::-webkit-scrollbar {
  width: 5px;
}
#sidebar::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

#activity-header {
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
}

#activity-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

#activity-meta {
  font-size: 12px;
  color: var(--text-secondary);
}

/* ─── Stats Panel ─── */
#stats-panel {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.stat-card {
  background: var(--bg-card);
  border-radius: 6px;
  padding: 8px 10px;
}

.stat-label {
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 2px;
}

.stat-value {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.2;
}

.stat-unit {
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 400;
  margin-left: 2px;
}

/* Hover info card (shows while hovering map) */
#hover-info-card {
  margin-top: 8px;
  padding: 8px 10px;
  background: var(--bg-hover);
  border-radius: 6px;
  border: 1px solid var(--accent2);
  font-size: 12px;
  min-height: 40px;
}

#hover-info-card.empty {
  color: var(--text-dim);
  font-style: italic;
}

/* ─── Color Toggle ─── */
#color-toggle-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}

.toggle-label {
  font-size: 11px;
  color: var(--text-secondary);
  margin-right: 2px;
}

.toggle-btn {
  flex: 1;
  padding: 5px 8px;
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  transition:
    background 0.15s,
    color 0.15s,
    border-color 0.15s;
}

.toggle-btn.active {
  background: var(--accent2);
  color: #fff;
  border-color: var(--accent2);
}

.toggle-btn:hover:not(.active) {
  border-color: var(--accent2);
  color: var(--text-primary);
}

/* ─── Charts ─── */
#charts-container {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chart-wrap {
  background: var(--bg-card);
  border-radius: 6px;
  padding: 6px 4px;
}

.chart-title {
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

.canvas-stack {
  position: relative;
  width: 240px;
  height: 90px;
}

.canvas-stack canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

/* ─── Laps Section ─── */
#laps-section {
  padding: 10px 16px 16px;
}

.section-title {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

#laps-table-wrap {
  overflow-x: auto;
}

.laps-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.laps-table th {
  text-align: left;
  color: var(--text-dim);
  font-weight: 400;
  padding: 3px 6px 5px;
  font-size: 10px;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
}

.laps-table td {
  padding: 5px 6px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.laps-table tr:last-child td {
  border-bottom: none;
}

.laps-table tr.active td {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.laps-table tr:hover td {
  background: rgba(26, 115, 232, 0.1);
}

/* lap number badge */
.lap-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent2);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
}

/* ─── Map ─── */
#map {
  flex: 1;
  position: relative;
  height: 100vh;
}

/* MapLibre canvas fills container */
#map .maplibregl-map {
  width: 100%;
  height: 100%;
}

/* ─── Hover Tooltip (floating on map) ─── */
#hover-tooltip {
  position: absolute;
  background: rgba(18, 18, 31, 0.9);
  border: 1px solid var(--accent2);
  border-radius: 6px;
  padding: 8px 10px;
  pointer-events: none;
  z-index: 10;
  min-width: 180px;
  font-size: 12px;
  backdrop-filter: blur(4px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

#hover-tooltip.hidden {
  display: none;
}

#tooltip-lap {
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  margin-bottom: 2px;
}

#tooltip-distance {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.tooltip-row {
  display: flex;
  gap: 12px;
  margin-bottom: 3px;
}

.tooltip-label {
  color: var(--text-dim);
  min-width: 52px;
  font-size: 10px;
  text-transform: uppercase;
}

.tooltip-row span:last-child,
.tooltip-row span:nth-child(2),
.tooltip-row span:nth-child(4) {
  color: var(--text-primary);
  font-weight: 500;
}

/* ─── Color Legend ─── */
#color-legend {
  position: absolute;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(18, 18, 31, 0.85);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 6px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 10;
  backdrop-filter: blur(4px);
}

.legend-label {
  font-size: 10px;
  color: var(--text-secondary);
  white-space: nowrap;
}

#legend-gradient {
  width: 120px;
  height: 8px;
  border-radius: 4px;
}

/* Keep map attribution readable above overlays on smaller screens */
#map .maplibregl-ctrl-bottom-right,
#map .maplibregl-ctrl-bottom-left {
  z-index: 11;
}

@media (max-width: 1024px) {
  #color-legend {
    bottom: calc(48px + env(safe-area-inset-bottom, 0px));
  }
}

@media (max-width: 640px) {
  #color-legend {
    bottom: calc(58px + env(safe-area-inset-bottom, 0px));
    gap: 6px;
    padding: 6px 8px;
  }

  #legend-gradient {
    width: 96px;
  }

  .legend-label {
    font-size: 9px;
  }
}

/* ─── Sidebar Toggle Button ─── */
#btn-sidebar-toggle {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 10;
  width: 28px;
  height: 28px;
  background: rgba(18, 18, 31, 0.85);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 5px;
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  transition:
    color 0.15s,
    border-color 0.15s;
}

#btn-sidebar-toggle:hover {
  color: var(--text-primary);
  border-color: var(--accent2);
}
