/**
 * AY Assistant Chat Widget Styles
 * Dark theme matching site aesthetic (#8a2be2 accent)
 */

/* ─── Toggle Button ─────────────────────────────────────────────── */
.ay-asst-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 99999;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  background: #8a2be2;
  color: #fff;
  font-size: 28px;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(138, 43, 226, 0.4);
  transition: transform 0.2s, box-shadow 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ay-asst-toggle:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(138, 43, 226, 0.6);
}

.ay-asst-panel.ay-asst-open ~ .ay-asst-toggle,
body.ay-asst-open .ay-asst-toggle {
  transform: scale(0.9);
  opacity: 0;
  pointer-events: none;
}

/* ─── Chat Panel ────────────────────────────────────────────────── */
.ay-asst-panel {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 99998;
  width: 380px;
  max-width: calc(100vw - 48px);
  height: 520px;
  max-height: calc(100vh - 48px);
  background: #1a1a2e;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
}

.ay-asst-panel.ay-asst-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* ─── Header ────────────────────────────────────────────────────── */
.ay-asst-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: rgba(138, 43, 226, 0.15);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.ay-asst-title {
  color: #e6e6ec;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
}

.ay-asst-close {
  background: none;
  border: none;
  color: #8a8a99;
  font-size: 24px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  transition: color 0.15s;
}

.ay-asst-close:hover {
  color: #fff;
}

/* ─── Messages Area ─────────────────────────────────────────────── */
.ay-asst-messages {
  flex: 1;
  min-height: 0; /* иначе flex-элемент не сожмётся и уедет под строку ввода */
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain; /* прокрутка чата не утягивает за собой страницу */
}

.ay-asst-messages::-webkit-scrollbar {
  width: 4px;
}

.ay-asst-messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
}

/* ─── Message Bubbles ───────────────────────────────────────────── */
.ay-asst-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.45;
  word-wrap: break-word;
}

.ay-asst-msg-user {
  align-self: flex-end;
  background: #8a2be2;
  color: #fff;
  border-bottom-right-radius: 4px;
}

.ay-asst-msg-bot {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.07);
  color: #d4d4dc;
  border-bottom-left-radius: 4px;
}

.ay-asst-loading {
  opacity: 0.6;
  font-style: italic;
}

/* ─── Video Cards Grid ──────────────────────────────────────────── */
.ay-asst-cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 4px;
}

.ay-asst-card {
  display: flex;
  flex-direction: column;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  overflow: hidden;
  text-decoration: none;
  transition: border-color 0.15s, transform 0.15s;
}

.ay-asst-card:hover {
  border-color: #8a2be2;
  transform: translateY(-2px);
}

.ay-asst-card-thumb {
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #12121e;
}

.ay-asst-card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.ay-asst-card-title {
  padding: 8px 10px;
  color: #d4d4dc;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.3;
  flex: 1;
}

.ay-asst-card-lock,
.ay-asst-card-free {
  padding: 4px 10px 8px;
  font-size: 11px;
  font-weight: 600;
}

.ay-asst-card-lock {
  color: #f59e0b;
}

.ay-asst-card-free {
  color: #22c55e;
}

/* ─── Subscribe CTA ─────────────────────────────────────────────── */
.ay-asst-subscribe {
  text-align: center;
  padding: 8px 0;
}

.ay-asst-subscribe-btn {
  display: inline-block;
  padding: 10px 22px;
  background: linear-gradient(135deg, #8a2be2, #a855f7);
  color: #fff;
  text-decoration: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  transition: opacity 0.15s;
}

.ay-asst-subscribe-btn:hover {
  opacity: 0.9;
}

/* ─── Catalog Link ──────────────────────────────────────────────── */
.ay-asst-catalog {
  padding: 4px 0 10px;
}

.ay-asst-catalog-btn {
  display: inline-block;
  padding: 9px 18px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(168, 85, 247, 0.45);
  color: #c9a6f5;
  text-decoration: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  transition: background 0.15s, color 0.15s;
}

.ay-asst-catalog-btn:hover {
  background: rgba(168, 85, 247, 0.15);
  color: #fff;
}

/* ─── Input Row ─────────────────────────────────────────────────── */
.ay-asst-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 16px;
  background: rgba(0, 0, 0, 0.2);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  flex-shrink: 0; /* строка ввода никогда не схлопывается — она якорь панели */
}

#ay-assistant-input {
  flex: 1;
  resize: none;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
  color: #e6e6ec;
  font-family: inherit;
  font-size: 14px;
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.15s;
  max-height: 120px;
  line-height: 1.4;
}

#ay-assistant-input:focus {
  border-color: #8a2be2;
}

#ay-assistant-input::placeholder {
  color: #6a6a7a;
}

.ay-asst-send {
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 8px;
  background: #8a2be2;
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}

.ay-asst-send:hover {
  background: #7a1bd2;
}

/* ─── Mobile ────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .ay-asst-panel {
    width: 100vw;
    max-width: 100vw;
    bottom: 0;
    right: 0;
    border: 0; /* иначе 2px рамки не влезают в заданную высоту и шапка режется */
    border-radius: 0;

    /* Высоту задаёт JS по visualViewport — только так строка ввода встаёт
       ровно над клавиатурой. dvh и vh здесь лишь запасной вариант на случай,
       если visualViewport недоступен. */
    height: 100vh;
    height: 100dvh;
    max-height: none;
  }

  .ay-asst-panel.ay-asst-vv {
    height: var(--ay-asst-vh);
    bottom: var(--ay-asst-bottom);
  }

  /* Пока чат открыт, страница под ним не скроллится и не «подглядывает». */
  body.ay-asst-mobile-open {
    overflow: hidden;
  }

  body.ay-asst-mobile-open .ay-asst-toggle {
    opacity: 0;
    pointer-events: none;
  }

  /* Плавающий переключатель языка GTranslate висит на z-index 999999 и на
     полноэкранном чате закрывает левую часть строки ввода. Пока чат открыт,
     он не нужен — вернётся сразу после закрытия. */
  body.ay-asst-mobile-open #gt_float_wrapper,
  body.ay-asst-mobile-open .gt_float_switcher {
    display: none;
  }

  /* Меньше 16px — и iOS зумит страницу при фокусе, ломая всю раскладку. */
  #ay-assistant-input {
    font-size: 16px;
    max-height: 80px;
  }

  .ay-asst-toggle {
    bottom: 16px;
    right: 16px;
    width: 54px;
    height: 54px;
    font-size: 24px;
  }

  .ay-asst-cards {
    grid-template-columns: 1fr;
  }
}