/* Переписка с «Помощником HomeOffer» (раздел «Спросить базу»).
   Вид перенесён из раздела «Сообщения» портала HomeOffer:
   front-wt/messenger-mobile-0919/src/features/messenger/ui/Messenger.module.scss
   (токены .tokens, пузыри .bub/.mOut, шапка .chead/.cheadTitle, поле .crow/.cfield/.send,
   «печатает» .typing, разделитель .datesep) и ui/voice/Voice.module.scss (.recording, .recDot, .recTime).
   Все токены живут на .as-chat, чтобы не задевать остальной кабинет. */

.as-chat {
  --ho-a60: rgba(255, 206, 96, .6);
  --ho-a60-hover: #f6e5bf;
  --ho-a60-strong: #e6ba57;
  --ho-tile-bg: #ffffff;
  --ho-tile-ink: #4a4a4a;
  --ho-tile-shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 2px 10px rgba(0, 0, 0, .07);
  --ho-tile-radius: 10px;
  --fg-1: #373737;
  --fg-2: #5c5c5c;
  --fg-3: #838383;
  --fg-4: #acacac;
  --fg-meta: #717171;
  --fg-meta-on-yellow: #6b6b6b;
  --bg-1: #ffffff;
  --bg-2: #f7f7f7;
  --bg-3: #efefef;
  --canvas: #ebeae7;
  --bubble-in: #ffffff;
  --bubble-out: #ffebbe;
  --red: #f44444;
  --red-bg: rgba(244, 68, 68, .12);
  --red-strong: #d0312f;
  --sh-1: 0 1px 6px rgba(0, 0, 0, .06);
  --sh-island: 0 4px 14px rgba(0, 0, 0, .1), 0 1px 2px rgba(0, 0, 0, .06);
  --btn-accent-shadow: 0 1px 1.5px rgba(120, 84, 0, .16), 0 2px 6px rgba(120, 84, 0, .1);
  --glass: rgba(252, 252, 252, .97);
  --r-md: 10px;
  --r-pill: 50px;
  --ease: cubic-bezier(.4, 0, .2, 1);
  --crow-main: 42px;

  position: relative;
  display: flex;
  flex-direction: column;
  height: 640px;
  min-height: 420px;
  border-radius: 20px;
  overflow: hidden;
  background: var(--canvas);
  box-shadow: var(--sh-1);
  font-family: 'Onest', system-ui, sans-serif;
  color: var(--fg-1);
}
.as-chat *, .as-chat *::before, .as-chat *::after { box-sizing: border-box; }
:where(.as-chat) button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.as-chat svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ── шапка: плавающий остров, как .chead/.cheadTitle ─────────────────────── */
.as-head {
  position: absolute; top: 0; left: 0; right: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  min-height: 66px; padding: 0 10px;
  pointer-events: none;
}
.as-head::before {
  content: ''; position: absolute; inset: 0 0 -14px;
  background: linear-gradient(to bottom, var(--canvas) 55%, rgba(235, 234, 231, 0));
  pointer-events: none;
}
.as-head > * { position: relative; pointer-events: auto; }
.as-title {
  flex: 1 1 auto; min-width: 0;
  display: flex; align-items: center; gap: 10px;
  height: 44px; padding: 0 14px 0 5px;
  border-radius: var(--r-pill);
  background: var(--glass);
  box-shadow: var(--sh-island);
}
.as-ava {
  width: 34px; height: 34px; flex: none;
  display: grid; place-items: center;
  border-radius: var(--ho-tile-radius);
  background: var(--ho-tile-bg);
  color: var(--ho-tile-ink);
  box-shadow: var(--ho-tile-shadow);
}
.as-ava svg { width: 19px; height: 19px; }
.as-ava--sm { width: 28px; height: 28px; }
.as-ava--sm svg { width: 16px; height: 16px; }
.as-title-txt { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.as-name { font-size: 15.5px; line-height: 1.2; font-weight: 700; letter-spacing: -.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.as-sub { font-size: 12px; line-height: 1.2; color: var(--fg-meta); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.as-sub.is-typing { color: var(--fg-1); font-weight: 600; }
.as-newbtn {
  flex: none; height: 44px; padding: 0 16px 0 12px;
  display: inline-flex; align-items: center; gap: 7px;
  border-radius: var(--r-pill);
  background: var(--glass); box-shadow: var(--sh-island);
  font-size: 13px; font-weight: 600; color: var(--fg-1);
  transition: background .15s var(--ease);
}
.as-newbtn:hover, .as-newbtn:focus-visible { background: var(--bg-3); outline: none; }
.as-newbtn svg { width: 18px; height: 18px; }

/* ── лента ───────────────────────────────────────────────────────────────── */
.as-feed {
  flex: 1 1 auto; min-height: 0;
  overflow-y: auto; overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 76px 16px 12px;
  display: flex; flex-direction: column; gap: 6px;
  scroll-behavior: smooth;
}
.as-datesep {
  align-self: center; margin: 4px 0 8px; padding: 4px 12px;
  border-radius: var(--r-pill); background: rgba(255, 255, 255, .55);
  color: var(--fg-meta); font-size: 11.5px; font-weight: 600;
}
.as-m { display: flex; align-items: flex-end; gap: 8px; animation: asIn .18s cubic-bezier(.22, 1, .36, 1); }
.as-m--out { justify-content: flex-end; }
.as-m--out + .as-m--in, .as-m--in + .as-m--out { margin-top: 8px; }
@keyframes asIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.as-bub {
  max-width: min(640px, 82%);
  padding: 8px 12px 6px;
  border-radius: 16px;
  border-bottom-left-radius: 6px;
  background: var(--bubble-in);
  box-shadow: var(--sh-1);
  font-size: 14.5px; line-height: 1.42;
  overflow-wrap: anywhere;
}
.as-m--out .as-bub { background: var(--bubble-out); border-bottom-left-radius: 16px; border-bottom-right-radius: 6px; }
.as-m--out .as-bub .as-time { color: var(--fg-meta-on-yellow); }
.as-text { white-space: pre-wrap; }
.as-bub.is-err { background: var(--red-bg); box-shadow: none; }

/* разметка ответа (ctx.md) внутри пузыря */
.as-md > :first-child { margin-top: 0; }
.as-md > :last-child { margin-bottom: 0; }
.as-md p { margin: 0 0 8px; }
.as-md ul, .as-md ol { margin: 0 0 8px; padding-left: 20px; }
.as-md li { margin: 2px 0; }
.as-md h2, .as-md h3, .as-md h4, .as-md h5 { font-size: 14.5px; font-weight: 700; margin: 10px 0 4px; }
.as-md a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.as-md .cab-table { font-size: 13px; }
.as-ref {
  display: inline-grid; place-items: center;
  min-width: 18px; height: 18px; padding: 0 4px; margin: 0 1px;
  border-radius: 6px; background: var(--ho-a60);
  font-size: 11px; font-weight: 700; line-height: 1; vertical-align: 1px;
  cursor: pointer;
}
.as-ref:hover { background: var(--ho-a60-strong); }

.as-note { font-size: 13px; color: var(--fg-2); margin: 0 0 8px; padding: 8px 10px; border-radius: var(--r-md); background: var(--bg-2); }

/* источники под ответом */
.as-src { margin-top: 10px; display: flex; flex-direction: column; gap: 4px; }
.as-src-h { font-size: 11.5px; font-weight: 700; color: var(--fg-meta); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 2px; }
.as-src-i {
  display: flex; align-items: flex-start; gap: 9px; width: 100%;
  min-height: 44px; padding: 8px 10px; text-align: left;
  border-radius: var(--r-md); background: var(--bg-2);
  transition: background .15s var(--ease);
}
.as-src-i:hover, .as-src-i:focus-visible { background: var(--ho-a60-hover); outline: none; }
.as-src-n { flex: none; min-width: 22px; height: 22px; display: grid; place-items: center; border-radius: 7px; background: var(--bg-1); font-size: 11.5px; font-weight: 700; margin-top: 1px; }
.as-src-b { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.as-src-t { font-size: 13px; font-weight: 600; line-height: 1.3; }
.as-src-s { font-size: 12px; line-height: 1.35; color: var(--fg-meta); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.as-src-go { flex: none; margin-left: auto; color: var(--fg-3); align-self: center; }
.as-src-go svg { width: 16px; height: 16px; }

/* подвал пузыря: действия и время */
.as-foot { display: flex; align-items: center; justify-content: flex-end; gap: 4px; margin-top: 4px; user-select: none; -webkit-user-select: none; }
.as-foot--bot { justify-content: space-between; margin: 8px -6px -2px; }
.as-acts { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; }
.as-act {
  height: 32px; min-width: 32px; padding: 0 8px;
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  border-radius: var(--r-md); color: var(--fg-2); font-size: 12px; font-weight: 600;
  transition: background .15s var(--ease), color .15s var(--ease);
}
.as-act svg { width: 17px; height: 17px; }
.as-act:hover, .as-act:focus-visible { background: var(--bg-3); color: var(--fg-1); outline: none; }
.as-act.is-on { background: var(--ho-a60); color: var(--fg-1); }
.as-act-done { font-size: 12px; color: var(--fg-meta); padding: 0 6px; }
.as-time { font-size: 11px; color: var(--fg-meta); white-space: nowrap; }

/* приветствие и примеры вопросов */
.as-hello-t { font-weight: 700; margin-bottom: 2px; }
.as-sugs { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 4px 36px; max-width: min(640px, 90%); }
.as-sug {
  min-height: 40px; padding: 9px 14px;
  border-radius: var(--r-pill);
  background: var(--ho-tile-bg); box-shadow: var(--ho-tile-shadow);
  font-size: 13.5px; font-weight: 500; text-align: left; line-height: 1.3;
  transition: background .15s var(--ease);
}
.as-sug:hover, .as-sug:focus-visible { background: var(--ho-a60-hover); outline: none; }
.as-sug:disabled { opacity: .55; cursor: default; }

/* «Помощник печатает»: те же 6px точки и blink, что у .typing */
.as-typing { display: flex; flex-direction: column; gap: 7px; min-width: 230px; }
.as-typing-row { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--fg-2); }
.as-dots { display: inline-flex; gap: 4px; }
.as-dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--fg-4); display: inline-block; animation: asBlink 1.1s infinite; }
.as-dots i:nth-child(2) { animation-delay: .18s; }
.as-dots i:nth-child(3) { animation-delay: .36s; }
@keyframes asBlink { 0%, 80%, 100% { opacity: .3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-2px); } }
.as-prog { height: 4px; border-radius: 4px; background: var(--bg-3); overflow: hidden; }
.as-prog i { display: block; height: 100%; width: 0; border-radius: 4px; background: var(--ho-a60-strong); transition: width .9s linear; }
.as-typing-meta { display: flex; justify-content: space-between; gap: 10px; font-size: 11.5px; color: var(--fg-meta); font-variant-numeric: tabular-nums; }
.as-typing-stop { align-self: flex-start; }

/* ── поле ввода: одна капсула .crow ──────────────────────────────────────── */
.as-composer { flex: none; position: relative; padding: 6px 10px 10px; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
.as-rec {
  display: none; align-items: center; gap: 8px;
  min-height: 36px; margin: 0 4px 6px; padding: 0 6px 0 12px;
  border-radius: var(--r-pill); background: var(--ho-a60);
  font-size: 12.5px; color: var(--fg-1);
}
.as-chat.is-rec .as-rec { display: flex; }
.as-rec-dot { width: 9px; height: 9px; flex: none; border-radius: 50%; background: var(--red); animation: asRecPulse 1.1s ease-in-out infinite alternate; }
@keyframes asRecPulse { from { opacity: .35; } to { opacity: 1; } }
.as-rec-time { font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; flex: none; }
.as-rec-hint { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: rgba(55, 55, 55, .72); }
.as-rec-x { width: 32px; height: 32px; flex: none; display: grid; place-items: center; border-radius: 50%; color: var(--fg-2); }
.as-rec-x:hover, .as-rec-x:focus-visible { background: var(--red-bg); color: var(--red); outline: none; }
.as-rec-x svg { width: 16px; height: 16px; }

.as-tip {
  display: none; margin: 0 4px 6px; padding: 9px 12px;
  border-radius: 14px; background: var(--fg-1); color: #fff;
  font-size: 12.5px; line-height: 1.4;
}
.as-tip.is-on { display: block; animation: asIn .18s cubic-bezier(.22, 1, .36, 1); }

.as-crow {
  display: flex; align-items: flex-end; gap: 4px;
  padding: 5px; border-radius: 27px;
  background: var(--glass); box-shadow: var(--sh-island);
}
.as-field {
  flex: 1; min-width: 0;
  min-height: var(--crow-main); max-height: 130px;
  field-sizing: content;
  resize: none; overflow-y: auto;
  border: 0; outline: none;
  border-radius: 22px; background: var(--bg-2);
  padding: 11px 14px; font: inherit; font-size: 14.5px; line-height: 1.35; color: var(--fg-1);
}
.as-field::placeholder { color: var(--fg-meta); }
.as-chat.is-rec .as-field { color: var(--fg-2); }
.as-ibtn {
  width: var(--crow-main); height: var(--crow-main); flex: none;
  display: grid; place-items: center; border-radius: 50%;
  color: var(--fg-2); position: relative;
  transition: background .15s var(--ease), color .15s var(--ease);
}
.as-ibtn:hover, .as-ibtn:focus-visible { background: var(--bg-3); color: var(--fg-1); outline: none; }
.as-ibtn.is-off { color: var(--fg-4); }
.as-mic.is-on { background: var(--ho-a60); color: var(--fg-1); }
.as-mic.is-on::before {
  content: ''; position: absolute; inset: 0; border-radius: 50%;
  background: var(--ho-a60); z-index: -1;
  animation: asHalo 1.4s ease-out infinite;
}
.as-mic { isolation: isolate; }
@keyframes asHalo { from { transform: scale(1); opacity: .9; } to { transform: scale(1.55); opacity: 0; } }
.as-send {
  width: var(--crow-main); height: var(--crow-main); flex: none;
  display: grid; place-items: center; border-radius: 50%;
  background: var(--ho-a60); color: #2e2a20;
  box-shadow: var(--btn-accent-shadow);
  transition: background .15s var(--ease), transform .14s var(--ease);
}
.as-send:hover, .as-send:focus-visible { background: var(--ho-a60-hover); outline: none; }
.as-send:active { transform: scale(.94); }
.as-send:disabled { background: var(--bg-3); color: var(--fg-4); box-shadow: none; cursor: default; transform: none; }
.as-send svg { fill: currentColor; stroke: none; }
.as-hint { margin: 6px 14px 0; font-size: 11.5px; color: var(--fg-meta); text-align: center; }

/* ── касания и телефон ───────────────────────────────────────────────────── */
@media (pointer: coarse) {
  .as-chat { --crow-main: 44px; }
  .as-field { font-size: 16px; }
  .as-act { height: 44px; min-width: 44px; }
}
@media (max-width: 768px) {
  /* тач-таргеты от 44px и 16px в поле, чтобы iOS не увеличивал страницу при вводе */
  .as-chat { --crow-main: 44px; border-radius: 16px; margin: 0 -8px; }
  .as-field { font-size: 16px; }
  .as-sug { min-height: 44px; }
  .as-act { height: 44px; min-width: 44px; }
  .as-feed { padding: 72px 10px 10px; }
  .as-bub { max-width: 88%; }
  .as-sugs { margin-left: 0; max-width: 100%; }
  .as-newbtn { width: 44px; padding: 0; justify-content: center; }
  .as-newbtn span { display: none; }
  .as-head { padding: 0 8px; }
  .as-composer { padding: 4px 6px 8px; }
  .as-hint { display: none; }
  .as-typing { min-width: 0; width: 100%; }
  .as-m--in .as-bub { max-width: calc(100% - 36px); }
}
@media (prefers-reduced-motion: reduce) {
  .as-m, .as-tip.is-on { animation: none; }
  .as-dots i, .as-rec-dot, .as-mic.is-on::before { animation: none; }
  .as-feed { scroll-behavior: auto; }
}
.as-src-more { align-self: flex-start; margin-top: 2px; }
.as-src-i[hidden] { display: none; }

/* ответ пишется на глазах: номера пока без перехода, ссылки появятся по готовности */
.as-live { margin-bottom: 6px; }
.as-ref.is-pending { cursor: default; background: var(--bg-2); color: var(--fg-3); }
.as-src-s { -webkit-line-clamp: 3; font-style: normal; color: var(--fg-2); }
.as-src-where { font-size: 11.5px; font-weight: 600; color: var(--fg-meta); margin-top: 2px; }
