/* AI Assistant — matches existing site tokens, does not restyle the website */
:root {
  --ai-primary: var(--primary, #0056b3);
  --ai-accent: var(--accent, #00b4d8);
  --ai-dark: #0a2540;
  --ai-surface: rgba(255, 255, 255, 0.86);
  --ai-shadow: 0 18px 50px rgba(10, 37, 64, 0.22);
}

.ai-launcher {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 10040;
  width: 58px;
  height: 58px;
  border: 0;
  border-radius: 18px;
  cursor: pointer;
  color: #fff;
  background: linear-gradient(135deg, var(--ai-primary), var(--ai-accent));
  box-shadow: var(--ai-shadow);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.45rem;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
  isolation: isolate;
}

.ai-launcher:hover {
  transform: translateY(-3px) scale(1.03);
}

.ai-launcher.is-open {
  background: linear-gradient(135deg, #334155, #64748b);
}

.ai-panel {
  position: fixed;
  right: 22px;
  bottom: 92px;
  width: min(380px, calc(100vw - 24px));
  height: min(560px, calc(100vh - 120px));
  z-index: 10041;
  display: flex;
  flex-direction: column;
  border-radius: 22px;
  overflow: hidden;
  background: var(--ai-surface);
  backdrop-filter: blur(18px) saturate(1.2);
  -webkit-backdrop-filter: blur(18px) saturate(1.2);
  border: 1px solid rgba(255, 255, 255, 0.55);
  box-shadow: var(--ai-shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(16px) scale(0.96);
  transition: opacity 0.28s ease, transform 0.28s ease;
}

.ai-panel.is-open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

.ai-panel-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.9rem 1rem;
  background: linear-gradient(135deg, var(--ai-dark), var(--ai-primary));
  color: #fff;
}

.ai-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(255, 255, 255, 0.45);
  background: #fff;
  box-shadow: 0 0 0 0 rgba(0, 180, 216, 0.45);
  animation: aiAvatarPulse 2.4s ease-in-out infinite;
}

@keyframes aiAvatarPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(0, 180, 216, 0.35); }
  50% { box-shadow: 0 0 0 8px rgba(0, 180, 216, 0); }
}

.ai-panel-header h3 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
}

.ai-panel-header p {
  margin: 0;
  font-size: 0.75rem;
  opacity: 0.85;
}

.ai-header-actions {
  margin-left: auto;
  display: flex;
  gap: 0.35rem;
}

.ai-icon-btn {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  background: linear-gradient(180deg, rgba(248, 250, 252, 0.7), rgba(255, 255, 255, 0.55));
}

.ai-msg {
  max-width: 92%;
  padding: 0.7rem 0.85rem;
  border-radius: 14px;
  font-size: 0.9rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  animation: aiMsgIn 0.38s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes aiMsgIn {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
    filter: blur(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
    filter: blur(0);
  }
}

.ai-msg.bot {
  align-self: flex-start;
  background: #fff;
  border: 1px solid rgba(0, 86, 179, 0.08);
  box-shadow: 0 6px 18px rgba(10, 37, 64, 0.06);
}

.ai-msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--ai-primary), var(--ai-accent));
  color: #fff;
}

.ai-msg .ai-md strong { font-weight: 700; }
.ai-msg .ai-md code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82em;
  background: rgba(15, 23, 42, 0.06);
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
}
.ai-msg.user .ai-md code { background: rgba(255, 255, 255, 0.18); }
.ai-msg .ai-md pre {
  margin: 0.5rem 0 0;
  padding: 0.65rem;
  border-radius: 10px;
  background: #0f172a;
  color: #e2e8f0;
  overflow-x: auto;
  font-size: 0.78rem;
}
.ai-msg .ai-md ul { margin: 0.35rem 0 0 1.1rem; padding: 0; }

.ai-typing {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0.65rem 0.85rem;
  background: #fff;
  border-radius: 14px;
  border: 1px solid rgba(0, 86, 179, 0.08);
  animation: aiMsgIn 0.3s ease both;
}
.ai-typing-dots {
  display: inline-flex;
  gap: 4px;
}
.ai-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ai-primary);
  animation: aiDot 1s infinite ease-in-out;
}
.ai-typing span:nth-child(2) { animation-delay: 0.15s; }
.ai-typing span:nth-child(3) { animation-delay: 0.3s; }
.ai-thinking-label {
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #64748b;
  animation: aiThinkFade 1.4s ease-in-out infinite;
}
@keyframes aiDot {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-4px); opacity: 1; }
}
@keyframes aiThinkFade {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 1; }
}

.ai-cards {
  display: grid;
  gap: 0.5rem;
  margin-top: 0.55rem;
}
.ai-card {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  padding: 0.45rem;
  border-radius: 12px;
  background: #f8fafc;
  border: 1px solid rgba(0, 86, 179, 0.08);
  text-decoration: none;
  color: inherit;
  transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
  animation: aiCardSlide 0.45s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.ai-card:nth-child(2) { animation-delay: 0.06s; }
.ai-card:nth-child(3) { animation-delay: 0.12s; }
.ai-card:nth-child(4) { animation-delay: 0.18s; }
@keyframes aiCardSlide {
  from { opacity: 0; transform: translateX(16px); }
  to { opacity: 1; transform: translateX(0); }
}
.ai-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 24px rgba(10, 37, 64, 0.1);
  border-color: rgba(0, 180, 216, 0.35);
}
.ai-card img {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 10px;
  background: #e2e8f0;
}
.ai-card strong { display: block; font-size: 0.82rem; }
.ai-card span { display: block; font-size: 0.72rem; color: #64748b; }

.ai-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0 1rem 0.55rem;
}

.ai-wa-row {
  padding: 0 1rem 0.55rem;
}

.ai-wa-btn {
  width: 100%;
  border: 1px solid rgba(37, 211, 102, 0.35);
  background: linear-gradient(135deg, rgba(37, 211, 102, 0.12), rgba(18, 140, 126, 0.1));
  color: #0f766e;
  border-radius: 12px;
  padding: 0.55rem 0.75rem;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.ai-wa-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(18, 140, 126, 0.15);
}

.ai-wa-btn .bi-whatsapp {
  color: #25d366;
  font-size: 1rem;
}
.ai-chip {
  border: 1px solid rgba(0, 86, 179, 0.18);
  background: #fff;
  color: var(--ai-primary);
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  font-size: 0.75rem;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease, border-color 0.2s ease;
  animation: aiChipIn 0.4s ease both;
}
.ai-chip:nth-child(1) { animation-delay: 0.02s; }
.ai-chip:nth-child(2) { animation-delay: 0.08s; }
.ai-chip:nth-child(3) { animation-delay: 0.14s; }
.ai-chip:nth-child(4) { animation-delay: 0.2s; }
@keyframes aiChipIn {
  from { opacity: 0; transform: translateY(8px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.ai-chip:hover {
  transform: translateY(-2px);
  background: rgba(0, 86, 179, 0.06);
  border-color: var(--ai-accent);
}

.ai-composer {
  display: flex;
  gap: 0.4rem;
  padding: 0.75rem;
  border-top: 1px solid rgba(15, 23, 42, 0.06);
  background: rgba(255, 255, 255, 0.9);
}
.ai-composer input,
.ai-composer textarea {
  flex: 1;
  border: 1px solid #dbe3ee;
  border-radius: 12px;
  padding: 0.65rem 0.75rem;
  resize: none;
  font: inherit;
  min-height: 42px;
  max-height: 90px;
}
.ai-composer button {
  border: 0;
  border-radius: 12px;
  width: 42px;
  height: 42px;
  background: linear-gradient(135deg, var(--ai-primary), var(--ai-accent));
  color: #fff;
  cursor: pointer;
}
.ai-composer button:disabled { opacity: 0.6; cursor: not-allowed; }

.ai-search-wrap {
  position: relative;
  max-width: 420px;
  margin: 0 auto 16px;
}
.ai-search-wrap input {
  width: 100%;
  border-radius: 999px;
  border: 1px solid rgba(0, 86, 179, 0.15);
  padding: 0.75rem 1rem 0.75rem 2.6rem;
  background: #fff;
  box-shadow: 0 8px 24px rgba(10, 37, 64, 0.06);
}
.ai-search-wrap .bi-search {
  position: absolute;
  left: 0.95rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ai-primary);
}
.ai-search-results {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  background: #fff;
  border-radius: 14px;
  box-shadow: var(--ai-shadow);
  border: 1px solid rgba(0, 86, 179, 0.08);
  max-height: 280px;
  overflow: auto;
  display: none;
  z-index: 50;
}
.ai-search-results.is-open { display: block; }
.ai-search-item {
  display: block;
  padding: 0.65rem 0.85rem;
  text-decoration: none;
  color: inherit;
  border-bottom: 1px solid #f1f5f9;
}
.ai-search-item:hover { background: #f8fafc; }
.ai-search-item small { color: #64748b; }

@media (max-width: 575.98px) {
  .ai-launcher { right: 14px; bottom: 14px; }
  .ai-panel {
    right: 10px;
    left: 10px;
    width: auto;
    bottom: 78px;
    height: min(70vh, 560px);
  }
}

.ai-launcher::before {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 22px;
  border: 2px solid rgba(0, 180, 216, 0.35);
  animation: aiLauncherRing 2.2s ease-out infinite;
  pointer-events: none;
}
@keyframes aiLauncherRing {
  0% { transform: scale(0.92); opacity: 0.7; }
  100% { transform: scale(1.25); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .ai-panel,
  .ai-launcher,
  .ai-launcher::before,
  .ai-typing span,
  .ai-msg,
  .ai-card,
  .ai-chip,
  .ai-avatar,
  .ai-thinking-label {
    transition: none !important;
    animation: none !important;
  }
}
