/* FABRIKO — AI-агент-менеджер «FABRIKO»: стили чат-виджета.
   Тема сайта: тёмный премиум (панель #151a25/#1a2030, латунь #c9a86a,
   крем #ede6d8) — все цвета на переменных css/landing.css, вендорных
   библиотек нет, без внешних CDN. Загружается после landing.css.

   Слои: флоатер-кнопка (золото/крем на тёмном, снизу справа) → панель чата
   в теме сайта. Позиции — fixed, на scrollWidth страницы не влияют
   (h-scroll 0 инвариант). Анимации — только transform/opacity; глобальный
   reduced-motion из landing.css выключает их без отдельных правил. */

.agent-root { position: fixed; right: 20px; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); z-index: 90; font-family: var(--font-text); }

/* ── флоатер: латунная кнопка, кремовая иконка на тёмном ───────────────── */
.agent-fab {
  display: grid; place-items: center; width: 58px; height: 58px;
  border-radius: 50%; cursor: pointer;
  border: 1px solid rgba(232, 198, 140, 0.55);
  background:
    radial-gradient(120% 120% at 30% 24%, rgba(255, 240, 214, 0.34), transparent 52%),
    linear-gradient(135deg, var(--brass-strong), var(--brass) 55%, var(--brass-deep));
  color: var(--ink-on-brass);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45), 0 6px 22px rgba(201, 168, 106, 0.3);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  animation: agentFabGlow 3.4s ease-in-out infinite;
}
.agent-fab:hover { transform: translateY(-2px); box-shadow: 0 16px 36px rgba(0, 0, 0, 0.5), 0 8px 28px rgba(201, 168, 106, 0.42); }
.agent-fab svg { width: 26px; height: 26px; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.agent-fab .af-x { display: none; }
.agent-root.is-open .agent-fab .af-chat { display: none; }
.agent-root.is-open .agent-fab .af-x { display: block; }
.agent-root.is-open .agent-fab { animation: none; }
@keyframes agentFabGlow {
  0%, 100% { box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45), 0 6px 22px rgba(201, 168, 106, 0.3); }
  50% { box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45), 0 6px 30px rgba(226, 192, 135, 0.5); }
}

/* ── панель чата: карточка в теме CTA ──────────────────────────────────── */
.agent-panel {
  position: absolute; right: 0; bottom: calc(58px + 12px);
  width: min(384px, calc(100vw - 28px));
  height: min(600px, calc(100dvh - 130px));
  display: flex; flex-direction: column; overflow: hidden;
  border-radius: 20px; border: 1px solid rgba(201, 168, 106, 0.42);
  background:
    radial-gradient(420px 200px at 90% -40px, rgba(201, 168, 106, 0.16), transparent 60%),
    linear-gradient(165deg, #1a1f2c, #12151e);
  box-shadow: var(--shadow-2);
  animation: agentPanelIn 0.28s ease;
}
@keyframes agentPanelIn { from { opacity: 0; transform: translateY(10px) scale(0.98); } to { opacity: 1; transform: none; } }

.agent-head {
  display: flex; align-items: center; gap: 11px;
  padding: 13px 14px; border-bottom: 1px solid var(--line);
  background: rgba(13, 16, 23, 0.55);
}
.agent-avatar {
  display: grid; place-items: center; width: 38px; height: 38px; flex: none;
  border-radius: 12px; color: var(--ink-on-brass);
  background: linear-gradient(135deg, var(--brass-strong), var(--brass-deep));
  box-shadow: 0 4px 14px rgba(201, 168, 106, 0.35);
}
.agent-avatar svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.agent-head-txt { display: flex; flex-direction: column; min-width: 0; }
.agent-head-txt b { font-family: var(--font-display); font-size: 17px; letter-spacing: 0.04em; color: var(--text); line-height: 1.15; }
.agent-status { display: inline-flex; align-items: center; gap: 6px; font-style: normal; font-size: 11.5px; letter-spacing: 0.06em; color: var(--muted); }
.agent-status u { width: 6px; height: 6px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 8px rgba(157, 192, 139, 0.9); text-decoration: none; animation: agentDot 2.6s ease-in-out infinite; }
@keyframes agentDot { 0%, 100% { opacity: 0.55; } 50% { opacity: 1; } }
.agent-x {
  margin-left: auto; display: grid; place-items: center;
  width: 36px; height: 36px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--line-strong); background: transparent; color: var(--text-dim);
  transition: color 0.15s ease, border-color 0.15s ease;
}
.agent-x:hover { color: var(--brass-strong); border-color: var(--brass); }
.agent-x svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; }

/* ── лента сообщений ───────────────────────────────────────────────────── */
.agent-log {
  flex: 1; overflow-y: auto; overscroll-behavior: contain;
  padding: 14px 13px 10px; display: flex; flex-direction: column; gap: 9px;
  scrollbar-width: thin; scrollbar-color: rgba(201, 168, 106, 0.35) transparent;
}
.agent-msg {
  max-width: 86%; padding: 10px 13px; border-radius: 14px;
  font-size: 14.5px; line-height: 1.5; white-space: pre-line;
  animation: agentMsgIn 0.22s ease;
}
@keyframes agentMsgIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.agent-msg.is-agent {
  align-self: flex-start; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--line-strong);
  border-bottom-left-radius: 5px;
}
.agent-msg.is-user {
  align-self: flex-end; color: var(--text);
  background: var(--brass-dim); border: 1px solid rgba(201, 168, 106, 0.4);
  border-bottom-right-radius: 5px;
}
.agent-note {
  align-self: center; max-width: 90%; text-align: center;
  font-size: 12px; color: var(--muted); padding: 2px 6px;
}

/* индикатор набора: три латунные точки */
.agent-typing { display: inline-flex; gap: 4px; align-items: center; padding: 12px 14px; }
.agent-typing i {
  width: 6px; height: 6px; border-radius: 50%; background: var(--brass);
  animation: agentTyping 1.1s ease-in-out infinite;
}
.agent-typing i:nth-child(2) { animation-delay: 0.15s; }
.agent-typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes agentTyping { 0%, 100% { opacity: 0.25; transform: translateY(0); } 50% { opacity: 1; transform: translateY(-3px); } }

/* ── варианты ответа (кнопки-кнопки сценария) ──────────────────────────── */
.agent-opts { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-start; padding-top: 2px; }
.agent-opt {
  padding: 9px 14px; border-radius: 999px; cursor: pointer;
  border: 1px solid rgba(201, 168, 106, 0.5); background: rgba(201, 168, 106, 0.07);
  color: var(--brass-strong); font: 600 13.5px/1.2 var(--font-text); letter-spacing: 0.01em;
  transition: background 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}
.agent-opt:hover { background: rgba(201, 168, 106, 0.16); transform: translateY(-1px); box-shadow: 0 4px 14px rgba(201, 168, 106, 0.18); }

/* ── поле ввода ────────────────────────────────────────────────────────── */
.agent-input {
  display: flex; gap: 8px; align-items: center;
  padding: 10px; border-top: 1px solid var(--line);
  background: rgba(13, 16, 23, 0.45);
}
.agent-input input {
  flex: 1; min-width: 0; padding: 11px 14px; border-radius: 999px;
  border: 1px solid var(--line-strong); background: rgba(233, 224, 209, 0.04);
  color: var(--text); font: 500 14.5px var(--font-text);
  transition: border-color 0.15s ease;
}
.agent-input input::placeholder { color: var(--muted); }
.agent-input input:focus { outline: none; border-color: var(--brass); }
.agent-input input:disabled { opacity: 0.5; }
.agent-input button {
  display: grid; place-items: center; flex: none;
  width: 42px; height: 42px; border-radius: 50%; cursor: pointer;
  border: 1px solid rgba(232, 198, 140, 0.55); color: var(--ink-on-brass);
  background: linear-gradient(135deg, var(--brass-strong), var(--brass-deep));
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.agent-input button:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(201, 168, 106, 0.3); }
.agent-input button svg { width: 19px; height: 19px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.agent-input.is-off button { opacity: 0.55; }

.agent-fab:focus-visible, .agent-x:focus-visible, .agent-opt:focus-visible, .agent-input button:focus-visible, .agent-input input:focus-visible {
  outline: 2px solid var(--brass); outline-offset: 2px;
}

/* ── адаптив: 375 и уже ────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .agent-root { right: 12px; bottom: calc(14px + env(safe-area-inset-bottom, 0px)); }
  .agent-fab { width: 54px; height: 54px; }
  .agent-panel {
    right: -12px; /* панель выровнена по краю экрана относительно флоатера */
    width: calc(100vw - 20px);
    height: min(560px, calc(100dvh - 178px));
    bottom: calc(54px + 10px);
  }
  .agent-msg { max-width: 92%; font-size: 14px; }
  .agent-opt { padding: 10px 13px; font-size: 13px; }
}
/* очень низкие ландшафтные окна: панель не выше вьюпорта */
@media (max-height: 560px) {
  .agent-panel { height: calc(100dvh - 96px); }
}

/* волна 6: на телефоне флоатер уходит выше нижнего HUD-бара,
   иначе кнопка перекрывает дорожку станций и счётчик деталей */
@media (max-width: 760px) {
  .agent-root { bottom: calc(74px + env(safe-area-inset-bottom, 0px)); }
  /* на финале флоатер перекрывал правый край CTA «Открыть конструктор» —
     уступаем главной кнопке (P2 критика раунда 3) */
  /* карточки этих станций прижаты к низу (раунд 5): флоатер накрывал
     задание цеха и мок конструктора — на телефоне уступаем контенту */
  body[data-station="pilot"] .agent-root,
  body[data-station="explode-lab"] .agent-root,
  body[data-station="constructor"] .agent-root,
  body[data-station="material-studio"] .agent-root { display: none; }
}
