:root {
  --traffic-header-height: clamp(60px, 7.4dvh, 96px);
  --vessel: #b56b22;
  --vessel-stale: #8b7969;
}

:root[data-theme="night"] {
  --vessel: #f0a24d;
  --vessel-stale: #987f66;
}

body.traffic-page {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  min-height: 0;
}

.traffic-page .public-header {
  position: relative;
  z-index: 40;
  min-height: var(--traffic-header-height);
  flex: 0 0 auto;
}

.traffic-map-shell,
.traffic-map-shell .map-workspace {
  min-width: 0;
  min-height: 0;
  flex: 1 1 0;
  height: auto;
}
.traffic-map-shell { display: flex; }

.traffic-title-block { min-width: 222px; }

.traffic-layer-controls {
  position: absolute;
  z-index: 12;
  top: clamp(14px, 2vw, 28px);
  left: clamp(270px, 24vw, 360px);
  display: flex;
  gap: 6px;
  padding: 5px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.traffic-layer-controls label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 12px;
  border-radius: 8px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 11px;
  font-weight: 750;
  white-space: nowrap;
}

.traffic-layer-controls label:has(input:checked) {
  background: var(--accent-soft);
  color: var(--text);
}

.traffic-layer-controls input { accent-color: var(--accent); }

.target-panel { max-height: calc(100% - 170px); }
.target-panel .aircraft-field dd { white-space: normal; }
.target-panel-actions { display: flex; align-items: center; gap: 6px; }
#target-panel-expand, .target-peek { display: none; }

.legend-shape--vessel {
  width: 8px;
  height: 13px;
  clip-path: polygon(50% 0, 100% 35%, 82% 100%, 18% 100%, 0 35%);
  background: var(--vessel);
}

.maplibregl-canvas { cursor: grab; }

@media (max-width: 1050px) {
  .traffic-layer-controls {
    top: 84px;
    left: 14px;
  }
}

@media (max-width: 760px) {
  .traffic-title-block { min-width: 184px; }
  .traffic-layer-controls {
    top: 74px;
    right: 60px;
    left: 12px;
    overflow-x: auto;
    box-shadow: 0 9px 24px rgba(0, 0, 0, 0.18);
  }
  .traffic-layer-controls label {
    flex: 1 0 auto;
    justify-content: center;
    padding-inline: 8px;
  }
  .traffic-page .map-refresh { top: 76px; }
  .traffic-page .maplibregl-ctrl-top-right { top: 130px; }
  .target-panel { max-height: min(58dvh, 470px); }
}

@media (max-width: 430px) {
  .traffic-layer-controls { gap: 2px; }
  .traffic-layer-controls label { font-size: 10px; }
  .traffic-page .map-legend span:nth-child(2) { display: inline-flex; }
  .traffic-page .map-legend span:nth-child(3) { display: none; }
}
.maplibregl-canvas:active { cursor: grabbing; }

@media (max-width: 900px) {
  .traffic-layer-controls { left: 12px; top: 104px; }
  .map-refresh { top: 104px; }
  .maplibregl-ctrl-top-right { top: 154px; }
}

@media (max-width: 620px) {
  :root { --traffic-header-height: 100px; }
  .traffic-title-block { top: 10px; left: 8px; min-width: 170px; }
  .traffic-title-block h1 { font-size: 16px; }
  .traffic-layer-controls { top: 88px; right: 8px; left: 8px; justify-content: space-between; }
  .traffic-layer-controls label { flex: 1 1 0; justify-content: center; padding-inline: 6px; font-size: 10px; }
  .map-refresh { top: 146px; }
  .maplibregl-ctrl-top-right { top: 196px; }
  .map-legend { max-width: calc(100% - 16px); overflow: hidden; }
  .map-legend span:nth-child(3) { display: none; }
  .target-panel { max-height: min(56dvh, 470px); }
}

@media (max-width: 390px) {
  .traffic-layer-controls label { gap: 5px; font-size: 9px; }
  .map-legend span:nth-child(2) { display: inline-flex; }
}

@media (min-width: 2560px) {
  .traffic-layer-controls { top: 36px; left: 340px; }
}

/* Keep the restored floating controls clear at every supported viewport. */
.traffic-page .map-legend { bottom: 92px; }
.traffic-page .data-attribution { bottom: 64px; }

@media (max-width: 1050px) {
  .traffic-page .traffic-layer-controls { top: 135px; }
}

@media (max-width: 900px) {
  .traffic-page .traffic-layer-controls { top: 130px; }
}

@media (max-width: 620px) {
  .traffic-page .traffic-layer-controls { top: 110px; }
  .traffic-page .map-refresh { top: 174px; }
  .traffic-page .maplibregl-ctrl-top-right { top: 224px; }
}

@media (max-width: 1024px) {
  .traffic-page .traffic-title-block { top: 8px; left: 10px; min-width: 0; padding: 5px 9px; display: flex; align-items: center; gap: 12px; }
  .traffic-title-block > p { display: none; }
  .traffic-page .traffic-title-block h1 { font-size: 12px; }
  .traffic-title-block .workspace-readout { margin: 0; font-size: 10px; }
  .traffic-page .traffic-layer-controls { top: 44px; left: 10px; right: 62px; }
  .traffic-page .map-refresh { top: 46px; right: 10px; }
  .traffic-page .maplibregl-ctrl-top-right { top: 104px; }
  .traffic-page .target-panel[data-kind="aircraft"] { top: auto; bottom: 8px; left: 50%; right: auto; transform: translateX(-50%); width: min(520px, calc(100% - 16px)); height: max-content; min-height: 0; max-height: 38%; border-radius: 12px; background: var(--surface-solid); backdrop-filter: none; -webkit-backdrop-filter: none; box-shadow: none; }
  .target-panel[data-kind="aircraft"] .panel-heading { padding: 2px 8px 0; border: 0; align-items: center; gap: 8px; }
  .target-panel[data-kind="aircraft"] .panel-heading h2 { font-size: 17px; }
  .target-panel[data-kind="aircraft"] #target-kind,
  .target-panel[data-kind="aircraft"] #target-subtitle { display: none; }
  .target-panel[data-kind="aircraft"] #target-panel-expand { display: block; min-height: 44px; padding: 0 10px; color: var(--text); background: var(--accent-soft); border: 1px solid var(--line); border-radius: 8px; font-size: 11px; }
  .target-panel[data-kind="aircraft"] .target-peek { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 3px 8px; padding: 0 10px 7px; font-size: 11px; line-height: 1.3; }
  #target-peek-identity { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #target-peek-history { grid-column: 1 / -1; color: var(--text-muted); font-size: 10px; }
  .target-panel[data-kind="aircraft"]:not(.is-expanded) .aircraft-fields { display: none; }
  .traffic-page .target-panel[data-kind="aircraft"].is-expanded { max-height: 60%; }
  .traffic-page:has(.target-panel[data-kind="aircraft"]:not([hidden])) .map-legend,
  .traffic-page:has(.target-panel[data-kind="aircraft"]:not([hidden])) .data-attribution { visibility: hidden; }
}
