/*
- ============================================================
- AI-КОНСУЛЬТАНТ
- Стили виджета
- ============================================================
 */


/*
- ============================================================
- КНОПКА ОТКРЫТИЯ
- ============================================================
 */

.ai-chat-toggle {
    position: fixed;
    left: 20px;
    bottom: 20px;
    width: 60px;
    height: 60px;

    /* Тонкий стеклянный блик по краю */
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 50%;

    background: linear-gradient(135deg, var(--brand-color, #c53030) 0%, #7b1820 100%);
    color: #ffffff;

    font-size: 28px;
    cursor: pointer;

    /* Объемная тень + внутреннее свечение сверху */
    box-shadow:
        0 10px 25px rgba(151, 32, 42, 0.38),
        inset 0 1px 1px rgba(255, 255, 255, 0.35);

    z-index: 9998;
    display: flex;
    align-items: center;
    justify-content: center;

    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.3s ease;
}

.ai-chat-toggle:hover {
    transform: scale(1.1) translateY(-2px); /* Чуть увеличивается и приподнимается */
    box-shadow: 0 15px 30px rgba(151, 32, 42, 0.5);
}

.ai-chat-toggle:active {
    transform: scale(0.95);
}

/* Легкий поворот иконки при наведении на кнопку */
.ai-chat-toggle svg {
    transition: transform 0.3s ease;
}

.ai-chat-toggle:hover svg {
    transform: scale(1.08) rotate(-4deg);
}

/* Мягкая пульсирующая волна вокруг кнопки */
.ai-chat-toggle::before {
    content: "";
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 1.5px solid rgba(151, 32, 42, 0.45);
    opacity: 0;
    pointer-events: none;
    animation: aiPulseRing 3.5s infinite cubic-bezier(0.215, 0.61, 0.355, 1);
}

@keyframes aiPulseRing {
    0% {
        transform: scale(0.95);
        opacity: 0.7;
    }
    70% {
        transform: scale(1.35);
        opacity: 0;
    }
    100% {
        transform: scale(1.35);
        opacity: 0;
    }
}


/*
- ============================================================
- ОКНО ЧАТА
- ============================================================
 */

.ai-chat-window {
    position: fixed;
    left: 20px;
    bottom: 90px;
    width: 340px;
    max-width: calc(100vw - 40px);
    height: 460px;

    /* Матовое стекло и мягкая рамка */
    background: rgba(255, 255, 255, 0.90);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);

    display: flex;
    flex-direction: column;
    overflow: hidden;

    z-index: 9999;
    font-family: Arial, sans-serif;
    font-size: 14px;

    opacity: 0;
    pointer-events: none;
    transform: translateY(10px);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.ai-chat-window.open {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}


/*
- ============================================================
- ШАПКА
- ============================================================
 */

.ai-chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;

    /* Премиальный градиент вместо плоского цвета */
    background: linear-gradient(135deg, var(--brand-color, #c53030) 0%, #7b1820 100%);
    color: #ffffff;
    font-weight: 600;
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
}

.ai-chat-title {
    font-size: 15px;
    letter-spacing: -0.01em;
}

/* Контейнер для кнопок в шапке */
.ai-chat-actions {
    display: flex;
    align-items: center;
    gap: 6px; /* Аккуратный отступ между корзиной и крестиком */
}

/* Общие стили для обеих кнопок (корзина и крестик) */
.ai-chat-clear,
.ai-chat-close {
    border: none;
    background: transparent;
    color: #ffffff;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    transition: background 0.2s ease, transform 0.2s ease;
}

/* Эффект при наведении */
.ai-chat-clear:hover,
.ai-chat-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Настройка крестика */
.ai-chat-close {
    font-size: 20px;
}

/* Настройка иконки корзины */
.ai-chat-clear svg {
    display: block;
    width: 16px;
    height: 16px;
}

/* Небольшая анимация при клике */
.ai-chat-clear:active,
.ai-chat-close:active {
    transform: scale(0.9);
}


/*
- ============================================================
- ОБЛАСТЬ СООБЩЕНИЙ
- ============================================================
 */

.ai-chat-body {
    flex: 1;
    padding: 14px;
    overflow-y: auto;
    background: #f8fafc;

    /* Тонкий современный скроллбар */
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.15) transparent;
}

.ai-chat-body::-webkit-scrollbar {
    width: 5px;
}

.ai-chat-body::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 10px;
}


/*
- ============================================================
- СООБЩЕНИЯ
- ============================================================
 */

.ai-msg {
    margin: 8px 0;
    padding: 10px 14px;
    border-radius: 14px;
    max-width: 85%;
    line-height: 1.45;
    word-wrap: break-word;
    font-size: 14.5px;
    animation: fadeInMsg 0.25s ease-out; /* Плавное появление сообщения */
}

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

.ai-msg.bot a {
    color: var(--brand-color, #97202a);
    text-decoration: underline;
    font-weight: 500;
    word-break: break-all;
}

.ai-msg.bot a:hover {
    opacity: 0.8;
}

/* Сообщение консультанта */
.ai-msg.bot {
    background: #ffffff;
    color: #1a202c;
    border: 1px solid rgba(0, 0, 0, 0.04);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
    border-bottom-left-radius: 4px;
}

/* Сообщение пользователя */
.ai-msg.user {
    background: linear-gradient(135deg, var(--brand-color, #c53030) 0%, #97202a 100%);
    color: #ffffff;
    margin-left: auto;
    box-shadow: 0 4px 12px rgba(151, 32, 42, 0.2);
    border-bottom-right-radius: 4px;
}

.ai-msg-author {
    display: block;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    margin-bottom: 3px;
    opacity: 0.72;
}

.ai-msg.bot .ai-msg-author {
    color: #64748b;
    text-align: left;
}

.ai-msg.user .ai-msg-author {
    color: rgba(255, 255, 255, 0.85);
    text-align: left;
}

.ai-msg-text {
    line-height: 1.45;
}


/*
- ============================================================
- БЫСТРЫЕ ВОПРОСЫ
- ============================================================
 */

.ai-chat-faq {
    padding: 8px 12px;
    border-top: 1px solid #e2e8f0;
    background: rgba(255, 255, 255, 0.5);
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.ai-faq-btn {
    background: #ffffff;
    border: 1px solid rgba(151, 32, 42, 0.25);
    color: #97202a;
    border-radius: 20px;
    padding: 6px 12px;
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.ai-faq-btn:hover {
    background: var(--brand-color, #97202a);
    color: #ffffff;
    border-color: var(--brand-color, #97202a);
    transform: translateY(-1px);
}

.ai-faq-topic {
    font-weight: 600;
}

.ai-faq-back {
    background: #f8fafc;
    color: #475569;
    border-color: #cbd5e1;
}

.ai-faq-back:hover {
    background: #e2e8f0;
    color: #1e293b;
    border-color: #cbd5e1;
}


/*
- ============================================================
- ПОЛЕ ВВОДА
- ============================================================
 */

.ai-chat-input-row {
    display: flex;
    padding: 10px 12px;
    border-top: 1px solid #edf2f7;
    background: #ffffff;
    align-items: center;
    gap: 8px;
    border-bottom-left-radius: 16px;
    border-bottom-right-radius: 16px;
}

.ai-chat-input {
    flex: 1;
    border: 1px solid #e2e8f0;
    border-radius: 20px;
    padding: 8px 14px;
    outline: none;
    font-size: 14px;
    min-width: 0;
    background: #f8fafc;
    transition: border-color 0.2s ease, background 0.2s ease;
}

.ai-chat-input:focus {
    border-color: var(--brand-color, #c53030);
    background: #ffffff;
}

.ai-chat-counter {
    font-size: 11px;
    color: #94a3b8;
    user-select: none;
    flex-shrink: 0;
    transition: color 0.2s ease;
}

.ai-chat-counter.limit {
    color: #e53e3e;
    font-weight: 600;
}

.ai-chat-send {
    border: none;
    background: linear-gradient(135deg, var(--brand-color, #c53030) 0%, #7b1820 100%);
    color: #ffffff;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s ease, opacity 0.2s ease;
    flex-shrink: 0;
}

.ai-chat-send:hover {
    opacity: 0.9;
    transform: scale(1.05);
}

.ai-chat-send:disabled {
    background: #cbd5e1;
    color: #ffffff;
    cursor: not-allowed;
    opacity: 1;
    transform: none;
}

.ai-chat-limit-warning {
    padding: 0 12px 8px;
    background: #ffffff;
    color: #e53e3e;
    font-size: 12px;
    font-weight: 600;
}

.ai-chat-limit-warning[hidden] {
    display: none;
}


/*
- ============================================================
- АНИМАЦИЯ НАБОРА ТЕКСТА
- ============================================================
 */

.ai-typing {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 2px;
}

.ai-msg-typing {
    padding: 10px 14px;
    display: inline-block;
}

.ai-typing span {
    width: 6px;
    height: 6px;
    background: #97202a;
    border-radius: 50%;
    opacity: 0.4;
    animation: aiTypingBounce 1.2s infinite ease-in-out;
}

.ai-typing span:nth-child(2) { animation-delay: 0.2s; }
.ai-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes aiTypingBounce {
    0%, 80%, 100% { transform: scale(0.8); opacity: 0.4; }
    40% { transform: scale(1.2); opacity: 1; }
}


/*
- ============================================================
- МОБИЛЬНАЯ ВЕРСИЯ
- ============================================================
 */

@media (max-width: 480px) {
    .ai-chat-window {
        left: 10px;
        right: 10px;
        bottom: 80px;
        width: auto;
        height: 70vh;
        max-width: none;
    }

    .ai-chat-toggle {
        left: 15px;
        right: auto;
        bottom: 15px;
    }
}