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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: "Segoe UI", Tahoma, sans-serif;
  color: #0f172a;
  background: #f5f7fb;
}

body {
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  padding: 0.75rem 1rem;
  background: linear-gradient(120deg, #0f5faf, #0c8bc7);
  color: #f7fbff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}

.title {
  font-weight: 700;
  letter-spacing: 0.02em;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.weather-widget {
  position: relative;
}

.weather-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 140px;
}

.weather-summary {
  font-weight: 600;
  color: #0f5faf;
}

.weather-panel {
  position: absolute;
  right: 0;
  margin-top: 6px;
  background: #ffffff;
  color: #0f172a;
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.16);
  width: 240px;
  padding: 10px 12px;
  z-index: 900;
}

.weather-panel.hidden {
  display: none;
}

.weather-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  margin-bottom: 6px;
}

.weather-updated {
  font-size: 0.8rem;
  color: #475569;
}

.weather-forecast {
  display: grid;
  gap: 6px;
}

.weather-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 8px;
  background: #f5f7fb;
  border-radius: 8px;
}

.weather-label {
  font-weight: 600;
}

.weather-meta {
  font-size: 0.85rem;
  color: #475569;
}

.weather-error {
  color: #b91c1c;
  font-size: 0.9rem;
}

.topbar-btn {
  border: 1px solid rgba(255, 255, 255, 0.4);
  background: #f7fbff;
  color: #0f5faf;
  border-radius: 6px;
  padding: 6px 12px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.topbar-btn.icon-btn {
  padding: 6px;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.topbar-btn.icon-btn svg {
  width: 18px;
  height: 18px;
}

.topbar-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
}

.status {
  font-size: 0.9rem;
  opacity: 0.9;
}

.lang-select {
  border: 1px solid rgba(255, 255, 255, 0.4);
  background: rgba(255, 255, 255, 0.15);
  color: #f7fbff;
  border-radius: 6px;
  padding: 4px 8px;
  font: inherit;
  cursor: pointer;
}

.lang-select option {
  color: #0f172a;
}

.layout {
  flex: 1;
  display: flex;
  padding: 0.75rem;
}

#map {
  width: 100%;
  height: 100%;
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  overflow: hidden;
  position: relative;
}

.help-trigger {
  position: absolute;
  bottom: calc(var(--elevation-offset, 0px) + 72px);
  left: 16px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(12, 139, 199, 0.9);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18);
  z-index: 600;
}

.help-trigger:hover {
  background: rgba(12, 139, 199, 1);
}

.help-popup {
  position: fixed;
  bottom: calc(var(--elevation-offset, 0px) + 108px);
  left: 12px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid #e5e9f0;
  border-radius: 8px;
  padding: 10px 12px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
  font-size: 0.9rem;
  max-width: 260px;
  z-index: 650;
}

.hidden {
  display: none !important;
}
.error {
  color: #b00020;
}

.muted {
  color: #6b7280;
}

.km-label {
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid #e5e9f0;
  color: #0f172a;
  border-radius: 6px;
  padding: 1px 5px;
  font-size: 0.8rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.collapsible-panel {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.collapsible-panel .panel-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding: 4px 8px;
  border: none;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.collapsible-panel .panel-toggle-icon {
  font-weight: 700;
}

.collapsible-panel.collapsed .panel-body {
  display: none;
}

.legend-control {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid #e5e9f0;
  border-radius: 8px;
  padding: 6px 10px 10px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  font-size: 0.9rem;
}

.legend-body {
  display: grid;
  gap: 6px;
}

.legend-control .legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.legend-control .legend-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  border: none;
  background: transparent;
  cursor: pointer;
  font: inherit;
  color: inherit;
  border-radius: 6px;
}

.legend-control .legend-btn:hover {
  background: rgba(15, 95, 175, 0.08);
}

.legend-control .legend-dot {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid transparent;
}

.legend-control .legend-dot.live {
  background: #0c8bc7;
  border-color: #0c8bc7;
}

.legend-control .legend-dot.stale {
  background: #9ca3af;
  border-color: #6b7280;
}

.legend-control .legend-dot.selected {
  background: #f97316;
  border-color: #f97316;
}

.legend-control .legend-dot.you {
  background: #22c55e;
  border-color: #16a34a;
}

.legend-control .legend-btn.selected {
  background: rgba(12, 139, 199, 0.12);
}

.toggle-control {
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid #e5e9f0;
  border-radius: 8px;
  padding: 6px 10px 10px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  font-size: 0.9rem;
  min-width: 180px;
}

.toggle-body {
  display: grid;
  gap: 6px;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}

.history-inline-btn {
  margin-top: 6px;
  padding: 4px 8px;
  border: 1px solid #0c8bc7;
  background: #fff;
  color: #0c8bc7;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
}

.waypoint-label-icon {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
}

.waypoint-label-inner {
  background: rgba(255, 255, 255, 0.7);
  color: #0f172a;
  padding: 2px 6px;
  border-radius: 4px;
  white-space: nowrap;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.18);
  font-size: 0.9rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  width: auto !important;
  height: auto !important;
  margin: 0 !important;
  text-align: center;
}

.leaflet-div-icon {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
}
.waypoint-label-icon.hidden {
  display: none !important;
}

.context-menu {
  position: absolute;
  z-index: 1000;
  background: #ffffff;
  border: 1px solid #e5e9f0;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
  padding: 6px 0;
  min-width: 180px;
}

.context-menu.hidden {
  display: none;
}

.context-menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 12px;
  background: transparent;
  border: none;
  cursor: pointer;
  font: inherit;
  color: inherit;
}

.context-menu button:hover {
  background: rgba(15, 95, 175, 0.08);
}

.context-info {
  padding: 6px 12px;
  font-size: 0.9rem;
  color: #0f172a;
  border-bottom: 1px solid #e5e9f0;
}

.history-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1200;
  padding: 12px;
}

.history-modal {
  background: #fff;
  border-radius: 10px;
  width: min(720px, 100%);
  max-height: 80vh;
  overflow: auto;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.25);
  border: 1px solid #e5e9f0;
  padding: 16px;
}

.history-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.history-title-wrap {
  display: flex;
  flex-direction: row;
  gap: 6px;
  align-items: baseline;
}

.history-updated {
  font-size: 0.9rem;
  color: #4b5563;
}

.history-close {
  border: none;
  background: transparent;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  color: #0f172a;
}

.history-sections {
  display: grid;
  gap: 12px;
}

.history-section {
  border: 1px solid #e5e9f0;
  border-radius: 8px;
  padding: 10px;
  background: #f9fbff;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.history-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
  color: inherit;
  font: inherit;
}

.history-toggle {
  width: 10px;
  height: 10px;
  border-right: 2px solid #0f5faf;
  border-bottom: 2px solid #0f5faf;
  transform: rotate(45deg);
  transition: transform 120ms ease;
}

.history-label {
  font-weight: 700;
}

.history-row {
  padding: 4px 0;
  border-bottom: 1px solid #e5e9f0;
  font-size: 0.95rem;
}

.history-row.history-date {
  text-align: center;
  font-weight: 700;
}

.history-row:last-child {
  border-bottom: none;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.history-table th,
.history-table td {
  padding: 6px 8px;
  border-bottom: 1px solid #e5e9f0;
  text-align: left;
}

.history-table thead th {
  font-weight: 700;
  background: #f7fafc;
}

.history-table tr.history-date td {
  text-align: center;
  font-weight: 700;
  background: #eef2f7;
}

.history-table tbody tr:nth-child(odd):not(.history-date) {
  background: #f9fbff;
}

.history-table tbody tr:nth-child(even):not(.history-date) {
  background: #f3f7fc;
}

.history-empty {
  color: #6b7280;
  font-size: 0.95rem;
}

.history-section.collapsed .history-content {
  display: none;
}

.history-toggle.collapsed {
  transform: rotate(-45deg);
}

.elevation-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(15, 23, 42, 0.9);
  color: #e2e8f0;
  padding: 6px 10px;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.25);
  z-index: 1100;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: transform 180ms ease;
}

.elevation-bar.collapsed {
  transform: translateY(calc(100% - 40px));
}

.elevation-toggle {
  align-self: center;
  background: transparent;
  border: 1px solid rgba(226, 232, 240, 0.35);
  color: inherit;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
  font: inherit;
}

.elevation-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.elevation-chart {
  width: 100%;
  height: clamp(90px, 18vh, 160px);
}

.elevation-stats {
  position: absolute;
  top: 8px;
  right: 12px;
  font-size: 0.95rem;
  font-weight: 700;
  color: #f8fafc;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}

.elevation-grid-line {
  stroke: rgba(226, 232, 240, 0.35);
  stroke-width: 0.5;
}

.elevation-grid-label {
  fill: #e2e8f0;
  font-size: 10px;
  pointer-events: none;
}

.elevation-path {
  stroke: #38bdf8;
  stroke-width: 2;
  fill: none;
}

.elevation-progress-dot {
  fill: #fcd34d;
  stroke: #0f172a;
  stroke-width: 0.8;
}

.elevation-progress-label {
  fill: #f8fafc;
  font-size: 12px;
  font-weight: 700;
  paint-order: stroke;
  stroke: rgba(15, 23, 42, 0.7);
  stroke-width: 1px;
}

.elevation-stats-label {
  fill: #f8fafc;
  font-size: 12px;
  font-weight: 700;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

.elevation-empty {
  font-size: 0.9rem;
  color: #cbd5e1;
}

@media (max-width: 960px) {
  .layout {
    padding: 0.5rem;
    height: auto;
  }

  #map {
    min-height: 320px;
  }
}

@media (max-width: 640px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .weather-toggle {
    width: 100%;
  }

  .weather-panel {
    position: static;
    width: 100%;
    margin-top: 0;
  }
}

@media (max-width: 640px) {
  .elevation-stats {
    position: static;
    text-align: center;
    margin-top: -2px;
  }
}
