/* Avy AI Chat - floating widget.
   Colors driven by --avy-accent, set per-site from admin. */

#avy-ai-chat-root {
  --avy-accent: #1a73e8;
  --avy-accent-dark: #1557b0;
  --avy-bg: #ffffff;
  --avy-bubble-bot: #f1f3f4;
  --avy-text: #202124;
  --avy-text-muted: #5f6368;
  --avy-border: #e4e7eb;
  --avy-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
  --avy-radius: 16px;
  position: fixed;
  z-index: 2147483000;
  bottom: 85px;
  right: 33px;
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--avy-text);
}

#avy-ai-chat-root[data-position="bottom-left"] {
  right: auto;
  left: 20px;
}

#avy-ai-chat-root * {
  box-sizing: border-box;
}

/* Floating launcher button */
.avy-launcher {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--avy-accent);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
  border: none;
  transition:
    transform 0.2s ease,
    background 0.2s ease;
}
.avy-launcher:hover {
  transform: translateY(-2px);
  background: var(--avy-accent-dark);
}
.avy-launcher svg {
  width: 28px;
  height: 28px;
  fill: currentColor;
}

.avy-launcher .avy-launcher-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: #ff3b30;
  color: #fff;
  font-size: 11px;
  line-height: 1;
  padding: 4px 6px;
  border-radius: 10px;
  display: none;
}
.avy-launcher.has-badge .avy-launcher-badge {
  display: inline-block;
}
#avy-ai-chat-root .avy-header {
  background: #2a55cb;
}
/* Chat window */
.avy-window {
  position: absolute;
  bottom: 76px;
  right: 0;
  width: 380px;
  max-width: calc(100vw - 40px);
  height: 560px;
  max-height: calc(100vh - 120px);
  background: var(--avy-bg);
  border-radius: var(--avy-radius);
  box-shadow: var(--avy-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--avy-border);
  opacity: 0;
  transform: translateY(10px) scale(0.98);
  pointer-events: none;
  transition:
    opacity 0.2s ease,
    transform 0.2s ease;
}
#avy-ai-chat-root[data-position="bottom-left"] .avy-window {
  right: auto;
  left: 0;
}
.avy-window.is-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* Header — scoped under #avy-ai-chat-root so the bare .avy-header rule does
   not collide with the theme's site <header class="avy-header"> and force it
   to display:flex (which side-stacks __main and __nav on one row). */
#avy-ai-chat-root .avy-header {
  background: var(--avy-accent);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}
#avy-ai-chat-root .avy-header-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}
#avy-ai-chat-root .avy-header-avatar svg {
  width: 22px;
  height: 22px;
  fill: #fff;
}
#avy-ai-chat-root .avy-header-text {
  flex: 1 1 auto;
  min-width: 0;
}
#avy-ai-chat-root .avy-header-title {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.2;
}
#avy-ai-chat-root .avy-header-sub {
  font-size: 11px;
  opacity: 0.85;
  margin-top: 2px;
}
#avy-ai-chat-root .avy-header-action {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #fff;
  cursor: pointer;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}
#avy-ai-chat-root .avy-header-action:hover {
  background: rgba(255, 255, 255, 0.28);
}
.avy-header-action svg {
  width: 16px;
  height: 16px;
  fill: #fff;
}

/* Messages area */
.avy-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px;
  background: #fafbfc;
  scroll-behavior: smooth;
}

.avy-msg {
  max-width: 85%;
  margin-bottom: 12px;
  padding: 10px 13px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  animation: avy-fade-in 0.25s ease;
}
.avy-msg.avy-bot {
  background: var(--avy-bubble-bot);
  border-bottom-left-radius: 4px;
  align-self: flex-start;
}
.avy-msg.avy-user {
  background: var(--avy-accent);
  color: #fff;
  border-bottom-right-radius: 4px;
  margin-left: auto;
}
.avy-msg p {
  margin: 0 0 6px;
}
.avy-msg p:last-child {
  margin-bottom: 0;
}
.avy-msg a {
  color: var(--avy-accent);
  text-decoration: underline;
}
.avy-msg.avy-user a {
  color: #fff;
}
.avy-msg strong {
  font-weight: 600;
}
.avy-msg ul,
.avy-msg ol {
  margin: 4px 0 4px 18px;
  padding: 0;
}
.avy-msg code {
  background: rgba(0, 0, 0, 0.06);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 0.92em;
}

@keyframes avy-fade-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Typing indicator */
.avy-typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  height: 18px;
}
.avy-typing span {
  width: 7px;
  height: 7px;
  background: var(--avy-text-muted);
  border-radius: 50%;
  opacity: 0.4;
  animation: avy-bounce 1.2s infinite;
}
.avy-typing span:nth-child(2) {
  animation-delay: 0.2s;
}
.avy-typing span:nth-child(3) {
  animation-delay: 0.4s;
}
@keyframes avy-bounce {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-5px);
    opacity: 1;
  }
}

/* Product / article cards */
.avy-cards {
  margin-top: 10px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}
.avy-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  background: #fff;
  border: 1px solid var(--avy-border);
  border-radius: 10px;
  text-decoration: none;
  color: var(--avy-text);
  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease;
}
.avy-card:hover {
  border-color: var(--avy-accent);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}
.avy-card-thumb {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  object-fit: cover;
  background: #eef1f4;
  flex: 0 0 auto;
}
.avy-card-body {
  min-width: 0;
  flex: 1 1 auto;
}
.avy-card-title {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
  margin-bottom: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.avy-card-meta {
  font-size: 12px;
  color: var(--avy-text-muted);
}

/* FAQ source citations (Track E) — small row under an answer */
.avy-sources {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 6px;
  font-size: 11px;
  line-height: 1.4;
  color: var(--avy-text-muted);
}
.avy-sources-label {
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 10px;
}
.avy-source-chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  background: #f1f3f5;
  border: 1px solid var(--avy-border);
  color: var(--avy-text);
  text-decoration: none;
  font-size: 11px;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition:
    background 0.15s ease,
    border-color 0.15s ease;
}
.avy-source-chip:hover {
  background: #e7ecef;
  border-color: var(--avy-accent);
}

/* Quick replies */
.avy-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}
.avy-quick button {
  background: #fff;
  border: 1px solid var(--avy-accent);
  color: var(--avy-accent);
  padding: 5px 10px;
  font-size: 12px;
  border-radius: 14px;
  cursor: pointer;
  transition:
    background 0.15s ease,
    color 0.15s ease;
  font-family: inherit;
}
.avy-quick button:hover {
  background: var(--avy-accent);
  color: #fff;
}

/* Composer */
.avy-composer {
  flex: 0 0 auto;
  border-top: 1px solid var(--avy-border);
  padding: 10px;
  background: #fff;
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.avy-composer textarea {
  flex: 1 1 auto;
  resize: none;
  border: 1px solid var(--avy-border);
  border-radius: 12px;
  padding: 9px 12px;
  font-size: 14px;
  line-height: 1.4;
  min-height: 40px;
  max-height: 120px;
  font-family: inherit;
  color: var(--avy-text);
  background: #fff;
  outline: none;
  transition: border-color 0.15s ease;
}
.avy-composer textarea:focus {
  border-color: var(--avy-accent);
}
.avy-composer textarea:disabled {
  background: #fafbfc;
}
.avy-composer button {
  flex: 0 0 auto;
  background: var(--avy-accent);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}
.avy-composer button:hover {
  background: var(--avy-accent-dark);
}
.avy-composer button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.avy-composer button svg {
  width: 18px;
  height: 18px;
  fill: #fff;
}

/* Suggestions rail */
.avy-suggestions {
  padding: 0 16px 12px;
  background: #fafbfc;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.avy-suggestions:empty {
  display: none !important;
}
.avy-suggestions button {
  background: #fff;
  border: 1px solid var(--avy-border);
  color: var(--avy-text-muted);
  padding: 5px 10px;
  font-size: 12px;
  border-radius: 14px;
  cursor: pointer;
  font-family: inherit;
}
.avy-suggestions button:hover {
  border-color: var(--avy-accent);
  color: var(--avy-accent);
}

/* Power footer */
.avy-footer-note {
  font-size: 10px;
  color: var(--avy-text-muted);
  text-align: center;
  padding: 4px 0 8px;
  background: #fafbfc;
}

/* Mobile */
@media (max-width: 600px) {
  #avy-ai-chat-root {
    bottom: 70px;
    right: 15px;
  }
  #avy-ai-chat-root[data-position="bottom-left"] {
    left: 12px;
  }
  .avy-window {
    width: calc(100vw - 24px);
    height: calc(100vh - 140px);
    bottom: 65px;
  }
  .avy-launcher {
    width: 54px;
    height: 54px;
  }
}
