/**
 * Mobile Bottom Sheet - Unified architecture for all panels on mobile (max-width: 767px)
 * Desktop remains unchanged. Z-index: map (0), controls (20), sheets (35), profile (40), overlays (50)
 */
@media (max-width: 767px) {
  .mobile-bottom-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    width: 100%;
    height: clamp(66vh, 70vh, 75vh);
    max-height: 75vh;
    min-height: 66vh;
    transform: translateY(100%);
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    z-index: 35;
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  html.dark .mobile-bottom-sheet {
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.5);
  }

  .mobile-bottom-sheet.mobile-sheet-open {
    transform: translateY(0);
  }

  .mobile-bottom-sheet-handle {
    flex-shrink: 0;
    height: clamp(20px, 5vh, 28px);
    min-height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
  }

  .mobile-bottom-sheet-handle:active {
    cursor: grabbing;
  }

  .mobile-bottom-sheet-handle::before {
    content: '';
    width: 40px;
    height: 4px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.3);
  }

  html:not(.dark) .mobile-bottom-sheet-handle::before {
    background: rgba(0, 0, 0, 0.2);
  }

  /* Fluid scaling utilities - iPhone X baseline (375x812) */
  .mobile-touch-target {
    min-height: clamp(44px, 12vw, 52px);
    min-width: clamp(44px, 12vw, 52px);
  }

  .mobile-panel-padding {
    padding: clamp(12px, 4vw, 24px);
  }

  .mobile-text-body {
    font-size: clamp(0.875rem, 2.5vw, 1rem);
  }

  .mobile-text-heading {
    font-size: clamp(1rem, 4vw, 1.25rem);
  }

  /* Map controls (zoom, compass, GPS) - below bottom sheets on mobile */
  #map-controls-right {
    z-index: 10 !important;
  }

  /* Bottom sheets above map controls - POI and Discover panel */
  #poi-content-panel,
  #bottom-panel {
    z-index: 40 !important;
  }

  #bottom-panel-wrapper {
    z-index: 35 !important;
  }

  /* Bottom panel wrapper - on mobile, position at top-left under general menu (pt-6 + 40px button + 8px gap = 88px) */
  #bottom-panel-wrapper {
    top: 88px;
    bottom: auto;
    left: 24px;
    right: auto;
    height: 48px;
  }

  /* Toggle button - top-left under menu on mobile */
  #bottom-panel-toggle {
    top: 0;
    bottom: auto;
    left: 0;
  }

  /* Discover panel (#bottom-panel) - mobile bottom sheet, 100% width, anchored at bottom */
  #bottom-panel {
    position: fixed !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    top: auto !important;
    width: 100% !important;
    max-width: 100vw !important;
    height: clamp(66vh, 70vh, 75vh) !important;
    min-height: 66vh !important;
    max-height: 75vh !important;
    margin: 0 !important;
    padding: 0 !important;
    border-radius: 20px 20px 0 0;
    transform: translateY(100%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s ease, visibility 0.2s ease;
    z-index: 35;
  }

  #bottom-panel.visible {
    transform: translateY(0);
  }

  /* Bottom panel content - ensure vertical scroll works */
  #bottom-panel #bottom-panel-content {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* When Discover panel is open on mobile, hide the toggle (user closes via handle swipe or close button) */
  #bottom-panel-wrapper:has(#bottom-panel.visible) #bottom-panel-toggle {
    opacity: 0;
    pointer-events: none;
  }

  /* Hide bottom-panel handle on desktop - it's inside @media so only mobile gets it; ensure handle shows */
  #bottom-panel .bottom-panel-drag-handle {
    display: flex;
  }

  /* Bottom panel - fluid touch targets */
  #bottom-panel .tab-btn,
  #bottom-panel #bottom-panel-close,
  #bottom-panel #btn-resume {
    min-height: clamp(44px, 12vw, 52px);
    min-width: clamp(44px, 12vw, 52px);
  }

  /* Tabs: each tab name on one line, list can wrap to multiple lines */
  #bottom-panel-tabs {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  #bottom-panel .tab-btn {
    white-space: nowrap;
  }

  /* Guillaume's Resume - one line, 10% smaller */
  #bottom-panel #btn-resume {
    white-space: nowrap;
    padding-left: 0.675rem;
    padding-right: 0.675rem;
    padding-top: 0.6rem;
    padding-bottom: 0.6rem;
    font-size: 0.73125rem;
    gap: 0.3rem;
  }

  #bottom-panel #btn-resume .material-symbols-outlined {
    font-size: 1rem;
  }

  /* Tech enthusiast count - one line, 10% smaller */
  #nearby-friends-count {
    font-size: 0.675rem;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }

  /* Discover my world - two lines max */
  #bottom-panel h2 {
    font-size: 1rem;
    line-height: 1.25;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    max-height: 2.5em;
  }

  /* Widget tiles in bottom section - 30% smaller (90vw * 0.7 = 63vw) */
  #widget-tiles .bottom-section-tile,
  #widget-tiles button.bottom-section-tile {
    width: 63vw !important;
    max-width: 63vw !important;
    min-width: 63vw !important;
    aspect-ratio: 1;
  }

  /* Config overlays - fluid touch targets, padding, scrollable content */
  .config-overlay-inner .p-5 {
    padding: clamp(12px, 4vw, 24px);
    flex: 1;
    min-height: 0;
    overflow-y: auto;
  }

  /* Profile picture picker - mobile bottom sheet */
  .profile-picture-picker.profile-picker-mobile,
  .profile-picture-picker.mobile-bottom-sheet {
    left: 0 !important;
    right: 0 !important;
    top: auto !important;
    width: 100% !important;
    max-width: none !important;
    height: clamp(66vh, 70vh, 75vh) !important;
    min-height: 66vh !important;
    max-height: 75vh !important;
    transform: translateY(0) !important;
    border-radius: 20px 20px 0 0 !important;
    z-index: 40 !important;
  }

  /* Config overlays (Stock, Weather, Resume) - mobile bottom sheet */
  #stock-widget-config-overlay:not(.hidden),
  #weather-widget-config-overlay:not(.hidden),
  #resume-embed-overlay:not(.hidden) {
    align-items: flex-end;
    justify-content: flex-end;
  }

  #stock-widget-config-overlay:not(.hidden) .config-overlay-inner,
  #weather-widget-config-overlay:not(.hidden) .config-overlay-inner,
  #resume-embed-overlay:not(.hidden) .config-overlay-inner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-width: none;
    height: clamp(66vh, 70vh, 75vh);
    min-height: 66vh;
    max-height: 75vh;
    border-radius: 20px 20px 0 0;
    top: auto;
    margin: 0;
  }

  #resume-embed-overlay:not(.hidden) .config-overlay-inner {
    max-height: 75vh;
  }

  /* General menu button - same size as bottom section arrow (w-12 h-12 = 48px) on mobile */
  #btn-general-menu {
    width: 3rem !important;
    height: 3rem !important;
    min-width: 3rem !important;
    min-height: 3rem !important;
  }

  /* Widgets in floating user profile panel - 85% width, centered on mobile */
  .user-profile-panel .user-profile-widgets {
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  .user-profile-panel .user-profile-widgets > div,
  .user-profile-panel .user-profile-widgets > .widget-skeleton {
    width: 85% !important;
    max-width: 85% !important;
    min-width: 0 !important;
  }

  /* User profile panel - mobile bottom sheet */
  .user-profile-panel.user-profile-panel-mobile,
  .user-profile-panel.mobile-bottom-sheet {
    left: 0 !important;
    right: 0 !important;
    top: auto !important;
    width: 100% !important;
    max-width: none !important;
    height: clamp(66vh, 70vh, 75vh) !important;
    min-height: 66vh !important;
    max-height: 75vh !important;
    transform: translateY(0) !important;
    border-radius: 20px 20px 0 0 !important;
    z-index: 40 !important;
  }
}
