/* Мобільні PWA оптимізації для agro-space.app */

/* CSS змінні для viewport height */
:root {
    --vh: 1vh;
    --mobile-menu-height: 65px; /* Уніфіковано з smart-navigation.css - iOS стандарт */
}

/* Заховуємо скролбари в PWA режимі */
@media (display-mode: standalone) {
    ::-webkit-scrollbar {
        width: 2px;
    }
    
    ::-webkit-scrollbar-track {
        background: transparent;
    }
    
    ::-webkit-scrollbar-thumb {
        background: rgba(0,0,0,0.2);
        border-radius: 10px;
    }
}

/* Загальні стилі для всіх пристроїв */
.mobile-bottom-nav {
    display: none; /* За замовчуванням ховаємо */
    /* Забезпечуємо консистентність при показі */
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--mobile-menu-height) + env(safe-area-inset-bottom, 20px)); /* Уніфіковано Safe Area */
    min-height: calc(var(--mobile-menu-height) + env(safe-area-inset-bottom, 20px)); /* Уніфіковано Safe Area */
    max-height: calc(var(--mobile-menu-height) + env(safe-area-inset-bottom, 20px)); /* Уніфіковано Safe Area */
    background: rgba(255, 255, 255, 0.94) !important; /* Уніфіковано з smart-navigation.css - iOS стандарт */
    backdrop-filter: blur(20px); /* Уніфіковано з smart-navigation.css */
    -webkit-backdrop-filter: blur(20px); /* iOS підтримка */
    border-top: 0.5px solid rgba(60, 60, 67, 0.12); /* Уніфіковано з smart-navigation.css - iOS стиль */
    z-index: 2000;
    align-items: center;
    justify-content: space-around;
    padding: 8px 16px calc(8px + env(safe-area-inset-bottom, 20px)) 16px; /* Уніфіковано з smart-navigation.css */
    box-shadow: 0 -0.5px 0 0 rgba(60, 60, 67, 0.12); /* Уніфіковано з smart-navigation.css - iOS стиль */
}

.mobile-fab {
    display: none; /* За замовчуванням ховаємо */
}

/* PWA кнопка - загальні стилі для всіх пристроїв */
#installPWA {
    display: none; /* ЗАВЖДИ прихована за замовчуванням */
    transition: all 0.3s ease-in-out;
    opacity: 0;
    visibility: hidden;
    transform: scale(0.95);
}

#installPWA.show {
    display: flex !important; /* Показуємо як flex для правильного вирівнювання */
    opacity: 1;
    visibility: visible;
    transform: scale(1);
}

/* Забезпечуємо правильний gap для flexbox контейнера */
.d-flex[style*="gap"] {
    gap: 1rem !important;
}

/* Забезпечуємо центрування контейнера кнопок */
.d-flex.justify-content-center.align-items-center {
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
}

/* Гарантуємо, що всі кнопки мають однакові розміри */
.d-flex.justify-content-center .btn {
    width: 180px !important;
    height: 48px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    flex-shrink: 0;
    font-size: 0.9rem !important;
    padding: 0 !important;
}

/* Коли екран вужчий за 450px - автоматично вертикально */
@media (max-width: 450px) {
    .d-flex.justify-content-center.align-items-center[style*="flex-wrap"] {
        flex-direction: column !important;
        gap: 0.75rem !important;
    }
    
    .d-flex.justify-content-center .btn {
        width: 200px !important;
        height: 48px !important;
        max-width: 90vw;
    }
}

/* На дуже вузьких екранах */
@media (max-width: 350px) {
    .d-flex.justify-content-center .btn {
        width: 180px !important;
        font-size: 0.85rem !important;
    }
}

/* Гарантовано приховуємо мобільні елементи на десктопі */
@media (min-width: 769px) {
    .mobile-bottom-nav,
    .mobile-fab,
    .mobile-fields-panel {
        display: none !important;
    }
    
    .mobile-bottom-nav.force-show,
    .mobile-fab.force-show {
        display: none !important;
    }
}

/* Мобільні оптимізації - приховуємо елементи на мобільних */
@media (max-width: 768px) {
    /* Дозволяємо прокручування для головної сторінки */
    /* Дозволяємо прокручування для всіх сторінок крім карти */
    body, html {
        margin: 0;
        padding: 0;
        min-height: 100vh;
        min-height: calc(var(--vh, 1vh) * 100);
        overflow-x: hidden; /* Приховуємо горизонтальне прокручування */
        overflow-y: auto; /* Дозволяємо вертикальне прокручування */
    }

    /* Додаємо відступ знизу для мобільного меню - уніфіковано з smart-navigation.css */
    body {
        padding-bottom: calc(var(--mobile-menu-height) + env(safe-area-inset-bottom, 20px)) !important; /* Уніфіковано з smart-navigation.css */
    }

    /* Для сторінки карти - окремі правила */
    body.page-map {
        overflow: hidden !important;
        padding-bottom: 0 !important;
    }

    body.page-map .map-wrapper {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: calc(var(--mobile-menu-height) + env(safe-area-inset-bottom, 20px)) !important; /* Уніфіковано Safe Area - залишаємо місце для нижнього меню */
        z-index: 1 !important;
    }

    body.page-map #map {
        width: 100% !important;
        height: 100% !important;
        position: relative !important;
    }

    /* Додаткові мобільні стилі для головної сторінки */
    .container {
        padding-left: 15px !important;
        padding-right: 15px !important;
    }

    /* Покращуємо відображення кнопок на мобільних */
    .btn-lg {
        font-size: 1rem !important;
        padding: 0.75rem 1.5rem !important;
    }

    /* Hero секція мобільні оптимізації */
    .display-4 {
        font-size: 2rem !important;
    }

    .lead {
        font-size: 1rem !important;
    }

    /* Покращуємо карточки features */
    .card {
        margin-bottom: 1rem;
    }

    /* Для сторінки карти */
    .page-map body {
        overflow: hidden;
        padding-bottom: 0;
    }

    .page-map .map-wrapper {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 80px !important; /* Залишаємо місце для нижнього меню */
        z-index: 1 !important;
    }

    .page-map #map {
        width: 100% !important;
        height: 100% !important;
        position: relative !important;
    }

    /* Приховуємо navbar на мобільних */
    .navbar {
        display: none !important;
    }
    
    /* Приховуємо бокову панель на мобільних */
    .sidebar {
        display: none !important;
    }
    
    /* Приховуємо легенду на мобільних */
    .legend-container,
    #legend-container,
    .map-legend,
    .leaflet-control-legend,
    .legend-card {
        display: none !important;
    }
    
    /* Приховуємо панель фільтрів та інші десктопні контроли */
    .fields-card,
    .filters-panel,
    .control-panel,
    .desktop-controls {
        display: none !important;
    }
    
    /* Приховуємо хедер/навбар */
    header,
    .header,
    .top-nav {
        display: none !important;
    }
    
    /* Основний контейнер сторінки */
    .container-fluid {
        padding: 0 !important;
        margin: 0 !important;
    }
    
    /* Приховуємо всі десктопні контроли */
    .d-none.d-lg-block,
    .d-none.d-md-block {
        display: none !important;
    }
}

/* Форсуємо показ мобільних елементів */
.mobile-bottom-nav.force-show {
    display: flex !important;
}

.mobile-fab.force-show {
    display: flex !important;
}

/* Мобільні touch оптимізації */
@media (max-width: 768px) {
    /* Показуємо мобільні елементи */
    .mobile-bottom-nav {
        display: flex !important; /* Показуємо на мобільних */
    }
    
    .mobile-fab {
        display: flex !important; /* Показуємо на мобільних */
    }
    
    /* Мобільне нижнє меню - показуємо тільки на мобільних */
    .mobile-bottom-nav {
        display: flex !important; /* Показуємо на мобільних */
    }
    
    .mobile-nav-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        text-decoration: none;
        color: #6c757d;
        font-size: 12px;
        font-weight: 500;
        padding: 12px 8px calc(8px + env(safe-area-inset-bottom, 0px) / 2) 8px; /* Оптимальний padding */
        border-radius: 6px;
        transition: all 0.2s ease;
        min-width: 60px;
        flex: 1;
        text-align: center;
        position: relative;
        touch-action: manipulation;
        background: none;
        border: none;
        cursor: pointer;
        min-height: 50px; /* Стандартна мінімальна висота для зручного натискання */
    }
    
    .mobile-nav-item i {
        font-size: 22px;
        margin-bottom: 4px;
        transition: all 0.2s ease;
    }
    
    .mobile-nav-item.active {
        color: #198754;
        background: rgba(25, 135, 84, 0.08);
    }
    
    .mobile-nav-item.active i {
        transform: scale(1.05);
    }
    
    /* Спеціальні стилі для dropdown в мобільному меню */
    .mobile-nav-item.dropdown .btn {
        background: none !important;
        border: none !important;
        color: #6c757d !important;
        font-size: 12px !important;
        font-weight: 500 !important;
        padding: 12px 8px calc(8px + env(safe-area-inset-bottom, 0px) / 2) 8px !important; /* Оптимальний padding */
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        text-decoration: none !important;
        min-width: 60px !important;
        flex: 1 !important;
        text-align: center !important;
        position: relative !important;
        touch-action: manipulation !important;
        transition: all 0.2s ease !important;
        min-height: 50px !important; /* Стандартна мінімальна висота для зручного натискання */
    }
    
    .mobile-nav-item.dropdown .btn i {
        font-size: 22px !important;
        margin-bottom: 4px !important;
        transition: all 0.2s ease !important;
    }
    
    .mobile-nav-item.dropdown .btn:hover,
    .mobile-nav-item.dropdown .btn:focus {
        background: rgba(25, 135, 84, 0.08) !important;
        color: #198754 !important;
        box-shadow: none !important;
    }
    
    /* Dropdown menu в мобільному меню повинно відкриватися вгору */
    .mobile-nav-item.dropdown .dropdown-menu {
        bottom: 100% !important;
        top: auto !important;
        margin-bottom: 8px !important;
        border: 1px solid rgba(0, 0, 0, 0.1) !important;
        box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.1) !important;
    }
    
    /* Індикатор активного елементу (крапочка зверху) */
    .mobile-nav-item.active::before {
        content: '';
        position: absolute;
        top: -2px;
        left: 50%;
        transform: translateX(-50%);
        width: 4px;
        height: 4px;
        background: #198754;
        border-radius: 50%;
        animation: pulse 2s infinite;
    }
    
    @keyframes pulse {
        0% { opacity: 1; transform: translateX(-50%) scale(1); }
        50% { opacity: 0.5; transform: translateX(-50%) scale(1.2); }
        100% { opacity: 1; transform: translateX(-50%) scale(1); }
    }
    
    .mobile-nav-item:hover, .mobile-nav-item:active {
        color: #198754;
        background: rgba(25, 135, 84, 0.05);
        transform: translateY(-1px);
    }
    
    /* Центральна кнопка у звичайному стилі */
    .mobile-nav-center {
        background: none !important;
        color: #6c757d !important;
        border-radius: 6px !important;
        margin: 0 4px !important;
        box-shadow: none !important;
        border: none !important;
    }
    
    .mobile-nav-center .center-icon {
        color: #6c757d !important;
        font-size: 22px !important;
    }
    
    .mobile-nav-center span {
        color: #6c757d !important;
        font-size: 12px !important;
        font-weight: 500 !important;
        margin-top: 4px;
    }
    
    .mobile-nav-center:hover, .mobile-nav-center:active {
        background: rgba(25, 135, 84, 0.05) !important;
        color: #198754 !important;
        transform: translateY(-1px) !important;
        box-shadow: none !important;
    }
    
    .mobile-nav-center.active {
        background: rgba(25, 135, 84, 0.08) !important;
        color: #198754 !important;
        box-shadow: none !important;
    }
    
    .mobile-nav-center.active i {
        color: #198754 !important;
        transform: scale(1.05) !important;
    }
    
    .mobile-nav-center.active span {
        color: #198754 !important;
    }
    
    /* Мобільний випливаючий панель ділянок */
    .mobile-fields-panel {
        position: fixed;
        bottom: -70vh;
        left: 0;
        right: 0;
        height: 70vh;
        background: white;
        border-radius: 20px 20px 0 0;
        box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.15);
        z-index: 2500;
        transition: bottom 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }
    
    .mobile-fields-panel.show {
        bottom: 80px; /* Висота нижнього меню */
    }
    
    .mobile-panel-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 16px 20px 12px;
        border-bottom: 1px solid #e9ecef;
        background: #f8f9fa;
        border-radius: 20px 20px 0 0;
        position: relative;
    }
    
    .mobile-panel-handle {
        position: absolute;
        top: 8px;
        left: 50%;
        transform: translateX(-50%);
        width: 40px;
        height: 4px;
        background: #dee2e6;
        border-radius: 2px;
    }
    
    .mobile-panel-header h6 {
        color: #198754;
        font-weight: 600;
        margin-top: 8px;
    }
    
    .mobile-panel-actions {
        display: flex;
        gap: 8px;
        margin-top: 8px;
    }
    
    .mobile-panel-actions .btn {
        padding: 6px 8px;
        font-size: 14px;
        border-radius: 6px;
    }
    
    /* Стилі для dropdown експорту в header мобільної панелі */
    .mobile-panel-actions .btn-group .dropdown-toggle {
        padding: 6px 10px;
        font-size: 14px;
    }
    
    .mobile-panel-actions .dropdown-menu {
        font-size: 13px;
        min-width: 140px;
    }
    
    .mobile-panel-actions .dropdown-item {
        padding: 6px 12px;
    }
    
    .mobile-panel-actions .dropdown-item i {
        font-size: 12px;
        margin-right: 6px;
    }
    
    .mobile-panel-content {
        flex: 1;
        padding: 20px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .mobile-panel-actions {
        display: flex;
        gap: 8px;
        margin-top: 20px;
        padding-top: 16px;
        border-top: 1px solid #e9ecef;
        flex-wrap: wrap;
    }
    
    .mobile-panel-actions .btn {
        flex: 1;
        min-width: 0;
    }
    
    /* Overlay для закриття панелі */
    .mobile-panel-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.3);
        z-index: 2000;
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s ease;
    }
    
    .mobile-panel-overlay.show {
        opacity: 1;
        visibility: visible;
    }
    
    /* Стилі для мобільного реєстру в панелі */
    #mobile-tenants-registry {
        max-height: 40vh;
        overflow-y: auto;
    }
    
    /* Мобільна таблиця реєстру */
    #mobile-tenants-registry .table-responsive-mobile {
        border-radius: 8px;
        overflow: hidden;
        box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        font-size: 13px;
    }
    
    #mobile-tenants-registry .mobile-registry-table {
        margin-bottom: 0;
        font-size: 13px;
    }
    
    #mobile-tenants-registry .mobile-registry-table th {
        background: #198754;
        color: white;
        border: none;
        padding: 12px 8px;
        font-size: 12px;
        font-weight: 600;
        text-align: center;
    }
    
    #mobile-tenants-registry .mobile-registry-table td {
        padding: 12px 8px;
        vertical-align: middle;
        border-bottom: 1px solid #f1f3f4;
    }
    
    #mobile-tenants-registry .mobile-registry-table tbody tr {
        transition: all 0.2s ease;
        cursor: pointer;
        position: relative;
        overflow: hidden;
    }
    
    #mobile-tenants-registry .mobile-registry-table tbody tr:hover {
        background-color: rgba(13, 110, 253, 0.08);
        transform: translateX(2px);
    }
    
    #mobile-tenants-registry .mobile-registry-table tbody tr:active {
        background-color: rgba(13, 110, 253, 0.15);
        transform: scale(0.98);
    }
    
    /* Touch анімація для ділянок реєстру */
    #mobile-tenants-registry .mobile-registry-table tbody tr::before {
        content: '';
        position: absolute;
        top: 0;
        left: -100%;
        width: 100%;
        height: 100%;
        background: linear-gradient(90deg, transparent, rgba(13, 110, 253, 0.3), transparent);
        transition: left 0.3s ease;
        z-index: 1;
        pointer-events: none;
    }
    
    #mobile-tenants-registry .mobile-registry-table tbody tr:active::before {
        left: 100%;
    }
    
    /* Виділення активної ділянки */
    #mobile-tenants-registry .mobile-registry-table tbody tr.selected,
    #mobile-tenants-registry .mobile-registry-table tbody tr.highlighted {
        background-color: rgba(40, 167, 69, 0.1) !important;
        border-left: 3px solid #28a745;
    }
    
    #mobile-tenants-registry .btn {
        padding: 6px 10px;
        font-size: 11px;
        border-radius: 6px;
        margin: 2px;
    }
    
    #mobile-tenants-registry .btn i {
        font-size: 12px;
    }
    
    /* Стилі для спінера завантаження */
    #mobile-tenants-registry .spinner-border {
        width: 2rem;
        height: 2rem;
    }
    
    /* Заглушка коли немає даних */
    #mobile-tenants-registry .text-center.py-4 {
        padding: 2rem 1rem !important;
    }
    
    #mobile-tenants-registry .text-center.py-4 i {
        margin-bottom: 1rem;
    }
    
    /* Значок сповіщень */
    .mobile-nav-item .badge {
        position: absolute;
        top: 4px;
        right: 8px;
        min-width: 18px;
        height: 18px;
        font-size: 10px;
        border-radius: 9px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: #dc3545;
        color: white;
        font-weight: 600;
    }
    
    /* Збільшуємо кнопки для touch */
    .btn {
        min-height: 44px;
        min-width: 44px;
        padding: 12px 16px;
    }
    
    .btn-sm {
        min-height: 36px;
        min-width: 36px;
        padding: 8px 12px;
    }
    
    /* Touch-friendly елементи управління */
    .leaflet-control {
        touch-action: manipulation;
    }
    
    .leaflet-control-zoom a {
        width: 44px !important;
        height: 44px !important;
        line-height: 44px !important;
        font-size: 20px !important;
    }
    
    /* Оптимізований sidebar для мобільних */
    .sidebar {
        touch-action: pan-y;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }
    
    /* Покращені модальні вікна для touch */
    .modal-content {
        margin: 10px;
        border-radius: 12px;
        overflow: hidden;
    }
    
    .modal-header {
        padding: 20px;
        touch-action: manipulation;
    }
    
    .modal-body {
        padding: 20px;
        max-height: 60vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Фільтри оптимізовані для мобільних */
    .filter-section {
        margin-bottom: 24px;
    }
    
    .filter-section h6 {
        font-size: 16px;
        font-weight: 600;
        margin-bottom: 12px;
        touch-action: manipulation;
    }
    
    /* Чекбокси та радіо кнопки більшого розміру */
    .form-check-input {
        width: 20px;
        height: 20px;
        margin-top: 2px;
        border-width: 2px;
    }
    
    .form-check-label {
        font-size: 15px;
        line-height: 1.4;
        padding-left: 8px;
        touch-action: manipulation;
    }
    
    /* Мобільна навігація */
    .navbar-toggler {
        border: none;
        padding: 8px;
        border-radius: 8px;
    }
    
    .navbar-toggler:focus {
        box-shadow: 0 0 0 2px rgba(13, 110, 253, 0.25);
    }
    
    /* Оптимізований dropdown для мобільних */
    .dropdown-menu {
        min-width: 200px;
        border-radius: 12px;
        box-shadow: 0 8px 32px rgba(0,0,0,0.12);
        border: none;
        padding: 8px;
    }
    
    .dropdown-item {
        padding: 12px 16px;
        border-radius: 8px;
        font-size: 15px;
        touch-action: manipulation;
    }
    
    /* Карта оптимізована для мобільних */
    #map {
        touch-action: none;
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
    }
    
    /* Покращені контроли Leaflet для мобільних */
    .leaflet-control-container {
        pointer-events: auto;
    }
    
    .leaflet-control-zoom {
        margin-right: 10px !important;
        margin-top: 10px !important;
        border-radius: 8px !important; /* Заокруглені кути для групування */
    }
    
    .leaflet-control-layers {
        margin-right: 10px !important;
        margin-top: 86px !important; /* 10px + 66px (zoom height) + 10px відступ */
        border-radius: 8px !important; /* Заокруглені кути для групування */
    }
    
    /* Групування контролів карти в правому верхньому куті */
    .leaflet-top.leaflet-right {
        margin-top: env(safe-area-inset-top, 0px);
        margin-right: env(safe-area-inset-right, 0px);
    }
    
    /* Оптимізований розмір popup для мобільних */
    .leaflet-popup {
        margin-bottom: 100px; /* Уникаємо перекриття з нижнім меню */
    }
    
    /* Popup оптимізації */
    .leaflet-popup-content-wrapper {
        border-radius: 12px;
        box-shadow: 0 8px 32px rgba(0,0,0,0.12);
        max-width: 280px !important;
    }
    
    .leaflet-popup-content {
        font-size: 14px;
        line-height: 1.4;
        margin: 16px;
    }
    
    /* Реєстр орендарів мобільна версія */
    .tenants-registry {
        font-size: 14px;
    }
    
    .tenant-item {
        padding: 12px;
        margin-bottom: 8px;
        border-radius: 8px;
        touch-action: manipulation;
        min-height: 44px;
        display: flex;
        align-items: center;
    }
    
    .tenant-color {
        width: 20px;
        height: 20px;
        margin-right: 12px;
        border-radius: 50%;
        flex-shrink: 0;
    }
    
    .tenant-name {
        flex: 1;
        font-weight: 500;
    }
    
    /* Анімації для мобільних */
    .btn, .dropdown-item, .tenant-item {
        transition: all 0.2s ease;
    }
    
    .btn:active, .dropdown-item:active, .tenant-item:active {
        transform: scale(0.98);
        transition: transform 0.1s ease;
    }
    
    /* Покращена типографіка для мобільних */
    h1, h2, h3, h4, h5, h6 {
        line-height: 1.3;
    }
    
    /* Безпечна зона для iPhone з вирізом */
    @supports (padding: max(0px)) {
        .navbar, .sidebar {
            padding-left: max(15px, env(safe-area-inset-left));
            padding-right: max(15px, env(safe-area-inset-right));
        }
        
        .navbar {
            padding-top: max(8px, env(safe-area-inset-top));
        }
    }
    
    /* Темна тема для мобільних */
    @media (prefers-color-scheme: dark) {
        .modal-content {
            background-color: #1a1a1a;
            color: #ffffff;
            border: 1px solid #333;
        }
        
        .dropdown-menu {
            background-color: #1a1a1a;
            border: 1px solid #333;
        }
        
        .tenant-item {
            background-color: rgba(255,255,255,0.05);
            border: 1px solid rgba(255,255,255,0.1);
        }
        
        .tenant-item:hover {
            background-color: rgba(255,255,255,0.1);
        }
    }
}

/* Додаткові мобільні оптимізації для дуже маленьких екранів */
@media (max-width: 480px) {
    .container-fluid {
        padding-left: 10px;
        padding-right: 10px;
    }
    
    .modal-dialog {
        margin: 5px;
    }
    
    .modal-body {
        padding: 15px;
    }
    
    .btn {
        font-size: 14px;
    }
    
    .sidebar {
        width: 100vw;
        max-width: 100vw;
    }
    
    /* GPS кнопка на малих екранах */
    .map-gps-btn,
    button.map-gps-btn,
    #map-gps-btn {
        top: 126px !important; /* 10px + 66px (zoom) + 10px + 30px (layers) + 10px */
        right: 16px !important; /* 10px + 6px зсув для центрування з контролами (42px GPS vs 30px контролів) */
        width: 42px !important;
        height: 42px !important;
        font-size: 19px !important;
    }
}

    /* Оптимізації для landscape орієнтації на мобільних */
    @media (max-width: 768px) and (orientation: landscape) {
        .modal-body {
            max-height: 50vh;
        }
        
        .mobile-bottom-nav {
            height: calc(var(--mobile-menu-height) + env(safe-area-inset-bottom, 20px)); /* Уніфіковано Safe Area - така сама висота як у portrait */
            min-height: calc(var(--mobile-menu-height) + env(safe-area-inset-bottom, 20px)); /* Уніфіковано Safe Area */
            max-height: calc(var(--mobile-menu-height) + env(safe-area-inset-bottom, 20px)); /* Уніфіковано Safe Area */
            padding: 8px 16px calc(8px + env(safe-area-inset-bottom, 20px)) 16px; /* Уніфіковано Safe Area */
        }
        
        .mobile-nav-item {
            padding: 10px 6px calc(6px + env(safe-area-inset-bottom, 20px) / 2) 6px; /* Уніфіковано Safe Area */
            font-size: 11px; /* Трохи більший шрифт для кращої читабельності */
            min-height: 44px; /* Оптимальна мінімальна висота в landscape */
        }
        
        .mobile-nav-item i {
            font-size: 19px; /* Трохи більші іконки */
            margin-bottom: 3px;
        }
        
        .map-wrapper {
            bottom: calc(var(--mobile-menu-height) + env(safe-area-inset-bottom, 20px)) !important; /* Уніфіковано Safe Area - відповідно до стандартної висоти */
        }
        
        /* FAB кнопка в landscape */
        .mobile-fab {
            bottom: calc(var(--mobile-menu-height) + 10px + env(safe-area-inset-bottom, 20px)); /* Уніфіковано Safe Area */
            width: 48px;
            height: 48px;
            font-size: 20px;
        }
        
        .map-gps-btn,
        button.map-gps-btn,
        #map-gps-btn {
            top: 116px !important; /* Відповідно до нової позиції layers */
            right: 15px !important; /* 10px + 5px зсув для центрування з контролами (40px GPS vs 30px контролів) */
            width: 40px !important;
            height: 40px !important;
            font-size: 18px !important;
        }
        
        .leaflet-control-layers {
            margin-top: 76px !important; /* Під zoom control в landscape */
        }
    }
    
    /* Спеціальні оптимізації для iPhone - тепер тільки для специфічних елементів */
    @supports (-webkit-appearance: none) and (stroke-color: transparent) {
        /* GPS кнопка враховуючи safe area */
        .map-gps-btn {
            top: calc(115px + env(safe-area-inset-top, 0px)) !important;
        }
    }
    
    /* Floating Action Button для додавання полів (тільки на мобільних) */
    .mobile-fab {
        position: fixed;
        bottom: calc(var(--mobile-menu-height) + 20px + env(safe-area-inset-bottom, 20px)); /* Уніфіковано Safe Area - трохи вище меню */
        right: 20px;
        width: 56px;
        height: 56px;
        border-radius: 50%;
        background: linear-gradient(135deg, #198754, #28a745);
        color: white;
        border: none;
        font-size: 24px;
        box-shadow: 0 4px 20px rgba(25, 135, 84, 0.3);
        z-index: 1500;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: all 0.3s ease;
        touch-action: manipulation;
    }
    
    .mobile-fab:hover, .mobile-fab:active {
        transform: scale(1.1);
        box-shadow: 0 6px 25px rgba(25, 135, 84, 0.4);
        background: linear-gradient(135deg, #157347, #1e7e34);
    }
    
    .mobile-fab:active {
        transform: scale(0.95);
    }/* PWA splash screen оптимізації */
@media (display-mode: standalone) {
    body {
        user-select: none;
        -webkit-user-select: none;
        -webkit-touch-callout: none;
    }
    
    /* Дозволяємо виділення тексту в інпутах */
    input, textarea, .selectable {
        user-select: text;
        -webkit-user-select: text;
    }
}

/* PWA install button styles consolidated above in this file */

/* Мобільні оптимізації для dashboard карток */
@media (max-width: 768px) {
    /* Оптимізація dashboard grid для мобільних */
    #user-dashboard-grid {
        margin-top: 1rem !important;
    }
    
    #user-dashboard-grid .row {
        margin: 0 !important;
    }
    
    /* На мобільних робимо всі колонки повністю широкими */
    #user-dashboard-grid .col-md-6 {
        flex: 0 0 100% !important;
        max-width: 100% !important;
        padding: 0.25rem !important;
    }
    
    #user-dashboard-grid .col-12 {
        padding: 0.25rem !important;
    }
    
    /* Оптимізація карток для мобільних */
    #user-dashboard-grid .card {
        margin-bottom: 0.75rem;
        border-radius: 12px !important;
        box-shadow: 0 2px 8px rgba(0,0,0,0.1) !important;
    }
    
    #user-dashboard-grid .card-header {
        padding: 0.75rem 1rem !important;
        background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%) !important;
    }
    
    #user-dashboard-grid .card-header h6 {
        font-size: 0.9rem !important;
        margin-bottom: 0 !important;
    }
    
    #user-dashboard-grid .card-body {
        padding: 1rem !important;
    }
    
    /* Оптимізація статистичних блоків */
    .dashboard-stat {
        padding: 0.75rem !important;
        margin-bottom: 0.5rem;
    }
    
    .dashboard-stat .h4 {
        font-size: 1.5rem !important;
        line-height: 1.2 !important;
    }
    
    .dashboard-stat small {
        font-size: 0.75rem !important;
        display: block;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    /* Оптимізація двоколонкових статистик */
    #user-dashboard-grid .row.g-2 {
        margin: 0 !important;
    }
    
    #user-dashboard-grid .row.g-2 .col-6 {
        padding: 0.25rem !important;
    }
    
    #user-dashboard-grid .text-center.p-2 {
        padding: 0.5rem !important;
        border-radius: 8px !important;
        min-height: 70px;
        display: flex;
        flex-direction: column;
        justify-content: center;
    }
    
    #user-dashboard-grid .text-center.p-2 .h4 {
        font-size: 1.25rem !important;
        margin-bottom: 0.25rem !important;
        line-height: 1.1;
    }
    
    #user-dashboard-grid .text-center.p-2 small {
        font-size: 0.7rem !important;
        line-height: 1.1 !important;
        display: block;
        margin-top: auto;
    }
    
    /* Оптимізація кнопок */
    #user-dashboard-grid .btn-sm {
        font-size: 0.8rem !important;
        padding: 0.5rem 0.75rem !important;
    }
    
    /* Оптимізація списку запитів для мобільних */
    #user-requests-list {
        max-height: 250px;
        overflow-y: auto;
    }
    
    .requests-divider {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 0.75rem;
    }
    
    .request-actions {
        justify-content: space-between !important;
        gap: 0.5rem !important;
    }
    
    .request-actions .btn {
        flex: 1;
        font-size: 0.8rem !important;
    }
    
    /* Забезпечення мінімальної висоти карток */
    #user-dashboard-grid .card {
        min-height: auto;
    }
    
    #user-dashboard-grid .card-body {
        display: flex;
        flex-direction: column;
    }
}

/* Дуже маленькі екрани (менше 400px) */
@media (max-width: 400px) {
    #user-dashboard-grid .card-header h6 {
        font-size: 0.85rem !important;
    }
    
    #user-dashboard-grid .card-body {
        padding: 0.75rem !important;
    }
    
    .dashboard-stat .h4 {
        font-size: 1.25rem !important;
    }
    
    #user-dashboard-grid .text-center.p-2 .h4 {
        font-size: 1.1rem !important;
    }
    
    #user-dashboard-grid .text-center.p-2 small {
        font-size: 0.65rem !important;
    }
    
    #user-dashboard-grid .btn-sm {
        font-size: 0.75rem !important;
        padding: 0.4rem 0.6rem !important;
    }
    
    /* Компактніші відступи для маленьких екранів */
    #user-dashboard-grid .col-md-6 {
        padding: 0.125rem !important;
    }
    
    #user-dashboard-grid .card {
        margin-bottom: 0.5rem;
    }
}

/* Додаткові стилі для запобігання переносу тексту */
@media (max-width: 768px) {
    /* Забезпечуємо, що текст не переноситься неочікувано */
    #user-dashboard-grid .card-header h6 {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    /* Для текстів статистики */
    #user-dashboard-grid .text-center.p-2 small {
        hyphens: auto;
        word-break: break-word;
        overflow-wrap: break-word;
    }
    
    /* Для кнопок - забезпечуємо, що вони не стають занадто вузькими */
    #user-dashboard-grid .btn {
        min-width: 120px;
        white-space: nowrap;
    }
    
    /* Для заголовків карток - роби їх адаптивними */
    #user-dashboard-grid .card-header {
        overflow: hidden;
    }
    
    /* Забезпечуємо правильний overflow для чисел */
    #user-dashboard-grid .h4 {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    
    /* Оптимізація відступів у grid */
    #user-dashboard-grid .row.g-3 {
        --bs-gutter-x: 0.5rem !important;
        --bs-gutter-y: 0.5rem !important;
    }
    
    /* Забезпечуємо достатній padding для контейнера */
    .container {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }
}

/* Стилі для мобільного списку полів користувача */
.mobile-fields-list {
    max-height: calc(100vh - 300px);
    overflow-y: auto;
}

.mobile-field-item {
    background: white;
    border: 1px solid #e9ecef;
    border-radius: 12px;
    margin-bottom: 12px;
    padding: 0;
    box-shadow: 0 2px 6px rgba(0,0,0,0.08);
    transition: all 0.2s ease;
    overflow: hidden;
}

/* Дозволяємо overflow коли dropdown відкритий */
.mobile-field-item.dropdown-open {
    overflow: visible !important;
    z-index: 99998 !important;
}

.mobile-field-item:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    transform: translateY(-2px);
}

.mobile-field-layout {
    display: flex;
    height: 100px; /* Фіксована висота для всіх карток */
}

.mobile-field-visual {
    flex: 0 0 35%;
    background: #f8f9fa;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
}

.mobile-field-thumbnail-large {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mobile-field-thumbnail-large .field-thumbnail {
    width: 100%;
    height: 100%;
    border-radius: 6px;
}

.mobile-field-details {
    flex: 1;
    padding: 12px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.mobile-field-title-large {
    flex: 1;
    display: flex;
    align-items: flex-start; /* Вирівнювання по верху */
    margin-bottom: 8px;
    min-height: 0; /* Дозволяє зменшуватись */
}

.mobile-field-title-large h6 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    color: #333;
    line-height: 1.3;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2; /* Максимум 2 рядки */
    line-clamp: 2; /* Стандартна властивість */
    -webkit-box-orient: vertical;
    word-wrap: break-word;
    hyphens: auto;
}

.mobile-field-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.mobile-field-area {
    flex: 1;
}

.mobile-field-area small {
    font-size: 12px;
    color: #6c757d;
}

.mobile-field-header-line {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
    gap: 8px;
}

.mobile-field-header-line h6 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: #333;
    line-height: 1.3;
    flex: 1;
    min-width: 0; /* Дозволяє обрізання тексту */
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mobile-field-header-line small {
    font-size: 12px;
    color: #6c757d;
    flex-shrink: 0;
}

.mobile-field-title {
    margin-bottom: 4px;
}

.mobile-field-actions {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
}

.mobile-field-actions .btn {
    padding: 4px 6px;
    font-size: 12px;
    border-radius: 4px;
    min-width: 28px;
    height: 28px;
}

/* Стилі для dropdown експорту в мобільному */
.mobile-field-actions .btn-group .dropdown-toggle {
    padding: 4px 8px;
    font-size: 12px;
}

.mobile-field-actions .dropdown-menu {
    font-size: 12px;
    min-width: 120px;
}

.mobile-field-actions .dropdown-item {
    padding: 4px 8px;
}

.mobile-field-actions .dropdown-item i {
    font-size: 11px;
    margin-right: 4px;
}

.field-thumbnail {
    width: 100%;
    height: 100%;
    border-radius: 6px;
}

.field-thumbnail-placeholder {
    width: 100%;
    height: 100%;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #6c757d;
    font-size: 1rem;
}

.mobile-field-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
    margin-left: 8px;
    align-items: center;
}

.mobile-field-actions .btn {
    width: 30px;
    height: 30px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    border-width: 1px;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.mobile-field-actions .btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* Стилі для dropdown експорту в мобільному - оновлені */
.mobile-field-actions .btn-group {
    flex-shrink: 0;
}

.mobile-field-actions .btn-group .dropdown-toggle {
    width: 30px;
    height: 30px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    border-radius: 6px;
}

.mobile-field-actions .dropdown-menu {
    font-size: 11px;
    min-width: 110px;
}

.mobile-field-info {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-top: 4px;
    border-top: 1px solid #f1f3f4;
}

.mobile-field-info small {
    display: flex;
    align-items: center;
    font-size: 0.75rem;
    color: #6c757d;
}

/* Додаткові стилі для дуже маленьких екранів */
@media (max-width: 360px) {
    .mobile-field-item {
        padding: 10px;
        margin-bottom: 6px;
    }
    
    .mobile-field-header h6 {
        font-size: 0.85rem;
    }
    
    .mobile-field-actions .btn {
        width: 28px;
        height: 28px;
        font-size: 0.75rem;
    }
    
    .mobile-field-info small {
        font-size: 0.7rem;
    }
}

/* Стилі для горизонтальних телефонів */
@media (max-height: 500px) and (orientation: landscape) {
    .mobile-field-item {
        padding: 8px;
        margin-bottom: 4px;
    }
    
    .mobile-field-header h6 {
        font-size: 0.8rem;
        line-height: 1.2;
    }
    
    .mobile-field-actions .btn {
        width: 26px;
        height: 26px;
    }
}

/* Уведомлення про оновлення */
.pwa-update-notification {
    backdrop-filter: blur(10px);
    background: rgba(13, 110, 253, 0.9);
    border: none;
    border-radius: 12px;
    color: white;
}

/* Мобільна панель територій */
.mobile-territories-wrapper {
    max-height: 50vh;
    overflow-y: auto;
}

.mobile-territory-card {
    background: white !important;
    border: 1px solid #e9ecef !important;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 8px;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1) !important;
    transform: none !important;
    outline: none !important;
}

.mobile-territory-card:focus,
.mobile-territory-card:hover,
.mobile-territory-card:active,
.mobile-territory-card:visited {
    background: white !important;
    border: 1px solid #e9ecef !important;
    transform: none !important;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1) !important;
    outline: none !important;
}

.mobile-territory-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.mobile-territory-icon {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, #198754, #20c997);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 14px;
}

.mobile-territory-name {
    font-weight: 600;
    color: #333;
    font-size: 14px;
    margin: 0;
    line-height: 1.3;
}

.mobile-territory-code {
    color: #666;
    font-size: 12px;
    margin: 0;
}

.mobile-territory-select {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid #198754 !important;
    background: white !important;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #198754 !important;
    font-size: 10px;
}

.mobile-territory-select:hover,
.mobile-territory-select:active,
.mobile-territory-select:focus {
    border: 2px solid #198754 !important;
    background: white !important;
    color: #198754 !important;
}

/* Переконуємося що останній елемент не має особливого стилю */
.mobile-territory-card:last-child {
    background: white !important;
    border: 1px solid #e9ecef !important;
    transform: none !important;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1) !important;
}

.mobile-territory-card:last-child .mobile-territory-select {
    border: 2px solid #198754 !important;
    background: white !important;
    color: #198754 !important;
}

/* GPS кнопка на карті */
.map-gps-btn,
button.map-gps-btn,
#map-gps-btn {
    position: absolute;
    top: 126px; /* 10px + 66px (zoom) + 10px + 30px (layers) + 10px відступ */
    right: 17px !important; /* 10px + 7px зсув для центрування з контролами 30px ширини */
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: white;
    color: #6c757d;
    border: 2px solid #e9ecef;
    font-size: 20px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15), 0 2px 6px rgba(0, 0, 0, 0.1); /* Покращена тінь */
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    touch-action: manipulation;
    cursor: pointer;
}

.map-gps-btn:hover {
    background: #f8f9fa;
    border-color: #198754;
    color: #198754;
    transform: scale(1.05);
}

.map-gps-btn.active {
    background: #ffc107 !important;
    border-color: #ffca2c !important;
    color: #212529 !important;
    box-shadow: 0 6px 20px rgba(255, 193, 7, 0.4);
}

.map-gps-btn.active i {
    animation: pulse-gps-map 2s infinite;
}

@keyframes pulse-gps-map {
    0% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.7; transform: scale(1.1); }
    100% { opacity: 1; transform: scale(1); }
}

/* Мобільні toast оптимізації */
@media (max-width: 768px) {
    .toast-container {
        z-index: 2100 !important; /* Вище за мобільні панелі */
    }
    
    /* Коли відкрита мобільна панель, зсуваємо toast вище */
    .mobile-fields-panel.show ~ .toast-container,
    .mobile-panel-overlay.show ~ .toast-container {
        top: 10px !important;
        transform: translateX(-50%) !important;
    }
}

/* Стилі для GPS toast повідомлень */
.gps-location-toast {
    min-width: 300px;
    max-width: 400px;
    border: none !important;
    border-radius: 12px !important;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15) !important;
    backdrop-filter: blur(10px);
}

.gps-location-toast .toast-body {
    border-radius: 12px !important;
    padding: 16px !important;
    font-size: 14px !important;
    line-height: 1.4 !important;
}

.gps-location-toast .badge {
    font-size: 11px !important;
    padding: 4px 8px !important;
    border-radius: 6px !important;
}

/* Анімація для GPS toast */
.gps-location-toast {
    animation: slideInFromTop 0.4s ease-out;
}

@keyframes slideInFromTop {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0) scale(1);
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
        transform: translateX(-50%) scale(1);
    }
    to {
        opacity: 0;
        transform: translateX(-50%) scale(0.95);
    }
}

/* Стилі для мобільних GPS toast */
.mobile-gps-toast {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    border: none !important;
}

.mobile-gps-toast .btn-close {
    font-size: 12px;
    opacity: 0.7;
}

/* Покращені стилі для кола точності GPS */
.location-circle-accuracy {
    transition: all 0.3s ease !important;
}

/* Стилі для SVG кола точності */
.leaflet-overlay-pane .location-circle-accuracy {
    transition: all 0.3s ease !important;
}

/* Анімація пульсації для GPS маркера при активному відстеженні */
@keyframes gps-pulse {
    0% { 
        transform: scale(1);
        opacity: 1;
    }
    50% { 
        transform: scale(1.1);
        opacity: 0.8;
    }
    100% { 
        transform: scale(1);
        opacity: 1;
    }
}

.leaflet-marker-pane .leaflet-interactive[stroke="#ffffff"] {
    animation: gps-pulse 2s ease-in-out infinite;
}

/* Покращення GPS контролу */
.leaflet-control-locate {
    transition: all 0.2s ease !important;
}

.leaflet-control-locate.requesting {
    animation: spin 1s linear infinite !important;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Мобільні стилі для GPS індикаторів */
.map-gps-btn.loading i {
    animation: spin 1s linear infinite;
}

.map-gps-btn.active {
    background: #ffc107 !important;
    border-color: #ffca2c !important;
    color: #212529 !important;
    box-shadow: 0 6px 20px rgba(255, 193, 7, 0.4);
}

.map-gps-btn.active i {
    animation: pulse-gps-map 2s infinite;
}

/* Стилі для dropdown дій в мобільних картах полів */
.mobile-field-item .btn-group {
    display: inline-block;
    position: relative;
}

.mobile-field-item .dropdown-toggle {
    padding: 4px 8px;
    font-size: 12px;
    height: 28px;
    display: flex;
    align-items: center;
}

/* Критичні стилі для правильного відображення dropdown */
.mobile-field-item .btn-group {
    position: relative;
}

/* Контейнер полів має дозволяти overflow для dropdown меню */
#mobile-user-fields-content {
    overflow: visible !important;
    padding-bottom: 180px; /* Додатковий відступ для dropdown меню */
}

/* Контейнер списку полів також має overflow: visible */
.mobile-fields-list {
    overflow: visible !important;
    padding-bottom: 20px;
}

.mobile-field-item .dropdown-menu {
    position: absolute !important;
    top: 100% !important;
    bottom: auto !important;
    left: auto !important;
    right: 0 !important;
    font-size: 12px;
    min-width: 140px;
    max-width: 200px;
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.3);
    z-index: 99999 !important;
    margin-top: 4px;
    transform: none !important;
    will-change: transform;
    background: white;
    border: 1px solid #dee2e6;
    max-height: 200px;
    overflow-y: auto;
    overflow-x: hidden;
}

/* Стилі для меню що відкривається вгору */
.mobile-field-item .dropdown-menu.dropdown-up {
    animation: slideUpIn 0.15s ease-out;
}

/* Стилі для меню що відкривається вниз */
.mobile-field-item .dropdown-menu.dropdown-down {
    animation: slideDownIn 0.15s ease-out;
}

@keyframes slideUpIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideDownIn {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Стилі для прокрутки в малих меню */
.mobile-field-item .dropdown-menu::-webkit-scrollbar {
    width: 4px;
}

.mobile-field-item .dropdown-menu::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 2px;
}

.mobile-field-item .dropdown-menu::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 2px;
}

.mobile-field-item .dropdown-menu::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Адаптивне позиціонування для мобільних */
@media (max-width: 768px) {
    .mobile-field-item .dropdown-menu {
        right: 0 !important;
        left: auto !important;
        transform: translateX(0) !important;
    }
    
    /* Якщо кнопка близько до лівого краю */
    .mobile-field-item .btn-group:first-child .dropdown-menu {
        left: 0 !important;
        right: auto !important;
    }
}

/* Забезпечуємо, що карти полів не перекривають dropdown */
.mobile-field-item {
    position: relative;
    z-index: 1;
}

.mobile-field-item:has(.dropdown-menu.show) {
    z-index: 99998 !important;
    position: relative;
}

.mobile-field-item .dropdown-item {
    padding: 6px 12px;
    display: flex;
    align-items: center;
}

.mobile-field-item .dropdown-item i {
    font-size: 12px;
    margin-right: 6px;
    width: 14px;
}

.mobile-field-item .dropdown-item.text-danger {
    color: #dc3545 !important;
}

.mobile-field-item .dropdown-item.text-danger:hover {
    background-color: #f8d7da;
    color: #721c24 !important;
}

.mobile-field-item .dropdown-header {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #6c757d;
}

/* =============== Mobile Spatial Filter Optimizations =============== */

/* Mobile spatial filter button */
@media (max-width: 768px) {
    #spatial-filter-btn {
        min-height: 44px; /* Touch-friendly size */
        min-width: 44px;
        font-size: 16px;
    }
    
    #spatial-filter-btn.active {
        background-color: #ffc107 !important;
        border-color: #ffc107 !important;
        color: #000 !important;
    }
}

/* Mobile spatial filter indicator adjustments */
@media (max-width: 768px) {
    .spatial-filter-active-indicator {
        position: fixed !important;
        top: 20px !important; /* Вище кнопок управління шарами */
        left: 10px !important;
        right: 10px !important;
        transform: none !important;
        font-size: 14px !important;
        padding: 8px 12px !important;
        z-index: 1060 !important; /* Вищий z-index щоб бути поверх усіх кнопок */
        background: rgba(13, 110, 253, 0.95) !important;
        color: white !important;
        border-radius: 8px !important;
        box-shadow: 0 4px 12px rgba(0,0,0,0.3) !important;
        backdrop-filter: blur(10px) !important;
        border: none !important;
        margin-top: 5px !important; /* Невеликий відступ зверху */
    }
    
    /* Стилі для мобільного індикатора в панелі (якщо панель відкрита) */
    .mobile-fields-panel .spatial-filter-active-indicator {
        position: relative !important;
        top: auto !important;
        left: auto !important;
        right: auto !important;
        margin: 10px 0 !important;
        border-radius: 6px !important;
        background: #d1ecf1 !important;
        color: #0c5460 !important;
        border-left: 4px solid #0d6efd !important;
    }
}

/* Mobile popup optimizations for spatial filter */
@media (max-width: 768px) {
    .leaflet-popup-content-wrapper {
        max-width: 280px !important;
    }
    
    .parcel-popup {
        font-size: 14px;
    }
    
    .parcel-popup h6 {
        font-size: 16px;
        margin-bottom: 8px;
    }
    
    .stat-row {
        flex-direction: column !important;
        align-items: flex-start !important;
        margin-bottom: 10px !important;
        padding: 6px 0 !important;
        border-bottom: 1px solid #f0f0f0;
    }
    
    .stat-row:last-child {
        border-bottom: none !important;
    }
    
    .stat-label {
        font-size: 13px !important;
        margin-bottom: 4px;
    }
    
    .stat-value {
        font-size: 14px !important;
        font-weight: 700 !important;
        margin-left: 0 !important;
        color: #007bff !important;
    }
}

/* Touch improvements for mobile spatial filter operations */
@media (max-width: 768px) and (pointer: coarse) {
    .field-filter-item {
        min-height: 60px;
        padding: 12px;
        margin-bottom: 8px;
    }
    
    .field-filter-item:active {
        background-color: #f8f9fa;
        transform: scale(0.98);
    }
    
    #clear-spatial-filter-btn {
        min-height: 48px;
        font-size: 16px;
        padding: 12px 20px;
    }
}

/* PWA mode specific adjustments for spatial filter */
@media (display-mode: standalone) and (max-width: 768px) {
    .spatial-filter-active-indicator {
        top: 70px !important; /* Additional space for PWA status bar */
    }
}

/* Landscape orientation adjustments */
@media (max-width: 768px) and (orientation: landscape) {
    .spatial-filter-active-indicator {
        top: 45px !important;
        font-size: 12px !important;
        padding: 6px 10px !important;
    }
}

/* =============== End Mobile Spatial Filter Optimizations =============== */

/* =============== Mobile Registry Touch Optimizations (minimal) =============== */

/* Тільки покращення для тач-взаємодії без зміни вигляду */
@media (max-width: 768px) {
    /* Покращене виділення ділянок на мобільних пристроях */
    .leaflet-overlay-pane .mobile-highlighted {
        filter: drop-shadow(0 0 8px rgba(255, 0, 0, 0.7)) !important;
        z-index: 1000 !important;
    }
    
    /* Мінімальні тач-оптимізації без зміни вигляду */
    .parcel-row {
        -webkit-tap-highlight-color: rgba(0, 123, 255, 0.1);
        user-select: none;
    }
}

/* =============== End Mobile Registry Touch Optimizations =============== */

/* =============== Spatial Filter Registry Styles =============== */

/* CSS правила для просторової фільтрації реєстру */
.spatial-filter-hidden-row {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

.spatial-filter-visible-row {
    display: table-row !important;
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
}

.spatial-filter-header-row {
    display: table-row !important;
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    font-weight: bold;
}

/* Альтернативні селектори для надійності */
tr.spatial-filter-hidden-row,
tbody tr.spatial-filter-hidden-row {
    display: none !important;
}

tr.spatial-filter-visible-row,
tbody tr.spatial-filter-visible-row {
    display: table-row !important;
}

/* Додаткові правила для мобільного реєстру */
#mobile-registry-display .spatial-filter-hidden-row,
#mobile-registry-display tbody .spatial-filter-hidden-row {
    display: none !important;
}

#mobile-registry-display .spatial-filter-visible-row,
#mobile-registry-display tbody .spatial-filter-visible-row {
    display: table-row !important;
}

/* =============== End Spatial Filter Registry Styles =============== */

/* =============== Загальні мобільні оптимізації для index.html =============== */
@media (max-width: 767.98px) {
    /* Оптимізація відступів для головної сторінки */
    .hero-section {
        padding-top: 1rem !important;
        padding-bottom: 1rem !important;
    }
    
    .dashboard-section {
        padding-top: 1rem !important;
        padding-bottom: 1rem !important;
    }
    
    /* Оптимізація карток підприємств */
    .companies-cards-section {
        padding-top: 1rem !important;
        padding-bottom: 1rem !important;
    }
    
    .companies-cards-section .container {
        padding-left: 15px !important;
        padding-right: 15px !important;
    }
    
    /* Зменшуємо відступи між елементами */
    .row.g-3 {
        --bs-gutter-x: 0.5rem;
        --bs-gutter-y: 0.5rem;
    }
    
    /* Оптимізація заголовків */
    h1 {
        font-size: 1.5rem !important;
    }
    
    h2 {
        font-size: 1.3rem !important;
        margin-bottom: 1rem !important;
    }
    
    h3 {
        font-size: 1.1rem !important;
    }
    
    /* Загальна оптимізація контейнерів */
    .container {
        max-width: 100% !important;
    }
    
    /* Зменшуємо card padding на мобільних */
    .card-body {
        padding: 0.75rem !important;
    }
    
    .card-header {
        padding: 0.5rem 0.75rem !important;
    }
}
