/* ============================================================
   MOBILE — bottom sheet (<= 768px). Desktop is untouched.
   Pattern A: map fills the screen; the tools panel becomes a
   draggable bottom sheet with 3 snap points (peek / half / full).
   ============================================================ */

/* Drag handle is mobile-only: hidden by default so desktop is unaffected. */
.sheet-handle {
  display: none;
}

@media (max-width: 768px) {
  /* Block the browser's pull-to-refresh across the app on mobile */
  html,
  body {
    overscroll-behavior-y: contain;
  }

  /* Map owns the whole viewport */
  #map {
    height: 100vh;
    height: 100dvh; /* dynamic vh: accounts for mobile browser chrome */
  }

  /* Slim top title bar */
  .box-2.header {
    height: 44px;
    width: 100vw;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 600;
    color: #1f4158;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(6px);
    box-shadow: 0 1px 6px rgba(0, 0, 0, 0.15);
    z-index: 400000;
  }

  /* The sidebar becomes a bottom sheet */
  .box {
    box-sizing: border-box; /* keep padding inside 100vw — no right overflow */
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    width: 100vw;
    max-width: 100%;
    height: 85vh;
    height: 85dvh;
    max-height: 92dvh;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.22);
    padding: 0 14px calc(env(safe-area-inset-bottom) + 16px);
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain; /* don't chain scroll to the page */
    /* translateY controlled by JS snap points; default = peek */
    transform: translateY(calc(100% - 132px));
    transition: transform 260ms cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 500000;
    touch-action: pan-y;
  }
  .box.dragging {
    transition: none; /* follow the finger 1:1 while dragging */
  }

  /* Kill the desktop top-padding hack (<br><br><br>) visually */
  .box > br:first-of-type,
  .box > br:first-of-type + br,
  .box > br:first-of-type + br + br {
    display: none;
  }

  /* Grab handle pinned to the top of the sheet */
  .sheet-handle {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 10px 0 8px;
    margin: 0 -14px 4px;
    background: #fff;
    border-radius: 16px 16px 0 0;
    cursor: grab;
    touch-action: none; /* we own the drag — block browser pull-to-refresh */
    user-select: none;
    -webkit-user-select: none;
  }
  .sheet-handle:active {
    cursor: grabbing;
  }
  .sheet-handle .grip {
    width: 40px;
    height: 5px;
    border-radius: 3px;
    background: #cfd4da;
  }
  .sheet-handle .label {
    font-size: 12px;
    color: #8a9099;
    letter-spacing: 0.02em;
  }

  /* Bigger, thumb-friendly tool buttons */
  .BTN {
    padding: 16px 18px;
    font-size: 16px;
    margin-bottom: 10px;
  }
  .resetBTN {
    font-size: 20px;
    padding: 14px;
  }

  /* Full-width form controls + comfortable tap targets */
  .DIV select,
  .custom-select select,
  .custom-select-pal select,
  .custom-select-ras select,
  #slctmonth_com {
    width: 100%;
    font-size: 16px; /* >=16px stops iOS auto-zoom on focus */
    padding: 10px;
  }
  .searchField {
    width: 100%;
    height: 120px;
    font-size: 15px;
  }
  .DIV button {
    padding: 14px;
    font-size: 15px;
  }
  input[type="number"] {
    width: 46%;
    font-size: 16px;
    padding: 8px;
    margin: 3px 1%;
  }

  /* SQL results modal → full-screen friendly on phones */
  .modal {
    top: 50%;
    left: 50%;
    height: 80vh;
    height: 80dvh;
    max-width: 94vw;
    width: 94vw;
  }
  .modal-body {
    overflow-x: auto;
  }

  /* Leaflet zoom controls clear of the top bar */
  .leaflet-top.leaflet-left {
    margin-top: 50px;
  }
}
