/* --- Стили для ИИ-виджета --- */
#ai-chat-widget {
  position: fixed; bottom: 20px; right: 20px; width: 350px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15); border-radius: 12px;
  background: #fff; display: none; flex-direction: column; z-index: 9999;
  overflow: hidden; border: 1px solid #e0e0e0;
}
#ai-chat-header {
  background: #007bff; /* или ваш градиент */
  color: #fff; 
  padding: 15px;
  font-weight: bold; 
  cursor: pointer; 
  display: flex; 
  justify-content: space-between;
  align-items: center; /* <-- Добавляем это, чтобы выровнять элементы по вертикали */
}
#ai-chat-body { padding: 15px; display: flex; flex-direction: column; height: 350px; }
/* Контейнер с сообщениями */
#ai-chat-log { 
  flex: 1; 
  overflow-y: auto; 
  margin-bottom: 10px; 
  font-size: 14px; 
  line-height: 1.4; 
  padding-right: 10px; /* Чуть больше отступа, чтобы текст не прилипал */
  
  /* Скрываем стандартный скроллбар для Firefox */
  scrollbar-width: thin;
  scrollbar-color: #ccc transparent;
}

/* Тонкий и аккуратный скроллбар для Chrome/Edge/Safari */
#ai-chat-log::-webkit-scrollbar {
  width: 6px; /* Ширина скроллбара */
}

#ai-chat-log::-webkit-scrollbar-track {
  background: transparent; /* Прозрачный фон дорожки */
  margin: 4px 0; /* Отступы сверху и снизу, чтобы он не прилипал к краям */
}

#ai-chat-log::-webkit-scrollbar-thumb {
  background: #d1d1d1; /* Цвет ползунка */
  border-radius: 10px; /* Закругление */
}

#ai-chat-log::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8; /* Цвет при наведении */
}
.ai-msg-user { text-align: right; margin-bottom: 10px; }
.ai-msg-user span { background: #e3f2fd; padding: 8px 12px; border-radius: 12px 12px 0 12px; display: inline-block; color: #000; }
.ai-msg-bot { text-align: left; margin-bottom: 10px; }
.ai-msg-bot span { background: #f1f1f1; padding: 8px 12px; border-radius: 12px 12px 12px 0; display: inline-block; color: #333; }
#ai-chat-input-wrapper { 
    display: flex; 
    border-top: 1px solid #eee; 
    padding-top: 10px; 
}

#ai-chat-input { 
    flex: 1; 
    padding: 8px 12px !important; /* Уменьшаем отступы и добавляем !important */
    border: 1px solid #ccc !important; 
    border-radius: 6px !important; 
    outline: none !important; 
    font-size: 14px !important; 
    height: 40px !important; /* Фиксируем высоту */
    box-sizing: border-box !important; 
}

#ai-chat-send { 
    padding: 0 15px !important; /* Убираем вертикальные отступы, оставляем горизонтальные */
    margin-left: 8px !important; 
    background: #007bff !important; 
    color: #fff !important; 
    border: none !important; 
    border-radius: 6px !important; 
    cursor: pointer !important; 
    font-weight: bold !important; 
    height: 40px !important; /* Фиксируем высоту такую же, как у инпута */
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 16px !important;
}

#ai-chat-send:disabled { 
    background: #ccc !important; 
    cursor: not-allowed !important; 
}


/* Обертка для кнопки и подписи */
#ai-chat-wrapper {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    align-items: center;
    gap: 10px; /* Расстояние между плашкой и кругом */
    z-index: 10000;
    cursor: pointer;
}

/* Постоянная подпись на синем фоне */
#ai-chat-label {
    background: #007bff;
    color: #fff;
    padding: 8px 16px;
    border-radius: 20px; /* Овальная плашка */
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-weight: 600;
    font-size: 14px;
    box-shadow: 0 4px 10px rgba(0, 123, 255, 0.3);
    white-space: nowrap;
}

/* Круглая кнопка */
#ai-chat-toggle {
    width: 56px;
    height: 56px;
    background: #007bff;
    color: #fff;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 4px 15px rgba(0, 123, 255, 0.4);
    transition: transform 0.2s ease;
    position: relative;
}

#ai-chat-toggle:hover {
    transform: scale(1.05);
}

/* Пульсация вокруг круглой кнопки */
#ai-chat-toggle::before {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: inherit;
    z-index: -1;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: scale(1); opacity: 0.6; }
    100% { transform: scale(1.5); opacity: 0; }
}

/* На мобильных скрываем плашку, оставляем только круг */
@media (max-width: 480px) {
    #ai-chat-label {
        display: none;
    }
    #ai-chat-toggle {
        width: 55px;
        height: 55px;
    }
}


/* Адаптация для мобильных устройств */
@media (max-width: 480px) {
  #ai-chat-widget {
    width: calc(100% - 30px) !important;
    left: 15px !important;
    right: 15px !important;
    bottom: 70px !important;
    border-radius: 12px !important;
  }

  /* === ДОБАВЛЯЕМ ЭТОТ БЛОК === */
  /* Перебиваем отступы для развернутого состояния */
  #ai-chat-widget.expanded {
    width: 100vw !important;
    height: 100vh !important;
    left: 0 !important;      /* Убираем отступ слева */
    right: 0 !important;     /* Убираем отступ справа */
    bottom: 0 !important;    /* Прижимаем к низу */
    top: 0 !important;       /* Прижимаем к верху */
    border-radius: 0 !important;
    max-width: none;
    max-height: none;
  }
  /* ========================= */

  #ai-chat-toggle {
    width: 55px !important;
    height: 55px !important;
  }
  
  /* Убедимся, что история чата не перекрывается */
  #ai-chat-log {
    padding-right: 10px !important;
  }
}

/* Сброс стилей для кнопок оценки внутри виджета */
#ai-chat-widget button[onclick^="rateAnswer"] {
    background: none !important;
    border: none !important;
    margin: 0 !important;
    box-shadow: none !important;
    outline: none !important;
    line-height: 1 !important; /* Чтобы эмодзи не прыгали по высоте */
    height: auto !important;
    width: auto !important;
}

/* Класс для развернутого состояния */
#ai-chat-widget.expanded {
    width: 90vw !important;
    height: 90vh !important;
    bottom: 5vh !important;
    right: 5vw !important;
    max-width: 1200px;
    max-height: 900px;
    display: flex !important;
    flex-direction: column !important;
    position: fixed;
    /* Убрали overflow: hidden, чтобы ничего не обрезалось */
}

/* Тело чата занимает всё оставшееся место */
#ai-chat-widget.expanded #ai-chat-body {
    flex: 1 !important;
    display: flex;
    flex-direction: column;
    padding: 15px;
    height: 100% !important; /* Растягиваем на всю доступную высоту */
    min-height: 0; /* Важно для корректной работы flex внутри flex */
}

/* Лог чата скроллится, но не выталкивает ввод */
#ai-chat-widget.expanded #ai-chat-log {
    flex: 1;
    overflow-y: auto;
    margin-bottom: 10px; /* Небольшой отступ от лога до ввода */
    min-height: 0; /* Важно для корректной работы flex */
}

/* Поле ввода в нормальном потоке, прижато к низу */
#ai-chat-widget.expanded #ai-chat-input-wrapper {
    flex-shrink: 0; /* Запрещаем сжиматься */
    display: flex;
    padding-top: 10px;
    border-top: 1px solid #eee;
    background: #fff;
    width: 100%;
}

/* Адаптив для мобильных */
@media (max-width: 480px) {
    #ai-chat-widget.expanded {
        width: 100vw !important;
        height: 100vh !important;
        bottom: 0 !important;
        right: 0 !important;
        border-radius: 0 !important;
        max-width: none;
        max-height: none;
    }
    
    /* Добавляем отступы для тела чата на мобильных */
    #ai-chat-widget.expanded #ai-chat-body {
        padding: 10px 15px !important; /* 10px сверху/снизу, 15px слева/справа */
    }
    
    /* Убеждаемся, что лог не прилипает к краям */
    #ai-chat-widget.expanded #ai-chat-log {
        padding-right: 5px !important; /* Отступ для скроллбара */
    }

    /* Поле ввода тоже с отступами */
    #ai-chat-widget.expanded #ai-chat-input-wrapper {
        padding-left: 15px !important;
        padding-right: 15px !important;
    }
}

#ai-chat-header > div:last-child {
    display: flex;
    align-items: center;
    gap: 10px; /* Расстояние между иконками */
}

/* Анимация вращения для прелоадера */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Контейнер для кнопок оценок */
.rating-container {
    display: flex;
    gap: 5px;
    margin-top: 5px; /* Уменьшили отступ сверху */
    padding-top: 3px;
    border-top: none !important; /* Убираем линию, если она не нужна */
    justify-content: flex-end; /* Прижимаем кнопки к правому краю */
}

/* Сами кнопки */
.rating-container button {
    font-size: 14px !important; /* Уменьшили размер */
    padding: 2px 4px !important;
    opacity: 0.6;
    line-height: 1;
    height: 20px !important;
    width: 20px !important;
}

.rating-container button:hover {
    opacity: 1;
}