#mainForm {
    --primary-red: #F01A26;
    --dark-text: #222222;
    --gray-text: #666666;
    --placeholder-gray: #999999;
    --white: #FFFFFF;
    --radius: 6px;
    --input-height: 44px;
    font-family: 'Nunito Sans', sans-serif;
    -webkit-tap-highlight-color: transparent !important;
}

/* ========================================= */
/* 0. ГЛОБАЛЬНЫЙ СБРОС                       */
/* ========================================= */
#mainForm *, #mainForm *:focus, #mainForm *:active {
    outline: none !important;
    -webkit-tap-highlight-color: transparent !important;
}

/* ========================================= */
/* 1. БАЗОВЫЕ НАСТРОЙКИ                      */
/* ========================================= */
#mainForm .option-flag { width: 28px; height: 20px; margin-right: 15px; border-radius: 3px; object-fit: cover; }
#mainForm .option-icon { width: 32px; height: 32px; margin-right: 12px; object-fit: contain; }

.new-form-wrapper {
    background-color: rgba(255, 255, 255, 0.7);
    width: 100%; max-width: 800px;
    padding: 10px 20px; border-radius: 12px;
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.3);
    margin: 0 auto; position: relative; z-index: 5; 
}

/* ========================================= */
/* 2. Z-INDEX И СЛОИ                         */
/* ========================================= */
#mainForm fieldset, #mainForm .parcel-type-section { 
    border: none; padding: 0; margin: 0 0 5px 0; width: 100%; position: relative; z-index: 1; 
}
/* Поднимаем блок, если в нем открыт список */
#mainForm fieldset:has(.open), 
#mainForm .parcel-type-section:has(.open),
#mainForm .merged-input-group:has(.open) { 
    z-index: 10005 !important; 
    position: relative !important;
}

/* ========================================= */
/* 3. ПОЛЯ ВВОДА                             */
/* ========================================= */
#mainForm .section-labels { display: flex; justify-content: space-between; margin-bottom: 6px; }
#mainForm .label-text { font-size: 14px; font-weight: 800; color: var(--dark-text); display: block; margin-bottom: 0; }
#mainForm .row-container { display: flex; gap: 12px; align-items: stretch; position: relative; }

#mainForm .merged-input-group {
    flex: 1; display: flex; align-items: center;
    background: var(--white);
    border: 1px solid var(--primary-red);
    border-radius: var(--radius);
    position: relative; height: var(--input-height);
    transition: box-shadow 0.2s ease;
    min-width: 0; z-index: 10; 
}

#mainForm .vertical-divider { width: 1px; height: 60%; background-color: #ccc; flex-shrink: 0; }
#mainForm .address-segment { flex: 1; height: 100%; min-width: 0; }
#mainForm .address-segment input {
    width: 100%; height: 100%; border: none !important; background: transparent; 
    padding: 0 12px; font-size: 15px; color: var(--dark-text);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; 
}

#mainForm .postal-container { width: 90px; flex-shrink: 0; position: relative; z-index: 9; }
#mainForm .standard-input {
    width: 100%; height: var(--input-height);
    border: 1px solid var(--primary-red); border-radius: var(--radius);
    padding: 0 12px; font-size: 15px; color: var(--dark-text);
    background: var(--white); 
}
#mainForm .label-postal { width: 90px; flex-shrink: 0; position: relative; right: 10px; text-align: right; }


/* ============================================================ */
/* 4. ФЛАГ, ГЛОБУС И СТРЕЛКА (ФИНАЛЬНАЯ ВЕРСИЯ)                 */
/* ============================================================ */

/* КОНТЕЙНЕР */
#mainForm .country-wrapper {
    width: 75px !important; 
    min-width: 75px; 
    /* Убрали z-index: 15, чтобы фон не перекрывал рамку */
    margin: 0; 
    padding: 0;
    position: relative; /* Оставляем для позиционирования списка */
}

/* ТРИГГЕР (КНОПКА) */
#mainForm .flag-trigger {
    cursor: pointer; 
    display: flex; 
    align-items: center;
    width: 100%; /* На всю ширину контейнера */
    height: 100%;
    background: transparent;
    transition: background 0.2s;
    
    /* ВАЖНО: Радиус такой же, как у всей формы (6px), чтобы углы не торчали */
    border-radius: var(--radius) 0 0 var(--radius) !important; 
    
    position: relative;
    /* Небольшой отступ слева, чтобы фон не наезжал на левую границу рамки */
    margin-left: 1px; 
    width: calc(100% - 1px);
}

#mainForm .flag-trigger:not(:has(.default-globe)) { 
    padding: 10px !important; 
}

#mainForm .flag-trigger:hover { 
    background-color: #f9f9f9; 
}

/* --- ЭЛЕМЕНТЫ ВНУТРИ --- */

/* 1. ОБЫЧНЫЙ ФЛАГ */
#mainForm .current-flag {
    width: 24px;
    height: 17px;
    border-radius: 2px;
    object-fit: cover;
    margin-right: 6px; 
    box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}

/* 2. ТЕКСТ КОДА */
#mainForm .current-code {
    font-weight: 800;
    font-size: 15px;
    color: var(--dark-text);
    padding-top: 1px;
}

/* 3. ГЛОБУС */
#mainForm .current-flag.default-globe {
    width: 30px !important;
    height: 30px !important;
    object-fit: contain !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    margin: 10px !important; 
}

/* --- СТРЕЛКА --- */
#mainForm .flag-trigger::after {
    content: '';
    position: absolute;
    right: 10px !important;
    top: 50%;
    transform: translateY(-50%);
    width: 12px;
    height: 8px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='9' viewBox='0 0 14 9' fill='none'%3E%3Cpath d='M1 1L7 7L13 1' stroke='%23666666' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
    transition: transform 0.3s ease;
    pointer-events: none;
    opacity: 0.8;
}

#mainForm .flag-trigger:not(:has(.default-globe))::after {
    display: none !important;
}

#mainForm .custom-select-wrapper.open .flag-trigger:has(.default-globe)::after {
    transform: translateY(-50%) rotate(180deg);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='9' viewBox='0 0 14 9' fill='none'%3E%3Cpath d='M1 1L7 7L13 1' stroke='%23F01A26' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    opacity: 1;
}

/* ========================================= */
/* 5. ВЫПАДАЮЩИЕ СПИСКИ (ФИКС СКРОЛЛА)       */
/* ========================================= */
#mainForm .custom-select-wrapper { position: relative; height: 100%; }

/* ========================================= */
/* ИСПРАВЛЕННЫЙ БЛОК ДЛЯ СПИСКА (ФИКС СКРОЛЛА) */
/* ========================================= */
#mainForm .custom-options {
    position: absolute; 
    top: 115%; 
    left: 0;
    background: #fff; 
    border: 1px solid #e0e0e0;
    border-radius: 8px; 
    box-shadow: 0 15px 40px rgba(0,0,0,0.25);
    width: 100%; 
    min-width: 280px;
    
    /* Скрыто по умолчанию */
    opacity: 0; 
    visibility: hidden; 
    transform: translateY(-10px); 
    transition: opacity 0.3s, transform 0.3s, visibility 0s linear 0.3s;
    
    z-index: 2000 !important; 
    
    /* === ГЛАВНЫЕ ИСПРАВЛЕНИЯ === */
    pointer-events: auto !important; 
    cursor: pointer !important;
    
    /* Ограничиваем высоту */
    max-height: 300px !important; 
    
    /* Включаем прокрутку ТОЛЬКО по вертикали */
    overflow-y: auto !important; 
    overflow-x: hidden !important; 
    
    /* Запрещаем прокрутку родителя (страницы), пока мышь над списком */
    overscroll-behavior: contain !important; 
    -webkit-overflow-scrolling: touch !important; /* Плавность на iPhone */
}

/* Когда открыто */
#mainForm .custom-select-wrapper.open .custom-options { 
    opacity: 1; 
    visibility: visible; 
    transform: translateY(0); 
    transition: opacity 0.3s, transform 0.3s, visibility 0s linear 0s;
}

/* === ВАЖНО: Фикс для мобильных (чтобы список не улетал) === */
@media (max-width: 480px) {
    #wrapper-from .custom-options, #wrapper-to .custom-options {
        position: fixed !important; 
        top: 50% !important; 
        left: 5vw !important; 
        right: 5vw !important;
        width: 100vw !important; /* Ширина 90% экрана */
        max-width: none !important;
        transform: translateY(-50%) !important;
        
        /* Ограничиваем высоту на мобилке */
        max-height: 38vh !important; 
        
        /* Включаем скролл */
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        overscroll-behavior: contain !important;
        
        z-index: 2147483647 !important; 
        box-shadow: 0 0 0 1000px rgba(0,0,0,0.6) !important;
        border-radius: 12px !important;
    }
}

/* Стиль скроллбара (ТЕМНЫЙ) */
#mainForm .custom-options::-webkit-scrollbar { width: 8px; }
#mainForm .custom-options::-webkit-scrollbar-track { background: #f1f1f1; border-radius: 0 0 8px 0; }
#mainForm .custom-options::-webkit-scrollbar-thumb { 
    background: #666; /* Темный цвет */
    border-radius: 4px; 
}
#mainForm .custom-options::-webkit-scrollbar-thumb:hover { background: #444; }

#mainForm .custom-option {
    padding: 12px 15px; display: flex; align-items: center; cursor: pointer;
    border-bottom: 1px solid #f5f5f5; font-size: 16px; font-weight: 600; color: #333;
    transition: background 0.2s; gap: 10px;
}
#mainForm .custom-option:hover { background: #fff0f0; }

/* Parcel Type Trigger */
#mainForm .type-trigger {
    width: 100%; border: 1px solid var(--primary-red); border-radius: var(--radius); 
    padding: 0 12px; height: 44px; display: flex; align-items: center; cursor: pointer; background: #fff;
    justify-content: center; position: relative; z-index: 10;
}
#mainForm .current-type-content { display: flex; align-items: center; font-size: 15px; font-weight: 800; color: var(--dark-text); }
#mainForm .current-type-content.placeholder-style { color: var(--placeholder-gray); font-weight: 400; }
#mainForm .custom-arrow {
    position: absolute; right: 15px; width: 8px; height: 8px; 
    border-right: 2px solid var(--primary-red); border-bottom: 2px solid var(--primary-red);
    transform: rotate(45deg); transition: transform 0.2s;
}
#mainForm .custom-select-wrapper.open .custom-arrow { transform: rotate(225deg); top: 20px; }

/* ========================================= */
/* 6. ПОИСК                                  */
/* ========================================= */
.custom-search-box { position: sticky; top: 0; background: #fff; padding: 12px 15px; z-index: 105; border-bottom: 1px solid #f0f0f0; }
.country-search-input {
    width: 100%; height: 40px; padding: 0 15px 0 42px;
    border: 1px solid #e0e0e0; border-radius: 8px; font-size: 15px;
    background-color: #f8f8f8; outline: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%23F01A26' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'%3E%3C/circle%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'%3E%3C/line%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: 12px center; background-size: 18px;
}
.no-results-message { padding: 20px; text-align: center; color: #999; font-size: 14px; display: none; }

/* ========================================= */
/* 7. КАРТОЧКА ПОСЫЛКИ                       */
/* ========================================= */
#mainForm .parcel-card {
    background: #ffffff00; border-radius: var(--radius); padding: 7px; margin-bottom: 15px; 
    overflow: hidden; opacity: 0; max-height: 0; transform: scale(0.95); transition: all 0.4s; z-index: 2;
}
#mainForm .parcel-card.active { opacity: 1; max-height: 300px; transform: scale(1); border-width: 1px; }
#mainForm .parcel-card.removing { opacity: 0; max-height: 0; margin: 0; padding: 0; transform: scale(0.9); }

#mainForm .grid-4 { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 12px; }
#mainForm .dim-input-wrapper {
    position: relative; height: 44px; border: 1px solid var(--primary-red); border-radius: var(--radius); 
    background: var(--white); display: flex; align-items: center; z-index: 10;
}
#mainForm .dim-label { position: absolute; left: 10px; font-size: 13px; font-weight: 600; color: #555; }
#mainForm .dim-unit { position: absolute; right: 10px; font-size: 13px; color: #999; }
#mainForm .dim-input-wrapper input {
    width: 100%; height: 100%; border: none; background: transparent;
    text-align: right; padding-left: 50px; padding-right: 30px; font-size: 15px;
}

#mainForm .buttons-area { margin-top: 0px; display: flex; flex-direction: column; gap: 7px; }
#mainForm .card-header { display: flex; justify-content: space-between; margin-bottom: 10px; }
#mainForm .item-index { font-weight: 800; font-size: 14px; color: var(--dark-text); }
#mainForm .btn-remove { background: none; border: none; font-size: 24px; color: var(--gray-text); cursor: pointer; line-height: 0.7; }
#mainForm .btn-remove:hover { color: var(--primary-red); }
#mainForm .btn-secondary {
    height: 44px; width: 100%; padding: 12px; background: var(--white); border: 1px solid var(--primary-red);
    color: var(--primary-red); font-weight: 600; font-size: 16px; border-radius: var(--radius); cursor: pointer;
}
#mainForm .btn-primary {
    width: 100%; padding: 14px; background: var(--primary-red); border: none; color: var(--white);
    font-weight: 600; font-size: 18px; border-radius: var(--radius); cursor: pointer;
    display: flex; justify-content: center; align-items: center; gap: 5px;
    box-shadow: 0 4px 15px rgba(240, 26, 38, 0.4);
}

/* ========================================= */
/* 8. ПУЛЬСАЦИЯ */
/* ========================================= */
@keyframes pulse-intense {
    0% { 
        /* Начало: тень ярче (0.7), но вплотную к рамке */
        box-shadow: 0 0 0 0 rgba(0, 86, 167, 0.7); 
    }
    70% { 
        /* Середина: расходится до 10px (как было), но исчезает */
        box-shadow: 0 0 0 10px rgba(0, 86, 167, 0); 
    }
    100% { 
        box-shadow: 0 0 0 0 rgba(0, 86, 167, 0); 
    }
}

.pulsating-border {
    border: 1px solid #F01A26 !important;
    /* Время уменьшил до 1.5s (было 2s) -> стало быстрее */
    animation: pulse-intense 1.5s infinite ease-out !important;
    z-index: 20 !important; 
    position: relative;
}

/* Для кнопки */
@keyframes pulse-btn-intense {
    0% { 
        transform: scale(1); 
        box-shadow: 0 0 0 0 rgba(240, 26, 38, 0.7); 
    }
    50% { 
        transform: scale(1.02); 
        /* Размер тот же (12px), но старт был ярче */
        box-shadow: 0 0 0 12px rgba(240, 26, 38, 0); 
    }
    100% { 
        transform: scale(1); 
        box-shadow: 0 0 0 0 rgba(240, 26, 38, 0); 
    }
}

.btn-primary.pulsating-border {
    animation: pulse-btn-intense 1.5s infinite ease-out !important;
    border: none !important;
}
}

/* ========================================= */
/* 9. ФОКУС (ДВОЙНАЯ РАМКА С ОТСТУПОМ)       */
/* ========================================= */
#mainForm .merged-input-group:focus-within,
#mainForm .standard-input:focus,
#mainForm .custom-select-wrapper.open .type-trigger,
#mainForm .postal-container {
    border: 1px solid var(--primary-red) !important;
    /* Возвращаем эффект отступа */
    outline: 2px solid var(--primary-red) !important;
    outline-offset: 2px !important;
    z-index: 25; 
}

/* Если нет пульсации, убираем тень, чтобы она не мешала аутлайну */
#mainForm .merged-input-group:focus-within:not(.pulsating-border),
#mainForm .standard-input:focus:not(.pulsating-border),
#mainForm .custom-select-wrapper.open .type-trigger:not(.pulsating-border) {
    box-shadow: none !important;
}

/* ========================================= */
/* 10. GOOGLE MAPS FIX                       */
/* ========================================= */
.pac-container {
    z-index: 2147483647 !important; position: absolute !important;
    background-color: #FFFFFF !important; border: none !important; 
    border-radius: 0 0 12px 12px !important; box-shadow: 0 15px 40px rgba(0,0,0,0.25) !important;
    font-family: 'Nunito Sans', sans-serif !important; 
    margin-top: 5px !important; pointer-events: auto !important; cursor: pointer !important;
    box-sizing: border-box !important; overflow: hidden !important;
}
.pac-item {
    display: flex !important; align-items: center !important; padding: 12px 18px !important;
    background-color: #FFFFFF !important; border-top: 1px solid #f2f2f2 !important;
    cursor: pointer !important; min-height: 44px !important; max-width: 100% !important;
}
.pac-item:first-child { border-top: none !important; }
.pac-item span, .pac-item-query { 
    color: #222222 !important; font-size: 14px !important; line-height: 1.4 !important; white-space: nowrap !important; 
}
.pac-item-query { 
    font-weight: 800 !important; color: #000000 !important; padding-right: 6px !important; flex: 0 0 auto !important; 
}
.pac-item span:not(.pac-item-query) {
    flex: 1 1 auto !important; min-width: 0 !important; overflow: hidden !important; text-overflow: ellipsis !important;
}
.pac-item:hover, .pac-item-selected { background-color: #FFF5F5 !important; }
.pac-container::after, .pac-logo::after, .pac-icon { display: none !important; }

/* ========================================= */
/* 11. МОБИЛЬНАЯ АДАПТАЦИЯ                   */
/* ========================================= */
@media (max-width: 480px) {
    .new-form-wrapper { padding: 20px 15px; width: 100%; max-width: 100%; }
    #mainForm .country-wrapper { width: 70px !important; min-width: 70px; }
    #mainForm .current-flag { margin-right: 4px; }
    #mainForm .current-code { font-size: 13px; }
    #mainForm .current-flag.default-globe { width: 38px !important; height: 38px !important; }
    #mainForm .flag-trigger { width: 90%; padding-right: 24px !important; }
    #mainForm .flag-trigger:not(:has(.default-globe)) { padding: 10px !important; }
    #mainForm .postal-container { width: 70px; }
    #mainForm .label-text { font-size: 12px; }
    #mainForm .address-segment input, #mainForm .standard-input { font-size: 13px; padding: 0 8px; }
    #mainForm .grid-4 { grid-template-columns: 1fr 1fr; gap: 10px; }
    #mainForm .dim-input-wrapper { height: 40px; }
    #mainForm .dim-input-wrapper input { padding-left: 45px; font-size: 13px; }
    
    #wrapper-from .custom-options, #wrapper-to .custom-options {
        position: fixed !important; top: 50% !important; left: 15px; right: 15px;
        transform: translateY(-50%) !important;
        width: auto !important; max-width: none !important;
        
        /* Скролл есть, но ограничен высотой экрана */
        max-height: 38vh !important; 
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        
        z-index: 2147483647 !important; 
        box-shadow: 0 0 0 1000px rgba(0,0,0,0.6) !important;
        border-radius: 12px !important;
    }
    
    #wrapper-parcel-type .custom-options {
        position: absolute !important; top: 105% !important; left: 0 !important;
        width: 100% !important; height: auto !important; max-height: 250px !important;
        transform: none !important; z-index: 50 !important;
        box-shadow: 0 10px 30px rgba(0,0,0,0.2) !important;
        overflow-y: auto !important;
    }
    .pac-container { width: 94vw !important; left: 3vw !important; right: 3vw !important; }
}

/* === ДОПОЛНИТЕЛЬНО: ПРЯЧЕМ ЛОГОТИП GOOGLE === */
.globe-icon-large {
    width: 26px !important; height: 26px !important; min-width: 26px !important;
    object-fit: contain !important;
}
.option-flag, .option-icon { object-fit: contain; }
/* ИСПРАВЛЕННЫЙ CSS */
body.hide-pac-list .pac-container {
    /* Не используем display: none, иначе сбиваются координаты! */
    visibility: hidden !important; 
    opacity: 0 !important;
    pointer-events: none !important;
}

input.locked-style {
    opacity: 1 !important;
}