/* ==========================================================================
   KRITI ENERGYAN - CHAT WIDGET
   Scoped to #kp-chat-widget. Class names are unchanged, so this is a
   drop-in replacement. The one signature element is the header: a faint
   power-grid pattern with a live-wire line along its base. Everything
   else stays quiet on purpose.
   ========================================================================== */

#kp-chat-widget {
  --kp-primary: #0A3663;
  --kp-primary-hover: #072648;
  --kp-accent: #1A73E8;
  --kp-accent-hover: #1557B0;
  --kp-spark: #5AB0FF;
  --kp-bg: #FFFFFF;
  --kp-surface: #F5F7FA;
  --kp-text-heading: #0F172A;
  --kp-text-body: #334155;
  --kp-text-muted: #64748B;
  --kp-border: #E3E8EF;
  --kp-font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --kp-shadow: 0 1px 2px rgba(6, 31, 59, 0.08), 0 12px 32px rgba(6, 31, 59, 0.16), 0 32px 64px rgba(6, 31, 59, 0.14);
  --kp-radius: 20px;
  --kp-ease: cubic-bezier(0.16, 1, 0.3, 1);
  --kp-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --kp-safe-bottom: env(safe-area-inset-bottom, 20px);
  position: fixed;
  bottom: calc(var(--kp-safe-bottom) + 12px);
  right: 20px;
  z-index: 999999;
  font-family: var(--kp-font);
  font-size: 14px;
  line-height: 1.5;
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#kp-chat-widget *,
#kp-chat-widget *::before,
#kp-chat-widget *::after {
  box-sizing: border-box;
  margin: 0;
}

/* --------------------------------------------------------------------------
   Launcher
   -------------------------------------------------------------------------- */
.kp-chat-launcher {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(145deg, #2A85F7 0%, var(--kp-accent) 35%, var(--kp-primary) 100%);
  color: #ffffff;
  border: none;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(10, 54, 99, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.25);
  transition: transform 0.3s var(--kp-spring), box-shadow 0.2s ease;
  outline: none;
  padding: 0 !important;
}

/* Attention pulse: three rings after load, then it settles. */
.kp-chat-launcher::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  pointer-events: none;
  animation: kpPulse 2.4s ease-out 1.5s 3;
}

@keyframes kpPulse {
  0%   { box-shadow: 0 0 0 0 rgba(26, 115, 232, 0.5); }
  100% { box-shadow: 0 0 0 22px rgba(26, 115, 232, 0); }
}

.kp-chat-launcher:hover {
  transform: scale(1.07);
  box-shadow: 0 14px 32px rgba(10, 54, 99, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.kp-chat-launcher:active {
  transform: scale(0.96);
}

.kp-chat-launcher svg {
  width: 27px;
  height: 27px;
  fill: currentColor;
}

.kp-chat-badge {
  position: absolute;
  top: 1px;
  right: 1px;
  width: 14px;
  height: 14px;
  background-color: #10B981;
  border: 2px solid #ffffff;
  border-radius: 50%;
}

/* --------------------------------------------------------------------------
   Window shell
   -------------------------------------------------------------------------- */
.kp-chat-window {
  position: absolute;
  bottom: 76px;
  right: 0;
  width: 392px;
  max-width: calc(100vw - 32px);
  height: 620px;
  max-height: calc(100vh - 120px);
  max-height: calc(100dvh - 120px);
  background: var(--kp-bg);
  border-radius: var(--kp-radius);
  box-shadow: var(--kp-shadow);
  border: 1px solid rgba(10, 54, 99, 0.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(16px) scale(0.97);
  transform-origin: bottom right;
  transition:
    opacity 0.22s var(--kp-ease),
    transform 0.28s var(--kp-ease),
    visibility 0s linear 0.28s;
}

.kp-chat-window.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0) scale(1);
  transition-delay: 0s;
}

/* --------------------------------------------------------------------------
   Header - the signature element
   -------------------------------------------------------------------------- */
.kp-chat-header {
  position: relative;
  flex-shrink: 0;
  background-color: var(--kp-primary);
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.05) 1px, transparent 1px),
    radial-gradient(90% 180% at 100% 0%, rgba(26, 115, 232, 0.55) 0%, rgba(26, 115, 232, 0) 60%);
  background-size: 20px 20px, 20px 20px, auto;
  background-position: -1px -1px, -1px -1px, 0 0;
  color: #ffffff;
  padding: 18px 20px !important;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.kp-chat-header::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--kp-spark), var(--kp-accent) 45%, rgba(26, 115, 232, 0) 100%);
}

.kp-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.kp-header-avatar {
  position: relative;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px !important;
  border: 1px solid rgba(255, 255, 255, 0.25);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
  flex-shrink: 0;
}

.kp-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 50%;
  display: block;
}

.kp-status-dot {
  position: absolute;
  bottom: -1px;
  right: -1px;
  width: 11px;
  height: 11px;
  background: #10B981;
  border: 2px solid var(--kp-primary);
  border-radius: 50%;
  z-index: 2;
}

.kp-header-details h3 {
  font-size: 15px;
  font-weight: 650;
  color: #ffffff;
  line-height: 1.2;
  letter-spacing: -0.005em;
}

.kp-header-details p {
  font-size: 12px;
  color: #C5D5EA;
  margin-top: 3px;
}

.kp-header-actions {
  display: flex;
  gap: 2px;
}

.kp-icon-btn {
  background: transparent;
  border: none;
  color: #C5D5EA;
  cursor: pointer;
  padding: 8px !important;
  min-width: 34px;
  min-height: 34px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}

.kp-icon-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
}

/* --------------------------------------------------------------------------
   Message area
   -------------------------------------------------------------------------- */
.kp-chat-body {
  flex: 1;
  padding: 22px 18px !important;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--kp-surface);
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: #CBD5E1 transparent;
}

.kp-chat-body::-webkit-scrollbar {
  width: 6px;
}

.kp-chat-body::-webkit-scrollbar-thumb {
  background: #CBD5E1;
  border-radius: 6px;
}

.kp-chat-body::-webkit-scrollbar-thumb:hover {
  background: #94A3B8;
}

.kp-message-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 86%;
  animation: kpRise 0.32s var(--kp-ease) both;
}

@keyframes kpRise {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.kp-msg-bot {
  align-self: flex-start;
}

.kp-msg-user {
  align-self: flex-end;
}

/* Bubbles */
.kp-bubble {
  padding: 13px 18px !important;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.55;
  letter-spacing: -0.003em;
  word-break: break-word;
  white-space: pre-wrap;
}

.kp-msg-bot .kp-bubble {
  background: #ffffff;
  color: var(--kp-text-heading);
  border: 1px solid var(--kp-border);
  border-top-left-radius: 5px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.kp-msg-user .kp-bubble {
  background: var(--kp-accent);
  color: #ffffff;
  border-top-right-radius: 5px;
}

.kp-msg-time {
  font-size: 11px;
  color: var(--kp-text-muted);
  font-variant-numeric: tabular-nums;
  padding: 0 4px !important;
}

.kp-msg-user .kp-msg-time {
  text-align: right;
}

/* Typing indicator */
.kp-typing-indicator {
  display: none;
  align-self: flex-start;
  background: #ffffff;
  border: 1px solid var(--kp-border);
  padding: 13px 18px !important;
  border-radius: 16px;
  border-top-left-radius: 5px;
  gap: 5px;
  align-items: center;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.kp-typing-indicator.is-active {
  display: inline-flex;
}

.kp-typing-dot {
  width: 6px;
  height: 6px;
  background: var(--kp-accent);
  border-radius: 50%;
  animation: kpBounce 1.2s infinite ease-in-out;
}

.kp-typing-dot:nth-child(2) { animation-delay: 0.15s; }
.kp-typing-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes kpBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.35; }
  30%           { transform: translateY(-4px); opacity: 1; }
}

/* Quick replies */
.kp-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}

.kp-chip-btn {
  background: #ffffff;
  color: var(--kp-primary);
  border: 1px solid #C9D6E8;
  padding: 8px 14px !important;
  border-radius: 999px;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.15s;
  text-align: left;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  line-height: 1.4;
}

.kp-chip-btn:hover {
  background: var(--kp-primary);
  color: #ffffff;
  border-color: var(--kp-primary);
  transform: translateY(-1px);
}

.kp-chip-btn:active {
  transform: translateY(0);
}

/* --------------------------------------------------------------------------
   Footer / input
   -------------------------------------------------------------------------- */
.kp-chat-footer {
  flex-shrink: 0;
  background: var(--kp-bg);
  border-top: 1px solid var(--kp-border);
  padding: 14px 16px !important;
}

.kp-input-form {
  display: flex;
  align-items: center;
  gap: 10px;
}

.kp-input-field {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--kp-border);
  border-radius: 999px;
  padding: 12px 18px !important;
  font-family: inherit;
  font-size: 14px;
  color: var(--kp-text-heading);
  background: var(--kp-surface);
  outline: none;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

.kp-input-field::placeholder {
  color: #7B8BA1;
}

.kp-input-field:focus {
  border-color: var(--kp-accent);
  background: #ffffff;
  box-shadow: 0 0 0 4px rgba(26, 115, 232, 0.14);
}

.kp-send-btn {
  background: var(--kp-accent);
  color: #ffffff;
  border: none;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.2s var(--kp-spring);
  flex-shrink: 0;
  padding: 0 !important;
}

.kp-send-btn:hover {
  background: var(--kp-accent-hover);
  transform: scale(1.05);
}

.kp-send-btn:active {
  transform: scale(0.94);
}

.kp-send-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.kp-send-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

/* --------------------------------------------------------------------------
   Toast
   -------------------------------------------------------------------------- */
.kp-chat-toast {
  position: absolute;
  top: 88px;
  left: 50%;
  transform: translate(-50%, -6px);
  background: rgba(15, 23, 42, 0.94);
  color: #ffffff;
  padding: 8px 16px !important;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  border-radius: 999px;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.25s var(--kp-ease);
  z-index: 20;
}

.kp-chat-toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* --------------------------------------------------------------------------
   Keyboard focus
   -------------------------------------------------------------------------- */
.kp-chat-launcher:focus-visible,
.kp-chip-btn:focus-visible,
.kp-send-btn:focus-visible {
  outline: 2px solid var(--kp-accent);
  outline-offset: 3px;
}

.kp-icon-btn:focus-visible {
  outline: 2px solid #ffffff;
  outline-offset: -2px;
}

/* --------------------------------------------------------------------------
   Mobile: full-screen sheet
   -------------------------------------------------------------------------- */
@media (max-width: 480px) {
  #kp-chat-widget {
    right: 12px;
    bottom: calc(var(--kp-safe-bottom) + 10px);
  }

  .kp-chat-window {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    max-width: 100vw;
    max-height: 100vh;
    max-height: 100dvh;
    border-radius: 0;
    border: none;
    transform: translateY(24px);
    transform-origin: bottom center;
  }

  .kp-chat-header {
    padding-top: calc(16px + env(safe-area-inset-top, 0px)) !important;
  }

  .kp-chat-footer {
    padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px)) !important;
  }

  /* 16px stops iOS Safari from zooming the page when the input is focused */
  .kp-input-field {
    font-size: 16px;
  }

  .kp-message-group {
    max-width: 90%;
  }

  .kp-chat-toast {
    top: calc(88px + env(safe-area-inset-top, 0px));
  }
}

/* --------------------------------------------------------------------------
   Reduced motion
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  #kp-chat-widget *,
  #kp-chat-widget *::before,
  #kp-chat-widget *::after {
    animation: none !important;
    transition-duration: 0.01ms !important;
    transition-delay: 0s !important;
    scroll-behavior: auto !important;
  }
}