/* ===== AI CHAT WIDGET ===== */
#chat-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  font-family: var(--font-base, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif);
  pointer-events: none;
}
#chat-widget .chat-window {
  pointer-events: auto;
}
/* Badge «непрочитанное» — на нашей иконке «Связаться» (contact-hub) */
.chat-toggle__badge {
  position: absolute;
  top: -3px;
  left: -3px;
  min-width: 21px;
  height: 21px;
  padding: 0 5px;
  border-radius: 11px;
  background: #e03131;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  line-height: 21px;
  text-align: center;
  border: 2px solid #fff;
  box-shadow: 0 2px 8px rgba(224, 49, 49, 0.35);
  display: none;
  pointer-events: none;
  box-sizing: border-box;
  z-index: 5;
}
.chat-toggle__badge.is-visible {
  display: block;
  animation: chatBadgePop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes chatBadgePop {
  0% { transform: scale(0.3); }
  70% { transform: scale(1.25); }
  100% { transform: scale(1); }
}
/* Покачивание-«звонок» — на нашей иконке «Связаться» */
#messengers-widget .contact-hub__toggle.is-ringing {
  animation: chatRing 1.1s ease-in-out infinite;
}
@keyframes chatRing {
  0%   { transform: rotate(0deg); }
  8%   { transform: rotate(-9deg); }
  16%  { transform: rotate(8deg); }
  24%  { transform: rotate(-7deg); }
  32%  { transform: rotate(5deg); }
  40%  { transform: rotate(-3deg); }
  50%  { transform: rotate(0deg); }
  100% { transform: rotate(0deg); }
}
/* Пузырь «Поговорим?» — рядом с нашей иконкой */
.chat-toggle__bubble {
  position: fixed;
  right: 92px;
  bottom: 34px;
  max-width: 200px;
  background: #fff;
  border-radius: 16px 16px 16px 4px;
  padding: 10px 14px;
  box-shadow: 0 10px 30px rgba(52, 58, 64, 0.16);
  font-size: 14px;
  font-weight: 600;
  color: var(--dark, #343a40);
  cursor: pointer;
  opacity: 0;
  transform: translateY(8px) scale(0.97);
  pointer-events: none;
  transition: opacity 0.35s ease, transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 9999;
}
.chat-toggle__bubble::after {
  content: '';
  position: absolute;
  right: -7px;
  bottom: 14px;
  width: 14px;
  height: 14px;
  background: #fff;
  transform: rotate(45deg);
  border-radius: 2px;
}
.chat-toggle__bubble.is-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
.chat-toggle__bubble-title { display: block; }
.chat-toggle__bubble-sub {
  display: block;
  font-weight: 400;
  font-size: 11.5px;
  color: var(--teal, #676458);
  margin-top: 3px;
}
/* Не звоним громко: reduced-motion — без анимации, но с пузырём */
@media (prefers-reduced-motion: reduce) {
  #messengers-widget .contact-hub__toggle.is-ringing { animation: none; }
  .chat-toggle__badge.is-visible { animation: none; }
  .chat-toggle__bubble { transition: opacity 0.2s ease; }
}
.chat-window {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 840px;
  max-width: calc(100vw - 48px);
  height: 1020px;
  max-height: calc(100vh - 80px);
  background: #fff;
  border-radius: var(--radius-md, 16px);
  box-shadow: 0 12px 48px rgba(52,58,64,.22);
  display: none;
  flex-direction: column;
  overflow: hidden;
  z-index: 10001;
}
.chat-window.open { display: flex; }
.chat-header {
  background: var(--teal, #676458);
  color: #fff;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.chat-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}
.chat-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255,255,255,.2);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.chat-avatar svg { width: 22px; height: 22px; }
.chat-title { font-weight: 700; font-size: 15px; }
.chat-subtitle { font-size: 12px; opacity: .85; }
.chat-close {
  background: transparent;
  border: none;
  color: #fff;
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}
.chat-close:hover { background: rgba(255,255,255,.15); }

.chat-font-toggle {
  display: flex;
  align-items: center;
  gap: 2px;
  background: rgba(255,255,255,0.15);
  border-radius: 8px;
  padding: 2px;
  margin-right: 8px;
}
.chat-font-btn {
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.6);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  transition: all 0.15s ease;
}
.chat-font-btn:hover {
  color: #fff;
  background: rgba(255,255,255,0.15);
}
.chat-font-btn.active {
  color: #fff;
  background: rgba(255,255,255,0.25);
}
.chat-disclaimer {
  background: #fff8e6;
  border-bottom: 1px solid #f0e6c8;
  padding: 10px 14px;
  font-size: 12px;
  color: #6b5c2e;
  line-height: 1.4;
}
.chat-disclaimer a { color: var(--teal); text-decoration: underline; }
.chat-messages {
  --chat-font-size: 16px;
  font-size: var(--chat-font-size);
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #f8f9fa;
}
.chat-message {
  max-width: 80%;
  padding: 14px 16px;
  border-radius: 14px;
  font-size: var(--chat-font-size, 16px);
  line-height: 1.55;
  word-wrap: break-word;
}
.chat-message.user {
  align-self: flex-end;
  background: var(--teal, #676458);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-message.bot {
  align-self: flex-start;
  background: #fff;
  color: var(--dark, #343a40);
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.chat-message.error {
  background: #ffe5e5;
  color: #8b1a1a;
}
.chat-message.typing {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 14px 16px;
}
.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #adb5bd;
  animation: chatTyping 1.4s infinite ease-in-out both;
}
.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }
@keyframes chatTyping {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}
.chat-cta {
  margin-top: 10px;
  display: inline-block;
  background: var(--teal);
  color: #fff;
  padding: 8px 14px;
  border-radius: 20px;
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
}
.chat-input-area {
  padding: 12px 14px;
  background: #fff;
  border-top: 1px solid #e9ecef;
  display: flex;
  gap: 8px;
}
.chat-input {
  flex: 1;
  border: 1px solid #dee2e6;
  border-radius: 20px;
  padding: 10px 14px;
  font-size: var(--chat-font-size, 16px);
  outline: none;
  resize: none;
  min-height: 40px;
  max-height: 100px;
}
.chat-input:focus { border-color: var(--teal); }
.chat-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--teal);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chat-send:disabled { opacity: .5; cursor: not-allowed; }
.chat-send svg { width: 18px; height: 18px; }
.chat-footer {
  padding: 6px 14px;
  font-size: 11px;
  color: #868e96;
  text-align: center;
  background: #fff;
  border-top: 1px solid #f1f3f5;
}
@media (max-width: 768px) {
  .chat-toggle__bubble {
    right: 80px;
    bottom: calc(100px + env(safe-area-inset-bottom, 0px));
    max-width: 170px;
    font-size: 13px;
    z-index: 970;
  }
  .chat-window {
    right: 12px;
    bottom: calc(72px + env(safe-area-inset-bottom, 0px));
    max-height: calc(100vh - 96px - env(safe-area-inset-bottom, 0px));
  }
}
@media (max-width: 480px) {
  .chat-window.open {
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
  }
}
