/* Default Background */
:root {
  --aac-primary: #2563eb;
}

/* =========================
   TOGGLE BUTTON
========================= */
#aac-chat-toggle {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 60px;
  height: 60px;
  background: linear-gradient(135deg, var(--aac-primary, #2563eb), #7c3aed);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  cursor: pointer;
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.3);
  z-index: 9999;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  overflow: visible;
}

#aac-chat-toggle::before {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(124, 58, 237, 0.28), transparent 70%);
  animation: aacTogglePulse 2.2s infinite;
  z-index: -1;
}

#aac-chat-toggle:hover {
  transform: scale(1.05);
}

#aac-chat-toggle.aac-opened::before {
  animation: none;
  opacity: 0;
}

#aac-chat-toggle.aac-chat-attention {
  animation: aacAttentionNudge 0.5s ease 2;
}

#aac-chat-toggle.aac-left {
  right: auto;
  left: 20px;
}

@keyframes aacTogglePulse {
  0% {
    transform: scale(0.92);
    opacity: 0.7;
  }
  70% {
    transform: scale(1.22);
    opacity: 0;
  }
  100% {
    transform: scale(1.22);
    opacity: 0;
  }
}

@keyframes aacAttentionNudge {
  0% { transform: translateX(0); }
  25% { transform: translateX(-2px); }
  50% { transform: translateX(2px); }
  75% { transform: translateX(-1px); }
  100% { transform: translateX(0); }
}

/* =========================
   CHAT WINDOW
========================= */
#aac-chat-window {
  position: fixed;
  bottom: 90px;
  right: 20px;
  width: 360px;
  height: 520px;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(14px);
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.5);
  opacity: 0;
  transform: translateY(20px);
  pointer-events: none;
  transition: 0.25s ease;
  z-index: 9999;
}

#aac-chat-window.active {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
  animation: aacWindowIn 0.28s ease;
}

#aac-chat-window.aac-left {
  right: auto;
  left: 20px;
}

#aac-chat-window.aac-busy {
  box-shadow:
    0 30px 60px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(255, 255, 255, 0.04);
}

@keyframes aacWindowIn {
  0% {
    opacity: 0;
    transform: translateY(22px) scale(0.98);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* =========================
   HEADER
========================= */
#aac-chat-header {
  position: relative;
  padding: 16px 16px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: linear-gradient(
    135deg,
    rgba(51, 65, 85, 0.95),
    rgba(30, 41, 59, 0.95)
  );
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  color: white;
  overflow: hidden;
  box-shadow:
    inset 0 -1px 0 rgba(255, 255, 255, 0.06),
    0 4px 20px rgba(0, 0, 0, 0.25);
}

#aac-chat-header::before {
  content: "";
  position: absolute;
  top: 0;
  left: -100%;
  width: 200%;
  height: 2px;
  background: linear-gradient(
    90deg,
    transparent,
    #7c3aed,
    #2563eb,
    transparent
  );
  animation: glowMove 2.5s linear infinite;
}

#aac-chat-header::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    120deg,
    rgba(255, 255, 255, 0.06),
    transparent 40%
  );
  pointer-events: none;
}

@keyframes glowMove {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

#aac-chat-title {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.3px;
}

#aac-chat-subtitle {
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  opacity: 0.75;
}

#aac-chat-subtitle::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 10px rgba(34, 197, 94, 0.65);
  flex: none;
}

/* =========================
   CLOSE BUTTON
========================= */
#aac-chat-header button {
  flex: none;
}

#aac-chat-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  color: #ffffff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  padding: 0;
}

#aac-chat-close:hover {
  background: rgba(255, 255, 255, 0.18);
  transform: scale(1.05);
}

#aac-chat-close:active {
  transform: scale(0.95);
}

/* =========================
   MESSAGES
========================= */
#aac-chat-messages {
  flex: 1;
  padding: 12px;
  overflow-y: auto;
  scroll-behavior: smooth;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.015), transparent 20%),
    radial-gradient(circle at top right, rgba(124, 58, 237, 0.08), transparent 30%);
}

#aac-chat-messages::-webkit-scrollbar {
  width: 8px;
}

#aac-chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

#aac-chat-messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 20px;
}

#aac-chat-messages::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

.aac-msg {
  padding: 10px 14px;
  margin-bottom: 10px;
  border-radius: 14px;
  max-width: 80%;
  font-size: 14px;
  line-height: 1.45;
  word-break: break-word;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.06);
  animation: aacFadeIn 0.25s ease;
}

.aac-msg:hover {
  transform: scale(1.01);
  transition: 0.15s ease;
}

.aac-user-msg {
  background: linear-gradient(135deg, var(--aac-primary, #2563eb), #7c3aed);
  color: white;
  margin-left: auto;
  border-top-right-radius: 8px;
  box-shadow: 0 10px 25px rgba(79, 70, 229, 0.35);
}

.aac-bot-msg {
  background: rgba(30, 41, 59, 0.85);
  color: #e2e8f0;
  border-top-left-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.aac-first-msg {
  animation: aacFirstPop 0.4s ease;
}

@keyframes aacFadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes aacFirstPop {
  from {
    transform: translateY(10px) scale(0.96);
    opacity: 0;
  }
  to {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

/* =========================
   INPUT
========================= */
#aac-chat-input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  border-top: 1px solid #1e293b;
  padding: 10px;
  background: rgba(2, 6, 23, 0.35);
}

#aac-chat-input {
  flex: 1;
  min-height: 44px;
  max-height: 110px;
  resize: none;
  padding: 12px 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  outline: none;
  background: rgba(255, 255, 255, 0.04);
  color: #fff;
  border-radius: 14px;
  font-size: 14px;
  transition: all 0.2s ease;
  overflow-y: auto;
}

#aac-chat-input:hover {
  background: rgba(255, 255, 255, 0.06);
}

#aac-chat-input:focus {
  border-color: rgba(124, 58, 237, 0.6);
  box-shadow:
    0 0 0 2px rgba(255, 255, 255, 0.06),
    0 0 0 4px rgba(124, 58, 237, 0.2);
  background: rgba(255, 255, 255, 0.06);
}

#aac-chat-input::placeholder {
  color: #64748b;
}

#aac-chat-send {
  min-width: 68px;
  padding: 12px 18px;
  background: linear-gradient(135deg, #6366f1, #7c3aed);
  border: none;
  color: white;
  cursor: pointer;
  border-radius: 14px;
  font-weight: 600;
  transition: 0.2s ease;
  box-shadow: 0 8px 25px rgba(124, 58, 237, 0.45);
}

#aac-chat-send:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 28px rgba(124, 58, 237, 0.42);
}

#aac-chat-send:active {
  transform: scale(0.96);
}

#aac-chat-send:disabled {
  opacity: 0.7;
  cursor: not-allowed;
  transform: none;
}

#aac-chat-send.aac-is-loading {
  letter-spacing: 2px;
}

/* =========================
   TYPING
========================= */
.aac-typing::after {
  content: "...";
  animation: blink 1s infinite;
}

.aac-typing-wrap {
  display: inline-flex;
  align-items: center;
  min-width: 64px;
}

.aac-typing-dots {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  justify-content: center;
  height: 14px;
}

.aac-typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.75);
  animation: aacTypingBounce 1.2s infinite ease-in-out;
}

.aac-typing-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.aac-typing-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes blink {
  0% { opacity: 0.2; }
  50% { opacity: 1; }
  100% { opacity: 0.2; }
}

@keyframes aacTypingBounce {
  0%, 80%, 100% {
    transform: translateY(0);
    opacity: 0.45;
  }
  40% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

/* =========================
   MOBILE
========================= */
@media (max-width: 640px) {
  #aac-chat-toggle {
    right: 14px;
    bottom: 14px;
    width: 58px;
    height: 58px;
  }

  #aac-chat-toggle.aac-left {
    left: 14px;
    right: auto;
  }

  #aac-chat-window {
    right: 14px;
    left: 14px;
    bottom: 84px;
    width: auto;
    height: 68vh;
    max-height: 600px;
  }

  #aac-chat-window.aac-left {
    left: 14px;
    right: 14px;
  }
}