/* ============ Fuselage rendering ============ */
.fuselage-wrap {
  --seat-size: 1.5rem;
  --seat-gap: 0.25rem;
  --row-step: calc(var(--seat-size) + var(--seat-gap));
  --nose-h: 4.5rem;
  --wall: 3px;
  position: relative;
  width: fit-content;
  margin: 0 auto;
  padding: 0 1.5rem;
}
@media (min-width: 640px) {
  .fuselage-wrap { --seat-size: 2.25rem; --nose-h: 6.5rem; padding: 0 5rem; }
}
@media (min-width: 1024px) {
  .fuselage-wrap { --seat-size: 2.5rem; --nose-h: 7rem; }
}

.fuselage-nose {
  height: var(--nose-h);
  border: var(--wall) solid #b6bec9;
  border-bottom: none;
  border-radius: 50% 50% 0 0 / 92% 92% 0 0;
  background: linear-gradient(to bottom, #f8fafc, #f1f5f9);
  position: relative;
  overflow: hidden;
}
.fuselage-cockpit {
  position: absolute;
  top: 12%;
  left: 50%;
  transform: translateX(-50%);
  width: 42%;
  height: 20%;
  background: #64748b;
  border-radius: 50% 50% 40% 40% / 100% 100% 60% 60%;
  opacity: 0.85;
}
.fuselage-cabin {
  position: relative;
  border-left: var(--wall) solid #b6bec9;
  border-right: var(--wall) solid #b6bec9;
  background: #f1f5f9;
  padding: 0 0.625rem;
}
.fuselage-cabin .seat-grid { width: fit-content; margin: 0 auto; }
.fuselage-tail {
  height: calc(var(--nose-h) * 0.55);
  border: var(--wall) solid #b6bec9;
  border-top: none;
  border-radius: 0 0 50% 50% / 0 0 88% 88%;
  background: linear-gradient(to bottom, #f1f5f9, #e2e8f0);
}

/* Seat shape: rounded backrest band + armrests so tiles read as seats
   (AeroLOPA / SeatMaps-style) rather than plain boxes. Pure CSS. */
.seat-grid div[data-seat] { border-radius: 30% 30% 12% 12% / 22% 22% 10% 10% !important; }
.seat-grid div[data-seat]::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 24%;
  max-height: 12px;
  border-radius: inherit;
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  background: currentColor;
  opacity: 0.16;
  pointer-events: none;
}
.seat-grid div[data-seat]::after {
  content: '';
  position: absolute;
  top: 30%;
  bottom: 10%;
  left: 2px;
  right: 2px;
  border-left: 2px solid currentColor;
  border-right: 2px solid currentColor;
  border-radius: 2px;
  opacity: 0.18;
  pointer-events: none;
}
.seat-grid div[data-seat].seat-q-good { box-shadow: inset 0 -3px 0 #059669 !important; }
.seat-grid div[data-seat].seat-q-avoid { box-shadow: inset 0 -3px 0 #f59e0b !important; }
.seat-quality-key { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 14px; margin: 0 0 10px; font-size: 11px; color: #475569; }
.seat-quality-key span { display: inline-flex; align-items: center; gap: 5px; }
.sqk { display: inline-block; width: 14px; height: 12px; border-radius: 4px 4px 2px 2px; background: #f1f5f9; border: 1px solid #cbd5e1; }
.sqk-good { box-shadow: inset 0 -3px 0 #059669; }
.sqk-avoid { box-shadow: inset 0 -3px 0 #f59e0b; }
.seat-grid div[data-seat] .safe-seat-label { padding-top: 14%; font-weight: 700; }

/* Row numbers in the hull gutters (AeroLOPA-style; tiles carry letters only) */
.fuselage-row-num {
  position: absolute;
  width: 1.2rem;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 8px;
  font-weight: 500;
  line-height: 1;
  color: #94a3b8;
  pointer-events: none;
}
.fuselage-row-num-l { left: calc(-1 * var(--wall) - 1.4rem); text-align: right; }
.fuselage-row-num-r { right: calc(-1 * var(--wall) - 1.4rem); text-align: left; }
@media (min-width: 640px) { .fuselage-row-num { font-size: 10px; } }

/* Window ticks along the hull */
.fuselage-window-tick {
  position: absolute;
  width: 3px;
  height: calc(var(--seat-size) * 0.55);
  border-radius: 2px;
  background: #9aa6b5;
  display: none;
}
@media (min-width: 640px) { .fuselage-window-tick { display: block; } }

/* Emergency exit doors on the walls */
.fuselage-exit {
  position: absolute;
  width: 0.5rem;
  height: var(--seat-size);
  background: #dc2626;
  z-index: 2;
}
.fuselage-exit-left { left: calc(-1 * var(--wall)); border-radius: 3px 0 0 3px; }
.fuselage-exit-right { right: calc(-1 * var(--wall)); border-radius: 0 3px 3px 0; }

/* Bulkhead divider between adjacent cabins */
.fuselage-bulkhead {
  position: absolute;
  left: 0.25rem;
  right: 0.25rem;
  height: 2px;
  background: #cbd5e1;
}

/* Wings */
.fuselage-wing {
  position: absolute;
  width: 3.5rem;
  background: linear-gradient(to bottom, #cdd5de, #aeb8c4);
  display: none;
  z-index: 0;
}
@media (min-width: 640px) { .fuselage-wing { display: block; } }
.fuselage-wing-left {
  left: 1.5rem;
  clip-path: polygon(100% 0, 100% 100%, 0 100%, 0 62%);
}
.fuselage-wing-right {
  right: 1.5rem;
  clip-path: polygon(0 0, 100% 62%, 100% 100%, 0 100%);
}

/* Cabin class brackets (right margin) */
.cabin-bracket {
  position: absolute;
  right: 0;
  width: 1.1rem;
  border: 2px solid #94a3b8;
  border-left: none;
  border-radius: 0 4px 4px 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1;
}
@media (min-width: 640px) { .cabin-bracket { display: flex; } }
.cabin-bracket span {
  writing-mode: vertical-rl;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: #64748b;
  white-space: nowrap;
  background: inherit;
}

/* Per-cabin spec chips above the fuselage */
.cabin-spec-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  margin-bottom: 0.875rem;
}
.cabin-spec-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.625rem;
  border: 1px solid #e4e4e7;
  border-radius: 9999px;
  font-size: 0.75rem;
  color: #3f3f46;
  background: #fff;
}
@media (max-width: 639px) {
  /* Keep the last chip clear of the floating zoom buttons. */
  .cabin-spec-chips { padding-right: 3rem; }
}
.cabin-spec-chip strong { font-weight: 600; color: #18181b; }
.cabin-spec-chip-dims { color: #71717a; }
.cabin-spec-chip-swatch {
  width: 0.625rem;
  height: 0.625rem;
  border-radius: 3px;
  border: 1px solid rgba(0,0,0,0.15);
  flex-shrink: 0;
}
.cabin-swatch-first { background: #f3e8ff; border-color: #a855f7; }
.cabin-swatch-business { background: #dbeafe; border-color: #3b82f6; }
.cabin-swatch-premium_economy { background: #cffafe; border-color: #06b6d4; }
.cabin-swatch-economy { background: #dcfce7; border-color: #4ade80; }

/* Facility tiles (galleys, lavatories, closets...) */
.fuselage-facility {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 1.5px solid;
  border-radius: 4px;
  font-size: 8px;
  font-weight: 600;
  letter-spacing: 0.02em;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  cursor: default;
  overflow: hidden;
}
.fuselage-facility svg {
  width: 60%;
  height: 60%;
  max-width: 1rem;
  max-height: 1rem;
  flex-shrink: 0;
}
@media (min-width: 640px) { .fuselage-facility { font-size: 9px; } }
@media (min-width: 1024px) { .fuselage-facility { font-size: 10px; } }

/* Allow horizontal scroll when the fuselage is wider than its card */
.seatmap-container {
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  container-type: inline-size;
}
/* Narrow cards (e.g. flight page next to sidebar): drop the decorative
   wings/brackets so the fuselage itself fits without scrolling */
@container (max-width: 48rem) {
  .fuselage-wing, .cabin-bracket { display: none !important; }
  .fuselage-wrap { padding: 0 0.75rem; }
}
@media (max-width: 639px) {
  .seatmap-container { padding-bottom: 0.5rem; }
  .seat-grid div[data-seat] span {
    font-size: 0.625rem !important;
  }
}

/* Amenity badges in cabin chips */
.cabin-amenity-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 500;
  background: #f1f5f9;
  color: #475569;
}
.cabin-amenity-badge svg {
  width: 0.875rem;
  height: 0.875rem;
}

.grid-container {
  width: fit-content;
  margin: 0 auto;
  transform-origin: left top;
}

/* Fullscreen styles */
.seatmap-fullscreen-active {
  overflow: hidden !important;
}

.seatmap-fullscreen-container {
  position: fixed !important;
  inset: 0 !important;
  z-index: 9999 !important;
  background: #f9fafb !important;
  padding: 1rem !important;
  overflow: auto !important;
}

/* Safe area support for notched devices */
@supports (padding: env(safe-area-inset-top)) {
  .seatmap-fullscreen-container {
    padding-top: max(1rem, env(safe-area-inset-top)) !important;
    padding-bottom: max(1rem, env(safe-area-inset-bottom)) !important;
  }
}

/* Panel positioning on desktop */
@media (min-width: 640px) {
  .seat-detail-panel [data-seat-detail-target="panel"] {
    position: fixed;
    width: 400px;
    max-height: 500px;
  }
}

/* Safe area padding for mobile */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .seat-detail-panel [data-seat-detail-target="panel"] {
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* Seatmap-first layout - ensures seatmap is visible above the fold */
.seatmap-hero {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.seatmap-hero-main {
  width: 100%;
}

.seatmap-hero-sidebar {
  width: 100%;
}

/* Desktop: side-by-side with seatmap taking more space */
@media (min-width: 768px) {
  .seatmap-hero {
    flex-direction: row;
    gap: 1.5rem;
    align-items: stretch;
  }
  .seatmap-hero-main {
    width: 60%;
    order: 1;
  }
  .seatmap-hero-sidebar {
    width: 40%;
    order: 2;
    /* Pin the shorter column so it stays beside the tall seatmap instead of leaving a dead gutter */
    align-self: flex-start;
    position: sticky;
    top: 1rem;
  }
}
@media (min-width: 1024px) {
  .seatmap-hero-main {
    width: 65%;
  }
  .seatmap-hero-sidebar {
    width: 35%;
  }
}

.safe-seat {
  width: var(--seat-size);
  height: var(--seat-size);
  position: relative;
  background: var(--seat-bg);
  color: var(--seat-text);
  border: 1.5px solid var(--seat-border);
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-weight: 500;
}
.safe-seat.seat-cabin-first { --seat-bg: #f3e8ff; --seat-border: #a855f7; --seat-text: #6b21a8; }
.safe-seat.seat-cabin-business { --seat-bg: #dbeafe; --seat-border: #3b82f6; --seat-text: #1e40af; }
.safe-seat.seat-cabin-premium-economy { --seat-bg: #cffafe; --seat-border: #06b6d4; --seat-text: #155e75; }
.safe-seat.seat-cabin-economy { --seat-bg: #dcfce7; --seat-border: #4ade80; --seat-text: #166534; }
.safe-seat.seat-premium { --seat-border: #2563eb; }
.safe-seat.seat-status-occupied { --seat-bg: #e4e4e7; --seat-border: #e4e4e7; --seat-text: #a1a1aa; }
.safe-seat.seat-status-blocked {
  --seat-bg: repeating-linear-gradient(-45deg, #e4e4e7 0 4px, #fff 4px 6px);
  --seat-border: #d4d4d8;
  --seat-text: #a1a1aa;
}
