/* 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;
}

/* ---------------------------------------------------------------
 * Human handoff (bot zone): request button bar
 * --------------------------------------------------------------- */
.avy-human-bar {
  flex: 0 0 auto;
  padding: 0 16px 10px;
  background: #fafbfc;
}
.avy-human-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 12px;
  background: #fff;
  border: 1px solid var(--avy-border);
  border-radius: 10px;
  color: var(--avy-text);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition:
    border-color 0.15s ease,
    color 0.15s ease;
}
.avy-human-btn:hover {
  border-color: var(--avy-accent);
  color: var(--avy-accent);
}
.avy-human-btn svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
  flex: 0 0 auto;
}
.avy-human-btn.is-offline {
  color: var(--avy-text-muted);
  border-style: dashed;
}
.avy-human-btn.is-offline:hover {
  border-color: var(--avy-text-muted);
  color: var(--avy-text-muted);
}

/* Human handoff status bar (pending queue / live session) */
.avy-status-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  font-size: 12.5px;
  line-height: 1.3;
  border-top: 1px solid var(--avy-border);
}
.avy-status-bar.is-pending {
  background: #fff8e6;
  color: #8a6100;
}
.avy-status-bar.is-active {
  background: #e8f7ee;
  color: #1c7c46;
}
.avy-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: 0 0 auto;
}
.avy-status-bar.is-pending .avy-status-dot {
  background: #f5a623;
  animation: avy-pulse 1.4s ease-in-out infinite;
}
.avy-status-bar.is-active .avy-status-dot {
  background: #34a853;
}
@keyframes avy-pulse {
  0%,
  100% {
    opacity: 0.45;
  }
  50% {
    opacity: 1;
  }
}
.avy-status-text {
  flex: 1 1 auto;
  min-width: 0;
}
.avy-status-link {
  flex: 0 0 auto;
  border: none;
  background: transparent;
  color: inherit;
  font-size: 12px;
  font-family: inherit;
  text-decoration: underline;
  cursor: pointer;
  padding: 2px 4px;
}
.avy-status-link:hover {
  opacity: 0.75;
}

/* Agent bubble + system notice + sender caption */
.avy-msg.avy-agent {
  background: #e8f0fe;
  border-bottom-left-radius: 4px;
  align-self: flex-start;
}
.avy-msg.avy-sys {
  max-width: 92%;
  margin: 4px auto 12px;
  padding: 6px 12px;
  background: #eef1f4;
  border: 1px dashed var(--avy-border);
  border-radius: 10px;
  color: var(--avy-text-muted);
  font-size: 12px;
  text-align: center;
}
.avy-sender {
  margin-top: 5px;
  font-size: 11px;
  color: var(--avy-text-muted);
}

/* Overlay panels: handoff form + leave-a-message form.
   Anchored to .avy-window (position: absolute). */
.avy-panel {
  position: absolute;
  top: 60px;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  background: var(--avy-bg);
  overflow-y: auto;
}
.avy-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.avy-panel-title {
  font-size: 15px;
  font-weight: 600;
}
.avy-panel-x {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: #f1f3f4;
  color: var(--avy-text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.avy-panel-x:hover {
  background: #e4e7eb;
}
.avy-panel-x svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}
.avy-input {
  width: 100%;
  border: 1px solid var(--avy-border);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 14px;
  font-family: inherit;
  color: var(--avy-text);
  background: #fff;
  outline: none;
  transition: border-color 0.15s ease;
}
.avy-input:focus {
  border-color: var(--avy-accent);
}
.avy-input::placeholder {
  color: #9aa0a6;
}
.avy-input-area {
  resize: vertical;
  min-height: 84px;
  line-height: 1.5;
}
.avy-panel-note {
  font-size: 12px;
  line-height: 1.4;
  padding: 8px 10px;
  border-radius: 8px;
  background: #fdeceb;
  border: 1px solid #f5c6c2;
  color: #c5221f;
}
/* The same note slot doubles as an informational work-window label. */
.avy-panel-note.avy-window-note {
  background: #e8f0fe;
  border-color: #c6dafc;
  color: #33509e;
}
.avy-panel-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: auto;
  padding-top: 4px;
}
.avy-btn {
  padding: 9px 16px;
  border: 1px solid var(--avy-border);
  border-radius: 10px;
  background: #fff;
  color: var(--avy-text);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition:
    background 0.15s ease,
    border-color 0.15s ease,
    color 0.15s ease;
}
.avy-btn:hover {
  border-color: var(--avy-accent);
  color: var(--avy-accent);
}
.avy-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.avy-btn-primary {
  background: var(--avy-accent);
  border-color: var(--avy-accent);
  color: #fff;
}
.avy-btn-primary:hover {
  background: var(--avy-accent-dark);
  border-color: var(--avy-accent-dark);
  color: #fff;
}
/* Honeypot: invisible to humans, present in DOM for bots to fill. */
.avy-hp {
  position: absolute;
  left: -9999px;
  top: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
}

/* 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;
  }
  .avy-status-bar {
    padding: 8px 12px;
    font-size: 12px;
  }
  .avy-panel {
    padding: 14px;
  }
}
