/* ============================================================
   čevi chatbot - shared styles (loaded automatically by ai.js)
   Everything is scoped under #chat-container so page CSS cannot
   restyle the widget and the widget cannot restyle the page.
   ============================================================ */

#chat-container,
#chat-container *,
#chat-container *::before,
#chat-container *::after { box-sizing: border-box; }

#chat-container {
  font-family: Nunito, system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Tamil", sans-serif;
  line-height: 1.5;
  text-align: left;
  -webkit-text-size-adjust: 100%;
}
#chat-container button,
#chat-container input { font-family: inherit; }
#chat-container h4 { margin: 0; }
#chat-container :where(div, span, p, h4, button, input, svg) { line-height: inherit; }

/* ============================================
   CHATBOT STYLES - IMPROVED MODERN DESIGN
   ============================================ */

/* Chat Float Container */
#chat-container {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1.5rem;
}

/* Modern Chat Window */
#chat-container .chat-window-modern {
  width: 420px;
  height: 680px;
  max-height: 85vh;
  background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
  border-radius: 24px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5), 
              0 0 0 1px rgba(255, 255, 255, 0.1);
  overflow: hidden;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#chat-container .chat-window-modern.hidden {
  display: none;
}

/* Chat Header */
#chat-container .chat-header-modern {
  background: rgba(30, 41, 59, 0.8);
  backdrop-filter: blur(20px);
  padding: 20px 24px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#chat-container .chat-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

#chat-container .cv-status {
  width: 12px;
  height: 12px;
  background: #3b82f6;
  border-radius: 50%;
  animation: cevi-pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
  box-shadow: 0 0 12px #3b82f6;
}

@keyframes cevi-pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

#chat-container .chat-title-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

#chat-container .chat-title {
  color: white;
  font-size: 16px;
  font-weight: 700;
  margin: 0;
  line-height: 1;
}

#chat-container .chat-status {
  color: #60a5fa;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

#chat-container .cv-close-btn {
  background: transparent;
  border: none;
  color: #94a3b8;
  cursor: pointer;
  padding: 4px;
  border-radius: 8px;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

#chat-container .cv-close-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: white;
}

/* Chat Messages Area */
#chat-container .chat-messages-area {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.5) 0%, rgba(15, 23, 42, 0.8) 100%);
}

/* Scrollbar Styling */
#chat-container .chat-messages-area::-webkit-scrollbar {
  width: 6px;
}

#chat-container .chat-messages-area::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 10px;
}

#chat-container .chat-messages-area::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
}

#chat-container .chat-messages-area::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.15);
}

/* Message Bubbles */
#chat-container .ai-msg {
  background: rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(10px);
  padding: 14px 18px;
  border-radius: 18px 18px 18px 4px;
  color: #e2e8f0;
  max-width: 85%;
  font-size: 14px;
  line-height: 1.5;
  align-self: flex-start;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

#chat-container .user-msg {
  background: linear-gradient(135deg, #3b82f6 0%, #6366f1 100%);
  padding: 14px 18px;
  border-radius: 18px 18px 4px 18px;
  color: white;
  align-self: flex-end;
  max-width: 85%;
  font-size: 14px;
  line-height: 1.5;
  box-shadow: 0 4px 15px rgba(59, 130, 246, 0.3);
}

/* Quick Actions Bar */
#chat-container .quick-actions-bar {
  padding: 16px 24px;
  display: flex;
  gap: 10px;
  overflow-x: auto;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  background: rgba(15, 23, 42, 0.5);
}

#chat-container .quick-actions-bar::-webkit-scrollbar {
  display: none;
}

#chat-container .cv-chip {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #e2e8f0;
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.2s ease;
  backdrop-filter: blur(10px);
}

#chat-container .cv-chip:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(59, 130, 246, 0.5);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.2);
}

/* Chat Input Area */
#chat-container .chat-input-area {
  padding: 20px 24px;
  background: rgba(15, 23, 42, 0.8);
  backdrop-filter: blur(20px);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  gap: 12px;
  align-items: center;
}

#chat-container .chat-input-field {
  flex: 1;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: white;
  padding: 14px 18px;
  border-radius: 14px;
  font-size: 14px;
  outline: none;
  transition: all 0.2s ease;
}

#chat-container .chat-input-field::placeholder {
  color: rgba(255, 255, 255, 0.4);
}

#chat-container .chat-input-field:focus {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(59, 130, 246, 0.5);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Send Button */
#chat-container .cv-send-btn {
  background: linear-gradient(135deg, #3b82f6 0%, #6366f1 100%);
  border: none;
  border-radius: 14px;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px 20px;
  transition: all 0.2s ease;
  box-shadow: 0 4px 15px rgba(59, 130, 246, 0.3);
}

#chat-container .cv-send-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(59, 130, 246, 0.4);
}

#chat-container .cv-send-btn:active {
  transform: translateY(0);
}

/* Chat Orb Trigger */
#chat-container .chat-orb-trigger {
  background: transparent;
  border: none;
  box-shadow: none;
  -webkit-appearance: none;
  appearance: none;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
  padding: 0;
  outline: none;
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#chat-container .chat-orb-trigger:hover {
  transform: scale(1.05);
}

#chat-container .chat-orb-trigger:active {
  transform: scale(0.95);
}

/* Bunny Mascot (replaces the old Kimi-style orb) */
#chat-container .bunny-orb {
  width: 90px;
  position: relative;
  animation: bunnyFloat 4.5s ease-in-out infinite;
  /* No CSS filter/backdrop here: a filter on an animated element with 3D-transformed
     children makes some browsers paint a solid box behind it while scrolling. */
  background: transparent;
  isolation: isolate;
  will-change: transform;
}

#chat-container .bunny-orb svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

/* Ears: gentle sway + depth twirl, base stays anchored */
#chat-container .bny-ear-l, #chat-container .bny-ear-r {
  transform-box: view-box;
  transform-origin: 400px 315px;
}
#chat-container .bny-ear-l { animation: bnyEarL 3.8s ease-in-out infinite; }
#chat-container .bny-ear-r { animation: bnyEarR 3.8s ease-in-out infinite; }

#chat-container .bny-flap-l { transform-box: view-box; transform-origin: 286px 124px; animation: bnyFlapL 2.8s ease-in-out infinite; }
#chat-container .bny-flap-r { transform-box: view-box; transform-origin: 535px 124px; animation: bnyFlapR 2.8s ease-in-out infinite; }

#chat-container .bny-eyes { transform-box: fill-box; transform-origin: center; animation: bnyBlink 4.4s infinite; }
#chat-container .bny-mouth { transform-box: fill-box; transform-origin: 50% 0%; }

/* Thinking: ears wiggle faster while waiting for the answer */
#chat-container .bunny-orb[data-state="thinking"] .bny-ear-l { animation-duration: 1.3s; }
#chat-container .bunny-orb[data-state="thinking"] .bny-ear-r { animation-duration: 1.3s; }
#chat-container .bunny-orb[data-state="thinking"] .bny-flap-l, #chat-container .bunny-orb[data-state="thinking"] .bny-flap-r { animation-duration: 0.9s; }

/* Talking: mouth opens and closes */
#chat-container .bunny-orb[data-state="talking"] .bny-mouth { animation: bnyTalk 0.32s ease-in-out infinite alternate; }

@keyframes bunnyFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-9px); }
}
@keyframes bnyFlapL { 0%,100% { transform: rotate(0deg); } 50% { transform: rotate(-7deg); } }
@keyframes bnyFlapR { 0%,100% { transform: rotate(0deg); } 50% { transform: rotate(7deg); } }
@keyframes bnyEarL {
  0%,100% { transform: perspective(700px) rotate(-2deg) rotateX(0deg) translateY(0); }
  22% { transform: perspective(700px) rotate(-17deg) rotateX(20deg) translateY(2px); }
  38% { transform: perspective(700px) rotate(-21deg) rotateX(-12deg) translateY(3px); }
  55% { transform: perspective(700px) rotate(-9deg) rotateX(16deg) translateY(1px); }
  72% { transform: perspective(700px) rotate(-15deg) rotateX(-7deg) translateY(2px); }
}
@keyframes bnyEarR {
  0%,100% { transform: perspective(700px) rotate(2deg) rotateX(0deg) translateY(0); }
  22% { transform: perspective(700px) rotate(17deg) rotateX(-20deg) translateY(2px); }
  38% { transform: perspective(700px) rotate(21deg) rotateX(12deg) translateY(3px); }
  55% { transform: perspective(700px) rotate(9deg) rotateX(-16deg) translateY(1px); }
  72% { transform: perspective(700px) rotate(15deg) rotateX(7deg) translateY(2px); }
}
@keyframes bnyBlink {
  0%, 45%, 48%, 100% { transform: scaleY(1); }
  46.5% { transform: scaleY(0.12); }
}
@keyframes bnyTalk {
  from { transform: scaleY(0.55); }
  to   { transform: scaleY(1.15); }
}

@media (max-width: 640px) {
  #chat-container .bunny-orb { width: 62px; }
}
@media (prefers-reduced-motion: reduce) {
  #chat-container .bunny-orb, #chat-container .bunny-orb * { animation: none !important; }
}

/* Chat message extras: keep line breaks, typing dots, sources */
#chat-container .ai-msg { white-space: pre-wrap; word-break: break-word; }
#chat-container .user-msg { word-break: break-word; }

#chat-container .ai-msg.typing { display: flex; gap: 5px; align-items: center; padding: 16px 18px; }
#chat-container .ai-msg.typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: #94a3b8;
  animation: typingDot 1.2s ease-in-out infinite;
}
#chat-container .ai-msg.typing span:nth-child(2) { animation-delay: 0.15s; }
#chat-container .ai-msg.typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes typingDot {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-5px); opacity: 1; }
}

#chat-container .ai-sources {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 11px;
  color: #94a3b8;
  line-height: 1.4;
}


/* ============================================
   CHAT: header actions, expanded (full page) mode, mobile fit
   ============================================ */
#chat-container .chat-header-actions { display: flex; align-items: center; gap: 4px; }
#chat-container .chat-expand-btn .icon-collapse { display: none; }
#chat-container .chat-window-modern.expanded .chat-expand-btn .icon-expand { display: none; }
#chat-container .chat-window-modern.expanded .chat-expand-btn .icon-collapse { display: block; }

/* flex children must be allowed to shrink or the message list will not scroll */
#chat-container .chat-window-modern { min-height: 0; }
#chat-container .chat-messages-area { min-height: 0; overscroll-behavior: contain; }

/* ---- Expanded: full-page chat (desktop / tablet) ---- */
#chat-container .chat-window-modern.expanded {
  position: fixed !important;
  top: var(--chat-top, 0px) !important;
  left: 0 !important;
  right: 0 !important;
  width: 100% !important;
  height: var(--chat-vh, 100dvh) !important;
  max-height: none !important;
  border-radius: 0 !important;
  z-index: 10001;
  transition: none;
}
#chat-container.is-expanded .chat-orb-trigger { display: none; }

/* keep the conversation in a comfortable centred column */
#chat-container .chat-window-modern.expanded .chat-header-modern, #chat-container .chat-window-modern.expanded .chat-messages-area, #chat-container .chat-window-modern.expanded .quick-actions-bar, #chat-container .chat-window-modern.expanded .chat-input-area {
  padding-left: max(24px, calc((100% - 880px) / 2));
  padding-right: max(24px, calc((100% - 880px) / 2));
}
#chat-container .chat-window-modern.expanded .ai-msg, #chat-container .chat-window-modern.expanded .user-msg { max-width: 78%; font-size: 15px; }

/* ---- Normal (small) window on desktop: always fit above the bunny ---- */
@media (min-width: 641px) {
  #chat-container .chat-window-modern:not(.expanded) {
    height: min(680px, calc(100dvh - 220px));
    max-height: none;
  }
}

/* ---- Mobile: chat fills the screen and shrinks above the keyboard ---- */
@media (max-width: 640px) {
  #chat-container { bottom: 1rem; right: 1rem; }

  #chat-container .chat-window-modern {
    position: fixed !important;
    top: var(--chat-top, 0px) !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    height: var(--chat-vh, 100dvh) !important;
    max-height: none !important;
    border-radius: 0 !important;
    z-index: 10001;
    transition: none;
  }
  /* the window is full-screen, so the bunny would sit on top of the input */
  #chat-container.is-open .chat-orb-trigger { display: none; }

  /* already full-screen: no expand button needed */
  #chat-container .chat-expand-btn { display: none; }

  #chat-container .chat-header-modern { padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top, 0px)); }
  #chat-container .chat-messages-area { padding: 16px; gap: 12px; }
  #chat-container .ai-msg, #chat-container .user-msg { max-width: 90%; }
  #chat-container .quick-actions-bar { padding: 10px 16px; }
  #chat-container .cv-chip { padding: 8px 14px; font-size: 12px; }
  #chat-container .chat-input-area {
    padding: 10px 12px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    gap: 8px;
  }
  /* 16px stops iOS Safari zooming the page when the field is focused */
  #chat-container .chat-input-field { font-size: 16px; padding: 12px 14px; }
  #chat-container .cv-send-btn { padding: 12px 16px; }

  /* keyboard is open: give the messages the room */
  #chat-container .chat-window-modern.kb-open .quick-actions-bar { display: none; }
  #chat-container .chat-window-modern.kb-open .chat-header-modern { padding-top: 8px; padding-bottom: 8px; }
}

