/* ==========================================================================
   Crimson Parts AI Chat Widget - Scoped Styles (Production Static Asset)
   All selectors are prefixed with 'cp-chat-' to eliminate conflicts with
   Zoho Commerce templates or host page CSS.
   ========================================================================== */

:root {
  --cp-primary: #005baa;
  --cp-primary-hover: #004a8f;
  --cp-primary-light: #eff6ff;
  --cp-text-main: #0f172a;
  --cp-text-muted: #64748b;
  --cp-bg-main: #ffffff;
  --cp-bg-subtle: #f8fafc;
  --cp-border: #e2e8f0;
  --cp-user-bubble: #005baa;
  --cp-user-text: #ffffff;
  --cp-bot-bubble: #f1f5f9;
  --cp-bot-text: #1e293b;
  --cp-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.15), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
  --cp-radius-lg: 16px;
  --cp-radius-md: 10px;
  --cp-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* Reset Box Model inside Widget Root */
.cp-chat-root,
.cp-chat-root *,
.cp-chat-root *::before,
.cp-chat-root *::after {
  box-sizing: border-box;
  font-family: var(--cp-font);
  -webkit-font-smoothing: antialiased;
}

/* ==========================================================================
   Launcher Floating Button
   ========================================================================== */
.cp-chat-launcher {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background-color: var(--cp-primary);
  color: #ffffff;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 91, 170, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease;
  z-index: 999990;
  outline: none;
  padding: 0;
}

.cp-chat-launcher:hover {
  background-color: var(--cp-primary-hover);
  transform: scale(1.06);
  box-shadow: 0 6px 20px rgba(0, 91, 170, 0.55);
}

.cp-chat-launcher:active {
  transform: scale(0.96);
}

.cp-chat-launcher-icon,
.cp-chat-launcher-close {
  width: 28px;
  height: 28px;
  fill: currentColor;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.cp-chat-launcher.cp-chat-is-open .cp-chat-launcher-icon {
  display: none;
}

.cp-chat-launcher:not(.cp-chat-is-open) .cp-chat-launcher-close {
  display: none;
}

/* Notification badge indicator */
.cp-chat-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 14px;
  height: 14px;
  background-color: #22c55e;
  border: 2px solid #ffffff;
  border-radius: 50%;
}

/* ==========================================================================
   Chat Window Container
   ========================================================================== */
.cp-chat-window {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 380px;
  height: 580px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 120px);
  background: var(--cp-bg-main);
  border-radius: var(--cp-radius-lg);
  box-shadow: var(--cp-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 999999;
  border: 1px solid var(--cp-border);
  opacity: 0;
  visibility: hidden;
  transform: translateY(16px) scale(0.97);
  transition: opacity 0.25s cubic-bezier(0.16, 1, 0.3, 1),
              transform 0.25s cubic-bezier(0.16, 1, 0.3, 1),
              visibility 0.25s;
}

.cp-chat-window.cp-chat-is-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* ==========================================================================
   Header
   ========================================================================== */
.cp-chat-header {
  background: linear-gradient(135deg, #005baa 0%, #004a8f 100%);
  color: #ffffff;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  user-select: none;
}

.cp-chat-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.cp-chat-avatar {
  width: 38px;
  height: 38px;
  background-color: #ffffff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.5px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  flex-shrink: 0;
  overflow: hidden;
}

.cp-chat-avatar img,
.cp-chat-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  border-radius: 50%;
}

.cp-chat-title-group {
  display: flex;
  flex-direction: column;
}

.cp-chat-title {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
  line-height: 1.25;
  color: #ffffff;
}

.cp-chat-subtitle {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.85);
  margin: 2px 0 0 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

.cp-chat-status-dot {
  width: 7px;
  height: 7px;
  background-color: #22c55e;
  border-radius: 50%;
  display: inline-block;
}

.cp-chat-close-btn {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.85);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.cp-chat-close-btn:hover {
  background-color: rgba(255, 255, 255, 0.15);
  color: #ffffff;
}

/* ==========================================================================
   Chat Messages Body
   ========================================================================== */
.cp-chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background-color: var(--cp-bg-subtle);
  scroll-behavior: smooth;
}

.cp-chat-body::-webkit-scrollbar {
  width: 6px;
}
.cp-chat-body::-webkit-scrollbar-thumb {
  background-color: #cbd5e1;
  border-radius: 4px;
}
.cp-chat-body::-webkit-scrollbar-track {
  background: transparent;
}

/* Message Rows */
.cp-chat-msg-row {
  display: flex;
  flex-direction: column;
  max-width: 86%;
  animation: cp-chat-fade-in 0.2s ease-out;
}

@keyframes cp-chat-fade-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.cp-chat-msg-user {
  align-self: flex-end;
}

.cp-chat-msg-bot {
  align-self: flex-start;
}

/* Message Bubbles */
.cp-chat-bubble {
  padding: 12px 15px;
  font-size: 13.5px;
  line-height: 1.5;
  word-break: break-word;
}

.cp-chat-msg-user .cp-chat-bubble {
  background-color: var(--cp-user-bubble);
  color: var(--cp-user-text);
  border-radius: 14px 14px 2px 14px;
}

.cp-chat-msg-bot .cp-chat-bubble {
  background-color: #ffffff;
  color: var(--cp-bot-text);
  border-radius: 14px 14px 14px 2px;
  border: 1px solid var(--cp-border);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

/* Fallback message styling (soft amber tint for safe catalog fallbacks) */
.cp-chat-msg-fallback .cp-chat-bubble {
  background-color: #fffdf5;
  border-color: #fef08a;
}

/* Message Markdown Links */
.cp-chat-bubble a {
  color: #0284c7;
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.cp-chat-msg-user .cp-chat-bubble a {
  color: #ffffff;
  text-decoration: underline;
}

.cp-chat-bubble a:hover {
  color: #0369a1;
}

/* ==========================================================================
   Sources Cards / Badges Container
   ========================================================================== */
.cp-chat-sources {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.cp-chat-sources-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 700;
  color: var(--cp-text-muted);
}

.cp-chat-source-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background-color: #ffffff;
  border: 1px solid var(--cp-border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  color: var(--cp-text-main);
  text-decoration: none;
  transition: background-color 0.15s ease, border-color 0.15s ease;
  width: fit-content;
  max-width: 100%;
}

.cp-chat-source-item:hover {
  background-color: var(--cp-primary-light);
  border-color: #93c5fd;
  color: var(--cp-primary);
}

.cp-chat-source-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
}

.cp-chat-source-tag {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  padding: 1px 4px;
  border-radius: 4px;
  background-color: #e2e8f0;
  color: #475569;
}

/* ==========================================================================
   Human Handoff & Lead Capture Fallback Styles
   ========================================================================== */
.cp-chat-handoff-action {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cp-chat-handoff-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background-color: #ffffff;
  color: var(--cp-primary);
  border: 1px solid var(--cp-primary);
  border-radius: 20px;
  padding: 7px 14px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  width: fit-content;
  transition: all 0.15s ease;
  outline: none;
}

.cp-chat-handoff-btn:hover {
  background-color: var(--cp-primary);
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(0, 91, 170, 0.25);
  transform: translateY(-1px);
}

.cp-chat-lead-card {
  margin-top: 10px;
  background-color: #ffffff;
  border: 1px solid var(--cp-border);
  border-radius: var(--cp-radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  animation: cp-chat-fade-in 0.2s ease-out;
}

.cp-chat-lead-header {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.cp-chat-lead-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--cp-text-main);
  margin: 0;
}

.cp-chat-lead-subtitle {
  font-size: 11.5px;
  color: var(--cp-text-muted);
  line-height: 1.35;
}

.cp-chat-lead-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cp-chat-lead-input,
.cp-chat-lead-textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--cp-border);
  border-radius: 6px;
  font-size: 12.5px;
  color: var(--cp-text-main);
  background-color: var(--cp-bg-subtle);
  outline: none;
  transition: border-color 0.15s ease, background-color 0.15s ease;
  font-family: inherit;
  resize: vertical;
}

.cp-chat-lead-input:focus,
.cp-chat-lead-textarea:focus {
  border-color: var(--cp-primary);
  background-color: #ffffff;
  box-shadow: 0 0 0 2px rgba(0, 91, 170, 0.12);
}

.cp-chat-lead-input:disabled,
.cp-chat-lead-textarea:disabled {
  background-color: #f1f5f9;
  cursor: not-allowed;
  opacity: 0.7;
}

.cp-chat-lead-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}

.cp-chat-lead-submit {
  background-color: var(--cp-primary);
  color: #ffffff;
  border: none;
  border-radius: 6px;
  padding: 7px 14px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease;
  outline: none;
}

.cp-chat-lead-submit:hover:not(:disabled) {
  background-color: var(--cp-primary-hover);
}

.cp-chat-lead-submit:disabled {
  background-color: #cbd5e1;
  cursor: not-allowed;
}

.cp-chat-lead-cancel {
  background: transparent;
  color: var(--cp-text-muted);
  border: none;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
  border-radius: 6px;
  transition: color 0.15s ease;
  outline: none;
}

.cp-chat-lead-cancel:hover:not(:disabled) {
  color: var(--cp-text-main);
}

.cp-chat-lead-error-text {
  font-size: 11.5px;
  color: #dc2626;
  font-weight: 500;
  display: none;
}

.cp-chat-lead-success {
  margin-top: 10px;
  background-color: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: var(--cp-radius-md);
  padding: 12px;
  color: #166534;
  font-size: 12.5px;
  line-height: 1.45;
  animation: cp-chat-fade-in 0.2s ease-out;
}

/* ==========================================================================
   Typing Indicator
   ========================================================================== */
.cp-chat-typing-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 12px 16px;
  background-color: #ffffff;
  border: 1px solid var(--cp-border);
  border-radius: 14px 14px 14px 2px;
  width: fit-content;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.cp-chat-dot {
  width: 7px;
  height: 7px;
  background-color: #94a3b8;
  border-radius: 50%;
  animation: cp-chat-bounce 1.4s infinite ease-in-out both;
}

.cp-chat-dot:nth-child(1) { animation-delay: -0.32s; }
.cp-chat-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes cp-chat-bounce {
  0%, 80%, 100% {
    transform: scale(0);
  }
  40% {
    transform: scale(1);
  }
}

/* ==========================================================================
   Footer & Input Area
   ========================================================================== */
.cp-chat-footer {
  padding: 12px 14px;
  background-color: #ffffff;
  border-top: 1px solid var(--cp-border);
}

.cp-chat-form {
  display: flex;
  align-items: center;
  gap: 8px;
}

.cp-chat-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--cp-border);
  border-radius: var(--cp-radius-md);
  font-size: 13.5px;
  color: var(--cp-text-main);
  background-color: var(--cp-bg-subtle);
  outline: none;
  transition: border-color 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease;
}

.cp-chat-input:focus {
  border-color: var(--cp-primary);
  background-color: #ffffff;
  box-shadow: 0 0 0 3px rgba(0, 91, 170, 0.12);
}

.cp-chat-input:disabled {
  background-color: #f1f5f9;
  cursor: not-allowed;
  opacity: 0.7;
}

.cp-chat-send-btn {
  background-color: var(--cp-primary);
  color: #ffffff;
  border: none;
  width: 38px;
  height: 38px;
  border-radius: var(--cp-radius-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background-color 0.15s ease, opacity 0.15s ease, transform 0.15s ease;
  outline: none;
  padding: 0;
}

.cp-chat-send-btn:hover:not(:disabled) {
  background-color: var(--cp-primary-hover);
  transform: translateY(-1px);
}

.cp-chat-send-btn:disabled {
  background-color: #cbd5e1;
  cursor: not-allowed;
  opacity: 0.8;
}

.cp-chat-send-icon {
  width: 17px;
  height: 17px;
  fill: currentColor;
}

/* Disclaimer text */
.cp-chat-disclaimer {
  text-align: center;
  font-size: 10.5px;
  color: #94a3b8;
  margin-top: 6px;
  user-select: none;
}

/* ==========================================================================
   Mobile Responsive Behavior (< 480px)
   ========================================================================== */
@media (max-width: 480px) {
  .cp-chat-launcher {
    bottom: 16px;
    right: 16px;
    width: 54px;
    height: 54px;
  }

  .cp-chat-window {
    bottom: 0;
    right: 0;
    width: 100vw;
    height: 100%;
    max-width: 100vw;
    max-height: 100%;
    border-radius: 0;
    border: none;
  }

  .cp-chat-header {
    padding: 14px 16px;
    border-radius: 0;
  }
}
