/* Цвет чата: #3B4593 */
/* Кнопка чата — робот-помощник */
.chat-widget-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 64px;
    height: 64px;
    background: linear-gradient(145deg, #4A52A8 0%, #3B4593 100%);
    border-radius: 50%;
    box-shadow: 0 4px 16px rgba(59, 69, 147, 0.4), 0 0 0 3px rgba(255,255,255,0.15);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    z-index: 9999;
    color: #fff;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.chat-widget-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(59, 69, 147, 0.5), 0 0 0 3px rgba(255,255,255,0.2);
}

.chat-widget-btn__robot {
    width: 36px;
    height: 42px;
}

/* Лёгкая анимация «приветствия» робота в покое */
@keyframes chat-robot-wave {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(-3deg); }
    75% { transform: rotate(3deg); }
}

.chat-widget-btn:not(:hover) .chat-widget-btn__robot {
    animation: chat-robot-wave 3s ease-in-out infinite;
}

/* Окно чата: уменьшенные размеры, чтобы не перекрывать приветственный текст; max-width — не обрезаться на узких экранах */
.chat-window {
    position: fixed;
    bottom: 94px;
    right: 20px;
    width: 320px;
    max-width: calc(100vw - 40px);
    height: 480px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    box-shadow: 0 5px 25px rgba(0,0,0,0.2);
    display: flex;
    flex-direction: column;
    z-index: 9999;
    opacity: 0;
    transform: translateY(20px);
    pointer-events: none;
    transition: all 0.3s ease;
    border: 1px solid rgba(0,0,0,0.05);
}

.chat-window.active {
    opacity: 1;
    transform: translateY(0);
    pointer-events: all;
}

.chat-header {
    background: linear-gradient(135deg, #4A52A8 0%, #3B4593 100%);
    color: white;
    padding: 14px 18px;
    border-top-left-radius: 20px;
    border-top-right-radius: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header__title-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Иконка робота в заголовке — уменьшенный размер */
.chat-header__robot {
    width: 20px;
    height: 24px;
    flex-shrink: 0;
}

.chat-header h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
}

.chat-close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    line-height: 1;
}

/* min-height: 0 — чтобы flex-ребёнок сжимался и overflow-y: auto работал; иначе последняя строка обрезается */
.chat-messages {
    flex: 1;
    min-height: 0;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* Сообщения: увеличенный шрифт для читаемости */
.message {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 15px;
    font-size: 16px;
    line-height: 1.5;
    word-wrap: break-word;
}

.message.bot {
    align-self: flex-start;
    background-color: #f0f2f5;
    color: #222;
    border-bottom-left-radius: 5px;
}

.message.user {
    align-self: flex-end;
    background-color: #3B4593;
    color: white;
    border-bottom-right-radius: 5px;
}

/* Markdown Styles inside bot messages */
.message.bot a {
    color: #3B4593;
    text-decoration: underline;
}

.message.bot ul {
    margin: 5px 0;
    padding-left: 20px;
}

.chat-input-area {
    padding: 15px;
    border-top: 1px solid #eee;
    display: flex;
    gap: 10px;
}

.chat-input {
    flex: 1;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 20px;
    outline: none;
    font-size: 14px;
}

.chat-input:focus {
    border-color: #3B4593;
}

.chat-send-btn {
    background-color: #3B4593;
    color: white;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background 0.2s;
}

.chat-send-btn:hover {
    background-color: #2E3676;
}

.chat-send-btn svg {
    width: 16px;
    height: 16px;
    fill: white;
    margin-left: 2px;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 5px;
    padding: 10px 15px;
    background-color: #f0f2f5;
    border-radius: 15px;
    width: fit-content;
    margin-bottom: 10px;
    border-bottom-left-radius: 5px;
}

.dot {
    width: 8px;
    height: 8px;
    background-color: #90a4ae;
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.dot:nth-child(1) { animation-delay: -0.32s; }
.dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* ========== Адаптация под мобильные ========== */

/* Планшеты и узкие экраны (≤768px) */
@media (max-width: 768px) {
    .chat-widget-btn {
        bottom: calc(16px + env(safe-area-inset-bottom, 0px));
        right: calc(16px + env(safe-area-inset-right, 0px));
    }

    .chat-window {
        bottom: 92px;
        right: 16px;
        left: auto;
        width: min(400px, calc(100vw - 32px));
        max-width: none;
        height: 75vh;
        border-radius: 16px;
    }

    .chat-header {
        padding: 12px 14px;
        border-top-left-radius: 16px;
        border-top-right-radius: 16px;
    }

    .chat-messages {
        padding: 16px;
    }

    .chat-input-area {
        padding: 12px 14px;
    }
}

/* Телефоны (≤480px): полноэкранный чат, safe-area под вырез и home-индикатор */
@media (max-width: 480px) {
    .chat-widget-btn {
        bottom: calc(16px + env(safe-area-inset-bottom, 0px));
        right: calc(16px + env(safe-area-inset-right, 0px));
    }

    .chat-window {
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-width: none;
        height: 100%;
        min-height: 100dvh;
        min-height: -webkit-fill-available;
        border-radius: 0;
    }

    .chat-header {
        padding: 12px 16px;
        padding-top: max(12px, env(safe-area-inset-top));
        border-radius: 0;
    }

    .chat-close-btn {
        min-width: 44px;
        min-height: 44px;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 24px;
    }

    .chat-messages {
        padding: 16px;
        -webkit-overflow-scrolling: touch;
    }

    .chat-input-area {
        padding: 12px 16px;
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }

    /* 16px в input — без зума при фокусе на iOS */
    .chat-input {
        font-size: 16px;
        padding: 12px 14px;
    }

    /* Кнопка «Отправить» не менее 44×44 для удобного нажатия */
    .chat-send-btn {
        width: 44px;
        height: 44px;
        flex-shrink: 0;
    }

    .chat-send-btn svg {
        width: 18px;
        height: 18px;
    }

    .message {
        padding: 10px 14px;
        font-size: 15px;
    }
}

/* Очень маленькие экраны (≤360px) */
@media (max-width: 360px) {
    .chat-widget-btn {
        bottom: calc(12px + env(safe-area-inset-bottom, 0px));
        right: calc(12px + env(safe-area-inset-right, 0px));
        width: 56px;
        height: 56px;
    }

    .chat-widget-btn__robot {
        width: 30px;
        height: 36px;
    }

    .chat-header {
        padding: 10px 12px;
        padding-top: max(10px, env(safe-area-inset-top));
    }

    .chat-header h3 {
        font-size: 14px;
    }

    .chat-messages {
        padding: 12px;
    }

    .chat-input-area {
        padding: 10px 12px;
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }

    .chat-input {
        padding: 10px 12px;
        font-size: 16px;
    }

    .chat-send-btn {
        width: 42px;
        height: 42px;
    }

    .message {
        padding: 10px 12px;
        font-size: 15px;
    }
}
