/* ================================
   Chat Widget — NIVEL HR
   ================================ */

:root {
  --cw-primary: #2F6FED;
  --cw-primary-dark: #1a5cd1;
  --cw-online: #22c55e;
  --cw-shadow: 0 8px 40px rgba(0, 0, 0, 0.18);
  --cw-radius: 16px;
}

/* ---- Toggle Button ---- */
.cw-toggle {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--cw-primary) 0%, var(--cw-primary-dark) 100%);
  border: none;
  cursor: pointer;
  z-index: 9990;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 22px rgba(47, 111, 237, 0.45);
  transition: transform 0.25s ease, box-shadow 0.25s ease;
  padding: 0;
  overflow: visible;
}

.cw-toggle:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(47, 111, 237, 0.55);
}

.cw-toggle__avatar {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 700;
  color: #fff;
  line-height: 1;
  overflow: hidden;
}

.cw-toggle__avatar img,
.cw-toggle__avatar .cw-avatar-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

/* Online dot on toggle */
.cw-toggle .cw-online-dot {
  position: absolute;
  bottom: 3px;
  right: 3px;
  width: 14px;
  height: 14px;
  background: var(--cw-online);
  border-radius: 50%;
  border: 2px solid #fff;
  z-index: 1;
}

.cw-toggle .cw-online-dot::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  background: var(--cw-online);
  opacity: 0.35;
  animation: cwPulse 2s ease-in-out infinite;
}

@keyframes cwPulse {
  0%, 100% { transform: scale(1); opacity: 0.35; }
  50%       { transform: scale(1.7); opacity: 0; }
}

/* ---- Notification Bubble ---- */
.cw-bubble {
  position: fixed;
  bottom: 92px;
  right: 20px;
  max-width: 230px;
  background: #fff;
  border-radius: 12px 12px 4px 12px;
  padding: 12px 36px 12px 14px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  font-size: 14px;
  line-height: 1.5;
  color: #1e293b;
  z-index: 9991;
  animation: cwBubbleIn 0.3s ease;
  cursor: pointer;
}

@keyframes cwBubbleIn {
  from { opacity: 0; transform: translateY(10px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0)    scale(1);    }
}

.cw-bubble__close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 22px;
  height: 22px;
  background: none;
  border: none;
  cursor: pointer;
  color: #94a3b8;
  font-size: 14px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  padding: 0;
  transition: background 0.15s, color 0.15s;
}

.cw-bubble__close:hover {
  background: #f1f5f9;
  color: #475569;
}

/* ---- Chat Window ---- */
.cw-window {
  position: fixed;
  bottom: 92px;
  right: 20px;
  width: 360px;
  height: 500px;
  background: #fff;
  border-radius: var(--cw-radius);
  box-shadow: var(--cw-shadow);
  z-index: 9992;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: cwWindowIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes cwWindowIn {
  from { opacity: 0; transform: translateY(20px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0)    scale(1);    }
}

/* ---- Header ---- */
.cw-header {
  background: linear-gradient(135deg, var(--cw-primary) 0%, var(--cw-primary-dark) 100%);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.cw-header__avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.3);
}

.cw-header__avatar {
  position: relative;
}

.cw-header__avatar .cw-avatar-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.cw-header__info {
  flex: 1;
  min-width: 0;
}

.cw-header__name {
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  line-height: 1.2;
}

.cw-header__status {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.8);
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 3px;
}

.cw-header__status-dot {
  width: 7px;
  height: 7px;
  background: #86efac;
  border-radius: 50%;
  flex-shrink: 0;
}

.cw-header__close {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #fff;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s;
  padding: 0;
}

.cw-header__close:hover {
  background: rgba(255, 255, 255, 0.28);
}

/* ---- Messages ---- */
.cw-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #f8fafc;
  scroll-behavior: smooth;
}

.cw-messages::-webkit-scrollbar { width: 4px; }
.cw-messages::-webkit-scrollbar-track { background: transparent; }
.cw-messages::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 2px; }

.cw-msg {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  max-width: 88%;
}

.cw-msg--manager { align-self: flex-start; }
.cw-msg--user    { align-self: flex-end; flex-direction: row-reverse; }

.cw-msg__avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--cw-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  overflow: hidden;
  position: relative;
}

.cw-msg__avatar .cw-avatar-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.cw-msg--user .cw-msg__avatar {
  background: #64748b;
  font-size: 10px;
}

.cw-msg__bubble {
  background: #fff;
  border-radius: 12px 12px 12px 4px;
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.55;
  color: #1e293b;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.07);
  word-break: break-word;
}

.cw-msg--user .cw-msg__bubble {
  background: var(--cw-primary);
  color: #fff;
  border-radius: 12px 12px 4px 12px;
  box-shadow: 0 2px 8px rgba(47, 111, 237, 0.25);
}

/* ---- Typing indicator ---- */
.cw-typing {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  align-self: flex-start;
}

.cw-typing__bubble {
  background: #fff;
  border-radius: 12px 12px 12px 4px;
  padding: 12px 14px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.07);
  display: flex;
  gap: 4px;
  align-items: center;
}

.cw-typing__dot {
  width: 6px;
  height: 6px;
  background: #94a3b8;
  border-radius: 50%;
  animation: cwTyping 1.4s ease-in-out infinite;
}

.cw-typing__dot:nth-child(2) { animation-delay: 0.2s; }
.cw-typing__dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes cwTyping {
  0%, 60%, 100% { transform: translateY(0);   opacity: 0.4; }
  30%           { transform: translateY(-5px); opacity: 1;   }
}

/* ---- Choice buttons ---- */
.cw-choices {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 2px;
  padding-left: 36px;
}

.cw-choice-btn {
  background: #fff;
  border: 1.5px solid var(--cw-primary);
  color: var(--cw-primary);
  border-radius: 20px;
  padding: 7px 15px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  line-height: 1.3;
}

.cw-choice-btn:hover,
.cw-choice-btn.is-selected {
  background: var(--cw-primary);
  color: #fff;
}

/* ---- Action buttons (Telegram / Phone) ---- */
.cw-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-left: 36px;
  margin-top: 4px;
}

.cw-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  border: none;
  transition: all 0.2s;
  font-family: inherit;
  line-height: 1.3;
}

.cw-action-btn--tg {
  background: #0088cc;
  color: #fff;
}

.cw-action-btn--tg:hover {
  background: #0077b5;
  color: #fff;
}

.cw-action-btn--phone {
  background: #f1f5f9;
  color: #1e293b;
  border: 1px solid #e2e8f0;
}

.cw-action-btn--phone:hover {
  background: #e2e8f0;
}

/* ---- Quick replies in footer ---- */
.cw-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 12px 6px;
  border-top: 1px solid #f1f5f9;
}

.cw-quick-btn {
  background: #fff;
  border: 1.5px solid var(--cw-primary);
  color: var(--cw-primary);
  border-radius: 18px;
  padding: 6px 13px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  line-height: 1.3;
  white-space: nowrap;
}

.cw-quick-btn:hover {
  background: var(--cw-primary);
  color: #fff;
}

/* ---- Input footer ---- */
.cw-footer {
  padding: 8px 12px 12px;
  background: #fff;
  flex-shrink: 0;
  border-top: 1px solid #f1f5f9;
}

/* Строка с подсказкой и кнопкой «Назад» */
.cw-footer-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 2px 0 6px;
}

.cw-input-hint {
  font-size: 12px;
  color: var(--cw-primary);
  font-weight: 500;
  line-height: 1.3;
}

.cw-back-btn {
  background: none;
  border: 1px solid #e2e8f0;
  color: #64748b;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  padding: 3px 10px;
  border-radius: 20px;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  flex-shrink: 0;
  line-height: 1.4;
}

.cw-back-btn:hover {
  background: #f1f5f9;
  color: var(--cw-primary);
  border-color: var(--cw-primary);
}

/* Пульс-анимация рамки поля */
@keyframes cwInputPulse {
  0%, 100% { border-color: #e2e8f0; box-shadow: none; }
  50%       { border-color: var(--cw-primary); box-shadow: 0 0 0 3px rgba(47, 111, 237, 0.15); }
}

.cw-input-wrap--pulse {
  animation: cwInputPulse 0.75s ease 3;
}

.cw-input-wrap {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  background: #f8fafc;
  border: 1.5px solid #e2e8f0;
  border-radius: 12px;
  padding: 8px 8px 8px 14px;
  transition: border-color 0.2s;
}

.cw-input-wrap:focus-within {
  border-color: var(--cw-primary);
}

.cw-input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  outline: none;
  min-height: 20px;
  max-height: 80px;
  line-height: 1.5;
  color: #1e293b;
}

.cw-input::placeholder { color: #94a3b8; }

.cw-input--error {
  animation: cwShake 0.4s ease;
  color: #ef4444 !important;
}

@keyframes cwShake {
  0%, 100% { transform: translateX(0); }
  20%       { transform: translateX(-6px); }
  40%       { transform: translateX(6px); }
  60%       { transform: translateX(-4px); }
  80%       { transform: translateX(4px); }
}

.cw-send-btn {
  width: 34px;
  height: 34px;
  background: var(--cw-primary);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
  transition: background 0.2s, transform 0.15s;
  padding: 0;
}

.cw-send-btn:hover {
  background: var(--cw-primary-dark);
  transform: scale(1.06);
}

.cw-send-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none;
}

/* ---- Utilities ---- */
.cw-hidden { display: none !important; }

/* ---- Mobile ---- */
@media (max-width: 720px) {
  .cw-toggle {
    bottom: 16px;
    right: 16px;
    width: 66px;
    height: 66px;
  }

  .cw-bubble {
    bottom: 94px;
    right: 16px;
    max-width: 240px;
    font-size: 14px;
  }

  .cw-window {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    height: 75dvh;
    border-radius: 20px 20px 0 0;
    animation: cwWindowUp 0.3s ease;
  }

  @keyframes cwWindowUp {
    from { transform: translateY(100%); }
    to   { transform: translateY(0);    }
  }
}
