/* Окно чата. Цвета и размеры из правил в начале store.css. */
.chat__open {
  position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 34;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 56px; height: 56px; padding: 0; border: 0; border-radius: 999px;
  background: var(--brand); color: #fff; font: inherit; font-weight: 600; font-size: 15px; cursor: pointer;
  box-shadow: var(--shadow); transition: background .15s, transform .1s;
}
.chat__open span { display: none; }
.chat__open .i { width: 24px; height: 24px; }
.chat__open:active { transform: scale(.97); }
.chat.is-open .chat__open { display: none; }
.chat__unread {
  position: absolute; top: -2px; right: -2px; min-width: 22px; height: 22px; padding: 0 4px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 999px; background: var(--sun); color: var(--brand-dark); font-size: 13px; font-weight: 700;
}
.chat__unread[hidden] { display: none; }
/* над панелью покупки на телефоне; пока заполняют форму, кнопка не мешает */
body:has(.buybar.is-on) .chat__open { bottom: calc(84px + env(safe-area-inset-bottom)); }
@media (max-width: 719px) {
  body:has(.field input:focus, .field textarea:focus, .search input:focus) .chat__open { display: none; }
}
@media (min-width: 960px) {
  .chat__open { right: 24px; bottom: 24px; width: auto; padding: 0 20px; }
  .chat__open span { display: inline; }
}
@media (hover: hover) { .chat__open:hover { background: var(--brand-hover); } }

.chat__panel {
  --chat-h: 100dvh;
  position: fixed; inset: 0 0 auto 0; z-index: 90; height: var(--chat-h);
  display: flex; flex-direction: column; background: var(--surface); color: var(--ink);
}
.chat__panel[hidden] { display: none; }
@media (min-width: 720px) {
  .chat__panel {
    inset: auto 24px 24px auto; width: 400px; height: min(640px, calc(100dvh - 48px));
    border-radius: var(--r-lg); box-shadow: var(--shadow-lg); overflow: hidden;
  }
}
html.chat-locked, html.chat-locked body { overflow: hidden; }

.chat__head { flex: none; display: flex; align-items: center; gap: 12px; padding: 12px 8px 12px 16px; border-bottom: 1px solid var(--line); }
.chat__avatar { flex: none; width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center; border-radius: 999px; background: var(--sun-soft); color: var(--brand-dark); font-weight: 700; font-size: 18px; }
.chat__who { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.chat__who b { font-size: 16px; font-weight: 600; }
.chat__who small { font-size: 13px; color: var(--ink-3); }
.chat__close { flex: none; width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: 999px; background: none; color: inherit; cursor: pointer; }
@media (hover: hover) { .chat__close:hover { background: var(--surface-2); } }

.chat__list { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; display: flex; flex-direction: column; gap: 8px; padding: 16px; }
.chat__msg { max-width: 86%; padding: 8px 12px; border-radius: 16px; font-size: 15px; line-height: 1.4; white-space: pre-wrap; overflow-wrap: anywhere; }
.chat__msg--assistant, .chat__msg--manager { align-self: flex-start; background: var(--surface-2); border-bottom-left-radius: 4px; }
.chat__msg--manager { background: var(--sun-soft); }
.chat__msg--user { align-self: flex-end; background: var(--brand); color: #fff; border-bottom-right-radius: 4px; }
.chat__msg--note { align-self: center; max-width: 100%; background: none; color: var(--ink-3); font-size: 14px; text-align: center; }
.chat__retry { padding: 4px; border: 0; background: none; color: var(--sun-ink); font: inherit; font-weight: 600; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }

.chat__typing { display: inline-flex; gap: 4px; align-items: center; height: 36px; }
.chat__typing i { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); animation: chat-dot 1.2s infinite ease-in-out; }
.chat__typing i:nth-child(2) { animation-delay: .15s; }
.chat__typing i:nth-child(3) { animation-delay: .3s; }
@keyframes chat-dot { 0%, 60%, 100% { opacity: .3; transform: none; } 30% { opacity: 1; transform: translateY(-3px); } }
@media (prefers-reduced-motion: reduce) { .chat__typing i { animation: none; opacity: .6; } }

.chat__chips { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 4px; }
.chat__chip { min-height: 40px; padding: 4px 12px; border: 1px solid var(--line-2); border-radius: 999px; background: var(--surface); color: inherit; font: inherit; font-size: 14px; cursor: pointer; text-align: left; }
@media (hover: hover) { .chat__chip:hover { border-color: var(--brand); } }

.chat__cards { display: flex; flex-direction: column; gap: 8px; }
.chat-card { display: flex; align-items: center; gap: 8px; padding: 8px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.chat-card__link { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.chat-card__link img { flex: none; width: 56px; height: 56px; border-radius: 8px; object-fit: cover; background: var(--surface-2); }
.chat-card__text { min-width: 0; display: flex; flex-direction: column; font-size: 14px; line-height: 1.3; }
.chat-card__text b { font-weight: 500; }
.chat-card__text small { font-size: 13px; color: var(--ink-3); }
.chat-card__text em { font-style: normal; font-weight: 700; }
.chat-card--out .chat-card__text em { font-weight: 500; color: var(--ink-3); }
.chat-card--out img { filter: grayscale(.8) opacity(.6); }
.chat-card__add { flex: none; min-height: 40px; padding: 4px 12px; border: 0; border-radius: 8px; background: var(--brand-soft); color: var(--brand); font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.chat-card__add:disabled { opacity: .7; cursor: default; }
@media (hover: hover) { .chat-card__add:not(:disabled):hover { background: var(--brand); color: #fff; } .chat-card__link:hover b { color: var(--sun-ink); } }

.chat-order { display: flex; flex-direction: column; gap: 4px; padding: 12px; border-radius: 12px; background: var(--sun-soft); color: inherit; font-size: 14px; text-decoration: none; }
.chat-order b { font-size: 15px; font-weight: 700; }
.chat-order span { text-decoration: underline; text-underline-offset: 3px; }

.chat__form { flex: none; display: flex; align-items: flex-end; gap: 8px; padding: 8px 8px calc(8px + env(safe-area-inset-bottom)) 16px; border-top: 1px solid var(--line); }
.chat__form textarea { flex: 1; min-width: 0; min-height: 44px; max-height: 120px; padding: 10px 12px; border: 1px solid var(--field-line, var(--line-2)); border-radius: 12px; background: var(--surface); color: inherit; font: inherit; font-size: 16px; line-height: 1.4; resize: none; }
.chat__form button { flex: none; width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: 999px; background: var(--brand); color: #fff; cursor: pointer; }
.chat__form button:disabled { opacity: .5; cursor: default; }
@media print { .chat { display: none; } }
