/* ════════════════════════════════════════════════════════════════════════════
   CHAT PANEL  (#ai-chat-panel) — look, animations and phone behaviour.
   Loaded after css/main.css and overrides its chat rules; kept in its own file
   because main.css is compiled from SCSS. The script is in main.js ("AI CHATBOT").
   Colours kept from the original: dark header #2E2E2E, light body #f6f6f6,
   blue assistant bubble, yellow visitor bubble, blue/yellow rings on the icons.
   ════════════════════════════════════════════════════════════════════════════ */

#ai-chat-panel {
  right: 24px;
  bottom: 24px;
  width: 392px;
  height: min(640px, calc(100vh - 48px));
  background: #f6f6f6;
  border-radius: 24px;
  overflow: hidden;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28), 0 2px 8px rgba(0, 0, 0, 0.12);
  font-family: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  transform-origin: bottom right;
  opacity: 0;
  visibility: hidden;
  transform: translateY(18px) scale(0.94);
  transition: opacity 0.2s ease, transform 0.34s cubic-bezier(0.2, 0.9, 0.3, 1.12), visibility 0s linear 0.34s;
  -webkit-tap-highlight-color: transparent;
}
#ai-chat-panel.is-open {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition: opacity 0.2s ease, transform 0.34s cubic-bezier(0.2, 0.9, 0.3, 1.12), visibility 0s;
}

/* the round launcher steps aside while the panel is open */
#ai-chatbot-cont { transition: opacity 0.2s ease, transform 0.2s ease; }
html.ai-chat-open #ai-chatbot-cont { opacity: 0; transform: scale(0.8); pointer-events: none; }

/* ── HEADER ─────────────────────────────────────────────────────────────── */
.ai-chat-panel__header {
  flex: 0 0 auto;
  padding: 14px 14px 14px 16px;
  justify-content: space-between;
  gap: 12px;
  border-radius: 0;
  background-color: #2E2E2E;
}
.ai-chat-panel__id { display: flex; align-items: center; gap: 12px; min-width: 0; }
.ai-chat-panel__badge {
  flex: 0 0 auto;
  width: 42px; height: 42px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(255, 255, 255, 0.1);
}
.ai-chat-panel__header #ai-chat-panel__header-ailogo { position: static; width: 26px; height: auto; display: block; }
.ai-chat-panel__titles { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.ai-chat-panel__title { color: #fff; font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ai-chat-panel__status { display: flex; align-items: center; gap: 6px; margin-top: 3px; color: rgba(255, 255, 255, 0.66); font-size: 12.5px; }
.ai-chat-panel__status i {
  width: 7px; height: 7px; border-radius: 50%;
  background: #34c759;
  box-shadow: 0 0 0 0 rgba(52, 199, 89, 0.6);
  animation: ai-pulse 2.4s ease-out infinite;
}
.ai-chat-panel__close {
  flex: 0 0 auto;
  width: 34px; height: 34px;
  padding: 0;
  border-radius: 50%;
  justify-content: center;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  transition: background 0.15s ease, transform 0.15s ease;
}
.ai-chat-panel__close:hover { background: rgba(255, 255, 255, 0.2); color: #fff; }
.ai-chat-panel__close:active { transform: scale(0.92); }
.ai-chat-panel__close svg { width: 14px; height: 14px; display: block; }

/* ── BODY ───────────────────────────────────────────────────────────────── */
.ai-chat-panel__body { position: relative; padding: 0; min-height: 0; }
.ai-chat-panel__logo-wrap {
  inset: 0;
  width: auto; height: auto;
  padding: 0;
  align-content: center;
  gap: 14px;
  transition: opacity 0.4s ease;
}
.ai-chat-panel__logo { opacity: 0.08; filter: none; }
.ai-chat-panel__logo-wrap #ai-chat-panel__logo-long { width: 70%; }
#ai-chat-panel.has-messages .ai-chat-panel__logo-wrap { opacity: 0.55; }

.ai-chat-panel__messages {
  position: relative;
  gap: 10px;
  padding: 16px 14px 10px;
  min-height: 0;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 0, 0, 0.18) transparent;
}
.ai-chat-panel__messages::-webkit-scrollbar { width: 5px; }
.ai-chat-panel__messages::-webkit-scrollbar-thumb { background: rgba(0, 0, 0, 0.16); border-radius: 99px; }

/* ── MESSAGES ───────────────────────────────────────────────────────────── */
.ai-msg {
  align-items: flex-end;
  gap: 8px;
  padding: 0;
  animation: ai-msg-in 0.34s cubic-bezier(0.2, 0.9, 0.3, 1.1) both;
}
.ai-msg--assistant { padding-left: 0; transform-origin: bottom left; }
.ai-msg--user { padding-right: 0; flex-direction: row-reverse; justify-content: flex-start; transform-origin: bottom right; }
.ai-msg.is-restored { animation: none; }

.ai-msg__avatar {
  position: static;
  width: 32px; height: 32px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
}
.ai-msg--assistant .ai-msg__avatar { border-width: 2px; }
.ai-msg--user .ai-msg__avatar { border-width: 2px; }
.ai-msg__avatar-img { width: 19px; }
.userpicture img { width: 15px; }

.ai-msg__bubble {
  padding: 10px 14px;
  max-width: 78%;
  border-radius: 20px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  font-size: 15.5px;
  font-weight: 400;
  line-height: 1.45;
  white-space: pre-wrap;
  color: #1d1d1f;
}
.ai-msg--assistant .ai-msg__bubble { background: #dbe6fd; border-radius: 20px 20px 20px 6px; }
.ai-msg--user .ai-msg__bubble { background: #f7e5a6; border-radius: 20px 20px 6px 20px; }
.ai-msg__bubble.is-error { background: #fde3e1; color: #8a1f17; }
.ai-msg__bubble.is-fresh { animation: ai-fade 0.3s ease both; }

/* three dots while the answer is being written */
.ai-typing { display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 2px; }
.ai-typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: rgba(46, 46, 46, 0.5);
  animation: ai-dot 1.2s ease-in-out infinite;
}
.ai-typing span:nth-child(2) { animation-delay: 0.15s; }
.ai-typing span:nth-child(3) { animation-delay: 0.3s; }

/* suggested questions under the greeting */
.ai-chat-chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 4px 0 0 40px; }
.ai-chat-chip {
  border: 1px solid rgba(0, 0, 0, 0.12);
  background: #fff;
  color: #1d1d1f;
  font: inherit;
  font-size: 14px;
  line-height: 1.2;
  padding: 9px 14px;
  border-radius: 999px;
  cursor: pointer;
  text-align: left;
  animation: ai-msg-in 0.34s cubic-bezier(0.2, 0.9, 0.3, 1.1) both;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}
.ai-chat-chip:nth-child(1) { animation-delay: 0.12s; }
.ai-chat-chip:nth-child(2) { animation-delay: 0.19s; }
.ai-chat-chip:nth-child(3) { animation-delay: 0.26s; }
.ai-chat-chip:hover { background: #eef3ff; border-color: #86aaf7; }
.ai-chat-chip:active { transform: scale(0.96); }

/* ── FOOTER ─────────────────────────────────────────────────────────────── */
.ai-chat-panel__footer {
  flex: 0 0 auto;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
  background: #f6f6f6;
  border-top: 1px solid rgba(0, 0, 0, 0.06);
}
.ai-chat-panel__form {
  gap: 6px;
  padding: 5px 5px 5px 16px;
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.12);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.ai-chat-panel__form:focus-within { border-color: #86aaf7; box-shadow: 0 0 0 3px rgba(134, 170, 247, 0.28); }
.ai-chat-panel__input {
  min-width: 0;
  padding: 7px 0;
  font-family: inherit;
  font-size: 16px;            /* 16px: iPhones zoom the page on smaller input text */
  line-height: 1.3;
  border-radius: 0;
  -webkit-appearance: none; appearance: none;
}
.ai-chat-panel__send {
  flex: 0 0 auto;
  width: 36px; height: 36px;
  padding: 0;
  display: grid; place-items: center;
  background-color: #86aaf7;
  transition: background 0.15s ease, transform 0.15s ease, opacity 0.15s ease;
}
.ai-chat-panel__send svg { width: 17px; height: 17px; display: block; }
.ai-chat-panel__send:active { transform: scale(0.9); }
.ai-chat-panel__send:disabled { background: #d3d6dc; cursor: default; transform: none; }
.ai-chat-panel__note { margin: 7px 0 0; text-align: center; font-size: 11px; line-height: 1.3; color: rgba(0, 0, 0, 0.42); }

/* ── PHONES: the chat is a full-screen sheet ────────────────────────────────
   --ai-vv-top / --ai-vv-h are set by main.js from the visible part of the screen,
   so the sheet shrinks to sit exactly above the on-screen keyboard (iPhone and
   Android) instead of being covered by it or pushed off the top. */
@media (max-width: 600px) {
  #ai-chat-panel {
    left: 0; right: 0;
    top: var(--ai-vv-top, 0px);
    bottom: auto;
    width: auto;
    height: var(--ai-vv-h, 100vh);
    border-radius: 0;
    box-shadow: none;
    transform-origin: bottom center;
    transform: translateY(28px);
  }
  @supports (height: 100dvh) { #ai-chat-panel { height: var(--ai-vv-h, 100dvh); } }
  #ai-chat-panel.is-open { transform: none; }
  .ai-chat-panel__header { padding-top: calc(12px + env(safe-area-inset-top, 0px)); padding-bottom: 12px; }
  .ai-chat-panel__close { width: 38px; height: 38px; }
  .ai-msg__bubble { max-width: 82%; font-size: 16px; }
  /* the page behind does not scroll while the sheet is open */
  html.ai-chat-open, html.ai-chat-open body { overflow: hidden; }
}

@keyframes ai-msg-in { from { opacity: 0; transform: translateY(10px) scale(0.96); } to { opacity: 1; transform: none; } }
@keyframes ai-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes ai-dot { 0%, 60%, 100% { transform: translateY(0); opacity: 0.45; } 30% { transform: translateY(-4px); opacity: 1; } }
@keyframes ai-pulse { 0% { box-shadow: 0 0 0 0 rgba(52, 199, 89, 0.55); } 70%, 100% { box-shadow: 0 0 0 6px rgba(52, 199, 89, 0); } }

@media (prefers-reduced-motion: reduce) {
  #ai-chat-panel, #ai-chat-panel.is-open { transition: opacity 0.15s ease, visibility 0s; transform: none; }
  .ai-msg, .ai-chat-chip, .ai-msg__bubble.is-fresh, .ai-typing span, .ai-chat-panel__status i { animation: none; }
}
