/* Помощник: плавающая кнопка и панель чата. Цвета — из style.css, своих не
   заводим, иначе виджет отвяжется от темы сайта при следующей правке. */

/* Кнопка стоит над «Нашли баг?» (та занимает bottom: 18px): два плавающих
   элемента в одном углу, поэтому подняли на её высоту с зазором.
   --bottom-tabs-h выставляет script.js, когда снизу появляется таб-бар. На
   десктопе переменной нет, подставляется 0, и остаются те же 66 пикселей. */
.ai-fab {
  position: fixed;
  right: 18px;
  bottom: calc(var(--bottom-tabs-h, 0px) + 66px);
  width: auto;
  z-index: 150;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  box-shadow: var(--hard-shadow);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  padding: 9px 13px;
  transition: border-color 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.ai-fab:hover,
.ai-fab.is-open {
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-1px);
}

.ai-fab svg {
  width: 17px;
  height: 17px;
  flex-shrink: 0;
}

.ai-panel {
  position: fixed;
  right: 18px;
  bottom: calc(var(--bottom-tabs-h, 0px) + 66px);
  z-index: 151;
  display: flex;
  flex-direction: column;
  width: 360px;
  max-height: min(70vh, 560px);
  background: var(--bg-deep);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--hard-shadow);
  overflow: hidden;
}

.ai-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
}

.ai-head-title {
  color: var(--text);
  font-weight: 600;
  font-size: 14px;
}

/* Второстепенное действие: заметно только когда его ищут глазами. */
.ai-clear {
  background: none;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  margin-left: auto;
  margin-right: 6px;
  padding: 2px 4px;
  width: auto;
}

.ai-clear:hover { color: var(--text-dim); }

.ai-close {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  padding: 0 4px;
  width: auto;
}

.ai-close:hover { color: var(--text); }

.ai-thread {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  min-height: 120px;
  overflow-y: auto;
  padding: 12px;
}

.ai-hint {
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.5;
}

.ai-samples {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}

.ai-sample {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  padding: 6px 10px;
  text-align: left;
  width: auto;
}

.ai-sample:hover { border-color: var(--border-strong); }

.ai-msg {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  line-height: 1.5;
  padding: 8px 11px;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.ai-msg.is-user {
  align-self: flex-end;
  background: rgba(255, 201, 77, 0.10);
  border-color: rgba(255, 201, 77, 0.35);
  max-width: 85%;
}

.ai-msg.is-bot { background: var(--surface); }
.ai-msg.is-pending { color: var(--text-faint); }
.ai-msg.is-error { border-color: rgba(255, 63, 174, 0.45); color: var(--text-dim); }

.ai-form {
  display: flex;
  gap: 6px;
  align-items: flex-end;
  border-top: 1px solid var(--line);
  padding: 10px 12px 6px;
}

.ai-input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  flex: 1;
  font: inherit;
  font-size: 13px;
  max-height: 90px;
  min-height: 38px;
  padding: 9px 10px;
  resize: none;
}

.ai-input:focus { border-color: var(--border-strong); outline: none; }

.ai-send {
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: var(--accent-ink);
  cursor: pointer;
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  height: 38px;
  width: 40px;
  flex-shrink: 0;
}

.ai-send:disabled { cursor: default; opacity: 0.45; }

.ai-foot {
  color: var(--text-faint);
  font-size: 11px;
  padding: 0 12px 10px;
}

/* Где снизу таб-бар, там плавающей кнопки «Нашли баг?» уже нет — она уезжает в
   подвал. Значит и подниматься нашей не над чем: садится вплотную над баром,
   ровно как это делает соседняя кнопка на десктопе. Высоту бара в
   --bottom-tabs-h кладёт script.js, поэтому она переживёт его изменение. */
body.has-bottom-tabs .ai-fab { bottom: calc(var(--bottom-tabs-h, 0px) + 12px); }
body.has-bottom-tabs .ai-panel { bottom: calc(var(--bottom-tabs-h, 0px) + 60px); }

/* Подпись прячем, как у соседней кнопки: с текстом она занимает заметный кусок
   узкого экрана и лезет на содержимое. Порог 640 — тот же, что у неё, чтобы обе
   перестраивались одновременно. */
@media (max-width: 640px) {
  .ai-fab {
    right: 12px;
    padding: 10px;
  }

  .ai-fab span { display: none; }
}

/* Панель шириной в экран: 360 пикселей там не помещаются, а чат, вылезающий
   за край, читать нельзя. */
@media (max-width: 480px) {
  .ai-panel {
    right: 8px;
    left: 8px;
    width: auto;
    max-height: 62vh;
  }
}
