/* Kavach AI Chat Widget — premium glassmorphism */
:root {
  --kcw-primary: #1a1a2e;
  --kcw-accent: #c9a962;
  --kcw-glass: rgba(255, 255, 255, 0.12);
  --kcw-glass-border: rgba(255, 255, 255, 0.2);
  --kcw-shadow: 0 24px 64px rgba(0, 0, 0, 0.35);
  --kcw-radius: 20px;
  --kcw-font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

#kavach-chat-root {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 99999;
  font-family: var(--kcw-font);
}

#kavach-chat-root.kcw-position-left {
  right: auto;
  left: 24px;
}

#kavach-chat-toggle {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 1px solid var(--kcw-glass-border);
  background: linear-gradient(135deg, var(--kcw-primary, #1a1a2e) 0%, #2d2d44 100%);
  color: var(--kcw-accent);
  cursor: pointer;
  box-shadow: var(--kcw-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  overflow: visible;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}

#kavach-chat-toggle:hover {
  transform: scale(1.06);
  box-shadow: 0 28px 72px rgba(201, 169, 98, 0.25);
}

#kavach-chat-toggle .kcw-avatar {
  animation: kcw-avatar-float 3.2s ease-in-out infinite;
}

#kavach-chat-toggle:hover .kcw-avatar {
  animation: kcw-avatar-float 3.2s ease-in-out infinite, kcw-avatar-wiggle 0.5s ease;
}

#kavach-chat-panel.open ~ #kavach-chat-toggle .kcw-avatar {
  animation: none;
}

/* ── Animated avatar (Kavi shield-bot) ── */
.kcw-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  line-height: 0;
}

.kcw-avatar--sm { width: 28px; height: 28px; }
.kcw-avatar--md { width: 44px; height: 44px; }
.kcw-avatar--lg { width: 60px; height: 60px; }

.kcw-avatar {
  position: relative;
}

.kcw-avatar-stage {
  display: block;
  line-height: 0;
}

.kcw-avatar-lottie {
  position: absolute;
  inset: -8%;
  pointer-events: none;
  z-index: 2;
}

.kcw-avatar-logo {
  transform-origin: 32px 34px;
}

.kcw-avatar-fallback {
  transform-origin: 32px 34px;
}

.kcw-avatar-svg {
  display: block;
  overflow: visible;
}

.kcw-avatar-ring {
  transform-origin: 32px 32px;
  animation: kcw-ring-pulse 2.8s ease-in-out infinite;
}

.kcw-avatar-body {
  transform-origin: 32px 36px;
}

.kcw-avatar-logo,
.kcw-avatar-fallback {
  animation: kcw-logo-breathe 4s ease-in-out infinite;
}

.kcw-avatar-antenna-dot {
  animation: kcw-antenna-glow 2s ease-in-out infinite;
}

.kcw-avatar-smile {
  display: none;
}

/* Typing state */
.kcw-avatar--typing .kcw-avatar-logo,
.kcw-avatar--typing .kcw-avatar-fallback { opacity: 0.35; transition: opacity 0.2s; }
.kcw-avatar--typing .kcw-avatar-typing-dots { opacity: 1; }
.kcw-avatar--typing .kcw-avatar-body { animation: kcw-think-bob 1s ease-in-out infinite; }
.kcw-avatar--typing .kcw-avatar-typing-dots circle:nth-child(1) { animation: kcw-dot-bounce 1.2s infinite; }
.kcw-avatar--typing .kcw-avatar-typing-dots circle:nth-child(2) { animation: kcw-dot-bounce 1.2s infinite 0.15s; }
.kcw-avatar--typing .kcw-avatar-typing-dots circle:nth-child(3) { animation: kcw-dot-bounce 1.2s infinite 0.3s; }

/* Lottie CSS fallbacks */
.kcw-avatar--wave-fallback .kcw-avatar-stage,
.kcw-avatar--wave .kcw-avatar-stage {
  animation: kcw-avatar-wave 0.8s ease-in-out 2;
}

.kcw-avatar--celebrate-fallback .kcw-avatar-ring,
.kcw-avatar--celebrate .kcw-avatar-ring {
  animation: kcw-ring-celebrate 1.1s ease-out;
}

.kcw-avatar--celebrate-fallback .kcw-avatar-stage,
.kcw-avatar--celebrate .kcw-avatar-stage {
  animation: kcw-avatar-pop 0.55s ease-out;
}

/* Active / panel open */
.kcw-avatar--active .kcw-avatar-ring {
  animation: kcw-ring-active 1.6s ease-in-out infinite;
  opacity: 0.85;
}

@keyframes kcw-avatar-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

@keyframes kcw-avatar-wiggle {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(-4deg); }
  75% { transform: rotate(4deg); }
}

@keyframes kcw-ring-pulse {
  0%, 100% { transform: scale(1); opacity: 0.45; }
  50% { transform: scale(1.04); opacity: 0.7; }
}

@keyframes kcw-ring-active {
  0%, 100% { transform: scale(1); stroke-opacity: 0.6; }
  50% { transform: scale(1.08); stroke-opacity: 1; }
}

@keyframes kcw-logo-breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.03); }
}

@keyframes kcw-avatar-wave {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(-8deg); }
  75% { transform: rotate(8deg); }
}

@keyframes kcw-avatar-pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

@keyframes kcw-ring-celebrate {
  0% { transform: scale(1); opacity: 0.55; }
  50% { transform: scale(1.18); opacity: 1; }
  100% { transform: scale(1); opacity: 0.55; }
}

@keyframes kcw-antenna-glow {
  0%, 100% { opacity: 0.65; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.15); }
}

@keyframes kcw-smile {
  0%, 100% { transform: scaleX(1); }
  50% { transform: scaleX(1.06); }
}

.kcw-header-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.kcw-sound-btn,
.kcw-new-chat-btn {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.7);
  cursor: pointer;
  padding: 6px;
  font-size: 14px;
  line-height: 1;
}

.kcw-sound-btn.is-muted {
  color: rgba(255, 255, 255, 0.35);
}

.kcw-header-subtitle {
  display: block;
  font-size: 10px;
  color: rgba(201, 169, 98, 0.85);
  margin-top: 1px;
  letter-spacing: 0.2px;
}

@keyframes kcw-think-bob {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-1.5px) rotate(-1.5deg); }
}

@keyframes kcw-dot-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.45; }
  30% { transform: translateY(-3px); opacity: 1; }
}

/* Header with avatar */
.kcw-header-main {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.kcw-header-text {
  min-width: 0;
}

.kcw-status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.55);
  margin-top: 2px;
}

.kcw-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 6px rgba(74, 222, 128, 0.6);
  animation: kcw-status-pulse 2s ease-in-out infinite;
}

@keyframes kcw-status-pulse {
  0%, 100% { opacity: 0.7; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.2); }
}

/* Bot message row with mini avatar */
.kcw-msg-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  align-self: flex-start;
  max-width: 92%;
}

.kcw-msg-row .kcw-avatar {
  margin-bottom: 2px;
}

.kcw-msg-row .kcw-msg {
  max-width: 100%;
}

#kavach-chat-root.kcw-position-left #kavach-chat-panel {
  right: auto;
  left: 0;
}

#kavach-chat-panel {
  display: none;
  flex-direction: column;
  position: absolute;
  bottom: 76px;
  right: 0;
  width: min(380px, calc(100vw - 32px));
  height: min(560px, calc(100vh - 120px));
  border-radius: var(--kcw-radius);
  background: linear-gradient(160deg, color-mix(in srgb, var(--kcw-primary, #1a1a2e) 95%, transparent) 0%, rgba(45, 45, 68, 0.92) 100%);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--kcw-glass-border);
  box-shadow: var(--kcw-shadow);
  overflow: hidden;
  animation: kcw-slide-up 0.3s ease;
}

#kavach-chat-panel.open {
  display: flex;
}

.kcw-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.kcw-chat-pane {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#kavach-chat-panel.kcw-mode-callback .kcw-chat-pane,
#kavach-chat-panel.kcw-mode-callback #kcw-input-area {
  display: none !important;
}

#kavach-chat-panel.kcw-mode-callback #kcw-callback-panel {
  display: flex !important;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

#kavach-chat-panel.kcw-mode-chat #kcw-callback-panel {
  display: none !important;
}

#kcw-callback-panel[hidden] {
  display: none !important;
}

#kcw-chat-pane[hidden],
#kcw-typing[hidden],
#kcw-input-area[hidden] {
  display: none !important;
}

@keyframes kcw-slide-up {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

.kcw-header {
  padding: 16px 18px;
  background: rgba(0, 0, 0, 0.2);
  border-bottom: 1px solid var(--kcw-glass-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.kcw-header-text h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  letter-spacing: 0.3px;
}

.kcw-header-actions button {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.7);
  cursor: pointer;
  padding: 6px;
  font-size: 16px;
}

.kcw-tabs {
  display: flex;
  gap: 6px;
  padding: 10px 14px 0;
  background: rgba(0, 0, 0, 0.12);
  border-bottom: 1px solid var(--kcw-glass-border);
}

.kcw-tab {
  flex: 1;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.65);
  border-radius: 12px 12px 0 0;
  padding: 8px 10px;
  font-size: 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.kcw-tab.active {
  background: rgba(201, 169, 98, 0.18);
  border-color: rgba(201, 169, 98, 0.35);
  color: var(--kcw-accent);
}

.kcw-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

/* Callback request panel */
.kcw-callback {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px 16px 16px;
}

.kcw-callback-intro {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 12px;
  margin-bottom: 12px;
  border-radius: 12px;
  background: rgba(37, 211, 102, 0.12);
  border: 1px solid rgba(37, 211, 102, 0.25);
}

.kcw-callback-intro i {
  color: #25d366;
  font-size: 20px;
  margin-top: 2px;
}

.kcw-callback-intro strong {
  display: block;
  color: #fff;
  font-size: 13px;
}

.kcw-callback-intro span {
  display: block;
  color: rgba(255, 255, 255, 0.6);
  font-size: 11px;
  margin-top: 2px;
}

.kcw-callback-label {
  display: block;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.55);
  margin: 8px 0 4px;
}

.kcw-callback-input {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  padding: 9px 11px;
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  font-size: 13px;
  font-family: inherit;
}

.kcw-callback-textarea {
  resize: vertical;
  min-height: 56px;
}

.kcw-callback-phone-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.kcw-callback-prefix {
  color: rgba(255, 255, 255, 0.55);
  font-size: 13px;
  flex-shrink: 0;
}

.kcw-callback-phone-row .kcw-callback-input {
  flex: 1;
}

.kcw-callback-verified {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 6px;
  font-size: 11px;
  color: #4ade80;
}

.kcw-callback-btn {
  width: 100%;
  margin-top: 8px;
  border-radius: 12px;
  border: none;
  padding: 10px 12px;
  font-size: 12.5px;
  cursor: pointer;
  font-family: inherit;
}

.kcw-callback-btn--outline {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.kcw-callback-btn--primary {
  background: linear-gradient(135deg, var(--kcw-accent, #c9a962) 0%, #b8944f 100%);
  color: var(--kcw-primary, #1a1a2e);
  font-weight: 600;
}

.kcw-callback-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.kcw-callback-otp-row {
  margin-top: 4px;
}

.kcw-callback-otp-inputs {
  display: flex;
  gap: 8px;
}

.kcw-callback-otp-inputs .kcw-callback-input {
  flex: 1;
  letter-spacing: 0.15em;
  text-align: center;
}

.kcw-callback-otp-inputs .kcw-callback-btn {
  width: auto;
  margin-top: 0;
  flex-shrink: 0;
  padding: 10px 14px;
}

.kcw-callback-status {
  min-height: 18px;
  margin: 8px 0 0;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.55);
}

.kcw-callback-status--error { color: #f87171; }
.kcw-callback-status--success { color: #4ade80; }
.kcw-callback-status--pending { color: var(--kcw-accent); }

.kcw-callback-success {
  text-align: center;
  padding: 24px 12px;
}

.kcw-callback-success-icon {
  width: 52px;
  height: 52px;
  margin: 0 auto 12px;
  border-radius: 50%;
  background: rgba(74, 222, 128, 0.15);
  color: #4ade80;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}

.kcw-callback-success-text {
  color: #fff;
  font-size: 14px;
  margin: 0 0 16px;
  line-height: 1.45;
}

.kcw-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 13.5px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.kcw-msg.bot {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.1);
  color: #f0f0f5;
  border-bottom-left-radius: 4px;
}

.kcw-msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, #c9a962 0%, #b8944f 100%);
  color: #1a1a2e;
  border-bottom-right-radius: 4px;
}

.kcw-typing {
  align-self: flex-start;
  display: none;
  align-items: flex-end;
  gap: 8px;
}

.kcw-typing.show { display: flex; }

.kcw-typing-bubble {
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  display: flex;
  gap: 4px;
  align-items: center;
}

.kcw-typing-bubble span {
  width: 6px;
  height: 6px;
  background: var(--kcw-accent);
  border-radius: 50%;
  animation: kcw-bounce 1.2s infinite;
}

.kcw-typing-bubble span:nth-child(2) { animation-delay: 0.15s; }
.kcw-typing-bubble span:nth-child(3) { animation-delay: 0.3s; }

@keyframes kcw-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.kcw-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}

.kcw-btn-chip {
  padding: 8px 14px;
  border-radius: 20px;
  border: 1px solid rgba(201, 169, 98, 0.5);
  background: rgba(201, 169, 98, 0.12);
  color: var(--kcw-accent);
  font-size: 12.5px;
  cursor: pointer;
  transition: background 0.2s;
}

.kcw-btn-chip:hover {
  background: rgba(201, 169, 98, 0.28);
}

.kcw-input-area {
  padding: 12px 14px;
  border-top: 1px solid var(--kcw-glass-border);
  display: flex;
  gap: 8px;
  align-items: flex-end;
  background: rgba(0, 0, 0, 0.15);
}

.kcw-input-area textarea {
  flex: 1;
  resize: none;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 14px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  font-size: 13px;
  font-family: inherit;
  min-height: 40px;
  max-height: 100px;
}

.kcw-input-area textarea::placeholder { color: rgba(255, 255, 255, 0.4); }

.kcw-send, .kcw-upload {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--kcw-accent);
  color: var(--kcw-primary, #1a1a2e);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.kcw-upload {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

@media (prefers-reduced-motion: reduce) {
  .kcw-avatar,
  .kcw-avatar-ring,
  .kcw-avatar-logo,
  .kcw-avatar-fallback,
  .kcw-avatar-antenna-dot,
  .kcw-avatar-body,
  .kcw-status-dot,
  .kcw-avatar-stage,
  #kavach-chat-toggle .kcw-avatar {
    animation: none !important;
  }
  .kcw-avatar-lottie { display: none; }
}

@media (max-width: 480px) {
  #kavach-chat-root { bottom: 16px; right: 16px; }
  #kavach-chat-panel { width: calc(100vw - 32px); height: calc(100vh - 100px); }
}
