/* ============================================================================
   MOBILE GEOMETRY (≤ 39.99em)
   Explicit mobile layout model
   ============================================================================ */

@media (max-width: 39.99em) {

  :root {
    --content-panel-height: 60dvh;
  }

  html,
  body {
    height: 100%;
  }

  body {
    overflow: hidden;
  }

  .layout {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    /* critical for flex children */
    height: auto;
  }


  /* Page stack: header → map → bottom bar */
  .site-main {
    display: flex;
    flex-direction: column;
    height: calc(100dvh - var(--header-height-real));
    position: relative;
    min-height: 0;
    /* critical for flex children */
  }

  .site-header {
    flex: 0 0 auto;
    padding: 0.25rem 1rem;
  }

  /* Header stacks vertically on mobile */
  .header-inner {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }

  /* Top row: title + user menu */
  .header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  /* Search takes full row below */
  .search-container {
    width: 100%;
  }

  /* Map participates in layout */
  .map-container {
    position: relative !important;
    flex: 1 1 auto;
    min-height: 0;
    /* height: calc(100svh - var(--header-height-real)); */
    z-index: 1;
    padding-bottom: env(safe-area-inset-bottom);
  }

  #map {
    width: 100%;
    height: 100%;
  }

  /* Bottom results bar */
  .sidebar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    min-height: 0;
    height: var(--sidebar-height-mobile);
    border-top: 1px solid #ddd;
    z-index: 10;
    display: none;
    flex-direction: column;
    overflow: visible;
  }

  .sidebar-header {
    flex: 0 0 auto;
    padding: 0.5rem 1rem 0.25rem;
    font-weight: 600;
    font-size: 1rem;
  }

  .site-main.has-results-open .sidebar {
    display: flex;
  }


  /* Handle above bottom sheet / sidebar */
  /* add <div class="editor-form no-drag"> to elements that should not be draggable */
  .sidebar-handle,
  .content-handle,
  .profile-handle {
    height: 24px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding-top: 0px;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
  }

  .sidebar-handle::before,
  .content-handle::before,
  .profile-handle::before {
    content: '';
    width: 48px;
    height: 5px;
    border-radius: 3px;
    background: #bbb;
  }


  /* Campsite list */
  .campsite-list {
    display: block;
    overflow-y: auto;
    padding: 0.5rem 1rem;
    margin: 0;
    list-style: none;
    max-height: calc(var(--sidebar-height-mobile) - 3rem);
  }

  .campsite-list li {
    padding: 0.5rem 0;
    border-bottom: 1px solid #ddd;
  }

  .campsite-list li:last-child {
    border-bottom: none;
  }

  /* Content panel: mobile bottom sheet */
  .content {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: var(--content-panel-height);
    overflow-y: hidden;
    padding: 0;
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.15);
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
    z-index: 1000;
    display: none;
    padding-bottom: env(safe-area-inset-bottom);
    touch-action: none;
  }

  .site-main.has-editor-open #campsite-panel {
    display: block;
  }

  .site-main.has-profile-open #profile-panel {
    display: block;
  }

  /* Search (mobile: inside header) */
  .search-input {
    width: 100%;
    padding: 0.6rem 0.75rem;
    font-size: 1rem;
    border: 1px solid #ccc;
    border-radius: 8px;
    background: white;
    min-height: 44px;
    padding-right: 2rem;
  }

  .search-clear {
    position: absolute;
    right: 0.6rem;
    top: 50%;
    transform: translateY(-50%);
    border: none;
    background: none;
    font-size: 1.2rem;
    cursor: pointer;
    display: none;
  }

  .search-container.has-value .search-clear {
    display: block;
  }

  .user-menu {
    margin-top: 0.25rem;
  }
  .user-menu-button {
    border-radius: 50%;
    overflow: hidden;
  }
  .user-menu-icon {
    border-radius: 50%;
  }
}