/* Tracker controls share a status row, a camera toolbar and a safe area for overlays. */
.hud-topbar {
  z-index: 42;
  justify-content: flex-start;
  column-gap: 8px;
  row-gap: 4px;
}

.hud-topbar > *, .hud-tool-group > * {
  pointer-events: auto;
}

.hud-topbar > .camera-navigation {
  margin-left: auto;
}

.tracker-brand-icon {
  flex: none;
}

.tab-btn, .phase-pill, .metric-label, .stat-chip span {
  font-size: 11px;
}

.flight-telemetry, .flight-sub {
  font-size: 11.5px;
}

.sheet-action, #feed-status-text {
  display: none;
}

#feed-status-short {
  font: 700 12px var(--font-mono);
}

#hud-menu-btn[aria-expanded="true"] {
  border-color: var(--accent-cyan);
}

.hud-conditions-summary {
  color: #c4d4e4;
  font: 600 12px var(--font-mono);
}

.hud-conditions-summary strong {
  color: #f1f5f9;
  font-size: 12px;
}

.fps-pill {
  gap: 5px;
  color: #f1f5f9;
  font: 700 12px var(--font-mono);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  flex-shrink: 0;
}

.fps-pill .fps-unit {
  color: #a5b4c7;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.hud-tools .hud-btn {
  padding-inline: 9px;
}

.hud-tools .seg-btn {
  padding-inline: 7px;
}

.replay-bar, .cockpit-hud, .traffic-panel:not(.collapsed), .inspector-card {
  bottom: 32px;
}

.hud-tools {
  display: none;
  position: fixed;
  top: var(--topbar-bottom, 96px);
  left: var(--tools-left, 8px);
  width: min(372px, calc(100vw - 16px));
  max-height: calc(100dvh - var(--topbar-bottom, 96px) - 8px);
  overflow: auto;
  overscroll-behavior: contain;
  background: #0e1d2f;
  color: var(--text-primary);
  border: 1px solid #38516a;
  border-radius: 12px;
  padding: 12px;
  box-shadow: var(--shadow-hud);
}

.hud-topbar:has(#hud-menu-btn[aria-expanded="true"]) .hud-tools {
  display: grid;
  gap: 12px;
}

.hud-tool-group {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  order: 0;
  margin: 0;
}

.tool-group-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
}

.tool-group-title {
  display: block;
  width: 100%;
  font-size: 12px;
  font-weight: 700;
  color: #d7e5f4;
}

.tool-group-head .tool-group-title {
  width: auto;
}

.tool-group-meta {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tool-group-desc {
  width: 100%;
  font-size: 11px;
  line-height: 1.4;
  color: #8ba0b8;
  min-height: 15px;
}

.hud-conditions {
  order: 1;
}

.hud-tools :is(.seg-btn, .hud-btn, .hud-select) {
  min-height: 36px;
}

.hud-tools .plan-pill {
  display: inline-flex;
}

.hud-tools .sky-selector {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 3px;
  width: 100%;
  background: #081322;
  border-color: rgba(148, 184, 228, 0.18);
  box-shadow: none;
}

.hud-tools .sky-selector .seg-btn {
  padding-inline: 4px;
  text-align: center;
  white-space: nowrap;
}

@media (max-width: 360px) {
  .hud-tools .sky-selector {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.preset-select-row {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
}

.hud-select {
  flex: 1 1 auto;
  min-width: 0;
  padding: 6px 10px;
  border-radius: 9px;
  border: 1px solid rgba(148, 184, 228, 0.28);
  background: #081322;
  color: var(--text-primary);
  font: 600 12px var(--font-sans);
  cursor: pointer;
}

.camera-preset-reset {
  flex-shrink: 0;
  background: #0b1829;
  border-color: rgba(148, 184, 228, 0.18);
  color: #d7e5f4;
}

.layer-switch-list {
  width: 100%;
  background: #0b1829;
  border: 1px solid rgba(148, 184, 228, 0.16);
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.layer-switch-row {
  appearance: none;
  border: 0;
  border-bottom: 1px solid rgba(148, 184, 228, 0.1);
  background: transparent;
  color: var(--text-primary);
  font: 600 12px var(--font-sans);
  width: 100%;
  min-height: 38px;
  padding: 6px 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  text-align: left;
  transition: background 0.14s ease;
}

.layer-switch-row:last-child {
  border-bottom: 0;
}

.layer-switch-row:hover {
  background: rgba(148, 184, 228, 0.08);
}

.layer-switch-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
}

.layer-switch-track {
  width: 34px;
  height: 20px;
  border-radius: 999px;
  background: #1b2f45;
  border: 1px solid rgba(148, 184, 228, 0.25);
  padding: 2px;
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  transition: background 0.16s ease, border-color 0.16s ease;
}

.layer-switch-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #94a3b8;
  transform: translateX(0);
  transition: transform 0.16s ease, background 0.16s ease;
}

.layer-switch-row[aria-checked="true"] .layer-switch-track {
  background: #0284c7;
  border-color: var(--accent-cyan);
}

.layer-switch-row[aria-checked="true"] .layer-switch-thumb {
  background: #f8fafc;
  transform: translateX(14px);
}

.hud-tools .mode-switch {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 3px;
  width: 100%;
  background: #081322;
  border-color: rgba(148, 184, 228, 0.18);
  box-shadow: none;
}

.hud-tools .mode-switch .seg-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}

.source-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #475569;
  flex-shrink: 0;
}

.mode-switch [data-mode="live"][aria-checked="true"] .source-dot {
  background: var(--accent-emerald);
  box-shadow: 0 0 7px rgba(16, 185, 129, 0.8);
}

.mode-switch [data-mode="demo"][aria-checked="true"] .source-dot {
  background: var(--accent-amber);
  box-shadow: 0 0 7px rgba(245, 158, 11, 0.75);
}

.hud-tools .receiver-btn {
  width: 100%;
  justify-content: space-between;
  gap: 8px;
  background: #0b1829;
  border-color: rgba(148, 184, 228, 0.16);
  color: #d7e5f4;
}

.hud-tools .receiver-btn.connected {
  border-color: rgba(148, 184, 228, 0.22);
  color: #d7e5f4;
}

.hud-tools .receiver-btn:hover {
  background: #152942;
  border-color: rgba(148, 184, 228, 0.35);
}

.receiver-btn-left,
.receiver-btn-right {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.receiver-btn-right {
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 500;
  flex-shrink: 0;
}

.receiver-status-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-secondary);
  background: rgba(148, 163, 184, 0.12);
}

.receiver-status-pill.connected {
  color: #a7f3d0;
  background: rgba(16, 185, 129, 0.16);
}

.receiver-status-pill.degraded {
  color: #fde68a;
  background: rgba(245, 158, 11, 0.16);
}

.receiver-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

html:not([data-tracker-state="ready"]) .hud-topbar > :not(.topbar-left) {
  visibility: hidden;
}

#app :is(button, summary, a, input, select):focus-visible {
  outline: 2px solid #7dd3fc;
  outline-offset: 2px;
}

.hud-popover {
  position: fixed;
  top: var(--popover-top, var(--topbar-bottom, 64px));
  left: var(--popover-left, 12px);
  right: auto;
  max-width: calc(100vw - 24px);
  max-height: calc(100dvh - var(--popover-top, var(--topbar-bottom, 64px)) - 12px);
  overflow: auto;
  overscroll-behavior: contain;
}

.hud-popover .airport-roster-list {
  max-height: none;
  overflow: visible;
}

.popover-close {
  float: right;
  order: -1;
  align-self: flex-end;
  width: 32px;
  height: 32px;
  cursor: pointer;
  font-size: 20px;
  color: var(--text-primary);
  background: #15263a;
  border: 1px solid var(--glass-border);
  border-radius: 7px;
}

.sfo-zones-popover .popover-close, .atc-popover .popover-close {
  position: absolute;
  right: 9px;
  top: 7px;
}

#airport-roster-section > .popover-header, .atc-popover > .popover-header {
  min-height: 26px;
  padding-right: 36px;
}

.replay-ticks {
  display: flex;
  justify-content: space-between;
  color: #c0cedd;
  font: 10px var(--font-mono);
}

.replay-gap-key {
  font: 11px var(--font-sans);
  color: #fecaca;
}

#app:has(.replay-bar:not(.hidden)) .cockpit-hud {
  bottom: calc(40px + var(--replay-height, 86px));
}

html[data-camera-mode="cockpit"] .inspector-card {
  display: none;
}

.service-notice-banner {
  width: max-content;
  max-width: min(640px, calc(100vw - 24px));
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 5px 12px;
  padding: 9px 12px;
  pointer-events: auto;
}

.service-notice-tag {
  grid-column: 1;
  grid-row: 1;
  justify-self: start;
}

.service-notice-dismiss {
  grid-column: 2;
  grid-row: 1;
  min-width: 28px;
  min-height: 28px;
}

.service-notice-text {
  grid-column: 1 / -1;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.service-notice-link {
  grid-column: 1 / -1;
  justify-self: start;
}

.hud-topbar:has(.hud-popover:not(.hidden), .tracker-guide[open], #hud-menu-btn[aria-expanded="true"]) {
  z-index: 48;
}

@media (max-width: 900px), (max-height: 520px) {
  #app {
    --edge: calc(max(6px, env(safe-area-inset-bottom)) + 26px);
    --sheet-bottom: var(--edge);
  }
  #app:has(#replay-bar:not(.hidden)) {
    --sheet-bottom: calc(var(--edge) + var(--replay-height, 118px) + 8px);
  }
  .hud-topbar {
    inset: max(6px, env(safe-area-inset-top)) 8px auto;
    gap: 4px;
  }
  .hud-tools {
    left: auto;
    right: 8px;
  }
  .hud-conditions-summary, .topbar-about-link, .topbar-feedback-link {
    display: none;
  }
  .topbar-left {
    width: 100%;
    gap: 4px;
  }
  .brand-lockup, .airport-pill, #feed-status-pill, #fps-pill, #replay-toggle-btn, #hud-menu-btn, #analytics-btn {
    min-height: 36px;
    padding: 5px 7px;
    border-radius: 8px;
    gap: 4px;
  }
  .brand-title {
    font-size: 13px;
  }
  .tracker-brand-icon {
    width: 16px;
    height: 16px;
  }
  .airport-code {
    font-size: 12px;
    padding: 2px 3px;
  }
  .airport-meta, .tracker-guide-label, #feed-status-text {
    display: none;
  }
  #feed-status-short {
    display: inline;
    font-size: 10px;
  }
  #feed-status-pill {
    min-width: 0;
  }
  #feed-status-pill .status-dot {
    flex: none;
    width: 6px;
    height: 6px;
  }
  #hud-menu-btn {
    display: inline-flex;
    margin-left: auto;
  }
  #hud-menu-btn[aria-expanded="true"] {
    border-color: var(--accent-cyan);
  }
  .hud-topbar > .camera-navigation {
    order: 1;
    margin-left: 0;
    gap: 2px;
    padding: 3px;
    max-width: 100%;
    flex-wrap: wrap;
  }
  .camera-navigation button {
    min-height: 34px;
    padding: 5px 6px;
  }
  .camera-navigation .camera-icon-button {
    min-width: 26px;
    padding: 5px 4px;
  }
  .view-mode-switch {
    padding-right: 2px;
  }
  .camera-utility-buttons {
    padding-left: 2px;
  }
  .camera-navigation kbd, .camera-button-label {
    display: none;
  }
  .camera-navigation-help {
    right: auto;
    left: 0;
    max-height: calc(100dvh - 110px);
    overflow: auto;
  }
  .hud-popover {
    left: 8px;
    right: auto;
    top: var(--topbar-bottom, 96px);
    max-width: calc(100vw - 16px);
    max-height: calc(100dvh - var(--topbar-bottom, 96px) - 8px);
  }
  .atc-popover {
    width: min(360px, calc(100vw - 16px));
  }
  #app .traffic-panel, #app .inspector-card {
    inset: auto 8px var(--sheet-bottom);
    width: auto;
    max-width: 540px;
    margin-inline: auto;
    max-height: calc(100dvh - var(--topbar-bottom, 96px) - var(--sheet-bottom) - 8px);
  }
  #app .traffic-panel {
    height: min(46dvh, 430px);
  }
  #app .traffic-panel.collapsed {
    height: auto;
  }
  #app .traffic-panel.collapsed .panel-head {
    flex-direction: row;
    align-items: center;
    gap: 6px;
  }
  .traffic-panel.collapsed .panel-title-row {
    flex: 1;
    gap: 5px;
  }
  .panel-head {
    padding: 6px 8px;
    gap: 5px;
  }
  .panel-toggle-btn {
    min-width: 50px;
    min-height: 34px;
  }
  .panel-head .tab-btn {
    min-height: 30px;
  }
  .panel-head .stat-chip {
    padding: 2px 4px;
  }
  .panel-head .stat-chip strong, .panel-head .stat-chip span {
    display: inline;
  }
  .panel-head .stat-chip span {
    margin-left: 3px;
  }
  .sheet-action {
    display: inline-flex;
    align-items: center;
    min-height: 34px;
    padding: 4px 8px;
    border: 1px solid #33516a;
    border-radius: 7px;
    color: #b9e9ff;
    background: #142c42;
    font: 600 12px var(--font-sans);
    cursor: pointer;
  }
  #flight-peek-btn {
    display: none;
  }
  .traffic-panel.collapsed #flight-peek-btn:not([hidden]) {
    display: block;
    max-width: 52%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  #flight-back-btn {
    align-self: flex-start;
    margin-bottom: 4px;
  }
  #app .inspector-card {
    display: none;
    overflow-y: auto;
  }
  #app[data-flight-sheet="details"] .inspector-card:not(.hidden) {
    display: block;
  }
  #app[data-flight-sheet="details"]:has(.inspector-card:not(.hidden)) .traffic-panel {
    display: none;
  }
  html:is([data-camera-mode="fly"],[data-camera-mode="cockpit"]) #app .inspector-card {
    display: none;
  }
  html:is([data-camera-mode="fly"],[data-camera-mode="cockpit"]) #app .traffic-panel {
    display: flex;
  }
  #app .replay-bar {
    inset: auto 8px var(--edge);
    width: auto;
    max-width: 540px;
    margin-inline: auto;
    transform: none;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 4px 8px;
    padding: 6px 8px;
  }
  .replay-scrubber-col {
    grid-row: 2;
    grid-column: 1 / -1;
  }
  .speed-pill {
    min-height: 28px;
  }
  #app #cockpit-hud {
    inset: auto 8px var(--sheet-bottom);
    width: auto;
    max-width: 540px;
    margin-inline: auto;
    transform: none;
  }
  html[data-camera-mode="cockpit"] #app .traffic-panel {
    bottom: calc(var(--sheet-bottom) + var(--cockpit-height, 48px) + 6px);
  }
  .cockpit-tag {
    display: none;
  }
  .camera-fly-controls {
    bottom: calc(var(--sheet-bottom) + 64px);
  }
  .service-notice-banner {
    width: min(420px, calc(100vw - 16px));
    max-height: calc(100dvh - var(--topbar-bottom, 96px) - 60px);
    overflow-y: auto;
  }
  .tracker-guide-panel {
    width: min(410px, calc(100vw - 16px));
  }
  .app-version {
    font-size: 10px;
    padding: 2px 8px;
  }
}

@media (max-width: 370px) {
  .topbar-left {
    gap: 3px;
  }
  .camera-button-label, .airport-pill .caret {
    display: none;
  }
  .brand-lockup, .airport-pill, #feed-status-pill, #fps-pill, #replay-toggle-btn, #hud-menu-btn, #analytics-btn {
    padding-inline: 4px;
  }
  .brand-title {
    font-size: 12px;
  }
  .camera-navigation button {
    padding-inline: 5px;
  }
}

@media (max-height: 520px) and (min-width: 550px) {
  .hud-topbar {
    justify-content: space-between;
  }
  .topbar-left {
    width: auto;
  }
  #app .traffic-panel, #app .inspector-card {
    right: 8px;
    left: auto;
    width: min(360px, 48vw);
  }
  #app .traffic-panel:not(.collapsed) {
    height: calc(100dvh - var(--topbar-bottom, 64px) - var(--sheet-bottom) - 12px);
  }
  #app:has(.replay-bar:not(.hidden)) .traffic-panel:not(.collapsed) .stats-strip {
    display: none;
  }
}

.replay-ticks[hidden] {
  display: none;
}

@media (min-width: 901px) and (max-width: 1430px) and (min-height: 521px) {
  #app:has(#replay-bar:not(.hidden)) :is(.traffic-panel:not(.collapsed), .inspector-card) {
    bottom: calc(40px + var(--replay-height, 86px));
  }
  .inspector-card {
    max-height: calc(100dvh - var(--topbar-bottom, 90px) - var(--replay-height, 0px) - 44px);
    overflow-y: auto;
  }
}

@media (max-width: 900px), (max-height: 520px) {
  #hud-menu-btn {
    white-space: nowrap;
  }
}

.hud-topbar:has(#atc-popover:not(.hidden)) .hud-tools {
  visibility: hidden;
}
