/**
 * MOBILE MAP OVERRIDES — INTRO_1 + ANUNAKI
 * Google Maps-style bottom sheet pattern
 *
 * Ladowany WYLACZNIE na stronie demo (page-parcelselector-demo.php).
 * Pliki intro-popup.css i anunaki-popup.css pozostaja nienaruszone.
 *
 * Urzadzenia: smartfony i tablety (max-width: 768px)
 * Orientacja: portrait + landscape (osobne reguly)
 *
 * UX flow na mobile:
 *   1. Mapa wypelnia caly ekran (fullscreen)
 *   2. Header: minimalny pasek (flagi + X) — logo ukryte
 *   3. Sidebar: bottom sheet — wysuwa sie od dolu nad mapa
 *      - Drag handle (szary paski) sugeruje mozliwosc przesuwania
 *      - Wyszukiwarka zawsze widoczna u gory sheeta
 *      - Wyniki pojawiaja sie ponizej pola wyszukiwania (max 50% ekranu)
 *   4. Klikniecie markera: detail panel wysuwa sie od dolu (80vh max)
 *   5. Landscape: header jeszcze mniejszy, sidebar max 35%
 */

/* ============================================================
   INTRO_1 — Portrait mobile (<=768px)
   ============================================================ */
@media (max-width: 768px) {

    /* OVERLAY: bez blur — oszczednosc GPU na slabszych urzadzeniach */
    .inpost-popup-overlay {
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
    }

    /* CONTAINER: scisly pelny ekran
       100dvh = dynamic viewport height — uwzglednia toolbar Chrome/Safari/Firefox
       Fallback 100vh dla starszych przegladarek */
    .inpost-popup-container {
        position: fixed;
        inset: 0;
        width: 100%;
        height: 100vh;
        height: 100dvh;
        max-height: none;
        max-width: none;
        border-radius: 0;
        margin: 0;
        animation: none;
    }

    /* HEADER: minimalny pasek ~52px */
    .inpost-popup-header {
        flex-shrink: 0;
    }

    .inpost-popup-header-top {
        padding: 6px 10px;
        gap: 6px;
        min-height: 52px;
    }

    /* Logo: ukryte — miejsce dla flag i przycisku X
       Przycisk zamknij (.inpost-popup-close) pozostaje widoczny */
    .inpost-popup-logo-left {
        display: none;
    }
    .inpost-popup-logo-right .inpost-logo-img,
    .inpost-popup-logo-right .shop-logo-img {
        display: none;
    }
    .inpost-popup-logo-right {
        min-width: 44px;
        justify-content: flex-end;
    }

    /* Flagi: pelna szerokosc, horizontal scroll, bez widocznego scrollbara */
    .inpost-popup-flags {
        flex: 1;
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        justify-content: flex-start;
        gap: 4px;
        padding: 4px 0;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .inpost-popup-flags::-webkit-scrollbar { display: none; }

    .inpost-flag-btn {
        width: 30px;
        height: 30px;
        font-size: 17px;
        flex-shrink: 0;
        border-width: 2px;
    }
    .inpost-flag-btn.active::after {
        width: 14px;
        height: 14px;
        font-size: 9px;
        bottom: -3px;
        right: -3px;
    }

    /* Instrukcje (dolny wiersz headera): ukryte — zbedne na mobile */
    .inpost-popup-header-bottom {
        display: none;
    }

    /* BODY: kontener wzgledny — mapa i sidebar pozycjonowane absolutnie */
    .inpost-popup-body {
        flex: 1;
        flex-direction: column;
        position: relative;
        min-height: 0;
        overflow: hidden;
    }

    /* MAPA: absolute fill — wypelnia caly obszar body */
    .inpost-popup-map-container {
        position: absolute;
        inset: 0;
        flex: none;
        width: 100%;
        height: 100%;
    }

    /* SIDEBAR: bottom sheet nakladajacy sie na mape
       touch-action: pan-y — przewijanie listy nie porusza mapa */
    .inpost-popup-sidebar {
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-height: 50%;
        z-index: 500;
        background: #fff;
        border-radius: 20px 20px 0 0;
        box-shadow: 0 -4px 30px rgba(0, 0, 0, 0.25);
        border-right: none;
        display: flex;
        flex-direction: column;
        touch-action: none; /* Changed for JS swipe handling */
        transition: transform 0.6s cubic-bezier(0.16, 1, 0.3, 1);
        will-change: transform;
    }

    /* Drag handle — wizualny hint sugerujacy mozliwosc przesuwania */
    .inpost-popup-sidebar::before {
        content: '';
        display: block;
        flex-shrink: 0;
        width: 40px;
        height: 5px;
        background: #e0e0e0;
        border-radius: 3px;
        margin: 10px auto 10px;
    }

    /* WYSZUKIWARKA: Bardziej kompaktowa na mobile */
    .inpost-search-box {
        padding: 5px 15px 10px !important;
        border-bottom: 1px solid #f0f0f0 !important;
    }

    .inpost-search-input {
        padding: 8px 12px !important;
        font-size: 14px !important;
        height: 38px !important;
        border-radius: 12px !important;
        background: #f8f8f8 !important;
    }

    /* Lista punktow: przewijalna wewnatrz sheeta */
    .inpost-points-list {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        padding: 10px 15px !important;
    }

    /* Strzalki dla flag */
    .inpost-popup-flags-container {
        position: relative;
        display: flex;
        align-items: center;
        width: 100%;
        overflow: hidden;
    }

    .ps-flag-arrow {
        position: absolute;
        top: 50%;
        transform: translateY(-50%);
        width: 32px;
        height: 32px;
        background: #fff;
        color: #333;
        border: 1px solid #eee;
        border-radius: 50%;
        z-index: 10;
        display: flex; /* Always flex on mobile for easy navigation */
        align-items: center;
        justify-content: center;
        font-size: 12px;
        box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        cursor: pointer;
    }
    .ps-flag-arrow.left { left: 2px; }
    .ps-flag-arrow.right { right: 2px; }

    /* Floating Lupa Button */
    .ps-mobile-restore-search {
        position: fixed;
        bottom: 20px;
        right: 20px;
        width: 50px;
        height: 50px;
        background: #FF6600;
        color: white;
        border-radius: 50%;
        display: none;
        align-items: center;
        justify-content: center;
        font-size: 24px;
        z-index: 10001;
        box-shadow: 0 4px 15px rgba(255,102,0,0.4);
        border: 2px solid white;
    }

    /* STABILIZACJA SUKCESU - stop flickering */
    .inpost-success-panel {
        background: #fff;
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -4px 30px rgba(0,0,0,0.15);
        z-index: 1000;
        animation: slideInUpStable 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards;
        will-change: transform, opacity;
        display: flex !important;
        flex-direction: column;
        padding: 20px;
        max-height: 80vh;
    }

    @keyframes slideInUpStable {
        from { transform: translateY(100%); opacity: 0; }
        to { transform: translateY(0); opacity: 1; }
    }

    /* Footer statystyki: ukryty — zbedny na mobile */
    .inpost-popup-footer {
        display: none;
    }

    /* SELECTION MODE override: sidebar zostaje widoczny po wyborze paczkomatu
       (na desktopie chowa sie — tu nie chcemy tego zachowania) */
    .ps-selection-mode .inpost-popup-sidebar {
        transform: none !important;
        margin-left: 0 !important;
        opacity: 1 !important;
    }

    /* DETAIL MODAL: wysuwa sie od dolu jak bottom sheet */
    .inpost-detail-modal {
        width: 100%;
        max-width: 100%;
        margin: 0;
        border-radius: 16px 16px 0 0;
        max-height: 80vh;
        max-height: 80dvh;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
    }

    .detail-modal-header h3 {
        font-size: 18px;
        padding-right: 55px;
    }

    .detail-modal-close {
        width: 48px;
        height: 48px;
        font-size: 26px;
    }

    .detail-modal-footer {
        flex-direction: column;
        gap: 10px;
    }

    .detail-modal-footer .inpost-btn {
        width: 100%;
    }
}

/* iPhone SE i bardzo male ekrany: scisly pelny ekran bez marginesow */
@media (max-width: 480px) {
    .inpost-popup-container {
        width: 100% !important;
        margin: 0 !important;
        inset: 0 !important;
    }
}

/* ============================================================
   INTRO_1 — Landscape mobile (krotki ekran, np. iPhone poziomo)
   max-height: 500px wyklucza tablety w landscape
   ============================================================ */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {

    .inpost-popup-container {
        position: fixed;
        inset: 0;
        width: 100%;
        height: 100vh;
        height: 100dvh;
        max-height: none;
        border-radius: 0;
        margin: 0;
        animation: none;
    }

    /* Header jeszcze bardziej kompaktowy — liczy sie kazdy piksel */
    .inpost-popup-header-top {
        padding: 4px 10px;
        min-height: 40px;
    }
    .inpost-popup-header-bottom { display: none; }
    .inpost-popup-logo-left { display: none; }
    .inpost-popup-logo-right .inpost-logo-img,
    .inpost-popup-logo-right .shop-logo-img { display: none; }
    .inpost-popup-logo-right { min-width: 40px; }

    .inpost-flag-btn {
        width: 26px;
        height: 26px;
        font-size: 14px;
    }

    .inpost-popup-body {
        flex: 1;
        position: relative;
        min-height: 0;
        overflow: hidden;
    }

    .inpost-popup-map-container {
        position: absolute;
        inset: 0;
        flex: none;
        width: 100%;
        height: 100%;
    }

    /* Sidebar: max 35% — landscape jest krotki, mapa musi oddychac */
    .inpost-popup-sidebar {
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-height: 35%;
        z-index: 500;
        background: #fff;
        border-radius: 12px 12px 0 0;
        box-shadow: 0 -3px 16px rgba(0, 0, 0, 0.18);
        border-right: none;
        display: flex;
        flex-direction: column;
        touch-action: pan-y;
    }

    .inpost-popup-sidebar::before {
        content: '';
        display: block;
        flex-shrink: 0;
        width: 30px;
        height: 3px;
        background: #ddd;
        border-radius: 2px;
        margin: 6px auto 0;
    }

    .inpost-popup-footer { display: none; }

    .ps-selection-mode .inpost-popup-sidebar {
        transform: none !important;
        margin-left: 0 !important;
        opacity: 1 !important;
    }
}

/* ============================================================
   ANUNAKI — Mobile fixes (<=768px)
   ============================================================ */
@media (max-width: 768px) {

    /* Overlay: bez blur na mobile */
    .ank-overlay {
        padding: 0;
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
    }

    /* Container: scisly pelny ekran */
    .ank-container {
        position: fixed;
        inset: 0;
        width: 100%;
        height: 100vh;
        height: 100dvh;
        max-height: none;
        max-width: none;
        border-radius: 0;
        animation: none;
    }

    .ank-header-top { padding: 4px 10px; gap: 6px; min-height: 48px; }
    
    /* Logo: ukryte dla oszczednosci miejsca */
    .ank-logo { display: none !important; }
    
    /* Search Wrap: pelna szerokosc */
    .ank-search-wrap { flex: 1; margin: 0; }
    .ank-search-field { height: 38px !important; }
    .ank-search-input { font-size: 14px !important; padding: 4px 10px !important; }
    
    /* Search Btn: tylko ikona na mobile */
    .ank-search-btn { width: 44px; padding: 0; justify-content: center; }
    .ank-search-btn span { display: none; }
    
    /* Flags Container */
    .ank-flags-container {
        position: relative;
        display: flex;
        align-items: center;
        background: #f8fafc;
        border-bottom: 1px solid #e2e8f0;
        padding: 4px 0;
    }
    
    .ank-flags {
        flex: 1;
        display: flex;
        overflow-x: auto;
        padding: 4px 12px;
        gap: 8px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .ank-flags::-webkit-scrollbar { display: none; }
    
    .ank-flag-arrow {
        width: 32px;
        height: 32px;
        background: #fff;
        color: #64748b;
        border: none;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 14px;
        flex-shrink: 0;
        z-index: 10;
        box-shadow: 0 0 10px rgba(0,0,0,0.05);
    }
    .ank-flag-arrow.left { border-right: 1px solid #f1f5f9; }
    .ank-flag-arrow.right { border-left: 1px solid #f1f5f9; }

    .ank-flag-btn {
        padding: 6px 12px !important;
        font-size: 13px !important;
        flex-shrink: 0;
    }
    .ank-flag-btn .ank-flag-name {
        white-space: nowrap;
    }

    /* Detail panel: od dolu, bez marginesow */
    .ank-detail-panel {
        left: 0;
        right: 0;
        bottom: 0;
        border-radius: 16px 16px 0 0;
    }
}

/* ANUNAKI landscape */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
    .ank-container {
        position: fixed;
        inset: 0;
        height: 100vh;
        height: 100dvh;
        max-height: none;
        border-radius: 0;
        animation: none;
    }
    .ank-header-top { padding: 4px 12px; min-height: 40px; }
}
