/* =========================================================
   Виджет связи: «Написать мне» + «Обратный звонок»
   Использует переменные и классы .field / .check / .btn из styles.css
   ========================================================= */
.cw {
  --cw-gap: 20px;
  position: fixed; right: var(--cw-gap); bottom: calc(var(--cw-gap) + env(safe-area-inset-bottom));
  z-index: 60; display: flex; flex-direction: column; align-items: flex-end; gap: 12px;
  font-family: var(--font-body);
  transition: bottom .3s ease;
}

/* ---------- Кнопки-лаунчеры ---------- */
.cw__launchers { display: flex; align-items: center; gap: 10px; }
.cw__fab {
  position: relative; display: inline-flex; align-items: center; gap: 10px;
  height: 60px; border: 0; border-radius: 999px; cursor: pointer;
  font: 700 16px/1 var(--font-body); color: #fff;
  box-shadow: 0 12px 28px -10px rgba(18, 35, 28, .55);
  transition: transform .18s ease, background .2s ease, box-shadow .2s ease;
}
.cw__fab:hover { transform: translateY(-2px); }
.cw__fab:focus-visible { outline: 3px solid var(--orange); outline-offset: 3px; }
/* Чат — главное действие: оранжевая кнопка с тёмным текстом (как .btn--accent) и пульсацией */
.cw__fab--chat {
  padding: 0 24px 0 18px; background: var(--orange); color: var(--green-dark);
  box-shadow: 0 12px 28px -10px rgba(217, 112, 26, .85);
}
.cw__fab--chat:hover { background: var(--orange-deep); }
.cw__fab--chat:focus-visible { outline-color: var(--green-dark); }
/* Трубка — второстепенное: светлая кнопка с зелёной иконкой и тонкой рамкой, без пульсации */
.cw__fab--call {
  box-sizing: border-box; width: 52px; height: 52px; justify-content: center;
  background: var(--paper); color: var(--green); border: 1.5px solid rgba(46, 107, 82, .28);
  box-shadow: 0 10px 24px -12px rgba(18, 35, 28, .45);
}
.cw__fab--call:hover { background: var(--green-soft); border-color: var(--green); }
/* Иконка чата + мятная точка «на связи» */
.cw__fab-ico { position: relative; display: grid; place-items: center; flex: none; }
.cw__fab-ico::after {
  content: ""; position: absolute; top: -4px; right: -5px; width: 10px; height: 10px; border-radius: 50%;
  background: var(--mint); border: 2px solid var(--green-dark);
}
/* Мягкая «пульсация» чата, пока виджет не открывали */
.cw:not(.is-open) .cw__fab--chat::before {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  animation: cwPulse 2.6s ease-out infinite;
}
@keyframes cwPulse {
  0% { box-shadow: 0 0 0 0 rgba(242, 137, 43, .6); }
  70%, 100% { box-shadow: 0 0 0 12px rgba(242, 137, 43, 0); }
}
/* Открытая вкладка: белый зазор + тёмное кольцо — видно и на оранжевом чате, и на белой трубке */
.cw__fab.is-current { box-shadow: 0 0 0 3px var(--paper), 0 0 0 5.5px var(--green-dark), 0 12px 28px -10px rgba(18, 35, 28, .55); }

/* Подпись к трубке при наведении */
.cw__tip {
  position: absolute; right: calc(100% + 10px); top: 50%; transform: translate(6px, -50%);
  white-space: nowrap; padding: 8px 12px; border-radius: 10px;
  background: var(--ink); color: #fff; font-size: 14px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity .15s, transform .15s;
}
.cw__fab--call:hover .cw__tip, .cw__fab--call:focus-visible .cw__tip { opacity: 1; transform: translate(0, -50%); }
.cw.is-open .cw__tip { display: none; }

/* ---------- Панель ---------- */
.cw__panel {
  width: min(380px, calc(100vw - 2 * var(--cw-gap)));
  max-height: calc(100dvh - 116px);
  display: flex; flex-direction: column;
  background: var(--paper); color: var(--ink);
  border-radius: 24px; overflow: hidden;
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(23, 36, 31, .06);
  transform-origin: bottom right; animation: cwIn .24s ease;
}
.cw__panel[hidden] { display: none; }
@keyframes cwIn { from { opacity: 0; transform: translateY(12px) scale(.97); } to { opacity: 1; transform: none; } }

.cw__head {
  display: flex; align-items: center; gap: 12px; flex: none;
  padding: 16px 14px 16px 18px; background: var(--green-deep); color: #fff;
}
.cw__avatar { width: 48px; height: 48px; border-radius: 50%; object-fit: cover; border: 2.5px solid var(--orange); flex: none; }
.cw__who { flex: 1; min-width: 0; }
.cw__name { margin: 0; font: 500 17px/1.2 var(--font-head); }
.cw__status { margin: 4px 0 0; font-size: 13px; color: rgba(255, 255, 255, .75); display: flex; align-items: center; gap: 6px; }
.cw__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--mint); flex: none; box-shadow: 0 0 0 3px rgba(155, 227, 191, .25); }
.cw__x {
  width: 40px; height: 40px; border-radius: 50%; border: 0; flex: none; cursor: pointer;
  display: grid; place-items: center; background: rgba(255, 255, 255, .12); color: #fff; transition: background .2s;
}
.cw__x:hover { background: rgba(255, 255, 255, .24); }
.cw__x:focus-visible { outline: 3px solid var(--orange); outline-offset: 2px; }

.cw__tabs { display: flex; gap: 4px; padding: 6px; margin: 12px 14px 0; background: var(--bg); border-radius: 999px; flex: none; }
.cw__tab {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 8px; border: 0; border-radius: 999px; cursor: pointer;
  font: 700 14px/1.2 var(--font-body); color: var(--muted); background: transparent; transition: background .2s, color .2s;
}
.cw__tab[aria-selected="true"] { background: var(--paper); color: var(--ink); box-shadow: 0 2px 8px -3px rgba(23, 36, 31, .25); }
.cw__tab:focus-visible { outline: 3px solid var(--orange); outline-offset: 1px; }

.cw__body { padding: 16px 18px 18px; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.cw__body[hidden] { display: none; }

.cw__bubble {
  position: relative; background: var(--green-soft); border-radius: 4px 18px 18px 18px;
  padding: 12px 14px; font-size: 15px; line-height: 1.5; margin-bottom: 16px;
}
.cw__bubble p { margin: 0; }
.cw__label { font-size: 13px; font-weight: 700; color: var(--muted); margin: 0 0 8px; letter-spacing: .02em; }

.cw__msgs { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.cw__msg {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px 10px 10px;
  border: 1.5px solid var(--line); border-radius: 16px; text-decoration: none; color: var(--ink);
  transition: border-color .15s, background .15s, transform .15s;
}
.cw__msg:hover { border-color: var(--green); background: #FBFAF7; transform: translateX(2px); }
.cw__msg:focus-visible { outline: 3px solid var(--orange); outline-offset: 2px; }
.cw__msg-ico { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; color: #fff; flex: none; }
.cw__msg--tg .cw__msg-ico { background: #2AABEE; }
.cw__msg--wa .cw__msg-ico { background: #25D366; }
.cw__msg--max .cw__msg-ico { background: linear-gradient(135deg, #3D7BFF, #8A3DFF); }
.cw__msg-txt { flex: 1; display: grid; line-height: 1.3; }
.cw__msg-txt b { font-size: 15px; }
.cw__msg-txt small { font-size: 13px; color: var(--muted); }
.cw__msg-go { color: var(--muted); font-weight: 700; transition: transform .15s, color .15s; }
.cw__msg:hover .cw__msg-go { color: var(--green); transform: translateX(3px); }
.cw__note { font-size: 13px; color: var(--muted); margin: 12px 0 4px; }

.cw__form { display: grid; gap: 12px; }
.cw__form[hidden], .cw__done[hidden] { display: none; }
.cw__intro { font-size: 14px; color: var(--muted); margin: 0; }
.cw__form .field input { padding: 11px 14px; }
.cw__when { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.cw__when legend { font-size: 14px; font-weight: 700; margin-bottom: 6px; padding: 0; }
.cw__when input { position: absolute; opacity: 0; pointer-events: none; }
.cw__when span {
  display: inline-block; padding: 7px 12px; border-radius: 999px; border: 1.5px solid var(--line);
  font-size: 13px; font-weight: 700; cursor: pointer; transition: border-color .15s, background .15s, color .15s;
}
.cw__when input:checked + span { background: var(--green); border-color: var(--green); color: #fff; }
.cw__when label:has(input:focus-visible) span { outline: 3px solid var(--orange); outline-offset: 2px; }
.cw__form .check { font-size: 13px; }
.cw__form .btn { padding: 13px 20px; }
.cw__form .form__error { margin: 0; min-height: 0; font-size: 13px; color: #D2452F; font-weight: 600; }
.cw__form .form__error:empty { display: none; }

.cw__done { text-align: center; padding: 8px 4px 10px; }
.cw__done .form-success__icon { margin: 0 auto 12px; }
.cw__done-title { font: 500 19px/1.25 var(--font-head); margin: 0 0 8px; }
.cw__done-title:focus { outline: none; }
.cw__done p:not(.cw__done-title) { font-size: 14px; color: var(--muted); }


/* ---------- Подсказка-приветствие ---------- */
.cw__teaser {
  position: relative; max-width: 270px;
  opacity: 0; transform: translateY(8px); transition: opacity .3s ease, transform .3s ease;
}
.cw__teaser.is-in { opacity: 1; transform: none; }
.cw__teaser[hidden] { display: none; }
.cw__teaser-body {
  display: flex; align-items: center; gap: 10px; text-align: left; cursor: pointer;
  padding: 12px 16px 12px 12px; border: 0; border-radius: 18px 18px 4px 18px;
  background: var(--paper); color: var(--ink); box-shadow: var(--shadow-lg), 0 0 0 1px rgba(23, 36, 31, .06);
  font: 600 14px/1.4 var(--font-body);
}
.cw__teaser-body img { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; flex: none; }
.cw__teaser-body:focus-visible { outline: 3px solid var(--orange); outline-offset: 2px; }
.cw__teaser-x {
  position: absolute; top: -8px; left: -8px; width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center; border: 0; cursor: pointer;
  background: var(--ink); color: #fff; box-shadow: var(--shadow);
}

/* Пока открыто окно записи — виджет не нужен */
html.is-modal-open .cw { display: none; }

/* ---------- Мобильные ---------- */
@media (max-width: 900px) {
  /* Одна строка внизу: [Бесплатное знакомство] [трубка] [чат].
     widget.js переносит #stickyCta внутрь .cw__launchers; показ/скрытие по-прежнему делает script.js */
  .cw { --cw-gap: 12px; }
  /* Кнопка шириной по содержимому (фото + текст), строка прижата вправо;
     на совсем узких экранах текст сжимается с многоточием */
  .cw__launchers { max-width: calc(100vw - 2 * var(--cw-gap)); }
  .cw .sticky-cta { position: static; display: none; flex: 0 1 auto; min-width: 0; transform: none; transition: none; }
  .cw .sticky-cta.is-visible { display: block; animation: cwCtaIn .3s ease; }
  .cw .sticky-cta .btn {
    width: auto; max-width: 100%;
    height: 54px; padding: 0 20px 0 7px; gap: 10px;
    box-shadow: 0 12px 28px -10px rgba(18, 35, 28, .55);
  }
  /* Фото Екатерины на кнопке «Бесплатное знакомство» */
  .cw__cta-photo { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; border: 2px solid var(--orange); flex: none; }
  .cw__cta-text { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .cw__fab { height: 54px; }
  .cw__fab--call { width: 54px; height: 54px; }
  .cw__tip { display: none; }
  /* Рядом с кнопкой записи чат — только иконка, без подписи */
  .cw:has(.sticky-cta.is-visible) .cw__fab--chat { padding: 0; width: 54px; justify-content: center; }
  .cw:has(.sticky-cta.is-visible) .cw__fab-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}
/* Узкие телефоны: «Бесплатное знакомство» в одну строку рядом с фото */
@media (max-width: 400px) {
  .cw__launchers { gap: 6px; }
  .cw .sticky-cta .btn { height: 52px; padding: 0 12px 0 5px; gap: 8px; font-size: 14px; }
  .cw__cta-photo { width: 36px; height: 36px; }
  .cw__fab, .cw__fab--call, .cw:has(.sticky-cta.is-visible) .cw__fab--chat { width: 52px; height: 52px; }
}
@media (max-width: 370px) {
  .cw .sticky-cta .btn { font-size: 13px; padding-right: 10px; gap: 6px; }
}
@keyframes cwCtaIn { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
@media (max-width: 640px) {
  .cw__fab--chat { padding: 0; width: 54px; justify-content: center; }
  .cw__fab-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

  /* Панель — шторка снизу на всю ширину */
  .cw.is-open { left: 0; right: 0; bottom: 0; }
  .cw.is-open .cw__launchers, .cw.is-open .cw__teaser { display: none; }
  .cw__panel {
    width: 100%; max-height: 88dvh; border-radius: 24px 24px 0 0;
    padding-bottom: env(safe-area-inset-bottom); animation-name: cwSheet;
  }
  .cw.is-open::before {
    content: ""; position: fixed; inset: 0; z-index: -1; background: rgba(18, 35, 28, .5);
  }
  .cw__teaser { max-width: calc(100vw - 90px); }
}
@keyframes cwSheet { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  .cw__fab--chat::before { display: none; }
}
