/* SMART X — AI-оператор витрины (разметку строит public/js/assistant.js).
   Все классы с префиксом ast-, цвета — только токены main.css: виджет сам
   подстраивается под день/ночь и эффект стекла. Движение — transform и
   opacity; каждый @keyframes — внутри prefers-reduced-motion: no-preference,
   как требует свод запретов в main.css. */

.ast {
  /* нижний отступ кнопки уже учитывает «чёлку» снизу (home indicator) */
  --ast-base: calc(20px + env(safe-area-inset-bottom));
  --ast-side: calc(20px + env(safe-area-inset-right));
  --ast-size: 56px;
  /* --ast-lift-y выставляет скрипт: насколько поднять кнопку над панелью
     покупки (.buy-bar) или корзины (.cart-bar) */
  --ast-bg: var(--surface);
  --ast-ring: var(--surface);
  --ast-shadow: 0 28px 70px rgba(0, 0, 0, 0.62), 0 2px 10px rgba(0, 0, 0, 0.4);
  --ast-glow: 0 10px 28px rgba(53, 224, 134, 0.3), 0 2px 8px rgba(0, 0, 0, 0.32);
  --ast-glow-hover: 0 14px 36px rgba(53, 224, 134, 0.42), 0 2px 8px rgba(0, 0, 0, 0.32);
  font-family: var(--font);
}
:root[data-theme='light'] .ast {
  --ast-shadow: 0 26px 64px rgba(15, 23, 42, 0.16), 0 2px 10px rgba(15, 23, 42, 0.07);
  --ast-glow: 0 10px 26px rgba(11, 122, 70, 0.24), 0 2px 6px rgba(15, 23, 42, 0.12);
  --ast-glow-hover: 0 14px 34px rgba(11, 122, 70, 0.32), 0 2px 6px rgba(15, 23, 42, 0.12);
}
/* Стекло: панель висит над прокручиваемой страницей — здесь размытие
   оправдано (белый список glass). Плёнка плотнее карточек: в чате мелкий
   текст, и пятна фона не должны проступать сквозь него. */
:root[data-glass='on'] .ast {
  --ast-bg: rgba(16, 18, 26, 0.66);
  --ast-ring: var(--bg);
}
:root[data-theme='light'][data-glass='on'] .ast {
  --ast-bg: rgba(255, 255, 255, 0.72);
}

/* Служебный текст только для скринридера */
.ast-sr {
  position: absolute !important;
  width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ============================================================
   Кнопка-ланчер
   ============================================================ */
.ast-launcher {
  position: fixed; z-index: 150;            /* над шапкой (100) и панелями покупки, под тостом (200) */
  right: var(--ast-side);
  bottom: var(--ast-base);
  height: var(--ast-size); min-width: var(--ast-size);
  display: inline-flex; align-items: center;
  padding: 0; border: 0; border-radius: 999px;
  background: var(--accent); color: var(--black);
  box-shadow: var(--ast-glow);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  /* подъём над панелью и отклик на наведение/нажатие — одним transform */
  transform: translate3d(0, calc(var(--ast-lift-y, 0px) * -1 + var(--ast-hover-y, 0px)), 0) scale(var(--ast-press, 1));
  transition:
    transform var(--t-mid) var(--ease-out),
    opacity 160ms ease,
    visibility 0s linear 0s,
    background 160ms ease,
    padding var(--t-mid) var(--ease-out);
}
.ast-launcher-icons {
  position: relative; flex: 0 0 var(--ast-size);
  width: var(--ast-size); height: var(--ast-size);
  display: grid; place-items: center;
}
.ast-ico {
  grid-area: 1 / 1; display: grid; place-items: center;
  transition: transform var(--t-mid) var(--ease-out), opacity 180ms ease;
}
.ast-ico svg { width: 25px; height: 25px; }
.ast-ico-down { opacity: 0; transform: rotate(-90deg) scale(0.6); }
.ast-ico-down svg { width: 24px; height: 24px; }
/* Открытая панель (планшет/десктоп): кнопка превращается в «свернуть» */
.ast.is-open .ast-ico-chat { opacity: 0; transform: rotate(60deg) scale(0.6); }
.ast.is-open .ast-ico-down { opacity: 1; transform: none; }

/* Подпись «Задать вопрос» — только при первом появлении на широком экране */
.ast-launcher-label {
  max-width: 0; opacity: 0; overflow: hidden; white-space: nowrap;
  font-size: 14.5px; font-weight: 700; letter-spacing: -0.01em;
  margin-left: -6px;
  transition: max-width 360ms var(--ease-out), opacity 200ms ease;
}
.ast-launcher--pill { padding-right: 22px; }
.ast-launcher--pill .ast-launcher-label { max-width: 160px; opacity: 1; }

/* Непрочитанный ответ — красная точка с кольцом цвета фона */
.ast-unread {
  position: absolute; top: 3px; right: 3px;
  width: 13px; height: 13px; border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 0 2.5px var(--bg);
  opacity: 0; transform: scale(0);
  transition: opacity 160ms ease, transform var(--t-mid) var(--ease-spring);
  pointer-events: none;
}
.ast-launcher.has-unread .ast-unread { opacity: 1; transform: scale(1); }
.ast.is-open .ast-unread { opacity: 0; }

@media (hover: hover) {
  .ast-launcher:hover {
    --ast-hover-y: -2px;
    background: var(--accent-hover);
    box-shadow: var(--ast-glow-hover);
  }
}
.ast-launcher:active { --ast-press: 0.95; transition-duration: 120ms; }
.ast-launcher:focus-visible {
  outline: 2.5px solid var(--accent-ink);
  outline-offset: 4px;
}

/* Мобильное меню открыто — кнопка уходит, чтобы не накрывать пункты.
   :has — основной путь; класс ast--nav ставит скрипт для старых браузеров. */
body:has(#main-nav.open) .ast-launcher,
.ast.ast--nav .ast-launcher {
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity 160ms ease, visibility 0s linear 160ms;
}

/* Запасной подъём без скрипта (нет ResizeObserver): панели покупки видны до 920px.
   ≈ высота панели (70px + safe-area) + зазор 12px − собственный отступ кнопки */
@media (max-width: 920px) {
  body:has(.buy-bar) .ast:not([data-lift]),
  body:has(.cart-bar:not([hidden])) .ast:not([data-lift]) { --ast-lift-y: 62px; }
}

/* ============================================================
   Панель: плавающая карточка (≥ 640px)
   ============================================================ */
.ast-panel {
  position: fixed; z-index: 160;
  right: var(--ast-side);
  bottom: calc(var(--ast-base) + var(--ast-size) + 14px + var(--ast-lift-y, 0px));
  width: min(380px, calc(100vw - 32px));
  height: min(640px, calc(100vh - 120px - var(--ast-lift-y, 0px)));
  display: flex; flex-direction: column;
  background: var(--ast-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: var(--ast-shadow);
  overflow: hidden;
  /* закрыто: невидима, не ловит нажатия и выпадает из порядка Tab */
  opacity: 0; visibility: hidden; pointer-events: none;
  transform: translate3d(0, 12px, 0) scale(0.96);
  transform-origin: 100% 100%;
  /* уход короткий и честный, въезд — мягкий (асимметрия как у тоста) */
  transition:
    opacity 160ms var(--ease-exit),
    transform 160ms var(--ease-exit),
    visibility 0s linear 160ms;
}
.ast-panel.is-open {
  opacity: 1; visibility: visible; pointer-events: auto;
  transform: none;
  transition:
    opacity var(--t-mid) var(--ease-out),
    transform var(--t-mid) var(--ease-out),
    visibility 0s;
  /* своя группа в переходах между страницами: открытый чат стоит на месте,
     а не «выплывает» вместе с новой страницей */
  view-transition-name: ast-panel;
}
.ast-panel.ast-instant { transition: none !important; }
.ast-launcher { view-transition-name: ast-launcher; }

:root[data-theme='light'] .ast-panel { border-color: var(--border-strong); }
:root[data-glass='on'] .ast-panel {
  backdrop-filter: blur(20px) saturate(1.6);
  -webkit-backdrop-filter: blur(20px) saturate(1.6);
  border-color: var(--border-strong);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14), var(--ast-shadow);
}
:root[data-theme='light'][data-glass='on'] .ast-panel {
  border-color: rgba(255, 255, 255, 0.9);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.95), var(--ast-shadow);
}

/* ---------- Шапка ---------- */
.ast-head {
  position: relative; flex: 0 0 auto;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 8px 12px 16px;
  background: linear-gradient(180deg, var(--glass), transparent);
}
/* тонкая мятная линия под шапкой — фирменная кромка */
.ast-head::after {
  content: ''; position: absolute; left: 16px; right: 16px; bottom: 0; height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent) 50%, transparent);
  opacity: 0.5; pointer-events: none;
}
:root[data-theme='light'] .ast-head::after { opacity: 0.75; }

.ast-avatar {
  position: relative; flex: 0 0 40px;
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 800; letter-spacing: -0.02em;
  color: var(--accent-ink);
  background: radial-gradient(circle at 32% 26%, rgba(53, 224, 134, 0.34), rgba(53, 224, 134, 0.07) 72%);
  border: 1px solid rgba(53, 224, 134, 0.34);
}
:root[data-theme='light'] .ast-avatar { border-color: rgba(11, 122, 70, 0.28); }
/* «в сети» — неподвижная точка, без бесконечных пульсаций */
.ast-avatar::after {
  content: ''; position: absolute; right: -1px; bottom: -1px;
  width: 11px; height: 11px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 2.5px var(--ast-ring);
}

.ast-head-text { flex: 1 1 auto; min-width: 0; }
.ast-title {
  display: flex; align-items: center; gap: 7px;
  font-size: 15.5px; font-weight: 700; letter-spacing: var(--track-tight, -0.02em);
  line-height: 1.25;
}
.ast-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ast-ai {
  flex: 0 0 auto;
  padding: 2px 7px; border-radius: 999px;
  font-size: 10px; font-weight: 800; letter-spacing: 0.08em; line-height: 1.4;
  color: var(--accent-ink); background: var(--accent-dim);
  border: 1px solid rgba(53, 224, 134, 0.3);
}
.ast-status {
  margin-top: 2px;
  font-size: 12.5px; color: var(--text-dim); line-height: 1.3;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.ast-head-actions { flex: 0 0 auto; display: flex; gap: 2px; }
.ast-hbtn {
  width: 44px; height: 44px; border-radius: 999px;
  display: grid; place-items: center;
  border: 0; background: transparent; color: var(--text-dim);
  cursor: pointer; -webkit-tap-highlight-color: transparent;
  transition: background 160ms ease, color 160ms ease, transform 120ms ease;
}
.ast-hbtn svg { width: 19px; height: 19px; }
.ast-hbtn:active { transform: scale(0.94); }
@media (hover: hover) {
  .ast-hbtn:hover { background: var(--glass-strong); color: var(--text); }
}

/* ---------- Лента сообщений ---------- */
.ast-scroll {
  position: relative;                       /* точка отсчёта offsetTop для скрипта */
  flex: 1 1 auto; min-height: 0;
  overflow-y: auto; overflow-x: hidden;
  overscroll-behavior: contain;             /* прокрутка чата не тянет страницу */
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--scroll-thumb) transparent;
}
.ast-scroll::-webkit-scrollbar { width: 8px; }
.ast-scroll::-webkit-scrollbar-thumb { background: var(--scroll-thumb); border-radius: 8px; border: 2px solid transparent; background-clip: padding-box; }

.ast-log {
  display: flex; flex-direction: column; gap: 14px;
  padding: 18px 16px 10px;
}
.ast-msg { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.ast-msg--user { align-items: flex-end; }
.ast-msg--bot { align-items: flex-start; }

.ast-bubble {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 14.5px; line-height: 1.5;
  overflow-wrap: anywhere;
}
.ast-msg--bot .ast-bubble {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-bottom-left-radius: 6px;
}
.ast-msg--user .ast-bubble {
  background: var(--accent-dim);
  border: 1px solid rgba(53, 224, 134, 0.24);
  border-bottom-right-radius: 6px;
  white-space: pre-wrap;                    /* переносы строк из поля ввода */
}
:root[data-theme='light'] .ast-msg--user .ast-bubble { border-color: rgba(11, 122, 70, 0.18); }
.ast-msg--err .ast-bubble { border-color: rgba(242, 85, 90, 0.42); }

/* Разметка ответа: абзацы, пункты, жирный, ссылки */
.ast-bubble p { margin: 0 0 8px; }
.ast-bubble p:last-child, .ast-bubble ul:last-child { margin-bottom: 0; }
.ast-bubble ul { margin: 2px 0 8px; padding-left: 18px; }
.ast-bubble li { margin: 3px 0; padding-left: 2px; }
.ast-bubble li::marker { color: var(--accent-ink); }
.ast-bubble strong { font-weight: 700; }
.ast-bubble a {
  color: var(--accent-ink); font-weight: 600;
  text-decoration: underline; text-decoration-thickness: 1px;
  text-underline-offset: 3px; text-decoration-color: rgba(53, 224, 134, 0.45);
}
.ast-bubble a:hover { text-decoration-color: currentColor; }

/* ---------- Подсказки ---------- */
.ast-chips { display: flex; flex-wrap: wrap; gap: 8px; max-width: 100%; }
.ast-chip {
  min-height: 36px; padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--glass);
  color: var(--text);
  font: 500 13.5px/1.2 var(--font); letter-spacing: -0.005em;
  text-align: left;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease, transform 120ms ease;
}
.ast-chip:active { transform: scale(0.97); }
@media (hover: hover) {
  .ast-chip:hover {
    background: var(--accent-dim);
    border-color: rgba(53, 224, 134, 0.42);
  }
  :root[data-theme='light'] .ast-chip:hover { border-color: rgba(11, 122, 70, 0.35); }
}

/* ---------- Действия под ответом: «Повторить», менеджер ---------- */
.ast-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.ast-mini,
.ast-handoff {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 40px; padding: 9px 16px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--glass);
  color: var(--text);
  font: 600 13.5px/1.2 var(--font);
  text-decoration: none;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
  transition: background 160ms ease, border-color 160ms ease, transform 120ms ease;
}
.ast-mini svg, .ast-handoff svg { width: 17px; height: 17px; flex-shrink: 0; }
.ast-handoff svg { color: var(--accent-ink); }
.ast-mini:active, .ast-handoff:active { transform: scale(0.97); }
@media (hover: hover) {
  .ast-mini:hover, .ast-handoff:hover { background: var(--glass-strong); }
}

/* ---------- Карточки товаров ---------- */
.ast-cards {
  align-self: stretch;
  display: flex; gap: 10px;
  /* лента выходит под края ленты сообщений — карточки листаются «из-за края» */
  margin: 0 -16px; padding: 2px 16px 6px;
  overflow-x: auto; overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scroll-padding: 0 16px;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}
.ast-cards::-webkit-scrollbar { display: none; }
.ast-card {
  flex: 0 0 min(258px, 84%);
  scroll-snap-align: start;
  display: flex; flex-direction: column; gap: 10px;
  padding: 10px;
  border-radius: 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  transition: border-color 160ms ease;
}
@media (hover: hover) {
  .ast-card:hover { border-color: var(--border-strong); }
  .ast-card-link:hover .ast-card-name { color: var(--accent-ink); }
}
.ast-card-link {
  flex: 1 1 auto;
  display: flex; align-items: flex-start; gap: 12px;
  color: inherit; text-decoration: none;
  border-radius: 12px;
}
.ast-card-media {
  flex: 0 0 72px; width: 72px; height: 72px;
  border-radius: 12px; overflow: hidden;
  background: var(--media-bg);                /* тёмная подложка фото — во всех темах */
  display: grid; place-items: center;
}
.ast-card-media img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ast-card-ph { color: rgba(255, 255, 255, 0.35); display: grid; place-items: center; }
.ast-card-ph svg { width: 26px; height: 26px; }
.ast-card-body { min-width: 0; display: flex; flex-direction: column; gap: 5px; padding-top: 1px; }
.ast-card-name {
  font-size: 13.5px; font-weight: 600; line-height: 1.3; letter-spacing: -0.01em;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  transition: color 160ms ease;
}
.ast-card-price { display: flex; align-items: baseline; flex-wrap: wrap; gap: 2px 7px; }
.ast-card-price b { font-size: 15px; font-weight: 700; letter-spacing: -0.02em; white-space: nowrap; }
.ast-card-price b.is-request { font-size: 12.5px; font-weight: 600; color: var(--text-dim); letter-spacing: 0; }
.ast-card-price s { font-size: 12px; color: var(--text-faint); white-space: nowrap; }
.ast-card-badge {
  align-self: flex-start;
  padding: 3px 9px; border-radius: 999px;
  font-size: 10.5px; font-weight: 600; letter-spacing: 0.01em;
  background: var(--glass-strong); color: var(--text-dim);
}
.ast-card-add {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 38px; padding: 8px 14px;
  border: 0; border-radius: 999px;
  background: var(--accent); color: var(--black);
  font: 700 13px/1 var(--font); letter-spacing: -0.005em;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
  transition: background 160ms ease, transform 120ms ease;
}
.ast-card-add svg { width: 16px; height: 16px; flex-shrink: 0; }
.ast-card-add:active { transform: scale(0.97); }
.ast-card-add.is-done { background: var(--accent-dim); color: var(--accent-ink); }
@media (hover: hover) {
  .ast-card-add:hover { background: var(--accent-hover); }
  .ast-card-add.is-done:hover { background: var(--accent-dim); }
}

/* ---------- «Печатает…» ----------
   По умолчанию (и при «уменьшить движение») — неподвижная надпись;
   три прыгающие точки включаются только при разрешённом движении. */
.ast-typing .ast-bubble { padding: 11px 16px; color: var(--text-dim); font-size: 13.5px; }
.ast-dots { display: none; gap: 5px; align-items: center; height: 20px; }
.ast-dots i {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-faint);
}

/* ---------- Поле ввода ---------- */
.ast-compose {
  flex: 0 0 auto;
  padding: 10px 12px 10px;
  border-top: 1px solid var(--border);
}
.ast-field {
  display: flex; align-items: flex-end; gap: 6px;
  padding: 4px 4px 4px 14px;
  border-radius: 24px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  transition: border-color 140ms ease, box-shadow 140ms ease;
}
.ast-field:focus-within {
  border-color: var(--accent-ink);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
/* Селектор двойной: глобальные правила textarea и textarea:focus в main.css
   (рамка, фон, min-height 92px) иначе перебивали бы поле чата */
.ast-field .ast-input,
.ast-field .ast-input:focus {
  flex: 1 1 auto; min-width: 0; width: auto;
  height: 40px;                              /* одна строка; дальше растит скрипт */
  min-height: 40px;
  max-height: 106px;                         /* 4 строки по 22px + отступы */
  padding: 9px 0;
  border: 0; border-radius: 0; outline: 0; background: transparent; resize: none;
  box-shadow: none;
  transition: none;
  color: var(--text);
  font: 400 14.5px/22px var(--font);
  overflow-y: hidden;
  scrollbar-width: thin;
}
.ast-input::placeholder { color: var(--text-faint); opacity: 1; }
.ast-send {
  flex: 0 0 40px; width: 40px; height: 40px;
  border: 0; border-radius: 999px;
  display: grid; place-items: center;
  background: var(--accent); color: var(--black);
  cursor: pointer; -webkit-tap-highlight-color: transparent;
  transition: background 160ms ease, color 160ms ease, transform 120ms ease;
}
.ast-send svg { width: 19px; height: 19px; }
.ast-send:active:not(:disabled) { transform: scale(0.92); }
.ast-send:disabled { background: var(--glass-strong); color: var(--text-faint); cursor: default; }
@media (hover: hover) {
  .ast-send:not(:disabled):hover { background: var(--accent-hover); }
}
.ast-foot {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 7px 8px 0;
  font-size: 11.5px; line-height: 1.3; color: var(--text-faint);
}
.ast-hint { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ast-count { flex: 0 0 auto; font-variant-numeric: tabular-nums; }
.ast-count.is-warn { color: var(--danger); font-weight: 600; }

/* ---------- Кольца фокуса ----------
   Мятный контур в тон сайту; на светлой теме — тёмно-мятный --accent-ink. */
.ast-hbtn:focus-visible,
.ast-chip:focus-visible,
.ast-mini:focus-visible,
.ast-handoff:focus-visible,
.ast-card-add:focus-visible,
.ast-send:focus-visible,
.ast-bubble a:focus-visible {
  outline: 2px solid var(--accent-ink);
  outline-offset: 2px;
}
.ast-card-link:focus-visible { outline: 2px solid var(--accent-ink); outline-offset: 3px; }
.ast-input:focus-visible { outline: none; }  /* кольцо рисует .ast-field:focus-within */

/* ============================================================
   Телефон (< 640px, а также телефон боком — высота < 520px):
   полноэкранный лист. Граница совпадает с PHONE_MQ в assistant.js —
   скрипт по ней же запирает прокрутку и следит за клавиатурой.
   ============================================================ */
@media (max-width: 639.98px), (max-height: 519.98px) {
  .ast {
    --ast-base: calc(16px + env(safe-area-inset-bottom));
    --ast-side: calc(16px + env(safe-area-inset-right));
    --ast-size: 54px;
  }
  .ast-ico svg { width: 24px; height: 24px; }

  /* лист закрывает экран — кнопка под ним не нужна */
  .ast.is-open .ast-launcher { opacity: 0; visibility: hidden; pointer-events: none; }
  /* тост «Добавлено в корзину» занимает почти всю ширину низа экрана —
     кнопка на это время уступает место, а не торчит из-под него */
  body:has(.toast.show) .ast-launcher { opacity: 0; pointer-events: none; }
  /* А пока открыт сам лист, тот же тост (z-index 200) лёг бы на поле ввода,
     и его кнопка «Корзина» ловила бы нажатие, которое целилось в поле.
     Поднимаем тост над формой: её высоту пишет скрипт в --ast-toast-gap.
     Второе правило с :has перебивает подъём тоста у панели корзины
     (cart.css) — там селектор сильнее. */
  html.ast-lock .toast { bottom: var(--ast-toast-gap, calc(84px + env(safe-area-inset-bottom))); }
  html.ast-lock body:has(.ast-panel.is-open) .toast { bottom: var(--ast-toast-gap, calc(84px + env(safe-area-inset-bottom))); }

  .ast-panel {
    /* top и height уточняет скрипт по visualViewport (клавиатура iOS);
       100vh — запас для браузеров без dvh */
    top: 0; left: 0; right: 0; bottom: auto;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    border: 0; border-radius: 0;
    transform: translate3d(0, 12px, 0) scale(0.98);
    transform-origin: 50% 100%;
  }
  .ast-head { padding-top: calc(10px + env(safe-area-inset-top)); padding-left: calc(16px + env(safe-area-inset-left)); padding-right: calc(6px + env(safe-area-inset-right)); }
  .ast-log { padding-left: calc(14px + env(safe-area-inset-left)); padding-right: calc(14px + env(safe-area-inset-right)); }
  .ast-cards { margin: 0 -14px; padding-left: 14px; padding-right: 14px; scroll-padding: 0 14px; }
  .ast-compose { padding: 8px calc(10px + env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) calc(10px + env(safe-area-inset-left)); }
  /* 16px — меньше iOS увеличивает страницу при фокусе на поле */
  .ast-field .ast-input { font-size: 16px; }
  .ast-bubble { max-width: 90%; font-size: 15px; }
  .ast-chip { min-height: 40px; font-size: 14px; }
  .ast-card-add { min-height: 42px; }
  .ast-hint { display: none; }
  .ast-foot { padding-top: 0; justify-content: flex-end; }
  .ast-foot:has(.ast-count:empty) { display: none; }
}

/* Пока лист открыт, страница под ним не прокручивается (класс ставит скрипт,
   он же возвращает прежнюю позицию прокрутки) */
html.ast-lock { overflow: hidden; }
html.ast-lock body {
  position: fixed; left: 0; right: 0; width: 100%;
  overflow: hidden;
}

/* ============================================================
   Деградация стекла: нет backdrop-filter или «уменьшить прозрачность»
   ============================================================ */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  :root[data-glass='on'] .ast { --ast-bg: rgba(14, 16, 22, 0.97); }
  :root[data-theme='light'][data-glass='on'] .ast { --ast-bg: rgba(255, 255, 255, 0.97); }
}
@media (prefers-reduced-transparency: reduce) {
  :root[data-glass='on'] .ast { --ast-bg: rgba(14, 16, 22, 0.97); }
  :root[data-theme='light'][data-glass='on'] .ast { --ast-bg: rgba(255, 255, 255, 0.97); }
  :root[data-glass='on'] .ast-panel { backdrop-filter: none; -webkit-backdrop-filter: none; }
}

/* ============================================================
   Движение
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  .ast-panel, .ast-panel.is-open { transform: none; transition: none; }
  .ast-launcher { transition: opacity 160ms ease, visibility 0s; }
  .ast-ico, .ast-launcher-label, .ast-unread { transition: none; }
}

@media (prefers-reduced-motion: no-preference) {
  /* Кнопка мягко появляется после загрузки. fill-mode backwards: по окончании
     анимация отпускает transform — подъём над панелью работает переходом */
  .ast-launcher { animation: ast-launcher-in var(--t-major) var(--ease-out) 240ms backwards; }
  @keyframes ast-launcher-in {
    from { opacity: 0; transform: translate3d(0, 14px, 0) scale(0.86); }
  }

  /* Пульс-кольцо — один раз за визит (класс снимает скрипт по окончании) */
  .ast-launcher::before {
    content: ''; position: absolute; inset: 0; border-radius: inherit;
    border: 2px solid var(--accent);
    opacity: 0; pointer-events: none;
  }
  .ast-launcher.ast-pulse::before { animation: ast-pulse 1.6s var(--ease-out) 900ms 2; }
  @keyframes ast-pulse {
    0% { opacity: 0.75; transform: scale(1); }
    100% { opacity: 0; transform: scale(1.55); }
  }

  /* Новое сообщение въезжает снизу */
  .ast-msg.ast-new { animation: ast-msg-in 320ms var(--ease-out) both; }
  @keyframes ast-msg-in {
    from { opacity: 0; transform: translate3d(0, 8px, 0); }
  }

  /* «Печатает»: три точки по очереди */
  .ast-typing .ast-dots { display: inline-flex; }
  .ast-typing .ast-typing-text {
    position: absolute; width: 1px; height: 1px; overflow: hidden;
    clip: rect(0 0 0 0); white-space: nowrap;
  }
  .ast-dots i { animation: ast-dot 1.1s ease-in-out infinite; }
  .ast-dots i:nth-child(2) { animation-delay: 0.15s; }
  .ast-dots i:nth-child(3) { animation-delay: 0.3s; }
  @keyframes ast-dot {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.45; }
    30% { transform: translateY(-4px); opacity: 1; }
  }
}

/* Режим монтажника: оптовая цена в карточке чата, метка «опт» как в каталоге */
.ast-opt {
  align-self: center;
  padding: 1px 6px; border-radius: 999px;
  background: var(--accent-dim); color: var(--accent-ink);
  font-size: 9.5px; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase;
  line-height: 1.4;
}
