/**
 * Hiking Trails Map Styles v2.0
 * Desktop: overlay panel (unchanged behavior)
 * Mobile: draggable bottom sheet with peek/half/full states
 * 
 * Beaver Builder compatibility:
 *   - Uses !important sparingly but necessarily to override BB's
 *     .fl-module-html and .fl-col-content overflow defaults
 *   - z-index kept within reasonable range (10-25) to avoid
 *     conflicting with BB's editor UI (z-index 100+)
 *   - touch-action set on drag handle only, not entire container,
 *     so BB's own scroll behavior isn't affected
 */


/* ============================================
   CONTAINER — Desktop (panoramic aspect ratio)
   ============================================ */

.hiking-trails-container {
  position: relative;
  width: 100%;
  aspect-ratio: var(--lq-aspect-ratio, 21 / 9);
  min-height: var(--lq-min-height, 400px);
  max-height: var(--lq-max-height, 80vh);
  overflow: hidden;
}

/* Map fills entire container on all viewports */
.hiking-trails-map {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
}


/* ============================================
   DESKTOP PANEL — Left overlay (≥769px)
   ============================================ */

.hiking-panel {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 380px;
  max-width: calc(90vw - 64px);
  margin: 32px;
  background-color: #2d544d !important;
  color: #fffef8 ;
  z-index: 10;
  overflow-y: auto;
  box-shadow: 4px 0 20px rgba(0, 0, 0, 0.3);
  border-radius: 8px;
}

.hiking-panel-inner {
  padding: 40px 30px;
}


/* ============================================
   TITLE
   ============================================ */

.hiking-title {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 2.5rem;
  font-weight: 400;
  margin: 0 0 30px 0;
  letter-spacing: 0.02em;
  color: #ffffff;
}


/* ============================================
   SECTION DIVIDERS
   ============================================ */

.section-divider {
  border: none;
  border-top: 1px solid rgba(255, 255, 255, 0.2);
  margin: 0;
}


/* ============================================
   DIFFICULTY SECTIONS — Accordion
   ============================================ */

.difficulty-section {
  margin-bottom: 0;
}

.difficulty-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 20px 0;
  background: none;
  border: none;
  color: #ffffff;
  font-family: 'Montserrat', 'Helvetica Neue', sans-serif;
  font-size: 1rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: opacity 0.2s ease;
}

.difficulty-header:hover {
  opacity: 0.85;
}

.difficulty-header .chevron {
  width: 20px;
  height: 20px;
  transition: transform 0.3s ease;
  flex-shrink: 0;
}

.difficulty-header.expanded .chevron {
  transform: rotate(180deg);
}


/* ============================================
   ACCORDION CONTENT
   ============================================ */

.difficulty-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease-out, padding 0.3s ease-out;
  padding: 0;
}

.difficulty-content.expanded {
  max-height: 500px;
  padding-bottom: 15px;
}


/* ============================================
   ROUTE LIST — Desktop (checkboxes)
   ============================================ */

.route-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.route-item {
  margin-bottom: 0 !important;
}

.route-label {
  display: flex;
  align-items: center;
  cursor: pointer;
  padding: 8px 0;
  transition: opacity 0.2s ease;
}

.route-label:hover {
  opacity: 0.85;
}


/* ============================================
   CUSTOM CHECKBOX
   ============================================ */

.route-checkbox {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.checkbox-custom {
  width: 18px;
  height: 18px;
  border: 2px solid #ffffff;
  border-radius: 2px;
  margin-right: 12px;
  flex-shrink: 0;
  position: relative;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.route-checkbox:checked + .checkbox-custom {
  background-color: #ffffff;
}

.route-checkbox:checked + .checkbox-custom::after {
  content: '';
  position: absolute;
  left: 5px;
  top: 1px;
  width: 5px;
  height: 10px;
  border: solid #2d544d;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.route-checkbox:focus + .checkbox-custom {
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.3);
}


/* ============================================
   ROUTE TEXT
   ============================================ */

.route-name {
  font-family: 'Montserrat', 'Helvetica Neue', sans-serif;
  font-size: 0.9rem;
  font-weight: 400;
  margin-right: 6px;
}

.route-distance {
  font-family: 'Montserrat', 'Helvetica Neue', sans-serif;
  font-size: 0.85rem;
  font-weight: 400;
  opacity: 0.8;
}


/* ============================================
   MARKER INFO WINDOW
   ============================================ */

.marker-info {
  padding: 8px 12px;
  font-family: 'Montserrat', 'Helvetica Neue', sans-serif;
  font-size: 14px;
}

.marker-info strong {
  color: #2d544d;
}


/* ============================================
   DESKTOP: Tablet adjustments
   ============================================ */

@media (max-width: 1024px) {
  .hiking-panel {
    width: 320px;
  }
  
  .hiking-panel-inner {
    padding: 30px 25px;
  }
  
  .hiking-title {
    font-size: 2rem;
  }
}


/* ============================================
   MOBILE BOTTOM SHEET (≤768px)
   ============================================ */

@media (max-width: 768px) {

  /**
   * Container becomes flex column:
   *   1. Status bar  (fixed height, top)
   *   2. Map area    (flex: 1, holds map + bottom sheet)
   */
  .hiking-trails-container {
    aspect-ratio: unset !important;
    height: var(--lq-mobile-height, 85vh) !important;
    min-height: 480px !important;
    max-height: none !important;
    overflow: hidden;
    display: flex !important;
    flex-direction: column !important;
  }

  /**
   * Beaver Builder fix: BB's .fl-col-content and .fl-module-html
   * can set overflow: hidden which clips the sheet during drag.
   */
  .fl-col-content:has(.hiking-trails-container),
  .fl-module-html:has(.hiking-trails-container),
  .fl-module-content:has(.hiking-trails-container) {
    overflow: visible !important;
  }


  /* ---- Status Bar (structural, above map) ---- */
  .map-status-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #2d544d;
    color: #ffffff;
    padding: 10px 16px;
    flex-shrink: 0;
    z-index: 5;
  }

  .map-status-bar-left {
    display: flex;
    flex-direction: column;
    gap: 1px;
  }

  .map-status-count {
    font-family: 'Montserrat', sans-serif;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.7);
    line-height: 1.2;
  }

  .map-status-label {
    font-family: 'Playfair Display', Georgia, serif;
    font-size: 15px;
    font-weight: 500;
    color: #ffffff;
    line-height: 1.2;
  }


  /* ---- Map Area (holds map + bottom sheet) ---- */
  .hiking-map-area {
    flex: 1;
    position: relative;
    overflow: hidden;
    min-height: 0; /* flex child shrink fix */
  }

  /* Map fills the map area */
  .hiking-trails-map {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
  }


  /* ---- Bottom Sheet ---- */
  .hiking-panel {
    /* Override desktop positioning */
    position: absolute;
    top: unset;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100% !important;
    max-width: 100% !important;
    margin: 0;

    /* Sheet appearance */
    background-color: #ffffff !important;
    color: #2c2c2a;
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -4px 30px rgba(0, 0, 0, 0.18);
    z-index: 20;

    /* Height controlled by JS via CSS variable */
    height: var(--sheet-height, 200px);
    transition: height 0.38s cubic-bezier(0.32, 0.72, 0, 1);

    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  /* Fade mask at bottom edge in peek state */
  .hiking-panel::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 40px;
    background: linear-gradient(to bottom, rgba(255,255,255,0) 0%, rgba(255,255,255,1) 100%);
    pointer-events: none;
    z-index: 2;
    transition: opacity 0.3s ease;
    opacity: 1;
  }

  .hiking-panel.sheet-half::after,
  .hiking-panel.sheet-full::after {
    opacity: 0;
  }

  /* Disable transition during active drag */
  .hiking-panel.is-dragging {
    transition: none !important;
  }

  /* ---- Drag Handle ---- */
  .sheet-drag-handle {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 0 6px;
    cursor: grab;
    flex-shrink: 0;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
  }

  .sheet-drag-handle:active {
    cursor: grabbing;
  }

  .sheet-drag-handle-bar {
    width: 40px;
    height: 4px;
    border-radius: 2px;
    background: #d1cfc7;
  }

  /* ---- Scrollable Content Area ---- */
  .sheet-scroll-area {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
  }

  .hiking-panel-inner {
    padding: 0 20px 28px;
  }


  /* ---- Title: Dark green on white ---- */
  .hiking-title {
    font-size: 1.6rem;
    color: #2d544d;
    margin-bottom: 4px;
  }

  /* ---- Subtitle hint ---- */
  .sheet-subtitle {
    font-family: 'Montserrat', sans-serif;
    font-size: 12px;
    color: #888780;
    margin: 0 0 14px;
    line-height: 1.4;
  }


  /* ---- Difficulty Tags ---- */
  .difficulty-tag {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-family: 'Montserrat', sans-serif;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    padding: 4px 10px;
    border-radius: 20px;
    margin-bottom: 8px;
  }

  .difficulty-tag--novice {
    background: rgba(76, 175, 80, 0.12);
    color: #388E3C;
  }

  .difficulty-tag--intermediate {
    background: rgba(255, 152, 0, 0.12);
    color: #E65100;
  }

  .difficulty-tag--expert {
    background: rgba(229, 57, 53, 0.12);
    color: #C62828;
  }

  .difficulty-tag-icon {
    font-size: 8px;
  }

  .difficulty-active-count {
    font-family: 'Montserrat', sans-serif;
    font-size: 11px;
    font-weight: 600;
    margin-left: 6px;
  }


  /* ---- Mobile Trail Cards ---- */
  .trail-card {
    background: #fafaf8;
    border: 1.5px solid #e8e6df;
    border-radius: 14px;
    padding: 14px 16px;
    margin-bottom: 10px;
    transition: background 0.25s ease, border-color 0.25s ease;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .trail-card.is-active {
    border-color: var(--trail-card-color, #4CAF50);
    background: var(--trail-card-bg, rgba(76, 175, 80, 0.08));
  }

  .trail-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .trail-card-left {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
  }

  .trail-card-toggle {
    width: 22px;
    height: 22px;
    border-radius: 6px;
    background: #d1cfc7;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s ease;
  }

  .trail-card.is-active .trail-card-toggle {
    background: var(--trail-card-color, #4CAF50);
  }

  .trail-card-toggle svg {
    opacity: 0;
    transition: opacity 0.2s ease;
  }

  .trail-card.is-active .trail-card-toggle svg {
    opacity: 1;
  }

  .trail-card-name {
    font-family: 'Playfair Display', Georgia, serif;
    font-size: 15px;
    font-weight: 500;
    color: #2c2c2a;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .trail-card-subtitle {
    font-family: 'Montserrat', sans-serif;
    font-size: 12px;
    font-weight: 400;
    color: #888780;
    margin-left: 5px;
  }

  .trail-card-expand {
    background: none;
    border: none;
    padding: 4px;
    cursor: pointer;
    color: #888780;
    flex-shrink: 0;
    transition: transform 0.25s ease;
    line-height: 0;
  }

  .trail-card-expand.is-expanded {
    transform: rotate(180deg);
  }


  /* ---- Trail Meta Row ---- */
  .trail-card-meta {
    display: flex;
    gap: 12px;
    margin-top: 8px;
    flex-wrap: wrap;
  }

  .trail-meta-item {
    display: flex;
    align-items: center;
    gap: 4px;
    font-family: 'Montserrat', sans-serif;
    font-size: 12px;
    color: #73726c;
  }

  .trail-meta-item svg {
    flex-shrink: 0;
  }


  /* ---- Trail Details (expandable) ---- */
  .trail-card-details {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease, margin-top 0.3s ease, padding-top 0.3s ease;
    margin-top: 0;
    padding-top: 0;
  }

  .trail-card-details.is-expanded {
    max-height: 200px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
  }

  .trail-card-description {
    font-family: 'Montserrat', sans-serif;
    font-size: 13px;
    line-height: 1.5;
    color: #5f5e5a;
    margin: 0;
  }


  /* ---- Safety Info Box ---- */
  .trail-safety-box {
    margin-top: 16px;
    padding: 14px 16px;
    background: rgba(45, 84, 77, 0.06);
    border-radius: 12px;
    font-family: 'Montserrat', sans-serif;
    font-size: 12px;
    color: #5f5e5a;
    line-height: 1.5;
  }

  .trail-safety-box strong {
    color: #2d544d;
  }


  /* ---- Hide desktop-only elements on mobile ---- */
  .section-divider {
    display: none;
  }

  .desktop-only {
    display: none !important;
  }

  .mobile-only {
    display: block !important;
  }

  /* Old floating pill — hidden, replaced by status bar */
  .map-status-pill {
    display: none !important;
  }
}

/* Hide mobile elements on desktop */
@media (min-width: 769px) {
  .sheet-drag-handle,
  .sheet-subtitle,
  .map-status-pill,
  .map-status-bar,
  .trail-safety-box,
  .mobile-only {
    display: none !important;
  }

  /* No fade mask on desktop */
  .hiking-panel::after {
    display: none !important;
  }

  /* Desktop doesn't use the map area wrapper */
  .hiking-map-area {
    display: contents;
  }

  .desktop-only {
    display: block !important;
  }

  .sheet-scroll-area {
    overflow-y: auto;
    height: 100%;
  }
}


/* ============================================
   SMALL MOBILE (≤480px)
   ============================================ */

@media (max-width: 480px) {
  .hiking-trails-container {
    min-height: 440px !important;
  }

  .hiking-title {
    font-size: 1.4rem;
  }

  .trail-card {
    padding: 12px 14px;
  }

  .trail-card-name {
    font-size: 14px;
  }
}


/* ============================================
   ACCESSIBILITY
   ============================================ */

/* Focus styles for keyboard navigation */
.difficulty-header:focus {
  outline: 2px solid #ffffff;
  outline-offset: 2px;
}

.difficulty-header:focus:not(:focus-visible) {
  outline: none;
}

.difficulty-header:focus-visible {
  outline: 2px solid #ffffff;
  outline-offset: 2px;
}

.route-checkbox:focus + .checkbox-custom {
  outline: 2px solid #ffffff;
  outline-offset: 2px;
}

.route-checkbox:focus:not(:focus-visible) + .checkbox-custom {
  outline: none;
  box-shadow: none;
}

.route-checkbox:focus-visible + .checkbox-custom {
  outline: 2px solid #ffffff;
  outline-offset: 2px;
}

/* Mobile card focus */
@media (max-width: 768px) {
  .trail-card:focus-within {
    outline: 2px solid #2d544d;
    outline-offset: 2px;
  }

  .trail-card:focus-within:not(:focus-visible-within) {
    outline: none;
  }

  .trail-card-expand:focus-visible {
    outline: 2px solid #2d544d;
    outline-offset: 2px;
    border-radius: 4px;
  }
}

/* Screen reader only utility */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}


/* ============================================
   REDUCED MOTION
   ============================================ */

@media (prefers-reduced-motion: reduce) {
  .difficulty-content,
  .difficulty-header .chevron,
  .hiking-panel,
  .checkbox-custom,
  .trail-card,
  .trail-card-toggle,
  .trail-card-details,
  .trail-card-expand,
  .map-status-pill {
    transition: none !important;
  }
}


/* ============================================
   HIGH CONTRAST
   ============================================ */

@media (prefers-contrast: high) {
  .hiking-panel {
    border: 2px solid #ffffff;
  }

  .checkbox-custom {
    border-width: 3px;
  }

  .section-divider {
    border-top-width: 2px;
    border-top-color: #ffffff;
  }

  .difficulty-header:focus,
  .route-checkbox:focus-visible + .checkbox-custom {
    outline-width: 3px;
  }

  /* Mobile high contrast */
  @media (max-width: 768px) {
    .trail-card {
      border-width: 2px;
    }

    .trail-card.is-active {
      border-width: 3px;
    }

    .hiking-panel {
      border: 2px solid #2d544d !important;
    }
  }
}


/* ============================================
   LOADING STATE
   ============================================ */

.hiking-trails-container.loading .hiking-trails-map {
  background: #e5e5e5;
}

.hiking-trails-container.loading::after {
  content: 'Loading trails...';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: 'Montserrat', sans-serif;
  color: #666;
  z-index: 5;
}


/* ============================================
   ANIMATION — Trail highlight pulse
   ============================================ */

@keyframes trailPulse {
  0%, 100% { stroke-opacity: 0.9; }
  50% { stroke-opacity: 0.5; }
}
