/* EngineXpress. Чат с менеджером в правом нижнем углу */
.chat { position: fixed; right: 24px; bottom: 0; z-index: 80; width: 380px; font-family: var(--font-sans); pointer-events: none; }
.chat__panel, .chat__teaser { pointer-events: auto; }
.chat__badge { flex: none; min-width: 22px; height: 22px; padding: 0 7px; border-radius: var(--radius-full); background: var(--signal); color: var(--on-signal); font: 700 12px/22px var(--font-sans); box-sizing: border-box; text-align: center; animation: chat-pop .5s var(--ease) both; }
.chat__badge[hidden] { display: none; }

/* Подсказка-приветствие над свёрнутым чатом */
.chat__teaser { position: absolute; right: 0; bottom: 82px; width: 300px; animation: chat-rise .6s var(--ease) both; }
.chat__teaser[hidden] { display: none; }
.chat__teaser-body { display: flex; gap: 12px; width: 100%; padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--bg); box-shadow: var(--shadow-md); text-align: left; font: 400 14px/20px var(--font-sans); color: var(--ink-2); cursor: pointer; }
.chat__teaser-body b { display: block; color: var(--ink); font-weight: 600; margin-bottom: 2px; }
.chat__teaser-x { position: absolute; top: -10px; right: -6px; z-index: 1; display: grid; place-items: center; width: 26px; height: 26px; border: 1px solid var(--line); border-radius: var(--radius-full); background: var(--bg); color: var(--ink-3); cursor: pointer; }
.chat__teaser-x .ex-ic { width: 14px; height: 14px; }

/* Панель: в свёрнутом виде над краем экрана видна только шапка, по клику панель выезжает вверх */
.chat { --head-h: 68px; }
.chat__panel { display: flex; flex-direction: column; height: min(600px, calc(100vh - 90px)); border-radius: 18px 18px 0 0; background: var(--bg); box-shadow: 0 -4px 30px #020b4733, 0 0 2px #020b471a; overflow: hidden;
  transform: translateY(calc(100% - var(--head-h))); transition: transform .65s var(--ease); will-change: transform; }
.chat.is-open .chat__panel { transform: none; }

.chat__head { flex: none; display: flex; align-items: center; gap: 12px; width: 100%; height: var(--head-h); padding: 0 14px 0 16px; border: 0; background: var(--brand); color: var(--on-brand); text-align: left; font: inherit; cursor: pointer; transition: background .3s var(--ease); }
.chat__head:hover { background: var(--brand-hover); }
.chat__head:focus-visible { outline: none; box-shadow: inset 0 0 0 3px #ffffff80; }
.chat__ava-wrap { position: relative; flex: none; width: 40px; height: 40px; }
.chat__ava { display: block; flex: none; width: 40px; height: 40px; border-radius: var(--radius-full); }
.chat__head .chat__ava { box-shadow: 0 0 0 1.5px #ffffff59; }
.chat__dot { position: absolute; right: -1px; bottom: -1px; width: 12px; height: 12px; border: 2px solid var(--brand); border-radius: 50%; background: var(--line-strong); }
.chat__dot.is-on { background: #2fd27a; }
.chat__who { flex: 1; min-width: 0; display: grid; }
.chat__who b { font: 600 16px/20px var(--font-sans); }
.chat__who span { font-size: 13px; line-height: 18px; color: var(--on-brand-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat__arrow { flex: none; display: grid; place-items: center; width: 32px; height: 32px; transition: transform .6s var(--ease); }
.chat.is-open .chat__arrow { transform: rotate(180deg); }
.chat__main { flex: 1; min-height: 0; display: flex; flex-direction: column; position: relative; }

.chat__body { flex: 1; overflow-y: auto; padding: 16px 14px 8px; background: var(--bg-alt); overscroll-behavior: contain; }
.chat__msgs { display: flex; flex-direction: column; gap: 8px; }

/* Сообщения */
.cmsg { max-width: 84%; padding: 9px 13px; border-radius: 16px; font-size: 15px; line-height: 21px; white-space: pre-wrap; overflow-wrap: anywhere; animation: chat-msg .4s var(--ease) both; }
.cmsg--in { align-self: flex-start; background: var(--bg); color: var(--ink); border-bottom-left-radius: 6px; box-shadow: 0 1px 2px #020b470f; }
.cmsg--out { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 6px; }
.cmsg--out.is-sending { opacity: .6; }
.cmsg__time { display: block; margin-top: 2px; font-size: 11px; line-height: 14px; opacity: .55; text-align: right; }
.cmsg--sys { align-self: center; max-width: 90%; padding: 2px 8px; color: var(--ink-3); font-size: 13px; line-height: 18px; text-align: center; background: none; }

/* Картинки */
.cmsg--img { padding: 4px; }
.cmsg__img { display: block; max-width: 220px; max-height: 220px; border-radius: 12px; cursor: zoom-in; background: var(--bg-sunken); }
.cmsg--img .cmsg__time { padding: 2px 6px 0; }
.cmsg--img .cmsg__text { display: block; padding: 4px 8px 0; }
.chat__attach { flex: none; display: grid; place-items: center; width: 38px; height: 42px; border-radius: 10px; color: var(--ink-3); cursor: pointer; transition: color .25s var(--ease), background .25s var(--ease); }
.chat__attach:hover { color: var(--brand); background: var(--brand-soft); }
.chat__attach .ex-ic { width: 21px; height: 21px; }
.chat__drop { position: absolute; inset: 0; z-index: 3; display: grid; place-items: center; margin: 8px; border: 2px dashed var(--brand); border-radius: 14px; background: #eef1fcf2; color: var(--brand); font-weight: 600; pointer-events: none; }
.chat__drop[hidden] { display: none; }

/* Популярные вопросы */
.chat__quick { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; margin-top: 4px; animation: chat-msg .4s .2s var(--ease) both; }
.chat__q { max-width: 90%; padding: 8px 12px; border: 1px solid var(--brand-tint); border-radius: 14px; background: var(--bg); color: var(--brand); font: 500 14px/19px var(--font-sans); text-align: left; cursor: pointer; transition: background .25s var(--ease), border-color .25s var(--ease); }
.chat__q:hover { background: var(--brand-soft); border-color: var(--brand); }

/* Выбор способа связи */
.chat__offer { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 2px; animation: chat-msg .4s .2s var(--ease) both; }
.chat__ch { display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 12px; border: 1px solid var(--brand-tint); border-radius: var(--radius-full); background: var(--bg); color: var(--brand); font: 500 14px/1 var(--font-sans); cursor: pointer; }
.chat__ch .ex-ic { width: 16px; height: 16px; }
.chat__ch:hover, .chat__ch.is-active { background: var(--brand); border-color: var(--brand); color: #fff; }
.chat__phone { display: flex; gap: 6px; width: 100%; margin-top: 4px; animation: chat-msg .6s var(--ease) both; }
.chat__phone input { flex: 1; min-width: 0; height: 40px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); font: 400 15px/1 var(--font-sans); }
.chat__phone input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.chat__phone button { height: 40px; padding: 0 14px; border: 0; border-radius: var(--radius-sm); background: var(--brand); color: #fff; font: 600 14px/1 var(--font-sans); cursor: pointer; }

/* Печатает */
.chat__typing { display: flex; align-items: center; gap: 8px; padding: 10px 2px 4px; color: var(--ink-3); font-size: 13px; animation: chat-msg .35s var(--ease) both; }
.chat__typing[hidden] { display: none; }
.chat__dots { display: inline-flex; gap: 3px; padding: 8px 10px; border-radius: 12px; background: var(--bg); }
.chat__dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--ink-3); animation: chat-dot 1.2s infinite ease-in-out; }
.chat__dots i:nth-child(2) { animation-delay: .15s; }
.chat__dots i:nth-child(3) { animation-delay: .3s; }

/* Поле ввода */
.chat__form { padding: 10px 12px 12px; border-top: 1px solid var(--line); background: var(--bg); }
.chat__agree { display: flex; gap: 8px; align-items: flex-start; margin-bottom: 8px; font-size: 12px; line-height: 16px; color: var(--ink-2); cursor: pointer; }
.chat__agree input { flex: none; width: 18px; height: 18px; margin: 0; accent-color: var(--brand); cursor: pointer; }
.chat__agree a { color: var(--accent); }
.chat__agree.is-shake { animation: chat-shake .55s; color: var(--danger); }
.chat__agree[hidden] { display: none; }
.chat__input { display: flex; align-items: flex-end; gap: 8px; }
.chat__input textarea { flex: 1; min-width: 0; max-height: 120px; padding: 10px 12px; border: 1px solid var(--line-strong); border-radius: 12px; resize: none; font: 400 15px/20px var(--font-sans); color: var(--ink); }
.chat__input textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.chat__send { flex: none; display: grid; place-items: center; width: 42px; height: 42px; border: 0; border-radius: 12px; background: var(--accent); color: #fff; cursor: pointer; transition: opacity .25s var(--ease), transform .25s var(--ease); }
.chat__send:disabled { opacity: .35; cursor: default; }
.chat__send:not(:disabled):active { transform: scale(.94); }
.chat__send .ex-ic { width: 19px; height: 19px; }
.chat__err { margin-top: 6px; color: var(--danger); font-size: 13px; line-height: 18px; }
.chat__err[hidden] { display: none; }

@keyframes chat-msg { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes chat-rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes chat-dot { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-4px); opacity: 1; } }
@keyframes chat-pop { from { transform: scale(0); } to { transform: none; } }
@keyframes chat-shake { 0%, 100% { transform: none; } 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }

/* На телефоне: свёрнутая шапка не занимает экран, чат открывается кнопкой «Чат» в нижней панели и выезжает снизу */
@media (max-width: 860px) {
  .chat { left: 0; right: 0; width: auto; }
  .chat__panel { height: min(88vh, 100%); height: min(88dvh, 100%); transform: translateY(100%); box-shadow: none; visibility: hidden; transition: transform .6s var(--ease), visibility 0s .6s; }
  .chat.is-open .chat__panel { visibility: visible; transition: transform .6s var(--ease), visibility 0s; }
  .chat.is-open .chat__panel { transform: none; box-shadow: 0 0 0 100vmax #020b474d, 0 -8px 30px #020b4733; }
  .chat__teaser { right: 14px; width: min(300px, calc(100vw - 28px)); bottom: calc(84px + env(safe-area-inset-bottom)); }
  body:has(.mbuy.is-shown) .chat__teaser { bottom: calc(148px + env(safe-area-inset-bottom)); }
  .chat__form { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .chat__input textarea { font-size: 16px; } /* без автоматического увеличения на iPhone */
}
@media (prefers-reduced-motion: reduce) {
  .chat__panel, .cmsg, .chat__quick, .chat__offer, .chat__teaser, .chat__arrow { animation: none !important; transition: none !important; }
}

/* непрочитанное сообщение менеджера на телефоне: точка на кнопке «Чат» */
.mbar [data-chat-open] { position: relative; }
.mbar [data-chat-open].has-unread::after { content: ""; position: absolute; top: 4px; right: calc(50% - 16px); width: 9px; height: 9px; border: 2px solid var(--bg); border-radius: 50%; background: var(--signal); animation: chat-pop .4s var(--ease) both; }
