:root {
  --bg: #e6edf5;
  --surface: #ffffff;
  --surface-2: #f5f8fc;
  --text: #0f172a;
  --muted: #4a5568;
  --border: #cbd5e1;
  --accent: #005f73;
  --accent-2: #1f6feb;
  --danger: #b42318;
  --warning: #b54708;
  --success: #067647;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
  --tab-height: 68px;
}

body {
  margin: 0;
  font-family: "Segoe UI", "SF Pro Text", "Helvetica Neue", sans-serif;
  background:
    radial-gradient(circle at 12% 12%, rgba(0, 95, 115, 0.18), transparent 42%),
    radial-gradient(circle at 88% 5%, rgba(31, 111, 235, 0.17), transparent 38%),
    var(--bg);
  color: var(--text);
}

.protocol-warning {
  margin: 0.8rem;
  border: 1px solid #fda29b;
  background: #fef3f2;
  color: #7a271a;
  border-radius: 10px;
  padding: 0.7rem 0.8rem;
  font-size: 0.9rem;
}

* {
  box-sizing: border-box;
}

#app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 900;
  background: rgba(255, 255, 255, 0.93);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  padding: 0.55rem 0.9rem calc(0.5rem + env(safe-area-inset-top));
}

.topbar-main {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
}

#flight-title {
  margin: 0;
  font-size: 1rem;
  letter-spacing: 0.015em;
}

.status-wrap {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  font-size: 0.73rem;
  font-weight: 700;
  padding: 0.26rem 0.6rem;
}

.pill-yellow {
  background: #fef3c7;
  color: #7a2e0e;
}

.pill-blue {
  background: #dbeafe;
  color: #1d4ed8;
}

.pill-red {
  background: #fee4e2;
  color: #b42318;
}

.pill-green {
  background: #dcfae6;
  color: #067647;
}

.topbar-actions {
  margin-top: 0.5rem;
  display: flex;
  gap: 0.45rem;
  overflow-x: auto;
  padding-bottom: 0.2rem;
}

.btn {
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 0.55rem 0.78rem;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
}

.btn:active {
  transform: translateY(1px);
}

.btn-accent {
  background: linear-gradient(140deg, var(--accent), #0a9396);
  color: #fff;
  border-color: transparent;
}

.btn.btn-compact {
  min-height: 32px;
  padding: 0.28rem 0.58rem;
  font-size: 0.76rem;
  border-radius: 9px;
}

.file-btn {
  display: inline-flex;
  align-items: center;
}

.layout {
  display: flex;
  flex: 1;
  min-height: 0;
}

.sidebar {
  display: none;
  width: 220px;
  border-right: 1px solid var(--border);
  background: var(--surface-2);
  padding: 0.65rem;
}

.tab-btn {
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0.58rem 0.75rem;
  cursor: pointer;
}

.tab-btn.active {
  background: rgba(0, 95, 115, 0.13);
  border-color: rgba(0, 95, 115, 0.35);
}

.content {
  flex: 1;
  min-width: 0;
  min-height: 0;
  position: relative;
}

.tab-panel {
  display: none;
  height: calc(100dvh - 162px - var(--tab-height));
  min-height: 380px;
}

.tab-panel.active {
  display: block;
}

.panel-scroll {
  height: 100%;
  overflow: auto;
  padding: 0.95rem;
  padding-bottom: calc(1rem + env(safe-area-inset-bottom));
}

.map-wrap {
  position: relative;
  height: 100%;
}

#map {
  height: 100%;
  width: 100%;
}

.floating-route-panel {
  position: absolute;
  left: 0.6rem;
  right: 0.6rem;
  bottom: 0.9rem;
  z-index: 550;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  max-height: 45%;
  overflow: hidden;
}

.route-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  padding: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.route-panel-header h2 {
  margin: 0;
  font-size: 0.95rem;
}

.route-panel-header > div {
  display: flex;
  gap: 0.3rem;
}

.waypoint-list {
  overflow: auto;
  max-height: min(38dvh, 330px);
  padding: 0.4rem;
}

.mobile-view-btn,
.mobile-route-launch {
  display: none;
}

.waypoint-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 0.5rem;
  margin-bottom: 0.4rem;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.35rem;
}

.waypoint-item.dragging {
  opacity: 0.6;
}

.waypoint-item strong {
  font-size: 0.92rem;
}

.waypoint-meta {
  color: var(--muted);
  font-size: 0.78rem;
}

.waypoint-actions {
  display: flex;
  gap: 0.25rem;
}

.icon-btn {
  min-height: 38px;
  min-width: 38px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
}

.card-grid {
  display: grid;
  gap: 0.85rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.8rem;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.05);
}

.card h3,
.card h4 {
  margin-top: 0;
  margin-bottom: 0.55rem;
}

.form-grid {
  display: grid;
  gap: 0.68rem;
}

label,
.field {
  display: grid;
  gap: 0.3rem;
  font-size: 0.84rem;
  color: var(--muted);
}

input,
select,
textarea {
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  padding: 0.55rem 0.7rem;
  font-size: 0.92rem;
}

textarea {
  min-height: 84px;
}

textarea.procedure-textarea {
  min-height: 44px;
  resize: none;
  overflow: hidden;
  line-height: 1.35;
}

.inline-control {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 44px;
  color: var(--text);
}

.inline-control input[type="checkbox"] {
  min-height: auto;
  height: 20px;
  width: 20px;
}

.row {
  display: grid;
  gap: 0.65rem;
}

.row.two {
  grid-template-columns: 1fr 1fr;
}

.row.three {
  grid-template-columns: repeat(3, 1fr);
}

.small-muted {
  color: var(--muted);
  font-size: 0.8rem;
}

.navlog-cards {
  display: grid;
  gap: 0.6rem;
}

.navlog-leg {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  padding: 0.72rem;
}

.navlog-leg h4 {
  margin: 0;
  font-size: 0.95rem;
}

.navlog-leg .metrics {
  margin-top: 0.45rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem 0.6rem;
  font-size: 0.84rem;
}

.navlog-table-wrap {
  overflow: auto;
}

.navlog-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
}

.navlog-table th,
.navlog-table td {
  border-bottom: 1px solid var(--border);
  padding: 0.35rem;
  text-align: left;
}

.value-lg {
  font-size: 1.25rem;
  font-weight: 800;
}

.disclaimer {
  border: 1px solid #fedf89;
  background: #fffaeb;
  color: #7a2e0e;
  border-radius: 10px;
  padding: 0.58rem 0.7rem;
  font-size: 0.83rem;
}

.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--tab-height) + 12px + env(safe-area-inset-bottom));
  background: rgba(15, 23, 42, 0.92);
  color: #fff;
  padding: 0.6rem 0.85rem;
  border-radius: 10px;
  font-size: 0.83rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 1200;
}

.toast.show {
  opacity: 1;
}

.bottom-tabs {
  position: sticky;
  bottom: 0;
  z-index: 920;
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 0.25rem;
  border-top: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.98);
  padding: 0.3rem 0.25rem calc(0.35rem + env(safe-area-inset-bottom));
  height: var(--tab-height);
}

.bottom-tabs .tab-btn {
  padding: 0.35rem 0.2rem;
  font-size: 0.73rem;
  line-height: 1.1;
}

.modal {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0;
  width: min(92vw, 480px);
}

.modal::backdrop {
  background: rgba(2, 6, 23, 0.5);
}

.modal-form {
  padding: 0.85rem;
  display: grid;
  gap: 0.62rem;
}

menu {
  display: flex;
  justify-content: flex-end;
  gap: 0.45rem;
  margin: 0;
  padding: 0;
}

.wp-marker span {
  display: block;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid #f8fafc;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.35);
}

.gps-aircraft-marker {
  background: transparent;
  border: none;
}

.gps-aircraft-wrap {
  width: 34px;
  height: 34px;
  transform-origin: 50% 50%;
}

.gps-aircraft-svg {
  width: 34px;
  height: 34px;
  display: block;
  overflow: visible;
}

.gps-aircraft-shadow {
  fill: rgba(2, 6, 23, 0.38);
}

.gps-aircraft-body {
  fill: #f8fafc;
  stroke: #0f172a;
  stroke-width: 1.8;
  stroke-linejoin: round;
}

.gps-aircraft-wing {
  stroke: #0ea5e9;
  stroke-width: 2;
  stroke-linecap: round;
}

.gps-aircraft-center {
  fill: #ef4444;
}

.theme-dark .gps-aircraft-body {
  fill: #f1f5f9;
  stroke: #020617;
}

.leg-label-chip {
  min-height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 0.45rem;
  border-radius: 999px;
  border: 1px solid rgba(15, 23, 42, 0.25);
  background: rgba(255, 255, 255, 0.9);
  color: #0f172a;
  font-size: 0.7rem;
  font-weight: 700;
  white-space: nowrap;
  backdrop-filter: blur(3px);
}

.theme-dark .leg-label-chip {
  background: rgba(17, 24, 39, 0.92);
  color: #e5e7eb;
  border-color: rgba(203, 213, 225, 0.35);
}

.leg-popup {
  font-size: 0.82rem;
  line-height: 1.35;
}

.notam-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 22px;
  max-width: 120px;
  padding: 0 0.45rem;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--notam-color), #ffffff 15%);
  background: rgba(255, 255, 255, 0.92);
  color: color-mix(in srgb, var(--notam-color), #0f172a 25%);
  font-size: 0.67rem;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 1px 6px rgba(15, 23, 42, 0.25);
  pointer-events: auto;
}

.theme-dark .notam-chip {
  background: rgba(15, 23, 42, 0.9);
  color: #e2e8f0;
  border-color: color-mix(in srgb, var(--notam-color), #94a3b8 20%);
}

.airport-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 22px;
  min-width: 46px;
  max-width: 64px;
  padding: 0 0.42rem;
  border-radius: 999px;
  border: 1px solid #0b4f6c;
  background: rgba(255, 255, 255, 0.94);
  color: #0b4f6c;
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 1px 6px rgba(15, 23, 42, 0.25);
}

.theme-dark .airport-chip {
  background: rgba(15, 23, 42, 0.92);
  color: #93c5fd;
  border-color: #60a5fa;
}

.airspace-warning-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  min-height: 24px;
  min-width: 30px;
  padding: 0 0.5rem;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--airspace-color), #ffffff 18%);
  background: rgba(255, 255, 255, 0.95);
  color: color-mix(in srgb, var(--airspace-color), #0f172a 20%);
  font-size: 0.75rem;
  font-weight: 900;
  box-shadow: 0 1px 6px rgba(15, 23, 42, 0.25);
}

.airspace-warning-chip span {
  font-size: 0.66rem;
  opacity: 0.95;
}

.theme-dark .airspace-warning-chip {
  background: rgba(15, 23, 42, 0.92);
  color: #f8fafc;
  border-color: color-mix(in srgb, var(--airspace-color), #94a3b8 22%);
}

.quick-cards {
  display: grid;
  gap: 0.6rem;
}

.wx-explain-list {
  margin: 0.35rem 0 0;
  padding-left: 1rem;
  font-size: 0.8rem;
}

.wx-explain-list li {
  margin-bottom: 0.2rem;
}

.notam-list {
  margin-top: 0.6rem;
  display: grid;
  gap: 0.6rem;
}

.notam-card .row.two {
  grid-template-columns: 1.1fr 0.9fr;
}

.notam-brief-list {
  margin: 0.6rem 0;
  display: grid;
  gap: 0.5rem;
}

.route-warning-list {
  margin-top: 0.35rem;
  display: grid;
  gap: 0.35rem;
}

.route-warning-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.45rem;
}

.route-warning-row span {
  flex: 1;
  min-width: 0;
}

.route-warning-row .btn {
  flex: 0 0 auto;
}

.route-warning-more {
  margin-top: 0.1rem;
}

.route-warning-more summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.8rem;
}

.route-warning-more-rows {
  margin-top: 0.35rem;
  display: grid;
  gap: 0.35rem;
}

.waypoint-warning-list {
  margin-top: 0.35rem;
}

.navlog-warning-list {
  margin-top: 0.45rem;
}

.inflight-warning-list {
  margin-top: 0.5rem;
}
.cgenv {
  width: 100%;
  max-width: 360px;
  height: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #f8fafc;
}

@media (min-width: 980px) {
  .sidebar {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
  }

  .bottom-tabs {
    display: none;
  }

  .tab-panel {
    height: calc(100dvh - 128px);
  }

  .floating-route-panel {
    left: auto;
    right: 1rem;
    width: min(390px, 40%);
  }

  .row.two {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 979px) {
  .topbar {
    padding: 0.35rem 0.55rem calc(0.3rem + env(safe-area-inset-top));
  }

  #flight-title {
    display: none;
  }

  .topbar-main {
    gap: 0.35rem;
  }

  .status-wrap {
    justify-content: flex-start;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 0.25rem;
  }

  .status-wrap .pill {
    white-space: nowrap;
    font-size: 0.66rem;
    padding: 0.2rem 0.45rem;
  }

  .topbar-actions {
    margin-top: 0.28rem;
    gap: 0.28rem;
    padding-bottom: 0.05rem;
  }

  .topbar-actions .btn {
    min-height: 36px;
    padding: 0.38rem 0.56rem;
    font-size: 0.78rem;
    border-radius: 10px;
    white-space: nowrap;
  }

  .tab-panel {
    height: 100%;
    min-height: 0;
  }

  .tab-panel:not([data-tab-panel="map"]) .panel-scroll {
    width: 100%;
    height: 100%;
    padding: 0.55rem;
    overflow-x: hidden;
  }

  .tab-panel:not([data-tab-panel="map"]) .card-grid,
  .tab-panel:not([data-tab-panel="map"]) .quick-cards {
    grid-template-columns: minmax(0, 1fr);
  }

  .tab-panel:not([data-tab-panel="map"]) .row.two,
  .tab-panel:not([data-tab-panel="map"]) .row.three,
  .tab-panel:not([data-tab-panel="map"]) .navlog-leg .metrics,
  .tab-panel:not([data-tab-panel="map"]) .notam-card .row.two {
    grid-template-columns: minmax(0, 1fr);
  }

  .tab-panel:not([data-tab-panel="map"]) .row.two > *,
  .tab-panel:not([data-tab-panel="map"]) .row.three > * {
    min-width: 0;
  }

  .map-wrap.mobile-map-only .floating-route-panel {
    display: none;
  }

  .map-wrap.mobile-map-only .mobile-route-launch {
    display: inline-flex;
    position: absolute;
    right: 0.75rem;
    bottom: 0.95rem;
    z-index: 560;
  }

  .map-wrap.mobile-route-only #map {
    display: none;
  }

  .map-wrap.mobile-route-only .floating-route-panel {
    position: absolute;
    left: 0.5rem;
    right: 0.5rem;
    top: 0.5rem;
    bottom: 0.5rem;
    max-height: none;
    display: flex;
    flex-direction: column;
  }

  .map-wrap.mobile-route-only .waypoint-list {
    flex: 1;
    max-height: none;
  }

  .mobile-view-btn {
    display: inline-flex;
  }
}

.theme-dark {
  --bg: #0b1220;
  --surface: #0f172a;
  --surface-2: #162235;
  --text: #f8fafc;
  --muted: #dbe5f1;
  --border: #334155;
  --shadow: 0 8px 24px rgba(2, 6, 23, 0.5);
}

.theme-dark .topbar,
.theme-dark .bottom-tabs,
.theme-dark .floating-route-panel {
  background: rgba(17, 24, 39, 0.93);
}

.theme-dark .panel-scroll,
.theme-dark .card,
.theme-dark .navlog-leg,
.theme-dark .waypoint-item,
.theme-dark .route-panel-header,
.theme-dark .modal-form {
  color: var(--text);
}

.theme-dark .small-muted {
  color: var(--muted);
}

.theme-dark .btn:not(.btn-accent),
.theme-dark .icon-btn,
.theme-dark .tab-btn {
  background: #0f172a;
  color: var(--text);
  border-color: #475569;
}

.theme-dark input,
.theme-dark select,
.theme-dark textarea {
  background: #0b1324;
  color: var(--text);
  border-color: #475569;
}

.theme-dark input::placeholder,
.theme-dark textarea::placeholder {
  color: #93a4b8;
  opacity: 1;
}

.theme-dark select option {
  background: #0b1324;
  color: var(--text);
}

.theme-dark .navlog-table th,
.theme-dark .navlog-table td {
  color: var(--text);
}

.theme-dark a {
  color: #93c5fd;
}

.theme-dark .disclaimer {
  background: #3b1d07;
  border-color: #7a2e0e;
  color: #fbbf24;
}

.high-contrast {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f0f0f0;
  --text: #000000;
  --muted: #111111;
  --border: #000000;
}

@media print {
  body {
    background: #fff;
  }

  .topbar,
  .sidebar,
  .bottom-tabs,
  .floating-route-panel,
  #map,
  #tab-map,
  #tab-settings,
  #tab-inflight,
  .btn,
  .icon-btn,
  .toast {
    display: none !important;
  }

  .layout,
  .content,
  .tab-panel,
  .panel-scroll {
    display: block !important;
    height: auto !important;
    overflow: visible !important;
    padding: 0 !important;
  }

  #tab-brief,
  #tab-navlog,
  #tab-fuel,
  #tab-wb,
  #tab-plan,
  #tab-notams {
    display: block !important;
    page-break-inside: avoid;
  }

  .card {
    box-shadow: none;
    border-color: #777;
    break-inside: avoid;
  }
}

