:root {
  --bg: #0f1722;
  --card: #1b2635;
  --line: #2a3a4d;
  --text: #f1f5f9;
  --muted: #9aa9bb;
  --blue: #1296e0;
  --danger: #b93b3b;
}

* {
  box-sizing: border-box;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  height: 100%;
}

/* Flex column so the map grows; grid + display:none telemetry had mis-assigned the 1fr row to the footer. */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-height: 0;
  overflow: hidden;
}

.app-shell > .topbar {
  flex: 0 0 auto;
}

.app-shell > .telemetry-bar {
  flex: 0 0 auto;
}

.app-shell > .bottom-bar {
  flex: 0 0 auto;
}

.telemetry-bar {
  background: #222;
  color: #e5e7eb;
  border-bottom: 1px solid #333;
  flex-shrink: 0;
}

.telemetry-bar[hidden] {
  display: none !important;
}

.telemetry-close-row {
  display: flex;
  justify-content: flex-end;
  padding: 6px 10px 0;
}

.join-settings {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.join-settings-heading {
  margin: 0 0 4px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #f1f5f9;
}

.join-settings-desc {
  margin: 0 0 10px;
  font-size: 12px;
  line-height: 1.45;
  color: var(--muted);
}

.join-settings-card {
  background: #131d2a;
  border: 1px solid #2a3f5c;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.join-panel .join-settings-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0;
  padding: 12px 14px;
  cursor: pointer;
  font-size: 14px;
  color: #e8eef5;
  border-bottom: 1px solid #243449;
  transition: background 0.12s ease;
}

.join-panel .join-settings-row:last-child {
  border-bottom: none;
}

.join-panel .join-settings-row:hover {
  background: rgba(255, 255, 255, 0.04);
}

.join-settings-label {
  font-weight: 600;
  flex: 1;
  min-width: 0;
  color: #dbe7f3;
}

.join-settings-select {
  flex: 0 1 auto;
  min-width: 128px;
  max-width: min(52%, 180px);
  appearance: none;
  -webkit-appearance: none;
  background-color: #0f1b29;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
  background-size: 14px;
  border: 1px solid #3d4f66;
  border-radius: 8px;
  color: #f1f5f9;
  font-size: 13px;
  font-weight: 600;
  padding: 9px 32px 9px 12px;
  cursor: pointer;
}

.join-settings-select:hover {
  border-color: #5a6e8a;
}

.join-settings-select:focus {
  outline: none;
  border-color: #5aa4ff;
  box-shadow: 0 0 0 2px rgba(90, 164, 255, 0.22);
}

.join-panel .join-settings-row--map-type {
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  padding-top: 14px;
  padding-bottom: 14px;
  cursor: default;
}

.join-panel .join-settings-row--map-type:hover {
  background: transparent;
}

.join-map-type-seg {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  width: 100%;
}

.join-map-type-btn {
  flex: 1 1 0;
  min-width: 0;
  appearance: none;
  border: 1px solid #3d4f66;
  border-radius: 8px;
  background: #0f1b29;
  color: #cbd5e1;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  padding: 9px 8px;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.join-map-type-btn:hover {
  border-color: #5a6e8a;
  color: #e8eef5;
}

.join-map-type-btn.is-active {
  background: var(--blue);
  border-color: #3d8cc0;
  color: #fff;
  box-shadow: 0 0 0 1px rgba(18, 150, 224, 0.35);
}

.join-map-type-btn:focus-visible {
  outline: none;
  border-color: #5aa4ff;
  box-shadow: 0 0 0 2px rgba(90, 164, 255, 0.25);
}

.telemetry-close {
  margin-left: auto;
  appearance: none;
  border: none;
  background: #374151;
  color: #e5e7eb;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.telemetry-close:hover {
  background: #4b5563;
}

.telemetry-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr) auto;
  align-items: stretch;
  gap: 8px 12px;
  padding: 8px 12px;
  min-height: 56px;
}

.telemetry-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-width: 0;
}

.telemetry-value {
  font-size: 22px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.telemetry-value.heading {
  color: #7dc816;
}

.telemetry-value.altitude {
  color: #13f0dc;
}

.telemetry-value.speed {
  color: #f5fd74;
}

.telemetry-label {
  margin-top: 2px;
  font-size: 11px;
  color: #9ca3af;
  font-weight: 500;
}

.telemetry-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  gap: 6px;
  min-width: 200px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.navigate-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: stretch;
  width: 100%;
}

.navigate-btn {
  appearance: none;
  border: none;
  border-radius: 999px;
  padding: 8px 18px;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  background: #3498db;
  color: #fff;
}

.navigate-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.navigate-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 4000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.5);
  box-sizing: border-box;
}

.navigate-modal-overlay[hidden] {
  display: none !important;
}

.navigate-modal-card {
  position: relative;
  width: 100%;
  max-width: 360px;
  padding: 48px 22px 16px;
  background: #ffffff;
  border-radius: 22px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  color: #111827;
}

.navigate-modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  appearance: none;
  border: none;
  border-radius: 10px;
  background: #f3f4f6;
  color: #374151;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.navigate-modal-close:hover {
  background: #e5e7eb;
}

.navigate-modal-title {
  margin: 0 0 6px;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #111827;
}

.navigate-modal-sub {
  margin: 0 0 18px;
  font-size: 14px;
  line-height: 1.4;
  color: #6b7280;
}

.navigate-modal-buttons {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
  width: 100%;
}

.navigate-modal-choice {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  appearance: none;
  border: none;
  border-radius: 999px;
  padding: 14px 20px;
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  color: #fff;
  font-family: inherit;
  transition: filter 0.12s ease, transform 0.08s ease;
}

.navigate-modal-choice:hover:not(:disabled) {
  filter: brightness(1.05);
}

.navigate-modal-choice:active:not(:disabled) {
  transform: scale(0.99);
}

.navigate-modal-choice:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.navigate-modal-choice--balloon {
  background: #3399ff;
}

.navigate-modal-choice--waypoint {
  background: #ff9800;
}

.navigate-modal-choice-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #fff;
}

.navigate-modal-choice-label {
  flex: 0 0 auto;
}

.navigate-modal-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 18px;
  padding-top: 4px;
}

.navigate-modal-cancel {
  appearance: none;
  border: none;
  background: transparent;
  color: #5c6bc0;
  font-size: 16px;
  font-weight: 600;
  padding: 10px 14px;
  cursor: pointer;
  font-family: inherit;
  border-radius: 8px;
}

.navigate-modal-cancel:hover {
  background: rgba(92, 107, 192, 0.08);
}

.telemetry-device {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  font-size: 11px;
  color: #cbd5e1;
  max-width: min(100%, 280px);
}

.telemetry-coords {
  white-space: nowrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  color: #9ca3af;
  margin-top: 2px;
}

/* ADMIN slot only: channel + password on their own lines (never ellipsize). */
.telemetry-admin-creds {
  display: block;
  margin-top: 4px;
  max-width: 100%;
  text-align: right;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  line-height: 1.35;
  color: #fbbf24;
  white-space: pre-line;
  word-break: break-all;
}

.telemetry-nickname {
  font-weight: 600;
  color: #f1f5f9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.telemetry-ago {
  color: #94a3b8;
}

.waypoint-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 8px;
  padding: 6px 12px 8px;
  font-size: 12px;
  color: #cbd5e1;
  border-top: 1px solid #2e2e2e;
  background: #1a1a1a;
}

.waypoint-title {
  font-weight: 700;
  color: #ff00ff;
  margin-right: 4px;
}

.waypoint-name {
  font-weight: 600;
  color: #f1f5f9;
}

.waypoint-sep {
  color: #6b7280;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  min-height: 60px;
  padding: 0 14px;
  background: #fff;
  color: #111;
  border-bottom: 1px solid #e5e7eb;
  box-sizing: border-box;
}

.topbar-left {
  display: flex;
  align-items: center;
}

.topbar-center {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-self: center;
  white-space: nowrap;
}

.topbar-logo {
  width: 30px;
  height: 30px;
  object-fit: contain;
}

.title {
  font-weight: 600;
}

.status-pill {
  background: #f3f4f6;
  color: #334155;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
}

#statusPill.connected {
  background: #16a34a;
  color: #ffffff;
  font-weight: 600;
}

#statusPill.disconnected {
  background: #fee2e2;
  color: #991b1b;
}

#statusPill.connecting {
  background: #fef3c7;
  color: #92400e;
}

.topbar-right {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-self: end;
}

.content {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 320px 1fr;
  min-height: 0;
  overflow: hidden;
}

/* Widen map when join form is hidden; sidebar is only a narrow strip with the Show button */
.content.content--join-collapsed {
  grid-template-columns: auto 1fr;
}

.join-panel {
  background: var(--card);
  border-right: 1px solid var(--line);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.join-panel h1 {
  margin: 0;
  font-size: 22px;
}

.join-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.join-panel.collapsed {
  gap: 0;
  align-self: start;
  padding: 8px;
  width: min-content;
  min-width: 0;
  max-width: 96px;
  box-sizing: border-box;
}

.join-panel.collapsed #joinPanelBody {
  display: none;
}

.join-panel.collapsed .join-panel-header h1 {
  display: none;
}

.join-panel.collapsed .join-panel-header {
  justify-content: center;
  gap: 0;
  margin: 0;
  width: 100%;
}

.join-panel.collapsed #joinPanelToggle {
  width: 100%;
  min-height: 44px;
  padding: 10px 8px;
  font-size: 12px;
  white-space: nowrap;
}

.subtle,
.hint {
  color: var(--muted);
  margin: 0 0 8px;
  font-size: 13px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: #dbe7f3;
}

input {
  background: #0f1b29;
  border: 1px solid #334155;
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  outline: none;
}

input:focus {
  border-color: #5aa4ff;
}

.primary-btn,
.chip-btn {
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 600;
}

.primary-btn {
  background: var(--blue);
  color: #fff;
  margin-top: 4px;
}

.primary-btn.danger {
  background: var(--danger);
}

.chip-btn {
  background: #253446;
  color: #fff;
}

.chip-btn.danger {
  background: var(--danger);
}

.map-panel {
  position: relative;
  min-height: 0;
  overflow: hidden;
  z-index: 1;
}

#map {
  width: 100%;
  height: 100%;
  min-height: 0;
}

.crew-sheet {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 8px;
  z-index: 4;
  max-width: 480px;
  margin-left: auto;
  margin-right: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  color: var(--text);
}

.crew-sheet[hidden] {
  display: none !important;
}

.crew-sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px 0;
  gap: 10px;
}

.crew-sheet-badge {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #1296e0;
}

.crew-sheet-close {
  appearance: none;
  border: none;
  background: #253446;
  color: #e5e7eb;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.crew-sheet-close:hover {
  background: #31455e;
}

.crew-sheet-body {
  padding: 8px 12px 12px;
}

.crew-sheet-name {
  font-size: 18px;
  font-weight: 700;
  color: #f1f5f9;
  margin-bottom: 6px;
}

.crew-sheet-lines {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
}

.crew-sheet-line {
  font-size: 13px;
  color: var(--muted);
}

.crew-sheet-nav {
  width: 100%;
  appearance: none;
  border: none;
  border-radius: 999px;
  padding: 10px 14px;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  background: #3498db;
  color: #fff;
}

.crew-sheet-nav:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.bottom-bar {
  position: relative;
  z-index: 20;
  flex-shrink: 0;
  border-top: 1px solid var(--line);
  background: #111b28;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  padding: 10px 14px;
  gap: 12px;
}

.metrics {
  display: flex;
  gap: 14px;
  color: #d7e4f2;
  font-size: 13px;
  flex: 1 1 auto;
  min-width: 0;
}

.footer-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

@media (max-width: 900px) {
  .telemetry-main {
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: auto auto;
    padding: 8px 10px;
  }

  .telemetry-actions {
    grid-column: 1 / -1;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    min-width: 0;
    width: 100%;
  }

  .telemetry-device {
    align-items: flex-end;
  }

  .telemetry-value {
    font-size: 18px;
  }

  .content {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    position: relative;
    min-height: 0;
    overflow: hidden;
  }

  .join-panel {
    position: absolute;
    top: 8px;
    left: 8px;
    right: 8px;
    z-index: 3;
    border: 1px solid #31455e;
    border-radius: 12px;
    background: rgba(27, 38, 53, 0.94);
    backdrop-filter: blur(4px);
    padding: 12px;
    max-height: none;
    overflow: visible;
  }

  .join-panel h1 {
    font-size: 18px;
  }

  .join-panel .subtle {
    margin-bottom: 4px;
  }

  .join-panel label {
    font-size: 12px;
    gap: 4px;
  }

  .join-panel input {
    padding: 8px 9px;
  }

  .join-panel .primary-btn {
    padding: 9px 10px;
    margin-top: 2px;
  }

  .join-panel.collapsed {
    right: auto;
    width: min-content;
    max-width: 96px;
    min-width: 0;
    padding: 8px;
  }

  .map-panel {
    flex: 1 1 auto;
    min-height: 0;
    height: auto;
    overflow: hidden;
  }

  .bottom-bar {
    flex-wrap: nowrap;
    align-items: center;
    justify-content: flex-start;
    padding: 8px 10px;
  }

  .chip-btn {
    padding: 8px 10px;
    font-size: 12px;
  }

  .metrics {
    flex: 1 1 auto;
    min-width: 0;
    justify-content: flex-start;
    font-size: 12px;
  }

  .footer-right {
    margin-left: auto;
    flex-shrink: 0;
  }

  .topbar {
    padding: 0 10px;
    min-height: 60px;
  }

  .title {
    font-size: 16px;
  }

  .topbar-center {
    gap: 8px;
  }

  .topbar-logo {
    width: 24px;
    height: 24px;
  }

  .status-pill {
    font-size: 11px;
    padding: 5px 8px;
  }
}

@media (max-width: 520px) {
  .join-panel {
    padding: 10px;
  }

  .join-panel h1 {
    font-size: 16px;
  }

  .join-panel .subtle,
  .join-panel .hint {
    display: none;
  }

  #joinPanelBody {
    display: grid;
    gap: 6px;
  }

  .metrics {
    gap: 10px;
  }

  .title {
    font-size: 15px;
  }

  .topbar-logo {
    width: 22px;
    height: 22px;
  }

  .topbar-right {
    gap: 6px;
  }
}
