:root {
  color-scheme: light;
  --bg: #edf2f7;
  --ink: #1f2937;
  --ink-muted: #4b5563;
  --accent: #0b7285;
  --panel: #ffffff;
  --error: #b42318;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  min-height: 100%;
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  background: radial-gradient(circle at 20% 20%, #f8fbff, var(--bg));
  color: var(--ink);
}

.layout {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  min-height: 100dvh;
  gap: 8px;
  padding: 12px;
}

.topbar {
  background: var(--panel);
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: 0 6px 20px rgb(15 23 42 / 10%);
}

.topbar h1 {
  margin: 0 0 6px;
  font-size: clamp(1.1rem, 2.6vw, 1.5rem);
}

.topbar p {
  margin: 0;
  color: var(--ink-muted);
  line-height: 1.4;
}

.status {
  margin-top: 8px;
  font-weight: 600;
  color: var(--accent);
}

.status[data-error="1"] {
  color: var(--error);
}

.download-progress {
  margin-top: 8px;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
}

.download-progress[hidden] {
  display: none;
}

.download-progress-text {
  font-size: 0.88rem;
  color: var(--ink-muted);
  font-weight: 600;
  white-space: nowrap;
}

.download-progress[data-error="1"] .download-progress-text {
  color: var(--error);
}

#download-progress-bar {
  width: 180px;
  height: 10px;
  flex: 0 0 auto;
}

.tileset-button {
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #f8fafc;
  color: var(--ink);
  padding: 5px;
  font: inherit;
  cursor: pointer;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
}

.tileset-button:hover {
  border-color: #94a3b8;
}

.tileset-button-active {
  border-color: var(--accent);
  background: #b8dfe6;
  color: #0a3d49;
  box-shadow: 0 0 0 2px var(--accent);
}

.tileset-button-icon {
  width: 100%;
  height: 100%;
  display: block;
}

.map {
  flex: 1 1 auto;
  min-height: 0;
  border-radius: 12px;
  overflow: hidden;
  position: relative;
  box-shadow: 0 8px 24px rgb(15 23 42 / 10%);
}

.map-search-control {
  position: relative;
}

.map-search-button {
  background: rgb(255 255 255 / 93%);
}

.map-search-panel {
  position: absolute;
  top: 0;
  right: 46px;
  min-width: 260px;
  max-width: min(70vw, 360px);
  background: rgb(255 255 255 / 97%);
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgb(15 23 42 / 18%);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.map-search-panel[hidden] {
  display: none;
}

.map-search-input {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 6px 8px;
  font: inherit;
}

.map-search-results {
  margin: 0;
  padding: 0;
  list-style: none;
  max-height: 220px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.map-search-result {
  margin: 0;
  padding: 0;
  border-radius: 8px;
}

.map-search-result-button {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 8px;
  background: #f8fafc;
  color: #0f172a;
  padding: 6px 8px;
  text-align: left;
  cursor: pointer;
  font: inherit;
}

.map-search-result-button:hover {
  border-color: #94a3b8;
}

.map-search-result-active .map-search-result-button {
  background: #e6f4f7;
  border-color: var(--accent);
}

.map-toolbar-wrapper {
  position: relative;
}

.map-icon-rail {
  background: rgb(255 255 255 / 93%);
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  box-shadow: 0 6px 18px rgb(15 23 42 / 14%);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  transition:
    opacity 0.18s ease,
    transform 0.18s ease;
}

.map-toolbar-rail-hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateX(12px);
  position: absolute;
  top: 0;
  right: 0;
}

#map.map-pen-active,
#map.map-pen-active .leaflet-container,
#map.map-pen-active .leaflet-grab,
#map.map-pen-active .leaflet-interactive {
  cursor: crosshair;
}

#map.map-pen-active.map-pen-draggable-hover,
#map.map-pen-active.map-pen-draggable-hover .leaflet-container,
#map.map-pen-active.map-pen-draggable-hover .leaflet-grab,
#map.map-pen-active.map-pen-draggable-hover .leaflet-interactive {
  cursor: grab;
}

.map-icon-section {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.map-icon-section + .map-icon-section {
  padding-top: 5px;
  border-top: 1px solid #dbe3ed;
}

.map-icon-section-title {
  font-size: 0.58rem;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 700;
  text-align: center;
}

.map-icon-section-buttons {
  display: flex;
  flex-direction: column;
  gap: 5px;
  align-items: center;
}

.flight-log-window {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 950;
  width: 320px;
  height: 240px;
  min-width: 240px;
  min-height: 130px;
  max-width: calc(100% - 18px);
  max-height: calc(100% - 18px);
  background: rgb(255 255 255 / 97%);
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  box-shadow: 0 10px 24px rgb(15 23 42 / 22%);
  display: flex;
  flex-direction: column;
  overflow: auto;
  resize: both;
}

.flight-log-window-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid #dbe3ed;
  background: #f8fafc;
  cursor: move;
  user-select: none;
}

.flight-log-window-title {
  margin: 0;
  font-size: 0.8rem;
  font-weight: 700;
  color: #0f172a;
}

.flight-log-window-actions {
  display: flex;
  gap: 6px;
}

.flight-log-window-action {
  width: 24px;
  height: 24px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #fff;
  color: #1f2937;
  font: inherit;
  line-height: 1;
  cursor: pointer;
}

.flight-log-window-action:hover {
  border-color: #94a3b8;
}

.flight-log-window-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
}

.flight-log-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.75rem;
}

.flight-log-table th,
.flight-log-table td {
  border-bottom: 1px solid #e2e8f0;
  padding: 5px 8px;
  text-align: left;
  white-space: nowrap;
}

.flight-log-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f8fafc;
  color: #334155;
  font-weight: 700;
}

.flight-log-header-with-help {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.flight-log-help-icon {
  width: 14px;
  height: 14px;
  border: 1px solid #94a3b8;
  border-radius: 999px;
  background: #fff;
  color: #475569;
  font-size: 9px;
  line-height: 1;
  font-weight: 700;
  padding: 0;
  cursor: pointer;
}

.flight-log-help-bubble {
  position: fixed;
  z-index: 9999;
  min-width: 170px;
  max-width: 230px;
  background: #0f172a;
  color: #e2e8f0;
  border: 1px solid #334155;
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 0.66rem;
  font-weight: 500;
  white-space: normal;
  box-shadow: 0 8px 18px rgb(15 23 42 / 34%);
}

.flight-log-empty {
  color: #64748b;
  text-align: center;
  font-style: italic;
}

.flight-log-window-minimized {
  height: auto;
  min-height: 0;
  resize: none;
  overflow: hidden;
}

.flight-log-window-minimized .flight-log-window-body {
  display: none;
}

.aerodrome-label {
  background: rgb(15 23 42 / 78%);
  border: 1px solid rgb(226 232 240 / 82%);
  border-radius: 999px;
  box-shadow: 0 1px 4px rgb(15 23 42 / 28%);
  color: #fff;
  font-size: 0.66rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.02em;
  padding: 2px 5px;
  text-shadow: 0 1px 1px rgb(15 23 42 / 70%);
  pointer-events: auto;
  cursor: pointer;
  z-index: 900;
}

.pen-waypoint-label {
  pointer-events: none;
}

.map .aerodrome-marker-icon-cached {
  filter: hue-rotate(90deg);
}

.map .aerodrome-marker-icon-uncached {
  filter: hue-rotate(-35deg) saturate(1.25);
}

@media (max-width: 760px) {
  .layout {
    padding: 8px;
  }

  .map {
    border-radius: 10px;
  }

  .tileset-button {
    width: 36px;
    height: 36px;
    padding: 4px;
  }

  .flight-log-window {
    width: min(92vw, 360px);
    max-width: calc(100% - 10px);
    max-height: calc(100% - 10px);
  }
}

.leaflet-control-attribution {
  font-size: 0.6rem;
}
