.suvvy-chat-root { position: relative; z-index: 100; }

/* Мобильные устройства - значительно снижаем z-index чтобы не перекрывать мобильное меню */
@media (max-width: 768px) {
  .suvvy-chat-root { z-index: 50; }
  .suvvy-fab { z-index: 50; }
  .suvvy-chat-panel { z-index: 50; }
}

/* Специальные правила для темы Impreza */
.impreza-theme .suvvy-chat-root,
.theme-impreza .suvvy-chat-root,
body.impreza .suvvy-chat-root,
body[class*="impreza"] .suvvy-chat-root {
  z-index: 50;
}

@media (max-width: 768px) {
  .impreza-theme .suvvy-fab,
  .theme-impreza .suvvy-fab,
  body.impreza .suvvy-fab,
  body[class*="impreza"] .suvvy-fab,
  .impreza-theme .suvvy-chat-panel,
  .theme-impreza .suvvy-chat-panel,
  body.impreza .suvvy-chat-panel,
  body[class*="impreza"] .suvvy-chat-panel {
    z-index: 50;
  }
}

.suvvy-fab { position: fixed; bottom: 18px; right: 18px; width: 52px; height: 52px; border-radius: 50%; color:#fff; border:none; font-size:24px; cursor:pointer; box-shadow: 0 10px 30px rgba(0,0,0,.2); }
.suvvy-fab.left { left: 18px; right: auto; }
.suvvy-chat-panel { position: fixed; bottom: 80px; right: 18px; width: 600px; max-width: calc(100% - 36px); background: var(--suvvy-bg, #f8fafc); border-radius: 12px; overflow: hidden; box-shadow: 0 10px 40px rgba(0,0,0,.15); }
.suvvy-chat-panel.embedded { position: relative; bottom: auto; right: auto; width: 100%; max-width: none; box-shadow: none; }
.suvvy-chat-header { color:#fff; padding: 10px 14px; display:flex; align-items:center; justify-content:space-between; }
.suvvy-chat-header .title { font-weight:700; }
.suvvy-chat-header .header-actions { display: flex; align-items: center; gap: 8px; }
.suvvy-chat-header .suvvy-chat-search { 
  background: rgba(255,255,255,0.2); 
  border: none; 
  color: #fff; 
  padding: 6px 8px; 
  border-radius: 4px; 
  cursor: pointer; 
  font-size: 14px;
  transition: background-color 0.2s ease;
}
.suvvy-chat-header .suvvy-chat-search:hover { background: rgba(255,255,255,0.3); }

/* Иконка поиска в заголовке */
.suvvy-chat-header .suvvy-chat-search::before {
  content: '🔍';
  font-size: 14px;
  line-height: 1;
}

/* Иконка поиска в inline режиме */
.suvvy-chat-search-inline::before {
  content: '🔍';
  font-size: 16px;
  line-height: 1;
}
.suvvy-chat-messages { 
    padding: 0; 
    height: 360px; 
    overflow: auto; 
    background: var(--suvvy-bg, #ffffff); 
    scroll-behavior: smooth;
    display: flex;
    flex-direction: column;
}
.suvvy-chat-panel.embedded .suvvy-chat-messages { 
    height: var(--suvvy-embed-messages-height, 420px); 
}
.suvvy-chat-input { 
    display: flex; 
    gap: 0; 
    padding: 16px; 
    background: var(--suvvy-bg, #ffffff); 
    align-items: center; 
    border-top: 1px solid var(--suvvy-border, #e5e7eb);
    transition: border-radius 0.2s ease;
}
.composer-inner {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    background: var(--suvvy-input-bg, #f9f9f9);
    border: 1px solid var(--suvvy-border, #e5e7eb);
    border-radius: 20px;
    padding: 8px 16px;
    min-height: 48px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, border-radius 0.2s ease;
}
.composer-inner:focus-within {
    border-color: #10a37f;
    box-shadow: 0 0 0 2px rgba(16, 163, 127, 0.1);
}
.input-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    min-height: 20px;
}
.suvvy-chat-input textarea { 
    flex: 1; 
    min-height: 20px; 
    max-height: 120px; 
    resize: none; 
    border: none; 
    border-radius: 0; 
    padding: 4px 0; 
    outline: none; 
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 16px;
    line-height: 1.4;
    background: transparent;
    color: var(--suvvy-text, #374151);
}
.suvvy-chat-input textarea::placeholder {
    color: #9ca3af;
}
.suvvy-chat-input button { 
    min-width: 32px; 
    height: 32px;
    color: #6b7280; 
    border: none; 
    border-radius: 50%; 
    padding: 0; 
    cursor: pointer; 
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    transition: background-color 0.2s ease, color 0.2s ease;
}
.suvvy-chat-input button:hover {
    background: #e5e7eb;
    color: #374151;
}

/* Стили для файлов */
.suvvy-file-preview {
    padding: 8px 16px;
    background: #f9f9f9;
    border-top: 1px solid #e5e7eb;
}

.suvvy-file-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
}

.suvvy-file-name {
    font-size: 14px;
    color: #374151;
    flex: 1;
    margin-right: 8px;
}

.suvvy-file-remove {
    background: #ef4444;
    color: white;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.suvvy-file-remove:hover {
    background: #dc2626;
}

/* Стили для файлов в сообщениях */
.suvvy-file-attachment {
    margin: 8px 0;
    padding: 8px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 8px;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.file-preview {
    display: flex;
    align-items: center;
    gap: 8px;
}

.file-icon {
    font-size: 16px;
}

.file-name {
    font-weight: 500;
    color: #374151;
}

.file-size {
    font-size: 12px;
    color: #6b7280;
    margin-left: auto;
}

/* Счетчик оставшихся сообщений */
.suvvy-remaining-counter {
    padding: 8px 16px;
    background: #fef3c7;
    border: 1px solid #f59e0b;
    border-radius: 8px;
    margin: 8px 16px;
    text-align: center;
}

.suvvy-remaining-counter span {
    font-size: 14px;
    color: #92400e;
    font-weight: 500;
}
.suvvy-chat-mic {
    font-size: 18px;
    font-weight: 400;
}
#suvvy-chat-send {
    background: var(--suvvy-accent, #10a37f);
    color: #fff;
    min-width: 32px;
    height: 32px;
    border-radius: 50%;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease, transform 0.1s ease;
}
#suvvy-chat-send:hover {
    background: var(--suvvy-accent-hover, #0d8a6b);
    transform: scale(1.05);
}
#suvvy-chat-send:active {
    transform: scale(0.95);
}
#suvvy-chat-send::after {
    content: '➤';
    font-size: 16px;
    line-height: 1;
    color: #fff;
}

/* Подсказка под полем ввода */
.suvvy-chat-hint {
    font-size: 11px;
    color: var(--suvvy-text, #6b7280);
    text-align: center;
    margin: 8px 16px 0 16px;
    padding: 4px 8px;
    opacity: 0.7;
    transition: opacity 0.2s ease;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    position: relative;
    z-index: 1;
}

.suvvy-chat-hint:hover {
    opacity: 1;
}

/* Скрываем подсказку на мобильных устройствах */
@media (max-width: 768px) {
    .suvvy-chat-hint .suvvy-hint-text {
        display: none !important;
    }
}

/* Стили для ссылки на политику конфиденциальности */
.suvvy-privacy-link {
    margin-top: 4px;
}

.suvvy-privacy-link a {
    font-size: 11px;
    color: var(--suvvy-text, #6b7280);
    text-decoration: none;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    transition: opacity 0.2s ease;
}

.suvvy-privacy-link a:hover {
    opacity: 0.8;
}

/* Состояния ошибок */
.suvvy-chat-msg.error .message-content {
    border: 1px solid #ef4444;
    background: #fef2f2;
}

.suvvy-chat-msg.error .status {
    color: #ef4444;
    font-weight: 500;
}

/* Индикатор соединения */
.suvvy-connection-status {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    user-select: none;
    pointer-events: none;
}

/* Анимация для статуса */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.suvvy-connection-status[style*="reconnecting"] {
    animation: pulse 1.5s infinite;
}

.suvvy-chat-msg { 
    display: flex; 
    margin: 0;
    padding: 16px 20px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    word-wrap: break-word;
    align-items: flex-start;
    gap: 16px;
    border-bottom: 1px solid #f0f0f0;
}
.suvvy-chat-msg:last-child {
    border-bottom: none;
}
.suvvy-chat-msg.in { 
    background: var(--suvvy-bg, #ffffff);
    flex-direction: row;
}
.suvvy-chat-msg.out { 
    background: var(--suvvy-bg, #ffffff);
    flex-direction: row-reverse;
}
.suvvy-chat-msg.system { 
    background: #fef3c7; 
    border: 1px solid #f59e0b;
    text-align: center;
    font-style: italic;
    justify-content: center;
}
.suvvy-chat-msg .message-content {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 18px;
    background: var(--suvvy-ai-msg-bg, #f7f7f8);
    color: var(--suvvy-text, #374151);
}
.suvvy-chat-msg.out .message-content {
    background: var(--suvvy-user-msg-bg, #10a37f);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.suvvy-chat-msg.in .message-content {
    background: var(--suvvy-ai-msg-bg, #f7f7f8);
    color: var(--suvvy-text, #374151);
    border-bottom-left-radius: 4px;
}
.suvvy-chat-msg .status { 
    font-size:11px; 
    opacity:.7; 
    margin-left:8px; 
    vertical-align:bottom;
    display: inline-block;
    color: rgba(255, 255, 255, 0.7);
}

/* Таймштампы сообщений */
.suvvy-chat-msg .message-timestamp {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.7);
    margin-left: 8px;
    margin-top: 4px;
    opacity: 0.8;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    display: block;
    text-align: right;
    line-height: 1;
}
.suvvy-chat-msg.in .message-timestamp {
    color: var(--suvvy-ai-timestamp, #9ca3af);
    text-align: right;
    margin-left: 0;
    margin-right: 8px;
}

/* Аватарка ИИ */
.suvvy-chat-msg .avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--suvvy-accent, #10a37f);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    flex-shrink: 0;
    overflow: hidden;
}

.suvvy-chat-msg .avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

/* Стили для поиска */
.suvvy-search-bar {
    background: var(--suvvy-bg, #ffffff);
    border-bottom: 1px solid var(--suvvy-border, #e5e7eb);
    padding: 12px 16px;
}

.search-input-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

#suvvy-search-input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--suvvy-border, #e5e7eb);
    border-radius: 6px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s ease;
}

#suvvy-search-input:focus {
    border-color: var(--suvvy-accent, #10a37f);
    box-shadow: 0 0 0 2px rgba(16, 163, 127, 0.1);
}

.search-clear {
  background: #6b7280;
  color: white;
  border: none;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s ease;
}

.search-clear:hover {
  background: #374151;
}

.search-results-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    color: var(--suvvy-text, #6b7280);
}

.search-navigation {
    display: flex;
    gap: 4px;
}

.search-prev, .search-next {
    background: var(--suvvy-accent, #10a37f);
    color: white;
    border: none;
    border-radius: 4px;
    width: 24px;
    height: 24px;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease;
}

.search-prev:hover, .search-next:hover {
    background: var(--suvvy-accent-hover, #0d8a6b);
}

.search-prev:disabled, .search-next:disabled {
    background: #d1d5db;
    cursor: not-allowed;
}

/* Подсветка результатов поиска */
.search-highlight {
    background: #fef08a;
    color: #92400e;
    padding: 1px 2px;
    border-radius: 2px;
    font-weight: 500;
}

.suvvy-chat-msg.search-active {
    background: rgba(16, 163, 127, 0.1);
    border-left: 3px solid var(--suvvy-accent, #10a37f);
}
.suvvy-chat-msg.out.delivered .status::before { content:'✓✓'; margin-right:2px; }
.suvvy-chat-msg strong { font-weight:700; }
.suvvy-chat-msg em { font-style:italic; }
.suvvy-chat-msg s { text-decoration: line-through; }
.suvvy-chat-msg pre { background:#0f172a; color:#e5e7eb; padding:10px 12px; border-radius:10px; overflow:auto; }
.suvvy-chat-msg code { background:rgba(0,0,0,.06); padding:2px 6px; border-radius:6px; }
.suvvy-chat-typing { display:block; margin:8px 0; }
.suvvy-chat-typing .bubble{ display:inline-flex; align-items:center; gap:4px; background:#e9ecff; padding:8px 12px; border-radius:12px; }
.suvvy-chat-typing .dot{ width:6px; height:6px; border-radius:50%; background:#7c85ff; opacity:.6; animation:bounce 1.2s infinite ease-in-out; }
.suvvy-chat-typing .dot:nth-child(2){ animation-delay:.2s; } .suvvy-chat-typing .dot:nth-child(3){ animation-delay:.4s; }
@keyframes bounce{ 0%,80%,100%{ transform:scale(.8); opacity:.4;} 40%{ transform:scale(1); opacity:1;} }

/* Дополнительные стили для мобильных устройств */
@media (max-width: 768px) {
  /* Увеличиваем отступы от краев экрана */
  .suvvy-fab { 
    bottom: 20px; 
    right: 20px; 
    width: 56px; 
    height: 56px; 
    font-size: 26px;
  }
  .suvvy-fab.left { 
    left: 20px; 
    right: auto; 
  }
  
  /* Панель чата на мобильных */
  .suvvy-chat-panel { 
    bottom: 90px; 
    right: 10px; 
    left: 10px;
    width: auto;
    max-width: none;
    max-height: calc(100vh - 120px);
  }
  
  /* Уменьшаем высоту сообщений на мобильных */
  .suvvy-chat-messages { 
    height: 300px; 
    max-height: calc(100vh - 200px);
  }
  
  /* Адаптивная высота для встроенного чата на мобильных */
  .suvvy-chat-panel.embedded .suvvy-chat-messages { 
    height: var(--suvvy-embed-messages-height, 300px) !important;
    max-height: calc(100vh - 200px) !important;
  }
  
  /* Дополнительные ограничения для встроенного чата на мобильных */
  .suvvy-chat-panel.embedded {
    max-height: 700px !important;
  }
  
  /* Адаптируем размеры сообщений */
  .suvvy-chat-msg { 
    padding: 12px 16px;
    font-size: 15px;
  }
  
  .suvvy-chat-msg .message-content {
    max-width: 85%;
    padding: 10px 14px;
  }
  
  /* Адаптируем поле ввода */
  .suvvy-chat-input { 
    padding: 12px; 
  }
  
  .composer-inner {
    padding: 6px 12px;
    min-height: 44px;
  }
  
  .suvvy-chat-input textarea {
    font-size: 16px; /* Предотвращает зум на iOS */
  }
}

/* Очень маленькие экраны */
@media (max-width: 480px) {
  .suvvy-fab { 
    bottom: 15px; 
    right: 15px; 
    width: 50px; 
    height: 50px; 
    font-size: 22px;
  }
  .suvvy-fab.left { 
    left: 15px; 
    right: auto; 
  }
  
  .suvvy-chat-panel { 
    bottom: 80px; 
    right: 8px; 
    left: 8px;
    max-height: calc(100vh - 100px);
  }
  
  .suvvy-chat-messages { 
    height: 250px; 
    max-height: calc(100vh - 180px);
  }
  
  .suvvy-chat-msg { 
    padding: 10px 12px;
    font-size: 14px;
  }
  
  .suvvy-chat-msg .message-content {
    max-width: 90%;
    padding: 8px 12px;
  }
}

/* Специальные правила для совместимости с мобильными меню */
@media (max-width: 768px) {
  /* Обеспечиваем, что чат не перекрывает стандартные мобильные меню */
  .suvvy-chat-root,
  .suvvy-fab,
  .suvvy-chat-panel {
    /* Снижаем z-index чтобы не перекрывать мобильные меню тем */
    z-index: 50 !important;
  }
  
  /* Дополнительная защита от перекрытия навигации */
  .suvvy-fab {
    /* Увеличиваем отступ от верхней части экрана */
    top: auto;
    /* Убеждаемся, что кнопка не перекрывает шапку */
    margin-top: 80px;
    bottom: 20px;
  }
  
  /* Если мобильное меню открыто, скрываем чат */
  body.menu-open .suvvy-chat-root,
  body.mobile-menu-open .suvvy-chat-root,
  body.nav-open .suvvy-chat-root,
  body.burger-menu-open .suvvy-chat-root,
  /* Специально для темы Impreza */
  body.impreza.menu-open .suvvy-chat-root,
  body[class*="impreza"].menu-open .suvvy-chat-root,
  body.nav-open .suvvy-chat-root,
  body.mobile-menu-open .suvvy-chat-root {
    display: none !important;
  }
  
  /* Альтернативные селекторы для популярных тем */
  .mobile-menu-open .suvvy-chat-root,
  .menu-opened .suvvy-chat-root,
  .navigation-open .suvvy-chat-root,
  .sidebar-open .suvvy-chat-root {
    display: none !important;
  }
}

/* Дополнительные правила для предотвращения конфликтов с мобильными меню */
@media (max-width: 1024px) {
  /* На планшетах тоже может быть мобильное меню */
  .suvvy-chat-root { z-index: 50; }
  .suvvy-fab { z-index: 50; }
  .suvvy-chat-panel { z-index: 50; }
}

/* Дополнительные правила для фиксированных шапок */
@media (max-width: 768px) {
  /* Если шапка фиксированная, добавляем отступ сверху */
  body.has-fixed-header .suvvy-fab,
  body.header-fixed .suvvy-fab,
  body[class*="fixed-header"] .suvvy-fab {
    top: 80px !important;
    bottom: auto !important;
  }
  
  /* Для темы Impreza с фиксированной шапкой */
  body.impreza .suvvy-fab,
  body[class*="impreza"] .suvvy-fab {
    top: 70px !important;
    bottom: auto !important;
  }
  
  /* Панель чата тоже сдвигаем */
  body.has-fixed-header .suvvy-chat-panel,
  body.header-fixed .suvvy-chat-panel,
  body[class*="fixed-header"] .suvvy-chat-panel,
  body.impreza .suvvy-chat-panel,
  body[class*="impreza"] .suvvy-chat-panel {
    bottom: auto !important;
    top: 140px !important;
    max-height: calc(100vh - 160px) !important;
  }
}
