/**
 * Browse Mobile Views - List/Map Toggle System
 * Responsive styles for mobile and tablet browse pages
 */

/* ==========================================================================
   Floating Toggle Buttons (View Toggle & Filter Toggle)
   ========================================================================== */

.btn-view-toggle,
.btn-filter-toggle {
  position: fixed;
  bottom: 24px;
  z-index: 1000;

  /* Styling */
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  background-color: #25336E;
  color: white;
  border: none;
  border-radius: 50px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15), 0 2px 4px rgba(0, 0, 0, 0.1);
  font-family: Tahoma, "Segoe UI", Roboto, sans-serif;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 200ms ease;
  white-space: nowrap;

  /* Hide on desktop by default */
  display: none;
}

/* Position buttons as a centered group */
.btn-view-toggle {
  left: 50%;
  transform: translateX(calc(-100% - 4px)); /* Position to the left of center */
}

.btn-filter-toggle {
  left: 50%;
  transform: translateX(4px); /* Position to the right of center */
}

.btn-view-toggle:hover,
.btn-filter-toggle:hover {
  background-color: #1a2552;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2), 0 3px 6px rgba(0, 0, 0, 0.15);
}

.btn-view-toggle:hover {
  transform: translateX(calc(-100% - 4px)) translateY(-2px);
}

.btn-filter-toggle:hover {
  transform: translateX(4px) translateY(-2px);
}

.btn-view-toggle:active {
  transform: translateX(calc(-100% - 4px)) translateY(0);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.btn-filter-toggle:active {
  transform: translateX(4px) translateY(0);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

/* Badge styling for filter count */
.btn-filter-toggle .badge {
  position: relative;
  top: -1px;
  background-color: #FFB200;
  color: #000;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
  margin-left: -4px;
}

/* Icon visibility based on current view */
.btn-view-toggle[data-current-view="list"] .icon-list,
.btn-view-toggle[data-current-view="list"] .label-list {
  display: none;
}

.btn-view-toggle[data-current-view="list"] .icon-map,
.btn-view-toggle[data-current-view="list"] .label-map {
  display: inline-flex;
}

.btn-view-toggle[data-current-view="map"] .icon-map,
.btn-view-toggle[data-current-view="map"] .label-map {
  display: none;
}

.btn-view-toggle[data-current-view="map"] .icon-list,
.btn-view-toggle[data-current-view="map"] .label-list {
  display: inline-flex;
}

.btn-view-toggle .icon-list,
.btn-view-toggle .icon-map {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
}

.btn-view-toggle .label-text {
  display: inline-flex;
}

/* ==========================================================================
   Mobile/Tablet - View Mode Styles (<992px)
   ========================================================================== */

@media (max-width: 991px) {
  /* Show toggle buttons on mobile/tablet */
  body.mobile-view-active .btn-view-toggle,
  body.mobile-view-active .btn-filter-toggle {
    display: flex;
  }

  /* Map view: show hero but make it floating */
  body[data-view-mode="map"] .browse-hero {
    position: fixed;
    top: 56px; /* Below nav bar */
    left: 0;
    right: 0;
    z-index: 950;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    padding: 0.75rem 1rem;
    margin-bottom: 0;
  }

  /* Hide filters in map view - only show search */
  body[data-view-mode="map"] .browse-hero__filters {
    display: none !important;
  }

  /* Compact search bar in map view */
  body[data-view-mode="map"] .browse-hero__search {
    margin-bottom: 0;
  }

  /* Optimize search input for floating bar */
  body[data-view-mode="map"] .browse-search-container {
    border-radius: 50px;
    background: white;
  }

  /* Hide footer in map view */
  body[data-view-mode="map"] footer {
    display: none !important;
  }

  /* Hide browse container padding/margins in map view */
  body[data-view-mode="map"] .browse-container {
    padding: 0;
    margin: 0;
  }

  /* Mobile-specific hero layout improvements */
  body.mobile-view-active .browse-hero {
    padding: 1rem 1rem 0.5rem 1rem;
    margin-bottom: 0.5rem;
  }

  /* Reduce bottom padding/margin on search bar */
  body.mobile-view-active .browse-hero__search {
    margin-bottom: 0.5rem;
  }

  /* Category buttons side-by-side on mobile */
  body.mobile-view-active .browse-category-buttons {
    flex-direction: row !important;
    justify-content: center;
    gap: 0.5rem;
  }

  body.mobile-view-active .browse-category-label {
    display: none; /* Hide "Browse the Switchboard for..." label on mobile */
  }

  body.mobile-view-active .browse-category-btn {
    flex: 1;
    min-width: 120px;
    max-width: 150px;
  }

  /* Compact search bar layout */
  body.mobile-view-active .browse-search-container {
    flex-direction: row !important;
    border-radius: 50px;
    padding: 4px;
    gap: 4px;
  }

  body.mobile-view-active .browse-search-input {
    flex: 1;
    padding: 10px 12px;
    font-size: 0.9rem;
  }

  /* Hide location dropdown in search bar on mobile */
  body.mobile-view-active .browse-search-container .dropdown {
    display: none !important;
  }

  body.mobile-view-active .browse-search-btn {
    width: auto !important;
    padding: 10px 20px;
    border-radius: 50px;
  }

  /* Hide filter dropdowns on mobile - they'll be in the drawer */
  body.mobile-view-active .browse-hero__filters > .d-flex {
    display: none !important;
  }

  /* Keep the filters container visible but empty-looking */
  body.mobile-view-active .browse-hero__filters {
    min-height: 0;
    margin: 0;
    padding: 0;
  }



  /* List View - Show only results, remove map completely */
  body[data-view-mode="list"] .browse-container.view-list .results-container {
    display: block !important;
    height: calc(100vh - 200px);
    overflow-y: auto;
  }

  body[data-view-mode="list"] .browse-container.view-list .browse-map-column {
    display: none !important;
  }

  body[data-view-mode="list"] .browse-results-column {
    min-height: calc(100vh - 250px);
  }

  /* Make results column full width in List view */
  body[data-view-mode="list"] .browse-results-column {
    flex: 0 0 100%;
    max-width: 100%;
  }

  /* Map View - Full screen map with pinned nav and search */
  body[data-view-mode="map"] {
    overflow: hidden;
    height: 100vh;
    position: fixed;
    width: 100%;
  }

  /* Ensure navbar stays pinned at top in map view */
  body[data-view-mode="map"] nav,
  body[data-view-mode="map"] .navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    margin-bottom: 0 !important;
  }

  /* Floating search bar - make it transparent */
  body[data-view-mode="map"] .browse-hero {
    position: fixed;
    top: 56px; /* Below navbar */
    left: 0;
    right: 0;
    z-index: 950;
    background: transparent !important;
    background-image: none !important;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    box-shadow: none;
    border-radius: 0;
    margin: 0;
    padding: 0.5rem 1rem;
  }

  body[data-view-mode="map"] .browse-hero::before {
    display: none; /* Remove gradient overlay */
  }

  /* Make category buttons container transparent in map view */
  body[data-view-mode="map"] .browse-category-buttons {
    background: transparent !important;
    padding: 0.5rem 1rem;
  }

  /* Inactive category buttons - frosted glass effect */
  body[data-view-mode="map"] .browse-category-btn:not(.browse-category-btn--active) {
    background: rgba(255, 255, 255, 0.95) !important;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  }

  /* Active category button - maintain brand navy with enhanced shadow */
  body[data-view-mode="map"] .browse-category-btn--active {
    background-color: #25336E !important;
    border-color: #25336E !important;
    box-shadow: 0 4px 12px rgba(37, 51, 110, 0.4), 0 2px 8px rgba(0, 0, 0, 0.15);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
  }

  /* Floating results count in map view */
  body[data-view-mode="map"] .browse-results-count-floating {
    display: block !important;
    text-align: center;
    padding: 0 0.75rem;
    margin-top: 0.25rem;
  }

  body[data-view-mode="map"] .results-count-text {
    display: inline-block;
    font-size: 0.8rem;
    color: rgba(0, 0, 0, 0.7);
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
    font-weight: 500;
  }

  body[data-view-mode="map"] .results-count-load-more {
    color: #0d6efd;
    text-decoration: none;
    cursor: pointer;
    font-weight: 500;
    margin-left: 0.25rem;
  }

  body[data-view-mode="map"] .results-count-load-more:hover {
    text-decoration: underline;
  }

  /* Hide results in Map view */
  body[data-view-mode="map"] .results-container,
  body[data-view-mode="map"] .col-12.col-lg-5 {
    display: none !important;
  }

  /* Map column - full screen below navbar */
  body[data-view-mode="map"] .map-column {
    position: fixed !important;
    top: 56px; /* Below nav bar only */
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: calc(100vh - 56px);
    z-index: 500;
    padding: 0 !important;
    margin: 0 !important;
  }

  body[data-view-mode="map"] .map-container {
    position: relative;
    width: 100%;
    height: 100%;
    border-radius: 0;
    border: none;
    margin: 0;
    box-shadow: none;
  }

  body[data-view-mode="map"] .map-card {
    height: 100%;
    border-radius: 0;
    border: none;
    border-top: none !important;
    box-shadow: none;
    margin: 0;
  }

  body[data-view-mode="map"] .map-card .card-body {
    padding: 0;
    height: 100%;
  }

  body[data-view-mode="map"] .browse-map,
  body[data-view-mode="map"] #map {
    height: 100% !important;
    min-height: 100% !important;
    width: 100% !important;
  }

  /* Hide the recenter button in mobile map view to reduce clutter */
  body[data-view-mode="map"] #recenter-map-btn {
    display: none;
  }

  /* Hide footer in Map view */
  body[data-view-mode="map"] footer {
    display: none !important;
  }

  /* Ensure browse form doesn't interfere in Map view */
  body[data-view-mode="map"] .browse-content-row {
    position: relative;
    margin: 0;
    padding: 0;
  }
}

/* ==========================================================================
   Floating Search Bar (Map View) - Not used anymore, using hero instead
   ========================================================================== */

.map-view-search-bar {
  display: none !important; /* Not used - we use the hero search bar */
}

/* ==========================================================================
   Filter FAB (Floating Action Button) - Map View Only
   ========================================================================== */

.fab-filter {
  position: fixed;
  bottom: 88px; /* Above toggle button */
  right: 24px;
  z-index: 1000;

  /* Circular button */
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background-color: #25336E;
  color: white;
  border: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15), 0 2px 4px rgba(0, 0, 0, 0.1);
  cursor: pointer;
  transition: all 200ms ease;

  /* Center icon */
  display: none; /* Hidden by default */
  align-items: center;
  justify-content: center;

  /* Badge */
  position: relative;
}

.fab-filter:hover {
  background-color: #1a2552;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
  transform: translateY(-2px);
}

.fab-filter:active {
  transform: translateY(0);
}

.fab-filter .icon {
  font-size: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.fab-filter .badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background-color: #FFB200;
  color: #000;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
}

/* Hide FAB on mobile - we use the floating Filters button instead */
@media (max-width: 991px) {
  body.mobile-view-active .fab-filter {
    display: none !important;
  }
}

/* ==========================================================================
   Filter Drawer (Mobile/Tablet)
   ========================================================================== */

.filter-drawer {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1100;
  pointer-events: none;
  display: none; /* Hidden by default */
}

.filter-drawer[data-drawer-state="open"] {
  pointer-events: auto;
}

.filter-drawer-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  opacity: 0;
  transition: opacity 300ms ease-out;
  cursor: pointer;
}

.filter-drawer[data-drawer-state="open"] .filter-drawer-overlay {
  opacity: 1;
}

.filter-drawer-content {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 75vh;
  background: white;
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.15);
  transform: translateY(100%);
  transition: transform 300ms ease-out;
  display: flex;
  flex-direction: column;
}

.filter-drawer[data-drawer-state="open"] .filter-drawer-content {
  transform: translateY(0);
}

.filter-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 16px;
  border-bottom: 1px solid #e5e7eb;
  flex-shrink: 0;
}

.filter-drawer-header h3 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  color: #1f2937;
}

.filter-drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.filter-drawer-footer {
  padding: 16px 20px;
  border-top: 1px solid #e5e7eb;
  flex-shrink: 0;
}

.filter-drawer-footer .btn {
  width: 100%;
}

/* Show drawer on mobile/tablet in both List and Map views */
@media (max-width: 991px) {
  body.mobile-view-active .filter-drawer {
    display: block;
  }

  /* Style filters in drawer */
  .filter-drawer #drawer-filter-content {
    display: block;
  }

  .filter-drawer #drawer-filter-content .d-flex {
    display: flex !important;
    flex-direction: column;
    gap: 1rem;
  }

  .filter-drawer .dropdown {
    width: 100%;
  }

  .filter-drawer .dropdown-toggle {
    width: 100%;
    text-align: left;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .filter-drawer .dropdown-menu {
    width: 100%;
  }
}

/* ==========================================================================
   Desktop - Hide Mobile UI & Reset Styles (≥992px)
   ========================================================================== */

@media (min-width: 992px) {
  /* Hide ALL mobile-specific UI elements - absolute priority */
  .btn-view-toggle,
  .btn-filter-toggle,
  .fab-filter,
  .filter-drawer,
  .location-filter-mobile {
    display: none !important;
  }

  /* Ensure both columns are always visible on desktop */
  .browse-results-column,
  .browse-map-column,
  body[data-view-mode] .browse-results-column,
  body[data-view-mode] .browse-map-column,
  body[data-view-mode="list"] .browse-results-column,
  body[data-view-mode="list"] .browse-map-column,
  body[data-view-mode="map"] .browse-results-column,
  body[data-view-mode="map"] .browse-map-column {
    display: block !important;
  }

  /* Ensure results and map containers are visible */
  .results-container,
  .map-container,
  body[data-view-mode] .results-container,
  body[data-view-mode] .map-container {
    display: block !important;
    opacity: 1 !important;
  }
}

/* ==========================================================================
   View Transition Animations
   ========================================================================== */

.results-container,
.map-container {
  transition: opacity 200ms ease-in-out;
}

body[data-view-mode] .results-container,
body[data-view-mode] .map-container {
  opacity: 1;
}

/* Fade out when switching */
body.view-transitioning .results-container,
body.view-transitioning .map-container {
  opacity: 0.5;
}

/* ==========================================================================
   Touch Optimizations
   ========================================================================== */

@media (max-width: 991px) {
  /* Increase touch targets */
  .btn-view-toggle,
  .btn-filter-toggle,
  .fab-filter {
    min-width: 44px;
    min-height: 44px;
  }

  /* Remove tap highlight */
  .btn-view-toggle,
  .btn-filter-toggle,
  .fab-filter,
  .filter-drawer-overlay {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
  }

  /* Optimize scrolling */
  .results-container,
  .filter-drawer-body {
    -webkit-overflow-scrolling: touch;
  }
}

/* ==========================================================================
   Accessibility
   ========================================================================== */

.btn-view-toggle:focus,
.btn-filter-toggle:focus,
.fab-filter:focus {
  outline: 2px solid #FFB200;
  outline-offset: 2px;
}

/* ==========================================================================
   Loading States
   ========================================================================== */

.map-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 400px;
}

.map-loading::after {
  content: '';
  width: 40px;
  height: 40px;
  border: 4px solid #e5e7eb;
  border-top-color: #25336E;
  border-radius: 50%;
  animation: spinner 0.8s linear infinite;
}

@keyframes spinner {
  to { transform: rotate(360deg); }
}
