/* --- Общая обёртка --- */
#kb-chat {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: 360px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
  z-index: 999999;
  box-shadow: 0 8px 30px rgba(2,6,23,0.25);
  border-radius: 12px;
  overflow: hidden;
  display: none; /* по умолчанию скрыто */
  flex-direction: column;
  animation: slideUp 0.3s ease;
}

  @keyframes slideUp {
    from { transform: translateY(40px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
  }

/* header */
#kb-chat .header {
  background: linear-gradient(90deg,#0b76ff,#0066d6);
  color: #fff;
  padding: 12px 14px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  cursor: pointer;
}
#kb-chat .header .title { font-weight:600; }
#kb-chat .header .badge { font-size:12px; opacity:0.9; background: rgba(255,255,255,0.12); padding:4px 8px; border-radius:8px; }

/* body */
#kb-body { background:#fff; display:flex; flex-direction:column; height:520px; }
/* messages area */
#kb-messages { padding:12px; flex:1; overflow:auto; }
.msg { margin:8px 0; max-width:86%; line-height:1.35; word-wrap:break-word; }
.msg.user { margin-left:auto; background:#e6f0ff; padding:8px 10px; border-radius:12px 12px 6px 12px; }
.msg.bot  { background:#f5f7fb; padding:8px 10px; border-radius:12px 12px 12px 6px; }
.msg .meta { font-size:11px; color:#666; margin-top:6px; }

/* input area */
#kb-input-row { display:flex; border-top:1px solid #eee; padding:10px; gap:8px; align-items:center; }
#kb-input { flex:1; padding:10px 12px; border-radius:10px; border:1px solid #e6e9ef; outline:none; font-size:14px; }
.kb-btn { background:#0b76ff; color:#fff; border:none; padding:10px 12px; border-radius:10px; cursor:pointer; font-weight:600; }
.kb-btn.secondary { background:#f3f6fb; color:#0b76ff; border:1px solid #e7eefb; font-weight:600; }

/* upload area (admin) */
#kb-upload { padding:10px; border-top:1px dashed #eee; font-size:13px; display:flex; gap:8px; align-items:center; }
#kb-upload input[type=file] { font-size:13px; }

/* sources panel */
.kb-sources { margin-top:8px; font-size:13px; color:#444; }
.kb-source { border-left:3px solid #edf2ff; padding:8px 10px; margin:6px 0; background:#fbfdff; border-radius:6px; cursor:pointer; }
.kb-source .s-title { font-weight:600; font-size:13px; }
.kb-source .s-snippet { font-size:12px; color:#555; margin-top:6px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }

/* small helpers */
.kb-note { font-size:12px; color:#666; padding:8px; text-align:center; }
.kb-hidden { display:none; }

/* compact mobile */
@media (max-width:420px) {
  #kb-chat { right: 8px; left: 8px; width: auto; bottom: 12px; }
  #kb-body { height: 420px; }
}

@media (min-width: 768px) {
    #kb-chat {
        width: 420px;
    }
}
@media (min-width: 1200px) {
    #kb-chat {
        width: 500px;
    }
}

/* typing indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 24px;
}

.typing-indicator span {
  width: 6px;
  height: 6px;
  background-color: #999;
  border-radius: 50%;
  animation: blink 1.4s infinite both;
}

.typing-indicator span:nth-child(1) {
  animation-delay: 0s;
}
.typing-indicator span:nth-child(2) {
  animation-delay: 0.2s;
}
.typing-indicator span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes blink {
  0% {
    opacity: 0.2;
    transform: translateY(0);
  }
  20% {
    opacity: 1;
    transform: translateY(-3px);
  }
  100% {
    opacity: 0.2;
    transform: translateY(0);
  }
}

  /* Контейнер для всего виджета */
  #chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
  }

  /* Кнопка открытия/сворачивания */
  #chat-toggle {
    width: 60px;
    height: 60px;
    background-color: #007bff;
    border-radius: 50%;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
    border: none;
    cursor: pointer;
    color: white;
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: pulse 2s infinite;
    transition: background-color 0.3s ease;
  }

  #chat-toggle:hover {
    background-color: #0056b3;
  }

  /* Анимация пульсации */
  @keyframes pulse {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(0,123,255, 0.4); }
    70% { transform: scale(1.1); box-shadow: 0 0 0 10px rgba(0,123,255, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(0,123,255, 0); }
  }

  #kb-toggle button {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
  }

  .timestamp {
    font-size: 10px;
    opacity: 0.6;
    margin-top: 2px;
    text-align: right;
    -moz-user-select: none; /* Для Firefox */
    -webkit-user-select: none; /* Для Chrome, Safari, Opera */
    -ms-user-select: none; /* Для Internet Explorer 10+ */
    user-select: none;
  }