/* Подключение шрифта BENZIN Regular */
@font-face {
    font-family: 'BENZIN';
    src: url('fonts/Benzin-Regular.woff2') format('woff2'),
         url('fonts/Benzin-Regular.woff') format('woff'),
         url('fonts/Benzin-Regular.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

:root {
    --bg-color: #f5f5f5;
    --text-color: #333333;
    --primary: #E26B2D;
    --secondary: #C45A1F;
    --accent-thermo: #F07A3A;
    --success: #4CAF50;
    --border: #dddddd;
    --white: #ffffff;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: Arial, Helvetica, sans-serif;
    margin: 0;
    padding: 16px;
    background: var(--bg-color);
    color: var(--text-color);
}

/* body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    margin: 0;
    padding: 16px;
    background: var(--bg-color);
    color: var(--text-color);
    -webkit-text-fill-color: var(--text-color);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
} */

.logo-container {
    text-align: center;
    margin: 0 0 20px 0;
    width: 100%;
}

.logo-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    flex-wrap: wrap;
}

.logo {
    max-width: 200px;
    width: auto;
    height: auto;
    max-height: 60px;
    object-fit: contain;
}

.logo-etm {
    max-width: 200px;
    max-height: 60px;
}

/* Адаптивность для маленьких экранов */
@media (max-width: 480px) {
    .logo {
        max-width: 160px;
        max-height: 50px;
    }
}

.container {
    max-width: 480px;
    margin: 0 auto;
    width: 100%;
}

@media screen and (min-width: 768px) {
    body {
        padding: 24px 32px;
    }

    .container {
        max-width: 820px;
    }

    .selector-group label {
        font-size: 17px;
    }

    .option-btn {
        min-width: 120px;
        padding: 14px 18px;
    }

    .equipment-grid {
        gap: 20px;
    }

    .equipment-card {
        padding: 20px;
    }

    .result-card {
        padding: 28px;
    }
}

/* Шапка с логотипом */
.header {
    text-align: center;
    margin-bottom: 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* .logo {
    width: 120px;
    height: 120px;
    object-fit: contain;
    object-position: center;
    margin-bottom: 12px;
    display: block;
}
 */
/* h1 {
    font-size: 24px;
    text-align: center;
    margin: 0 0 8px 0;
    color: var(--primary);
    -webkit-text-fill-color: var(--primary);
    font-weight: 600;
} */

/* Группы выбора */
.selector-group {
    margin-bottom: 24px;
}

.selector-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--text-color);
    -webkit-text-fill-color: var(--text-color);
    font-size: 16px;
}

.button-group {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* Базовые стили для всех кнопок */
button, 
.option-btn {
    border: none;
    background: none;
    font: inherit;
    cursor: pointer;
    outline: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-appearance: none;
    appearance: none;
}

/* Стили для опций выбора */
.option-btn {
    flex: 1;
    min-width: 100px;
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: 8px;
    background: var(--white);
    font-size: 16px;
    font-weight: 500;
    color: var(--text-color) !important;
    -webkit-text-fill-color: var(--text-color) !important;
    transition: all 0.3s ease;
    text-align: center;
}

.option-btn:hover {
    border-color: var(--primary);
}

.option-btn.selected {
    background: var(--primary) !important;
    border-color: var(--primary) !important;
    color: var(--white) !important;
    -webkit-text-fill-color: var(--white) !important;
}

/* Кнопка рекомендации */
.recommend-btn {
    width: 100%;
    padding: 16px;
    background: var(--primary) !important;
    border: none;
    border-radius: 8px;
    font-size: 18px;
    font-weight: 600;
    color: var(--white) !important;
    -webkit-text-fill-color: var(--white) !important;
    cursor: pointer;
    transition: background 0.3s ease;
    margin: 8px 0;
}

.recommend-btn:hover:not(:disabled) {
    background: var(--secondary) !important;
}

.recommend-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Карточка результата */
.result-card {
    margin-top: 24px;
    padding: 20px;
    background: var(--white);
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.equipment-grid {
    display: flex;
    gap: 12px;
    align-items: stretch;
}

.equipment-card {
    flex: 1;
    min-width: 0;
    padding: 14px;
    background: #f8f9fa;
    border-radius: 10px;
}

.equipment-card h3 {
    margin: 0 0 10px 0;
    font-size: 16px;
    color: var(--primary);
    -webkit-text-fill-color: var(--primary);
    font-family: 'BENZIN', Arial, sans-serif;
    font-weight: normal;
}

@media screen and (max-width: 480px) {
    .equipment-grid {
        flex-direction: column;
    }
}

.step-collapse {
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    transition: max-height 450ms ease, opacity 350ms ease;
    will-change: max-height, opacity;
}

.step-collapse.active {
    max-height: 1200px;
    opacity: 1;
}

/* Чуть другой оттенок оранжевого для терморегулятора */
.thermo-btn {
    background: var(--accent-thermo) !important;
}

.thermo-btn:hover:not(:disabled) {
    background: var(--primary) !important;
}

#stepThermo .option-btn:hover {
    border-color: var(--accent-thermo);
}

#stepThermo .option-btn.selected {
    background: var(--accent-thermo) !important;
    border-color: var(--accent-thermo) !important;
}

.wizard-step {
    transition: opacity 300ms ease;
}

.reset-btn {
    width: 100%;
    margin-top: 20px;
    padding: 14px;
    background: transparent !important;
    border: 2px solid var(--primary) !important;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    color: var(--primary) !important;
    -webkit-text-fill-color: var(--primary) !important;
    cursor: pointer;
    transition: all 0.3s ease;
}

.reset-btn:hover {
    background: var(--primary) !important;
    color: var(--white) !important;
    -webkit-text-fill-color: var(--white) !important;
}

.result-card h2 {
    margin: 0 0 16px 0;
    font-size: 20px;
    color: var(--success);
    -webkit-text-fill-color: var(--success);
    font-weight: 600;
}

.recommendation-item {
    margin: 12px 0;
    padding: 16px;
    background: #f8f9fa;
    border-radius: 8px;
}

.recommendation-item strong {
    display: block;
    margin-bottom: 8px;
    color: var(--primary);
    -webkit-text-fill-color: var(--primary);
    font-size: 16px;
}

.recommendation-item p {
    margin: 6px 0;
    font-size: 14px;
    color: var(--text-color);
    -webkit-text-fill-color: var(--text-color);
    line-height: 1.4;
}

/* Ссылка на товар */
.recommendation-link {
    display: inline-block;
    margin-top: 12px;
    padding: 10px 16px;
    background: var(--primary) !important;
    color: var(--white) !important;
    -webkit-text-fill-color: var(--white) !important;
    text-decoration: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.3s ease;
    border: none;
    cursor: pointer;
}

.recommendation-link:hover {
    background: var(--secondary) !important;
}

/* Исправления для мобильных устройств */
@media screen and (max-width: 480px) {
    .option-btn {
        min-width: calc(50% - 4px);
        font-size: 15px;
        padding: 14px 12px;
    }
    
    .logo {
        max-width: 160px;
        max-height: 50px;
        width: auto;
        height: auto;
    }
    
    h1 {
        font-size: 22px;
    }
}

/* Фикс для WebView Telegram */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
    .option-btn,
    .recommend-btn,
    .recommendation-link {
        color: inherit;
    }
    
    .option-btn.selected {
        color: var(--white) !important;
    }
}

/* Убираем все стандартные выделения */
:focus {
    outline: none;
}

::-moz-focus-inner {
    border: 0;
}

/* Для очень маленьких экранов */
@media screen and (max-width: 320px) {
    .option-btn {
        min-width: 100%;
    }
    
    .logo {
        max-width: 140px;
        max-height: 44px;
        width: auto;
        height: auto;
    }
}

/* Вкладки */
.tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
    border-bottom: 2px solid var(--border);
    padding-bottom: 8px;
}

.tab-btn {
    flex: 1;
    padding: 12px;
    background: none;
    border: none;
    border-radius: 8px 8px 0 0;
    font-size: 16px;
    font-weight: 500;
    color: #666;
    cursor: pointer;
    transition: all 0.3s ease;
}

.tab-btn:hover {
    background: #f0f0f0;
}

 .tab-btn.active {
    color: white;
    border-bottom: 3px solid var(--primary);
    background: #E26B2D;
} 

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Поле ввода */
.input-field {
    width: 100%;
    padding: 14px;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 16px;
    box-sizing: border-box;
    transition: border 0.3s ease;
}

.input-field:focus {
    border-color: var(--primary);
    outline: none;
}

.result-value {
    font-size: 32px;
    font-weight: bold;
    color: var(--primary);
    text-align: center;
    margin: 16px 0 8px;
}

.result-unit {
    text-align: center;
    color: #666;
    font-size: 14px;
}

/* Слайдер */
.slider {
    width: 100%;
    margin: 10px 0;
    -webkit-appearance: none;
    appearance: none;
    height: 8px;
    background: linear-gradient(to right, var(--primary) 0%, var(--primary) 50%, #ddd 50%, #ddd 100%);
    border-radius: 4px;
    outline: none;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 24px;
    height: 24px;
    background: white;
    border: 2px solid var(--primary);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
    margin-top: -8px;
}

.slider::-moz-range-thumb {
    width: 24px;
    height: 24px;
    background: white;
    border: 2px solid var(--primary);
    border-radius: 50%;
    cursor: pointer;
}

.slider-labels {
    display: flex;
    justify-content: space-between;
    margin-top: 5px;
    color: #666;
    font-size: 12px;
}

/* Модальное окно для просмотра изображений */
.image-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9);
    z-index: 9999;
    cursor: pointer;
    animation: fadeIn 0.3s ease;
}

.image-modal.active {
    display: flex;
    justify-content: center;
    align-items: center;
}

.image-modal img {
    max-width: 90%;
    max-height: 90%;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.image-modal-close {
    position: absolute;
    top: 20px;
    right: 35px;
    color: #fff;
    font-size: 40px;
    font-weight: bold;
    cursor: pointer;
    transition: 0.3s;
    z-index: 10000;
}

.image-modal-close:hover {
    color: #999;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.recommendation-note {
    margin-top: 16px;
    padding: 12px;
    background: #fff3cd;
    border-left: 4px solid #ffc107;
    border-radius: 8px;
    font-size: 14px;
    color: #856404;
}

.recommendation-note strong {
    color: #856404;
    font-weight: 700;
}
/* Заголовки — BENZIN */
/* h1, h2, h3, .result-value, .tab-btn.active {
    font-family: 'BENZIN', Arial, sans-serif;
    font-weight: normal;
} */

/* Конкретный заголовок h1 (переопределяем) */
h1 {
    font-family: 'BENZIN', Arial, sans-serif;
    font-size: 24px;
    text-align: center;
    margin: 0 0 20px 0;
    color: var(--primary);
}

/* Всё остальное — уже Arial от body */

/* Заголовки и элементы навигации — BENZIN */
.selector-group label,
.tab-btn,
h1, h2, h3,
.result-value {
    font-family: 'BENZIN', Arial, sans-serif;
    font-weight: normal;
}

/* Кнопки и остальной интерфейс — ARIAL */
.option-btn,
.recommend-btn,
.input-field,
.recommendation-item p,
.result-unit,
.recommendation-note,
.slider-labels {
    font-family: Arial, Helvetica, sans-serif;
}

.spoiler {
    margin: 12px 0;
    background: #f8f9fa;
    border-radius: 8px;
    overflow: hidden;
}

.spoiler summary {
    padding: 12px 16px;
    cursor: pointer;
    font-weight: 500;
    color: var(--primary);
    background: #f0f0f0;
    user-select: none;
}

.spoiler summary:hover {
    background: #e6e6e6;
}

.spoiler-content {
    padding: 12px 16px;
    font-size: 14px;
    color: var(--text-color);
    line-height: 1.4;
    border-top: 1px solid #ddd;
}

/* ===== КНОПКА ДОБАВЛЕНИЯ В КОРЗИНУ (iPRO) ===== */
.add-to-cart-btn {
    width: 100%;
    padding: 16px;
    margin-top: 16px;
    background: #28a745 !important;
    border: none;
    border-radius: 8px;
    font-size: 18px;
    font-weight: 600;
    color: #ffffff !important;
    -webkit-text-fill-color: #ffffff !important;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: Arial, Helvetica, sans-serif;
}

.add-to-cart-btn:hover {
    background: #218838 !important;
    transform: scale(1.02);
}

.add-to-cart-btn:active {
    transform: scale(0.98);
}

.add-to-cart-btn.success {
    background: #28a745 !important;
}

.add-to-cart-btn.success::after {
    content: " ✅";
}

/* Стили для отображения выбранного мата */
.mat-selected {
    background: #e8f5e9;
    border-left: 4px solid #4CAF50;
    padding: 12px 16px;
    border-radius: 8px;
    margin: 8px 0;
}

.mat-selected strong {
    color: #2e7d32;
}
/* Мелкий текст, подписи, поля — Arial */
// ============================================================
// ========== ИНТЕГРАЦИЯ С iPRO (добавление в корзину) ==========
// ============================================================

/**
 * Отправка товаров в корзину iPRO
 * @param {Array} products - массив объектов { art, cnt, name }
 */
function sendToIpro(products) {
    if (!products || products.length === 0) {
        console.warn('Нет товаров для отправки в iPRO');
        return;
    }

    // Формируем JSON строго по инструкции
    const goods = JSON.stringify({
        products: products.map(item => ({
            art: String(item.art || '').trim(),
            cnt: Number(item.cnt) || 1,
            name: String(item.name || 'Товар').trim()
        }))
    });

    // Отправка в родительское окно (iPRO)
    try {
        window.top.postMessage(goods, '*');
        console.log('✅ Отправлено в iPRO:', goods);
    } catch (e) {
        console.error('❌ Ошибка отправки в iPRO:', e);
    }
}

/**
 * Получение текущей рекомендации с артикулами
 * Возвращает объект с товарами для корзины
 */
function getCartProducts() {
    const products = [];

    // 1. Мат (основной)
    const rec = recommendations[selectedRoom]?.[selectedFloor]?.[selectedBase];
    if (rec) {
        // Артикул мата (ЗАМЕНИТЬ НА РЕАЛЬНЫЕ АРТИКУЛЫ ИЗ ЭТМ!)
        const matArts = {
            'Теплолюкс TROPIX МНН': 'YT-00010866',
            'Warmstad WSM': 'YT-00011124',
            'Теплолюкс ProfiMat': 'YT-00010867',
            'Теплолюкс Alumia': 'YT-00010868',
            'Теплолюкс EvoHeat': 'YT-00010869',
            'Пленочный теплый пол SLIM HEAT': 'YT-00010870'
        };

        const art = matArts[rec.model] || 'YT-00000000';
        products.push({
            art: art,
            cnt: 1,
            name: rec.model || 'Нагревательный мат'
        });
    }

    // 2. Терморегулятор (если выбран)
    if (lastPickedThermostat) {
        const t = lastPickedThermostat;
        // Извлекаем артикул из ссылки (последние цифры) или заглушка
        let art = 'YT-00000001';
        if (t.link) {
            const match = t.link.match(/\/(\d+)$/);
            if (match) {
                art = 'YT-' + String(match[1]).padStart(8, '0');
            }
        }
        products.push({
            art: art,
            cnt: 1,
            name: t.name || 'Терморегулятор'
        });
    }

    return products;
}

// ===== ОБРАБОТЧИК КНОПКИ "ДОБАВИТЬ В КОРЗИНУ" =====
document.addEventListener('DOMContentLoaded', function() {
    const addToCartBtn = document.getElementById('addToCartBtn');
    
    if (addToCartBtn) {
        addToCartBtn.addEventListener('click', function() {
            const products = getCartProducts();
            
            if (products.length === 0) {
                alert('Сначала получите рекомендацию');
                return;
            }

            // Отправляем в iPRO
            sendToIpro(products);

            // Визуальная обратная связь
            const originalText = this.innerHTML;
            this.innerHTML = '✅ Добавлено в корзину!';
            this.style.background = '#28a745 !important';
            this.disabled = true;
            
            setTimeout(() => {
                this.innerHTML = originalText;
                this.style.background = '';
                this.disabled = false;
            }, 3000);
        });
    }
});

// Показываем кнопку "Добавить в корзину" после получения рекомендации
const originalThermoNext = document.getElementById('thermoNextBtn');
if (originalThermoNext) {
    const origClick = originalThermoNext.click;
    originalThermoNext.addEventListener('click', function() {
        setTimeout(() => {
            const btn = document.getElementById('addToCartBtn');
            if (btn) {
                btn.style.display = 'block';
            }
        }, 200);
    });
}

// Также показываем кнопку, если результат уже был показан
// (на случай, если пользователь вернулся к результату)
const resetBtn = document.getElementById('resetBtn');
if (resetBtn) {
    resetBtn.addEventListener('click', function() {
        const btn = document.getElementById('addToCartBtn');
        if (btn) {
            btn.style.display = 'none';
        }
    });
}

console.log('✅ Интеграция с iPRO активирована');