/* AutoPartsAgent web chat widget */
#apa-chat-launcher {
  position: fixed;
  left: 10px;
  bottom: 10px;
  z-index: 2147483000;
  width: 58px;
  height: 58px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(145deg, #ff8b34, #ff6a00);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 10px 28px rgba(255, 106, 0, 0.38);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .15s ease, box-shadow .15s ease;
}
#apa-chat-launcher:hover { transform: translateY(-2px); box-shadow: 0 14px 32px rgba(255, 106, 0, .48); }
#apa-chat-launcher svg { width: 28px; height: 28px; }
#apa-chat-launcher .apa-dot {
  position: absolute; top: 2px; right: 2px;
  width: 13px; height: 13px; border-radius: 50%;
  background: #38d17c; border: 2px solid #08142b;
}

.apa-chat {
  position: fixed;
  left: 18px;
  bottom: 88px;
  z-index: 2147483000;
  width: 380px;
  max-width: calc(100vw - 24px);
  height: 560px;
  max-height: calc(100vh - 120px);
  background: #0c1a35;
  border: 1px solid #27406d;
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .55);
  display: none;
  flex-direction: column;
  overflow: hidden;
  font-family: inherit;
  color: #f5f7ff;
}
.apa-chat.apa-open { display: flex; }

.apa-chat__head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px;
  background: #102448;
  border-bottom: 1px solid #27406d;
}
.apa-chat__head b { font-size: 15px; line-height: 1.2; }
.apa-chat__head small { display: block; color: #9aa8c3; font-size: 11.5px; margin-top: 2px; }
.apa-chat__avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: linear-gradient(145deg, #ff8b34, #ff6a00);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px; color: #fff; flex: 0 0 auto;
}
.apa-chat__close {
  margin-left: auto; background: transparent; border: none; color: #9aa8c3;
  font-size: 22px; cursor: pointer; line-height: 1; padding: 4px 6px;
}
.apa-chat__close:hover { color: #fff; }

.apa-chat__body {
  flex: 1 1 auto; overflow-y: auto; padding: 14px;
  display: flex; flex-direction: column; gap: 10px;
  background:
    radial-gradient(1200px 300px at 100% 0%, rgba(255, 122, 26, .07), transparent 60%),
    #0c1a35;
}
.apa-msg { max-width: 88%; padding: 9px 12px; border-radius: 12px; font-size: 13.5px; line-height: 1.45; white-space: pre-wrap; word-break: break-word; }
.apa-msg--bot { background: #16294f; border: 1px solid #23395f; align-self: flex-start; border-bottom-left-radius: 4px; }
.apa-msg--user { background: rgba(255, 122, 26, .16); border: 1px solid rgba(255, 122, 26, .38); align-self: flex-end; border-bottom-right-radius: 4px; }

.apa-part { margin-top: 8px; display: flex; gap: 10px; align-items: flex-start; background: #102448; border: 1px solid #27406d; border-radius: 10px; padding: 8px; }
.apa-part__img { width: 54px; height: 54px; border-radius: 8px; object-fit: contain; background: #0c1a35; flex: 0 0 auto; }
.apa-part__body { flex: 1 1 auto; min-width: 0; }
.apa-part__name { font-size: 12.5px; line-height: 1.3; margin: 0 0 3px; }
.apa-part__meta { font-size: 11px; color: #9aa8c3; }
.apa-part__row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 6px; }
.apa-part__price { font-weight: 700; font-size: 13px; color: #ffb072; }
.apa-part__add {
  border: none; border-radius: 8px; cursor: pointer;
  background: linear-gradient(145deg, #ff8b34, #ff6a00); color: #fff;
  font-size: 11.5px; font-weight: 600; padding: 6px 10px;
}
.apa-part__add:disabled { opacity: .6; cursor: default; }

.apa-action {
  display: block; width: 100%; margin-top: 10px; box-sizing: border-box;
  border: 1px solid rgba(255, 122, 26, .5); background: rgba(255, 122, 26, .12);
  color: #ffb072; border-radius: 9px; padding: 7px 12px;
  font: inherit; font-size: 12.5px; cursor: pointer;
}
.apa-action:hover { background: rgba(255, 122, 26, .22); }

.apa-typing { align-self: flex-start; display: flex; gap: 4px; padding: 10px 12px; background: #16294f; border-radius: 12px; }
.apa-typing i { width: 6px; height: 6px; border-radius: 50%; background: #9aa8c3; animation: apaBlink 1.2s infinite; }
.apa-typing i:nth-child(2) { animation-delay: .18s; }
.apa-typing i:nth-child(3) { animation-delay: .36s; }
@keyframes apaBlink { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }

.apa-chat__foot { border-top: 1px solid #27406d; background: #102448; padding: 10px; }
.apa-chat__form { display: flex; gap: 8px; align-items: flex-end; }
.apa-chat__input {
  flex: 1 1 auto; resize: none; max-height: 92px; min-height: 40px;
  background: #0c1a35; border: 1px solid #27406d; border-radius: 10px;
  color: #f5f7ff; font: inherit; font-size: 13.5px; padding: 10px 12px; outline: none;
}
.apa-chat__input:focus { border-color: #ff7a1a; }
.apa-chat__send {
  flex: 0 0 auto; width: 42px; height: 40px; border: none; border-radius: 10px;
  background: linear-gradient(145deg, #ff8b34, #ff6a00); color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.apa-chat__send:disabled { opacity: .5; cursor: default; }
.apa-chat__note { font-size: 10.5px; color: #7f8dab; margin: 7px 2px 0; text-align: center; }

.apa-toast {
  position: fixed; right: 18px; bottom: 88px; z-index: 2147483001;
  background: #123; color: #fff; border: 1px solid #27406d;
  border-radius: 10px; padding: 10px 14px; font-size: 13px;
  box-shadow: 0 10px 30px rgba(0,0,0,.4);
  display: flex; gap: 10px; align-items: center;
}

/* не перекрывать плавающую кнопку корзины (.cart-badge) */
#apa-chat-launcher.apa-raised { bottom: 88px; }
.apa-chat.apa-raised { bottom: 158px; }
.apa-toast.apa-raised { bottom: 158px; }
.apa-toast a { color: #ffb072; font-weight: 600; text-decoration: none; }

@media (max-width: 480px) {
  .apa-chat { right: 8px; left: 8px; width: auto; bottom: 78px; height: calc(100vh - 110px); max-height: none; }
  #apa-chat-launcher { left: 12px; bottom: 12px; }
  #apa-chat-launcher.apa-raised { bottom: 82px; }
  .apa-chat.apa-raised { bottom: 146px; height: calc(100vh - 180px); }
  .apa-toast.apa-raised { bottom: 146px; }
}

.apa-chat-label {
  font-size: 14px;
  font-weight: 600;
  margin-left: 4px;
  white-space: nowrap;
}
#apa-chat-launcher {
  padding: 0;
  border-radius: 999px;
  width: 48px;
  height: 48px;
  overflow: hidden;
  transition: width .18s ease, padding .18s ease, transform .15s ease, box-shadow .15s ease;
}

/* Текст показуємо лише при наведенні, щоб не перекривати фільтри */
#apa-chat-launcher .apa-chat-label {
  max-width: 0;
  opacity: 0;
  overflow: hidden;
  transition: max-width .18s ease, opacity .18s ease, margin .18s ease;
  margin-left: 0;
}

#apa-chat-launcher:hover .apa-chat-label,
#apa-chat-launcher:focus-visible .apa-chat-label {
  max-width: 130px;
  opacity: 1;
  margin-left: 6px;
}

#apa-chat-launcher:hover,
#apa-chat-launcher:focus-visible {
  width: auto;
  padding: 0 16px 0 12px;
}
.apa-teaser {
  position: fixed;
  left: 18px;
  bottom: 84px;
  z-index: 2147483001;
  max-width: 250px;
  background: #0c1a35;
  border: 1px solid #27406d;
  border-radius: 14px;
  padding: 12px 30px 12px 14px;
  box-shadow: 0 16px 40px rgba(0,0,0,.5);
  color: #dbe3f2;
  font-size: 13px;
  line-height: 1.35;
  cursor: pointer;
}
.apa-teaser b { display: block; color: #ffb072; margin-bottom: 3px; font-size: 13.5px; }
.apa-teaser__close {
  position: absolute; top: 6px; right: 8px;
  background: none; border: none; color: #9aa8c3;
  font-size: 18px; line-height: 1; cursor: pointer;
}

/* Один разовый «пульс» кнопки чата — привлекает внимание новичка */
@media (prefers-reduced-motion: no-preference) {
  #apa-chat-launcher.apa-pulse::after {
    content: "";
    position: absolute;
    inset: -5px;
    border-radius: 999px;
    border: 2px solid rgba(255, 106, 0, .55);
    animation: apaPulse 1.5s ease-out 2;
    pointer-events: none;
  }
}

@keyframes apaPulse {
  0% { transform: scale(.92); opacity: .85; }
  100% { transform: scale(1.35); opacity: 0; }
}

/* Карточка товара в чате — кликабельная */
.apa-part.is-link {
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease;
}

.apa-part.is-link:hover {
  border-color: rgba(255, 157, 69, .55);
  background: rgba(255, 157, 69, .06);
}

.apa-part.is-link:focus-visible {
  outline: 2px solid rgba(255, 157, 69, .6);
  outline-offset: 2px;
}

/* ── Оверлей карточки товара в чате ─────────────────────────────────── */
.apa-pm-backdrop {
  position: fixed;
  inset: 0;
  z-index: 2147483600;
  background: rgba(4, 10, 22, .66);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.apa-pm {
  position: relative;
  width: min(420px, 100%);
  background: #102448;
  border: 1px solid #27406d;
  border-radius: 16px;
  padding: 18px;
  color: #e8eefc;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .55);
}

.apa-pm__close {
  position: absolute;
  top: 8px;
  right: 10px;
  background: none;
  border: none;
  color: #9aa8c3;
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
}

.apa-pm__head { display: flex; gap: 14px; align-items: flex-start; }

.apa-pm__img {
  width: 96px;
  height: 96px;
  object-fit: contain;
  border-radius: 10px;
  background: #0b1b37;
  flex: 0 0 auto;
}

.apa-pm__info { min-width: 0; }

.apa-pm__name { font-size: 15px; font-weight: 600; line-height: 1.35; padding-right: 18px; }

.apa-pm__meta { font-size: 12px; color: #9aa8c3; margin-top: 3px; }

.apa-pm__price { font-size: 20px; font-weight: 700; color: #ffb072; margin-top: 8px; }

.apa-pm__avail { font-size: 12.5px; color: #7fd6a0; margin-top: 2px; }

.apa-pm__actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }

.apa-pm__add {
  flex: 1 1 auto;
  min-height: 42px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(145deg, #ff8b34, #ff6a00);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

.apa-pm__open {
  flex: 1 1 auto;
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  border: 1px solid #27406d;
  color: #cfd8ea;
  text-decoration: none;
  font-size: 13px;
}

@media (max-width: 480px) {
  .apa-pm-backdrop { align-items: flex-end; padding: 0; }
  .apa-pm {
    width: 100%;
    border-radius: 16px 16px 0 0;
    padding: 16px 14px calc(16px + env(safe-area-inset-bottom));
  }
}

/* Кнопка «Новий чат» в шапке */
.apa-chat__reset {
  margin-left: auto;
  margin-right: 4px;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: none;
  background: rgba(255, 255, 255, .16);
  color: inherit;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s ease;
}
.apa-chat__reset:hover { background: rgba(255, 255, 255, .3); }
.apa-chat__reset:active { transform: scale(.95); }
