/* ─── KP ASSISTANT CHAT WIDGET ─── */
#kp-chat-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.9rem 1.3rem;
  border-radius: 999px;
  background: linear-gradient(180deg, #4db2ff 0%, var(--accent) 50%, #2a7acc 100%);
  color: var(--white);
  font-family: var(--font-primary);
  font-weight: 600;
  font-size: 0.95rem;
  box-shadow: 0 4px 15px var(--accent-glow), inset 0 1px 0 rgba(255, 255, 255, 0.35);
  min-height: 44px;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}

#kp-chat-toggle:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px var(--accent-glow), inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

#kp-chat-toggle svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

#kp-chat-toggle .kp-chat-close-icon {
  display: none;
}

#kp-chat-toggle[aria-expanded="true"] .kp-chat-open-icon {
  display: none;
}

#kp-chat-toggle[aria-expanded="true"] .kp-chat-close-icon {
  display: block;
}

#kp-chat-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

#kp-chat-panel {
  position: fixed;
  bottom: 90px;
  right: 24px;
  z-index: 9999;
  width: min(380px, calc(100vw - 32px));
  max-height: min(600px, calc(100vh - 130px));
  max-height: min(600px, calc(100dvh - 130px));
  display: flex;
  flex-direction: column;
  background: var(--navy);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 28px 56px rgba(0, 0, 0, 0.5), 0 10px 20px rgba(0, 0, 0, 0.35);
  overflow: hidden;
  opacity: 0;
  transform: translateY(16px) scale(0.98);
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.25s cubic-bezier(0.22, 1, 0.36, 1), transform 0.25s cubic-bezier(0.22, 1, 0.36, 1), visibility 0.25s;
}

#kp-chat-panel.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  visibility: visible;
  pointer-events: auto;
}

.kp-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.2rem;
  background: var(--dark);
  border-bottom: 1px solid var(--border);
}

.kp-chat-header h2 {
  font-family: var(--font-secondary);
  font-size: 1.05rem;
  color: var(--white);
  margin: 0;
}

.kp-chat-header p {
  font-size: 0.75rem;
  color: var(--gray);
  margin: 0.15rem 0 0;
}

.kp-chat-header-close {
  width: 44px;
  height: 44px;
  min-width: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--gray);
  transition: background 0.2s ease, color 0.2s ease;
}

.kp-chat-header-close:hover {
  background: var(--glass-strong);
  color: var(--white);
}

.kp-chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 1rem 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  scroll-behavior: smooth;
}

.kp-chat-bubble {
  max-width: 85%;
  padding: 0.65rem 0.9rem;
  border-radius: 14px;
  font-size: 0.88rem;
  line-height: 1.5;
}

.kp-chat-bubble.bot {
  align-self: flex-start;
  background: var(--card);
  color: var(--light-gray);
  border-bottom-left-radius: 4px;
}

.kp-chat-bubble.user {
  align-self: flex-end;
  background: var(--accent);
  color: var(--white);
  border-bottom-right-radius: 4px;
}

.kp-chat-quick-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0 1.2rem 0.8rem;
}

.kp-chat-quick-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--accent-light);
  font-size: 0.8rem;
  padding: 0.5rem 0.8rem;
  border-radius: 999px;
  min-height: 36px;
  transition: background 0.2s ease, color 0.2s ease;
}

.kp-chat-quick-btn:hover {
  background: var(--glass-strong);
  color: var(--white);
}

.kp-chat-typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 0.65rem 0.9rem;
  background: var(--card);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
}

.kp-chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--gray);
  opacity: 0.4;
}

@media (prefers-reduced-motion: no-preference) {
  .kp-chat-typing span {
    animation: kp-typing-pulse 1.2s ease-in-out infinite;
  }
  .kp-chat-typing span:nth-child(2) { animation-delay: 0.15s; }
  .kp-chat-typing span:nth-child(3) { animation-delay: 0.3s; }
}

@keyframes kp-typing-pulse {
  0%, 60%, 100% { opacity: 0.4; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

.kp-chat-footer {
  border-top: 1px solid var(--border);
  padding: 0.8rem 1rem;
  background: var(--dark);
}

.kp-chat-input-row {
  display: flex;
  gap: 0.5rem;
}

.kp-chat-input-row input {
  flex: 1;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--white);
  border-radius: 999px;
  padding: 0.6rem 1rem;
  font-family: var(--font-primary);
  font-size: 0.88rem;
  min-height: 40px;
}

.kp-chat-input-row input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.kp-chat-send {
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease;
}

.kp-chat-send:hover {
  background: var(--accent-light);
}

.kp-chat-send:disabled {
  opacity: 0.5;
  cursor: default;
}

.kp-chat-alt-action {
  display: block;
  text-align: center;
  font-size: 0.75rem;
  color: var(--gray);
  margin-top: 0.6rem;
}

.kp-chat-alt-action button,
button.kp-chat-alt-action {
  background: none;
  border: none;
  color: var(--accent-light);
  text-decoration: underline;
  font-size: inherit;
  font-family: inherit;
  cursor: pointer;
  padding: 0;
}

/* ─── Lead form ─── */
/* Slim bar pinned above the lead form and success view */
.kp-chat-subbar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  padding: 0 1rem;
  border-bottom: 1px solid var(--border);
}

.kp-chat-back {
  background: none;
  border: none;
  padding: 0 0.25rem;
  min-height: 36px;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--accent-light);
  cursor: pointer;
}

.kp-chat-back:hover { text-decoration: underline; }

.kp-chat-back:focus-visible {
  outline: 2px solid var(--accent-light);
  outline-offset: 2px;
  border-radius: 4px;
}

.kp-chat-lead-form {
  flex: 1;
  min-height: 0;
  padding: 1rem 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  overflow-y: auto;
}

.kp-chat-lead-form label {
  font-size: 0.78rem;
  color: var(--gray);
  display: block;
  margin-bottom: 0.3rem;
}

.kp-chat-lead-form input,
.kp-chat-lead-form select,
.kp-chat-lead-form textarea {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--white);
  border-radius: 8px;
  padding: 0.6rem 0.8rem;
  font-family: var(--font-primary);
  font-size: 0.88rem;
  min-height: 40px;
}

.kp-chat-lead-form textarea {
  min-height: 72px;
  resize: vertical;
}

.kp-chat-lead-form input:focus,
.kp-chat-lead-form select:focus,
.kp-chat-lead-form textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.kp-chat-lead-honeypot {
  position: absolute;
  left: -9999px;
}

.kp-chat-lead-submit {
  background: linear-gradient(180deg, #4db2ff 0%, var(--accent) 50%, #2a7acc 100%);
  color: var(--white);
  font-weight: 600;
  border-radius: 999px;
  padding: 0.7rem 1rem;
  min-height: 44px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.kp-chat-lead-error {
  color: #ff8a8a;
  font-size: 0.78rem;
}

.kp-chat-lead-success {
  padding: 1.2rem;
  text-align: center;
  color: var(--light-gray);
  font-size: 0.9rem;
}

@media (prefers-reduced-motion: reduce) {
  #kp-chat-panel,
  #kp-chat-toggle {
    transition: none;
  }
}

@media (max-width: 480px) {
  #kp-chat-panel {
    right: 16px;
    left: 16px;
    width: auto;
    bottom: 84px;
  }
  #kp-chat-toggle {
    right: 16px;
    bottom: 16px;
  }
}
