/* Base reset and typography */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  background: #f8f9fa;
  color: #1a1a1a;
  overflow: hidden;
}

/* Map iframe - full screen background */
#mapFrame {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: none;
  z-index: 1;
}

/* ========================================
   FLOATING CONTROLS
   ======================================== */

#floatingControls {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  z-index: 100;
}

#floatingControls > * {
  pointer-events: auto;
}

/* Logo Badge - Top Center */
#logoBadge {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 14px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
  padding: 12px 20px 12px 12px;
  border-radius: 32px;
  box-shadow: 0 2px 16px rgba(0, 0, 0, 0.12);
}

#logoBadge img {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  object-fit: cover;
}

#logoBadge span {
  font-size: 18px;
  font-weight: 600;
  color: #003d7a;
  white-space: nowrap;
}

@media (max-width: 480px) {
  #logoBadge {
    padding: 10px 16px 10px 10px;
    gap: 10px;
  }
  #logoBadge img {
    width: 48px;
    height: 48px;
  }
  #logoBadge span {
    font-size: 15px;
  }
}

/* ========================================
   LAYERS DROPDOWN - Top Right
   ======================================== */

#layersControl {
  position: absolute;
  top: 16px;
  right: 16px;
}

#layersToggle {
  display: flex;
  align-items: center;
  gap: 8px;
  background: white;
  border: none;
  padding: 10px 14px;
  border-radius: 10px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: #333;
  transition: all 0.2s;
}

#layersToggle:hover {
  background: #f0f6ff;
  color: #0066cc;
}

#layersToggle svg {
  flex-shrink: 0;
}

#layersToggle .chevron {
  transition: transform 0.2s;
}

#layersControl.open #layersToggle .chevron {
  transform: rotate(180deg);
}

#layersDropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: white;
  border-radius: 10px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  padding: 8px 0;
  min-width: 160px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all 0.2s;
}

#layersControl.open #layersDropdown {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.layer-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  cursor: pointer;
  font-size: 13px;
  color: #333;
  transition: background 0.15s;
}

.layer-option:hover {
  background: #f0f6ff;
}

.layer-option input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: #0066cc;
  cursor: pointer;
}

/* ========================================
   TOP ROUTES CARD - Top Center (below logo)
   ======================================== */

#topRoutesCard {
  position: absolute;
  top: 105px;
  left: 50%;
  transform: translateX(-50%);
  width: 200px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
  border-radius: 10px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.12);
  overflow: hidden;
  transition: all 0.3s ease;
}

@media (max-width: 768px) {
  #topRoutesCard {
    top: 95px;
    width: 180px;
  }
}

#topRoutesToggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 12px 16px;
  background: linear-gradient(135deg, #001f3f 0%, #003d7a 100%);
  border: none;
  cursor: pointer;
  color: white;
  font-size: 13px;
  font-weight: 600;
  text-align: left;
}

#topRoutesToggle .badge {
  background: rgba(255, 255, 255, 0.2);
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  margin-left: auto;
  margin-right: 8px;
}

#topRoutesToggle .chevron {
  transition: transform 0.2s;
  flex-shrink: 0;
}

#topRoutesCard.open #topRoutesToggle .chevron {
  transform: rotate(180deg);
}

#topRoutesBody {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}

#topRoutesCard.open #topRoutesBody {
  max-height: 250px;
}

#topFlightsList {
  list-style: none;
  padding: 8px;
  margin: 0;
  max-height: 234px;
  overflow-y: auto;
}

#topFlightsList::-webkit-scrollbar {
  width: 5px;
}

#topFlightsList::-webkit-scrollbar-thumb {
  background: #d0d0d0;
  border-radius: 3px;
}

#topFlightsList li {
  padding: 10px 12px;
  margin-bottom: 4px;
  background: #f8f9fa;
  border-left: 3px solid #0066cc;
  border-radius: 6px;
  font-size: 13px;
  color: #333;
  cursor: pointer;
  transition: all 0.2s;
}

#topFlightsList li:hover {
  background: #e8f4ff;
  border-left-color: #003d7a;
}

#topFlightsList li:last-child {
  margin-bottom: 0;
}

/* ========================================
   BOTTOM SHEET
   ======================================== */

#bottomSheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: white;
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.1);
  z-index: 200;
  transition: transform 0.3s ease;
}

#dragHandle {
  display: flex;
  justify-content: center;
  padding: 12px 0 8px;
  cursor: grab;
}

#dragHandle span {
  width: 40px;
  height: 4px;
  background: #d0d0d0;
  border-radius: 2px;
}

#sheetContent {
  padding: 0 16px 20px;
}

/* Filter Chips Row */
#filterRow {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 12px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

#filterRow::-webkit-scrollbar {
  display: none;
}

.chip {
  padding: 10px 16px;
  border: 1px solid #e0e0e0;
  background: white;
  border-radius: 20px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: #444;
  transition: all 0.2s;
  white-space: nowrap;
  flex-shrink: 0;
}

.chip:hover {
  border-color: #0066cc;
  background: #f0f6ff;
  color: #0066cc;
}

.chip.active {
  background: #0066cc;
  color: white;
  border-color: #0066cc;
}

#customChip {
  border-style: dashed;
}

#customChip.active {
  border-style: solid;
}

/* Custom Date Section */
#customDateSection {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease, margin 0.3s ease;
  margin-bottom: 0;
}

#customDateSection.open {
  max-height: 80px;
  margin-bottom: 12px;
}

#customDateSection .date-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

#customDateSection .date-field {
  flex: 1;
}

#customDateSection .date-field label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: #666;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

#customDateSection .date-field input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #d0d0d0;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  transition: all 0.2s;
}

#customDateSection .date-field input:focus {
  outline: none;
  border-color: #0066cc;
  box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.1);
}

.btn-apply {
  padding: 10px 20px;
  background: #0066cc;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.btn-apply:hover {
  background: #0052a3;
}

.btn-apply:active {
  transform: scale(0.98);
}

/* Status Bar */
.status-bar {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  text-align: center;
  transition: all 0.3s;
}

.status-bar.loading {
  background: #fffbf0;
  border: 1px solid #ffd580;
  color: #8b5a00;
}

.status-bar.ready {
  background: #f0fdf4;
  border: 1px solid #86efac;
  color: #166534;
}

.status-bar.error {
  background: #fef2f2;
  border: 1px solid #fca5a5;
  color: #991b1b;
}

/* Data Credits */
#dataCredits {
  text-align: center;
  font-size: 10px;
  color: #888;
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px solid #eee;
}

#dataCredits a {
  color: #666;
  text-decoration: none;
}

#dataCredits a:hover {
  color: #0066cc;
  text-decoration: underline;
}

/* ========================================
   MOBILE BOTTOM SHEET DRAGGING
   ======================================== */

@media (max-width: 768px) {
  #bottomSheet {
    touch-action: none;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  #sheetContent {
    padding: 0 12px 16px;
  }

  #bottomSheet.dragging {
    transition: none;
  }

  #bottomSheet.expanded {
    transform: translateY(-60px);
  }

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

  .status-bar {
    font-size: 11px;
    padding: 8px 10px;
  }
}

/* ========================================
   WATERMARK - Bottom Center above date selector
   ======================================== */

#watermark {
  position: fixed;
  bottom: 220px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 150;
  background: rgba(0, 0, 0, 0.5);
  padding: 8px 16px;
  border-radius: 10px;
  backdrop-filter: blur(4px);
  text-align: center;
  transition: all 0.2s;
}

#watermark:hover {
  background: rgba(0, 0, 0, 0.7);
}

#watermark a {
  text-decoration: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

#watermark img {
  height: 50px;
  object-fit: contain;
}

#watermark .copyright {
  font-size: 12px;
  color: #b3d9ff;
}

@media (max-width: 768px) {
  #watermark {
    bottom: 145px;
    padding: 6px 10px;
  }

  #watermark img {
    height: 22px;
  }

  #watermark .copyright {
    font-size: 8px;
  }
}

/* ========================================
   ERROR MODAL
   ======================================== */

#errorBackdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.4);
  z-index: 2000;
  display: none;
}

#errorPopup {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: white;
  border-radius: 12px;
  padding: 28px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  z-index: 2001;
  max-width: 360px;
  width: 90%;
  display: none;
  text-align: center;
}

#errorPopup h3 {
  font-size: 16px;
  font-weight: 600;
  color: #991b1b;
  margin-bottom: 8px;
}

#errorMessage {
  font-size: 14px;
  color: #666;
  margin-bottom: 20px;
  line-height: 1.5;
}

#errorPopup button {
  padding: 12px 24px;
  border: none;
  background: #0066cc;
  color: white;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: all 0.2s;
}

#errorPopup button:hover {
  background: #0052a3;
}

/* ========================================
   DESKTOP ADJUSTMENTS
   ======================================== */

@media (min-width: 769px) {
  #bottomSheet {
    left: 50%;
    transform: translateX(-50%);
    max-width: 600px;
    border-radius: 20px 20px 0 0;
  }

  #dragHandle {
    display: none;
  }

  #sheetContent {
    padding: 16px 20px 20px;
  }

  #filterRow {
    justify-content: center;
  }

  #customDateSection.open {
    max-height: 60px;
  }

  #customDateSection .date-row {
    justify-content: center;
  }

  #customDateSection .date-field {
    flex: 0 1 150px;
  }
}
