/* SPV Locations v1.29: non-overlapping sticky headers and background scroll lock.
   Scope: auxiliary dialog windows only; does not style the feedback form. */

/* Disable scrolling of the planner behind any open auxiliary popup.
   :has() is supported by modern Chromium and iOS Safari; inner popup scrolls normally. */
html:has(#modal[open]),
html:has(#spv-tools-overlay:not([hidden])),
html:has(#spv-publish-overlay:not([hidden])),
html:has(.spv-published-shade),
html:has(#spv-crew-management-shade) {
  overflow: hidden !important;
  overscroll-behavior: none !important;
}
body:has(#modal[open]),
body:has(#spv-tools-overlay:not([hidden])),
body:has(#spv-publish-overlay:not([hidden])),
body:has(.spv-published-shade),
body:has(#spv-crew-management-shade) {
  overflow: hidden !important;
  overscroll-behavior: none !important;
}

/* More tools: no negative margins; the heading uses its own layout space.
   Slightly wider room for the two columns on desktop, with more vertical space. */
dialog#modal.spv-tools-dialog {
  width: min(650px, calc(100vw - 24px)) !important;
  max-height: calc(100dvh - 24px);
  padding: 20px 22px 22px !important;
  box-sizing: border-box;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
}
#modal.spv-tools-dialog > .modal-top {
  position: sticky !important;
  top: 0 !important;
  z-index: 12 !important;
  margin: 0 0 18px !important;
  padding: 4px 0 13px !important;
  min-height: 58px;
  background: #fff !important;
  border-bottom: 1px solid #dce4eb;
  box-sizing: border-box;
}
#modal.spv-tools-dialog > #modal-content { padding-top: 2px; }

/* Other long auxiliary windows: a sticky heading with real reserved spacing. */
#spv-tools-panel,
#spv-publish-overlay .spv-publish-dialog,
.spv-published-dialog,
.spv-crew-management-box {
  overscroll-behavior: contain;
}
#spv-tools-panel > .spv-tools-row:first-child,
#spv-publish-overlay .spv-publish-dialog > .spv-publish-head,
.spv-published-dialog > .spv-published-head,
.spv-crew-management-box > .spv-crew-manage-head {
  position: sticky !important;
  top: 0 !important;
  z-index: 12 !important;
  background: #fff !important;
  margin: 0 0 16px !important;
  padding: 4px 0 12px !important;
  min-height: 54px;
  box-sizing: border-box;
  border-bottom: 1px solid #dce4eb;
}
#spv-tools-panel #spv-tools-close,
#spv-publish-overlay #spv-publish-close,
.spv-published-dialog .spv-published-close,
.spv-crew-management-box .spv-crew-manage-head button {
  flex: 0 0 auto;
  min-width: 44px;
  min-height: 44px;
}
#spv-publish-overlay #spv-publish-close { font-size: 20px; line-height: 1.1; }

/* Native dialog / overlays use internal scrolling, never chain to planner. */
#modal[open] { overscroll-behavior-y: contain; }
#spv-tools-overlay:not([hidden]),
#spv-publish-overlay:not([hidden]),
.spv-published-shade,
#spv-crew-management-shade {
  overscroll-behavior: none;
}

/* These specific windows already have a sticky top X, so keep redundant
   automatically added footer Close buttons hidden. No feedback dialog changes. */
#modal.spv-tools-dialog > .spv-navigation-footer,
#spv-tools-panel > .spv-navigation-footer,
.spv-publish-dialog > .spv-navigation-footer,
.spv-published-dialog > .spv-navigation-footer,
.spv-crew-management-box > .spv-navigation-footer {
  display: none !important;
}

@media (max-width: 480px) {
  dialog#modal.spv-tools-dialog { padding: 14px 14px 18px !important; }
  #modal.spv-tools-dialog > .modal-top {
    min-height: 52px;
    padding: 2px 0 10px !important;
    margin-bottom: 13px !important;
  }
  #modal.spv-tools-dialog > .modal-top h2,
  #spv-publish-overlay .spv-publish-head h2,
  .spv-published-dialog > .spv-published-head h3,
  .spv-crew-management-box > .spv-crew-manage-head h3 {
    min-width: 0;
    overflow-wrap: anywhere;
  }
  #spv-publish-overlay .spv-publish-dialog > .spv-publish-head,
  .spv-published-dialog > .spv-published-head,
  .spv-crew-management-box > .spv-crew-manage-head { gap: 8px; }
}
