/* Only the ID and close follow scrolling; badges belong to the cover below. */
body.map-page #detailPanel {
  scroll-padding-top: 64px;
}

body.map-page #detailPanel > .detail-sticky-header {
  position: sticky;
  top: 0;
  z-index: 40;
  height: 0;
  pointer-events: none;
}

body.map-page #detailPanel .detail-sticky-controls {
  display: flex;
  align-items: center;
  width: max-content;
  max-width: 100%;
  margin-left: auto;
  gap: 8px;
  padding: 10px 12px;
}

/* Only the controls intercept input; the image and links remain usable between them. */
body.map-page #detailPanel > .detail-sticky-header :is(.detail-identifier-meta, #closeDetail),
body.map-page :is(#detailPanel, .editor-preview-card) > .detail-badges-header :is(.detail-category-badge, .event-status-badge) {
  pointer-events: auto;
}

body.map-page :is(#detailPanel, .editor-preview-card) > .detail-badges-header {
  position: relative;
  z-index: 35;
  height: 0;
  pointer-events: none;
}

body.map-page :is(#detailPanel, .editor-preview-card) > .detail-badges-header .detail-heading-meta {
  position: absolute;
  top: 18px;
  left: 12px;
  right: 12px;
  display: block;
  font-size: 0;
  line-height: 34px;
  min-width: 0;
  margin: 0;
  padding: 0;
}

/* The first line reserves the ID and close. Later lines use the full width
   below those controls instead of keeping an empty column on the right. */
body.map-page :is(#detailPanel, .editor-preview-card) > .detail-badges-header .detail-heading-meta::before {
  content: "";
  float: right;
  width: max(0px, calc(var(--detail-controls-space, 128px) - 12px));
  height: 34px;
}

body.map-page :is(#detailPanel, .editor-preview-card) > .detail-badges-header :is(.detail-category-badge, .event-status-badge) {
  display: inline-flex;
  vertical-align: top;
  margin: 0 4px 0 0 !important;
}

/* Flatten the status group so each badge wraps individually beside the category. */
body.map-page :is(#detailPanel, .editor-preview-card) > .detail-badges-header .detail-event-statuses:not([hidden]) {
  display: contents;
}

body.map-page :is(#detailPanel, .editor-preview-card) > .detail-badges-header .detail-category-badge {
  background: color-mix(in srgb, var(--category-color) 12%, #fff);
}

body.map-page #detailPanel > .detail-sticky-header .detail-identifier-meta {
  position: static;
  max-width: 110px;
  margin: 0;
}

body.map-page #detailPanel > .detail-sticky-header .detail-event-number {
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
}

body.map-page #detailPanel > .detail-sticky-header #closeDetail {
  position: static;
  margin: 0;
}

/* The media no longer needs to reserve room for the badges it used to contain. */
body.map-page :is(#detailPanel, .editor-preview-card) > .detail-cover {
  display: block;
  min-height: 0;
  padding: 0;
  aspect-ratio: auto;
}

/* Supersede the older missing-cover subgrid, which kept a fixed-ratio parent
   even when its artwork needed more height below the controls. */
body.map-page :is(#detailPanel, .editor-preview-card) > .detail-cover:has(> :is(#detailEmptyCover, .detail-empty-cover):not([hidden])) {
  display: block;
  min-height: 0;
  padding: 0;
  aspect-ratio: auto;
}

body.map-page :is(#detailPanel, .editor-preview-card) > .detail-cover > :is(#detailEmptyCover, .detail-empty-cover):not([hidden]) {
  display: block;
  aspect-ratio: 16 / 9;
  min-height: max(176px, calc(var(--detail-badge-bottom, 40px) + 132px));
}

body.map-page :is(#detailPanel, .editor-preview-card) > .detail-cover > :is(#detailEmptyCover, .detail-empty-cover) .detail-cover-fallback {
  position: absolute;
  inset: 0;
  padding: max(58px, calc(var(--detail-badge-bottom, 40px) + 16px)) 0 28px;
}

body.map-page :is(#detailPanel, .editor-preview-card) .detail-image-gallery {
  border-radius: 0;
}

/* Anchor preview tooltips to the full badge row so wrapped badges stay readable. */
body.map-page .editor-preview-card .detail-heading-meta .event-status-badge[data-status-tooltip] { position: static; }
body.map-page .editor-preview-card .detail-heading-meta .event-status-badge[data-status-tooltip]::after {
  left: 0; top: calc(100% + 4px); max-width: min(220px, 100%);
  overflow-wrap: anywhere; transform: translateY(-3px);
}
body.map-page .editor-preview-card .detail-heading-meta .event-status-badge[data-status-tooltip]:hover::after { transform: translateY(0); }

@media (max-width: 900px) {
  /* The outer tooltips must open into the panel, not beyond its clipped edges. */
  body.map-page #detailPanel > .detail-badges-header .event-status-badge:first-child::after {
    left: 0;
    transform: translateY(-3px);
  }

  body.map-page #detailPanel > .detail-badges-header .event-status-badge:first-child:hover::after {
    transform: translateY(0);
  }

  body.map-page #detailPanel > .detail-badges-header .event-status-badge:last-child:not(:first-child)::after {
    left: auto;
    right: 0;
    transform: translateY(-3px);
  }

  body.map-page #detailPanel > .detail-badges-header .event-status-badge:last-child:not(:first-child):hover::after {
    transform: translateY(0);
  }
}

