/* Віджет чат-бота (templates/partials/chatbot.php, assets/js/chatbot.js).
   Кольори/шрифти — з дизайн-системи main.css (:root). */

.chatbot {
  --cb-bottom: 20px;
  position: fixed;
  right: 20px;
  bottom: calc(var(--cb-bottom) + env(safe-area-inset-bottom, 0px));
  z-index: 90; /* нижче за cookie-банер (100), вище за sticky-шапку (40) */
  font-family: var(--font-body, system-ui, sans-serif);
}
/* поки видно cookie-банер — піднімаємо кнопку над ним (клас ставить chatbot.js) */
.chatbot.is-lifted { --cb-bottom: calc(var(--cookie-h, 90px) + 16px); }

.chatbot__toggle {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 0;
  cursor: pointer;
  color: #FFFFFF;
  background: linear-gradient(135deg, var(--color-brand, #00A7C7), var(--color-brand-dark, #007C93));
  box-shadow: 0 10px 30px rgba(0, 124, 147, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  position: relative;
}
.chatbot__toggle:hover,
.chatbot__toggle:focus-visible { transform: translateY(-2px); box-shadow: 0 14px 34px rgba(0, 124, 147, 0.45); }
.chatbot__toggle:focus-visible { outline: 3px solid var(--color-tint-2, #CDEEF3); outline-offset: 3px; }
.chatbot__icon-close { display: none; }
.chatbot.is-open .chatbot__icon-open { display: none; }
.chatbot.is-open .chatbot__icon-close { display: block; }

/* «пульс»-крапка, поки чат ще не відкривали */
.chatbot__toggle.has-dot::after {
  content: '';
  position: absolute;
  top: 6px;
  right: 6px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--color-accent-orange, #E76F3D);
  border: 2px solid #FFFFFF;
}

.chatbot__panel {
  position: absolute;
  right: 0;
  bottom: 76px;
  width: 370px;
  max-width: calc(100vw - 40px);
  height: 560px;
  max-height: calc(100vh - 120px);
  max-height: calc(100dvh - 120px);
  background: #FFFFFF;
  border: 1px solid var(--color-border, #E4EEF0);
  border-radius: 18px;
  box-shadow: 0 24px 60px rgba(11, 31, 38, 0.22);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  animation: chatbot-in 0.2s ease;
}
.chatbot__panel[hidden] { display: none; }
@keyframes chatbot-in { from { opacity: 0; transform: translateY(10px) scale(0.97); } to { opacity: 1; transform: none; } }

.chatbot__head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 14px 14px 16px;
  background: var(--color-ink, #0B1F26);
  color: #FFFFFF;
}
.chatbot__avatar { width: 36px; height: 36px; border-radius: 10px; background: rgba(255, 255, 255, 0.08); padding: 5px; object-fit: contain; flex-shrink: 0; }
.chatbot__title { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.chatbot__title strong { font-family: var(--font-heading, system-ui); font-size: 15px; line-height: 1.2; }
.chatbot__title span { font-size: 12px; color: #9FBCC4; }
.chatbot__close {
  border: 0;
  background: transparent;
  color: #D7E7EA;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chatbot__close:hover { background: rgba(255, 255, 255, 0.08); }

.chatbot__log {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 8px;
  background: var(--color-surface, #F7FBFC);
  display: flex;
  flex-direction: column;
  gap: 8px;
  overscroll-behavior: contain;
}

.chatbot__msg {
  max-width: 86%;
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-line;
  overflow-wrap: anywhere;
}
.chatbot__msg--bot {
  align-self: flex-start;
  background: #FFFFFF;
  color: var(--color-ink, #0B1F26);
  border: 1px solid var(--color-border, #E4EEF0);
  border-bottom-left-radius: 4px;
}
.chatbot__msg--user {
  align-self: flex-end;
  background: var(--color-brand-dark, #007C93);
  color: #FFFFFF;
  border-bottom-right-radius: 4px;
}
.chatbot__links { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; white-space: normal; }
.chatbot__links a {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-brand-dark, #007C93);
  background: var(--color-tint, #F1FBFC);
  border: 1px solid var(--color-tint-2, #CDEEF3);
  border-radius: 999px;
  padding: 4px 10px;
  text-decoration: none;
}
.chatbot__links a:hover { background: var(--color-tint-2, #CDEEF3); }

.chatbot__typing { align-self: flex-start; display: flex; gap: 4px; padding: 12px 14px; background: #FFFFFF; border: 1px solid var(--color-border, #E4EEF0); border-radius: 14px; }
.chatbot__typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--color-faint, #7C99A1); animation: chatbot-dot 1s infinite ease-in-out; }
.chatbot__typing span:nth-child(2) { animation-delay: 0.15s; }
.chatbot__typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes chatbot-dot { 0%, 80%, 100% { opacity: 0.3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

.chatbot__buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 14px;
  background: var(--color-surface, #F7FBFC);
  max-height: 150px;
  overflow-y: auto;
}
.chatbot__buttons:empty { display: none; }
.chatbot__btn {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-brand-dark, #007C93);
  background: #FFFFFF;
  border: 1px solid var(--color-brand, #00A7C7);
  border-radius: 999px;
  padding: 7px 12px;
  cursor: pointer;
  text-align: left;
  line-height: 1.3;
  transition: background 0.15s ease, color 0.15s ease;
}
.chatbot__btn:hover,
.chatbot__btn:focus-visible { background: var(--color-brand, #00A7C7); color: #FFFFFF; }

.chatbot__form {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--color-border, #E4EEF0);
  background: #FFFFFF;
}
.chatbot__input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 16px; /* ≥16px — щоб iOS не зумив сторінку при фокусі */
  padding: 10px 12px;
  border: 1px solid var(--color-border, #E4EEF0);
  border-radius: 12px;
  color: var(--color-ink, #0B1F26);
  background: #FFFFFF;
}
.chatbot__input:focus { outline: none; border-color: var(--color-brand, #00A7C7); box-shadow: 0 0 0 3px var(--color-tint, #F1FBFC); }
.chatbot__send {
  width: 44px;
  flex-shrink: 0;
  border: 0;
  border-radius: 12px;
  background: var(--color-brand, #00A7C7);
  color: #FFFFFF;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chatbot__send:disabled { opacity: 0.5; cursor: default; }

.chatbot__sr {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0);
  white-space: nowrap; border: 0;
}

/* Мобільні: панель на весь екран, кнопка трохи менша */
@media (max-width: 640px) {
  .chatbot { right: 16px; --cb-bottom: 16px; }
  .chatbot__toggle { width: 54px; height: 54px; }
  .chatbot.is-open .chatbot__toggle { display: none; }
  .chatbot__panel {
    position: fixed;
    inset: 0;
    width: 100%;
    max-width: none;
    height: 100%;
    max-height: none;
    border-radius: 0;
    border: 0;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: #FFFFFF;
  }
  .chatbot__msg { max-width: 90%; }
}

@media (prefers-reduced-motion: reduce) {
  .chatbot__panel, .chatbot__typing span { animation: none; }
  .chatbot__toggle { transition: none; }
}

@media print { .chatbot { display: none; } }
