/* AI Assistant chat widget — theme-aware via the existing --bg/--card/--gold vars */

.ai-widget-btn {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 950;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #e8c887, var(--gold, #c9973f));
  color: #14200f;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.28), 0 0 0 6px rgba(212, 175, 106, 0.12);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  animation: ai-btn-breathe 3s ease-in-out infinite;
}

.ai-widget-btn:hover { transform: translateY(-2px) scale(1.06); }
.ai-widget-btn.open { animation: none; }

@keyframes ai-btn-breathe {
  0%, 100% { box-shadow: 0 10px 28px rgba(0, 0, 0, 0.28), 0 0 0 6px rgba(212, 175, 106, 0.12); }
  50% { box-shadow: 0 10px 32px rgba(0, 0, 0, 0.3), 0 0 0 11px rgba(212, 175, 106, 0.2); }
}

.ai-widget-btn svg { width: 26px; height: 26px; }

.ai-widget-btn .ai-icon-close { display: none; }

.ai-widget-btn.open .ai-icon-chat { display: none; }
.ai-widget-btn.open .ai-icon-close { display: block; }

.ai-widget-panel {
  position: fixed;
  right: 22px;
  bottom: 92px;
  z-index: 950;
  width: 368px;
  max-width: calc(100vw - 32px);
  height: 520px;
  max-height: calc(100vh - 140px);
  background: var(--bg-2, #fbfaf7);
  border: 1px solid transparent;
  border-radius: 20px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform-origin: bottom right;
  transform: translateY(20px) scale(0.9);
  pointer-events: none;
  transition: opacity 0.32s cubic-bezier(0.34, 1.56, 0.64, 1), transform 0.32s cubic-bezier(0.34, 1.56, 0.64, 1), visibility 0.32s;
  visibility: hidden;
}

.ai-widget-panel.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
  visibility: visible;
}

.ai-widget-panel::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 20px;
  padding: 1.5px;
  background: linear-gradient(115deg, var(--gold, #b8873a), #f3d9a4, var(--gold, #b8873a), #7c5a25, var(--gold, #b8873a));
  background-size: 300% 300%;
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  animation: ai-border-flow 7s linear infinite;
  pointer-events: none;
  z-index: 1;
}

@keyframes ai-border-flow {
  0% { background-position: 0% 50%; }
  100% { background-position: 300% 50%; }
}

.ai-widget-header {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--card-border, #e7e3da);
  background: linear-gradient(135deg, rgba(212, 175, 106, 0.14), rgba(212, 175, 106, 0.03));
}

.ai-widget-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, #e8c887, var(--gold, #c9973f));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #14200f;
  flex-shrink: 0;
}

.ai-widget-avatar svg { width: 18px; height: 18px; }

.ai-widget-header-text { display: flex; flex-direction: column; line-height: 1.25; }
.ai-widget-header-title { font-family: var(--serif, "Playfair Display", Georgia, serif); font-weight: 600; font-size: 0.95rem; color: var(--text, #14201a); }
.ai-widget-header-sub { font-size: 0.72rem; color: var(--text-muted, #4b564f); }

.ai-widget-messages {
  position: relative;
  z-index: 2;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: thin;
  scrollbar-color: rgba(184, 135, 58, 0.4) transparent;
}

.ai-widget-messages::-webkit-scrollbar { width: 6px; }
.ai-widget-messages::-webkit-scrollbar-track { background: transparent; }
.ai-widget-messages::-webkit-scrollbar-thumb {
  background: rgba(184, 135, 58, 0.35);
  border-radius: 10px;
}
.ai-widget-messages::-webkit-scrollbar-thumb:hover { background: rgba(184, 135, 58, 0.6); }

.ai-msg {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 88%;
  animation: ai-msg-in 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}
.ai-msg.user { align-self: flex-end; align-items: flex-end; }
.ai-msg.assistant { align-self: flex-start; align-items: flex-start; }

@keyframes ai-msg-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.ai-msg-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.ai-msg:hover .ai-msg-actions,
.ai-msg:focus-within .ai-msg-actions { opacity: 1; }

.ai-action-btn {
  width: 22px;
  height: 22px;
  border: none;
  background: transparent;
  color: var(--text-muted, #4b564f);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  padding: 0;
}
.ai-action-btn:hover { color: var(--gold, #c9973f); background: rgba(184, 135, 58, 0.1); }
.ai-action-btn.copied { color: #3f9c62; }
.ai-action-btn svg { width: 13px; height: 13px; }

.ai-bubble-attachment {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
  font-size: 0.76rem;
  opacity: 0.9;
}
.ai-bubble-attachment img {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  object-fit: cover;
}
.ai-bubble-attachment-icon {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.ai-bubble-attachment-icon svg { width: 18px; height: 18px; }

.ai-bubble {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.86rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.ai-msg.user .ai-bubble {
  background: var(--gold, #c9973f);
  color: #14200f;
  border-bottom-right-radius: 4px;
}

.ai-msg.assistant .ai-bubble {
  background: var(--card, rgba(20, 32, 26, 0.035));
  border: 1px solid var(--card-border, #e7e3da);
  color: var(--text, #14201a);
  border-bottom-left-radius: 4px;
}

.ai-bubble.ai-typing-bubble { display: flex; gap: 4px; align-items: center; padding: 12px 14px; }
.ai-typing-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-muted, #4b564f);
  animation: ai-typing-bounce 1.1s infinite ease-in-out;
}
.ai-typing-dot:nth-child(2) { animation-delay: 0.15s; }
.ai-typing-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes ai-typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.ai-listing-cards { display: flex; flex-direction: column; gap: 8px; width: 100%; }

.ai-listing-card {
  display: flex;
  gap: 10px;
  padding: 8px;
  background: var(--card, rgba(20, 32, 26, 0.035));
  border: 1px solid var(--card-border, #e7e3da);
  border-radius: 12px;
  text-decoration: none;
  color: var(--text, #14201a);
  transition: border-color 0.15s ease;
}

.ai-listing-card:hover { border-color: var(--gold-soft, rgba(184, 135, 58, 0.35)); }

.ai-listing-card-img {
  width: 56px;
  height: 56px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--bg, #fbfaf7);
}

.ai-listing-card-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ai-listing-card-price { font-family: var(--serif, "Playfair Display", Georgia, serif); font-weight: 600; color: var(--gold, #c9973f); font-size: 0.88rem; }
.ai-listing-card-title { font-size: 0.78rem; color: var(--text, #14201a); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-listing-card-meta { font-size: 0.72rem; color: var(--text-muted, #4b564f); }

.ai-attachment-preview {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 12px 8px;
  padding: 6px 8px;
  background: var(--card, rgba(20, 32, 26, 0.035));
  border: 1px solid var(--card-border, #e7e3da);
  border-radius: 10px;
  font-size: 0.78rem;
  color: var(--text, #14201a);
}

.ai-attachment-preview[hidden] { display: none; }

.ai-attachment-preview img {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
}

.ai-attachment-preview-icon {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.ai-attachment-preview-icon svg { width: 15px; height: 15px; color: var(--gold, #c9973f); }

.ai-attachment-preview-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-attachment-remove {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  border: none;
  background: transparent;
  color: var(--text-muted, #4b564f);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}
.ai-attachment-remove:hover { color: #c94f47; background: rgba(201, 79, 71, 0.12); }
.ai-attachment-remove svg { width: 12px; height: 12px; }

.ai-widget-form {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--card-border, #e7e3da);
  background: var(--bg-2, #fbfaf7);
}

.ai-attach-btn {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 10px;
  border: 1px solid var(--card-border, #e7e3da);
  cursor: pointer;
  background: var(--bg, #fbfaf7);
  color: var(--text-muted, #4b564f);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}
.ai-attach-btn:hover { color: var(--gold, #c9973f); border-color: var(--gold-soft, rgba(184, 135, 58, 0.35)); transform: translateY(-1px); }
.ai-attach-btn.active { color: var(--gold, #c9973f); border-color: var(--gold, #c9973f); }
.ai-attach-btn svg { width: 17px; height: 17px; }

.ai-attach-wrap { position: relative; flex-shrink: 0; }

.ai-attach-menu {
  position: absolute;
  bottom: 48px;
  left: 0;
  z-index: 10;
  min-width: 172px;
  background: var(--bg-2, #fbfaf7);
  border: 1px solid var(--card-border, #e7e3da);
  border-radius: 12px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.18);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ai-attach-menu[hidden] { display: none; }

.ai-attach-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border: none;
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text, #14201a);
  font-family: var(--sans, "Inter", system-ui, -apple-system, sans-serif);
  font-size: 0.82rem;
  text-align: left;
}
.ai-attach-menu-item:hover { background: rgba(184, 135, 58, 0.1); color: var(--gold, #c9973f); }
.ai-attach-menu-item svg { width: 16px; height: 16px; flex-shrink: 0; }

.ai-widget-input {
  flex: 1;
  border: 1px solid var(--card-border, #e7e3da);
  background: var(--bg, #fbfaf7);
  color: var(--text, #14201a);
  border-radius: 12px;
  padding: 10px 12px;
  font-family: var(--sans, "Inter", system-ui, -apple-system, sans-serif);
  font-size: 0.85rem;
  resize: none;
  max-height: 80px;
  overflow-y: hidden;
  scrollbar-width: thin;
  scrollbar-color: rgba(184, 135, 58, 0.4) transparent;
}

.ai-widget-input::-webkit-scrollbar { width: 6px; }
.ai-widget-input::-webkit-scrollbar-track { background: transparent; }
.ai-widget-input::-webkit-scrollbar-thumb {
  background: rgba(184, 135, 58, 0.35);
  border-radius: 10px;
}

.ai-widget-input:focus { outline: none; border-color: var(--gold-soft, rgba(184, 135, 58, 0.35)); }

.ai-widget-send {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  background: linear-gradient(135deg, #e8c887, var(--gold, #c9973f));
  color: #14200f;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.ai-widget-send:hover:not(:disabled) { transform: translateY(-1px) scale(1.05); box-shadow: 0 6px 16px rgba(184, 135, 58, 0.35); }
.ai-widget-send:disabled { opacity: 0.5; cursor: default; }
.ai-widget-send svg { width: 17px; height: 17px; }

.ai-widget-hint {
  position: relative;
  z-index: 2;
  margin: 0 16px 8px;
  padding: 0;
  font-size: 0.6rem;
  line-height: 1.4;
  color: var(--text-muted, #4b564f);
  opacity: 0.85;
}

@media (max-width: 480px) {
  .ai-widget-panel {
    right: 16px;
    left: 16px;
    width: auto;
    bottom: 88px;
  }
  .ai-widget-btn { right: 16px; bottom: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .ai-widget-btn,
  .ai-widget-panel,
  .ai-widget-panel::before,
  .ai-msg,
  .ai-widget-send,
  .ai-attach-btn {
    animation: none !important;
    transition: none !important;
  }
}
