/* The legend floats below the shared tabs without shifting the map cards. */
body.dt-map-shell .dropdown-panel[data-layer-tab="Legend"] {
  position: absolute;
  top: 30px;
  left: 0;
  margin-top: 0 !important;
  padding: 0 !important;
  z-index: 150;
  border-radius: 0 0 9px 9px;
  overflow: hidden;
  background: #fff !important;
  box-shadow: 0 8px 26px #142b4933;
}
.dt-map-legend {
  --legend-text: #294458;
  --legend-muted: #647d8e;
  --legend-border: #dce7ec;
  --legend-heading: #f2f7fa;
  color: var(--legend-text);
  background: #fff;
  font: 12px/1.45 system-ui, sans-serif;
  text-align: left;
  container-type: inline-size;
}
.dt-legend-header { padding: 12px 14px 10px; border-bottom: 1px solid var(--legend-border); }
.dt-legend-header h3 { margin: 0 0 4px; color: var(--legend-text); font-size: 14px; }
.dt-legend-header p { margin: 0 0 9px; color: var(--legend-muted); }
.dt-legend-header input {
  box-sizing: border-box; width: 100%; height: 30px; border: 1px solid var(--legend-border);
  border-radius: 5px; padding: 4px 9px; background: #fff; color: var(--legend-text); font: inherit;
}
.dt-legend-header input:focus-visible { outline: 2px solid #2388f8; outline-offset: 1px; }
.dt-legend-content { max-height: min(52dvh, 460px); overflow: auto; overscroll-behavior: contain; }
.dt-legend-content:focus-visible { outline: 2px solid #2388f8; outline-offset: -2px; }
.dt-legend-section { border-bottom: 1px solid var(--legend-border); }
.dt-legend-section summary {
  position: sticky; top: 0; z-index: 1; cursor: pointer; padding: 8px 14px;
  background: var(--legend-heading); color: var(--legend-text); font-weight: 650;
}
.dt-legend-section-note { margin: 8px 14px; color: var(--legend-muted); font-size: 11px; }
.dt-legend-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.dt-legend-row { display: grid; grid-template-columns: 68px minmax(0,1fr); gap: 10px; padding: 8px 14px; align-items: center; }
.dt-legend-grid .dt-legend-row { border-top: 1px solid var(--legend-border); }
.dt-legend-grid .dt-legend-row:nth-child(even) { border-left: 1px solid var(--legend-border); }
.dt-legend-row strong { display: block; color: var(--legend-text); font-size: 12px; }
.dt-legend-row p { margin: 2px 0 0; color: var(--legend-muted); font-size: 11px; overflow-wrap: anywhere; }
.dt-legend-sample { display: flex; align-items: center; justify-content: center; width: 68px; min-height: 34px; }
.dt-legend-sample > img { max-width: 68px; max-height: 34px; }
.dt-legend-section[data-legend-section="IENC chart overlay"] .dt-legend-sample {
  border-radius: 4px; background: #edf4f8; border: 1px solid #d3dfe6; box-sizing: border-box;
}
.dt-legend-themed-icon { display: flex; align-items: center; justify-content: center; }
.dt-legend-themed-icon img { width: 32px; height: 32px; }
.dt-legend-dark-icon { display: none; }
.dt-legend-faded { opacity: .68; }
.dt-legend-faded img { width: 34px; height: 34px; }
.dt-legend-water-badge {
  display: inline-block; padding: 3px 6px; border: 1px solid #577c932e; border-radius: 4px;
  color: #2582b0; background: #fffffff0; font: 600 12px sans-serif; white-space: nowrap;
}
.dt-legend-empty { padding: 16px; color: var(--legend-muted); }
@container (max-width: 600px) {
  .dt-legend-grid { grid-template-columns: minmax(0, 1fr); }
  .dt-legend-grid .dt-legend-row:nth-child(even) { border-left: 0; }
}
body.dark-water-theme .dt-map-legend {
  --legend-text: #dcebf5; --legend-muted: #a9c1d3; --legend-border: #36536a; --legend-heading: #1e3b51;
  background: #163044;
}
body.dark-water-theme .dt-legend-header input { background: #1c3a50; }
body.dark-water-theme .dt-legend-light-icon { display: none; }
body.dark-water-theme .dt-legend-dark-icon { display: block; }
body.dark-water-theme .dt-legend-water-badge { color: #81d9ff; background: #142e41c7; border-color: #9bc5da3d; }
/* Keep map status cards from overlapping the open legend. */
body.dt-map-shell .map:has(.dropdown-panel[data-layer-tab="Legend"]) .vessel-layer-controls,
body.dt-map-shell .map:has(.dropdown-panel[data-layer-tab="Legend"]) .nts-map-control { visibility: hidden; }
