#ap-chat-bubble {
  position: fixed;
  bottom: 22px;
  right: 22px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--accent-gradient);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px rgba(124, 58, 237, 0.45);
  z-index: 999;
  transition: transform 0.2s ease;
}
#ap-chat-bubble:hover { transform: scale(1.06); }
#ap-chat-bubble svg { width: 26px; height: 26px; color: #fff; }
#ap-chat-bubble .ap-close-icon { display: none; }
#ap-chat-bubble.ap-open .ap-chat-icon { display: none; }
#ap-chat-bubble.ap-open .ap-close-icon { display: block; }

#ap-chat-window {
  position: fixed;
  bottom: 92px;
  right: 22px;
  width: min(360px, calc(100vw - 32px));
  height: min(480px, calc(100vh - 140px));
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  display: none;
  flex-direction: column;
  overflow: hidden;
  z-index: 999;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
}
#ap-chat-window.ap-open { display: flex; }

#ap-chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  flex-shrink: 0;
}
#ap-chat-header > img {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  flex-shrink: 0;
}
#ap-chat-header-text {
  display: flex;
  flex-direction: column;
  line-height: 1.3;
  min-width: 0;
}

#ap-chat-header-title {
  font-family: Syne, sans-serif;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text-primary);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

#ap-verified-wrap {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  outline: none;
  flex-shrink: 0;
}
#ap-verified-badge {
  width: 1em;
  height: 1em;
  display: block;
}

/* Tooltip — fixed to viewport, appended to body, never clipped by widget */
#ap-verified-tooltip {
  position: fixed;
  background: var(--bg-card, #1e1b2e);
  border: 1px solid var(--border, rgba(124,58,237,0.35));
  color: var(--text-primary, #fff);
  font-family: "DM Sans", sans-serif;
  font-size: 0.72rem;
  font-weight: 500;
  white-space: nowrap;
  padding: 4px 10px;
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.45);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
  z-index: 10000;
}
#ap-verified-tooltip::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--border, rgba(124,58,237,0.35));
}
#ap-verified-tooltip.ap-tooltip-visible {
  opacity: 1;
}

#ap-chat-header-sub {
  font-size: 0.72rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 5px;
}
#ap-chat-header-sub::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #7c3aed;
  display: inline-block;
}

#ap-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.ap-msg {
  font-size: 0.88rem;
  line-height: 1.5;
  max-width: 85%;
  padding: 9px 13px;
  word-break: break-word;
  white-space: pre-wrap;
}
.ap-msg-bot {
  white-space: normal;
}
.ap-msg-bot {
  align-self: flex-start;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 2px 12px 12px;
  color: var(--text-primary);
}
.ap-msg-user {
  align-self: flex-end;
  background: var(--accent-purple);
  border-radius: 12px 2px 12px 12px;
  color: #fff;
}
.ap-msg-typing { opacity: 0.6; font-style: italic; }

#ap-chat-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  border-top: 1px solid var(--border);
  padding: 10px;
  flex-shrink: 0;
}
#ap-chat-input {
  flex: 1;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  color: var(--text-primary);
  font-family: "DM Sans", sans-serif;
  font-size: 0.88rem;
  outline: none;
}
#ap-chat-input:focus { border-color: var(--accent-purple); }
#ap-chat-send {
  background: var(--accent-gradient);
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  color: #fff;
  font-weight: 600;
  font-family: "DM Sans", sans-serif;
  font-size: 0.85rem;
  cursor: pointer;
  transition: opacity 0.2s;
  flex-shrink: 0;
}
#ap-chat-send:disabled { opacity: 0.5; cursor: default; }

@media (max-width: 420px) {
  #ap-chat-window { right: 16px; left: 16px; width: auto; bottom: 84px; }
  #ap-chat-bubble { right: 16px; }
}

/* Markdown rendering inside bot messages */
.ap-msg-bot p {
  margin: 0 0 6px;
}
.ap-msg-bot p:last-child {
  margin-bottom: 0;
}
.ap-msg-bot strong {
  font-weight: 700;
  color: var(--text-primary, #fff);
}
.ap-msg-bot ul {
  margin: 6px 0 6px 0;
  padding-left: 16px;
  list-style: disc;
}
.ap-msg-bot li {
  margin-bottom: 3px;
  line-height: 1.5;
}

/* ── Menu buttons ── */
.ap-btn-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 4px 0 2px;
  max-width: 100%;
}

.ap-menu-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 6px 12px;
  color: var(--text-primary);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.18s, border-color 0.18s, transform 0.12s;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  line-height: 1.4;
}

.ap-menu-btn:hover {
  background: rgba(124, 58, 237, 0.12);
  border-color: var(--accent-purple);
  transform: translateY(-1px);
}

.ap-menu-btn:active { transform: translateY(0); }
