/* ============================================================
   AI CHAT WIDGET — Applash Solution
   Brand: navy #022d62 | accent: sky #0ea5e9
   ============================================================ */

#ai-chat-btn {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 9998;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, #022d62, #0ea5e9);
  border: none;
  cursor: pointer;
  box-shadow: 0 6px 24px rgba(2,45,98,.40), 0 0 0 0 rgba(14,165,233,.3);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .25s ease, box-shadow .25s ease;
  animation: ai-pulse 2.8s ease-in-out infinite;
}
#ai-chat-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 10px 32px rgba(2,45,98,.50);
  animation: none;
}
#ai-chat-btn svg { width: 26px; height: 26px; }
@keyframes ai-pulse {
  0%, 100% { box-shadow: 0 6px 24px rgba(2,45,98,.4), 0 0 0 0 rgba(14,165,233,.3); }
  50%       { box-shadow: 0 6px 24px rgba(2,45,98,.4), 0 0 0 10px rgba(14,165,233,0); }
}

/* Badge */
#ai-chat-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  width: 18px;
  height: 18px;
  background: #ef4444;
  border-radius: 50%;
  border: 2px solid #fff;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
}

/* ── Panel ── */
#ai-chat-panel {
  position: fixed;
  bottom: 100px;
  right: 28px;
  z-index: 9999;
  width: 380px;
  max-width: calc(100vw - 40px);
  height: 560px;
  max-height: calc(100vh - 120px);
  background: #ffffff;
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(2,45,98,.22), 0 4px 16px rgba(0,0,0,.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(16px) scale(.97);
  pointer-events: none;
  transition: opacity .28s ease, transform .28s cubic-bezier(.34,1.56,.64,1);
}
#ai-chat-panel.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

/* ── Header ── */
.ai-chat-header {
  background: linear-gradient(135deg, #022d62 0%, #034a8f 100%);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.ai-chat-header-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255,255,255,.15);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.ai-chat-header-avatar svg { width: 20px; height: 20px; }
.ai-chat-header-info { flex: 1; }
.ai-chat-header-name {
  font-size: .92rem;
  font-weight: 700;
  color: #fff;
  margin: 0;
  line-height: 1.2;
}
.ai-chat-header-status {
  font-size: .74rem;
  color: rgba(255,255,255,.7);
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
}
.ai-chat-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #22c55e;
  animation: ai-blink 1.8s ease-in-out infinite;
}
@keyframes ai-blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: .3; }
}
.ai-chat-header-actions { display: flex; gap: 8px; }
.ai-chat-header-btn {
  background: rgba(255,255,255,.12);
  border: none;
  border-radius: 8px;
  width: 32px;
  height: 32px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255,255,255,.8);
  transition: background .2s;
}
.ai-chat-header-btn:hover { background: rgba(255,255,255,.22); color: #fff; }
.ai-chat-header-btn svg { width: 14px; height: 14px; }

/* ── Messages ── */
.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #f8fafc;
  scroll-behavior: smooth;
}
.ai-chat-messages::-webkit-scrollbar { width: 4px; }
.ai-chat-messages::-webkit-scrollbar-track { background: transparent; }
.ai-chat-messages::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }

/* Welcome card */
.ai-chat-welcome {
  background: linear-gradient(135deg, #eff6ff, #e0f2fe);
  border: 1px solid #bfdbfe;
  border-radius: 14px;
  padding: 14px 16px;
  text-align: center;
  font-size: .82rem;
  color: #1e40af;
}
.ai-chat-welcome strong { display: block; font-size: .9rem; margin-bottom: 4px; color: #1e3a8a; }

/* Message bubbles */
.ai-msg { display: flex; gap: 8px; align-items: flex-end; max-width: 92%; }
.ai-msg.user  { align-self: flex-end; flex-direction: row-reverse; }
.ai-msg.bot   { align-self: flex-start; }

.ai-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .7rem;
  font-weight: 700;
}
.ai-msg.user .ai-msg-avatar  { background: #022d62; color: #fff; }
.ai-msg.bot  .ai-msg-avatar  { background: #0ea5e9; color: #fff; }

.ai-msg-bubble {
  border-radius: 16px;
  padding: 10px 14px;
  font-size: .85rem;
  line-height: 1.55;
  word-break: break-word;
}
.ai-msg.user .ai-msg-bubble {
  background: #022d62;
  color: #fff;
  border-bottom-right-radius: 4px;
}
.ai-msg.bot .ai-msg-bubble {
  background: #fff;
  color: #1e293b;
  border: 1px solid #e2e8f0;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}

.ai-msg-time {
  font-size: .68rem;
  color: #94a3b8;
  margin-top: 3px;
  text-align: right;
}
.ai-msg.bot .ai-msg-time { text-align: left; }

/* Sources */
.ai-sources {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 7px;
}
.ai-source-chip {
  font-size: .68rem;
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
  border-radius: 20px;
  padding: 2px 9px;
  text-decoration: none;
  transition: background .2s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
}
.ai-source-chip:hover { background: #dbeafe; color: #1e40af; }

/* Typing indicator */
.ai-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  width: fit-content;
}
.ai-typing span {
  width: 7px;
  height: 7px;
  background: #0ea5e9;
  border-radius: 50%;
  animation: ai-dot 1.2s ease-in-out infinite;
}
.ai-typing span:nth-child(2) { animation-delay: .2s; }
.ai-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes ai-dot {
  0%, 80%, 100% { transform: scale(.7); opacity: .4; }
  40%            { transform: scale(1);  opacity: 1; }
}

/* ── Input ── */
.ai-chat-input-wrap {
  padding: 14px 16px;
  background: #fff;
  border-top: 1px solid #e2e8f0;
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-shrink: 0;
}
#ai-chat-input {
  flex: 1;
  border: 1.5px solid #e2e8f0;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: .85rem;
  resize: none;
  outline: none;
  max-height: 100px;
  min-height: 42px;
  line-height: 1.5;
  color: #1e293b;
  background: #f8fafc;
  transition: border-color .2s;
  font-family: inherit;
}
#ai-chat-input:focus { border-color: #0ea5e9; background: #fff; }
#ai-chat-input::placeholder { color: #94a3b8; }
#ai-chat-send {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, #022d62, #0ea5e9);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity .2s, transform .15s;
}
#ai-chat-send:hover { opacity: .9; transform: scale(1.04); }
#ai-chat-send:disabled { opacity: .45; cursor: not-allowed; transform: none; }
#ai-chat-send svg { width: 18px; height: 18px; }

.ai-chat-footer {
  text-align: center;
  font-size: .68rem;
  color: #94a3b8;
  padding: 6px 16px 10px;
  background: #fff;
}

/* ── Mobile ── */
@media (max-width: 480px) {
  #ai-chat-panel {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-width: 100%;
    border-radius: 20px 20px 0 0;
    height: 88vh;
    max-height: 88vh;
  }
  #ai-chat-btn { bottom: 20px; right: 20px; }
}
