/* AI-консультант. Оформление наследуется от скина: assistant.js читает со страницы фон,
   цвет текста, шрифт и цвет главной кнопки и кладёт их в --as-*. Скин может задать
   цвета и явно — переменными --assistant-accent/-on-accent/-bg/-ink/-font. */
.as {
  --as-accent: var(--assistant-accent, #2563eb);
  --as-on-accent: var(--assistant-on-accent, #fff);
  --as-bg: var(--assistant-bg, #0d1016);
  --as-ink: var(--assistant-ink, #f6f2ea);
  --as-font: var(--assistant-font, 'Manrope', system-ui, sans-serif);
  --as-muted: color-mix(in srgb, var(--as-ink) 60%, transparent);
  --as-line: color-mix(in srgb, var(--as-ink) 14%, transparent);
  --as-soft: color-mix(in srgb, var(--as-ink) 7%, transparent);
  --as-shadow: rgba(0, 0, 0, .45);
  position: fixed; right: 20px; bottom: 20px; z-index: 60;
  font-size: 14px; line-height: 1.5; font-family: var(--as-font); color: var(--as-ink);
}
/* Скины стилизуют теги глобально (section, header, p, form, label — отступы, рамки):
   внутри виджета обнуляем, иначе чужие отступы съедают место переписки. */
.as *, .as *::before, .as *::after { box-sizing: border-box; }
.as p, .as form, .as label, .as small, .as b { margin: 0; }
.as-panel, .as-head, .as-log, .as-start, .as-form { margin: 0; min-height: 0; max-width: none; }
.as[data-scheme="light"] { --as-shadow: rgba(20, 24, 40, .18); }
.as-fab {
  display: flex; align-items: center; gap: 8px; padding: 12px 18px; border: 0; border-radius: 999px;
  background: var(--as-accent); color: var(--as-on-accent); font: inherit; font-weight: 700; cursor: pointer;
  box-shadow: 0 10px 30px var(--as-shadow);
}
.as-fab:hover { filter: brightness(1.06); }
.as-fab-label { display: grid; text-align: left; line-height: 1.15; }
.as-fab-label small { font-size: 11px; font-weight: 600; opacity: .7; }
.as-spark { flex: none; }
.as[data-open="true"] .as-fab { display: none; }
.as-panel { padding: 0;
  display: flex; flex-direction: column; width: min(380px, calc(100vw - 32px)); height: min(560px, calc(100dvh - 40px));
  background: var(--as-bg); border: 1px solid var(--as-line); border-radius: 18px; overflow: hidden;
  box-shadow: 0 24px 60px var(--as-shadow);
}
.as-panel[hidden] { display: none; }
/* Открытый чат — поверх плавающих кнопок и панелей скина (кинорежим, «Оформить», липкие шапки). */
.as[data-open="true"] { z-index: 1000; }
.as-head { flex: none; display: flex; align-items: center; gap: 10px; padding: 10px 12px 10px 16px; border-bottom: 1px solid var(--as-line); }
.as-head b { display: block; font-size: 15px; }
.as-head small { display: block; color: var(--as-muted); font-size: 12px; }
.as-dot { width: 9px; height: 9px; border-radius: 50%; background: #4ade80; box-shadow: 0 0 0 4px rgba(74, 222, 128, .15); flex: none; }
.as-close { margin-left: auto; width: 32px; height: 32px; border: 0; border-radius: 8px; background: transparent; color: var(--as-muted); font-size: 24px; line-height: 1; cursor: pointer; }
.as-close:hover { color: var(--as-ink); background: var(--as-soft); }
.as-log { flex: 1 1 auto; min-height: 96px; overflow-y: auto; padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; overscroll-behavior: contain; }
.as-msg { margin: 0; max-width: 86%; padding: 9px 13px; border-radius: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.as-msg--bot { align-self: flex-start; background: var(--as-soft); border-bottom-left-radius: 4px; }
.as-msg--me { align-self: flex-end; background: var(--as-accent); color: var(--as-on-accent); border-bottom-right-radius: 4px; }
/* Ответ менеджера из Telegram — живой человек, не консультант: своя подпись и рамка цвета сайта. */
.as-msg--manager { align-self: flex-start; background: var(--as-soft); border: 1px solid color-mix(in srgb, var(--as-accent) 55%, transparent); border-bottom-left-radius: 4px; }
.as-who { display: block; margin-bottom: 2px; font-size: 11px; font-weight: 700; letter-spacing: .02em; color: var(--as-muted); }
.as-who::before { content: "👤 "; }
.as-fab { position: relative; }
.as-badge { position: absolute; top: -6px; right: -6px; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
  background: #ef4444; color: #fff; font-size: 12px; font-weight: 700; line-height: 20px; text-align: center; }
.as-badge[hidden] { display: none; }
.as-msg--note { align-self: center; max-width: 100%; font-size: 12px; color: var(--as-muted); background: transparent; text-align: center; }
.as-typing { display: inline-flex; gap: 4px; }
.as-typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--as-muted); animation: as-blink 1s infinite; }
.as-typing i:nth-child(2) { animation-delay: .15s; } .as-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes as-blink { 50% { opacity: .25; } }
.as-form { flex: none; display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--as-line); }
.as-form textarea {
  flex: 1; resize: none; max-height: 120px; padding: 10px 12px; border: 1px solid var(--as-line); border-radius: 12px;
  background: var(--as-soft); color: var(--as-ink); font: inherit;
}
.as-form textarea:focus { outline: none; border-color: var(--as-accent); }
.as-form button { width: 44px; border: 0; border-radius: 12px; background: var(--as-accent); color: var(--as-on-accent); cursor: pointer; }
.as-form button:disabled { opacity: .5; cursor: default; }
.as-start { flex: none; display: grid; gap: 6px; padding: 0 16px 12px; }
.as-start[hidden], .as-form[hidden] { display: none; }
.as-start label { display: grid; gap: 4px; font-size: 12px; color: var(--as-muted); }
.as-start input {
  padding: 10px 12px; border: 1px solid var(--as-line); border-radius: 12px;
  background: var(--as-soft); color: var(--as-ink); font: inherit; font-size: 15px;
}
.as-start input:focus { outline: none; border-color: var(--as-accent); }
.as-start input[aria-invalid="true"] { border-color: #f87171; }
.as-err { min-height: 0; font-size: 12px; color: #f87171; }
.as-err:empty { display: none; }
.as-start button { margin-top: 6px; padding: 11px; border: 0; border-radius: 12px; background: var(--as-accent); color: var(--as-on-accent); font: inherit; font-weight: 700; cursor: pointer; }
.as-start button:disabled { opacity: .5; }
.as-start small { font-size: 11px; color: var(--as-muted); }
.as-start small a { color: inherit; text-decoration: underline; }
.as-note { flex: none; padding: 0 14px 8px; font-size: 11px; line-height: 1.35; color: var(--as-muted); }
.as-note a { color: inherit; text-decoration: underline; }
@media (max-width: 480px) {
  .as { right: 12px; bottom: 12px; }
  .as[data-open="true"] { left: 8px; right: 8px; bottom: 8px; }
  .as-panel { width: 100%; height: calc(100dvh - 16px); }
  .as-fab-label small { display: none; }
  .as-fab { padding: 12px 16px; }
  /* Мельче 16px — iPhone приближает страницу при фокусе на поле. */
  .as-start input, .as-form textarea { font-size: 16px; }
}
@media (prefers-reduced-motion: reduce) { .as-typing i { animation: none; } }
