/* ЦИФРА Chat Widget — стили
 * 2026-05-07: первая версия, бирюза #5DB5B0 как основной цвет
 * 2026-05-11: единый FAB вместо Envybox+Medflex — главный CTA на сайте.
 *             Оранжевый #F39C12 как primary (более заметен на белом WP-фоне).
 *             Бирюза остаётся как secondary (родной бренд из логотипа).
 *             Добавлены callback-chip в шапке и inline-форма обратного звонка.
 * Префикс cifra-chat-* — изоляция от стилей родительского WP-сайта
 */

@import url('https://fonts.googleapis.com/css2?family=Exo+2:wght@500;600;700&display=swap');

:root {
  /* Primary — оранжевый CTA (FAB, send, callback, consent) */
  --cifra-orange: #F39C12;
  --cifra-orange-dark: #E67E22;
  --cifra-orange-light: #FFF4E0;
  /* Secondary — бирюза (родной бренд: аватар, header, user-сообщения) */
  --cifra-teal: #5DB5B0;
  --cifra-teal-dark: #4A9994;
  --cifra-teal-light: #E8F4F3;
  /* Нейтральные */
  --cifra-grey: #787D86;
  --cifra-grey-light: #F2F3F5;
  --cifra-text: #2C2F36;
  --cifra-white: #FFFFFF;
  --cifra-shadow: 0 8px 32px rgba(243, 156, 18, 0.28);
  --cifra-shadow-strong: 0 16px 48px rgba(243, 156, 18, 0.38);
}

/* ─── FAB кнопка ─────────────────────────────────────────────────── */

.cifra-chat-fab {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: 64px;
  height: 64px;
  border: none;
  border-radius: 50%;
  background: var(--cifra-orange);
  color: var(--cifra-white);
  cursor: pointer;
  box-shadow: var(--cifra-shadow);
  z-index: 2147483600;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
  font-family: 'Exo 2', sans-serif;
}

.cifra-chat-fab:hover {
  transform: scale(1.06);
  background: var(--cifra-orange-dark);
  box-shadow: var(--cifra-shadow-strong);
}

.cifra-chat-fab:active { transform: scale(0.96); }

.cifra-chat-fab svg { width: 30px; height: 30px; }

.cifra-chat-fab__badge {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 12px;
  height: 12px;
  background: #FF5B5B;
  border: 2px solid var(--cifra-white);
  border-radius: 50%;
  animation: cifra-pulse 2s infinite;
}

@keyframes cifra-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.3); opacity: 0.7; }
}

/* Greeting bubble — всплывает через 30с */
.cifra-chat-greeting {
  position: fixed;
  right: 96px;
  bottom: 28px;
  max-width: 280px;
  background: var(--cifra-white);
  border-radius: 16px;
  padding: 14px 18px;
  box-shadow: var(--cifra-shadow);
  font-family: 'Exo 2', sans-serif;
  font-weight: 500;
  font-size: 14px;
  line-height: 1.45;
  color: var(--cifra-text);
  z-index: 2147483599;
  cursor: pointer;
  animation: cifra-slide-in 0.4s ease;
}

.cifra-chat-greeting::after {
  content: '';
  position: absolute;
  right: -8px;
  bottom: 22px;
  width: 0;
  height: 0;
  border-left: 8px solid var(--cifra-white);
  border-top: 8px solid transparent;
  border-bottom: 8px solid transparent;
}

.cifra-chat-greeting__close {
  position: absolute;
  top: 4px;
  right: 8px;
  background: none;
  border: none;
  color: var(--cifra-grey);
  font-size: 18px;
  cursor: pointer;
  padding: 2px 6px;
  line-height: 1;
}

@keyframes cifra-slide-in {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ─── Окно чата ────────────────────────────────────────────────── */

.cifra-chat-window {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: 380px;
  height: 600px;
  max-height: calc(100vh - 40px);
  background: var(--cifra-white);
  border-radius: 20px;
  box-shadow: var(--cifra-shadow-strong);
  z-index: 2147483601;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: 'Exo 2', sans-serif;
  color: var(--cifra-text);
  animation: cifra-window-in 0.3s ease;
}

@keyframes cifra-window-in {
  from { opacity: 0; transform: translateY(20px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ─── Header ─────────────────────────────────────────────────────── */
/* 2026-05-11: header остался бирюзовый (родной бренд ЦИФРЫ из логотипа),
   но добавлен chip-кнопка "Обратный звонок" — это callback-флоу в одном виджете. */

.cifra-chat-header {
  background: var(--cifra-teal);
  color: var(--cifra-white);
  padding: 18px 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
  overflow: hidden;
}

.cifra-chat-header__top {
  display: flex;
  align-items: center;
  gap: 12px;
}

.cifra-chat-header__cluster {
  position: absolute;
  top: 0;
  right: 0;
  width: 90px;
  height: 60px;
  opacity: 0.35;
  pointer-events: none;
}

/* 2026-05-11: аватар стал круглым (border-radius 50% вместо 12px) — внутри
   фото-иллюстрация Софьи, img заполняет круг через object-fit:cover. */
.cifra-chat-header__avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--cifra-white);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
  z-index: 1;
  overflow: hidden;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.85);
}

.cifra-chat-header__avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.cifra-chat-header__avatar svg { width: 28px; height: 28px; }  /* fallback при отсутствии img */

.cifra-chat-header__title {
  flex: 1;
  position: relative;
  z-index: 1;
  min-width: 0;
}

.cifra-chat-header__title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.5px;
}

.cifra-chat-header__online {
  width: 8px;
  height: 8px;
  background: #6CE8B0;
  border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(108, 232, 176, 0.3);
}

.cifra-chat-header__subtitle {
  font-size: 12px;
  font-weight: 500;
  opacity: 0.92;
  margin-top: 2px;
}

.cifra-chat-header__close {
  background: rgba(255, 255, 255, 0.18);
  border: none;
  color: var(--cifra-white);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease;
  position: relative;
  z-index: 1;
}

.cifra-chat-header__close:hover { background: rgba(255, 255, 255, 0.3); }

/* 2026-05-11 вечер: chip "Обратный звонок" переехал из шапки в отдельную полосу
   между body и input footer'ом. На белом фоне оранжевый CTA читается ярче. */
.cifra-chat-callback-bar {
  background: var(--cifra-white);
  padding: 10px 12px 6px;
  display: flex;
  justify-content: center;
  border-top: 1px solid rgba(120, 125, 134, 0.08);
}

.cifra-chat-callback-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  background: var(--cifra-orange);
  color: var(--cifra-white);
  border: none;
  border-radius: 14px;
  padding: 11px 18px;
  font-family: 'Exo 2', sans-serif;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.1s ease, box-shadow 0.2s ease;
  box-shadow: 0 4px 12px rgba(243, 156, 18, 0.30);
}

.cifra-chat-callback-chip:hover {
  background: var(--cifra-orange-dark);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(243, 156, 18, 0.40);
}

.cifra-chat-callback-chip:active { transform: translateY(0); }
.cifra-chat-callback-chip svg { width: 16px; height: 16px; }
.cifra-chat-callback-chip[disabled] {
  background: var(--cifra-grey);
  opacity: 0.6;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

/* ─── Тело сообщений ──────────────────────────────────────────── */

.cifra-chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: var(--cifra-grey-light);
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}

.cifra-chat-body::-webkit-scrollbar { width: 6px; }
.cifra-chat-body::-webkit-scrollbar-thumb {
  background: rgba(120, 125, 134, 0.3);
  border-radius: 3px;
}

.cifra-chat-msg {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.45;
  word-wrap: break-word;
  white-space: pre-wrap;
  animation: cifra-msg-in 0.25s ease;
}

@keyframes cifra-msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.cifra-chat-msg--agent {
  align-self: flex-start;
  background: var(--cifra-white);
  color: var(--cifra-text);
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.cifra-chat-msg--user {
  align-self: flex-end;
  background: var(--cifra-teal);
  color: var(--cifra-white);
  border-bottom-right-radius: 4px;
}

.cifra-chat-msg--system {
  align-self: center;
  background: transparent;
  color: var(--cifra-grey);
  font-size: 12px;
  font-style: italic;
  max-width: 100%;
  text-align: center;
}

/* "Заявка отправлена" — успешный callback chip-статус */
.cifra-chat-msg--success {
  align-self: center;
  background: var(--cifra-orange-light);
  color: var(--cifra-orange-dark);
  font-size: 13px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 14px;
  border: 1px solid var(--cifra-orange);
  max-width: 90%;
  text-align: center;
}

.cifra-chat-typing {
  align-self: flex-start;
  background: var(--cifra-white);
  padding: 12px 16px;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  display: flex;
  gap: 4px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.cifra-chat-typing span {
  width: 6px;
  height: 6px;
  background: var(--cifra-orange);
  border-radius: 50%;
  animation: cifra-typing 1.2s infinite;
}

.cifra-chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.cifra-chat-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes cifra-typing {
  0%, 60%, 100% { transform: scale(0.7); opacity: 0.5; }
  30% { transform: scale(1); opacity: 1; }
}

/* ─── Inline-форма обратного звонка ─────────────────────────────── */
/* 2026-05-11: появляется в теле чата при клике на chip "Обратный звонок"
   — не выкидывает пациента из диалога с Софьёй. */

.cifra-chat-callback-form {
  align-self: stretch;
  background: var(--cifra-white);
  border: 1px solid var(--cifra-orange);
  border-radius: 16px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: cifra-msg-in 0.25s ease;
}

.cifra-chat-callback-form__title {
  font-weight: 700;
  font-size: 14px;
  color: var(--cifra-text);
}

.cifra-chat-callback-form__hint {
  font-size: 12px;
  color: var(--cifra-grey);
  line-height: 1.4;
}

.cifra-chat-callback-form input[type="tel"],
.cifra-chat-callback-form input[type="text"] {
  border: 1px solid rgba(120, 125, 134, 0.3);
  border-radius: 10px;
  padding: 10px 12px;
  font-family: 'Exo 2', sans-serif;
  font-size: 14px;
  outline: none;
  color: var(--cifra-text);
  transition: border-color 0.2s ease;
}

.cifra-chat-callback-form input:focus { border-color: var(--cifra-orange); }

.cifra-chat-callback-form__row {
  display: flex;
  gap: 8px;
}

.cifra-chat-callback-form__row input { flex: 1; }

.cifra-chat-callback-form__submit {
  background: var(--cifra-orange);
  color: var(--cifra-white);
  border: none;
  border-radius: 10px;
  padding: 11px 16px;
  font-family: 'Exo 2', sans-serif;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.1s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.cifra-chat-callback-form__submit:hover { background: var(--cifra-orange-dark); }
.cifra-chat-callback-form__submit:active { transform: scale(0.97); }
.cifra-chat-callback-form__submit:disabled {
  background: var(--cifra-grey);
  opacity: 0.6;
  cursor: not-allowed;
}

.cifra-chat-callback-form__cancel {
  background: none;
  border: none;
  color: var(--cifra-grey);
  font-family: 'Exo 2', sans-serif;
  font-size: 12px;
  cursor: pointer;
  padding: 4px;
  text-decoration: underline;
}

.cifra-chat-callback-form__consent {
  font-size: 11px;
  color: var(--cifra-grey);
  line-height: 1.4;
}

.cifra-chat-callback-form__consent a {
  color: var(--cifra-orange-dark);
  text-decoration: underline;
}

/* ─── Согласие 152-ФЗ (стартовый экран) ──────────────────────── */

.cifra-chat-consent {
  padding: 24px 20px;
  background: var(--cifra-white);
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1;
  justify-content: center;
}

.cifra-chat-consent__title {
  font-weight: 700;
  font-size: 18px;
  color: var(--cifra-text);
}

.cifra-chat-consent__text {
  font-size: 13px;
  line-height: 1.5;
  color: var(--cifra-grey);
}

.cifra-chat-consent__text a {
  color: var(--cifra-orange-dark);
  text-decoration: underline;
}

.cifra-chat-consent__btn {
  background: var(--cifra-orange);
  color: var(--cifra-white);
  border: none;
  border-radius: 12px;
  padding: 14px 18px;
  font-family: 'Exo 2', sans-serif;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  transition: background 0.2s ease;
}

.cifra-chat-consent__btn:hover { background: var(--cifra-orange-dark); }

/* ─── Поле ввода ──────────────────────────────────────────────── */

.cifra-chat-footer {
  background: var(--cifra-white);
  padding: 12px;
  border-top: 1px solid rgba(120, 125, 134, 0.12);
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.cifra-chat-input {
  flex: 1;
  border: 1px solid rgba(120, 125, 134, 0.25);
  border-radius: 14px;
  padding: 10px 14px;
  font-family: 'Exo 2', sans-serif;
  font-size: 15px;
  line-height: 1.4;
  resize: none;
  max-height: 120px;
  min-height: 40px;
  outline: none;
  color: var(--cifra-text);
  transition: border-color 0.2s ease;
}

.cifra-chat-input:focus { border-color: var(--cifra-orange); }
.cifra-chat-input::placeholder { color: var(--cifra-grey); }

.cifra-chat-send {
  background: var(--cifra-orange);
  color: var(--cifra-white);
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s ease, transform 0.1s ease;
}

.cifra-chat-send:hover { background: var(--cifra-orange-dark); }
.cifra-chat-send:active { transform: scale(0.94); }
.cifra-chat-send:disabled { background: var(--cifra-grey); opacity: 0.5; cursor: not-allowed; }
.cifra-chat-send svg { width: 18px; height: 18px; }

.cifra-chat-powered {
  text-align: center;
  font-size: 10px;
  color: var(--cifra-grey);
  padding: 6px 0 8px;
  background: var(--cifra-white);
  letter-spacing: 0.5px;
}

.cifra-chat-powered a { color: var(--cifra-grey); text-decoration: none; }
.cifra-chat-powered a:hover { color: var(--cifra-orange-dark); }

/* ─── Mobile fullscreen ───────────────────────────────────────── */

@media (max-width: 480px) {
  .cifra-chat-window {
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100dvh;
    max-height: none;
    border-radius: 0;
  }

  .cifra-chat-greeting {
    right: 16px;
    bottom: 92px;
    max-width: calc(100vw - 32px);
  }

  .cifra-chat-fab { right: 16px; bottom: 16px; }

  .cifra-chat-input { font-size: 16px; /* предотвращает зум на iOS */ }
}

/* Скрываем виджет когда чат открыт */
.cifra-chat--open .cifra-chat-fab,
.cifra-chat--open .cifra-chat-greeting { display: none; }

.cifra-chat-window--hidden { display: none; }
