/* ==========================================================================
   Art Orehova — ИИ-ассистент: кнопка-«пилюля» и окно чата
   Использует токены из styles.css (цвета, радиусы, тени, шрифты).
   ========================================================================== */

.ast {
  position: fixed;
  right: max(22px, env(safe-area-inset-right));
  bottom: max(22px, env(safe-area-inset-bottom));
  z-index: 90;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
  pointer-events: none;
}
.ast > * { pointer-events: auto; }

/* ---------- Кнопка ---------- */
.ast__fab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  height: 58px;
  padding: 0 22px 0 8px;
  border: 0;
  border-radius: var(--r-pill);
  background:
    radial-gradient(80% 120% at 100% 0%, rgba(240, 126, 5, .35) 0%, transparent 60%),
    linear-gradient(120deg, #5E3F82 0%, var(--violet) 55%, #8A5E9E 100%);
  color: #fff;
  font-family: var(--font-sans);
  font-size: .98rem;
  font-weight: 800;
  box-shadow: 0 18px 36px -14px rgba(94, 63, 130, .8), inset 0 0 0 1px rgba(255, 255, 255, .14);
  transition: transform var(--t) var(--ease), box-shadow var(--t) var(--ease), padding .35s var(--ease), gap .35s var(--ease);
}
.ast__fab:hover { transform: translateY(-3px); box-shadow: 0 24px 44px -14px rgba(94, 63, 130, .85), inset 0 0 0 1px rgba(255, 255, 255, .2); }
.ast__fab-icon {
  display: grid;
  place-items: center;
  width: 42px; height: 42px;
  flex-shrink: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 30%, #F8A04A 0%, #E2700C 55%, #C9580A 100%);
  color: #fff;
  box-shadow: 0 6px 14px -6px rgba(240, 126, 5, .9);
  transition: transform .5s var(--ease);
}
.ast__fab-icon .icon { width: 22px; height: 22px; stroke-width: 2; }
.ast__fab:hover .ast__fab-icon { transform: rotate(72deg) scale(1.05); }
.ast__fab-label {
  max-width: 230px;
  overflow: hidden;
  white-space: nowrap;
  transition: max-width .4s var(--ease), opacity .25s var(--ease);
}
.ast__fab-dot {
  position: absolute;
  top: 7px; left: 39px;
  width: 11px; height: 11px;
  border-radius: 50%;
  background: #6AD394;
  box-shadow: 0 0 0 3px #6E4E92;
  animation: astPulse 2.4s ease-in-out infinite;
}
@keyframes astPulse { 50% { box-shadow: 0 0 0 3px #6E4E92, 0 0 0 7px rgba(106, 211, 148, .25); } }
.ast.is-compact .ast__fab,
.ast.is-open .ast__fab { padding: 0 8px; gap: 0; }
.ast.is-compact .ast__fab-label,
.ast.is-open .ast__fab-label { max-width: 0; opacity: 0; }
.ast.is-open .ast__fab-icon { transform: rotate(135deg); }
.ast.is-open .ast__fab-dot { opacity: 0; }

/* ---------- Подсказка ---------- */
.ast__nudge {
  display: flex;
  align-items: center;
  gap: 2px;
  max-width: 270px;
  padding: 8px 6px 8px 16px;
  border-radius: 18px 18px 6px 18px;
  background: var(--surface);
  box-shadow: var(--shadow-md), 0 0 0 1px var(--line);
  font-size: .88rem;
  font-weight: 700;
  line-height: 1.35;
  color: var(--ink);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .25s var(--ease), transform .3s var(--ease);
}
.ast__nudge.is-visible { opacity: 1; transform: none; }
.ast__nudge-text { cursor: pointer; }
.ast__nudge-text:hover { color: var(--violet-700); }
.ast__nudge-x {
  display: grid;
  place-items: center;
  width: 30px; height: 30px;
  flex-shrink: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-3);
}
.ast__nudge-x:hover { background: var(--bg-soft); color: var(--ink); }
.ast__nudge-x .icon { width: 15px; height: 15px; }

/* ---------- Окно ---------- */
.ast__panel {
  display: flex;
  flex-direction: column;
  width: min(412px, calc(100vw - 32px));
  height: min(660px, calc(100dvh - 116px));
  overflow: hidden;
  border-radius: 28px;
  background: var(--surface);
  box-shadow: 0 40px 80px -24px rgba(43, 33, 53, .5), 0 0 0 1px rgba(43, 33, 53, .06);
  opacity: 0;
  transform: translateY(18px) scale(.96);
  transform-origin: 100% 100%;
  transition: opacity .25s var(--ease), transform .32s var(--ease);
}
.ast.is-open .ast__panel { opacity: 1; transform: none; }

.ast__head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 10px 16px 16px;
  color: #fff;
  background:
    radial-gradient(60% 140% at 100% 0%, rgba(240, 126, 5, .45) 0%, transparent 60%),
    radial-gradient(40% 120% at 0% 100%, rgba(246, 182, 198, .3) 0%, transparent 60%),
    linear-gradient(120deg, #4E3470 0%, var(--violet) 60%, #8A5E9E 100%);
}
.ast__avatar {
  display: grid;
  place-items: center;
  width: 46px; height: 46px;
  flex-shrink: 0;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, .22);
}
.ast__avatar svg { width: 30px; height: 30px; }
.ast__titles { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.ast__title { font-family: var(--font-serif); font-size: 1.35rem; font-weight: 700; letter-spacing: -.01em; }
.ast__subtitle { font-size: .78rem; font-weight: 600; opacity: .88; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ast__mode {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 5px;
  font-size: .64rem;
  font-weight: 800;
  letter-spacing: .1em;
  text-transform: uppercase;
  opacity: .9;
}
.ast__mode-dot { width: 7px; height: 7px; border-radius: 50%; background: #FFD7A3; }
.ast__mode.is-ai .ast__mode-dot { background: #7CE3A1; box-shadow: 0 0 0 3px rgba(124, 227, 161, .25); }
.ast__hbtn {
  display: grid;
  place-items: center;
  width: 38px; height: 38px;
  flex-shrink: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #fff;
  transition: background-color var(--t) var(--ease);
}
.ast__hbtn:hover { background: rgba(255, 255, 255, .16); }
.ast__hbtn .icon { width: 18px; height: 18px; }

/* ---------- Лента сообщений ---------- */
.ast__log {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px 14px 10px;
  background: linear-gradient(180deg, #FAF6FD 0%, var(--bg) 100%);
  scrollbar-width: thin;
  scrollbar-color: var(--violet-100) transparent;
}
.ast__msg { display: flex; flex-direction: column; gap: 8px; max-width: 94%; }
.ast__msg--assistant { align-self: flex-start; }
.ast__msg--user { align-self: flex-end; align-items: flex-end; max-width: 86%; }
.ast__msg.is-new { animation: astIn .4s var(--ease); }
@keyframes astIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.ast__bubble {
  padding: 11px 15px;
  border-radius: 20px;
  font-size: .93rem;
  line-height: 1.55;
  color: var(--ink-2);
  overflow-wrap: anywhere;
}
.ast__msg--assistant .ast__bubble {
  background: var(--surface);
  border: 1px solid var(--line);
  border-top-left-radius: 6px;
  box-shadow: var(--shadow-xs);
}
.ast__msg--user .ast__bubble {
  background: var(--violet);
  color: #fff;
  border-top-right-radius: 6px;
  white-space: pre-wrap;
  box-shadow: 0 8px 18px -12px rgba(115, 82, 151, .9);
}
.ast__bubble p { color: inherit; }
.ast__bubble > * + * { margin-top: .55em; }
.ast__bubble ul, .ast__bubble ol { margin-block: .45em; padding-left: 1.2em; list-style: revert; }
.ast__bubble ul li::marker { color: var(--orange); }
.ast__bubble ol li::marker { color: var(--violet); font-weight: 800; }
.ast__bubble li + li { margin-top: .2em; }
.ast__bubble strong { color: var(--ink); }
.ast__msg--user .ast__bubble strong { color: #fff; }
.ast__bubble a { color: var(--violet); font-weight: 700; text-decoration: underline; text-decoration-color: var(--violet-100); text-underline-offset: 2px; }
.ast__bubble a:hover { color: var(--violet-700); text-decoration-color: currentColor; }
.ast__note {
  padding: .4rem .65rem;
  border-radius: 10px;
  background: var(--orange-50);
  color: var(--orange-700) !important;
  font-size: .78rem;
  font-weight: 700;
}
.is-streaming .ast__bubble > :last-child::after {
  content: "";
  display: inline-block;
  width: 7px; height: 1em;
  margin-left: 3px;
  border-radius: 2px;
  background: var(--violet);
  vertical-align: -2px;
  animation: astBlink 1s steps(2) infinite;
}
@keyframes astBlink { 50% { opacity: 0; } }

/* Индикатор набора */
.ast__dots { display: inline-flex; gap: 5px; padding: 4px 2px; }
.ast__dots i {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--violet);
  opacity: .35;
  animation: astDot 1.2s ease-in-out infinite;
}
.ast__dots i:nth-child(2) { animation-delay: .15s; background: #C9608A; }
.ast__dots i:nth-child(3) { animation-delay: .3s; background: var(--orange); }
@keyframes astDot { 30% { opacity: 1; transform: translateY(-4px); } }

/* Карточки занятий и событий */
.ast__cards { display: flex; flex-direction: column; gap: 6px; margin-top: .7em; }
.ast__card {
  --c: var(--cat-painting);
  --cd: #9A4A0E;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px 8px 8px;
  border: 0;
  border-radius: 14px;
  background: var(--c);
  text-align: left;
  color: var(--ink);
  transition: transform var(--t) var(--ease), box-shadow var(--t) var(--ease);
}
.ast__card:hover { transform: translateY(-2px); box-shadow: 0 10px 18px -12px rgba(58, 34, 74, .5); }
.ast__card--drawing  { --c: var(--cat-drawing);  --cd: #5E4185; }
.ast__card--ceramics { --c: var(--cat-ceramics); --cd: #4C6E44; }
.ast__card--kids     { --c: var(--cat-kids);     --cd: #8A6410; }
.ast__card--therapy  { --c: var(--cat-therapy);  --cd: #9A3F5B; }
.ast__card-badge {
  min-width: 46px;
  padding: .32rem .45rem;
  border-radius: 10px;
  background: rgba(255, 255, 255, .85);
  color: var(--cd);
  font-size: .68rem;
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: .03em;
  text-align: center;
  text-transform: uppercase;
}
.ast__card-main { min-width: 0; }
.ast__card-title { display: block; font-size: .84rem; font-weight: 800; line-height: 1.25; }
.ast__card-sub { display: block; margin-top: 1px; font-size: .74rem; font-weight: 600; line-height: 1.3; color: var(--ink-2); }
.ast__card-price { max-width: 92px; font-size: .72rem; font-weight: 800; line-height: 1.2; text-align: right; color: var(--orange-700); }

/* Кнопки действий и быстрые вопросы */
.ast__actions, .ast__chips { display: flex; flex-wrap: wrap; gap: 6px; }
.ast__act {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: .46rem .85rem;
  border: 0;
  border-radius: var(--r-pill);
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--line-2);
  font-size: .8rem;
  font-weight: 800;
  color: var(--ink);
  transition: transform var(--t) var(--ease), box-shadow var(--t) var(--ease), background-color var(--t) var(--ease);
}
.ast__act .icon { width: 15px; height: 15px; color: var(--violet); }
.ast__act:hover { transform: translateY(-2px); color: var(--ink); box-shadow: inset 0 0 0 1px var(--violet-100), 0 8px 16px -10px rgba(58, 34, 74, .4); }
.ast__act--primary { background: var(--violet); color: #fff; box-shadow: 0 8px 16px -10px rgba(115, 82, 151, .9); }
.ast__act--primary .icon { color: #fff; }
.ast__act--primary:hover { background: var(--violet-600); color: #fff; }
.ast__chip {
  padding: .42rem .8rem;
  border: 1px dashed #D6C4EA;
  border-radius: var(--r-pill);
  background: var(--violet-50);
  font-size: .8rem;
  font-weight: 700;
  line-height: 1.3;
  text-align: left;
  color: var(--violet-700);
  transition: background-color var(--t) var(--ease), border-color var(--t) var(--ease), transform var(--t) var(--ease);
}
.ast__chip:hover { background: #fff; border-style: solid; border-color: var(--violet); transform: translateY(-2px); }
.ast__chips--start { margin-top: 4px; }

/* ---------- Поле ввода ---------- */
.ast__form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px 8px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}
.ast__input {
  flex: 1;
  min-height: 46px;
  max-height: 120px;
  resize: none;
  padding: .72rem 1rem;
  border: 1px solid var(--line-2);
  border-radius: 20px;
  background: var(--bg);
  font: inherit;
  font-size: .94rem;
  line-height: 1.4;
  color: var(--ink);
  transition: border-color var(--t) var(--ease), box-shadow var(--t) var(--ease), background-color var(--t) var(--ease);
}
.ast__input::placeholder { color: var(--ink-3); }
.ast__input:focus { outline: none; background: #fff; border-color: var(--violet); box-shadow: 0 0 0 4px rgba(115, 82, 151, .14); }
.ast__send {
  display: grid;
  place-items: center;
  width: 46px; height: 46px;
  flex-shrink: 0;
  border: 0;
  border-radius: 50%;
  background: var(--orange-fill);
  color: #fff;
  box-shadow: 0 8px 16px -10px rgba(214, 100, 12, .9);
  transition: transform var(--t) var(--ease), opacity var(--t) var(--ease), background-color var(--t) var(--ease);
}
.ast__send .icon { width: 19px; height: 19px; transform: translate(-1px, 1px); }
.ast__send:hover:not(:disabled) { transform: translateY(-2px) rotate(-8deg); background: var(--orange-fill-hover); }
.ast__send:disabled { opacity: .4; cursor: default; box-shadow: none; }
.ast__disclaimer {
  padding: 0 16px 12px;
  background: var(--surface);
  font-size: .7rem;
  line-height: 1.4;
  text-align: center;
  color: var(--ink-3);
}

/* ---------- Телефоны: полноэкранный чат ---------- */
@media (max-width: 640px) {
  .ast { right: 14px; bottom: max(14px, env(safe-area-inset-bottom)); }
  .ast__fab { height: 54px; font-size: .92rem; }
  .ast__fab-icon { width: 40px; height: 40px; }
  .ast__fab-dot { left: 37px; }
  .ast__panel {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    border-radius: 0;
    transform: translateY(24px);
  }
  .ast__head { padding-top: max(14px, env(safe-area-inset-top)); }
  .ast__disclaimer { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  .ast.is-open .ast__fab, .ast.is-open .ast__nudge { display: none; }
  .ast-open, .ast-open body { overflow: hidden; }
  .ast__msg { max-width: 96%; }
}

@media (prefers-reduced-motion: reduce) {
  .ast__fab-dot { animation: none; }
}

@media print { .ast { display: none !important; } }
