* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #14161a;
}

#map {
  position: absolute;
  inset: 0;
}

/* A translucent scrim over the map while the initial site data fetch and
   first map "load" are in flight. Hidden by default -- app.js only adds
   is-visible if loading is still going after 500ms, so a fast load (the
   common case; see README's Portability/perf notes) never shows this at
   all, and it's not fighting a fade-in/fade-out flash on every page view.
   Deliberately see-through rather than an opaque cover: the map/sidebar/
   markers should be visible filling in underneath as they become ready,
   with the spinner just signaling "still settling", not hiding that
   progress. */
#loadingOverlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(20, 22, 26, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease;
}

#loadingOverlay.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid #383e47;
  border-top-color: #ff5a3c;
  border-radius: 50%;
  animation: spinner-rotate 800ms linear infinite;
}

@keyframes spinner-rotate {
  to {
    transform: rotate(360deg);
  }
}

.zoom-controls {
  display: flex;
  flex-direction: row;
  align-items: center;
  margin: 10px 0 4px;
}

.zoom-controls button {
  width: 36px;
  background: #2a2e35;
  border: 1px solid #40454e;
  border-right: none;
  color: #f2f2f2;
  font-size: 18px;
  line-height: 1;
  font-family: inherit;
  padding: 8px 0;
  cursor: pointer;
}

.zoom-controls button:first-child {
  border-radius: 6px 0 0 6px;
}

.zoom-controls button:last-child {
  border-radius: 0 6px 6px 0;
  border-right: 1px solid #40454e;
}

.zoom-controls button:hover {
  background: #383e47;
}

.zoom-controls button:active {
  background: #22262d;
}

.hamburger-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #2a2e35;
  border: 1px solid #40454e;
  border-radius: 6px;
  color: #f2f2f2;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}

.hamburger-btn:hover {
  background: #383e47;
}

.hamburger-btn[aria-expanded="true"] {
  background: #383e47;
  border-color: #5c636f;
}

.sign-in-btn {
  display: inline-flex;
  align-items: center;
  height: 36px;
  padding: 0 12px;
  background: #2a2e35;
  border: 1px solid #40454e;
  border-radius: 6px;
  color: #f2f2f2;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
}

.sign-in-btn:hover {
  background: #383e47;
}

.terrain-content .sign-in-btn {
  display: flex;
  width: 100%;
  justify-content: center;
  box-sizing: border-box;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border: none;
  border-bottom: 1px solid #2a2e35;
  border-radius: 0;
  background: none;
}

.terrain-content .sign-in-btn:hover {
  background: none;
  text-decoration: underline;
}

/* Opens inline between the header and the search box, pushing the search
   box and site list below it down the panel instead of floating over
   them -- so it needs no anchor positioning of its own. */
.terrain-content {
  margin-top: 12px;
  background: rgba(20, 22, 26, 0.97);
  border: 1px solid #40454e;
  border-radius: 10px;
  padding: 14px 16px;
}

.terrain-content[hidden] {
  display: none;
}

.terrain-content label {
  display: block;
  margin: 10px 0 4px;
  font-size: 12.5px;
  color: #cfd3d9;
}

.terrain-content label:first-child {
  margin-top: 0;
}

.terrain-content input[type="range"] {
  width: 100%;
}

#panel {
  position: absolute;
  top: 16px;
  left: 16px;
  bottom: 16px;
  z-index: 10;
  width: 320px;
  background: rgba(20, 22, 26, 0.92);
  color: #f2f2f2;
  border-radius: 10px;
  font-size: 13px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: max-height 0.25s ease;
}

.panel-handle {
  display: none;
}

/* --- Bottom sheet: below this width #panel docks to the bottom edge and
   collapses/expands (via #panelHandle) instead of sitting fixed beside a
   map that's too narrow to share space with a 320px sidebar. --- */
@media (max-width: 700px) {
  #panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    max-height: 33vh;
    border-radius: 16px 16px 0 0;
  }

  #panel.sheet-collapsed {
    max-height: 64px;
  }

  .panel-handle {
    display: flex;
    justify-content: center;
    align-items: center;
    flex: 0 0 auto;
    padding: 10px 0 4px;
    touch-action: none;
    cursor: grab;
  }

  .panel-handle::before {
    content: "";
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: #4a505a;
  }

  /* Taken out of #panel's flow entirely (fixed positioning does that) so
     the logo and zoom controls stay reachable regardless of whether the
     sheet below is collapsed, expanded, or scrolled to some other view. */
  .panel-topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10;
    background: rgba(20, 22, 26, 0.92);
    border-radius: 0 0 10px 10px;
    padding: 12px 16px;
  }
}

.panel-topbar {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  padding: 16px 18px 8px;
}

.panel-topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel-topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-search {
  position: relative;
  margin-top: 10px;
}

.topbar-search input {
  width: 100%;
  padding: 7px 10px;
  border-radius: 6px;
  border: 1px solid #40454e;
  background: #1c1f25;
  color: #f2f2f2;
  font-size: 12.5px;
}

.place-suggestions {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 20;
  max-height: 240px;
  overflow-y: auto;
  background: rgba(20, 22, 26, 0.97);
  border: 1px solid #40454e;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.place-suggestions[hidden] {
  display: none;
}

.place-suggestion {
  padding: 8px 10px;
  font-size: 12.5px;
  color: #f2f2f2;
  cursor: pointer;
}

.place-suggestion:hover,
.place-suggestion.active {
  background: #2a2e35;
}

.panel-topbar .zoom-controls {
  margin: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-logo {
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
}

#panel h1 {
  margin: 0 0 2px;
  font-size: 18px;
}

#panel .sub {
  margin: 0 0 14px;
  color: #9aa1ab;
  font-size: 12px;
}

.buttons {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.buttons button {
  flex: 1 1 auto;
  background: #2a2e35;
  color: #f2f2f2;
  border: 1px solid #40454e;
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 12.5px;
  cursor: pointer;
}

.buttons button:hover {
  background: #383e47;
}

/* --- Sites list, merged into the same left panel as the map controls --- */

#sitesListView,
#siteDetailView,
#airspaceListView,
#accessView,
#siteForm {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}

#sitesListView[hidden],
#siteDetailView[hidden],
#airspaceListView[hidden],
#accessView[hidden],
#siteForm[hidden] {
  display: none;
}

#airspaceEntries {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 0 8px 12px;
  scrollbar-width: thin;
  scrollbar-color: #4a505a #1c1f25;
}

.airspace-entry-class {
  color: #9aa1ab;
  font-weight: 400;
}

.sites-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 8px;
  flex: 0 0 auto;
}

.sites-header h2 {
  margin: 0;
  font-size: 16px;
}

.link-btn {
  background: none;
  border: none;
  color: #7fb3ff;
  font-size: 12.5px;
  cursor: pointer;
  padding: 4px;
}

.link-btn:hover {
  text-decoration: underline;
}

#addSiteBtn {
  background: #ff5a3c;
  color: #14161a;
  border: none;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}

#addSiteBtn:hover {
  background: #ff7355;
}

.list-filters {
  display: flex;
  gap: 6px;
  margin: 0 0 12px;
}

#siteSearch {
  flex: 1 1 auto;
  min-width: 0;
  padding: 7px 10px;
  border-radius: 6px;
  border: 1px solid #40454e;
  background: #1c1f25;
  color: #f2f2f2;
  font-size: 12.5px;
}

#areaFilter {
  flex: 0 0 auto;
  max-width: 40%;
  padding: 7px 8px;
  border-radius: 6px;
  border: 1px solid #40454e;
  background: #1c1f25;
  color: #f2f2f2;
  font-size: 12.5px;
}

#siteList {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 0 8px 12px;
  scrollbar-width: thin;
  scrollbar-color: #4a505a #1c1f25;
}

#siteList::-webkit-scrollbar {
  width: 8px;
}

#siteList::-webkit-scrollbar-track {
  background: #1c1f25;
}

#siteList::-webkit-scrollbar-thumb {
  background: #4a505a;
  border-radius: 4px;
}

#siteList::-webkit-scrollbar-thumb:hover {
  background: #5c636f;
}

.site-item {
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 2px;
}

.site-item:hover {
  background: #262a31;
}

.site-item.airspace-pinned {
  background: #2f3542;
  box-shadow: inset 3px 0 0 #ffffff;
}

.site-item .site-name {
  font-size: 13px;
  font-weight: 600;
}

.site-item .site-area {
  font-size: 11.5px;
  color: #9aa1ab;
}

#siteDetailContent,
#siteForm,
#accessView {
  overflow-y: auto;
  padding: 0 16px 16px;
}

#siteDetailContent h3 {
  margin: 0 0 2px;
  font-size: 16px;
}

#siteDetailContent .site-area {
  color: #9aa1ab;
  font-size: 12px;
  margin-bottom: 10px;
}

#siteDetailContent .section-label,
#siteForm .section-label,
#accessView .section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #7f8791;
  margin: 12px 0 4px;
}

#siteDetailContent .rich {
  font-size: 12.5px;
  line-height: 1.5;
}

#siteDetailContent .rich p {
  margin: 0 0 6px;
}

#siteDetailContent .stat-row {
  display: flex;
  gap: 16px;
  font-size: 12.5px;
  color: #cfd3d9;
}

/* Read-only gallery (site detail view, both dynamic and static modes):
   photos as an image grid, PDFs/GPX tracks as a separate named-link list
   underneath -- a thumbnail grid doesn't carry a file-type link well. */
.media-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}

.media-thumb {
  position: relative;
  width: 84px;
  height: 84px;
  border-radius: 6px;
  overflow: hidden;
  background: #1c1f25;
  display: block;
}

.media-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.media-file-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 6px;
}

.media-file-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 6px;
  background: #1c1f25;
  color: inherit;
  text-decoration: none;
}

.media-file-kind {
  flex: 0 0 auto;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: #ff5a36;
}

.media-file-title {
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.media-file-desc {
  flex: 1 1 auto;
  font-size: 11.5px;
  color: #9aa1ab;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Editable media manager (site edit form, dynamic mode only). */
.media-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 6px;
}

.media-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.media-row-thumb {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border-radius: 6px;
  overflow: hidden;
  background: #1c1f25;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: #9aa1ab;
}

.media-row-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.media-row-body {
  flex: 1 1 auto;
  min-width: 0;
}

.media-row-title {
  font-size: 11.5px;
  color: #cfd3d9;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.media-row-body input[type="text"] {
  width: 100%;
  margin-top: 3px;
  padding: 5px 8px;
  border-radius: 5px;
  border: 1px solid #40454e;
  background: #1c1f25;
  color: #f2f2f2;
  font-size: 11.5px;
}

.media-row-remove {
  flex: 0 0 auto;
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  border: none;
  border-radius: 4px;
  width: 22px;
  height: 22px;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
}

#siteForm label,
#accessView label {
  display: block;
  margin: 10px 0 4px;
  font-size: 12px;
  color: #cfd3d9;
}

#siteForm input[type="text"],
#siteForm input[type="number"],
#accessView input[type="email"],
#accessView input[type="text"] {
  width: 100%;
  padding: 7px 10px;
  border-radius: 6px;
  border: 1px solid #40454e;
  background: #1c1f25;
  color: #f2f2f2;
  font-size: 12.5px;
  font-family: inherit;
}

/* Quill defaults to a light theme -- retint it to match the rest of the
   dark form instead of leaving a bright white box in the middle of it. */
.rte {
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid #40454e;
}

.rte .ql-toolbar.ql-snow {
  border: none;
  border-bottom: 1px solid #40454e;
  background: #22262d;
}

.rte .ql-toolbar.ql-snow.rte-toolbar-hidden {
  display: none;
}

.rte .ql-toolbar.ql-snow .ql-stroke {
  stroke: #cfd3d9;
}

.rte .ql-toolbar.ql-snow .ql-fill {
  fill: #cfd3d9;
}

.rte .ql-toolbar.ql-snow .ql-picker-label {
  color: #cfd3d9;
}

.rte .ql-toolbar.ql-snow button:hover .ql-stroke,
.rte .ql-toolbar.ql-snow button.ql-active .ql-stroke {
  stroke: #ff5a3c;
}

.rte .ql-toolbar.ql-snow button:hover .ql-fill,
.rte .ql-toolbar.ql-snow button.ql-active .ql-fill {
  fill: #ff5a3c;
}

.rte .ql-container.ql-snow {
  border: none;
  background: #1c1f25;
  color: #f2f2f2;
  font-size: 12.5px;
  font-family: inherit;
}

.rte .ql-editor {
  min-height: 70px;
}

.rte .ql-editor.ql-blank::before {
  color: #6b7178;
  font-style: normal;
}

.rte .ql-snow .ql-picker-options {
  background: #22262d;
  border: 1px solid #40454e;
}

.rte .ql-snow .ql-picker-item {
  color: #cfd3d9;
}

#siteForm .field-row {
  display: flex;
  gap: 10px;
}

#siteForm .field-row > div {
  flex: 1;
}

#siteForm .hint,
#accessView .hint {
  font-size: 11px;
  color: #9aa1ab;
  margin: 8px 0 4px;
}

/* --- Access management (invite links, allowlist) --- */

#inviteForm button {
  width: 100%;
  background: #ff5a3c;
  color: #14161a;
  font-weight: 600;
  border: none;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 12.5px;
  cursor: pointer;
  margin-top: 8px;
}

.invite-link-row {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

.invite-link-row input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid #40454e;
  background: #1c1f25;
  color: #cfd3d9;
  font-size: 11.5px;
}

.invite-link-row button {
  background: #2a2e35;
  color: #f2f2f2;
  border: 1px solid #40454e;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
}

.access-entry {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 2px;
  border-bottom: 1px solid #262a31;
  font-size: 12.5px;
}

.access-entry:last-child {
  border-bottom: none;
}

.access-entry-email {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.access-entry-meta {
  font-size: 10.5px;
  color: #7f8791;
}

.access-entry button {
  flex: 0 0 auto;
  background: #3a2226;
  color: #ff8a7a;
  border: 1px solid #5a2f34;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 11px;
  cursor: pointer;
}

.access-empty {
  font-size: 12px;
  color: #7f8791;
  padding: 4px 2px;
}

#siteForm #useCurrentViewBtn,
#siteForm #pickPinBtn {
  width: 100%;
  background: #2a2e35;
  color: #f2f2f2;
  border: 1px solid #40454e;
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 12.5px;
  cursor: pointer;
  margin-top: 8px;
}

#siteForm #pickPinBtn.active {
  background: #ff5a3c;
  color: #14161a;
  border-color: #ff5a3c;
  font-weight: 600;
}

#saveSiteBtn {
  background: #ff5a3c;
  color: #14161a;
  font-weight: 600;
}

#deleteSiteBtn {
  background: #3a2226 !important;
  color: #ff8a7a !important;
  border-color: #5a2f34 !important;
}

#placingBanner {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  background: #ff5a3c;
  color: #14161a;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 600;
}

#placingBanner button {
  background: none;
  border: none;
  color: #14161a;
  text-decoration: underline;
  cursor: pointer;
  font-weight: 600;
  font-size: 12.5px;
}

/* --- Airspace overlay controls --- */

.airspace-controls {
  border-top: 1px solid #2a2e35;
  padding-top: 10px;
  margin-top: 10px;
}

.airspace-toggle-row {
  display: flex !important;
  align-items: center;
  gap: 6px;
  margin: 0 0 8px !important;
  font-size: 12.5px !important;
  color: #f2f2f2 !important;
  cursor: pointer;
}

.airspace-legend {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.airspace-legend[hidden] {
  display: none;
}

.airspace-legend label {
  display: flex !important;
  align-items: center;
  gap: 7px;
  margin: 0 !important;
  font-size: 12px !important;
  color: #cfd3d9 !important;
  cursor: pointer;
}

.airspace-legend .swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex: 0 0 auto;
}

.airspace-attribution {
  margin-top: 8px;
  font-size: 10.5px;
  line-height: 1.4;
  color: #6b7178;
}

.airspace-attribution a {
  color: #7fb3ff;
}

/* --- Glide range tool --- */

.glide-legend {
  border-top: 1px solid #2a2e35;
  padding-top: 10px;
  margin-top: 10px;
}

.glide-legend[hidden] {
  display: none;
}

.glide-legend-title {
  font-size: 12px;
  font-weight: 600;
  color: #f2f2f2;
  margin-bottom: 8px;
}

.glide-legend-rows {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
}

.glide-legend-row {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: #cfd3d9;
}

.glide-legend .swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex: 0 0 auto;
}

.glide-legend button {
  width: 100%;
  background: #2a2e35;
  color: #f2f2f2;
  border: 1px solid #40454e;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
}

.glide-legend button:hover {
  background: #383e47;
}

.glide-hover-tip {
  position: absolute;
  z-index: 25;
  pointer-events: none;
  background: #14161aee;
  border: 1px solid #2a2e35;
  border-radius: 5px;
  padding: 3px 7px;
  font-size: 12px;
  font-weight: 600;
  color: #f2f2f2;
}

.site-marker {
  width: 26px;
  height: 26px;
  border-radius: 50% 50% 50% 0;
  background: #ff5a3c;
  border: 2px solid #14161a;
  transform: rotate(-45deg);
  cursor: pointer;
}

.site-marker::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 8px;
  height: 8px;
  background: #14161a;
  border-radius: 50%;
  transform: translate(-50%, -50%) rotate(45deg);
}

/* The in-progress pin position while adding/editing a site's location --
   distinct from the solid .site-marker so it reads as "not saved yet",
   not a second real site. Same pin shape, inverted colors. */
.site-marker-draft {
  background: #fff;
  border-color: #ff5a3c;
  cursor: default;
}

.site-marker-draft::after {
  background: #ff5a3c;
}

.site-marker-label {
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  color: #fff;
  background: rgba(20, 22, 26, 0.72);
  padding: 3px 6px;
  border-radius: 4px;
  white-space: nowrap;
  cursor: pointer;
}
