/* Чат-виджет на сайте — серая градация */
.chat-widget {
  position: fixed;
  right: 20px;
  bottom: 90px;
  width: 330px;
  max-width: calc(100vw - 40px);
  height: 440px;
  max-height: calc(100vh - 130px);
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .28);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 10500;
}
.chat-widget.hidden { display: none; }

/* Ручка изменения размера (левый верхний угол) */
.chat-widget__resize {
  position: absolute;
  left: 2px;
  top: 2px;
  width: 14px;
  height: 14px;
  cursor: nwse-resize;
  z-index: 3;
  opacity: .45;
  background:
    linear-gradient(135deg, transparent 44%, #e0e0e0 44%, #e0e0e0 54%, transparent 54%),
    linear-gradient(135deg, transparent 24%, #e0e0e0 24%, #e0e0e0 34%, transparent 34%);
}
.chat-widget__resize:hover { opacity: 1; }

/* Шапка */
.chat-widget__header {
  background: #3f3f3f;
  color: #fff;
  padding: 9px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.chat-widget__person { display: flex; align-items: center; }
.chat-widget__avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .18);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-right: 9px;
  font-size: 16px;
  color: #e8e8e8;
}
.chat-widget__who { display: flex; flex-direction: column; line-height: 1.25; }
.chat-widget__name { font-weight: 600; font-size: 14px; }
.chat-widget__online { font-size: 11px; color: #c4c4c4; }
.chat-widget__dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #b8b8b8;
  margin-right: 4px;
  vertical-align: middle;
}
.chat-widget__close {
  background: none;
  border: 0;
  color: #e8e8e8;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  opacity: .85;
}
.chat-widget__close:hover { opacity: 1; color: #fff; }

/* Сообщения */
.chat-widget__messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  font-size: 13px;
  background: #f7f7f7;
  display: flex;
  flex-direction: column;
}
.chat-widget__msg {
  margin-bottom: 8px;
  padding: 7px 11px;
  border-radius: 12px;
  max-width: 85%;
  white-space: pre-wrap;
  word-wrap: break-word;
  align-self: flex-start;
  box-shadow: 0 1px 1px rgba(0, 0, 0, .06);
}
.chat-widget__msg--bot { background: #fff; color: #333; border: 1px solid #e2e2e2; white-space: normal; }
.chat-widget__msg--bot a { color: #444; text-decoration: underline; }
.chat-widget__msg--user { background: #d5d5d5; color: #222; align-self: flex-end; }
.chat-widget__msg--user a { color: #222; text-decoration: underline; }
.chat-widget__msg--operator { background: #e8e8e8; color: #333; }
.chat-widget__msg--operator a { color: #444; text-decoration: underline; }
.chat-widget__author { font-size: 12px; color: #666; font-weight: 600; }
.chat-widget__msg--error { background: #ededed; color: #2e2e2e; border: 1px solid #d0d0d0; }
.chat-widget__time { display: block; font-size: 10px; color: #999; margin-top: 3px; }
.chat-widget__msg--user .chat-widget__time { color: #6f6f6f; text-align: right; }

/* Markdown внутри сообщений */
.chat-widget__msg p { margin: 0 0 6px; }
.chat-widget__msg p:last-child { margin-bottom: 0; }
.chat-widget__msg ul, .chat-widget__msg ol { margin: 4px 0; padding-left: 18px; }
.chat-widget__msg li { margin: 0; }
.chat-widget__msg li > p { margin: 0; }
.chat-widget__msg table { border-collapse: collapse; width: 100%; margin: 4px 0; font-size: 12px; }
.chat-widget__msg th, .chat-widget__msg td { border: 1px solid #ddd; padding: 3px 6px; text-align: left; }
.chat-widget__msg code { background: #f0f0f0; padding: 0 3px; border-radius: 3px; }

/* «печатает…» */
.chat-widget__typing { display: inline-flex; align-items: center; gap: 4px; padding: 3px 0; }
.chat-widget__typing i {
  width: 6px; height: 6px; border-radius: 50%; background: #aaa;
  display: inline-block; animation: chat-typing 1s infinite ease-in-out;
}
.chat-widget__typing i:nth-child(2) { animation-delay: .15s; }
.chat-widget__typing i:nth-child(3) { animation-delay: .3s; }
@keyframes chat-typing {
  0%, 60%, 100% { opacity: .3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-2px); }
}

/* Подвал и форма */
.chat-widget__footer {
  border-top: 1px solid #e8e8e8;
  padding: 6px 10px;
  font-size: 12px;
  text-align: center;
  background: #fff;
}
.chat-widget__footer a { color: #555; text-decoration: underline; }

.chat-widget__form {
  display: flex;
  border-top: 1px solid #e8e8e8;
  padding: 8px;
  gap: 6px;
  align-items: flex-end;
  background: #fff;
}
.chat-widget__form textarea {
  flex: 1;
  min-width: 0;
  border: 1px solid #ccc;
  border-radius: 6px;
  padding: 7px 9px;
  font-size: 13px;
  resize: none;
  overflow-y: hidden;
  line-height: 1.3;
  font-family: inherit;
}
.chat-widget__form textarea:focus { outline: none; border-color: #888; }
.chat-widget__send {
  flex: 0 0 auto;
  width: 38px;
  height: 36px;
  border: 0;
  border-radius: 6px;
  background: #6c6c6c;
  color: #fff;
  font-size: 15px;
  cursor: pointer;
}
.chat-widget__send:hover { background: #555; }

/* Кнопка-тумблер */
.chat-widget__toggle {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #6c6c6c;
  color: #fff;
  border: 0;
  font-size: 22px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .3);
  cursor: pointer;
  z-index: 10500;
}
.chat-widget__toggle:hover { background: #555; }
.chat-widget__toggle .glyphicon { top: 2px; }

/* Бейдж новых сообщений на кнопке */
.chat-widget__badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 10px;
  background: #2e2e2e;
  color: #fff;
  font-size: 12px;
  line-height: 20px;
  text-align: center;
  font-weight: 600;
  box-shadow: 0 0 0 2px #fff;
}
.chat-widget__badge.hidden { display: none; }
