.map-page,
.history-map-page {
  --history-ink: #172033;
  --history-muted: #637083;
  --history-line: #d9e1eb;
  --history-panel: rgba(255, 255, 255, .94);
  --history-accent: #2563eb;
  --history-current: #e11d48;
}

.history-panel--overlay {
  position: absolute;
  z-index: 460;
  left: 16px;
  top: 72px;
  width: min(430px, calc(100% - 32px));
  max-height: calc(100% - 156px);
  overflow: auto;
  border: 1px solid var(--history-line);
  border-radius: 8px;
  background: var(--history-panel);
  box-shadow: 0 14px 38px rgba(15, 23, 42, .16);
  backdrop-filter: blur(7px);
}

.history-panel--overlay.is-dragging {
  user-select: none;
}

.history-panel--overlay[hidden],
.history-toolbar--timeline[hidden] {
  display: none;
}

.history-panel-main {
  padding: 12px 12px 10px;
}

.history-kicker {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--history-muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.history-drag-handle {
  cursor: move;
  touch-action: none;
}

.history-close-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  flex: 0 0 auto;
  border: 1px solid var(--history-line);
  border-radius: 8px;
  background: #fff;
  color: var(--history-muted);
  font: inherit;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}

.history-close-button:hover,
.history-close-button:focus-visible {
  border-color: #b8cdfb;
  color: #1d4ed8;
  background: #f8fbff;
}

.history-title {
  margin: 7px 0 0;
  font-size: 15px;
  line-height: 1.25;
}

.history-event-title {
  margin: 10px 0 0;
  color: var(--history-ink);
  font-size: 13px;
  font-weight: 800;
}

.history-event-text {
  margin: 5px 0 0;
  color: #263247;
  font-size: 12px;
  line-height: 1.45;
}

.history-event-media {
  position: relative;
  margin: 10px 0 0;
  overflow: hidden;
  border: 1px solid var(--history-line);
  border-radius: 8px;
  background: #eef3f8;
}

.history-event-media[hidden],
.history-plant-links[hidden],
.history-plant-link[hidden],
.history-marker-index[hidden] {
  display: none;
}

.history-event-media img {
  display: block;
  width: 100%;
  max-height: 150px;
  object-fit: cover;
}

.history-event-media.is-cropped img {
  position: absolute;
  inset: 0 auto auto 0;
  width: auto;
  max-width: none;
  height: auto;
  max-height: none;
  object-fit: initial;
  transform-origin: 0 0;
}

.history-plant-links {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 9px;
}

.history-plant-link {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border: 1px solid #b8cdfb;
  border-radius: 8px;
  padding: 5px 8px;
  background: #eaf1ff;
  color: #1d4ed8;
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
}

.history-progress {
  width: calc(100% - 24px);
  height: 7px;
  margin: 0 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8eef6;
}

.history-progress-bar {
  width: 0%;
  height: 100%;
  background: var(--history-accent);
  transition: width .22s ease;
}

.history-panel-controls {
  display: grid;
  grid-template-columns: 38px 1fr 38px;
  gap: 8px;
  padding: 10px 12px 8px;
}

.history-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  border: 1px solid var(--history-line);
  border-radius: 8px;
  padding: 6px 10px;
  background: #fff;
  color: var(--history-ink);
  font: inherit;
  font-size: 12px;
  text-decoration: none;
  cursor: pointer;
}

.history-button.primary {
  border-color: #b8cdfb;
  background: #eaf1ff;
  color: #1d4ed8;
  font-weight: 800;
}

.history-button:disabled {
  cursor: not-allowed;
  opacity: .55;
}

.history-year-pill {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  border: 1px solid #4fc3f7;
  border-radius: 8px;
  background: linear-gradient(135deg, #174e80 0%, #2563eb 100%);
  color: #fff;
  font-size: 14px;
  font-weight: 900;
}

.history-arrow-button {
  width: 38px;
  min-height: 36px;
  padding: 0;
  font-size: 18px;
}

.history-toolbar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 0 12px 10px;
}

.history-toolbar--timeline {
  grid-template-columns: minmax(46px, 1fr) minmax(52px, 1fr) minmax(52px, 20%);
  align-items: center;
  padding: 10px 0 0;
}

.history-toolbar--timeline .history-button {
  min-height: 32px;
  padding-inline: 8px;
}

.history-playback-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  min-width: 0;
}

.history-playback-group .history-button:not([hidden]) {
  display: inline-flex;
}

.history-playback-group .history-button[hidden] {
  display: none;
}

.history-playback-group #playPauseBtn:not([hidden]) {
  grid-column: 1 / -1;
}

.history-speed-control {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px;
  align-items: center;
  gap: 5px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  justify-self: end;
}

.history-speed-slider {
  width: 100%;
  min-width: 0;
  accent-color: var(--history-accent);
}

.history-speed-value {
  color: var(--history-muted);
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.history-status {
  padding: 0 12px 12px;
  color: var(--history-muted);
  font-size: 11px;
}

.history-event-list {
  display: grid;
  gap: 6px;
  max-height: 230px;
  overflow: auto;
  padding: 0 12px 12px;
}

.history-event-jump {
  position: relative;
  display: grid;
  grid-template-columns: 24px 44px 1fr 22px;
  gap: 6px;
  width: 100%;
  border: 1px solid var(--history-line);
  border-radius: 8px;
  padding: 7px 7px 8px;
  background: #fff;
  color: var(--history-ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.history-event-jump:hover {
  border-color: #b8cdfb;
  background: #f8fbff;
}

.history-event-jump.is-current {
  border-color: #93b4f7;
  background: #eaf1ff;
  box-shadow: inset 3px 0 0 var(--history-accent);
}

.history-event-jump-index {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  align-self: center;
  border-radius: 999px;
  background: #eaf1ff;
  color: #1d4ed8;
  font-size: 11px;
  font-weight: 900;
  opacity: 0;
  transform: scale(.86);
  transition: opacity .18s ease, transform .18s ease;
}

.history-event-jump.is-reached .history-event-jump-index {
  opacity: 1;
  transform: scale(1);
}

.history-event-jump.is-current .history-event-jump-index {
  background: var(--history-accent);
  color: #fff;
}

.history-event-jump-year {
  color: var(--history-accent);
  font-size: 11px;
  font-weight: 800;
}

.history-event-jump-main {
  min-width: 0;
}

.history-event-jump-title {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 700;
}

.history-event-ok {
  display: grid;
  width: 20px;
  height: 20px;
  place-items: center;
  align-self: center;
  color: #0f766e;
  font-size: 14px;
  font-weight: 900;
  opacity: 0;
  transform: scale(.82);
  transition: opacity .18s ease, transform .18s ease;
}

.history-event-ok svg {
  display: block;
  width: 20px;
  height: 20px;
}

.history-event-jump.is-reached .history-event-ok {
  opacity: 1;
  transform: scale(1);
}

.history-event-row-timer {
  grid-column: 1 / -1;
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  border: 1px solid rgba(37, 99, 235, .18);
  background: #cbd8ea;
  opacity: 0;
  margin-top: 2px;
}

.history-event-jump.is-current .history-event-row-timer {
  opacity: 1;
}

.history-event-row-timer-bar {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #e11d48, #f59e0b);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .35) inset, 0 0 12px rgba(225, 29, 72, .35);
  transition: width linear;
}

.history-marker-wrap {
  position: relative;
  width: 44px;
  height: 30px;
}

.history-current-marker {
  position: absolute;
  left: 0;
  top: 4px;
  width: 22px;
  height: 22px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: var(--history-current);
  box-shadow: 0 0 0 4px rgba(225, 29, 72, .25), 0 8px 18px rgba(15, 23, 42, .3);
}

.history-event-marker {
  position: absolute;
  left: 4px;
  top: 8px;
  width: 14px;
  height: 14px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--history-accent);
  box-shadow: 0 3px 10px rgba(15, 23, 42, .24);
}

.history-marker-index {
  position: absolute;
  left: 18px;
  top: 0;
  min-width: 22px;
  height: 20px;
  border: 1px solid rgba(37, 99, 235, .35);
  border-radius: 999px;
  padding: 0 5px;
  background: rgba(255, 255, 255, .96);
  color: #1d4ed8;
  font-size: 11px;
  font-weight: 900;
  line-height: 18px;
  text-align: center;
  box-shadow: 0 4px 10px rgba(15, 23, 42, .18);
}

.history-marker-wrap.is-active .history-marker-index {
  border-color: rgba(225, 29, 72, .45);
  color: var(--history-current);
}

.history-next-arrow {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid #b8cdfb;
  background: rgba(255, 255, 255, .94);
  color: var(--history-accent);
  font-size: 20px;
  font-weight: 900;
  box-shadow: 0 5px 12px rgba(15, 23, 42, .18);
}

.history-route-active {
  filter: drop-shadow(0 2px 4px rgba(37, 99, 235, .22));
}

.history-route-dash {
  animation: historyRouteDash 1.15s linear infinite;
  stroke-dasharray: 10 10;
}

.history-route-pulse {
  animation: historyRoutePulse 1.5s ease-in-out infinite;
}

.history-route-comet {
  opacity: .42;
}

.history-route-comet-dot {
  width: 14px;
  height: 14px;
  border: 3px solid rgba(255, 255, 255, .96);
  border-radius: 50%;
  background: var(--history-accent);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, .22), 0 6px 14px rgba(15, 23, 42, .28);
}

.history-route-pulse-dot {
  width: 18px;
  height: 18px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: #f59e0b;
  box-shadow: 0 0 0 0 rgba(245, 158, 11, .45), 0 7px 16px rgba(15, 23, 42, .25);
  animation: historyTargetPulse 1.4s ease-out infinite;
}

@keyframes historyRouteDash {
  to {
    stroke-dashoffset: -20;
  }
}

@keyframes historyRoutePulse {
  0%,
  100% {
    opacity: .55;
    stroke-width: 4;
  }

  50% {
    opacity: 1;
    stroke-width: 7;
  }
}

@keyframes historyTargetPulse {
  70% {
    box-shadow: 0 0 0 14px rgba(245, 158, 11, 0), 0 7px 16px rgba(15, 23, 42, .25);
  }

  100% {
    box-shadow: 0 0 0 0 rgba(245, 158, 11, 0), 0 7px 16px rgba(15, 23, 42, .25);
  }
}

@media (prefers-reduced-motion: reduce) {
  .history-route-dash,
  .history-route-pulse,
  .history-route-pulse-dot {
    animation: none;
  }
}

.history-popup {
  min-width: 230px;
  max-width: 310px;
}

.history-popup h2 {
  margin: 0 0 6px;
  font-size: 16px;
  line-height: 1.2;
}

.history-popup p {
  margin: 0;
  color: #2b3548;
  font-size: 13px;
  line-height: 1.42;
}

.history-popup-meta {
  margin-top: 8px;
  color: var(--history-muted);
  font-size: 12px;
}

.history-popup-controls {
  display: grid;
  grid-template-columns: 38px 1fr 38px;
  gap: 7px;
  margin-top: 10px;
}

.history-popup-controls button {
  min-height: 34px;
  border: 1px solid var(--history-line);
  border-radius: 8px;
  background: #fff;
  color: var(--history-ink);
  font: inherit;
  cursor: pointer;
}

.history-popup-controls .history-popup-step {
  font-weight: 700;
  color: var(--history-muted);
  cursor: default;
}

.leaflet-popup-content-wrapper {
  border-radius: 8px;
}

@media (max-width: 700px) {
  .history-panel--overlay {
    left: 10px;
    right: 10px;
    top: 68px;
    width: auto;
    max-height: calc(100% - 170px);
  }
}
