/*
 * Vessel card layout. One header (category, name, close), one scrolling body,
 * and grouped sections inside it. It sits last in the cascade and uses the
 * card's id, so the older layered card rules cannot move its controls: the
 * old `.vessel-card button` rule used to pin every button, including the
 * track-range buttons, on top of the close button.
 */
html body .map-bg > #vesselCard {
  display: none;
  flex-direction: column;
  gap: 0;
  padding: 0;
  overflow: hidden;
  border-radius: 16px;
  max-height: min(740px, 100% - 32px);
  color: var(--popup-text);
}
html body .map-bg > #vesselCard.show { display: flex; }

/* Layout wrappers carry no box of their own; older rules box every div. */
html body #vesselCard .vc-head,
html body #vesselCard .vc-ident,
html body #vesselCard .track-head,
html body #vesselCard #vesselMeta,
html body #vesselCard #vesselDetails,
html body #vesselCard .track-scrub {
  border-top: 0;
  border-inline: 0;
  border-radius: 0;
  box-shadow: none;
}
html body #vesselCard .vc-ident,
html body #vesselCard .track-head,
html body #vesselCard #vesselMeta,
html body #vesselCard #vesselDetails,
html body #vesselCard .track-scrub { border-bottom: 0; background: none; padding: 0; }

/* Header */
#vesselCard .vc-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  flex: none;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--popup-line);
  background: var(--popup-footer);
}
html body #vesselCard .vc-head { border-top: 0; }
#vesselCard .vc-ident {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  flex: 1;
  min-width: 0;
}
html body .map-bg > #vesselCard #vesselCategory {
  position: static;
  margin: 0;
  order: 0;
}
html body .map-bg > #vesselCard #vesselName {
  position: static;
  order: 0;
  margin: 0;
  font-size: 20px;
  line-height: 1.25;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}
html body .map-bg > #vesselCard #closeCard {
  position: static;
  inset: auto;
  flex: none;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 10px;
  border: 1px solid var(--popup-line);
  background: var(--popup-subtle);
  color: var(--popup-text);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, transform .15s ease;
}
html body .map-bg > #vesselCard #closeCard:hover,
html body .map-bg > #vesselCard #closeCard:focus-visible {
  background: var(--surface-hover);
  border-color: var(--accent-border);
}
html body .map-bg > #vesselCard #closeCard:active { transform: scale(.94); }

/* Body: the only scrolling part */
html body .map-bg > #vesselCard > .vessel-card-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1 1 auto;
  min-height: 0;
  margin: 0;
  padding: 14px 16px 18px;
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 0;
  background: none;
  box-shadow: none;
  scrollbar-width: thin;
}
#vesselCard .vessel-card-body > * { margin: 0; min-width: 0; }
#vesselCard .vessel-card-body > .freshness { order: 1; }
#vesselCard .vessel-card-body > .sim-badge { order: 2; }
#vesselCard .vessel-card-body > #vesselMeta { order: 3; }
#vesselCard .vessel-card-body > .vessel-risk { order: 4; }
#vesselCard .vessel-card-body > #vesselMethod { order: 5; }
#vesselCard .vessel-card-body > #trackPanel { order: 6; }
#vesselCard .vessel-card-body > #vesselDetails { order: 7; display: flex; flex-direction: column; gap: 12px; }

/* Every button inside the card is an ordinary control; none is pinned. */
#vesselCard .vessel-card-body button {
  position: static;
  inset: auto;
  font: inherit;
  cursor: pointer;
}

/* Track panel */
html body #vesselCard #trackPanel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--popup-line);
  background: var(--popup-subtle);
}
#vesselCard .track-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
#vesselCard .track-head b { font-size: 13px; color: var(--popup-text); }
html body #vesselCard .track-head button {
  min-height: 28px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--popup-line);
  background: transparent;
  color: var(--popup-muted);
  font-size: 12px;
}
html body #vesselCard .track-head button[hidden] { display: none; }
html body #vesselCard .track-head button[aria-pressed="true"] {
  border-color: var(--success-border);
  background: var(--success-soft);
  color: var(--success-text);
}
#vesselCard .track-head button:hover,
#vesselCard .track-head button:focus-visible { border-color: var(--accent-border); }
#vesselCard #trackOrigin { margin: 0; font-size: 12px; line-height: 1.55; color: var(--popup-muted); }
html body #vesselCard .track-spans {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 4px;
  padding: 3px;
  border-radius: 10px;
  border: 1px solid var(--popup-line);
  background: var(--surface-inset, rgba(0, 0, 0, .2));
}
html body #vesselCard .track-spans button {
  min-height: 32px;
  padding: 4px 2px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--popup-muted);
  font-size: 12px;
  line-height: 1.2;
  white-space: nowrap;
  box-shadow: none;
  transition: background .15s ease, color .15s ease;
}
html body #vesselCard .track-spans button:hover { color: var(--popup-text); }
html body #vesselCard .track-spans button.selected,
html body #vesselCard .track-spans button[aria-pressed="true"] {
  background: var(--accent-soft, rgba(67, 189, 218, .22));
  color: var(--popup-text);
  box-shadow: inset 0 0 0 1px var(--accent-border);
}
#vesselCard .track-scrub { display: grid; gap: 6px; font-size: 12px; color: var(--popup-muted); }
#vesselCard .track-scrub input { width: 100%; margin: 0; }
#vesselCard .track-scrub span { min-height: 0; font-variant-numeric: tabular-nums; }

/* Grouped sections: evidence, details, account */
#vesselCard .detail-group {
  margin: 0;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--popup-line);
  background: var(--popup-subtle);
}
#vesselCard .detail-group > h4 {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .02em;
  color: var(--popup-muted);
}

/* Account actions: a watchlist row, a download, and a collapsed report form */
#vesselCard .vessel-account { display: flex; flex-direction: column; gap: 10px; }
#vesselCard .vessel-account .vessel-account-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 0;
  border: 0;
}
html body #vesselCard .vessel-account select,
html body #vesselCard .vessel-account input,
html body #vesselCard .vessel-account textarea {
  width: 100%;
  min-height: 36px;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid var(--popup-line);
  background: var(--surface-inset, rgba(0, 0, 0, .2));
  color: var(--popup-text);
  font: inherit;
  font-size: 13px;
}
#vesselCard .vessel-account textarea { min-height: 72px; resize: vertical; }
html body #vesselCard .vessel-account button {
  min-height: 36px;
  padding: 6px 14px;
  border-radius: 10px;
  border: 1px solid var(--success-border);
  background: var(--success-soft);
  color: var(--success-text);
  font-size: 13px;
  font-weight: 600;
}
html body #vesselCard .vessel-account button:disabled { opacity: .55; cursor: not-allowed; }
html body #vesselCard .vessel-account button:hover:not(:disabled),
html body #vesselCard .vessel-account button:focus-visible { border-color: var(--accent-border); }
html body #vesselCard .vessel-account .vessel-account-dossier {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 6px 12px;
  border-radius: 10px;
  border: 1px solid var(--popup-line);
  background: transparent;
  color: var(--popup-text);
  font-size: 13px;
  text-decoration: none;
}
html body #vesselCard .vessel-account .vessel-account-dossier:hover,
html body #vesselCard .vessel-account .vessel-account-dossier:focus-visible { border-color: var(--accent-border); background: var(--surface-hover); }
#vesselCard .vessel-correction { border-top: 1px solid var(--popup-line); padding-top: 10px; }
#vesselCard .vessel-correction > summary { cursor: pointer; font-size: 13px; color: var(--popup-muted); list-style-position: inside; }
#vesselCard .vessel-correction form { display: grid; gap: 8px; margin-top: 10px; }
#vesselCard .vessel-account-status { margin: 0; min-height: 0; font-size: 12px; color: var(--popup-muted); }
#vesselCard .vessel-account-status:empty { display: none; }
#vesselCard .vessel-account-login { color: var(--success-text); font-size: 13px; }

/* Phones: the card is a bottom sheet with the same structure */
@media (max-width: 720px) {
  html body .map-bg > #vesselCard { max-height: min(78vh, 100% - 16px); border-radius: 18px 18px 14px 14px; }
  #vesselCard .vc-head { padding: 12px 14px 10px; }
  html body .map-bg > #vesselCard #vesselName { font-size: 18px; }
  html body .map-bg > #vesselCard > .vessel-card-body { padding: 12px 14px 16px; }
  html body #vesselCard .track-spans button { font-size: 11px; }
  /* The status strip would sit over the sheet; it returns when the card closes. */
  body:has(#vesselCard.show) .status-strip { visibility: hidden; }
}

@media (prefers-reduced-motion: reduce) {
  html body .map-bg > #vesselCard #closeCard,
  html body #vesselCard .track-spans button { transition: none; }
}

#vesselCard .track-scrub span,
#vesselCard .track-scrub { background: none; box-shadow: none; border: 0; }
