/* 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);
  }
  
  .maplibregl-ctrl-group:has(.maplibregl-ctrl-zoom-in) {
    display: none !important;
  }
  
  .member-counter {
    bottom: 6vh;
    left: 2vh;
    padding: 10px 12px;
    font-size: 2vh;
    gap: 1vh;
  }

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

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

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

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

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

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

  .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;
  }

  .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;
  }
  .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; }
  #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; }

  .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;
    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 */
    padding-bottom: 0 !important;
  }
  #mobile-popup .business-card .card-description,
  .maplibregl-popup .business-card .card-description {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    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;
  }
  #mobile-popup .business-card .learn-more-btn,
  .maplibregl-popup .business-card .learn-more-btn {
    padding: 1vh !important;
    font-size: 2vh;
  }
  #mobile-popup .business-card .card-footer,
  .maplibregl-popup .business-card .card-footer {
    position: sticky !important;
    bottom: 0 !important;
    left: 0 !important; right: 0 !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;
    /* 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%;
  }
  .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; }
  .social-link { flex: 0 0 auto; }

  body.mobile-popup-open #mobile-popup { opacity: 1; pointer-events: auto; }
  #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;
    height: 4vh;
    width: 4vh;
    top: 2vh;
    right: 2vh;
    border-radius: 50%;
    font-size: 4vh;
    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;
  }
  .mobile-popup-close:hover { background: rgba(0,0,0,0.15); transform: scale(1.05); }
  .mobile-popup-close:active { transform: scale(.95); }

  /* 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;
  }
  /* 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-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; }
}

/* 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 */
  .social-links {
    gap: 1vh; /* Even smaller gap */
  }
  
  .social-link {
    width: 5vh !important; /* Smaller icons */
    height: 5vh !important;
    font-size: 3vh !important; /* Smaller icon size */
  }

/* 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;
  }
}
