/* Базовые стили контейнера */
.ymap-apartments-container {
    display: grid;
    gap: 20px;
    padding: 10px;
    width: 100%;
    margin: 0 auto;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    align-items: start; /* Выравнивание карточек по верху */
}

/* Карточка - точные размеры из верстки с flex для внутреннего выравнивания */
.card {
    width: 100%;
    max-width: 320px;
    background: white;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
    position: relative;
    margin: 0 auto;
    cursor: pointer;
    transition: transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94), box-shadow 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    display: flex;
    flex-direction: column;
    height: 100%; /* Карточки займут полную доступную высоту в строке */
}

.card:hover {
    transform: translateY(-8px) scale(1.03);
    box-shadow: 0 20px 40px rgba(93, 61, 181, 0.25), 0 8px 16px rgba(93, 61, 181, 0.15);
}

/* Контейнер изображения - правильная настройка touch */
.image-container {
    position: relative;
    overflow: hidden;
    background: #f0f0f0;
    aspect-ratio: 320 / 200;
    /* ПРАВИЛЬНАЯ настройка touch-action */
    touch-action: manipulation; /* Разрешает zoom и pan, но убирает двойной тап задержку */
    user-select: none;
    -webkit-user-select: none;
    flex-shrink: 0;
}

/* Состояние когда идет горизонтальный свайп */
.image-container.swiping-horizontal {
    touch-action: none; /* Временно блокируем все touch действия */
}

.apartment-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    cursor: pointer;
    transition: opacity 0.4s ease, transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    display: block;
    pointer-events: none;
    -webkit-user-drag: none;
    -khtml-user-drag: none;
    -moz-user-drag: none;
    -o-user-drag: none;
    user-drag: none;
}

.card:hover .apartment-image {
    transform: scale(1.05);
}

.image-container:hover .apartment-image {
    cursor: crosshair;
}

/* Пагинация - точно как в верстке */
.pagination {
    position: absolute;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 4px;
}

.pagination-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.pagination-dot.active {
    background: white;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.3);
}

/* Контент - flex для правильного распределения пространства */
.content {
    padding: 16px;
    display: flex;
    flex-direction: column;
    flex-grow: 1; /* Контент растягивается на доступное пространство */
}

/* Заголовок - гибкая высота, растягивается */
.title {
    font-size: 18px;
    font-weight: 600;
    color: #5D3DB5;
    margin-bottom: 8px;
    line-height: 1.2;
    min-height: 1.2em; /* Минимальная высота для одной строки */
    flex-grow: 1; /* Заголовок растягивается и занимает доступное место */
    transition: color 0.4s ease;
}

.card:hover .title {
    color: #4A2D95;
}

/* Нижняя секция - всегда внизу карточки */
.bottom-section {
    margin-top: auto; /* Прижимает всю нижнюю секцию к низу */
}

/* Адрес - динамическая высота, выравнивается JavaScript по рядам */
.address {
    color: #666;
    font-size: 14px;
    margin-bottom: 16px;
    display: flex;
    align-items: flex-start;
    gap: 6px;
    line-height: 1.4;
    overflow: hidden; /* Скрываем лишний текст если он не помещается */
    transition: height 0.4s ease, color 0.4s ease; /* Плавное изменение высоты */
}

.card:hover .address {
    color: #555;
}

.address-text {
    display: -webkit-box;
    -webkit-line-clamp: 2; /* Ограничиваем до 2 строк */
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}

.location-icon {
    width: 16px;
    height: 16px;
    margin-top: 1px;
    opacity: 0.6;
    flex-shrink: 0;
    transition: opacity 0.4s ease;
}

.card:hover .location-icon {
    opacity: 0.8;
}

/* Фичи - теперь в нижней секции */
.features {
    display: flex;
    gap: 16px;
    margin-bottom: 20px;
    font-size: 14px;
    color: #666;
    flex-wrap: wrap;
    transition: color 0.4s ease;
}

.card:hover .features {
    color: #555;
}

.feature {
    display: flex;
    align-items: center;
    gap: 4px;
}

.feature-icon {
    width: 16px;
    height: 16px;
    opacity: 0.6;
    flex-shrink: 0;
    transition: opacity 0.4s ease;
}

.card:hover .feature-icon {
    opacity: 0.8;
}

/* Секция с кнопкой - в нижней секции */
.price-section {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 12px;
}

/* Кнопка "Забронировать" - точные стили из верстки */
.select-btn {
    background: #FF7E56;
    color: #E2FFDA;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94), color 0.4s ease, transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    white-space: nowrap;
    width: 100%;
    font-family: inherit;
    text-decoration: none;
    display: inline-block;
    text-align: center;
    line-height: 1;
}

.select-btn:hover {
    background: #e55a2b;
    color: #5D3DB5;
    text-decoration: none;
    transform: translateY(-2px);
}

.select-btn:focus {
    outline: none;
    background: #e55a2b;
    color: #5D3DB5;
    text-decoration: none;
}

/* Load more button - стили аналогичные кнопкам на карточках с полностью закругленными углами */
.ymap-load-more {
    grid-column: 1 / -1;
    text-align: center;
    margin: 29px 0 0 0;
}

.ymap-load-more button {
    /* Базовые размеры и позиционирование */
    width: auto;
    min-width: 180px;
    height: auto;
    padding: 12px 24px;
    
    /* Шрифт - аналогично кнопкам на карточках */
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-style: normal;
    font-weight: 600;
    font-size: 14px;
    line-height: 1;
    text-align: center;
    white-space: nowrap;
    text-decoration: none;
    
    /* Цвета - аналогично кнопкам на карточках */
    background: #FF7E56;
    color: #E2FFDA;
    border: none;
    
    /* ПОЛНОСТЬЮ закругленные углы */
    border-radius: 50px;
    
    /* Курсор и переходы */
    cursor: pointer;
    transition: background-color 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94), 
                color 0.4s ease, 
                transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94),
                box-shadow 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    outline: none;
    
    /* Убираем стандартные стили кнопки */
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    position: relative;
}

.ymap-load-more button:hover {
    background: #e55a2b;
    color: #5D3DB5;
    text-decoration: none;
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(255, 126, 86, 0.3), 0 4px 8px rgba(255, 126, 86, 0.2);
}

.ymap-load-more button:active,
.ymap-load-more button:focus {
    background: #e55a2b;
    color: #5D3DB5;
    text-decoration: none;
    outline: none;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(255, 126, 86, 0.25), 0 2px 4px rgba(255, 126, 86, 0.15);
}

/* Состояние загрузки */
.ymap-load-more button:disabled {
    background: #cccccc;
    color: #666666;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.ymap-load-more button:disabled:hover {
    background: #cccccc;
    color: #666666;
    transform: none;
    box-shadow: none;
}

/* Адаптация для мобильных устройств */
@media (max-width: 480px) {
    .ymap-apartments-container {
        /* Базовое правило для мобильных - 2 колонки по умолчанию */
        grid-template-columns: repeat(2, 1fr);
        max-width: 100%;
        padding: 5px;
        gap: 12px;
    }
    
    /* Специфичные правила для мобильных колонок */
    .ymap-apartments-container.mobile-columns-1 {
        grid-template-columns: 1fr !important;
    }
    
    .ymap-apartments-container.mobile-columns-2 {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    
    .ymap-apartments-container.mobile-columns-3 {
        grid-template-columns: repeat(3, 1fr) !important;
    }
    
    .ymap-apartments-container.mobile-columns-4 {
        grid-template-columns: repeat(4, 1fr) !important;
    }
    
    .card {
        max-width: 100%;
        margin: 0;
        border-radius: 8px;
    }
    
    .card:hover {
        transform: translateY(-4px) scale(1.02);
        box-shadow: 0 12px 24px rgba(93, 61, 181, 0.2), 0 4px 8px rgba(93, 61, 181, 0.12);
    }
    
    .content {
        padding: 12px;
    }
    
    .address {
        font-size: 13px !important;
        /* Убираем фиксированную высоту - JavaScript установит нужную */
    }
    
    .features {
        gap: 12px;
        font-size: 13px;
    }
    
    .price-section {
        justify-content: flex-start;
    }
    
    .select-btn {
        width: 100%;
        padding: 14px 24px;
    }
    
    .ymap-load-more {
        margin: 20px 0 0 0;
    }
    
    .ymap-load-more button {
        min-width: 160px;
        padding: 14px 24px;
        font-size: 14px;
    }
    
    .ymap-load-more button:hover {
        transform: translateY(-1px);
        box-shadow: 0 6px 16px rgba(255, 126, 86, 0.25), 0 3px 6px rgba(255, 126, 86, 0.15);
    }
}

/* Планшеты - 2-4 колонки в зависимости от ширины */
@media (min-width: 481px) and (max-width: 768px) {
    .ymap-apartments-container {
        grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
        max-width: 100%;
        padding: 8px;
    }
    
    .content {
        padding: 18px;
    }
    
    /* Убираем фиксированную высоту - JavaScript установит нужную */
}

/* Маленький десктоп - до 3 колонок */
@media (min-width: 769px) and (max-width: 1200px) {
    .ymap-apartments-container {
        grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
        max-width: 900px;
    }
    
    /* Убираем фиксированную высоту - JavaScript установит нужную */
}

/* Большой десктоп - ТОЧНОЕ количество колонок из шорткода */
@media (min-width: 1201px) {
    .ymap-apartments-container.max-columns-1 {
        grid-template-columns: 1fr !important;
        max-width: 320px;
    }
    
    .ymap-apartments-container.max-columns-2 {
        grid-template-columns: repeat(2, 1fr) !important;
        max-width: 680px;
    }
    
    .ymap-apartments-container.max-columns-3 {
        grid-template-columns: repeat(3, 1fr) !important;
        max-width: 1020px;
    }
    
    .ymap-apartments-container.max-columns-4 {
        grid-template-columns: repeat(4, 1fr) !important;
        max-width: 1360px;
    }
    
    .ymap-apartments-container.max-columns-5 {
        grid-template-columns: repeat(5, 1fr) !important;
        max-width: 1700px;
    }
    
    .ymap-apartments-container.max-columns-6 {
        grid-template-columns: repeat(6, 1fr) !important;
        max-width: 2040px;
    }
    
    /* По умолчанию если класс не указан - 4 колонки */
    .ymap-apartments-container:not([class*="max-columns-"]) {
        grid-template-columns: repeat(4, 1fr) !important;
        max-width: 1360px;
    }
    
    /* Убираем фиксированную высоту - JavaScript установит нужную */
}

/* Дополнительные состояния для лучшего UX */
.ymap-load-more button:before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: inherit;
    background: linear-gradient(45deg, transparent 30%, rgba(255, 255, 255, 0.1) 50%, transparent 70%);
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.ymap-load-more button:hover:before {
    opacity: 1;
}

/* Анимация нажатия */
.ymap-load-more button:active {
    animation: button-press 0.1s ease;
}

@keyframes button-press {
    0% { transform: translateY(-2px) scale(1); }
    50% { transform: translateY(0) scale(0.98); }
    100% { transform: translateY(-1px) scale(1); }
}

/* No results message */
.ymap-no-apartments {
    display: none;
    grid-column: 1 / -1;
    text-align: center;
    padding: 30px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 18px;
    color: #6D6D6E;
}