/* Chat Widget Styles */
#wpai-chat-widget {
  position: fixed;
  bottom: 20px;
  z-index: 9999;
  --wpai-theme: #160211;
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu,
    Cantarell, sans-serif;
}

#wpai-chat-widget.wpai-pos-right {
  right: 20px !important;
  left: auto !important;
}

#wpai-chat-widget.wpai-pos-left {
  left: 20px !important;
  right: auto !important;
}

.wpai-widget-label {
  position: absolute;
  bottom: 68px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10000;
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
  display: inline-flex !important;
  align-items: center;
  gap: 6px;
  background: #ffffff !important;
  border: 1px solid #e5e7eb !important;
  box-shadow: 0 8px 22px -16px rgba(15, 23, 42, 0.45);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.2px;
  padding: 8px 12px;
  white-space: nowrap;
  color: var(--wpai-theme) !important;
  pointer-events: none;
  text-shadow: 0 0 0 rgba(15, 23, 42, 0.25);
  animation: wpaiLabelPulse 1.9s ease-in-out infinite;
  border-radius: 999px;
}

#wpai-chat-widget.wpai-pos-right .wpai-widget-label {
  left: auto;
  right: 0;
  transform: translateX(-92%);
  transform-origin: right center;
}

#wpai-chat-widget.wpai-pos-left .wpai-widget-label {
  right: auto;
  left: 0;
  transform: translateX(92%);
  transform-origin: left center;
}

#wpai-chat-widget.wpai-pos-right .wpai-widget-label::after,
#wpai-chat-widget.wpai-pos-left .wpai-widget-label::after {
  content: "";
  position: absolute;
  bottom: -6px;
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 6px solid #ffffff;
  filter: drop-shadow(0 -1px 0 rgba(229, 231, 235, 0.9));
}

#wpai-chat-widget.wpai-pos-right .wpai-widget-label::after {
  right: 14px;
}

#wpai-chat-widget.wpai-pos-left .wpai-widget-label::after {
  left: 14px;
}

#wpai-chat-widget.wpai-open .wpai-widget-label {
  display: none !important;
}

.wpai-label-emoji {
  display: inline-block;
  animation: wpaiEmojiWave 1.8s ease-in-out infinite;
  transform-origin: 70% 70%;
}

.wpai-widget-label.is-rolling {
  animation: wpaiLabelSwap 0.45s ease;
}

@keyframes wpaiRainbowSweep {
  0% {
    background-position: 0% 50%;
  }
  100% {
    background-position: 220% 50%;
  }
}

/* Keep label plain and always visible for cross-browser reliability. */

/* Floating Button */
#wpai-chat-button {
  width: 60px;
  height: 60px;
  background: var(--wpai-theme);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 6px 24px rgba(15, 23, 42, 0.3);
  transition: all 0.3s ease;
  animation: pulse 2s infinite;
}

#wpai-chat-button:hover {
  transform: scale(1.1);
  filter: brightness(1.08);
  box-shadow: 0 8px 32px rgba(15, 23, 42, 0.35);
}

.wpai-bubble-icon {
  width: 26px;
  height: 26px;
  object-fit: contain;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.12);
  padding: 2px;
}

@keyframes wpaiLabelPulse {
  0%,
  100% {
    transform: translateX(-50%) translateY(0) scale(1);
    opacity: 0.9;
    text-shadow: 0 0 0 rgba(22, 2, 17, 0.2);
  }

  50% {
    transform: translateX(-50%) translateY(-2px) scale(1.045);
    opacity: 1;
    text-shadow: 0 2px 8px rgba(22, 2, 17, 0.28);
  }
}

@keyframes wpaiEmojiWave {
  0%,
  100% {
    transform: rotate(0deg);
  }
  30% {
    transform: rotate(12deg);
  }
  60% {
    transform: rotate(-6deg);
  }
}

@keyframes wpaiLabelSwap {
  0% {
    opacity: 0;
    transform: translateY(2px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {

  0%,
  100% {
    box-shadow: 0 4px 20px rgba(15, 23, 42, 0.3);
  }

  50% {
    box-shadow:
      0 4px 30px rgba(15, 23, 42, 0.5),
      0 0 0 10px rgba(15, 23, 42, 0.12);
  }
}

/* Chat Box */
#wpai-chat-box {
  position: fixed;
  bottom: 80px;
  width: 380px;
  height: 450px;
  max-height: calc(100vh - 100px);
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  animation: slideUp 0.3s ease;
}

#wpai-chat-widget.wpai-pos-right #wpai-chat-box {
  right: 20px !important;
  left: auto !important;
}

#wpai-chat-widget.wpai-pos-left #wpai-chat-box {
  left: 20px !important;
  right: auto !important;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Header */
.wpai-chat-header {
  background: var(--wpai-theme);
  padding: 16px 20px;
  border-radius: 16px 16px 0 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: none;
}

.wpai-header-actions {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

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

.wpai-assistant-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.wpai-assistant-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  overflow: hidden;
  background: #f0f0f0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--wpai-theme);
}

.wpai-assistant-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.wpai-assistant-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--wpai-theme-contrast);
}

.wpai-live-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.wpai-live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #19a34a;
  box-shadow: 0 0 0 rgba(25, 163, 74, 0.5);
  animation: wpaiLivePulse 1.8s infinite;
}

.wpai-live-text {
  font-size: 12px;
  font-weight: 500;
  color: var(--wpai-theme-contrast);
  opacity: 0.9;
}

@keyframes wpaiLivePulse {
  0% {
    box-shadow: 0 0 0 0 rgba(25, 163, 74, 0.45);
  }
  70% {
    box-shadow: 0 0 0 8px rgba(25, 163, 74, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(25, 163, 74, 0);
  }
}

/* Sub Header */
.wpai-chat-subheader {
  background: linear-gradient(135deg, #ffffff 0%, #f8f8f8 100%);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid #b9b9b9;
}

.wpai-sparkle-icon {
  width: 36px;
  height: 36px;
  background: #ffffff;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(22, 2, 17, 0.1);
}

.wpai-chat-subheader h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: #160211;
}

#wpai-close-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  border-radius: 6px;
  transition: background 0.2s;
}

#wpai-minimize-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  border-radius: 6px;
  transition: background 0.2s;
}

#wpai-close-btn:hover,
#wpai-minimize-btn:hover {
  background: rgba(255, 255, 255, 0.16);
}

.wpai-chat-header svg path {
  stroke: var(--wpai-theme-contrast);
}

#wpai-chat-box.wpai-chat-minimized {
  height: auto;
  max-height: none;
}

#wpai-chat-box.wpai-chat-minimized .wpai-messages-container,
#wpai-chat-box.wpai-chat-minimized .wpai-input-container {
  display: none;
}

#wpai-chat-box.wpai-chat-minimized .wpai-chat-header {
  border-bottom: none;
  border-radius: 16px;
}

/* Messages Container */
.wpai-messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  background: linear-gradient(180deg, #ffffff 0%, #f9f9f9 100%);
}

/* Input Container */
.wpai-input-container {
  padding: 16px 20px;
  background: #ffffff;
  border-top: 1px solid #b9b9b9;
  border-radius: 0 0 16px 16px;
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

#wpai-upload-btn {
  width: 36px;
  height: 36px;
  background: transparent;
  border: none;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
  padding: 0;
  position: relative;
}

#wpai-upload-btn:hover {
  background: #f0f0f0;
}

#wpai-upload-btn.wpai-has-file {
  background: #eaf3ff;
}

#wpai-upload-btn.wpai-has-file::after {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #19a34a;
  position: absolute;
  top: 3px;
  right: 3px;
}

.wpai-upload-state {
  display: none;
  max-width: 90px;
  font-size: 11px;
  color: #4b5563;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  align-self: center;
}

.wpai-upload-state.is-visible {
  display: inline-block;
}

#wpai-message-input {
  flex: 1;
  border: 2px solid #b9b9b9;
  border-radius: 10px;
  padding: 9px 13px 9px 15px;
  font-size: 14px;
  color: #160211;
  outline: none;
  transition: all 0.3s ease;
  resize: none;
  min-height: 40px;
  max-height: 80px;
  overflow: hidden;
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu,
    Cantarell, sans-serif;
  line-height: 1.4;
}

#wpai-message-input.typing {
  border-color: var(--wpai-theme);
  animation: borderPulse 2s ease-in-out infinite;
}

@keyframes borderPulse {

  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(22, 2, 17, 0.4);
  }

  50% {
    box-shadow: 0 0 0 8px rgba(22, 2, 17, 0);
  }
}

#wpai-message-input.scrollable {
  overflow-y: auto;
}

#wpai-message-input:focus {
  border-color: var(--wpai-theme);
}

#wpai-message-input::placeholder {
  color: #aaaaaa;
}

#wpai-send-btn {
  width: 36px;
  height: 36px;
  background: var(--wpai-theme);
  border: none;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
  padding: 0;
}

#wpai-send-btn:hover {
  filter: brightness(1.08);
  transform: scale(1.05);
}

#wpai-send-btn svg {
  width: 18px;
  height: 18px;
}

#wpai-send-btn svg path {
  stroke: var(--wpai-theme-contrast);
}

#wpai-upload-btn svg {
  width: 18px;
  height: 18px;
}

/* Scrollbar for textarea */
#wpai-message-input.scrollable::-webkit-scrollbar {
  width: 8px;
}

#wpai-message-input.scrollable::-webkit-scrollbar-track {
  background: #F5F5F5;
  border-radius: 4px;
  margin: 6px 4px 6px 0;
}

#wpai-message-input.scrollable::-webkit-scrollbar-thumb {
  background: #B9B9B9;
  border-radius: 4px;
}

#wpai-message-input.scrollable::-webkit-scrollbar-thumb:hover {
  background: #606060;
}

/* Scrollbar for messages */
.wpai-messages-container::-webkit-scrollbar {
  width: 6px;
}

.wpai-messages-container::-webkit-scrollbar-track {
  background: transparent;
}

.wpai-messages-container::-webkit-scrollbar-thumb {
  background: #b9b9b9;
  border-radius: 3px;
}

.wpai-messages-container::-webkit-scrollbar-thumb:hover {
  background: #606060;
}

/* Responsive */
@media (max-width: 480px) {
  #wpai-chat-box {
    width: calc(100vw - 20px);
    height: calc(100vh - 100px);
    max-height: calc(100vh - 100px);
    bottom: 10px;
  }

  /* Target the widget container for mobile positioning */
  #wpai-chat-widget.wpai-pos-right {
    right: 10px !important;
    left: auto !important;
    bottom: 10px;
  }

  #wpai-chat-widget.wpai-pos-left {
    left: 10px !important;
    right: auto !important;
    bottom: 10px;
  }

  .wpai-widget-label {
    bottom: 66px;
    font-size: 11px;
    padding: 0;
  }

  /* Ensure the box aligns with the widget corner on mobile */
  #wpai-chat-widget.wpai-pos-right #wpai-chat-box {
    right: 10px !important;
    left: auto !important;
  }

  #wpai-chat-widget.wpai-pos-left #wpai-chat-box {
    left: 10px !important;
    right: auto !important;
  }
}

@media (max-height: 600px) {
  #wpai-chat-box {
    height: calc(100vh - 100px);
    max-height: calc(100vh - 100px);
  }
}

/* Message Bubbles */
.wpai-message {
  margin-bottom: 16px;
  display: flex;
}

.wpai-message-user {
  justify-content: flex-end;
}

.wpai-message-bot {
  justify-content: flex-start;
}

.wpai-message-bubble {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
  white-space: pre-line;
}

.wpai-message-user .wpai-message-bubble {
  background: var(--wpai-theme);
  color: #ffffff;
  border-bottom-right-radius: 4px;
}

.wpai-message-bot .wpai-message-bubble {
  background: #f0f0f0;
  color: #160211;
  border-bottom-left-radius: 4px;
}

.wpai-message-bot .wpai-message-bubble.wpai-product-cards-bubble {
  max-width: 96%;
  width: 96%;
  background: transparent;
  padding: 0;
  box-shadow: none;
}

/* Typing Indicator */
.wpai-typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  background: #f0f0f0;
  border-radius: 12px;
  border-bottom-left-radius: 4px;
  width: fit-content;
  margin-bottom: 16px;
}

.wpai-typing-indicator span {
  width: 8px;
  height: 8px;
  background: #606060;
  border-radius: 50%;
  animation: typing 1.4s infinite;
}

.wpai-typing-indicator span:nth-child(2) {
  animation-delay: 0.2s;
}

.wpai-typing-indicator span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing {

  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.7;
  }

  30% {
    transform: translateY(-10px);
    opacity: 1;
  }
}

/* Product Links and Images */
.wpai-message-bubble a {
  color: var(--wpai-theme);
  text-decoration: underline;
  font-weight: 600;
}

.wpai-message-user .wpai-message-bubble a {
  color: #ffffff;
}

.wpai-message-bubble a:hover {
  color: var(--wpai-theme);
  filter: brightness(1.05);
}

.wpai-message-user .wpai-message-bubble a:hover {
  color: #ffffff;
  opacity: 0.9;
}

.wpai-message-bubble img {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  margin: 8px 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Quick Prompts */
.wpai-quick-prompts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.wpai-quick-prompt-btn {
  border: 1px solid #b9b9b9;
  background: #ffffff;
  color: #000000 !important;
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: 0.1px;
  text-shadow: none;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  cursor: pointer;
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

#wpai-chat-widget .wpai-quick-prompt-btn:hover,
#wpai-chat-widget .wpai-quick-prompt-btn:focus-visible,
#wpai-chat-widget .wpai-quick-prompt-btn:active {
  border-color: #000000 !important;
  background: #000000 !important;
  color: #ffffff !important;
  transform: none !important;
  opacity: 1 !important;
  filter: none !important;
}
