/* Mobile Styles for Tīklošanās Karte */

/* Reduce density on mobile to free visual space */
@media (max-width: 768px) {
  :root {
    --border-radius: 1.5vw !important;
  }

  .glass-panel.sidebar-back { display: none; }
  .glass-panel.accent-top-right { top: 12px; right: 12px; width: 160px; height: 160px; }
  .glass-panel.accent-bottom-right { display: none; }

  .category-bar {
    top: var(--map-header-offset);
  }
  
  /* Keep zoom controls visible on mobile (Safari/iOS often needs them). */
  
  .member-counter {
    bottom: 6vh;
    left: 2vh;
    padding: 10px 12px;
    font-size: 2vh;
    gap: 1vh;
    transition: transform 220ms ease, opacity 220ms ease;
    will-change: transform, opacity;
    transform: translateY(0);
    opacity: 1;
  }

  /* Hide member counter when the mobile drawer is open (slide down out of sight) */
  body.mobile-sidebar-open .member-counter {
    transform: translateY(220%);
    opacity: 0;
    pointer-events: none;
  }

  .member-counter i {
    font-size: 2vh;
  }

  .lightbox-inner {
    max-width: 80vw;
    max-height: 80vh;
  }

  .lightbox-image {
    max-width: 80vw;
    max-height: 80vh;
  }

  .lightbox-nav {
    width: 4vh;
    height: 5vh;
    font-size: 4vh;
    line-height: 1;
  }

  .lightbox-nav.prev {
    left: -8.5vw;
  }

  .lightbox-nav.next {
    right: -8.5vw;
  }

  .lightbox-close {
    width: 5vh;
    height: 5vh;
    font-size: 0;
    top: 0;
    right: -9.5vw;
  }

  .lightbox-counter {
    bottom: -5vh;
  }

  .floating-sidebar {
    display: flex;
    flex-direction: column;
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
    min-height: 30px;
    height: auto;
    max-height: 30vh;
    border-radius: var(--border-radius) var(--border-radius) 0 0;
    overflow: visible;
    transform: translateY(100%);
    transition: transform 0.3s ease;
  }

  .floating-sidebar.open {
    transform: translateY(0);
  }

  .mobile-toggle {
    display: flex;
    position: absolute;
    top: -30px;
    left: 0;
    right: 0;
    width: 100%;
    height: 2vh;
    min-height: 30px;
    border-radius: var(--border-radius) var(--border-radius) 0 0;
    background: rgba(255, 255, 255, 0.45);
    backdrop-filter: blur(10px);
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
    transition: background 0.2s ease;
    z-index: 100;
    align-items: center;
    justify-content: center;
  }

  .mobile-toggle:active {
    background: rgba(255, 255, 255, 0.65);
  }

  .mobile-toggle::before {
    content: '';
    width: 0;
    height: 0;
    border-left: 1vh solid transparent;
    border-right: 1vh solid transparent;
    border-bottom: 1.3vh solid var(--color-burgundy);
    position: absolute;
    transition: transform 0.3s ease;
  }

  .floating-sidebar.open .mobile-toggle::before {
    transform: rotate(180deg);
  }

  .hamburger {
    display: none;
  }

  .maplibregl-ctrl-bottom-left,
  .maplibregl-ctrl-bottom-right {
    margin-bottom: 16px !important;
  }

  .maplibregl-ctrl-bottom-left {
    margin-left: 16px !important;
  }

  .maplibregl-ctrl-attrib {
    display: none !important;
  }

  .maplibregl-ctrl-attrib-button {
    display: none !important;
  }

  .vislatvijas-credit {
    display: none !important;
  }

  /* Make MapLibre marker dots easier to tap on mobile (bigger hitbox, same visual dot) */
  .maplibregl-marker {
    overflow: visible;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  .maplibregl-marker::before {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    width: var(--marker-hitbox-size, 5.2vh);
    height: var(--marker-hitbox-size, 5.2vh);
    transform: translate(-50%, -50%);
    background: transparent;
    outline: none;
    border-radius: 999px;
  }

  /* Debug-only: visualize hitbox while tuning on mobile */
  body.debug-hitbox .maplibregl-marker::before {
    background: rgba(123, 36, 41, 0.14);
    outline: 1px dashed rgba(123, 36, 41, 0.30);
  }

  .business-card .gallery-main-image { width: 100%; height: 100%; object-fit: contain; }
  .business-card .gallery-dots {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    padding: 10px 0 4px;
  }
  .business-card .gallery-dots .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    border: 2px transparent;
    background: rgba(255,255,255,0.6);
    opacity: 0.8;
    padding: 0;
  }
  .business-card .gallery-dots .dot.active {
    background: rgba(90, 27, 30, 0.85);
    border-color: rgba(90, 27, 30, 0.85);
    opacity: 1;
  }

  .business-card .card-topbar { 
    padding: 2vh;
  }

  /* Hide desktop side actions on mobile */
  .business-card .card-actions-vertical { display: none !important; }

  /* Ensure gallery stacks: stage on top, dots below */
  #mobile-popup .business-card .card-image,
  .maplibregl-popup .business-card .card-image { display: flex; flex-direction: column; align-items: center; justify-content: flex-start; height: 260px; padding: 2vh; }

  /* Safari-only: the base .card-image::before gradient can sit above the <img>
     (and even capture touches). Disable it inside the popup. */
  html.is-safari #mobile-popup .business-card .card-image::before {
    opacity: 0 !important;
    pointer-events: none !important;
  }
  #mobile-popup .business-card .gallery-column.minimal-gallery,
  .maplibregl-popup .business-card .gallery-column.minimal-gallery { display: flex; flex-direction: column; width: 100%; height: 100%; }
  #mobile-popup .business-card .gallery-stage,
  .maplibregl-popup .business-card .gallery-stage { order: 1; flex: 1 1 auto; width: 100%; }
  #mobile-popup .business-card .gallery-dots,
  .maplibregl-popup .business-card .gallery-dots { order: 2; position: static; width: 100%; justify-content: center; }

  /* When vertical space is tight, shrink the image area first (keep buttons visible). */
  #mobile-popup .business-card .card-image {
    flex: 0 1 auto !important;
    height: auto !important;
    max-height: clamp(140px, 28vh, 220px) !important;
    padding: 1vh !important;
  }
  #mobile-popup .business-card .gallery-stage {
    flex: 0 1 auto !important;
    max-height: clamp(140px, 28vh, 220px) !important;
  }
  #mobile-popup .business-card .gallery-main-image {
    max-height: clamp(140px, 28vh, 220px) !important;
  }

  /* If the description is long, shrink the image area further so the footer never gets pushed out. */
  #mobile-popup.has-long-text .business-card .card-image,
  #mobile-popup.has-long-text .business-card .gallery-stage,
  #mobile-popup.has-long-text .business-card .gallery-main-image {
    max-height: 20vh !important;
    min-height: 0 !important;
  }

  /* If content is actually clipping, shrink the image even more (guarantee room for button/footer). */
  #mobile-popup.has-overflow .business-card .card-image,
  #mobile-popup.has-overflow .business-card .gallery-stage,
  #mobile-popup.has-overflow .business-card .gallery-main-image {
    max-height: 16vh !important;
    min-height: 0 !important;
  }

  .category-pill {
    font-weight: 550 !important;
    padding: 1vh !important;
  }

  .location-logo {
    height: 5vh !important;
    width: 5vh !important;
  }
  
  /* Sticky icon row at bottom of popup */
  #mobile-popup .business-card .card-footer,
  .maplibregl-popup .business-card .card-footer {
    position: sticky;
    bottom: 0;
    left: 0;
    right: 0;
    justify-content: center;
    background: linear-gradient(180deg, rgba(255,255,255,0.95) 0%, rgba(255,255,255,1) 24px);
    border-top: 1px solid rgba(222,229,219,0.8);
    z-index: 5;
    padding: 0 !important;
  }

  /* Improve swipe: allow vertical scroll while recognizing horizontal swipes */
  .business-card .gallery-stage { touch-action: pan-y; }
  .business-card .gallery-main-image { -webkit-user-drag: none; user-select: none; }
  
  /* Mobile: footer always visible; only description scrolls */
  #mobile-popup .mobile-popup-inner {
    overflow: hidden;              /* stop whole card from scrolling */
    display: flex;
    flex-direction: column;
    max-height: 80vh;              /* constrain height */
  }
  #mobile-popup .business-card,
  .maplibregl-popup .business-card { height: 100%; display: flex; flex-direction: column; }
  #mobile-popup .business-card .card-body-row,
  .maplibregl-popup .business-card .card-body-row { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
  #mobile-popup .business-card .card-content,
  .maplibregl-popup .business-card .card-content {
    flex: 1 1 auto;
    min-height: 0;                 /* enable inner flex children scrolling */
    display: flex;
    flex-direction: column;
    overflow: hidden;              /* no scroll here */
  }
  #mobile-popup .business-card .card-description,
  .maplibregl-popup .business-card .card-description {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;              /* scroll only the text */
  }
  #mobile-popup .business-card .card-footer,
  .maplibregl-popup .business-card .card-footer {
    position: sticky;              /* pin to bottom of the visible content area */
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(180deg, rgba(255,255,255,0.95) 0%, rgba(255,255,255,1) 24px);
    border-top: 1px solid rgba(222,229,219,0.8);
    z-index: 5;
  }

  #mobile-popup .mobile-popup-inner {
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
    max-height: 80vh !important;
  }
  #mobile-popup .business-card,
  .maplibregl-popup .business-card { height: 100% !important; display: flex !important; flex-direction: column !important; }
  #mobile-popup .business-card .card-body-row,
  .maplibregl-popup .business-card .card-body-row { flex: 1 1 auto !important; min-height: 0 !important; display: flex !important; flex-direction: column !important; }
  #mobile-popup .business-card .card-content,
  .maplibregl-popup .business-card .card-content {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important; /* prevent whole content from scrolling */
    justify-content: flex-start !important;
  }
  #mobile-popup .business-card .card-description,
  .maplibregl-popup .business-card .card-description {
    flex: 1 1 auto !important;
    min-height: 72px !important; /* min only (visible) */
    max-height: none !important; /* height is controlled by flex; scroll handles overflow */
    overflow-y: auto !important; /* scroll only description */
    margin-top: 1vh !important;
    padding: 0 2vh !important;
  }
  #mobile-popup .business-card .card-learn-more,
  .maplibregl-popup .business-card .card-learn-more {
    padding: 1vh 2vh !important;
    flex: 0 0 auto !important;
  }
  #mobile-popup .business-card .learn-more-btn,
  .maplibregl-popup .business-card .learn-more-btn {
    padding: 1vh !important;
    font-size: max(14px, 2vh);
  }
  #mobile-popup .business-card .card-footer,
  .maplibregl-popup .business-card .card-footer {
    position: static !important;
    margin-top: auto !important;
    left: auto !important;
    right: auto !important;
    bottom: auto !important;
    background: linear-gradient(180deg, rgba(255,255,255,0.95) 0%, rgba(255,255,255,1) 24px) !important;
    border-top: 1px solid rgba(222,229,219,0.8) !important;
    z-index: 5 !important;
  }
  
  #mobile-popup .business-card .card-body-row,
  .maplibregl-popup .business-card .card-body-row { position: relative; display:flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }
  
  #mobile-popup .business-card .card-image,
  .maplibregl-popup .business-card .card-image {
    order: 0 !important;          /* avoid weird stacking from base order:-1 */
    flex: 0 0 auto;               /* do not shrink */
    height: auto;                 /* allow natural height if needed */
    z-index: 1;                   /* stay above content background */
  }
  #mobile-popup .business-card .gallery-column.minimal-gallery,
  .maplibregl-popup .business-card .gallery-column.minimal-gallery { flex: 0 0 auto; }
  #mobile-popup .business-card .gallery-stage,
  .maplibregl-popup .business-card .gallery-stage { flex: 1 1 auto; min-height: 0; }
  #mobile-popup .business-card .card-content,
  .maplibregl-popup .business-card .card-content { position: relative; z-index: 0; }
  
  .card-title {
    font-size: 20px;
  }

  .social-links {
    justify-content: center;
    width: 100%;
    /* Allow horizontal scroll if too many icons */
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: var(--color-gray) transparent;
    padding: 2vh;
    flex-wrap: nowrap;
    max-width: 100%;
  }

  /* Safari-only: reduce footer row padding so it doesn't steal vertical space */
  html.is-safari #mobile-popup .social-links {
    padding: 0 6px !important;
    gap: 3px !important;
    justify-content: center;
  }

  /* Safari-only: keep the sticky footer itself compact */
  html.is-safari #mobile-popup .business-card .card-footer {
    padding: 0 !important;
  }
  .social-links::-webkit-scrollbar { height: 6px; }
  .social-links::-webkit-scrollbar-track { background: transparent; }
  .social-links::-webkit-scrollbar-thumb { background: rgba(177,187,172,0.6); border-radius: 3px; }
  /* Safari-only: keep popup social icons from oversizing/glitching */
  html.is-safari #mobile-popup .social-link {
    flex: 0 0 auto;
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
    min-height: 44px !important;
    font-size: 22px !important;
  }

  html.is-safari #mobile-popup .social-link img,
  html.is-safari #mobile-popup .social-link .social-icon {
    width: 30px !important;
    height: 30px !important;
    max-width: 30px !important;
    max-height: 30px !important;
    display: block;
    object-fit: contain;
  }

  body.mobile-popup-open #mobile-popup { opacity: 1; pointer-events: auto; }

  /* When the centered mobile popup is open, keep Map controls visible but put
     them behind the overlay so they can't overlap the close button. */
  body.mobile-popup-open .maplibregl-control-container.vislat-map-controls-detached {
    z-index: 1100 !important; /* below #mobile-popup (z-index: 1200) */
  }

  #mobile-popup {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.35);
    backdrop-filter: blur(4px);
    z-index: 1200;
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s ease;
    padding: 24px;
  }
  #mobile-popup .mobile-popup-inner {
    position: relative;
    width: 100%;
    max-width: 560px;
    max-height: 80vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: #fff;
    border-radius: var(--border-radius);
    box-shadow: 0 20px 60px rgba(0,0,0,0.25);
    animation: mobilePopIn .25s ease;
  }
  @keyframes mobilePopIn { from { transform: translateY(12px); opacity:0;} to { transform: translateY(0); opacity:1;} }

  .mobile-popup-close {
    position: absolute;
    top: 0.8vh;
    right: 0.8vh;
    height: 40px;
    width: 40px;
    border-radius: 50%;
    font-size: 28px;
    line-height: 1;
    padding: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .2s ease, transform .2s ease;
    background: #fff !important;
    color: var(--color-burgundy) !important;
    border: 1px solid rgba(123,36,41,0.25) !important;
    box-shadow: 0 6px 18px rgba(0,0,0,0.18) !important;
    z-index: 50 !important;
  }

  /* Safari-only: ensure minimum tap target + centered glyph */
  html.is-safari #mobile-popup .mobile-popup-close {
    position: absolute !important;
    top: 0.8vh !important;
    right: 0.8vh !important;
    height: 40px;
    width: 40px;
    font-size: 0;
    padding-bottom: 0;
    -webkit-appearance: none;
    appearance: none;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    isolation: isolate;
    z-index: 60 !important;
    pointer-events: auto;
  }

  /* Safari-only: draw the × ourselves for perfect centering */
  html.is-safari #mobile-popup .mobile-popup-close::before {
    content: '×';
    color: var(--color-burgundy);
    font-size: 28px;
    line-height: 1;
    display: block;
    width: 100%;
    text-align: center;
    transform: translateY(-1px);
    position: relative;
    z-index: 1;
  }

  /* Safari-only: smaller visual circle, full-size tap target */
  html.is-safari #mobile-popup .mobile-popup-close::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    width: 30px;
    height: 30px;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    background: #fff;
    border: 1px solid rgba(123,36,41,0.25);
    box-shadow: 0 4px 10px rgba(0,0,0,0.14);
    z-index: 0;
    pointer-events: none;
  }
  .mobile-popup-close:hover { background: rgba(0,0,0,0.15); transform: scale(1.05); }
  .mobile-popup-close:active { transform: scale(.95); }

  /* iOS Safari: avoid tap highlight + focus rings in touch UI */
  html.is-safari .mobile-popup-close,
  html.is-safari #mobile-popup a,
  html.is-safari #mobile-popup button,
  html.is-safari #mobile-popup [role="button"],
  html.is-safari .lightbox-overlay button,
  html.is-safari .lightbox-overlay [href] {
    -webkit-tap-highlight-color: transparent;
  }
  @media (hover: none), (pointer: coarse) {
    html.is-safari #mobile-popup a:focus,
    html.is-safari #mobile-popup button:focus,
    html.is-safari #mobile-popup [tabindex]:focus,
    html.is-safari .lightbox-overlay button:focus,
    html.is-safari .lightbox-overlay [tabindex]:focus,
    html.is-safari .lightbox-overlay [href]:focus {
      outline: none !important;
    }
    html.is-safari #mobile-popup a:focus-visible,
    html.is-safari #mobile-popup button:focus-visible,
    html.is-safari #mobile-popup [tabindex]:focus-visible,
    html.is-safari .lightbox-overlay button:focus-visible,
    html.is-safari .lightbox-overlay [tabindex]:focus-visible,
    html.is-safari .lightbox-overlay [href]:focus-visible {
      outline: none !important;
    }
  }

  /* Hide maplibre default popup container when using custom overlay */
  body.mobile-popup-open .maplibregl-popup { display: none !important; }

  .gallery-thumbs, .gallery-nav { display: none !important; }

  .business-card .card-description { overflow: visible; }

  /* Fix list markers on mobile - move marker very close to text */
  #mobile-popup .card-description ul,
  #mobile-popup .card-description ol,
  .maplibregl-popup .card-description ul,
  .maplibregl-popup .card-description ol {
    padding-left: 20px !important;
    margin-left: 0;
    list-style-position: outside;
  }
  
  #mobile-popup .card-description li,
  .maplibregl-popup .card-description li {
    margin-left: 0;
    padding-left: 0;
  }

  /* Limit gallery/image height so text/content isn't squished in mobile popup */
  #mobile-popup .business-card .card-image,
  #mobile-popup .business-card .gallery-stage {
    max-height: 50vh;
  }
  #mobile-popup .business-card .gallery-main-image {
    max-height: 50vh;
    width: 100%;
    height: auto;
    object-fit: contain;
  }
  html.is-safari #mobile-popup .business-card .gallery-main-image {
    opacity: 1 !important;
    filter: none !important;
  }
  /* Safety: if default MapLibre popup is ever shown on small screens */
  .maplibregl-popup-content .business-card .card-image,
  .maplibregl-popup-content .business-card .gallery-stage {
    max-height: 50vh;
  }
  .maplibregl-popup-content .business-card .gallery-main-image {
    max-height: 50vh;
    width: 100%;
    height: auto;
    object-fit: contain;
  }

  /* Make mobile drawer scrollable */
  .floating-sidebar .locations-container {
    flex: 0 0 auto !important;
    height: auto !important;
    max-height: 30vh !important;
    overflow-y: auto !important;
    gap: 1vh;
    padding: 1vh;
    display: flex !important;
    flex-direction: column !important;
  }

  .floating-sidebar .location-card {
    width: 100% !important;
    height: auto !important;
    flex-shrink: 0 !important;
    padding: 1vh !important;
  }

  .floating-sidebar .location-empty-state {
    width: 100% !important;
    height: auto !important;
    min-height: 7vh !important;
    padding: 1vh !important;
  }

  .floating-sidebar .location-card-content {
    gap: 1vh !important;
  }

  .floating-sidebar .business-card {
    height: auto !important;
    min-height: fit-content !important;
    flex: 0 0 auto !important;
    flex-shrink: 0 !important;
  }

  .floating-sidebar .business-card .card-image {
    flex-shrink: 0 !important;
  }

  .floating-sidebar .business-card .card-body-row {
    flex: 0 0 auto !important;
    height: auto !important;
    min-height: fit-content !important;
  }

  .floating-sidebar .business-card .card-content {
    overflow-y: visible !important;
    max-height: none !important;
    height: auto !important;
    flex: 0 0 auto !important;
  }

  .floating-sidebar .business-card .card-description {
    overflow-y: visible !important;
    max-height: none !important;
    height: auto !important;
  }

  /* Hide close button on mobile (sidebar is always visible there) */
  .sidebar-close {
    display: none;
  }
}

@media (max-width: 480px) {
  .glass-panel.accent-top-right { width: 130px; height: 130px; border-radius: 28px; }
}

/* Keep card body and image from exceeding mobile popup height */
@media (max-width: 768px) and (max-height: 800px) {
  #mobile-popup .business-card .card-body-row {
    max-height: calc(80vh - 100px) !important;
    overflow-x: hidden !important;
  }
  .business-card .card-body-row { max-height: inherit; }
  .gallery-main-image {
    max-height: 20vh !important;
    max-width: 100% !important;
    height: auto !important;
    object-fit: contain !important;
  }
}

/* Ultra-small phone tweaks: keep popup images from dominating (e.g., iPhone SE) */
@media (max-width: 360px) {
  #mobile-popup .business-card .card-image,
  #mobile-popup .business-card .gallery-stage {
    height: auto !important;
    min-height: 150px !important;
    max-height: 38vh !important; /* tighter than 50vh for very short screens */
  }
  #mobile-popup .business-card .gallery-main-image {
    height: auto !important;
    max-height: 38vh !important;
    width: 100% !important;
    object-fit: contain !important;
  }
  /* If default popup shows on tiny screens, apply same cap */
  .maplibregl-popup-content .business-card .card-image,
  .maplibregl-popup-content .business-card .gallery-stage {
    height: auto !important;
    min-height: 150px !important;
    max-height: 38vh !important;
  }
  .maplibregl-popup-content .business-card .gallery-main-image {
    height: auto !important;
    max-height: 38vh !important;
    width: 100% !important;
    object-fit: contain !important;
  }
}

/* Final tiny-phone overrides: keep image area compact and clipped */
@media (max-width: 360px) {
  #mobile-popup .business-card .gallery-stage { overflow: hidden !important; }
  #mobile-popup .business-card .card-image,
  #mobile-popup .business-card .gallery-stage {
    height: auto !important;
    min-height: 120px !important;
    max-height: 32vh !important; /* tighter than previous 38vh */
  }
  #mobile-popup .business-card .gallery-main-image {
    width: 100% !important;
    height: auto !important;
    max-height: 32vh !important;
    object-fit: contain !important;
  }
  /* Fallback for default popup, same caps */
  .maplibregl-popup-content .business-card .gallery-stage { overflow: hidden !important; }
  .maplibregl-popup-content .business-card .card-image,
  .maplibregl-popup-content .business-card .gallery-stage {
    height: auto !important;
    min-height: 120px !important;
    max-height: 32vh !important;
  }
  .maplibregl-popup-content .business-card .gallery-main-image {
    width: 100% !important;
    height: auto !important;
    max-height: 32vh !important;
    object-fit: contain !important;
  }
}

/* Final SE-size override: image area max 200px on tiny screens */
@media (max-width: 360px) {
  #mobile-popup .business-card .card-image,
  #mobile-popup .business-card .gallery-stage,
  #mobile-popup .business-card .gallery-main-image,
  .maplibregl-popup-content .business-card .card-image,
  .maplibregl-popup-content .business-card .gallery-stage,
  .maplibregl-popup-content .business-card .gallery-main-image {
    max-height: 200px !important;
    height: auto !important;
  }
}

/* Extra small social icons for ultra-narrow screens (popup only) */
@media (max-width: 360px) {
  #mobile-popup .social-links {
    gap: 1vh;
  }
  #mobile-popup .social-link {
    width: 5vh !important;
    height: 5vh !important;
    max-width: 40px;
    max-height: 40px;
    font-size: 3vh !important;
  }
}

/* Also account for short heights regardless of width */
@media (max-height: 640px) and (max-width: 400px) {
  #mobile-popup .business-card .card-image,
  #mobile-popup .business-card .gallery-stage { max-height: 34vh !important; }
  #mobile-popup .business-card .gallery-main-image { max-height: 34vh !important; }
  .maplibregl-popup-content .business-card .card-image,
  .maplibregl-popup-content .business-card .gallery-stage { max-height: 34vh !important; }
  .maplibregl-popup-content .business-card .gallery-main-image { max-height: 34vh !important; }
}

/* Final hard cap for small phones (<=400px wide, e.g., iPhone SE 375px): 200px image area */
@media (max-width: 400px) {
  #mobile-popup .business-card .card-image,
  #mobile-popup .business-card .gallery-stage,
  #mobile-popup .business-card .gallery-main-image,
  .maplibregl-popup-content .business-card .card-image,
  .maplibregl-popup-content .business-card .gallery-stage,
  .maplibregl-popup-content .business-card .gallery-main-image {
    height: auto !important;
    min-height: 100px !important;
    max-height: 200px !important;
  }
}

/* Fallback for older browsers that don't support modern CSS - target very small/old devices */
/* iPhone 8 is 375x667. Only target screens ≤375px wide AND ≤680px tall */
@media (max-width: 375px) and (max-height: 680px) {
  .social-link {
    flex: 0 0 auto;
    min-width: 40px !important;
    min-height: 40px !important;
    overflow: hidden;
  }

  .social-link img,
  .social-link .social-icon {
    min-width: 40px !important;
    min-height: 40px !important;
    display: block;
    object-fit: contain;
  }
}
