/* Fullscreen History view */
body:has(#history:not(.hidden)) { overflow: hidden; }
body:has(#history:not(.hidden)) main { position: fixed; inset: 0; width: 100vw; height: 100dvh; margin: 0; padding: 0; overflow: hidden; }
body:has(#history:not(.hidden)) main > header { position: absolute; z-index: 11002; inset: 0 0 auto; height: 0; min-height: 0; padding: 0; border: 0; background: transparent; pointer-events: none; }
body:has(#history:not(.hidden)) main > header > * { pointer-events: auto; }
body:has(#history:not(.hidden)) main > header > div,
body:has(#history:not(.hidden)) #refresh { display: none !important; }
body:has(#history:not(.hidden)) #mobileMenuToggle { display: inline-grid; position: fixed; z-index: 11003; top: 14px; left: 14px; width: 46px; height: 46px; border: 1px solid rgb(255 255 255 / 25%); border-radius: 15px; background: #14243a; color: #fff; box-shadow: none; }
body:has(#history:not(.hidden)) #history { position: absolute; inset: 0; display: block; width: 100%; height: 100%; padding: 0; }
body:has(#history:not(.hidden)) #historyMap { position: absolute; z-index: 0; inset: 0; width: 100%; height: 100%; min-height: 0; border: 0; border-radius: 0; }

/* One high-contrast panel contains filters, actions and playback */
body:has(#history:not(.hidden)) .history-controls {
  position: absolute;
  z-index: 900;
  top: 14px;
  left: 50%;
  width: min(900px, calc(100vw - 120px));
  max-height: calc(100dvh - 28px);
  margin: 0;
  padding: 14px;
  overflow: auto;
  transform: translateX(-50%);
  border: 1px solid rgb(151 187 232 / 32%);
  border-radius: 18px;
  background: linear-gradient(145deg, rgb(25 47 73 / 97%), rgb(14 31 51 / 97%) 76%);
  color: #fff;
  box-shadow: 0 12px 30px rgb(5 15 30 / 30%);
  backdrop-filter: blur(10px);
  color-scheme: dark;
}
body:has(#history:not(.hidden)) .history-controls .filters {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: end;
  gap: 12px;
  margin: 0;
}
body:has(#history:not(.hidden)) .history-controls .filters label {
  display: grid;
  min-width: 0;
  gap: 7px;
  color: #e6eef9;
  font-size: 13px;
  font-weight: 650;
  line-height: 1.35;
}
body:has(#history:not(.hidden)) .history-controls .filters input,
body:has(#history:not(.hidden)) .history-controls .filters select {
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid #526b88;
  border-radius: 11px;
  background: #10243b;
  color: #fff;
  color-scheme: dark;
  font-size: 14px;
  transition: border-color .16s ease, box-shadow .16s ease, background-color .16s ease;
}
body:has(#history:not(.hidden)) .history-controls .filters input:hover,
body:has(#history:not(.hidden)) .history-controls .filters select:hover,
body:has(#history:not(.hidden)) .history-actions select:hover { border-color: #8aadd8; background-color: #142b46; }
body:has(#history:not(.hidden)) .history-controls .filters input:focus-visible,
body:has(#history:not(.hidden)) .history-controls .filters select:focus-visible,
body:has(#history:not(.hidden)) .history-actions select:focus-visible { outline: none; border-color: #80adff; box-shadow: 0 0 0 3px rgb(75 140 255 / 28%); }
body:has(#history:not(.hidden)) .history-controls input[type="datetime-local"]::-webkit-calendar-picker-indicator { cursor: pointer; filter: none; opacity: .95; }
body:has(#history:not(.hidden)) .history-controls input[type="datetime-local"] { accent-color: #78a8ff; }
body:has(#history:not(.hidden)) .history-actions {
  display: flex;
  width: min(100%, 560px);
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin: 10px auto 0;
}
body:has(#history:not(.hidden)) .history-actions #loadHistory {
  width: 128px;
  min-width: 128px;
  min-height: 42px;
  padding: 7px 12px;
  border-radius: 11px;
  font-size: 13px;
}
body:has(#history:not(.hidden)) .history-actions #playHistory {
  display: flex;
  width: 142px;
  min-width: 142px;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 7px 12px;
  border-radius: 12px;
}
body:has(#history:not(.hidden)) .history-actions #playHistory svg { width: 20px; height: 20px; fill: currentColor; }
body:has(#history:not(.hidden)) .history-actions #playHistory { border: 1px solid #6886aa; background: #1a3554; color: #f8fafc; box-shadow: none; }
body:has(#history:not(.hidden)) .history-actions #playHistory:hover:not(:disabled) { border-color: #91b8ed; background: #24466d; }
body:has(#history:not(.hidden)) .history-actions #playHistory:disabled { border-color: #60748e; background: #263b55; color: #d7e2f0; opacity: 1; }
body:has(#history:not(.hidden)) .history-actions label {
  display: flex;
  min-width: 170px;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: #f8fafc;
  font-size: 13px;
  font-weight: 650;
  white-space: nowrap;
}
body:has(#history:not(.hidden)) .history-actions select {
  flex: 0 0 92px;
  width: 92px;
  min-width: 92px;
  min-height: 46px;
  padding: 7px 22px 7px 8px;
  border: 1px solid #526b88;
  border-radius: 11px;
  background: #10243b;
  color: #fff;
  color-scheme: dark;
  font-size: 13px;
  transition: border-color .16s ease, box-shadow .16s ease, background-color .16s ease;
}
body:has(#history:not(.hidden)) .history-actions button { transition: transform .14s ease, border-color .16s ease, background-color .16s ease, box-shadow .16s ease; }
body:has(#history:not(.hidden)) .history-actions button:active:not(:disabled) { transform: translateY(1px); }
body:has(#history:not(.hidden)) .history-actions button:focus-visible { outline: 3px solid rgb(128 173 255 / 72%); outline-offset: 2px; }
body:has(#history:not(.hidden)) .history-playback {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  margin: 8px 0 0;
}
body:has(#history:not(.hidden)) .history-playback input[type="range"] { width: 100%; min-width: 0; height: 30px; margin: 0; accent-color: #7db1ff; cursor: pointer; }
body:has(#history:not(.hidden)) .history-playback input[type="range"]:focus-visible { outline: 2px solid #80adff; outline-offset: 3px; border-radius: 8px; }
body:has(#history:not(.hidden)) #historyStepLabel { min-width: 0; color: #f1f5f9; font-size: 11px; white-space: nowrap; }
body:has(#history:not(.hidden)) #historyStepLabel:empty,
body:has(#history:not(.hidden)) #historyInfo:empty { display: none; }
body:has(#history:not(.hidden)) #historyInfo { margin: 7px 0 0; color: #f1f5f9; font-size: 11px; line-height: 1.4; }

/* Reuse the compact slide-out menu without covering the map with a shadow */
body:has(#history:not(.hidden)) #sidebar {
  display: flex !important;
  z-index: 11001;
  width: var(--mobile-drawer-width);
  transform: translateX(-105%);
  visibility: hidden;
  transition: transform .22s ease, visibility .22s;
  background: #101c2d;
  box-shadow: none;
}
body:has(#history:not(.hidden)).mobile-menu-open #sidebar { transform: translateX(0); visibility: visible; }
body:has(#history:not(.hidden)) #sidebar .brand { position: relative; padding-right: 42px; }
body:has(#history:not(.hidden)) #mapMenuClose {
  display: none;
  position: absolute;
  top: 0;
  right: 0;
  width: 44px;
  height: 44px;
  min-height: 44px;
  place-items: center;
  padding: 0;
  border: 1px solid #ffffff35;
  border-radius: 12px;
  background: #1a2a40;
  color: #fff;
  box-shadow: none;
  font-size: 24px;
  line-height: 1;
}
body:has(#history:not(.hidden)).mobile-menu-open #mapMenuClose { display: grid; }
body:has(#history:not(.hidden)) .mobile-menu-backdrop { position: fixed; z-index: 11000; inset: 0; display: none; background: transparent; box-shadow: none; }
body:has(#history:not(.hidden)).mobile-menu-open .mobile-menu-backdrop { display: block; background: transparent; }

@media (max-width: 700px) {
  body:has(#history:not(.hidden)) #mobileMenuToggle { top: calc(10px + env(safe-area-inset-top)); left: 10px; width: 44px; height: 44px; }
  body:has(#history:not(.hidden)) .history-controls {
    top: auto;
    right: 10px;
    bottom: calc(10px + env(safe-area-inset-bottom));
    left: 10px;
    width: auto;
    max-height: min(55dvh, 380px);
    padding: 11px;
    transform: none;
    border-radius: 16px;
  }
  body:has(#history:not(.hidden)) .history-controls .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  body:has(#history:not(.hidden)) .history-controls .filters label:first-child { grid-column: 1 / -1; }
  body:has(#history:not(.hidden)) .history-controls .filters label { gap: 5px; font-size: 12px; }
  body:has(#history:not(.hidden)) .history-controls .filters input,
  body:has(#history:not(.hidden)) .history-controls .filters select { min-height: 44px; padding: 8px; font-size: 12px; }
  body:has(#history:not(.hidden)) .history-actions { width: 100%; gap: 12px; }
  body:has(#history:not(.hidden)) .history-actions #loadHistory { width: 90px; min-width: 90px; min-height: 44px; padding: 7px 8px; font-size: 11px; }
  body:has(#history:not(.hidden)) .history-actions #playHistory { display: inline-grid; width: 44px; min-width: 44px; height: 44px; min-height: 44px; place-items: center; padding: 0; }
  body:has(#history:not(.hidden)) .history-actions .history-play-text,
  body:has(#history:not(.hidden)) .history-speed > span { display: none; }
  body:has(#history:not(.hidden)) .history-actions label { min-width: 88px; }
  body:has(#history:not(.hidden)) .history-actions select { flex-basis: 88px; width: 88px; min-width: 88px; min-height: 44px; padding: 6px 20px 6px 7px; font-size: 11px; }
  body:has(#history:not(.hidden)) .history-playback { grid-template-columns: minmax(0, 1fr) auto; }
  body:has(#history:not(.hidden)) #sidebar { padding-top: calc(18px + env(safe-area-inset-top)); }
}
@media (max-width: 380px) {
  body:has(#history:not(.hidden)) .history-controls { padding: 9px; }
  body:has(#history:not(.hidden)) .history-controls .filters { gap: 7px; }
  body:has(#history:not(.hidden)) .history-controls .filters label,
  body:has(#history:not(.hidden)) #historyInfo { font-size: 11px; }
  body:has(#history:not(.hidden)) .history-controls .filters input,
  body:has(#history:not(.hidden)) .history-controls .filters select { padding: 6px; font-size: 11px; }
}
