/* ──────────────────────────────────────────
   Chat Widget — встроенный чат поддержки
   ────────────────────────────────────────── */

.cw-btn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #698cf0;
  border: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(105,140,240,.5);
  transition: transform .2s, box-shadow .2s;
  z-index: 9998;
  padding: 0;
}
.cw-btn:hover { transform: translateY(-2px) scale(1.05); box-shadow: 0 6px 24px rgba(105,140,240,.6); }
.cw-btn.is-open { background: #5a6a8a; }

/* Пульсирующее кольцо */
.cw-btn::before {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  background: rgba(105,140,240,.35);
  animation: cwPulse 2s ease-in-out infinite;
  z-index: -1;
}
.cw-btn.is-open::before { display: none; }

@keyframes cwPulse {
  0%   { transform: scale(1);   opacity: .7; }
  60%  { transform: scale(1.35); opacity: 0; }
  100% { transform: scale(1.35); opacity: 0; }
}

/* Появление при загрузке */
@keyframes cwBounceIn {
  0%   { transform: scale(0) translateY(20px); opacity: 0; }
  70%  { transform: scale(1.1) translateY(-4px); opacity: 1; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}
.cw-btn {
  animation: cwBounceIn .5s .8s cubic-bezier(.22,.68,0,1.2) both;
}
.cw-btn .cw-icon-open  { display: flex; }
.cw-btn .cw-icon-close { display: none; }
.cw-btn.is-open .cw-icon-open  { display: none; }
.cw-btn.is-open .cw-icon-close { display: flex; }

.cw-badge {
  position: absolute;
  top: -2px; right: -2px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #e05555;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid #fff;
  display: none;
}
.cw-badge.show { display: flex; }

.cw-window {
  position: fixed;
  bottom: 90px;
  right: 28px;
  width: 340px;
  height: 480px;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 12px 48px rgba(0,0,0,.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 9997;
  transform: scale(.85) translateY(20px);
  opacity: 0;
  pointer-events: none;
  transition: transform .25s cubic-bezier(.22,.68,0,1.2), opacity .2s;
}
.cw-window.is-open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: all;
}

/* Header */
.cw-header {
  background: #698cf0;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 0 0 auto;
}
.cw-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: rgba(255,255,255,.2);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; flex: 0 0 auto;
}
.cw-header-info { flex: 1; min-width: 0; }
.cw-header-name {
  font-weight: 700; font-size: 14px; color: #fff;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cw-header-status { font-size: 12px; color: rgba(255,255,255,.8); margin-top: 2px; }
.cw-status-dot {
  display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: #4cef90; margin-right: 5px; vertical-align: middle;
}
.cw-close-btn {
  background: 0; border: 0; cursor: pointer;
  color: rgba(255,255,255,.8); font-size: 20px; line-height: 1;
  padding: 4px; display: flex; align-items: center;
}

/* Pre-form */
.cw-preform {
  flex: 1; padding: 20px 16px;
  display: flex; flex-direction: column; gap: 12px;
  overflow-y: auto;
}
.cw-preform p {
  font-size: 14px; color: #555; line-height: 1.6; margin: 0;
}
.cw-preform input[type=text] {
  width: 100%; padding: 10px 14px;
  border: 1px solid #dde0f0; border-radius: 8px;
  font-size: 14px; font-family: inherit; outline: none;
  transition: border-color .2s;
}
.cw-preform input[type=text]:focus { border-color: #698cf0; }
.cw-start-btn {
  width: 100%; padding: 12px;
  background: #698cf0; color: #fff; border: 0;
  border-radius: 8px; font-size: 14px; font-weight: 700;
  font-family: inherit; cursor: pointer;
  transition: opacity .18s;
}
.cw-start-btn:hover { opacity: .9; }
.cw-start-btn:disabled { opacity: .5; cursor: default; }

/* Messages */
.cw-messages {
  flex: 1; overflow-y: auto; padding: 14px 14px 8px;
  display: flex; flex-direction: column; gap: 8px;
  background: #f6f7fb;
}
.cw-messages::-webkit-scrollbar { width: 3px; }
.cw-messages::-webkit-scrollbar-thumb { background: #d0d4e8; border-radius: 2px; }

.cw-msg { max-width: 82%; display: flex; flex-direction: column; gap: 2px; }
.cw-msg.in  { align-self: flex-start; }
.cw-msg.out { align-self: flex-end; }

.cw-sender { font-size: 11px; color: #8888aa; margin-left: 3px; }
.cw-msg.out .cw-sender { text-align: right; margin-right: 3px; margin-left: 0; }

.cw-bubble {
  padding: 9px 13px; border-radius: 12px;
  font-size: 14px; line-height: 1.5; word-break: break-word;
}
.cw-msg.in  .cw-bubble { background: #fff; border: 1px solid #e8eaf0; border-top-left-radius: 3px; color: #222; }
.cw-msg.out .cw-bubble { background: #698cf0; border-top-right-radius: 3px; color: #fff; }

.cw-time { font-size: 10px; color: #aaa; margin-left: 3px; }
.cw-msg.out .cw-time { text-align: right; margin-right: 3px; margin-left: 0; }

.cw-sys {
  align-self: center; font-size: 11px; color: #999;
  background: #eceef6; padding: 4px 10px; border-radius: 20px;
  text-align: center; max-width: 90%;
}

.cw-typing {
  align-self: flex-start; padding: 9px 13px;
  background: #fff; border: 1px solid #e8eaf0;
  border-radius: 12px; border-top-left-radius: 3px;
  display: none;
}
.cw-typing.show { display: flex; gap: 4px; align-items: center; }
.cw-dot {
  width: 6px; height: 6px; border-radius: 50%; background: #aaa;
  animation: cwbounce 1.2s ease-in-out infinite;
}
.cw-dot:nth-child(2) { animation-delay: .2s; }
.cw-dot:nth-child(3) { animation-delay: .4s; }
@keyframes cwbounce {
  0%,80%,100% { transform: translateY(0); }
  40%          { transform: translateY(-5px); }
}

/* Input */
.cw-input-area {
  flex: 0 0 auto; padding: 10px 12px;
  border-top: 1px solid #eceef6;
  display: flex; gap: 8px; align-items: flex-end;
  background: #fff;
}
.cw-textarea {
  flex: 1; border: 1px solid #dde0f0; border-radius: 18px;
  padding: 8px 14px; font-size: 14px; font-family: inherit;
  resize: none; max-height: 80px; outline: none;
  transition: border-color .2s; line-height: 1.5; color: #222;
  background: #f6f7fb;
}
.cw-textarea:focus { border-color: #698cf0; background: #fff; }
.cw-send {
  width: 38px; height: 38px; border-radius: 50%;
  background: #698cf0; border: 0; color: #fff;
  font-size: 16px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex: 0 0 auto; transition: transform .15s;
}
.cw-send:hover { transform: scale(1.08); }
.cw-send:disabled { opacity: .4; transform: none; cursor: default; }

/* Loading / Error states */
.cw-loader {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px;
}
.cw-spinner {
  width: 32px; height: 32px; border: 3px solid #e8eaf0;
  border-top-color: #698cf0; border-radius: 50%;
  animation: cwspin .7s linear infinite;
}
@keyframes cwspin { to { transform: rotate(360deg); } }
.cw-loader-text { font-size: 13px; color: #999; }



/* Меню выбора на мобильном */
.cw-menu {
  position: fixed;
  bottom: 88px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 9997;
  transform: scale(.85) translateY(20px);
  opacity: 0;
  pointer-events: none;
  transition: transform .25s cubic-bezier(.22,.68,0,1.2), opacity .2s;
}
.cw-menu.is-open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: all;
}
.cw-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fff;
  border: 0;
  border-radius: 24px;
  padding: 10px 18px 10px 12px;
  box-shadow: 0 4px 16px rgba(0,0,0,.15);
  cursor: pointer;
  font-family: "Montserrat", Arial, sans-serif;
  font-size: 14px;
  font-weight: 600;
  color: #222;
  white-space: nowrap;
  transition: transform .15s, box-shadow .15s;
}
.cw-menu-item:hover { transform: translateX(-3px); box-shadow: 0 6px 20px rgba(0,0,0,.2); }
.cw-menu-item-icon {
  width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; flex: 0 0 auto;
}
.cw-menu-item-icon.chat  { background: #698cf0; }
.cw-menu-item-icon.video { background: #4a6db5; }

/* На десктопе меню скрыто — кнопка сразу открывает чат */
@media (min-width: 769px) {
  .cw-menu { display: none !important; }
}
/* На мобильном — кнопка открывает меню, не чат */
@media (max-width: 768px) {
  .cw-window {
    display: none;
  }
  .cw-window.is-open {
    display: flex;
  }
}

@media (max-width: 768px) {
  /* Полноэкранный чат — как Telegram */
  .cw-window {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    width: 100%; height: 100%;
    border-radius: 0;
    display: none;
    flex-direction: column;
    background: #f0f2f5;
    z-index: 9997;
    overflow: hidden;
  }
  .cw-window.is-open { display: flex; }

  .cw-header {
    flex: 0 0 auto;
    border-radius: 0;
    padding-top: max(14px, env(safe-area-inset-top));
  }

  .cw-preform {
    flex: 1;
    overflow-y: auto;
    background: #f0f2f5;
    padding: 32px 24px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 14px;
  }

  .cw-loader { flex: 1; background: #f0f2f5; }

  .cw-messages {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: #f0f2f5;
    padding: 12px 12px 8px;
  }

  .cw-msg.in .cw-bubble {
    background: #fff;
    border: none;
    border-radius: 12px 12px 12px 3px;
    box-shadow: 0 1px 2px rgba(0,0,0,.1);
    color: #111;
  }
  .cw-msg.out .cw-bubble {
    border-radius: 12px 12px 3px 12px;
  }
  .cw-sys {
    background: rgba(0,0,0,.08);
    color: #666;
    border-radius: 12px;
    font-size: 11px;
  }

  .cw-input-area {
    flex: 0 0 auto;
    background: #fff;
    border-top: 1px solid #e0e3ed;
    padding: 8px 12px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    gap: 8px;
  }
  .cw-textarea {
    background: #f0f2f5 !important;
    border: none !important;
    border-radius: 20px !important;
    color: #111 !important;
    font-size: 16px !important; /* предотвращает зум на iOS */
    padding: 10px 16px !important;
  }
  .cw-textarea::placeholder { color: #aaa !important; }
  .cw-textarea:focus {
    background: #fff !important;
    outline: none !important;
  }

  .cw-btn {
    bottom: calc(16px + env(safe-area-inset-bottom));
    right: 14px;
    width: 52px;
    height: 52px;
  }
}

@media (max-width: 768px) {
  .cw-btn.is-open {
    display: none !important;
  }
  /* Кнопка закрытия в шапке — крупнее на мобильном */
  .cw-close-btn {
    font-size: 22px;
    padding: 8px;
    opacity: .9;
  }
  /* Поле ввода — не перекрывается кнопкой */
  .cw-input-area {
    padding-right: 12px !important;
  }
}


.cw-hint.show {
  opacity: 1;
  transform: translateX(0);
  pointer-events: auto;
  cursor: pointer;
}
@media (max-width: 768px) {
  .cw-hint {
    bottom: calc(92px + env(safe-area-inset-bottom));
    right: 14px;
    max-width: 168px;
    font-size: 12px;
    padding: 10px 14px;
  }
}

/* Hint — элегантный пузырь как у Intercom */
.cw-hint {
  position: fixed;
  bottom: 88px;
  right: 24px;
  max-width: 220px;
  background: #fff;
  border-radius: 16px 16px 4px 16px;
  box-shadow: 0 4px 24px rgba(0,0,0,.14), 0 1px 4px rgba(0,0,0,.08);
  padding: 14px 18px;
  z-index: 9996;
  opacity: 0;
  transform: scale(.85) translateY(8px);
  transform-origin: bottom right;
  transition: opacity .25s ease, transform .25s cubic-bezier(.22,.68,0,1.2);
  pointer-events: none;
  cursor: pointer;
}
.cw-hint.show {
  opacity: 1;
  transform: scale(1) translateY(0);
  pointer-events: auto;
}
.cw-hint-title {
  font-family: "Montserrat", Arial, sans-serif;
  font-size: 14px;
  font-weight: 700;
  color: #1a1a2e;
  margin-bottom: 4px;
}
.cw-hint-sub {
  font-family: "Montserrat", Arial, sans-serif;
  font-size: 12px;
  font-weight: 400;
  color: #777;
  line-height: 1.5;
}
.cw-hint-close {
  position: absolute;
  top: -8px;
  left: -8px;
  width: 22px; height: 22px;
  background: #888;
  border-radius: 50%;
  border: 2px solid #fff;
  color: #fff;
  font-size: 11px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  line-height: 1;
}
@media (max-width: 768px) {
  .cw-hint {
    bottom: calc(92px + env(safe-area-inset-bottom));
    right: 14px;
    max-width: 168px;
  }
  /* На мобильном не показываем hint на первом экране */
  body:not(.scrolled) .cw-hint {
    display: none !important;
  }
  .cw-hint-title {
    font-size: 13px;
    line-height: 1.35;
  }
  .cw-hint-sub {
    font-size: 11px;
    line-height: 1.45;
  }
}

/* ── ИИ-помощник ───────────────────────────────────────────── */
.cw-msg.in.ai .cw-bubble {
  background: #f0f4ff;
  border: 1px solid #c8d4f8;
  border-top-left-radius: 3px;
  color: #222;
}
.cw-msg.in.ai .cw-sender {
  color: #698cf0;
  font-weight: 600;
}
.cw-ai-disclaimer {
  font-size: 10px;
  color: #a0a8c8;
  margin-top: 3px;
  margin-left: 3px;
  font-style: italic;
}

/* ── Кнопки выбора действия ──────────────────────────────────── */
.cw-actions {
  padding: 12px 14px 14px;
  border-top: 1px solid #e8eaf0;
  background: #f8f9ff;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.cw-actions-label {
  font-size: 12px;
  color: #7a7f9a;
  text-align: center;
  margin-bottom: 2px;
}
.cw-action-btn {
  border: none;
  border-radius: 10px;
  padding: 11px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
  letter-spacing: .01em;
}
.cw-action-btn:active { transform: scale(.97); }
.cw-action-btn.chat {
  background: #698cf0;
  color: #fff;
}
.cw-action-btn.chat:hover { opacity: .88; }
.cw-action-btn.video {
  background: #fff;
  color: #698cf0;
  border: 2px solid #698cf0;
}
.cw-action-btn.video:hover { background: #f0f4ff; }
