:root {
  --chat-primary: #d32f2f;
  --chat-bg: #2b2b2b;
  --chat-radius: 16px;
  --chat-min-width: 200px;
  --chat-max-width: 400px;
}

/* Контейнер */
#chat-widget-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 340px;
  min-width: var(--chat-min-width);
  max-width: var(--chat-max-width);
  height: 500px;
  max-height: calc(100vh - 40px);
  background: var(--chat-bg);
  border-radius: 12px;
  box-shadow: 0 6px 20px rgba(0,0,0,.2);
  display: none;
  flex-direction: column;
  z-index: 1000;
  overflow: hidden;
  transition: opacity .2s ease, transform .2s ease;
  opacity: 0;
  transform: scale(.95);
}
#chat-widget-container.show { display: flex; opacity: 1; transform: scale(1); }
#chat-widget-container.resizing { user-select: none; }

/* Ручки ресайза */
#chat-resize-handle-left {
  position: absolute; top: 0; left: 0; width: 8px; height: 100%;
  cursor: ew-resize; background: transparent; z-index: 1002;
}
#chat-resize-handle-top {
  position: absolute; top: 0; left: 8px; right: 8px; height: 8px;
  cursor: ns-resize; background: transparent; z-index: 1002;
}
#chat-resize-handle-corner {
  position: absolute; top: 0; left: 0; width: 14px; height: 14px;
  cursor: nwse-resize; background: transparent; z-index: 1003;
}
#chat-widget-container:hover #chat-resize-handle-left {
  background: linear-gradient(to right, rgba(255,255,255,.08), transparent);
}
#chat-widget-container:hover #chat-resize-handle-top {
  background: linear-gradient(to bottom, rgba(255,255,255,.08), transparent);
}
#chat-widget-container:hover #chat-resize-handle-corner {
  background: linear-gradient(135deg, rgba(255,255,255,.15) 0 49%, transparent 50% 100%);
}

/* Шапка */
#chat-widget-header {
  position: relative;
  background: #222; color: #fff;
  padding: 14px 16px;
  display: flex; justify-content: flex-end; align-items: center;
  font-weight: bold; font-size: 16px;
}
.chat-title { position: absolute; left: 50%; transform: translateX(-50%); font-size: 18px; display: flex; align-items: center; }
.chat-title img.chat-logo { margin-bottom: 4px; height: 23px; width: auto; }
.chat-header-buttons { display: flex; gap: 12px; }
.chat-btn-min, .chat-btn-close { background: transparent; color: white; border: none; font-size: 20px; cursor: pointer; }

/* Тело */
#chat-widget-body {
  flex: 1; padding: 14px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px;
  scrollbar-width: thin; scrollbar-color: #666 transparent;
}
#chat-widget-body p {
  font-size: 14px; max-width: 85%; padding: 10px 14px; border-radius: var(--chat-radius); word-break: break-word;
}
#chat-widget-body p.user {
  background: #999; color: white; align-self: flex-end;
  border-radius: var(--chat-radius) var(--chat-radius) 4px var(--chat-radius);
}
#chat-widget-body p.bot {
  background: #444; color: white; align-self: flex-start;
  border-radius: var(--chat-radius) var(--chat-radius) var(--chat-radius) 4px;
}

/* Лоадер */
#chat-loading {
  display: none;
  padding: 10px 14px;
  background: #1e1e1e;
  border-top: 1px solid #333;
  font-style: italic;
  font-size: 14px;
  color: white;
  align-items: center;
  gap: 10px;
}
.loader {
  width: 18px;
  height: 18px;
  display: inline-block;
  position: relative;
  color: #FFF;
  animation: rotation 1s linear infinite;
}
.loader::after,
.loader::before {
  content: '';
  position: absolute;
  width: 9px;
  height: 9px;
  top: 0;
  background-color: #FFF;
  border-radius: 50%;
  animation: scale50 1s infinite ease-in-out;
}
.loader::before {
  top: auto;
  bottom: 0;
  background-color: #FF3D00;
  animation-delay: 0.5s;
}
@keyframes rotation { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
@keyframes scale50 { 0%,100% { transform: scale(0); } 50% { transform: scale(1); } }

/* Футер */
#chat-widget-footer {
  background: #1e1e1e; padding: 10px; display: flex; border-top: 1px solid #333; gap: 8px;
}
#chat-widget-input {
  flex: 1; padding: 10px 12px; border-radius: 20px; border: none; font-size: 14px; background: white; color: black;
}
#chat-widget-send {
  background: var(--chat-primary); color: white; border: none; padding: 0 16px; border-radius: 20px; cursor: pointer;
}

/* Кнопка запуска и мини-чип */
.chat-launch-btn {
  position: fixed; bottom: 60px; right: 60px;
  background: #dedddd; color: white; border: none; padding: 6px 6px; border-radius: 12px;
  font-weight: bold; cursor: pointer; z-index: 1001;
}
.chat-minimized {
  position: fixed; bottom: 20px; right: 20px;
  background: #1e1e1e; color: #fff; padding: 6px 12px; border-radius: 12px; font-size: 14px; font-weight: 500;
  z-index: 1001; display: none; cursor: pointer;
}
.chat-indicator { margin-left: 6px; font-size: 14px; color: #f44336; }

/* Vorschläge */
.chat-suggestions { margin: 6px 0 10px; }
.chat-suggestions .section-title { font-weight: 700; color: #fff; margin: 8px 0 6px; font-size: 14px; }
.chat-suggestions .section-chip { display: inline-block; padding: 6px 12px; margin: 10px 0 6px; border: 3px solid #555; border-radius: 999px; background: #2a2a2a; color: #fff; font-weight: 700; font-size: 13px; line-height: 1.1; }
.suggestion-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 12px 12px; }
.suggestion-pill { background: #e3f2fd; color: #0b3954; border: 0; border-radius: 16px; padding: 6px 10px; font-size: 13px; cursor: pointer; }
.suggestions-dismiss { background: transparent; color: #bbb; border: 0; cursor: pointer; font-size: 16px; margin-left: 6px; line-height: 1; }


/* Кнопка обновления */
.chat-btn-refresh {
  background: transparent;
  color: white;
  border: none;
  font-size: 18px;
  cursor: pointer;
  transform: rotate(0deg);
  transition: transform 0.3s ease;
}
.chat-btn-refresh:hover { transform: rotate(90deg); }

/* === Фиксированный размер на мобильных === */
/* === Мобильная версия: фикс 350px + всегда справа === */


/* === Центрирование виджета на мобильных === */
:root {
  --chat-side-gap: 16px;   /* отступы слева/справа на мобилке */
}

@media (max-width: 768px) {
  #chat-widget-container {
    left: 50% !important;
    right: auto !important;
    width: calc(100vw - (var(--chat-side-gap) * 2)) !important;
    min-width: 0 !important;
    max-width: 100% !important;
    bottom: max(16px, env(safe-area-inset-bottom)) !important;

    height: 85vh !important;      /* <-- занимаем 85% экрана */
    max-height: none !important;  /* убираем ограничитель */

    transform: translateX(-50%) scale(.95) !important;
  }

  #chat-widget-container.show {
    transform: translateX(-50%) scale(1) !important;
  }

  /* кнопка запуска и чип по центру */
  .chat-launch-btn,
  .chat-minimized {
    left: 50% !important;
    right: auto !important;
    transform: translateX(-50%) !important;
    bottom: max(16px, env(safe-area-inset-bottom)) !important;
    z-index: 2147483647 !important;
  }

  #chat-resize-handle-left,
  #chat-resize-handle-top,
  #chat-resize-handle-corner {
    display: none !important;
  }
}


/* (необязательно) для очень узких экранов ещё чуть меньше отступ */
@media (max-width: 420px) {
  :root { --chat-side-gap: 12px; }
}

