/* ==========================================================================
   UDARAX AI CHAT WIDGET STYLES
   Floating Launcher & Interactive Conversational Dialog Window
   ========================================================================== */

/* --- Floating Circular Launcher Button --- */
.udarax-chat-launcher {
  position: fixed !important;
  bottom: 26px !important;
  right: 26px !important;
  z-index: 99999 !important;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #303644 0%, #1a1e28 100%);
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.28), 0 3px 8px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #ffffff;
  padding: 0;
  outline: none;
  transition: transform 0.22s cubic-bezier(0.16, 1, 0.3, 1),
              box-shadow 0.22s ease,
              background 0.22s ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.udarax-chat-launcher:hover {
  transform: scale(1.06);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.36), 0 4px 10px rgba(0, 0, 0, 0.2);
}

.udarax-chat-launcher:active {
  transform: scale(0.95);
}

/* Chat & Close Icons within Launcher */
.udarax-chat-launcher .icon-chat,
.udarax-chat-launcher .icon-close {
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.18s ease;
}

.udarax-chat-launcher .icon-chat {
  opacity: 1;
  transform: scale(1) rotate(0deg);
}

.udarax-chat-launcher .icon-close {
  display: none;
  opacity: 0;
  transform: scale(0.7) rotate(-90deg);
  font-size: 1.25rem;
}

/* State when Chat Window is Open */
.udarax-chat-launcher.is-active .icon-chat {
  display: none;
  opacity: 0;
  transform: scale(0.7) rotate(90deg);
}

.udarax-chat-launcher.is-active .icon-close {
  display: flex;
  opacity: 1;
  transform: scale(1) rotate(0deg);
}

/* Unread Notification Badge Dot */
.udarax-chat-launcher .launcher-badge {
  position: absolute;
  top: 1px;
  right: 1px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background-color: #ff5500;
  border: 2.5px solid #ffffff;
  box-shadow: 0 0 8px rgba(255, 85, 0, 0.6);
  pointer-events: none;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.udarax-chat-launcher.has-opened .launcher-badge,
.udarax-chat-launcher.is-active .launcher-badge {
  transform: scale(0);
  opacity: 0;
}

/* --- Expandable Chat Dialog Window --- */
.udarax-chat-window {
  position: fixed !important;
  bottom: 94px !important;
  right: 26px !important;
  z-index: 99998 !important;
  width: 375px;
  max-width: calc(100vw - 32px);
  height: 540px;
  max-height: calc(100vh - 120px);
  border-radius: 20px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background-color: #f8f9fb;
  border: 1px solid var(--border-medium);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.2), 0 6px 18px rgba(0, 0, 0, 0.08);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(18px) scale(0.96);
  transform-origin: bottom right;
  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;
}

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

/* Dark Theme Overrides for Dialog */
[data-theme="dark"] .udarax-chat-window {
  background-color: #0e121a;
  border-color: #242938;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6), 0 6px 18px rgba(0, 0, 0, 0.35);
}

/* --- Dialog Header (Dark Header Bar) --- */
.udarax-chat-window .chat-header {
  background: #090c13;
  color: #ffffff;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.udarax-chat-window .chat-header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.udarax-chat-window .chat-header-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ff6e1a 0%, #ff5500 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 10px rgba(255, 85, 0, 0.35);
}

.udarax-chat-window .chat-header-avatar img {
  width: 22px;
  height: 22px;
  object-fit: contain;
  filter: brightness(0) invert(1);
}

.udarax-chat-window .chat-header-info {
  display: flex;
  flex-direction: column;
}

.udarax-chat-window .chat-header-title {
  font-family: var(--font-display-tech);
  font-weight: 700;
  font-size: 1.05rem;
  line-height: 1.2;
  color: #ffffff;
  margin: 0;
  letter-spacing: -0.01em;
}

.udarax-chat-window .chat-header-status {
  font-size: 0.74rem;
  color: #94a3b8;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
  font-weight: 500;
}

.udarax-chat-window .chat-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: #10b981;
  box-shadow: 0 0 6px rgba(16, 185, 129, 0.6);
  display: inline-block;
  animation: pulseChatDot 2s infinite ease-in-out;
}

@keyframes pulseChatDot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.55; transform: scale(0.9); }
}

.udarax-chat-window .chat-close-btn {
  background: transparent;
  border: none;
  color: #94a3b8;
  font-size: 1.1rem;
  padding: 4px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, background 0.15s;
  outline: none;
}

.udarax-chat-window .chat-close-btn:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.08);
}

/* --- Consultative Scoping Ribbon --- */
.udarax-chat-window .chat-scoping-ribbon {
  background: linear-gradient(90deg, #101520 0%, #161e2e 100%);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding: 7px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
  font-size: 0.74rem;
}

.udarax-chat-window .scoping-ribbon-content {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #e2e8f0;
  font-weight: 500;
}

.udarax-chat-window .scoping-ribbon-sparkle {
  font-size: 0.8rem;
  line-height: 1;
}

.udarax-chat-window .scoping-ribbon-link {
  color: #ff8533;
  text-decoration: none;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  white-space: nowrap;
  transition: color 0.15s ease, transform 0.15s ease;
}

.udarax-chat-window .scoping-ribbon-link:hover {
  color: #ffa366;
  transform: translateX(2px);
}

/* --- In-Chat Lead Confirmation Badge Card --- */
.chat-lead-badge-card {
  margin: 2px 0 6px 44px;
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.1) 0%, rgba(16, 185, 129, 0.03) 100%);
  border: 1px solid rgba(16, 185, 129, 0.35);
  border-radius: 12px;
  padding: 9px 13px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  animation: leadBadgeSlideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

[data-theme="dark"] .chat-lead-badge-card {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.14) 0%, rgba(16, 185, 129, 0.05) 100%);
  border-color: rgba(16, 185, 129, 0.45);
}

.chat-lead-badge-card .lead-badge-icon {
  color: #10b981;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}

.chat-lead-badge-card .lead-badge-content {
  flex: 1;
}

.chat-lead-badge-card .lead-badge-title {
  font-size: 0.79rem;
  font-weight: 700;
  color: #065f46;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

[data-theme="dark"] .chat-lead-badge-card .lead-badge-title {
  color: #34d399;
}

.chat-lead-badge-card .lead-ref-tag {
  font-family: var(--font-mono, monospace);
  font-size: 0.69rem;
  background: rgba(16, 185, 129, 0.2);
  color: #047857;
  padding: 1px 6px;
  border-radius: 4px;
  font-weight: 600;
}

[data-theme="dark"] .chat-lead-badge-card .lead-ref-tag {
  color: #a7f3d0;
  background: rgba(16, 185, 129, 0.25);
}

.chat-lead-badge-card .lead-badge-sub {
  font-size: 0.71rem;
  color: #047857;
  margin-top: 2px;
  line-height: 1.35;
}

[data-theme="dark"] .chat-lead-badge-card .lead-badge-sub {
  color: #a7f3d0;
}

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

/* --- Messages Container --- */
.udarax-chat-window .chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

/* Custom Scrollbar */
.udarax-chat-window .chat-messages::-webkit-scrollbar {
  width: 5px;
}
.udarax-chat-window .chat-messages::-webkit-scrollbar-track {
  background: transparent;
}
.udarax-chat-window .chat-messages::-webkit-scrollbar-thumb {
  background-color: rgba(148, 163, 184, 0.4);
  border-radius: 10px;
}
.udarax-chat-window .chat-messages::-webkit-scrollbar-thumb:hover {
  background-color: rgba(148, 163, 184, 0.7);
}

/* Message Rows */
.chat-msg-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  max-width: 100%;
  animation: chatMsgFadeIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

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

/* Assistant Message */
.chat-msg-row.is-assistant {
  align-self: flex-start;
}

.chat-msg-row.is-assistant .chat-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ff6e1a 0%, #ff5500 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
  box-shadow: 0 1px 4px rgba(255, 85, 0, 0.25);
}

.chat-msg-row.is-assistant .chat-msg-avatar img {
  width: 16px;
  height: 16px;
  object-fit: contain;
  filter: brightness(0) invert(1);
}

.chat-msg-row.is-assistant .chat-msg-bubble {
  background-color: #ffffff;
  color: #1e293b;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 16px;
  border-top-left-radius: 4px;
  padding: 12px 14px;
  font-size: 0.88rem;
  line-height: 1.54;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.02);
  max-width: 82%;
}

[data-theme="dark"] .chat-msg-row.is-assistant .chat-msg-bubble {
  background-color: #161b26;
  color: #e2e8f0;
  border-color: rgba(255, 255, 255, 0.08);
}

/* User Message */
.chat-msg-row.is-user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.chat-msg-row.is-user .chat-user-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #090c13;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
  font-size: 0.75rem;
}

[data-theme="dark"] .chat-msg-row.is-user .chat-user-avatar {
  background: #242a38;
}

.chat-msg-row.is-user .chat-msg-bubble {
  background-color: #090c13;
  color: #ffffff;
  border-radius: 16px;
  border-top-right-radius: 4px;
  padding: 9px 14px;
  font-size: 0.88rem;
  line-height: 1.45;
  max-width: 78%;
  word-break: break-word;
}

[data-theme="dark"] .chat-msg-row.is-user .chat-msg-bubble {
  background-color: #222838;
  color: #ffffff;
}

/* Typing Indicator Animation */
.chat-typing-bubble {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px !important;
}

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

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

@keyframes chatTypingBounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; }
  40% { transform: scale(1); opacity: 1; }
}

/* --- Footer Input Area --- */
.udarax-chat-window .chat-input-area {
  padding: 12px 14px;
  background-color: #ffffff;
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

[data-theme="dark"] .udarax-chat-window .chat-input-area {
  background-color: #111520;
  border-color: #202432;
}

.udarax-chat-window .chat-input-pill {
  display: flex;
  align-items: center;
  background-color: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 9999px;
  padding: 4px 6px 4px 16px;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background-color 0.18s ease;
}

.udarax-chat-window .chat-input-pill:focus-within {
  border-color: #ff5500;
  background-color: #ffffff;
  box-shadow: 0 0 0 2px rgba(255, 85, 0, 0.12);
}

[data-theme="dark"] .udarax-chat-window .chat-input-pill {
  background-color: #171b26;
  border-color: #262c3e;
}

[data-theme="dark"] .udarax-chat-window .chat-input-pill:focus-within {
  border-color: #ff6822;
  background-color: #1a202e;
  box-shadow: 0 0 0 2px rgba(255, 104, 34, 0.18);
}

.udarax-chat-window .chat-input-field {
  flex: 1;
  border: none;
  background: transparent;
  outline: none;
  font-size: 0.88rem;
  color: var(--text-primary);
  font-family: var(--font-sans);
  padding: 6px 0;
}

.udarax-chat-window .chat-input-field::placeholder {
  color: #94a3b8;
  font-size: 0.88rem;
}

.udarax-chat-window .chat-send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #f59656 0%, #ea7a32 100%);
  color: #ffffff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(234, 122, 50, 0.35);
  transition: transform 0.15s ease, opacity 0.15s ease, background 0.15s ease;
  outline: none;
}

.udarax-chat-window .chat-send-btn:hover {
  transform: scale(1.05);
  background: linear-gradient(135deg, #f8a164 0%, #eb813d 100%);
}

.udarax-chat-window .chat-send-btn:active {
  transform: scale(0.94);
}

.udarax-chat-window .chat-send-btn svg {
  transform: translate(-1px, 1px);
}

/* --- Suggested Quick Prompt Chips --- */
.chat-suggested-prompts {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px 0 8px 38px;
  animation: chatMsgFadeIn 0.3s ease;
}

.chat-prompt-pill {
  background: var(--bg-surface, #ffffff);
  border: 1px solid var(--border-subtle, #e2e8f0);
  border-radius: 9999px;
  padding: 5px 12px;
  font-size: 0.76rem;
  font-family: var(--font-sans);
  font-weight: 500;
  color: var(--text-secondary, #475569);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  white-space: nowrap;
}

.chat-prompt-pill:hover {
  border-color: #ff5500;
  color: #ff5500;
  background-color: rgba(255, 85, 0, 0.04);
  transform: translateY(-1px);
}

[data-theme="dark"] .chat-prompt-pill {
  background: #151a24;
  border-color: #242c3c;
  color: #cbd5e1;
}

[data-theme="dark"] .chat-prompt-pill:hover {
  background: rgba(255, 85, 0, 0.12);
  border-color: rgba(255, 85, 0, 0.4);
  color: #ff8533;
}

/* --- Formatted Markdown Inside Chat Bubbles --- */
.chat-msg-bubble p {
  margin: 0 0 0.5rem;
}

.chat-msg-bubble p:last-child {
  margin-bottom: 0;
}

.chat-msg-bubble ul,
.chat-msg-bubble ol {
  margin: 0.4rem 0 0.5rem 1.15rem;
  padding: 0;
}

.chat-msg-bubble li {
  margin-bottom: 0.25rem;
}

.chat-msg-bubble a {
  color: #ff5500;
  text-decoration: underline;
  font-weight: 600;
}

.chat-msg-bubble a:hover {
  color: #ea580c;
}

.chat-msg-bubble code {
  font-family: var(--font-mono, monospace);
  font-size: 0.8rem;
  background: rgba(0, 0, 0, 0.07);
  padding: 2px 5px;
  border-radius: 4px;
}

[data-theme="dark"] .chat-msg-bubble code {
  background: rgba(255, 255, 255, 0.12);
  color: #f8fafc;
}

/* --- Mobile Responsiveness --- */
@media (max-width: 480px) {
  .udarax-chat-launcher {
    bottom: 18px;
    right: 18px;
    width: 54px;
    height: 54px;
  }

  .udarax-chat-window {
    bottom: 82px;
    right: 12px;
    left: 12px;
    width: auto;
    max-width: calc(100vw - 24px);
    height: calc(100dvh - 100px);
    max-height: 580px;
    border-radius: 18px;
  }
}
