@import url("https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600&display=swap");

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden; /* prevents page scroll */
}

/* GLOBAL RESET */
* {
  box-sizing: border-box;
}

/* Dynamic viewport height (mobile-safe) */
:root {
  --appvh: 100vh;
} /* default */
@supports (height: 100dvh) {
  :root {
    --appvh: 100dvh;
  } /* modern browsers use dynamic vh */
}

/* Toolbox sizing vars */
:root {
  --tools-vertical-margin: 0px; /* outer bottom margin */
  --tools-header-h: 48px; /* default; JS will measure exact header height */
}

/* FULLSCREEN MAP */
#map {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 1;
}

/* Live traffic markers */
.traffic-div-icon {
  background: transparent;
  border: 0;
}
.traffic-icon {
  --traffic-fill: #00ff00;
  --traffic-stroke: #1b3a57;
  width: 16px;
  height: 16px;
  transform: rotate(var(--track));
  transform-origin: 50% 50%;
}
.traffic-icon svg {
  display: block;
}
.traffic-icon .traffic-triangle {
  fill: var(--traffic-fill);
  stroke: var(--traffic-stroke);
  stroke-width: 1.5;
}
.traffic-in-alerting .traffic-icon {
  --traffic-fill: #d64541;
  --traffic-stroke: #7a1d1d;
}
.traffic-in-detection .traffic-icon {
  --traffic-fill: #f39c12;
  --traffic-stroke: #9a5d00;
}
/* MAIN TOOL PANEL */
#mapTools {
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: absolute;
  bottom: var(--tools-vertical-margin);
  top: auto;
  left: 10px;
  z-index: 1000;
  pointer-events: auto;
  max-height: calc(var(--appvh, 100vh) - 2 * var(--tools-vertical-margin));
  overflow: hidden;
  width: 300px;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 10px;
  box-shadow: 0 0 8px rgba(0, 0, 0, 0.2);
  overflow: hidden;
  font-family: "Montserrat", sans-serif;
}

@supports (padding: max(0px)) {
  #mapTools {
    bottom: max(var(--tools-vertical-margin), env(safe-area-inset-bottom));
  }
}

/* COLLAPSIBLE TOGGLE */
#toolsToggle {
  text-align: center;
  padding: 6px 0;
  font-size: 13px;
  background: #eee;
  cursor: pointer;
  user-select: none;
  border-bottom: 1px solid #ccc;
}

/* Header stays fixed, content scrolls and is height-capped */
#toolsContent {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  max-height: calc(
    var(--appvh, 100vh) - (var(--tools-vertical-margin) * 2) - var(--tools-header-h)
  );
  padding-bottom: 16px;
  min-height: 0; /* important when parent is flex */
}

/* If you toggle classes, ensure expanded state restores the cap properly */
#mapTools:not(.collapsed) #toolsContent {
  max-height: calc(
    var(--appvh, 100vh) - (var(--tools-vertical-margin) * 2) - var(--tools-header-h)
  );
}
#mapTools.collapsed #toolsContent {
  max-height: 0;
  padding: 0;
  overflow: hidden;
}

/* Slider + info button row */
.overlayControl .overlayFooter {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}
.overlayControl .overlayFooter input[type="range"] {
  flex: 1;
}
.overlayRow {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.overlayRow label {
  flex: 1 1 auto;
  min-width: 0;
}
.overlayRow input[type="checkbox"] {
  flex: 0 0 auto;
}
.overlayRow .legendInfoBtn {
  flex: 0 0 22px;
}

/* Compact “i” button */
.legendInfoBtn {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #004080;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}
.legendInfoBtn:hover {
  background: #f1f5f9;
}

/* Legend panel with slide animation (extended) */
.legendPanel {
  overflow: hidden; /* closed: clipped */
  max-height: 0; /* closed height */
  opacity: 0;
  margin-top: 6px;
  padding: 0 8px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #fff;
  font-size: 12px;
}
.legendPanel.is-open {
  opacity: 1;
  padding: 8px; /* open padding */
  max-height: 380px; /* << more room */
  overflow-y: auto; /* scroll when long */
}
.legendPanel.legendPanelStatic {
  margin-top: 8px;
  opacity: 1;
  padding: 8px;
  max-height: none;
  overflow: hidden;
}
.legendPanel.legendPanelStatic.is-open {
  max-height: none;
  overflow: hidden;
}
.datasetInfoPanel {
  line-height: 1.35;
}
.datasetInfoRow {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}
.datasetInfoLabel {
  font-weight: 700;
  color: #334155;
}
.datasetInfoDate {
  color: #0b1b3a;
  text-align: right;
  overflow-wrap: anywhere;
}
.datasetInfoError {
  color: #9f1239;
}
.datasetInfoLoading {
  color: #475569;
}

/* Legend row look-alike to geo.admin */
.legendItem {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 2px 0;
}
.legendSwatch {
  width: 12px;
  height: 12px;
  flex: 0 0 12px;
  border-radius: 2px;
  border: 1px solid rgba(0, 0, 0, 0.15);
}

/* TOOLBOX CARD */
.toolBox {
  position: relative;
  margin: 8px 0;
  padding: 10px;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.digisky-logo {
  margin: 0 0 10px 10px; /* position padding from the corner */
  z-index: 1001; /* > map (1) and > tools (1000) */
}

/* Results panel */
.resultsPanel {
  width: 100%;
  margin-top: 0.5rem;
  background: #ffffff;
  color: #0b1b3a;
  border-radius: 8px;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.1);
  padding: 8px;
  z-index: 1000;
}

.resultsPanel h4 {
  margin: 0 0 6px 0;
  font-size: 0.75rem;
  font-weight: 700;
  color: #0b1b3a;
}

.metricRow {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 4px 0;
  border-bottom: 1px solid #eef1f6;
}
.metricRow:last-child {
  border-bottom: 0;
}

.metricLabel {
  font-size: 0.6875rem;
  color: #3a509f;
  font-weight: 600;
  flex: 1 1 70%;
  min-width: 0;
}
.metricValue {
  font-size: 0.75rem;
  font-weight: 700;
  flex: 0 0 auto;
  text-align: right;
  white-space: nowrap;
  min-width: 4.5rem;
  padding-left: 6px;
  line-height: 1.15;
}
.metricValue.wrap {
  white-space: normal; /* allow line breaks for long unit */
}

/* Small colored chips to echo layer colors */
.chip {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-right: 6px;
}
/* Clickable chips + hidden state */
.chip {
  cursor: pointer;
  border: 1px solid rgba(0, 0, 0, 0.08);
}
.chip.off {
  opacity: 0.25;
  outline: 2px dashed rgba(0, 0, 0, 0.15);
}
.chip-scv {
  background: #ddb027;
}
.chip-grb {
  background: #dd3927;
}
.chip-aa {
  background: #ff0000;
}
.chip-ah {
  background: #0000ff;
} /* Assemblies Horizon */
.chip-atd {
  background: #4b176d;
} /* Alerting Volume */
.chip-decd {
  background: #c7a7e8;
} /* Detection Volume */

/* SEARCH TOOL */
#searchBox {
  width: 100%;
}

#searchBox input {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 14px;
}

#addrResults {
  display: none;
  margin-top: 6px;
  max-height: 240px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 13px;
  z-index: 2;
}

/* Clear (×) button inside the search field */
#searchBox {
  position: relative;
}
#searchBox input {
  padding-right: 28px;
} /* room for the × button */

#searchBox #addrClear {
  position: absolute;
  right: 8px;
  top: 8px;
  width: 20px;
  height: 20px;
  line-height: 18px;
  border: 0;
  border-radius: 50%;
  background: #edf2f7;
  cursor: pointer;
  font-size: 14px;
  display: none; /* hidden until there is text */
}
#searchBox #addrClear:hover {
  background: #e2e8f0;
}

#addrResults .result {
  padding: 6px 8px;
  cursor: pointer;
}

#addrResults .result:hover {
  background: #f2f2f2;
}

/* LAYERBOX LEAFLET PATCHES */
#layerBox .leaflet-control {
  width: 100%;
}

#layerBox .leaflet-control-layers {
  position: static;
  float: none;
  width: 100%;
  background: transparent;
  border: 0;
  box-shadow: none;
}

#layerBox .leaflet-control-layers-expanded {
  width: 100%;
  background: #fff;
  border-radius: 10px;
  border: 1px solid #ddd;
}

#layerBox .leaflet-control-layers-list {
  max-height: 220px;
  overflow-y: auto;
  padding: 8px;
}

#layerBox .leaflet-control-layers-base label,
#layerBox .leaflet-control-layers-overlays label {
  display: block;
  padding: 6px 8px;
}

#layerBox .leaflet-control-layers-separator {
  display: none;
}

/* MAIN LAYOUT SPLIT */
#mainContainer {
  display: flex;
  height: var(--appvh, 100vh);
  width: 100vw;
  overflow: hidden;
}

/* LEFT PANE: MAP + tools */
#mapPane {
  flex: 1 1 auto;
  min-width: 0;
  position: relative;
}

/* VERSION BOX */
#version-box {
  position: absolute;
  bottom: 20px;
  right: 10px;
  background: rgba(0, 0, 0, 0.6);
  color: white;
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 4px;
  font-family: sans-serif;
  z-index: 700;
}

/* RIGHT PANE: INPUT (kompakt, @digisky/ui FormField + Button) */
#inputPane {
  color: rgb(247, 247, 247);
  flex: 0 0 232px;
  background: rgb(58, 80, 159);
  padding: 10px 10px 24px;
  font-family: "Montserrat", sans-serif;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

#inputContent .ds-field__control:disabled {
  background: #eef1f6;
  color: #6b7280;
  cursor: not-allowed;
}

#inputContent .ds-btn {
  margin-top: 0.35rem;
}

#inputContent .ds-btn-row {
  margin-top: 0.35rem;
}

/* Optional: Add more breathing room above grouped sections (if any) */
.sectionTitle {
  margin-top: 24px;
  margin-bottom: 12px;
  font-weight: 600;
  font-size: 13px;
  text-transform: uppercase;
  color: #006699;
}

#inputHeader {
  color: rgb(247, 247, 247);
  font-weight: 700;
  font-size: 0.8rem;
  margin-bottom: 0.65rem;
  text-align: left;
  letter-spacing: 0.01em;
}

#digisky-logo {
  position: absolute;
  bottom: 60px;
  right: 10px;
  z-index: 1001; /* above the map */
}

#digisky-logo img {
  height: 80px; /* adjust size */
  width: auto;
  opacity: 0.9;
  z-index: 710;
}

#digisky-logo img:hover {
  opacity: 0.8;
}

/* Responsive fallback (for later) */
@media (max-width: 768px) {
  #version-box,
  #digisky-logo {
    z-index: 500; /* lower than #inputPane (1002) */
    bottom: 20px; /* move further down to avoid overlap */
    right: 6px;
    opacity: 0.75;
  }
}

/* ===== LEAFLET MEASURE CONTROL STYLING ===== */

/* Position: place it just under the Draw control */
.leaflet-top.leaflet-right .leaflet-control-measure {
  margin-top: 50px; /* Adjust so it sits below Draw control */
  margin-right: 10px;
}

/* Expanded panel styling */
.leaflet-control-measure .leaflet-control-measure-interaction {
  background: #fff;
  border-radius: 10px;
  border: 1px solid #ddd;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  padding: 10px;
  z-index: 2000;
}

/* Results inside measure control */
.leaflet-control-measure .results {
  background: #ffffff;
  color: #0b1b3a; /* same as .resultsPanel text */
  border-radius: 8px;
  border: 1px solid #eef1f6;
  padding: 8px;
  margin-top: 6px;
}

/* Form elements inside */
.leaflet-control-measure input,
.leaflet-control-measure button,
.leaflet-control-measure select {
  font-family: "Montserrat", sans-serif;
  font-size: 13px;
}
.leaflet-control-measure button {
  background-color: #004080;
  color: #fff;
  border: 0;
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
}
.leaflet-control-measure button:hover {
  background-color: #0059b3;
}

/* Z-index so it appears above overlays */
.leaflet-control-measure {
  z-index: 1001;
}

/* ===== Disclaimer Modal ===== */
.k-modal-backdrop {
  position: fixed; /* detach from the map container */
  inset: 0; /* top:0; right:0; bottom:0; left:0 */
  background: rgba(0, 0, 0, 0.35);
  display: none; /* default hidden */
  align-items: center; /* center modal vertically */
  justify-content: center; /* center modal horizontally */
  z-index: 10000; /* above Leaflet controls */
  font-family: "montserrat", sans-serif;
}

.k-modal-backdrop.is-open {
  display: flex; /* enable flex centering */
}

.k-modal {
  max-width: 520px;
  width: min(92vw, 520px);
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
  padding: 16px 18px;
}
.k-modal h3 {
  margin: 0 0 8px 0;
  font-size: 18px;
}
.k-btn {
  padding: 8px 12px;
  border-radius: 8px;
  border: 0;
  cursor: pointer;
  font-weight: 600;
  font-family: Montserrat, sans-serif;
}
.k-btn.primary {
  background: #004080;
  color: #fff;
}
.k-btn.ghost {
  background: #edf2f7;
  color: #1a202c;
}
.k-btn.primary:hover {
  background: #0059b3;
}
.k-btn.ghost:hover {
  background: #e2e8f0;
}

/* Footer row inside modals (Language + Disclaimer) */
.k-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}
.k-actions .spacer {
  flex: 1;
} /* optional helper */

/* ===== Language Modal ===== */
.lang-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 8px;
}
.lang-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 12px 10px;
  background: #fff;
  cursor: pointer;
  font-family: Montserrat, sans-serif;
  transition:
    background-color 0.2s ease,
    transform 0.1s ease,
    box-shadow 0.2s ease;
}
.lang-btn:hover {
  background: #f7fafc;
  transform: translateY(-2px);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

/* preceding line you already have: .lang-btn .code { font-weight: 700; letter-spacing: .5px; } */
.lang-btn .flag {
  line-height: 0;
}

/* --- Floating Language Button --- */
.fab-lang {
  position: fixed;
  right: 16px;
  bottom: 8px;
  z-index: 1200; /* above map/controls, below modals */
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 999px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: #fff;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
  cursor: pointer;
  font-weight: 700;
}

.fab-lang .code {
  font-size: 12px;
  letter-spacing: 0.04em;
}
.fab-lang .flag {
  line-height: 0;
  display: grid;
  place-items: center;
}

.fab-lang .flag-svg {
  height: 16px; /* keep native aspect ratios */
  width: auto;
  display: block;
  border-radius: 2px;
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.06),
    0 1px 2px rgba(0, 0, 0, 0.12);
}

/* Don’t let it collide with your bottom drawer on mobile */
@media (max-width: 768px) {
  .fab-lang {
    bottom: 84px;
  } /* lift a bit above the flight details pane */
}

.flag-svg {
  height: 16px; /* controls visual size */
  width: auto; /* preserves each flag’s native aspect ratio */
  display: block;
  border-radius: 2px;
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.06),
    0 1px 2px rgba(0, 0, 0, 0.12);
}

.lang-btn .code {
  font-weight: 700;
  letter-spacing: 0.5px;
}

/* ===== Bottom Sheet (mobile) ===== */
#sheetHandle {
  display: none; /* desktop hidden, mobile shows */
}

/* --- Mobile layout (≤ 768px) --- */
@media (max-width: 768px) {
  /* Base shell: position only, no forced height */
  #mapTools {
    position: absolute;
    left: 10px;
    width: calc(100vw - 20px);
    /* no top/bottom here */
  }

  /* Expanded state: respect BOTH top (15px) and bottom (120px) limits */
  #mapTools:not(.collapsed) {
    top: 15px;
    bottom: max(120px, env(safe-area-inset-bottom));
    /* the existing content cap still applies via #toolsContent max-height */
  }

  /* Collapsed state: shrink the whole container to header height,
     so you only see the header bar and not a big white box */
  #mapTools.collapsed {
    top: 15px;
    bottom: auto; /* release the bottom constraint */
    height: 0px;
    background: transparent; /* avoid a white slab */
    box-shadow: none;
    border: 0;
  }

  /* You already have this, keep it – just shown here for clarity */
  #mapTools.collapsed #toolsContent {
    max-height: 0;
    padding: 0;
    overflow: hidden;
  }

  /* Bottom sheet container */
  #inputPane {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    max-height: 90vh; /* max expanded height */
    height: auto; /* automatic when expanded */
    transform: translateY(calc(100% - 56px)); /* collapsed: show header strip (~56px) */
    transition: transform 0.25s ease;
    border-top-left-radius: 14px;
    border-top-right-radius: 14px;
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.25);
    z-index: 1800; /* above map & tools */
    padding-top: 10px; /* space for handle */
  }

  /* Expanded state toggled by JS */
  #inputPane.expanded {
    transform: translateY(0%);
  }

  /* Drag handle */
  #sheetHandle {
    display: block;
    width: 56px;
    height: 6px;
    background: rgba(255, 255, 255, 0.85);
    border-radius: 4px;
    margin: 0 auto 8px auto;
  }

  /* Make content scroll independently inside the sheet */
  #inputContent {
    max-height: calc(90vh - 56px);
    overflow-y: auto;
  }

  /* Layers FAB (shows on mobile only) */
  #layersFab {
    display: inline-flex;
    position: absolute;
    left: 10px;
    bottom: 96px;
    z-index: 1005; /* above tools panel */
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 50%;
    background: #ffffff;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
    align-items: center;
    justify-content: center;
    cursor: pointer;
  }
  #layersFab:hover {
    background: #f1f5f9;
  }

  /* --- Prevent iOS Safari auto-zoom on form fields (needs >=16px) --- */
  #inputPane input,
  #inputPane select,
  #inputPane textarea,
  #searchBox input {
    font-size: 16px; /* was 14px */
    line-height: 1.4;
  }
  #inputContent .ds-btn,
  #inputContent .ds-field__control {
    font-size: 16px;
  }

  /* --- Keep logo + version box above the sheet on mobile --- */
  /* Position them just above the collapsed sheet header (~56px), with safe-area inset */
  #version-box,
  #digisky-logo {
    bottom: calc(env(safe-area-inset-bottom, 0px) + 60px); /* 56px header + cushion */
    right: 10px;
    top: auto; /* ensure we’re using bottom anchoring */
    z-index: 1001; /* below the sheet (1002), above the map/tools */
    opacity: 0.9;
  }
  /* Make the map pane and map match the dynamic viewport */
  #mapPane {
    height: var(--appvh, 100vh);
  }
  #map {
    height: var(--appvh, 100vh);
  }

  /* Bottom sheet scroll area already uses max-height: calc(90vh - 56px);
     switch that to the dynamic unit for accurate sizing under toolbars */
  #inputContent {
    max-height: calc(var(--appvh, 100vh) - 56px);
  }
  #mapTools,
  #mapTools:not(.collapsed) #toolsContent,
  #toolsContent {
    /* already using var(--appvh), so it adapts under mobile URL bars */
    max-height: calc(
      var(--appvh, 100vh) - (var(--tools-vertical-margin) * 2) - var(--tools-header-h)
    );
  }
}

/* geo.admin identify popup */
.leaflet-popup-content .geoadmin-popup h4 {
  font:
    600 13px/1.2 Montserrat,
    system-ui,
    sans-serif;
  margin: 0 0 6px 0;
}

/* Make the modal a bit tighter on very small screens */
@media (max-width: 480px) {
  /* preceding line (keep): .k-modal { ... } */
  .k-modal-backdrop {
    position: fixed; /* detach from the map container */
    inset: 0; /* top:0; right:0; bottom:0; left:0 */
    background: rgba(0, 0, 0, 0.35);
    display: none; /* default hidden */
    align-items: center; /* center modal vertically */
    justify-content: center; /* center modal horizontally */
    z-index: 10000; /* above Leaflet controls */
  }

  .k-modal-backdrop.is-open {
    display: flex; /* enable flex centering */
  }

  .k-modal {
    max-width: 520px;
    width: min(92vw, 520px);
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
    padding: 16px 18px;
  }

  .lang-grid {
    gap: 8px; /* tighten spacing */
  }
}

#digitool-cookie-banner a.cookie-more {
  z-index: 10000;
  pointer-events: auto;
}
