/* =========================================
   RallyCAP — GPX Map Viewer Styles (V3)
   ========================================= */

/* ---- Map page: override variables for dark theme ---- */
.map-page {
  --bg: #0a0a0a;
  --bg-card: #111111;
  --bg-elevated: #1a1a1a;
  --text: #f5f5f0;
  --text-muted: rgba(245, 245, 240, 0.45);
  --accent: #FFFF00;
  --accent-hover: #e6e600;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.15);

  overflow: hidden;
  height: 100vh;
  background: var(--bg);
  color: var(--text);
}

/* ---- Map nav ---- */
.map-nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  height: 52px;
  background: rgba(10, 10, 10, 0.9);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
}

.map-nav__inner {
  max-width: 100%;
  padding: 0 1.25rem;
  height: 100%;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.map-nav__back {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  color: var(--text-muted);
  transition: background 0.2s, color 0.2s;
}

.map-nav__back:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
}

.map-nav__logo img { height: 18px; width: auto; filter: invert(1); }

.map-nav__upload {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.375rem 0.875rem;
  background: var(--accent);
  color: #000;
  border-radius: var(--radius-btn);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: background 0.2s;
  margin-left: 0.5rem;
}

.map-nav__upload:hover {
  background: var(--accent-hover);
}

.map-nav__export {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.375rem 0.875rem;
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius-btn);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  margin-left: 0.25rem;
}

.map-nav__export:hover {
  background: var(--accent);
  color: #000;
}

.map-nav__export[hidden] {
  display: none !important;
}

.map-nav__stats {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
}

.stat-name {
  color: var(--accent);
  font-weight: 500;
}

.stat-item {
  opacity: 0.6;
}

.stat-sections {
  opacity: 0.4;
  font-size: 0.65rem;
}

.map-nav__lang {
  display: flex;
  gap: 0.125rem;
  margin-left: 0.5rem;
}

/* ---- Map layout ---- */
.map-layout {
  display: flex;
  height: calc(100vh - 52px);
  margin-top: 52px;
}

/* ---- Table panel ---- */
.map-panel-table {
  width: 420px;
  flex-shrink: 0;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.map-panel-table__content {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

/* ---- Drop zone ---- */
.viz-drop {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-card);
  padding: 2.5rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  margin: 1.25rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
}

.viz-drop[hidden] {
  display: none !important;
}

.wp-table-wrap[hidden] {
  display: none !important;
}

.elevation-profile[hidden] {
  display: none !important;
}

.viz-drop:hover,
.viz-drop.drag-over {
  border-color: var(--accent);
  background: rgba(255, 255, 0, 0.03);
}

.viz-drop p {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* ---- Waypoint table ---- */
.wp-table-wrap {
  flex: 1;
  overflow-y: auto;
}

.tbl-header {
  display: flex;
  background: rgba(0, 0, 0, 0.4);
  border-bottom: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  position: sticky;
  top: 0;
  z-index: 3;
}

.tbl-header > div {
  text-align: center;
  padding: 8px 4px;
}

.section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: rgba(0, 0, 0, 0.6);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text);
  position: sticky;
  top: 30px;
  z-index: 2;
}

.sec-badge {
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-size: 0.6rem;
  font-weight: 700;
  color: #fff;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.sec-badge--ss { background: #e53935; }
.sec-badge--rs { background: #1e88e5; }

.sec-name {
  font-family: var(--font-mono);
  color: var(--text);
}

.sec-meta {
  margin-left: auto;
  font-weight: 400;
  color: var(--text-muted);
  font-size: 0.6rem;
}

.wp-row {
  display: flex;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  cursor: pointer;
  transition: background 0.1s;
  color: var(--text);
}

.wp-row:hover {
  background: rgba(255, 255, 0, 0.06) !important;
}

.wp-row.even {
  background: rgba(255, 255, 255, 0.015);
}

.wp-row > div {
  text-align: center;
  padding: 6px 4px;
  overflow: hidden;
}

.col-n  { width: 42px; flex-shrink: 0; font-weight: 700; }
.col-km { width: 68px; flex-shrink: 0; }
.col-wp { flex: 1; min-width: 60px; display: flex; align-items: center; gap: 6px; justify-content: center; }
.col-pen { width: 80px; flex-shrink: 0; font-size: 0.6rem; color: var(--text-muted); }
.col-rad { width: 70px; flex-shrink: 0; font-size: 0.6rem; color: var(--text-muted); }
.col-act { width: 36px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }

/* ---- Waypoint type select ---- */
.wp-type-select {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 2px 4px;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  font-weight: 600;
  cursor: pointer;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  min-width: 48px;
  text-align: center;
}

.wp-type-select:focus {
  border-color: var(--accent);
}

.wp-type-select option {
  background: var(--bg-elevated);
  color: var(--text);
}

/* ---- Waypoint delete button ---- */
.wp-delete {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  padding: 0;
  line-height: 1;
}

.wp-delete:hover {
  background: rgba(255, 64, 64, 0.15);
  color: #FF4040;
  border-color: rgba(255, 64, 64, 0.3);
}

.km-pill {
  display: inline-block;
  background: rgba(0, 0, 0, 0.6);
  color: var(--accent);
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.fia-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1.5px solid rgba(0, 0, 0, 0.4);
  font-size: 0.55rem;
  font-weight: 700;
  font-family: var(--font-display);
  flex-shrink: 0;
}

.wp-name {
  font-size: 0.65rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 80px;
}

/* ---- Resize handle ---- */
.map-resize-handle {
  width: 5px;
  cursor: col-resize;
  background: rgba(255, 255, 255, 0.04);
  flex-shrink: 0;
  transition: background 0.15s;
}

.map-resize-handle:hover {
  background: var(--accent);
}

/* ---- Right panel ---- */
.map-panel-right {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ---- Map container wrapper ---- */
.map-container-wrap {
  flex: 1 1 0;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

.map-container {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
}

.leaflet-container {
  background: #111 !important;
}

/* ---- Map type switcher ---- */
.map-type-switcher {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 999;
  display: flex;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-btn);
  overflow: hidden;
}

.map-type-btn {
  padding: 6px 12px;
  background: transparent;
  color: var(--text-muted);
  border: none;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.map-type-btn:not(:last-child) {
  border-right: 1px solid var(--border);
}

.map-type-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
}

.map-type-btn.active {
  background: var(--accent);
  color: #000;
  font-weight: 700;
}

/* ---- Layer toggles ---- */
.map-layer-toggles {
  position: absolute;
  top: 50px;
  right: 12px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.map-layer-toggles[hidden] {
  display: none !important;
}

.map-layer-btn {
  padding: 5px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}

.map-layer-btn:hover {
  background: rgba(255, 255, 255, 0.08);
}

.map-layer-btn.active {
  background: var(--accent);
  color: #000;
  font-weight: 600;
  border-color: var(--accent);
}

/* ---- Measure tool ---- */
.map-measure-btn {
  position: absolute;
  bottom: 12px;
  right: 12px;
  z-index: 999;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.map-measure-btn:hover {
  background: rgba(255, 255, 255, 0.08);
}

.map-measure-btn.active {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
}

.measure-tooltip {
  position: absolute;
  bottom: 48px;
  right: 12px;
  z-index: 999;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 10px 14px;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text);
  line-height: 1.6;
  white-space: nowrap;
  pointer-events: auto;
}

.measure-tooltip[hidden] {
  display: none !important;
}

.measure-tooltip b {
  color: var(--accent);
}

.measure-tooltip .measure-label {
  color: var(--text-muted);
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ---- Chevron arrow style ---- */
.trace-chevron {
  pointer-events: none !important;
}

/* ---- Elevation profile ---- */
.elevation-profile {
  height: 160px;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  position: relative;
  flex-shrink: 0;
}

.elevation-profile canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.elevation-tooltip {
  position: absolute;
  top: 8px;
  pointer-events: none;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 4px 10px;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--text);
  line-height: 1.4;
  white-space: nowrap;
  transform: translateX(-50%);
  z-index: 10;
}

.elevation-tooltip b {
  color: var(--accent);
}

/* ---- Popup override ---- */
.rally-popup .leaflet-popup-content-wrapper {
  background: var(--bg-elevated);
  color: var(--accent);
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.rally-popup .leaflet-popup-content {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  line-height: 1.6;
  margin: 0.875rem;
  color: var(--text-muted);
}

.rally-popup .leaflet-popup-content b {
  color: var(--text);
}

.rally-popup .leaflet-popup-tip {
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  box-shadow: none;
}

.rally-popup .leaflet-popup-close-button {
  color: var(--text-muted);
  font-size: 18px;
  top: 6px;
  right: 8px;
}

.rally-popup .leaflet-popup-close-button:hover {
  color: var(--accent);
}

/* =========================================
   RESPONSIVE
   ========================================= */
@media (max-width: 768px) {
  .map-layout {
    flex-direction: column;
  }

  .map-panel-table {
    width: 100% !important;
    max-height: 35vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .map-resize-handle {
    display: none;
  }

  .map-panel-right {
    flex: 1;
    min-height: 0;
  }

  .map-container-wrap {
    flex: 1;
    min-height: 200px;
  }

  .elevation-profile {
    height: 120px;
  }

  .map-nav__stats {
    display: none;
  }

  .map-nav__lang {
    display: none;
  }

  .map-type-switcher {
    top: 8px;
    right: 8px;
  }

  .map-type-btn {
    padding: 5px 8px;
    font-size: 0.6rem;
  }

  .map-layer-toggles {
    top: 42px;
    right: 8px;
  }

  .map-layer-btn {
    padding: 4px 8px;
    font-size: 0.55rem;
  }

  .col-pen, .col-rad, .col-act {
    display: none;
  }
}

@media (max-width: 480px) {
  .map-nav__upload span {
    display: none;
  }

  .map-nav__upload::before {
    content: 'GPX';
  }
}
