/* ClaudeAI Chat — Widget Styles */
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@300;400;500;600&display=swap');

#caic-root * { box-sizing: border-box; font-family: 'DM Sans', sans-serif; }

/* LAUNCHER BUTTON */
#caic-launcher {
  position: fixed;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  z-index: 99998;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(0,0,0,.25);
  transition: transform .2s ease, box-shadow .2s ease, opacity .2s ease;
  background: var(--caic-primary, #6c63ff);
  overflow: hidden;
  padding: 0;
}

#caic-launcher:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(0,0,0,.3);
}

#caic-launcher svg { width: 26px; height: 26px; fill: white; transition: opacity .2s; }
#caic-launcher .caic-icon-char { font-size: 18px; color: white; line-height: 1; font-style: normal; }

#caic-launcher .caic-icon-close {
  display: none;
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
}
#caic-launcher .caic-icon-chat  { display: flex; align-items: center; justify-content: center; }
#caic-launcher.open .caic-icon-chat  { display: none; }
#caic-launcher.open .caic-icon-close { display: flex; align-items: center; justify-content: center; }

/* CSS X for launcher close icon */
#caic-launcher .caic-icon-close {
  display: none;
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%,-50%);
  width: 20px; height: 20px;
}
#caic-launcher .caic-icon-close::before,
#caic-launcher .caic-icon-close::after {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  width: 18px; height: 2.5px;
  background: white;
  border-radius: 1px;
}
#caic-launcher .caic-icon-close::before { transform: translate(-50%,-50%) rotate(45deg); }
#caic-launcher .caic-icon-close::after  { transform: translate(-50%,-50%) rotate(-45deg); }

/* Hide the launcher entirely when open */
#caic-launcher.open { display: none !important; }

/* Custom icon wrap — gives close button a reliable containing block */
.caic-icon-wrap {
  position: relative;
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
}
.caic-icon-wrap .caic-icon-close {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  display: none;
  align-items: center; justify-content: center;
  z-index: 1;
}
#caic-launcher.open .caic-icon-wrap .caic-icon-close { display: flex; }

#caic-launcher .caic-icon-img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  position: relative; z-index: 0;
}
#caic-launcher.open .caic-icon-img { display: none; }

/* UNREAD BADGE */
#caic-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  background: #ef4444;
  color: white;
  font-size: 10px;
  font-weight: 700;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  display: none;
}

/* CHAT WINDOW */
#caic-window {
  position: fixed;
  z-index: 99999;
  width: 370px;
  max-height: 560px;
  display: flex;
  flex-direction: column;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 12px 48px rgba(0,0,0,.22);
  background: #fff;
  opacity: 0;
  transform: translateY(20px) scale(.97);
  transition: opacity .25s ease, transform .25s ease;
  pointer-events: none;
}

#caic-window.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

/* HEADER */
#caic-header {
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.caic-agent-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255,255,255,.25);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
  font-size: 18px;
}

.caic-agent-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.caic-agent-info { flex: 1; }
.caic-agent-name { font-size: 15px; font-weight: 700; line-height: 1.2; }
.caic-agent-status { font-size: 11px; opacity: .85; display: flex; align-items: center; gap: 4px; }
.caic-status-dot {
  width: 6px; height: 6px; border-radius: 50%; background: #4ade80;
  animation: caic-pulse 2s infinite;
}

@keyframes caic-pulse {
  0%,100% { opacity: 1; }
  50% { opacity: .5; }
}

#caic-close-btn {
  -webkit-appearance: none;
  appearance: none;
  background: rgba(255,255,255,.2);
  border: none;
  cursor: pointer;
  width: 28px;
  height: 28px;
  min-width: 28px;
  padding: 0;
  margin: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
  flex-shrink: 0;
  position: relative;
  box-sizing: border-box;
}
#caic-close-btn:hover { background: rgba(255,255,255,.35); }
/* CSS-only X — works in every browser, no SVG, no font dependency */
#caic-close-btn::before,
#caic-close-btn::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 12px;
  height: 2px;
  background: white;
  border-radius: 1px;
}
#caic-close-btn::before { transform: translate(-50%,-50%) rotate(45deg); }
#caic-close-btn::after  { transform: translate(-50%,-50%) rotate(-45deg); }

/* MESSAGES */
#caic-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #f9fafc;
  scroll-behavior: smooth;
}

#caic-messages::-webkit-scrollbar { width: 4px; }
#caic-messages::-webkit-scrollbar-track { background: transparent; }
#caic-messages::-webkit-scrollbar-thumb { background: #ddd; border-radius: 4px; }

.caic-msg {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  animation: caic-msg-in .25s ease;
}

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

.caic-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  background: #e5e7eb;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
}
.caic-msg-avatar img { width: 100%; height: 100%; object-fit: cover; }

.caic-msg-bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 13.5px;
  line-height: 1.5;
}

.caic-msg.bot .caic-msg-bubble {
  background: white;
  color: #1a1d2e;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}

.caic-msg.user {
  flex-direction: row-reverse;
}

.caic-msg.user .caic-msg-bubble {
  background: var(--caic-primary, #6c63ff);
  color: white;
  border-bottom-right-radius: 4px;
}

/* TYPING INDICATOR */
.caic-typing .caic-msg-bubble {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
}

.caic-typing-dot {
  width: 7px;
  height: 7px;
  background: #9ca3af;
  border-radius: 50%;
  animation: caic-bounce .9s infinite;
}
.caic-typing-dot:nth-child(2) { animation-delay: .15s; }
.caic-typing-dot:nth-child(3) { animation-delay: .3s; }

@keyframes caic-bounce {
  0%,80%,100% { transform: translateY(0); }
  40% { transform: translateY(-6px); }
}

/* INPUT */
#caic-input-row {
  padding: 12px 14px;
  background: white;
  border-top: 1px solid #eef0f5;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-shrink: 0;
}

#caic-input {
  flex: 1;
  border: 1px solid #e2e5ef;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 13px;
  resize: none;
  min-height: 40px;
  max-height: 120px;
  overflow-y: auto;
  line-height: 1.4;
  font-family: 'DM Sans', sans-serif;
  background: #f7f8fc;
  transition: border-color .15s;
}

#caic-input:focus {
  outline: none;
  border-color: var(--caic-primary, #6c63ff);
  background: white;
}

#caic-send-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  background: var(--caic-primary, #6c63ff);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform .15s, opacity .15s;
}
#caic-send-btn:hover { transform: scale(1.05); }
#caic-send-btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
/* CSS-only right-pointing arrow */
#caic-send-btn::before {
  content: '';
  display: block;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 7px 0 7px 13px;
  border-color: transparent transparent transparent white;
  margin-left: 3px;
}



@media (max-width: 400px) {
  #caic-window { width: calc(100vw - 20px); }
}

/* ---- CHAT WINDOW FIRST-OPEN INTRO ANIMATION ---- */
@keyframes caic-window-intro {
  0%   { opacity: 0; transform: translateY(32px) scale(0.92); }
  55%  { opacity: 1; transform: translateY(-7px) scale(1.025); }
  75%  { transform: translateY(3px) scale(0.99); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}
#caic-window.caic-intro {
  transition: none !important;
  animation: caic-window-intro 0.58s cubic-bezier(0.34, 1.4, 0.64, 1) both;
}

/* ---- ATTENTION ANIMATIONS ---- */
@keyframes caic-anim-pulse {
  0%,100% { box-shadow: 0 4px 20px rgba(0,0,0,.25), 0 0 0 0 var(--caic-primary, #6c63ff); }
  50%      { box-shadow: 0 4px 20px rgba(0,0,0,.25), 0 0 0 10px rgba(108,99,255,0); }
}

@keyframes caic-anim-bounce {
  0%,100% { transform: translateY(0); }
  30%     { transform: translateY(-10px); }
  60%     { transform: translateY(-4px); }
  80%     { transform: translateY(-7px); }
}

@keyframes caic-anim-shake {
  0%,100% { transform: rotate(0deg); }
  15%     { transform: rotate(-12deg); }
  30%     { transform: rotate(10deg); }
  45%     { transform: rotate(-8deg); }
  60%     { transform: rotate(6deg); }
  75%     { transform: rotate(-3deg); }
}

@keyframes caic-anim-tada {
  0%,100% { transform: scale(1) rotate(0deg); }
  10%,20% { transform: scale(0.9) rotate(-3deg); }
  30%,50%,70%,90% { transform: scale(1.1) rotate(3deg); }
  40%,60%,80%     { transform: scale(1.1) rotate(-3deg); }
}

#caic-launcher.caic-animate-pulse  { animation: caic-anim-pulse  1s ease 2; }
#caic-launcher.caic-animate-bounce { animation: caic-anim-bounce 0.8s ease 2; }
#caic-launcher.caic-animate-shake  { animation: caic-anim-shake  0.7s ease 2; }
#caic-launcher.caic-animate-tada   { animation: caic-anim-tada   0.9s ease 2; }

/* Prevent the launcher's own transition from fighting keyframe animations */
#caic-launcher.caic-animate-pulse,
#caic-launcher.caic-animate-bounce,
#caic-launcher.caic-animate-shake,
#caic-launcher.caic-animate-tada  { transition: none; }

/* ---- END CHAT BAR ---- */
#caic-end-bar {
  display: none;
  justify-content: flex-end;
  padding: 0 14px 8px;
  background: white;
  flex-shrink: 0;
}

#caic-end-btn {
  background: none;
  border: none;
  color: #aaa;
  font-size: 11px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  font-family: 'DM Sans', sans-serif;
  transition: color .15s, background .15s;
  letter-spacing: .02em;
}
#caic-end-btn:hover {
  color: #e74c3c;
  background: #fff0ef;
}

/* ---- ENDED STATE PANEL ---- */
#caic-ended-panel {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 20px 18px;
  background: white;
  border-top: 1px solid #eef0f5;
  flex-shrink: 0;
}

#caic-ended-msg {
  margin: 0;
  font-size: 13px;
  color: #888;
  text-align: center;
}

#caic-ended-actions {
  display: flex;
  gap: 8px;
  width: 100%;
}

#caic-download-btn,
#caic-newchat-btn {
  flex: 1;
  padding: 9px 10px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  font-family: 'DM Sans', sans-serif;
  transition: opacity .15s, transform .15s;
  text-align: center;
  line-height: 1.3;
}
#caic-download-btn:hover,
#caic-newchat-btn:hover { opacity: .88; transform: translateY(-1px); }

#caic-download-btn {
  background: #f0efff;
  color: #6c63ff;
  border: 1px solid #d4d0ff;
}

#caic-newchat-btn {
  background: var(--caic-primary, #6c63ff);
  color: white;
}
