/* =========================================
   AI ASSISTANT WIDGET STYLES
   ========================================= */

/* --- Контейнер виджета (Окно чата) --- */
.ai-chat-widget {
    position: fixed;
    bottom: 100px; /* Отступ снизу (чтобы не перекрывать кнопки карты) */
    right: 30px;
    width: 380px;  /* Стандартная ширина */
    height: 600px; /* Стандартная высота */
    max-height: 80vh; /* Не больше 80% высоты экрана */
    background-color: #ffffff;
    border-radius: 24px;
    box-shadow: 0 5px 40px rgba(0,0,0,0.16);
    display: flex;
    flex-direction: column;
    z-index: 2000; /* Поверх карты, фильтров и шторки */
    
    /* Состояние "Скрыто" */
    opacity: 0;
    pointer-events: none;
    transform: translateY(20px) scale(0.95);
    transform-origin: bottom right;
    transition: all 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
    
    /* Скрываем вылезающие элементы */
    overflow: hidden;
    border: 1px solid rgba(0,0,0,0.05);
}

/* Состояние "Открыто" */
.ai-chat-widget.show {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* === Состояние "Развернуто" (для ПК) === */
.ai-chat-widget.expanded {
    width: 700px;        /* Шире */
    height: 800px;       /* Выше */
    max-width: 90vw;     /* Чтобы не вылезало на маленьких экранах */
    max-height: 90vh;
}

/* --- Шапка чата --- */
.chat-header {
    padding: 16px 20px;
    background: var(--primary-gradient);
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    flex-shrink: 0; /* Не сжимать шапку */
}

.chat-header h6 {
    margin: 0;
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-header-actions {
    display: flex;
    gap: 8px;
}

.header-btn {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s;
}

.header-btn:hover {
    background: rgba(255,255,255,0.35);
}

/* --- Область сообщений --- */
.chat-messages {
    flex-grow: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
    background-color: #f8f9fa; /* Светлый фон для области сообщений */
    scroll-behavior: smooth;
}

/* Скроллбар для сообщений (тонкий) */
.chat-messages::-webkit-scrollbar {
    width: 6px;
}
.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}
.chat-messages::-webkit-scrollbar-thumb {
    background-color: rgba(0,0,0,0.1);
    border-radius: 10px;
}

/* --- Сообщение (Пузырь) --- */
.message {
    display: flex;
    max-width: 85%;
    animation: msgIn 0.2s ease-out;
}

@keyframes msgIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.message .text {
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 0.95rem;
    line-height: 1.5;
    word-wrap: break-word;
    position: relative;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

/* Стиль сообщения пользователя */
.message.user {
    align-self: flex-end;
}
.message.user .text {
    background: var(--primary-gradient);
    color: white;
    border-bottom-right-radius: 4px;
}

/* Стиль сообщения ассистента */
.message.assistant {
    align-self: flex-start;
}
.message.assistant .text {
    background-color: #ffffff;
    color: #333;
    border-bottom-left-radius: 4px;
    border: 1px solid rgba(0,0,0,0.05);
}

/* --- Форма ввода --- */
.chat-input-form {
    padding: 15px;
    background-color: #ffffff;
    border-top: 1px solid rgba(0,0,0,0.05);
    flex-shrink: 0;
}

.chat-input-wrapper {
    display: flex;
    gap: 10px;
    background: #f1f3f5;
    padding: 8px;
    border-radius: 30px;
    border: 1px solid transparent;
    transition: all 0.2s;
    align-items: center;
}

.chat-input-wrapper:focus-within {
    background: #fff;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.15);
}

.chat-input-form input {
    border: none;
    background: transparent;
    padding-left: 15px;
    flex-grow: 1;
    outline: none;
    color: #333;
    font-size: 0.95rem;
    height: 36px;
}

.chat-input-form button {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--primary-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s;
    flex-shrink: 0;
}

.chat-input-form button:hover {
    transform: scale(1.05);
}

.chat-input-form button i {
    font-size: 1rem;
    margin-left: -2px; /* Визуальная коррекция иконки send */
    margin-top: 2px;
}

/* --- Индикатор набора текста (Typing...) --- */
.typing-indicator {
    padding: 15px 20px !important;
    display: flex;
    align-items: center;
    gap: 4px;
    min-width: 60px;
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    background-color: #adb5bd;
    border-radius: 50%;
    display: inline-block;
    animation: bounce 1.4s infinite ease-in-out both;
}

.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* =========================================
   MOBILE RESPONSIVENESS (FULLSCREEN FIX)
   ========================================= */
@media (max-width: 768px) {
    .ai-chat-widget {
        /* ВАЖНО: Отступаем сверху на высоту хедера, чтобы он не перекрывал чат */
        top: var(--header-height); 
        bottom: 0;
        right: 0;
        left: 0;
        
        width: 100%;
        /* Высота = 100% экрана минус высота хедера */
        height: calc(100% - var(--header-height)); 
        max-height: none;
        
        border-radius: 0;
        transform-origin: center;
        border: none;
        box-shadow: none; /* Тень не нужна на весь экран */
    }

    .ai-chat-widget.show {
        transform: translateY(0);
    }

    /* Учет Safe Areas (для iPhone с челкой и полоской снизу) */
    .chat-header {
        padding-top: 15px; 
        padding-bottom: 15px;
    }

    .chat-input-form {
        /* Отступ снизу для iPhone home bar */
        padding-bottom: max(15px, env(safe-area-inset-bottom));
    }
    
    /* Увеличиваем размер текста для читаемости на мобильных */
    .message .text {
        font-size: 1rem; 
        padding: 14px 18px;
    }

    /* Скрываем кнопку расширения на мобильных (там всегда фуллскрин) */
    #chat-expand-btn {
        display: none;
    }
}

/* =========================================
   DARK MODE SUPPORT
   ========================================= */
[data-bs-theme="dark"] .ai-chat-widget {
    background-color: #1e1e1e;
    border-color: #333;
}

[data-bs-theme="dark"] .chat-messages {
    background-color: #121212;
}

/* Ассистент в темной теме */
[data-bs-theme="dark"] .message.assistant .text {
    background-color: #2c2c2c;
    color: #e0e0e0;
    border-color: #444;
}

/* Инпут в темной теме */
[data-bs-theme="dark"] .chat-input-form {
    background-color: #1e1e1e;
    border-color: #333;
}

[data-bs-theme="dark"] .chat-input-wrapper {
    background-color: #2c2c2c;
}

[data-bs-theme="dark"] .chat-input-form input {
    color: #fff;
}

[data-bs-theme="dark"] .chat-input-wrapper:focus-within {
    background-color: #2c2c2c; /* Сохраняем темный фон при фокусе */
    border-color: var(--primary-color);
}