/* ============================================================
   GAJ-DASTAK Chatbot Widget
   Elephant-themed floating query form with sparkle effects
   ============================================================ */

/* --- CSS Custom Properties --- */
:root {
  --cb-amber: #F5A623;
  --cb-amber-dark: #D4890A;
  --cb-green: #7BA68A;
  --cb-green-dark: #5A8A6A;
  --cb-bg-dark: #1a1a2e;
  --cb-bg-panel: #16213e;
  --cb-bg-input: #0f172a;
  --cb-text: #f0f0f0;
  --cb-text-muted: #9ca3af;
  --cb-border: #334155;
  --cb-radius: 12px;
  --cb-shadow: 0 8px 32px rgba(0,0,0,0.4);
  --cb-transition: 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- Floating Chat Button --- */
.chatbot-trigger {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 9999;
  width: 62px;
  height: 62px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: linear-gradient(135deg, var(--cb-amber), var(--cb-green));
  box-shadow: 0 4px 20px rgba(245, 166, 35, 0.4), 0 2px 8px rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--cb-transition), box-shadow var(--cb-transition);
  overflow: visible;
}

.chatbot-trigger:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 28px rgba(245, 166, 35, 0.55), 0 4px 12px rgba(0,0,0,0.3);
}

.chatbot-trigger:active {
  transform: scale(0.95);
}

.chatbot-trigger svg {
  width: 34px;
  height: 34px;
  fill: #fff;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.3));
  transition: opacity 0.2s;
}

.chatbot-trigger .cb-icon-close {
  display: none;
}

.chatbot-trigger.is-open .cb-icon-elephant {
  display: none;
}

.chatbot-trigger.is-open .cb-icon-close {
  display: block;
}

/* --- Sparkle Effect on Button --- */
.chatbot-trigger::before,
.chatbot-trigger::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
}

.chatbot-trigger::before {
  width: 6px;
  height: 6px;
  background: #fff;
  top: 6px;
  right: 8px;
  animation: cb-sparkle-1 2.4s ease-in-out infinite;
}

.chatbot-trigger::after {
  width: 4px;
  height: 4px;
  background: var(--cb-amber);
  bottom: 8px;
  left: 6px;
  animation: cb-sparkle-2 2.8s ease-in-out infinite 0.6s;
}

@keyframes cb-sparkle-1 {
  0%, 100% { opacity: 0; transform: scale(0) translate(0, 0); }
  20% { opacity: 1; transform: scale(1) translate(-4px, -6px); }
  40% { opacity: 0.6; transform: scale(1.3) translate(-8px, -12px); }
  60% { opacity: 0; transform: scale(0) translate(-12px, -18px); }
}

@keyframes cb-sparkle-2 {
  0%, 100% { opacity: 0; transform: scale(0) translate(0, 0); }
  25% { opacity: 1; transform: scale(1) translate(5px, 4px); }
  50% { opacity: 0.5; transform: scale(1.2) translate(10px, 8px); }
  70% { opacity: 0; transform: scale(0) translate(14px, 12px); }
}

/* Extra sparkle dots via box-shadow */
.chatbot-trigger .cb-sparkles {
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  pointer-events: none;
  animation: cb-sparkle-ring 3s linear infinite;
}

@keyframes cb-sparkle-ring {
  0% {
    box-shadow:
      12px -18px 0 -2px rgba(255,255,255,0),
      -16px -10px 0 -2px rgba(245,166,35,0),
      18px 8px 0 -2px rgba(255,255,255,0),
      -8px 18px 0 -2px rgba(123,166,138,0);
  }
  25% {
    box-shadow:
      12px -18px 0 0px rgba(255,255,255,0.9),
      -16px -10px 0 -2px rgba(245,166,35,0),
      18px 8px 0 -2px rgba(255,255,255,0),
      -8px 18px 0 -2px rgba(123,166,138,0);
  }
  50% {
    box-shadow:
      12px -18px 0 -2px rgba(255,255,255,0),
      -16px -10px 0 0px rgba(245,166,35,0.9),
      18px 8px 0 0px rgba(255,255,255,0.9),
      -8px 18px 0 -2px rgba(123,166,138,0);
  }
  75% {
    box-shadow:
      12px -18px 0 -2px rgba(255,255,255,0),
      -16px -10px 0 -2px rgba(245,166,35,0),
      18px 8px 0 -2px rgba(255,255,255,0),
      -8px 18px 0 0px rgba(123,166,138,0.9);
  }
  100% {
    box-shadow:
      12px -18px 0 -2px rgba(255,255,255,0),
      -16px -10px 0 -2px rgba(245,166,35,0),
      18px 8px 0 -2px rgba(255,255,255,0),
      -8px 18px 0 -2px rgba(123,166,138,0);
  }
}

/* --- Chat Panel --- */
.chatbot-panel {
  position: fixed;
  bottom: 100px;
  right: 28px;
  z-index: 9998;
  width: 380px;
  max-height: calc(100vh - 140px);
  background: var(--cb-bg-panel);
  border-radius: var(--cb-radius);
  box-shadow: var(--cb-shadow);
  border: 1px solid var(--cb-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;

  /* Hidden by default */
  opacity: 0;
  visibility: hidden;
  transform: translateY(24px) scale(0.95);
  transform-origin: bottom right;
  transition:
    opacity var(--cb-transition),
    visibility var(--cb-transition),
    transform var(--cb-transition);
}

.chatbot-panel.is-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* Closing animation */
.chatbot-panel.is-closing {
  opacity: 0;
  visibility: hidden;
  transform: translateY(16px) scale(0.92);
}

/* --- Panel Header --- */
.chatbot-header {
  background: linear-gradient(135deg, var(--cb-amber), var(--cb-green));
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;
  overflow: hidden;
}

.chatbot-header__icon {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
}

.chatbot-header__icon svg {
  width: 100%;
  height: 100%;
  fill: #fff;
  filter: drop-shadow(0 1px 3px rgba(0,0,0,0.2));
}

.chatbot-header__text {
  flex: 1;
}

.chatbot-header__title {
  font-family: 'Poppins', sans-serif;
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  line-height: 1.2;
  text-shadow: 0 1px 2px rgba(0,0,0,0.15);
}

.chatbot-header__subtitle {
  font-family: 'Roboto', sans-serif;
  font-size: 12px;
  color: rgba(255,255,255,0.85);
  margin-top: 2px;
}

/* Header sparkle shimmer */
.chatbot-header::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 60%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255,255,255,0.15),
    rgba(255,255,255,0.25),
    rgba(255,255,255,0.15),
    transparent
  );
  animation: cb-header-shimmer 4s ease-in-out infinite;
  pointer-events: none;
}

@keyframes cb-header-shimmer {
  0% { left: -100%; }
  50% { left: 120%; }
  100% { left: 120%; }
}

/* --- Panel Body / Form --- */
.chatbot-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
  scrollbar-width: thin;
  scrollbar-color: var(--cb-border) transparent;
}

.chatbot-body::-webkit-scrollbar {
  width: 5px;
}

.chatbot-body::-webkit-scrollbar-track {
  background: transparent;
}

.chatbot-body::-webkit-scrollbar-thumb {
  background: var(--cb-border);
  border-radius: 4px;
}

/* --- Form Elements --- */
.cb-form-group {
  margin-bottom: 14px;
}

.cb-form-group label {
  display: block;
  font-family: 'Roboto', sans-serif;
  font-size: 13px;
  font-weight: 500;
  color: var(--cb-text);
  margin-bottom: 5px;
}

.cb-form-group label .cb-required {
  color: var(--cb-amber);
  margin-left: 2px;
}

.cb-form-group label .cb-optional {
  color: var(--cb-text-muted);
  font-size: 11px;
  font-weight: 400;
}

.cb-form-group input,
.cb-form-group select,
.cb-form-group textarea {
  width: 100%;
  padding: 10px 14px;
  font-family: 'Roboto', sans-serif;
  font-size: 14px;
  color: var(--cb-text);
  background: var(--cb-bg-input);
  border: 1px solid var(--cb-border);
  border-radius: 8px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  box-sizing: border-box;
  -webkit-appearance: none;
}

.cb-form-group input::placeholder,
.cb-form-group textarea::placeholder {
  color: var(--cb-text-muted);
}

.cb-form-group input:focus,
.cb-form-group select:focus,
.cb-form-group textarea:focus {
  border-color: var(--cb-amber);
  box-shadow: 0 0 0 3px rgba(245, 166, 35, 0.15);
}

.cb-form-group select {
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%239ca3af' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

.cb-form-group select option {
  background: var(--cb-bg-input);
  color: var(--cb-text);
}

.cb-form-group textarea {
  resize: vertical;
  min-height: 80px;
  max-height: 160px;
}

/* Error state */
.cb-form-group.has-error input,
.cb-form-group.has-error select,
.cb-form-group.has-error textarea {
  border-color: #ef4444;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15);
}

.cb-form-error {
  font-size: 12px;
  color: #ef4444;
  margin-top: 4px;
  display: none;
}

.cb-form-group.has-error .cb-form-error {
  display: block;
}

/* Honeypot - visually hidden */
.cb-hp-field {
  position: absolute;
  left: -9999px;
  opacity: 0;
  height: 0;
  width: 0;
  overflow: hidden;
  pointer-events: none;
}

/* --- Submit Button --- */
.cb-submit-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px 20px;
  font-family: 'Poppins', sans-serif;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, var(--cb-amber), var(--cb-green));
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: box-shadow var(--cb-transition), transform 0.15s;
  position: relative;
  overflow: hidden;
  margin-top: 4px;
}

.cb-submit-btn:hover {
  box-shadow: 0 4px 20px rgba(245, 166, 35, 0.45), 0 0 40px rgba(245, 166, 35, 0.15);
}

.cb-submit-btn:active {
  transform: scale(0.97);
}

.cb-submit-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Shimmer effect on submit button */
.cb-submit-btn::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 50%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255,255,255,0.2),
    transparent
  );
  transition: left 0.5s;
}

.cb-submit-btn:hover::after {
  left: 120%;
}

/* Loading spinner */
.cb-submit-btn .cb-spinner {
  display: none;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: cb-spin 0.7s linear infinite;
}

.cb-submit-btn.is-loading .cb-spinner {
  display: block;
}

.cb-submit-btn.is-loading .cb-btn-text {
  display: none;
}

@keyframes cb-spin {
  to { transform: rotate(360deg); }
}

/* --- Success State --- */
.chatbot-success {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 20px;
  min-height: 280px;
}

.chatbot-success.is-visible {
  display: flex;
  animation: cb-fade-in 0.5s ease;
}

@keyframes cb-fade-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.cb-success-icon {
  width: 64px;
  height: 64px;
  margin-bottom: 16px;
  position: relative;
}

.cb-success-icon svg {
  width: 100%;
  height: 100%;
}

.cb-success-icon .cb-check-circle {
  stroke-dasharray: 200;
  stroke-dashoffset: 200;
  animation: cb-draw-check 0.8s ease forwards 0.2s;
}

@keyframes cb-draw-check {
  to { stroke-dashoffset: 0; }
}

.chatbot-success h3 {
  font-family: 'Poppins', sans-serif;
  font-size: 18px;
  font-weight: 600;
  color: var(--cb-amber);
  margin: 0 0 8px;
}

.chatbot-success p {
  font-family: 'Roboto', sans-serif;
  font-size: 14px;
  color: var(--cb-text-muted);
  margin: 0;
  line-height: 1.5;
}

/* --- Already Submitted State --- */
.chatbot-already {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 20px;
  min-height: 280px;
}

.chatbot-already.is-visible {
  display: flex;
  animation: cb-fade-in 0.5s ease;
}

.chatbot-already h3 {
  font-family: 'Poppins', sans-serif;
  font-size: 18px;
  font-weight: 600;
  color: var(--cb-green);
  margin: 0 0 8px;
}

.chatbot-already p {
  font-family: 'Roboto', sans-serif;
  font-size: 14px;
  color: var(--cb-text-muted);
  margin: 0 0 16px;
  line-height: 1.5;
}

.cb-new-query-btn {
  font-family: 'Poppins', sans-serif;
  font-size: 13px;
  font-weight: 500;
  color: var(--cb-amber);
  background: transparent;
  border: 1px solid var(--cb-amber);
  border-radius: 8px;
  padding: 8px 20px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.cb-new-query-btn:hover {
  background: var(--cb-amber);
  color: #fff;
}

/* --- Sparkle Burst (success confetti) --- */
.cb-sparkle-burst {
  position: absolute;
  pointer-events: none;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  overflow: hidden;
}

.cb-sparkle-burst .cb-particle {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  opacity: 0;
  animation: cb-burst 1s ease-out forwards;
}

@keyframes cb-burst {
  0% {
    opacity: 1;
    transform: translate(0, 0) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(var(--tx), var(--ty)) scale(0);
  }
}

/* --- Animated Elephant Icon --- */
.cb-icon-elephant,
.cb-header-elephant,
.cb-already-elephant {
  overflow: visible;
}

/* Body has a subtle breathing scale pulse */
.cb-elephant-body {
  transform-origin: 32px 34px;
  animation: cb-elephant-breathe 3.5s ease-in-out infinite;
}

/* Trunk gentle sway */
.cb-elephant-trunk {
  transform-origin: 11px 32px;
  animation: cb-elephant-trunk-sway 3s ease-in-out infinite;
}

/* Ear subtle flutter */
.cb-elephant-ear {
  transform-origin: 38px 20px;
  animation: cb-elephant-ear-flutter 4s ease-in-out infinite;
}

/* Eye gentle blink */
.cb-elephant-eye {
  animation: cb-elephant-blink 5s ease-in-out infinite;
}

/* Tusk follows trunk slightly */
.cb-elephant-tusk {
  transform-origin: 14px 29px;
  animation: cb-elephant-tusk-sway 3s ease-in-out infinite;
}

@keyframes cb-elephant-breathe {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.015);
  }
}

@keyframes cb-elephant-trunk-sway {
  0%, 100% {
    transform: rotate(0deg) translateY(0);
  }
  30% {
    transform: rotate(4deg) translateY(-0.5px);
  }
  70% {
    transform: rotate(-3deg) translateY(0.5px);
  }
}

@keyframes cb-elephant-ear-flutter {
  0%, 100% {
    transform: scaleX(1) rotate(0deg);
    opacity: 0.2;
  }
  40% {
    transform: scaleX(1.08) rotate(-2deg);
    opacity: 0.28;
  }
  60% {
    transform: scaleX(0.95) rotate(1deg);
    opacity: 0.15;
  }
}

@keyframes cb-elephant-blink {
  0%, 42%, 48%, 100% {
    opacity: 0.9;
    transform: scaleY(1);
  }
  45% {
    opacity: 0.1;
    transform: scaleY(0.1);
  }
}

@keyframes cb-elephant-tusk-sway {
  0%, 100% {
    transform: rotate(0deg);
  }
  30% {
    transform: rotate(2deg);
  }
  70% {
    transform: rotate(-1.5deg);
  }
}

/* Pause elephant animations when button is in open (close-icon) state */
.chatbot-trigger.is-open .cb-elephant-body,
.chatbot-trigger.is-open .cb-elephant-trunk,
.chatbot-trigger.is-open .cb-elephant-ear,
.chatbot-trigger.is-open .cb-elephant-eye,
.chatbot-trigger.is-open .cb-elephant-tusk {
  animation-play-state: paused;
}

/* --- Responsive --- */
@media (max-width: 600px) {
  .chatbot-panel {
    width: calc(100vw - 16px);
    right: 8px;
    bottom: 80px;
    max-height: calc(100vh - 100px);
    border-radius: 12px;
  }

  .chatbot-trigger {
    bottom: 16px;
    right: 16px;
    width: 50px;
    height: 50px;
  }

  .chatbot-trigger svg {
    width: 30px;
    height: 30px;
  }

  .chatbot-header {
    padding: 14px 16px;
  }

  .chatbot-body {
    padding: 16px;
  }
}

/* --- Reduced motion --- */
@media (prefers-reduced-motion: reduce) {
  .chatbot-trigger::before,
  .chatbot-trigger::after,
  .chatbot-trigger .cb-sparkles,
  .chatbot-header::after,
  .cb-submit-btn::after,
  .cb-elephant-body,
  .cb-elephant-trunk,
  .cb-elephant-ear,
  .cb-elephant-eye,
  .cb-elephant-tusk {
    animation: none;
  }

  .chatbot-panel {
    transition-duration: 0.01ms;
  }
}
