:root {
  --ink: #21170f;
  --muted: #6f6255;
  --line: #e1c79d;
  --paper: #f4ead9;
  --panel: rgba(255, 250, 239, 0.94);
  --teal: #006b70;
  --red: #c91525;
  --amber: #cf8b2d;
  --green: #1c8f5a;
  --shadow: 0 24px 70px rgba(63, 37, 15, 0.2);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 0%, rgba(201, 21, 37, 0.12), transparent 34%),
    radial-gradient(circle at 92% 18%, rgba(0, 107, 112, 0.13), transparent 30%),
    linear-gradient(180deg, #f8edd9 0%, #efe0c7 48%, #f6f3ec 100%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

/* Full-screen map stage */
html,
body {
  height: 100%;
}

body {
  overflow: hidden; /* desktop: panels scroll internally */
}

#map {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: #cfe0dd;
}

#mapScrim {
  position: fixed;
  inset: 0;
  z-index: 1150;
  background: rgba(33, 23, 15, 0.35);
  backdrop-filter: blur(6px);
}

/* Top bar (Leaflet control panes top out around z-index 1000) */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1100;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  height: 56px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
  box-shadow: 0 8px 30px rgba(63, 37, 15, 0.12);
}

.brand {
  font-weight: 950;
  font-size: 1.05rem;
}

.topbar-account {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn.slim {
  min-height: 32px;
  padding: 0 10px;
  font-size: 0.82rem;
}

.feed {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
}

#feedDot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 0 6px rgba(208, 138, 29, 0.18);
}

#feedDot.live {
  background: #4de59b;
  box-shadow: 0 0 0 6px rgba(77, 229, 155, 0.18);
}

/* Floating overlay columns */
.overlay {
  position: fixed;
  top: 72px;
  z-index: 1050;
  display: grid;
  gap: 12px;
  max-height: calc(100dvh - 88px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.overlay-left {
  left: 16px;
  width: min(360px, 40vw);
}

.overlay-right {
  right: 16px;
  width: min(430px, 44vw);
}

/* Login gate becomes a centered floating card over the scrim */
.login-gate {
  position: fixed;
  z-index: 1200;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(560px, calc(100% - 32px));
  margin: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
}

.login-gate h2 {
  margin-bottom: 8px;
  font-size: clamp(1.5rem, 3vw, 2.2rem);
}

.owner-setup,
.login-gate .note {
  grid-column: 1 / -1;
}

.owner-setup {
  display: grid;
  gap: 8px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.owner-setup.needs-attention {
  border: 1px solid rgba(201, 21, 37, 0.45);
  border-radius: 8px;
  padding: 14px;
  background: rgba(255, 238, 212, 0.75);
  box-shadow: 0 0 0 3px rgba(201, 21, 37, 0.12);
}

.owner-setup .login-grid {
  grid-template-columns: minmax(0, 1fr) auto;
}

.app-content {
  display: grid;
  gap: 16px;
}

.planner {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(320px, 0.95fr);
  gap: 16px;
  align-items: start;
}

.panel,
.route-card,
.controller-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  backdrop-filter: blur(16px);
}

.panel {
  padding: 18px;
  box-shadow: var(--shadow);
  background-image:
    linear-gradient(135deg, rgba(255, 255, 255, 0.64), rgba(255, 250, 239, 0.9)),
    repeating-linear-gradient(45deg, rgba(0, 107, 112, 0.035) 0 7px, transparent 7px 14px);
}

.panel h2 {
  margin: 0 0 14px;
  font-size: 1.1rem;
  line-height: 1.2;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 14px;
}

.field {
  display: grid;
  gap: 7px;
}

label {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

select,
input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

select:focus,
input:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(0, 124, 132, 0.14);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef3f4;
}

.segmented button {
  min-height: 40px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 900;
}

.segmented button.active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 3px 12px rgba(23, 32, 38, 0.12);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.btn {
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0 14px;
  background: linear-gradient(135deg, var(--teal), #00949b);
  color: #fff;
  cursor: pointer;
  font-weight: 900;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn.secondary {
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
}

.btn.red {
  background: linear-gradient(135deg, var(--red), #e33b42);
}

.btn.vatsim {
  background: linear-gradient(135deg, #2d6cdf, #0b4fb7);
}

.side {
  display: grid;
  gap: 16px;
}

.result {
  min-height: 0;
}

.route-card {
  padding: 16px;
}

.airports {
  font-size: clamp(1.8rem, 4vw, 3rem);
  font-weight: 950;
  line-height: 1;
}

.recommendation {
  margin: 14px 0;
  border: 1px solid rgba(201, 21, 37, 0.28);
  border-radius: 8px;
  padding: 13px 14px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.88), rgba(255, 238, 212, 0.9)),
    repeating-linear-gradient(135deg, rgba(201, 21, 37, 0.045) 0 7px, transparent 7px 14px);
}

.recommendation span {
  display: block;
  color: var(--red);
  font-size: 0.74rem;
  font-weight: 900;
  text-transform: uppercase;
}

.recommendation strong {
  display: block;
  margin-top: 5px;
  font-size: 1.05rem;
  line-height: 1.35;
}

.recommendation p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  background: #edf4f4;
  color: #28464c;
  font-size: 0.82rem;
  font-weight: 900;
}

.chip.green {
  background: #e4f5ec;
  color: #17613d;
}

.chip.red {
  background: #fae7eb;
  color: #912036;
}

.chip.amber {
  background: #fff0d8;
  color: #87550d;
}

.facts {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 14px 0;
}

.flight-list {
  display: grid;
  gap: 8px;
  margin: 16px 0;
}

.section-label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.flight-option {
  width: 100%;
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) minmax(150px, auto);
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.flight-option:hover,
.flight-option.selected {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(201, 21, 37, 0.12);
}

.airline-mark {
  min-height: 34px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  background: #f1f5f6;
  color: var(--red);
  font-weight: 950;
}

.flight-main,
.flight-meta {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.flight-main strong {
  overflow-wrap: anywhere;
}

.flight-main small,
.flight-meta span {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.flight-meta {
  justify-items: end;
}

.selected-package {
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.fact {
  min-height: 70px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
}

.fact span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.fact strong {
  overflow-wrap: anywhere;
}

.controller-list {
  display: grid;
  gap: 8px;
}

.controller-card {
  padding: 12px;
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: start;
}

.controller-card strong {
  display: block;
}

.controller-card small,
.small {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.5;
}

.empty,
.note {
  border: 1px dashed #c5ced3;
  border-radius: 8px;
  padding: 14px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.72);
  line-height: 1.5;
}

.note {
  margin: 14px 0 0;
  border-style: solid;
  background: #fff3dd;
  color: #68451d;
}

.login-grid {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 10px;
}

details.coverage summary {
  cursor: pointer;
  font-weight: 900;
  font-size: 1rem;
}

details.coverage[open] summary {
  margin-bottom: 12px;
}

/* Plane + airport markers (Leaflet divIcons) */
.plane-icon {
  pointer-events: auto;
}

.plane-icon svg {
  display: block;
  width: 22px;
  height: 22px;
  fill: var(--teal);
  stroke: #fff;
  stroke-width: 0.75;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.35));
  transition: transform 0.4s linear;
}

.apt-marker {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--teal);
  border: 2px solid #fff;
  box-shadow: 0 0 0 2px rgba(0, 107, 112, 0.25);
}

.apt-marker.tn {
  background: var(--red);
  box-shadow: 0 0 0 2px rgba(201, 21, 37, 0.3);
}

.apt-marker.selected {
  box-shadow: 0 0 0 4px rgba(207, 139, 45, 0.55);
}

/* Leaflet popup skin to match the paper theme */
.leaflet-popup-content-wrapper {
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  backdrop-filter: blur(10px);
}

.leaflet-popup-tip {
  background: var(--panel);
}

.leaflet-container {
  font-family: inherit;
}

/* Weather block in the selected package */
.wx-block {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.wx-station {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.82);
}

.wx-station .wx-head {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 6px;
}

.wx-station pre {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 0.8rem;
  line-height: 1.45;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

@media (max-width: 880px) {
  body {
    overflow: auto;
  }

  .overlay {
    position: static;
    max-height: none;
    overflow: visible;
    width: auto;
    margin: 0 12px 12px;
  }

  #appContent {
    padding-top: calc(56px + 42dvh); /* keep ~42dvh of live map visible above the stacked cards */
  }

  .topbar .feed {
    display: none;
  }

  .login-gate,
  .planner,
  .grid,
  .login-grid,
  .facts,
  .flight-option {
    grid-template-columns: 1fr;
  }

  .login-gate {
    width: calc(100% - 24px);
  }

  .flight-meta {
    justify-items: start;
  }
}
