/* Чат витрины — тёмное окно поверх любой страницы. Токены — на .avc, страницу не меняют.
   Цвет бренда — --brand (оттенки через color-mix). Телефон < 640 px: окно на весь экран, зоны нажатия >= 44 px. */
.avc {
  --avc-brand: var(--brand, #1F5FAD);
  --avc-bg: #0f1012;
  --avc-head: #050505;
  --avc-surface: #141518;
  --avc-field: #0c0c0c;
  --avc-line: rgba(255, 255, 255, .08);
  --avc-line-soft: rgba(255, 255, 255, .06);
  --avc-line-strong: rgba(255, 255, 255, .1);
  --avc-text: #e8e9f2;
  --avc-white: #fff;
  --avc-muted: #8c8e9e;
  --avc-eyebrow: #80818e;
  --avc-warn: #f5c451;
  --avc-ok: #3ccf8e;
  --avc-ok-bg: #12241b;
  --avc-ok-line: #1f3a2c;
  --avc-danger: #ff8a7a;
  --avc-ring: rgba(255, 255, 255, .72);
  --avc-accent: color-mix(in srgb, var(--avc-brand) 62%, #fff);
  --avc-tap: 44px;
  font: 450 15px/1.5 var(--font, "Manrope Variable", Manrope, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif);
  color: var(--avc-text);
  -webkit-font-smoothing: antialiased;
}
.avc *, .avc *::before, .avc *::after { box-sizing: border-box; }
.avc [hidden] { display: none !important; }
.avc .icon { width: 1em; height: 1em; flex: none; }
.avc-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.avc :where(button, a, input, textarea):focus-visible { outline: 2px solid var(--avc-ring); outline-offset: 2px; }

/* --- Кнопка-лаунчер: сообщение / крестик ---------------------------------------------------- */
.avc-fab {
  position: fixed; right: 20px; bottom: 20px; z-index: 1000;
  display: inline-flex; align-items: center; justify-content: center;
  width: 66px; height: 66px; padding: 0; border-radius: 50%; cursor: pointer;
  background: rgba(22, 22, 26, .95); color: var(--avc-white);
  border: .5px solid rgba(255, 255, 255, .14);
  box-shadow: 0 4px 18px rgba(0, 0, 0, .45);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  transition: transform .18s ease, background-color .18s ease;
}
.avc-fab:hover { transform: translateY(-1px); background: rgba(30, 30, 36, .97); }
.avc-fab .icon { width: 27px; height: 27px; }
.avc-fab-open, .avc-fab-close { display: inline-flex; }
.avc-fab-close { display: none; color: var(--avc-accent); }
.avc.avc-open .avc-fab-open { display: none; }
.avc.avc-open .avc-fab-close { display: inline-flex; }

/* --- Окно ----------------------------------------------------------------------------------- */
.avc-panel {
  position: fixed; right: 20px; bottom: 98px; z-index: 1001;
  display: flex; flex-direction: column;
  width: 380px; height: min(560px, calc(100vh - 118px)); height: min(560px, calc(100dvh - 118px));
  background: var(--avc-bg); color: var(--avc-text);
  border: 1px solid var(--avc-line-strong); border-radius: 22px; overflow: hidden;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .6);
  transform-origin: bottom right;
  animation: avc-in .2s cubic-bezier(.2, .8, .2, 1);
}
@keyframes avc-in { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }

/* Шапка */
.avc-head {
  flex: none; display: flex; align-items: center; gap: 12px;
  height: 64px; padding: 0 12px 0 16px;
  background: var(--avc-head); border-bottom: 1px solid var(--avc-line-soft);
}
.avc-tile {
  flex: none; display: inline-flex; align-items: center; justify-content: center; overflow: hidden;
  width: 36px; height: 36px; border-radius: 12px; color: var(--avc-white);
  border: 1px solid var(--avc-line);
  background: linear-gradient(135deg, #0b0e17 0%, color-mix(in srgb, var(--avc-brand) 22%, #0e0f18) 50%, color-mix(in srgb, var(--avc-brand) 55%, #120f1c) 100%);
}
.avc-tile .icon { width: 19px; height: 19px; }
.avc-tile img { width: 100%; height: 100%; object-fit: cover; }
.avc-head-text { flex: 1; min-width: 0; }
.avc-title {
  font-size: 15px; font-weight: 600; line-height: 1.25; color: var(--avc-white);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.avc-status {
  margin-top: 2px; font-size: 11.5px; line-height: 1.3; color: var(--avc-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.avc-status-warn { color: var(--avc-warn); }
.avc-status-ok { color: var(--avc-ok); }
.avc-status-dot { display: inline-block; width: 6px; height: 6px; margin-right: 6px; border-radius: 50%; background: var(--avc-ok); vertical-align: 1px; }
.avc-close {
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; padding: 0; border: 0; border-radius: 10px; cursor: pointer;
  background: transparent; color: var(--avc-muted); transition: color .15s, background-color .15s;
}
.avc-close:hover { color: var(--avc-white); background: rgba(255, 255, 255, .05); }
.avc-close .icon { width: 20px; height: 20px; }

/* Тело */
.avc-body {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  padding: 18px 16px; scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, .14) transparent;
}
.avc-body::-webkit-scrollbar { width: 6px; }
.avc-body::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .14); border-radius: 6px; }
.avc-body::-webkit-scrollbar-track { background: transparent; }

/* --- Приветственный экран ------------------------------------------------------------------- */
.avc-welcome { margin-bottom: 18px; }
.avc .avc-hello { margin: 2px 0 6px; font-size: 20px; line-height: 1.25; font-weight: 600; letter-spacing: -.01em; color: var(--avc-white); }
.avc-hello-text { margin: 0; font-size: 13.5px; line-height: 1.5; color: var(--avc-muted); }
.avc-eyebrow {
  margin: 22px 0 10px; font-size: 11px; font-weight: 600; line-height: 1.2;
  text-transform: uppercase; letter-spacing: .09em; color: var(--avc-eyebrow);
}
.avc-topics {
  list-style: none; margin: 0; padding: 0; overflow: hidden;
  background: var(--avc-surface); border: 1px solid var(--avc-line); border-radius: 16px;
}
.avc-topics li + li { border-top: 1px solid var(--avc-line-soft); }
.avc-topic {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 52px; padding: 10px 14px;
  border: 0; background: transparent; color: var(--avc-text); cursor: pointer; text-align: left;
  font: inherit; transition: background-color .15s;
}
.avc-topic:hover { background: rgba(255, 255, 255, .02); }
.avc-topic:focus-visible { outline-offset: -2px; }
.avc-topic-ico {
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 10px; color: var(--avc-accent);
  background: rgba(255, 255, 255, .04); border: 1px solid var(--avc-line-soft);
}
.avc-topic-ico .icon { width: 17px; height: 17px; }
.avc-topic-name { flex: 1; min-width: 0; font-size: 14px; font-weight: 500; line-height: 1.3; }
.avc-topic .avc-topic-go { width: 16px; height: 16px; color: var(--avc-muted); transition: transform .15s, color .15s; }
.avc-topic:hover .avc-topic-go { color: var(--avc-text); transform: translateX(2px); }

/* Пока приветствие на экране — приветствие помощника и быстрые ответы прячем (они в списке тем) */
.avc-welcoming .avc-msg-greeting, .avc-welcoming .avc-quick { display: none; }

/* --- Сообщения ------------------------------------------------------------------------------ */
.avc-msg { display: flex; align-items: flex-end; gap: 8px; margin: 0 0 14px; }
.avc-msg-buyer { justify-content: flex-end; }
.avc-ava {
  flex: none; display: inline-flex; align-items: center; justify-content: center; overflow: hidden;
  width: 32px; height: 32px; margin-bottom: 20px; border-radius: 50%;
  background: var(--avc-surface); border: 1px solid var(--avc-line-strong); color: var(--avc-text);
}
.avc-ava img { width: 100%; height: 100%; object-fit: cover; }
.avc-ava svg { width: 16px; height: 16px; }
.avc-msg-manager .avc-ava { background: var(--avc-ok-bg); border-color: var(--avc-ok-line); color: var(--avc-ok); }
.avc-col { display: flex; flex-direction: column; min-width: 0; max-width: calc(100% - 40px); }
.avc-msg-buyer .avc-col { align-items: flex-end; max-width: 84%; }
.avc-bubble {
  padding: 10px 14px; border-radius: 16px; font-size: 15px; line-height: 1.5;
  background: var(--avc-surface); border: 1px solid var(--avc-line); color: var(--avc-text);
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.avc-msg-assistant .avc-bubble, .avc-msg-manager .avc-bubble { border-bottom-left-radius: 6px; }
/* Ответ с разметкой (common/rich-text.js): абзацы, списки, жирный */
.avc-text.rt { display: block; white-space: normal; }
.avc-text.rt > * { margin: 0; }
.avc-text.rt > * + * { margin-top: 10px; }
.avc-text.rt ul, .avc-text.rt ol { padding-left: 0; list-style: none; display: grid; gap: 6px; counter-reset: rt; }
.avc-text.rt li { position: relative; padding-left: 18px; }
.avc-text.rt ul > li::before {
  content: ""; position: absolute; left: 4px; top: .68em; width: 5px; height: 5px; border-radius: 50%;
  background: color-mix(in srgb, var(--avc-brand) 70%, var(--avc-text));
}
.avc-text.rt ol > li { counter-increment: rt; padding-left: 22px; }
.avc-text.rt ol > li::before {
  content: counter(rt) "."; position: absolute; left: 0; top: 0; color: var(--avc-muted);
  font-variant-numeric: tabular-nums; font-weight: 600;
}
.avc-text.rt strong { font-weight: 700; color: var(--avc-white, #fff); }
.avc-text.rt .rt-head { font-size: 15.5px; }
.avc-msg-manager .avc-bubble { border-color: var(--avc-ok-line); }
.avc-msg-buyer .avc-bubble {
  border-bottom-right-radius: 6px; color: var(--avc-white);
  background: #1b1d2a; background: color-mix(in srgb, var(--avc-brand) 30%, #0f1012);
  border-color: color-mix(in srgb, var(--avc-brand) 48%, transparent);
}
.avc-meta { margin-top: 5px; padding: 0 4px; font-size: 12px; line-height: 1.2; color: var(--avc-muted); }
.avc-msg-manager .avc-meta-who { color: var(--avc-ok); }

/* Печатает */
.avc-typing .avc-bubble { display: inline-flex; align-items: center; gap: 5px; padding: 14px 16px; }
.avc-typing .avc-ava { margin-bottom: 0; }
.avc-dots { display: inline-flex; gap: 5px; }
.avc-dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--avc-muted); animation: avc-blink 1.2s infinite ease-in-out; }
.avc-dots i:nth-child(2) { animation-delay: .2s; }
.avc-dots i:nth-child(3) { animation-delay: .4s; }
@keyframes avc-blink { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-2px); } }

/* Системное событие — по центру */
.avc-note {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  margin: 4px 0 16px; padding: 0 12px; text-align: center; font-size: 12.5px; line-height: 1.4; color: var(--avc-muted);
}
.avc-note .icon { width: 14px; height: 14px; }
.avc-note-warn { color: var(--avc-warn); }

/* Ошибка с повтором */
.avc-error-line {
  display: flex; align-items: center; gap: 10px; margin: 0 0 14px 40px; padding: 10px 10px 10px 14px;
  border: 1px solid rgba(255, 138, 122, .22); border-radius: 14px; background: rgba(255, 138, 122, .06);
  color: var(--avc-danger); font-size: 13.5px; line-height: 1.4;
}
.avc-error-line > .icon { width: 16px; height: 16px; }
.avc-error-line > span { flex: 1; min-width: 0; }

/* Кнопка-действие (быстрые ответы, повтор) */
.avc-chip {
  flex: none; display: inline-flex; align-items: center; gap: 8px;
  min-height: var(--avc-tap); padding: 0 14px; border-radius: 12px; cursor: pointer;
  background: var(--avc-field); color: var(--avc-text); border: 1px solid var(--avc-line-strong);
  font: inherit; font-size: 14px; font-weight: 500; line-height: 1.2; text-align: left;
  transition: background-color .15s, border-color .15s;
}
.avc-chip:hover { background: #17181c; border-color: rgba(255, 255, 255, .18); }
.avc-chip .icon { width: 16px; height: 16px; color: var(--avc-muted); }
.avc-error-line .avc-chip { min-height: 36px; padding: 0 12px; font-size: 13px; color: var(--avc-text); }

/* Быстрые ответы — под последним сообщением помощника */
.avc-quick { display: flex; flex-wrap: wrap; gap: 8px; margin: -4px 0 14px 40px; }
.avc-quick:empty { display: none; }

/* --- Карточки машин ------------------------------------------------------------------------- */
.avc-cars {
  display: flex; gap: 10px; margin: -4px -16px 16px 0; padding: 0 16px 6px 40px;
  overflow-x: auto; scroll-snap-type: x proximity; scroll-padding-left: 40px; -webkit-overflow-scrolling: touch;
  scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, .12) transparent;
}
.avc-car {
  flex: none; width: 224px; scroll-snap-align: start; display: flex; flex-direction: column;
  background: var(--avc-surface); border: 1px solid var(--avc-line); border-radius: 16px; overflow: hidden;
}
.avc-car-photo { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; background: #1b1c20; display: block; }
.avc-car-body { padding: 10px 12px 4px; flex: 1; }
.avc-car-title { font-size: 14px; font-weight: 600; line-height: 1.3; color: var(--avc-white); overflow-wrap: anywhere; }
.avc-car-meta { margin-top: 2px; color: var(--avc-muted); font-size: 12.5px; }
.avc-car-price { margin-top: 6px; font-size: 15px; font-weight: 700; color: var(--avc-white); font-variant-numeric: tabular-nums; }
.avc-car-price-note { display: block; margin-top: 1px; font-size: 11.5px; font-weight: 500; color: var(--avc-muted); }
.avc-car-actions { display: flex; gap: 6px; padding: 8px 12px 12px; }
.avc-car-btn {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px;
  padding: 0 10px; border-radius: 12px; font: inherit; font-size: 13.5px; font-weight: 600; text-decoration: none; cursor: pointer;
  background: var(--avc-field); color: var(--avc-text); border: 1px solid var(--avc-line-strong);
}
.avc-car-btn:hover { background: #17181c; }
.avc-car-btn .icon { width: 14px; height: 14px; }
.avc-car-btn-main { background: var(--avc-white); color: #0b0b0d; border-color: var(--avc-white); }
.avc-car-btn-main:hover { background: #e9e9ee; }

/* --- Карточка статуса и форма контакта ----------------------------------------------------- */
.avc-card, .avc-contact {
  margin: 4px 0 16px; padding: 18px 16px 14px; text-align: center;
  background: var(--avc-surface); border: 1px solid var(--avc-line); border-radius: 18px;
}
.avc-card-ico {
  display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; margin: 0 auto 10px;
  border-radius: 12px; background: rgba(255, 255, 255, .04); border: 1px solid var(--avc-line); color: var(--avc-accent);
}
.avc-card-ico .icon { width: 19px; height: 19px; }
.avc-card-ok .avc-card-ico { color: var(--avc-ok); background: var(--avc-ok-bg); border-color: var(--avc-ok-line); }
.avc-card-title, .avc-contact-title { margin: 0 0 4px; font-size: 15px; font-weight: 600; line-height: 1.35; color: var(--avc-white); }
.avc-card-text { margin: 0 0 14px; font-size: 13.5px; line-height: 1.5; color: var(--avc-muted); }
.avc-card-caption { margin: 10px 0 0; font-size: 12px; color: var(--avc-muted); }
.avc-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: var(--avc-tap); padding: 0 16px; border-radius: 12px; cursor: pointer;
  background: var(--avc-white); color: #0b0b0d; border: 1px solid var(--avc-white);
  font: inherit; font-size: 14.5px; font-weight: 600; transition: background-color .15s, opacity .15s;
}
.avc-btn:hover { background: #e9e9ee; }
.avc-btn .icon { width: 16px; height: 16px; }
.avc-btn-ghost { background: transparent; color: var(--avc-text); border-color: var(--avc-line-strong); }
.avc-btn-ghost:hover { background: rgba(255, 255, 255, .04); }
.avc-btn[disabled] { opacity: .55; cursor: default; }

.avc-contact { display: grid; gap: 12px; text-align: left; }
.avc-contact .avc-card-ico { margin-bottom: 0; }
.avc-contact-title { margin: 0; text-align: center; }
.avc-contact label { display: grid; gap: 6px; font-size: 12.5px; font-weight: 500; color: var(--avc-muted); }
.avc .avc-contact input[type="text"] {
  width: 100%; min-height: var(--avc-tap); padding: 10px 12px; margin: 0;
  background: var(--avc-field); color: var(--avc-text); border: 1px solid var(--avc-line-strong); border-radius: 12px;
  font: inherit; font-size: 16px; box-shadow: none;
}
.avc .avc-contact input[type="text"]::placeholder { color: #5d5f6c; }
.avc .avc-contact input[type="text"]:focus { outline: none; border-color: var(--avc-accent); box-shadow: none; }
.avc-contact label.avc-consent { display: flex; gap: 10px; align-items: flex-start; font-size: 12.5px; line-height: 1.45; color: var(--avc-muted); }
.avc-contact label.avc-consent a { color: var(--avc-text); }
.avc .avc-consent input { flex: none; width: 20px; height: 20px; margin: 0; accent-color: var(--avc-accent); }
.avc-contact-error { margin: 0; color: var(--avc-danger); font-size: 13px; }
.avc-contact-actions { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.avc-contact-actions .avc-btn-ghost { width: auto; }

/* --- Подвал: поле и отправка ---------------------------------------------------------------- */
.avc-form {
  flex: none; display: flex; align-items: flex-end; gap: 8px;
  padding: 12px 12px 16px; padding-bottom: max(16px, env(safe-area-inset-bottom));
  background: var(--avc-head); border-top: 1px solid var(--avc-line-soft);
}
.avc-field {
  flex: 1; min-width: 0; display: flex; align-items: center; min-height: var(--avc-tap);
  background: var(--avc-field); border: 1px solid var(--avc-line-strong); border-radius: 12px;
  transition: border-color .15s;
}
.avc-field:focus-within { border-color: var(--avc-accent); }
.avc .avc-field textarea {
  display: block; width: 100%; min-height: 42px; max-height: 124px; margin: 0; padding: 11px 14px; resize: none;
  background: transparent; border: 0; border-radius: 12px; box-shadow: none; outline: none;
  color: var(--avc-text); font: inherit; font-size: 14px; line-height: 20px;
  overflow-y: hidden; scrollbar-width: thin;
}
.avc .avc-field textarea:focus-visible { outline: none; box-shadow: none; }
.avc .avc-field textarea::placeholder { color: #5d5f6c; }
.avc-send {
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; padding: 0; border: 0; border-radius: 12px; cursor: pointer;
  background: var(--avc-white); color: #0b0b0d;
  box-shadow: 0 8px 22px -12px rgba(255, 255, 255, .45);
  transition: background-color .15s, opacity .15s, box-shadow .15s;
}
.avc-send .icon { width: 20px; height: 20px; stroke-width: 2.2; }
.avc-send:hover:not(:disabled) { background: #e9e9ee; }
.avc-send:disabled { background: #2a2b31; color: #6c6e7a; box-shadow: none; cursor: default; }

@media (prefers-reduced-motion: reduce) {
  .avc-panel { animation: none; }
  .avc-dots i { animation: none; opacity: .6; }
  .avc-fab, .avc-topic .avc-topic-go { transition: none; }
}

/* --- Телефон: окно на весь экран ----------------------------------------------------------- */
@media (max-width: 639px) {
  .avc-panel {
    inset: 0; width: 100%; height: 100vh; height: 100dvh; max-height: none;
    border: 0; border-radius: 0; box-shadow: none; animation-name: avc-in-phone;
    padding-top: env(safe-area-inset-top); background: var(--avc-head);
  }
  .avc-body { background: var(--avc-bg); }
  .avc-fab { right: 16px; bottom: 16px; bottom: max(16px, env(safe-area-inset-bottom)); width: 60px; height: 60px; }
  .avc.avc-open .avc-fab { display: none; }
  .avc .avc-field textarea { font-size: 16px; }  /* iOS не увеличивает страницу при фокусе */
  html.avc-lock, html.avc-lock body { overflow: hidden; }
}
@keyframes avc-in-phone { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }

/* --- Страница внутри iframe: окно занимает всё, рамку и тень даёт виджет на сайте ---------- */
.avc-is-embed .avc-panel {
  position: fixed; inset: 0; width: 100%; height: 100%; max-height: none;
  border: 0; border-radius: 0; box-shadow: none; animation: none;
}
.avc-embed-body { background: #0f1012; }
