/* =========================================================
   365 AI Support Pro – Chat Widget Styles v1.1
   ========================================================= */

:root {
  --ai365-color: #2563eb;
  --ai365-color-dark: #1d4ed8;
  --ai365-color-light: #eff6ff;
  --ai365-radius: 16px;
  --ai365-shadow: 0 20px 60px rgba(0,0,0,0.18), 0 4px 16px rgba(0,0,0,0.08);
  --ai365-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --ai365-z: 999999;
  --ai365-widget-w: 380px;
  --ai365-widget-h: 560px;
}

/* ── Wrapper ─────────────────────────────────────────────── */
#ai365-chat-root {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: var(--ai365-z);
  font-family: var(--ai365-font);
}

/* ── LAUNCHER (nút nổi) ──────────────────────────────────── */
.ai365-launcher {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  position: relative;
}

/* Label "Chat với AI" nổi bên trên nút */
.ai365-cta-label {
  background: #fff;
  color: #1e293b;
  font-size: 13px;
  font-weight: 700;
  padding: 7px 14px;
  border-radius: 20px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  white-space: nowrap;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  border: none;
  transition: transform 0.2s, box-shadow 0.2s;
  position: relative;
}
.ai365-cta-label:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0,0,0,0.18);
}
/* Đuôi mũi tên nhỏ trỏ xuống nút */
.ai365-cta-label::after {
  content: '';
  position: absolute;
  bottom: -6px;
  right: 28px;
  width: 10px;
  height: 10px;
  background: #fff;
  transform: rotate(45deg);
  box-shadow: 2px 2px 4px rgba(0,0,0,0.08);
}
.ai365-cta-dot {
  width: 8px;
  height: 8px;
  background: #22c55e;
  border-radius: 50%;
  animation: ai365-online 2s infinite;
}
@keyframes ai365-online {
  0%,100% { opacity:1; transform:scale(1); }
  50%      { opacity:.6; transform:scale(1.3); }
}

/* Nút toggle tròn chính */
.ai365-toggle {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--ai365-color);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 24px rgba(0,0,0,0.25), 0 0 0 0 rgba(37,99,235,0.4);
  position: relative;
  outline: none;
  /* Hiệu ứng rung liên tục */
  animation: ai365-shake 4s ease-in-out infinite;
}
/* Ripple sóng lan ra */
.ai365-toggle::before,
.ai365-toggle::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--ai365-color);
  opacity: 0;
  animation: ai365-ripple 3s ease-out infinite;
}
.ai365-toggle::after {
  animation-delay: 1s;
}
.ai365-toggle.is-open::before,
.ai365-toggle.is-open::after {
  animation: none;
}
.ai365-toggle.is-open {
  animation: none;
  box-shadow: 0 6px 24px rgba(0,0,0,0.25);
}
.ai365-toggle:hover {
  transform: scale(1.06);
  animation: none;
}
.ai365-toggle:active {
  transform: scale(0.95);
}

/* Animation rung lắc */
@keyframes ai365-shake {
  0%,100%            { transform: rotate(0deg);   }
  5%                 { transform: rotate(-8deg);  }
  10%                { transform: rotate(8deg);   }
  15%                { transform: rotate(-6deg);  }
  20%                { transform: rotate(6deg);   }
  25%                { transform: rotate(-3deg);  }
  30%                { transform: rotate(0deg);   }
}

/* Animation sóng ripple */
@keyframes ai365-ripple {
  0%   { transform: scale(1);   opacity: 0.5; }
  100% { transform: scale(2.2); opacity: 0;   }
}

.ai365-toggle-icon {
  font-size: 28px;
  line-height: 1;
  transition: opacity 0.2s, transform 0.3s;
  z-index: 1;
  position: relative;
}
.ai365-toggle.is-open .ai365-toggle-icon {
  transform: rotate(90deg);
}

/* Badge đỏ unread */
.ai365-badge-dot {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 14px;
  height: 14px;
  background: #ef4444;
  border-radius: 50%;
  border: 2px solid #fff;
  z-index: 2;
  animation: ai365-pulse 2s infinite;
}
@keyframes ai365-pulse {
  0%,100% { transform: scale(1);   opacity: 1; }
  50%     { transform: scale(1.25); opacity: 0.75; }
}

/* ── Chat Window ─────────────────────────────────────────── */
.ai365-window {
  position: absolute;
  bottom: 84px;
  right: 0;
  width: var(--ai365-widget-w);
  height: var(--ai365-widget-h);
  background: #ffffff;
  border-radius: var(--ai365-radius);
  box-shadow: var(--ai365-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  transform: scale(0.8) translateY(20px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.3s cubic-bezier(.34,1.56,.64,1), opacity 0.25s ease;
}
.ai365-window.is-open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: all;
}

/* ── Header ──────────────────────────────────────────────── */
.ai365-header {
  background: var(--ai365-color);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.ai365-header-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}
.ai365-header-info { flex: 1; }
.ai365-header-title {
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  margin: 0;
  line-height: 1.3;
}
.ai365-header-status {
  color: rgba(255,255,255,0.85);
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 5px;
}
.ai365-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4ade80;
  display: inline-block;
}
.ai365-close-btn {
  background: rgba(255,255,255,0.15);
  border: none;
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 18px;
  transition: background 0.2s;
  flex-shrink: 0;
}
.ai365-close-btn:hover {
  background: rgba(255,255,255,0.28);
}

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

/* ── Message Bubble ──────────────────────────────────────── */
.ai365-msg {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  animation: ai365-msg-in 0.28s ease both;
}
@keyframes ai365-msg-in {
  from { opacity:0; transform:translateY(8px); }
  to   { opacity:1; transform:translateY(0); }
}
.ai365-msg--user { flex-direction: row-reverse; }
.ai365-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--ai365-color-light);
}
.ai365-msg--user .ai365-msg-avatar {
  background: var(--ai365-color);
}
.ai365-bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.55;
  word-break: break-word;
  white-space: pre-wrap;
}
.ai365-msg--bot .ai365-bubble {
  background: #ffffff;
  color: #1e293b;
  border: 1px solid #e2e8f0;
  border-bottom-left-radius: 4px;
}
.ai365-msg--user .ai365-bubble {
  background: var(--ai365-color);
  color: #ffffff;
  border-bottom-right-radius: 4px;
}

/* ── Typing Indicator ────────────────────────────────────── */
.ai365-typing {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 18px;
  border-bottom-left-radius: 4px;
  width: fit-content;
}
.ai365-typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #94a3b8;
  animation: ai365-typing 1.2s infinite ease-in-out;
}
.ai365-typing-dot:nth-child(1) { animation-delay: 0s; }
.ai365-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.ai365-typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes ai365-typing {
  0%,60%,100% { transform:translateY(0);  opacity:0.4; }
  30%         { transform:translateY(-6px); opacity:1; }
}

/* ── Input Area ──────────────────────────────────────────── */
.ai365-input-area {
  padding: 12px 14px;
  background: #ffffff;
  border-top: 1px solid #e2e8f0;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-shrink: 0;
}
.ai365-textarea {
  flex: 1;
  resize: none;
  border: 1.5px solid #e2e8f0;
  border-radius: 12px;
  padding: 9px 12px;
  font-family: var(--ai365-font);
  font-size: 14px;
  line-height: 1.5;
  color: #1e293b;
  max-height: 110px;
  overflow-y: auto;
  outline: none;
  transition: border-color 0.2s;
  background: #f8fafc;
}
.ai365-textarea:focus {
  border-color: var(--ai365-color);
  background: #fff;
}
.ai365-textarea::placeholder { color: #94a3b8; }
.ai365-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--ai365-color);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s, transform 0.15s;
  outline: none;
}
.ai365-send-btn:hover:not(:disabled) {
  background: var(--ai365-color-dark);
  transform: scale(1.06);
}
.ai365-send-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.ai365-send-btn svg { width: 17px; height: 17px; fill: #fff; }

/* ── Footer ──────────────────────────────────────────────── */
.ai365-footer {
  text-align: center;
  padding: 5px 0 9px;
  font-size: 11px;
  color: #94a3b8;
  background: #ffffff;
}
.ai365-footer a { color: var(--ai365-color); text-decoration: none; }

/* ── Error ───────────────────────────────────────────────── */
.ai365-bubble--error {
  background: #fef2f2 !important;
  border-color: #fecaca !important;
  color: #b91c1c !important;
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 480px) {
  :root {
    --ai365-widget-w: calc(100vw - 20px);
    --ai365-widget-h: 72vh;
  }
  #ai365-chat-root { bottom: 14px; right: 10px; }
  .ai365-window { right: 0; bottom: 82px; }
}
