/* ==========================================================================
   Community Inclusion Program - Floating AI Chat Widget Styles
   Palette: Trust Navy (#1A365D), Amber (#d97706), Soft Linen (#fcfbf9)
   Mobile-First & High-DPI Optimized
   ========================================================================== */

#cip-chat-widget {
  position: fixed !important;
  bottom: 24px !important;
  right: 24px !important;
  z-index: 2147483647 !important;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif !important;
  color: #1e293b !important;
  -webkit-font-smoothing: antialiased !important;
  transition: bottom 0.35s cubic-bezier(0.16, 1, 0.3, 1), transform 0.35s ease !important;
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
}

/* Rise above Donorbox popup when active */
#cip-chat-widget.cip-rise-above-donorbox,
body:has(.dbox-reminder-widget--show) #cip-chat-widget {
  bottom: 114px !important;
}

/* Floating Launcher Button */
.cip-chat-launcher {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: linear-gradient(135deg, #1A365D 0%, #2563eb 100%);
  box-shadow: 0 8px 24px rgba(26, 54, 93, 0.38), 0 2px 6px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: 3px solid #ffffff;
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.25s ease;
  position: relative;
  user-select: none;
}

.cip-chat-launcher:hover {
  transform: scale(1.08);
  box-shadow: 0 12px 28px rgba(26, 54, 93, 0.48);
}

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

.cip-launcher-avatar {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: block;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.cip-launcher-online-dot {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 14px;
  height: 14px;
  background-color: #22c55e;
  border: 2.5px solid #ffffff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  z-index: 2;
}

.cip-chat-launcher svg.icon-close {
  width: 26px;
  height: 26px;
  fill: #ffffff;
  display: none;
  transition: transform 0.25s ease;
}

.cip-chat-launcher.is-open .cip-launcher-avatar {
  display: none;
}

.cip-chat-launcher.is-open .cip-launcher-online-dot {
  display: none;
}

.cip-chat-launcher.is-open svg.icon-close {
  display: block;
}

.cip-chat-launcher.is-open {
  background: #1e293b;
}

/* Teaser / Greeting Bubble */
.cip-chat-teaser {
  position: absolute;
  bottom: 72px;
  right: 0;
  background: #ffffff;
  color: #0f172a;
  padding: 10px 16px;
  border-radius: 14px;
  border-bottom-right-radius: 4px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12), 0 1px 3px rgba(0, 0, 0, 0.05);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  border: 1px solid #f1f5f9;
  animation: cipBounce 3s infinite;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.cip-chat-teaser::after {
  content: '';
  position: absolute;
  bottom: -6px;
  right: 22px;
  width: 12px;
  height: 12px;
  background: #ffffff;
  transform: rotate(45deg);
  border-right: 1px solid #f1f5f9;
  border-bottom: 1px solid #f1f5f9;
}

.cip-chat-teaser-dot {
  width: 8px;
  height: 8px;
  background: #10b981;
  border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
}

@keyframes cipBounce {
  0%, 20%, 50%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-5px); }
  60% { transform: translateY(-2px); }
}

/* Chat Window Modal */
.cip-chat-window {
  position: absolute;
  bottom: 76px;
  right: 0;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 580px;
  max-height: calc(100vh - 110px);
  background: #ffffff;
  border-radius: 18px;
  box-shadow: 0 16px 48px rgba(15, 23, 42, 0.22), 0 2px 8px rgba(0, 0, 0, 0.06);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid #e2e8f0;
  opacity: 0;
  transform: translateY(20px) scale(0.96);
  pointer-events: none;
  transition: opacity 0.28s cubic-bezier(0.16, 1, 0.3, 1), transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}

.cip-chat-window.is-active {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* Header */
.cip-chat-header,
#cip-chat-widget .cip-chat-header {
  background: linear-gradient(135deg, #1A365D 0%, #1e40af 100%) !important;
  color: #ffffff !important;
  padding: 16px 18px !important;
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08) !important;
}

.cip-chat-header-profile,
#cip-chat-widget .cip-chat-header-profile {
  display: flex !important;
  align-items: center !important;
  gap: 12px !important;
}

.cip-chat-avatar,
#cip-chat-widget .cip-chat-avatar {
  width: 44px !important;
  height: 44px !important;
  border-radius: 50% !important;
  background: #ffffff !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2) !important;
  overflow: hidden !important;
  flex-shrink: 0 !important;
  border: 2px solid rgba(255, 255, 255, 0.8) !important;
}

.cip-chat-avatar img,
#cip-chat-widget .cip-chat-avatar img {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
  display: block !important;
}

.cip-chat-header-info,
#cip-chat-widget .cip-chat-header-info {
  color: #ffffff !important;
}

.cip-chat-header-info h3,
.cip-chat-header-info h3 *,
#cip-chat-widget .cip-chat-header-info h3,
:not(#tve) #cip-chat-widget .cip-chat-header-info h3 {
  margin: 0 !important;
  font-size: 15px !important;
  font-weight: 700 !important;
  line-height: 1.2 !important;
  letter-spacing: -0.01em !important;
  color: #ffffff !important;
  -webkit-text-fill-color: #ffffff !important;
}

.cip-chat-header-info p,
.cip-chat-header-info p *,
#cip-chat-widget .cip-chat-header-info p,
:not(#tve) #cip-chat-widget .cip-chat-header-info p {
  margin: 3px 0 0 0 !important;
  font-size: 12px !important;
  opacity: 0.95 !important;
  display: flex !important;
  align-items: center !important;
  gap: 6px !important;
  color: #f1f5f9 !important;
  -webkit-text-fill-color: #f1f5f9 !important;
}

.cip-chat-status-indicator {
  width: 8px !important;
  height: 8px !important;
  background: #22c55e !important;
  border-radius: 50% !important;
  display: inline-block !important;
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.35) !important;
}

.cip-chat-header-actions,
#cip-chat-widget .cip-chat-header-actions {
  display: flex !important;
  align-items: center !important;
  gap: 4px !important;
}

.cip-chat-header-actions button,
#cip-chat-widget .cip-chat-header-actions button {
  background: transparent !important;
  border: none !important;
  color: #ffffff !important;
  cursor: pointer !important;
  padding: 6px !important;
  border-radius: 8px !important;
  transition: background 0.15s ease, color 0.15s ease !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}

.cip-chat-header-actions button svg,
#cip-chat-widget .cip-chat-header-actions button svg {
  fill: #ffffff !important;
  color: #ffffff !important;
}

.cip-chat-header-actions button:hover,
#cip-chat-widget .cip-chat-header-actions button:hover {
  background: rgba(255, 255, 255, 0.2) !important;
  color: #ffffff !important;
}

/* Messages Body */
.cip-chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px;
  background: #fdfbf7;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

/* Speech Bubbles */
.cip-message {
  display: flex;
  flex-direction: column;
  max-width: 84%;
  animation: cipFadeIn 0.25s ease-out forwards;
}

@keyframes cipFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.cip-message.assistant {
  align-self: flex-start;
}

.cip-message.user {
  align-self: flex-end;
}

.cip-bubble {
  padding: 12px 16px;
  font-size: 14px;
  line-height: 1.5;
  border-radius: 16px;
  word-break: break-word;
}

.cip-message.assistant .cip-bubble {
  background: #ffffff;
  color: #1e293b;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
  border: 1px solid #f1f5f9;
}

.cip-message.user .cip-bubble {
  background: #1A365D;
  color: #ffffff;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 6px rgba(26, 54, 93, 0.2);
}

.cip-message-time {
  font-size: 10px;
  color: #94a3b8;
  margin-top: 4px;
  padding: 0 4px;
}

.cip-message.user .cip-message-time {
  align-self: flex-end;
}

/* Quick Action Suggestion Chips */
.cip-quick-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}

.cip-chip {
  background: #ffffff;
  color: #1A365D;
  border: 1px solid #cbd5e1;
  padding: 7px 12px;
  border-radius: 9999px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  box-shadow: 0 1px 2px rgba(0,0,0,0.03);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.cip-chip:hover {
  background: #1A365D;
  color: #ffffff;
  border-color: #1A365D;
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(26, 54, 93, 0.25);
}

/* Typing Indicator */
.cip-typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  background: #ffffff;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  border: 1px solid #f1f5f9;
  width: fit-content;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.cip-typing-indicator span {
  width: 6px;
  height: 6px;
  background: #94a3b8;
  border-radius: 50%;
  animation: cipDot 1.4s infinite ease-in-out;
}

.cip-typing-indicator span:nth-child(1) { animation-delay: 0s; }
.cip-typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.cip-typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes cipDot {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1.1); opacity: 1; }
}

/* Inline Contact / Lead Capture Card */
.cip-lead-card {
  background: #ffffff;
  border-radius: 14px;
  padding: 16px;
  border: 1px solid #e2e8f0;
  border-top: 3px solid #d97706;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.05);
  margin-top: 4px;
}

.cip-lead-card h4 {
  margin: 0 0 6px 0;
  font-size: 14px;
  color: #1A365D;
  font-weight: 700;
}

.cip-lead-card p {
  margin: 0 0 12px 0;
  font-size: 12px;
  color: #64748b;
  line-height: 1.4;
}

.cip-form-group {
  margin-bottom: 10px;
}

.cip-form-group label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: #475569;
  margin-bottom: 4px;
}

.cip-form-input, .cip-form-select {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 13px;
  color: #0f172a;
  background: #f8fafc;
  outline: none;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.cip-form-input:focus, .cip-form-select:focus {
  border-color: #2563eb;
  background: #ffffff;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.cip-btn-submit {
  width: 100%;
  background: linear-gradient(135deg, #d97706 0%, #b45309 100%);
  color: #ffffff;
  border: none;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 8px;
}

.cip-btn-submit:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(217, 119, 6, 0.35);
}

.cip-btn-submit:active {
  transform: translateY(0);
}

.cip-btn-submit:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

/* Chat Footer / Input Bar */
.cip-chat-footer {
  padding: 12px 14px;
  background: #ffffff;
  border-top: 1px solid #f1f5f9;
  display: flex;
  align-items: center;
  gap: 8px;
}

.cip-chat-input {
  flex: 1;
  border: 1px solid #e2e8f0;
  border-radius: 20px;
  padding: 9px 14px;
  font-size: 14px;
  color: #0f172a;
  background: #f8fafc;
  outline: none;
  resize: none;
  max-height: 80px;
  line-height: 1.4;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.cip-chat-input:focus {
  border-color: #2563eb;
  background: #ffffff;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.12);
}

.cip-chat-send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #1A365D;
  color: #ffffff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.15s ease, background 0.15s ease;
}

.cip-chat-send-btn:hover {
  background: #2563eb;
  transform: scale(1.05);
}

.cip-chat-send-btn:active {
  transform: scale(0.95);
}

.cip-chat-send-btn:disabled {
  background: #cbd5e1;
  cursor: not-allowed;
  transform: none;
}

.cip-chat-send-btn svg {
  width: 16px;
  height: 16px;
  fill: #ffffff;
  margin-left: 2px;
}

/* Mobile Responsiveness */
@media (max-width: 480px) {
  #cip-chat-widget {
    bottom: max(16px, env(safe-area-inset-bottom));
    right: max(16px, env(safe-area-inset-right));
  }

  #cip-chat-widget.cip-rise-above-donorbox,
  body:has(.dbox-reminder-widget--show) #cip-chat-widget {
    bottom: max(96px, calc(env(safe-area-inset-bottom) + 90px)) !important;
  }

  .cip-chat-window {
    bottom: 68px;
    right: 0;
    width: calc(100vw - 24px);
    height: 82vh;
    max-height: 580px;
    border-radius: 16px;
  }

  .cip-chat-launcher {
    width: 54px;
    height: 54px;
  }

  .cip-chat-teaser {
    display: none; /* Hide teaser bubble on small mobile screens to prevent clutter */
  }
}
