/* ============================
   ОСНОВА ЧАТА
============================ */
.hidden {
    display: none !important;
}

/* Кнопка открытия */
#ntrvl-chat-button {
    width: 64px;
    height: 64px;
    background: #4A61AB;
    border-radius: 50%;
    color: #fff;
    font-size: 30px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
    transition: .25s ease;
}

#ntrvl-chat-button:hover {
    transform: scale(1.08);
}

/* Окно чата */
#ntrvl-chat-window {
    width: 380px;
    height: 560px;
    background: #ffffff;
    border-radius: 18px;
    overflow: hidden;
    box-shadow: 0 0 35px rgba(0, 0, 0, 0.28);
    display: flex;
    flex-direction: column;

    /* Позиционирование */
    position: fixed;
    bottom: 110px;
    right: 30px;
    z-index: 9999998 !important;

    animation: chatOpen .25s ease;
}

@keyframes chatOpen {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================
   ШАПКА (Аэрофлот-стиль)
============================ */

#ntrvl-chat-header {
    background: #7e636f;
    /* твой фирменный */
    color: #fff;
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}

/* Левая часть */
.chat-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-logo {
    height: 46px;
    width: auto;
}

.chat-brand {
    font-size: 17px;
    font-weight: 600;
    letter-spacing: .6px;
    margin-top: 1px;
}

/* Правая часть */
.chat-header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-header-btn {
    background: transparent;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    padding: 4px 7px;
    border-radius: 6px;
    transition: background .2s;
}

.chat-header-btn:hover {
    background: rgba(255, 255, 255, 0.18);
}

.close-btn:hover {
    background: rgba(255, 0, 0, 0.28);
}

/* Лупа */
.search-btn {
    font-size: 19px;
    padding: 4px 6px;
}

/* Три точки */
.more-btn {
    font-size: 22px;
    margin-top: -2px;
}


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

#ntrvl-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 18px;
    background: #f4f4f4;
}

/* Скроллбар */
#ntrvl-chat-messages::-webkit-scrollbar {
    width: 8px;
}

#ntrvl-chat-messages::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 5px;
}

#ntrvl-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

/* Дата */
.chat-date {
    text-align: center;
    padding: 8px 0;
    color: #888;
    font-size: 13px;
    margin-bottom: 10px;
}

/* Обертка сообщения */
.msg {
    margin: 8px 0;
    display: flex;
    flex-direction: column;
    /* Чтобы блоки не растягивались */
    width: 100%;
}

/* Внутренний пузырь текста */
.msg .msg-text {
    position: relative;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 15px;
    line-height: 1.4;
    word-wrap: break-word;
    /* Перенос длинных слов */
    max-width: 80%;
    width: fit-content;
    /* Ширина по содержимому */
}

/* === БОТ (Розовый, слева) === */
.msg.bot {
    align-items: flex-start;
}

.msg.bot .msg-text {
    background: #f3e7ef;
    /* Светлый фирменный */
    color: #503543;
    border-bottom-left-radius: 2px;
    /* Эффект хвостика */
}

/* === ПОЛЬЗОВАТЕЛЬ (Синий, справа) === */
.msg.user {
    align-items: flex-end;
}

.msg.user .msg-text {
    background: #6789BC;
    /* 🔥 СИНИЙ ФОН */
    color: #fff;
    /* 🔥 БЕЛЫЙ ТЕКСТ */
    border-bottom-right-radius: 2px;
    /* Эффект хвостика */
    text-align: left;
}

/* === ВРЕМЯ И ГАЛОЧКИ === */
/* Исправление наложения: используем float вместо absolute */
.msg-time {
    float: right;
    /* Прижимаем вправо, текст обтекает */
    margin-left: 10px;
    /* Отступ от текста */
    margin-top: 6px;
    /* Чуть опускаем вниз */
    font-size: 11px;
    display: flex;
    /* Для выравнивания галочек */
    align-items: center;
    gap: 4px;
    white-space: nowrap;
    /* Время и галочки не разрываются */
    line-height: 1;
}

/* Цвет времени для Бота */
.msg.bot .msg-time {
    color: #8e7a85;
}

/* Цвет времени для Юзера */
.msg.user .msg-time {
    color: rgba(255, 255, 255, 0.75);
    /* Полупрозрачный белый */
}

/* Галочки внутри SVG */
.msg.user .msg-time svg path {
    stroke: #fff;
    /* Принудительно белые галочки */
}


/* ============================
   КНОПКИ-ТЕМЫ (бот предлагает)
============================ */

.chat-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 4px;
    margin-bottom: 8px;
    width: 100%;
    /* Чтобы кнопки занимали всю ширину */
}

.chat-btn {
    padding: 9px 14px;
    border: none;
    background: #84606e;
    color: white;
    border-radius: 12px;
    cursor: pointer;
    font-size: 14px;
    transition: background .2s;
    line-height: 1.3;
    text-align: left;
}

.chat-btn:hover {
    background: #6f4f5a;
}

/* Альтернативный стиль кнопок (бот предлагает темы) - если используются классы .bot-btn */
.bot-btn {
    border: 1px solid #7e636f;
    background: #ffffff;
    color: #7e636f;
    padding: 8px 12px;
    display: inline-block;
    border-radius: 14px;
    margin: 4px 0;
    cursor: pointer;
    transition: .15s ease;
}

.bot-btn:hover {
    background: #7e636f;
    color: #fff;
}


/* ============================
   НИЖНЯЯ ПАНЕЛЬ
============================ */

#ntrvl-chat-input-bar {
    display: flex;
    border-top: 1px solid #d7d7d7;
    padding: 12px;
    background: #fff;
}

#ntrvl-chat-input {
    flex: 1;
    padding: 10px 14px;
    border-radius: 10px;
    border: 1px solid #bbb;
    outline: none;
    font-size: 15px;
    transition: border-color .2s;
}

#ntrvl-chat-input:focus {
    border-color: #7e636f;
}

#ntrvl-chat-send {
    background: #7e636f;
    color: white;
    padding: 0 16px;
    /* padding fix */
    margin-left: 10px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: .2s;
}

#ntrvl-chat-send:hover {
    background: #6b5560;
}


/* ============================
   КНОПКА ПУЛЬСАЦИИ (ГЛАВНАЯ)
============================ */

#pulse-button {
    z-index: 9999999 !important;
    position: fixed;
    bottom: 30px;
    right: 30px;
}

.pulse-btn {
    width: 70px;
    height: 70px;
    background: #5D87C9;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 4px 25px rgba(0, 0, 0, 0.25);
    animation: pulse-wave 2.2s infinite ease-out;
}

/* Контейнер иконок внутри кнопки */
.pulse-inner {
    width: 38px;
    height: 38px;
    position: relative;
}

.icon-cycle {
    position: relative;
    width: 100%;
    height: 100%;
}

.icon {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    transform: scale(0.7);
    transition: opacity .4s, transform .4s;
}

.icon svg {
    width: 100%;
    height: 100%;
    display: block;
}

/* Анимации иконок */
.svg-n {
    animation: iconN 6s infinite;
}

.svg-doc {
    animation: iconDoc 6s infinite;
}

.svg-chat {
    animation: iconChat 6s infinite;
}

@keyframes iconN {

    0%,
    20% {
        opacity: 1;
        transform: scale(1);
    }

    21%,
    100% {
        opacity: 0;
    }
}

@keyframes iconDoc {

    0%,
    33% {
        opacity: 0;
    }

    34%,
    53% {
        opacity: 1;
        transform: scale(1);
    }

    54%,
    100% {
        opacity: 0;
    }
}

@keyframes iconChat {

    0%,
    66% {
        opacity: 0;
    }

    67%,
    87% {
        opacity: 1;
        transform: scale(1);
    }

    88%,
    100% {
        opacity: 0;
    }
}

@keyframes pulse-wave {
    0% {
        box-shadow: 0 0 0 0 rgba(93, 135, 201, 0.6), 0 0 0 0 rgba(93, 135, 201, 0.3);
    }

    70% {
        box-shadow: 0 0 0 18px rgba(93, 135, 201, 0), 0 0 0 36px rgba(93, 135, 201, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(93, 135, 201, 0), 0 0 0 0 rgba(93, 135, 201, 0);
    }
}


/* ============================
   КНОПКА ПРОКРУТКИ ВНИЗ
============================ */
.scroll-down-btn {
    position: absolute;
    right: 18px;
    bottom: 95px;

    width: 38px;
    height: 38px;
    background: #7e636f;
    color: white;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;

    font-size: 22px;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
    z-index: 99;
    transition: opacity .25s, transform .25s;
    opacity: 0;
    transform: scale(0.85);

    padding-bottom: 2px;
}

.scroll-down-btn.show {
    opacity: 1;
    transform: scale(1);
}

.scroll-down-btn.hidden {
    display: none;
}

/* ============================
      ВЛОЖЕНИЯ — ФОТО / ФАЙЛЫ
============================ */

/* Общий контейнер фото */
.msg-image {
    max-width: 80%;
    margin: 8px 0;
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.22);
    display: block;
}

/* Картинка внутри */
.msg-image img {
    width: 100%;
    height: auto;
    display: block;

    /* Чтобы фото не занимало весь экран */
    max-height: 260px;
    object-fit: cover;

    cursor: pointer;
}

/* Фото от бота — слева */
.msg.bot .msg-image {
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

/* Фото от юзера — справа */
.msg.user .msg-image {
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

/* Время под фото */
.msg-image .msg-time {
    margin: 6px;
    float: right;
    color: #8e7a85;
    font-size: 11px;
    opacity: 0.8;
}


/* ============================
       ДОКУМЕНТЫ
============================ */

.msg-file {
    max-width: 80%;
    display: flex;
    align-items: center;
    gap: 10px;

    background: #f2f2f2;
    padding: 12px 14px;
    border-radius: 14px;

    font-size: 15px;
    text-decoration: none;

    color: #333;
    margin: 8px 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
}

/* Документы от бота */
.msg.bot .msg-file {
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

/* Документы от юзера */
.msg.user .msg-file {
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

/* Иконка документа */
.msg-file .file-icon {
    font-size: 22px;
    color: #7e636f;
}

/* Имя документа */
.msg-file .file-name {
    font-weight: 600;
    color: #333;
    word-break: break-all;
}

/* ====== ГЛАВНЫЙ ФИКС ЧТОБЫ ФОТО НЕ ВЫЛЕТАЛО ====== */

/* Контейнер любого сообщения */
.msg {
    max-width: 100%;
}

/* Контейнер изображения */
.msg-image {
    max-width: 78% !important;
    width: auto;
    margin: 8px 0;
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.22);
    display: block;
}

/* Картинка внутри */
.msg-image img {
    width: 100% !important;
    height: auto;
    max-height: 260px;
    object-fit: cover;
    display: block;
}

/* Фото от бота — слева */
.msg.bot .msg-image {
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

/* Фото от юзера — справа */
.msg.user .msg-image {
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

/* ====== ПОИСК (идеально встроенный, ровно по краям) ====== */

#ntrvl-chat-search-bar {
    width: 100%;
    box-sizing: border-box;

    background: #ffffff;

    padding: 12px 16px 10px 16px;
    display: none;

    border-bottom: 1px solid #e5e5e5;

    /* Совпадает со скруглённым окном */
    border-top-left-radius: 0;
    border-top-right-radius: 0;

    animation: slideDown 0.25s ease;
}

#ntrvl-chat-search-bar.show {
    display: block !important;
}

/* Поле поиска */
#ntrvl-chat-search-input {
    width: 100%;
    box-sizing: border-box;

    padding: 10px 14px;
    font-size: 15px;

    border-radius: 12px;
    border: 1px solid #c8b8c2;

    background: #faf7f9;

    outline: none;
    transition: border-color .2s, background .2s;
}

#ntrvl-chat-search-input::placeholder {
    color: #a8949f;
}

#ntrvl-chat-search-input:focus {
    border-color: #7e636f;
    background: #ffffff;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}


/* =========================================
   КРАСИВЫЙ ПОИСК (ЦВЕТА)
========================================= */

/* Контейнер информации (счетчик 1/5 и стрелки) */
#ntrvl-chat-search-info {
    margin-top: 8px;
    padding: 0 4px;
    /* Flex чтобы элементы встали в ряд */
    display: flex !important;
    justify-content: space-between;
    align-items: center;

    font-size: 13px;
    color: #6d5a63;
    font-weight: 500;
}

/* Скрываем, только если явно добавлен класс hidden */
#ntrvl-chat-search-info.hidden {
    display: none !important;
}

.search-nav {
    display: flex;
    gap: 6px;
}

#search-prev,
#search-next {
    padding: 2px 6px;
    font-size: 14px;
    border: 1px solid #c8b8c2;
    background: #fff;
    border-radius: 6px;
    cursor: pointer;
    transition: background .2s, border-color .2s;
}

#search-prev:hover,
#search-next:hover {
    background: #ede3e8;
    border-color: #7e636f;
}

/* 1. ОБЫЧНОЕ СОВПАДЕНИЕ (Ярко-желтый) */
mark.search-highlight {
    background-color: #ffe600 !important;
    /* Яркий желтый маркер */
    color: #000 !important;
    border-radius: 3px;
    padding: 0 1px;
}

/* 2. ТЕКУЩЕЕ СОВПАДЕНИЕ (Тот же желтый, но с рамкой) */
mark.current-search {
    background-color: #ffe600 !important;
    /* Такой же желтый */
    color: #000 !important;
    outline: 2px solid #5a4852;
    /* Темная рамка для фокуса */
    z-index: 10;
    position: relative;
    font-weight: bold;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

/* === ВРЕМЯ И ГАЛОЧКИ === */
/* Всегда отдельной строкой внизу справа */
.msg-time {
    display: block;
    margin-top: 6px;
    font-size: 11px;
    line-height: 1;
    text-align: right;
    /* прижать вправо внутри пузыря */
    white-space: nowrap;
    /* не рвать время */
}

/* Цвет времени для Бота */
.msg.bot .msg-time {
    color: #8e7a85;
}

/* Цвет времени для Юзера */
.msg.user .msg-time {
    color: rgba(255, 255, 255, 0.75);
}

/* Галочки внутри SVG */
.msg.user .msg-time svg path {
    stroke: #fff;
}

/* ============================
   АВАТАР ДЛЯ БОТА / ОПЕРАТОРА
============================ */

/* Контейнер сообщения — аватар слева, пузырь справа */
.msg.bot,
.msg.operator {
    display: flex;
    flex-direction: row;
    /* аватар -> пузырь */
    align-items: flex-end;
    /* по нижнему краю */
}

/* Аватар кругленький */
.avatar-bot {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    overflow: hidden;
    background: #ffffff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);

    flex-shrink: 0;
    margin-right: 8px;

    transform: translateY(4px);
    /* чуть опустить вниз */
}

/* Лого внутри круга — красиво, полностью, по центру */
.avatar-bot img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center;
    background: #ffffff;

    transform: scale(0.72);
    /* вот это делает магию */
    transform-origin: center;

    padding: 0;
    /* убираем лишнее */
}


/* Пузырь текста */
.msg.bot .msg-text,
.msg.operator .msg-text {
    max-width: 75%;
}

/* === Делаем шрифт пузырей 1-в-1 как у .chat-btn === */
.msg .msg-text,
.msg-time,
.chat-date {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
        Roboto, Helvetica, Arial, sans-serif !important;
}

/* ============================
   РЕЙТИНГ (ЗВЕЗДЫ)
============================ */
.rating-container {
    background: #fff;
    padding: 15px;
    border-radius: 14px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    text-align: center;
    margin: 10px 0;
    width: fit-content;
    border: 1px solid #f0f0f0;
    min-width: 220px;
}

.rating-title {
    font-size: 14px;
    color: #555;
    margin-bottom: 10px;
    font-weight: 600;
}

.stars-row {
    display: flex;
    gap: 5px;
    justify-content: center;
}

.star-btn {
    font-size: 28px;
    cursor: pointer;
    transition: transform 0.2s, color 0.2s;
    user-select: none;
    line-height: 1;
}

.star-btn:hover {
    transform: scale(1.2);
}

.star-btn.filled {
    color: #FFD700;
    /* Золотой */
    text-shadow: 0 2px 5px rgba(255, 215, 0, 0.4);
}

.star-btn.empty {
    color: #e0e0e0;
    /* Серый */
}

/* Сообщение "Спасибо" */
.rating-thanks {
    font-size: 15px;
    color: #2e7d32;
    font-weight: bold;
    padding: 10px;
    animation: fadeIn 0.5s;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* =========================================
   МОБИЛЬНАЯ АДАПТАЦИЯ (Responsive)
========================================= */

@media (max-width: 480px) {

    /* 1. Окно чата на весь экран */
    #ntrvl-chat-window {
        width: 100% !important;
        height: 100% !important;
        /* На старых браузерах */
        height: 100dvh !important;
        /* На новых (учитывает адресную строку) */
        bottom: 0 !important;
        right: 0 !important;
        border-radius: 0 !important;
        position: fixed !important;
        display: flex;
        flex-direction: column;
    }

    /* 2. Шапка чуть крупнее для пальцев */
    #ntrvl-chat-header {
        padding: 15px;
    }

    .chat-header-btn {
        font-size: 24px;
        /* Крупнее крестик и лупа */
        padding: 8px;
    }

    /* 3. Кнопка открытия (пульс) чуть меньше и сдвинута */
    #pulse-button {
        width: 60px;
        height: 60px;
        bottom: 20px;
        right: 20px;
    }

    /* 4. Поле ввода фиксируем */
    #ntrvl-chat-input-bar {
        padding: 15px 10px;
        /* Учет безопасных зон iPhone (челка/полоска снизу) */
        padding-bottom: env(safe-area-inset-bottom, 15px);
    }

    #ntrvl-chat-input {
        font-size: 16px;
        /* Чтобы iOS не зумил страницу при вводе */
    }

    /* 5. Кнопка прокрутки вниз повыше */
    .scroll-down-btn {
        bottom: 80px;
        right: 20px;
    }

    /* 6. Поиск */
    #ntrvl-chat-search-bar {
        padding: 15px;
    }

    /* Скрываем скроллбар body, когда чат открыт, чтобы не елозил фон */
    body.chat-open {
        overflow: hidden;
    }
}