/**
 * Assistify for WooCommerce - Frontend Styles
 *
 * Customer chat widget styling with modern design.
 *
 * @package Assistify_For_WooCommerce
 * @since   1.0.0
 */

/* CSS Variables */
:root {
  --assistify-primary-color: #6861f2;
  --assistify-primary-dark: #5650d9;
  --assistify-bg-light: #f8f9fa;
  --assistify-border-color: #e0e0e0;
  --assistify-text-color: #333;
  --assistify-text-muted: #666;
  --assistify-transition: 0.2s ease;
  --assistify-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  --assistify-shadow-hover: 0 12px 40px rgba(0, 0, 0, 0.2);
}

/* Chat Widget Container */
.assistify-chat-widget {
  position: fixed;
  z-index: 999999;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  box-sizing: border-box;
}

.assistify-chat-widget *,
.assistify-chat-widget *::before,
.assistify-chat-widget *::after {
  box-sizing: inherit;
}

.assistify-position-bottom-right {
  bottom: 20px;
  right: 20px;
}

.assistify-position-bottom-left {
  bottom: 20px;
  left: 20px;
}

/* Chat Toggle Button */
.assistify-chat-toggle {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--assistify-primary-color);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--assistify-shadow);
  transition: transform var(--assistify-transition),
    box-shadow var(--assistify-transition);
  position: relative;
}

.assistify-chat-toggle:hover {
  transform: scale(1.05);
  box-shadow: var(--assistify-shadow-hover);
  background: var(--assistify-primary-dark);
}

.assistify-chat-toggle:focus {
  outline: 2px solid var(--assistify-primary-color);
  outline-offset: 2px;
}

.assistify-chat-toggle svg {
  width: 28px;
  height: 28px;
  color: #fff;
}

.assistify-chat-icon,
.assistify-close-icon {
  display: flex;
  align-items: center;
  justify-content: center;
}

.assistify-close-icon {
  display: none;
}

.assistify-chat-toggle[aria-expanded="true"] .assistify-chat-icon {
  display: none;
}

.assistify-chat-toggle[aria-expanded="true"] .assistify-close-icon {
  display: flex;
}

/* Notification Badge */
.assistify-chat-toggle .assistify-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 20px;
  height: 20px;
  background: #dc3545;
  color: #fff;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: assistifyPulse 2s infinite;
}

@keyframes assistifyPulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.1);
  }
}

/* Chat Container */
.assistify-chat-container {
  position: absolute;
  bottom: 75px;
  width: 380px;
  height: 520px;
  background: #fff;
  border-radius: 16px;
  box-shadow: var(--assistify-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px) scale(0.95);
  transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1),
    transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
    visibility 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.assistify-chat-widget.is-open .assistify-chat-container {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

.assistify-position-bottom-right .assistify-chat-container {
  right: 0;
}

.assistify-position-bottom-left .assistify-chat-container {
  left: 0;
}

/* Hidden state handled by opacity/visibility transitions */
.assistify-chat-container[hidden] {
  display: flex; /* Keep display but use opacity/visibility for animation */
}

/* Chat Header */
.assistify-chat-header {
  background: var(--assistify-primary-color);
  color: #fff;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.assistify-header-content {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.assistify-chat-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 6px;
  line-height: 1.2;
}

.assistify-header-subtitle {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.8);
  font-weight: 400;
}

/* Online status dot */
.assistify-status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.assistify-status-dot.is-online {
  background: #4ade80;
  box-shadow: 0 0 0 2px rgba(74, 222, 128, 0.3);
}

.assistify-status-dot.is-offline {
  background: #9ca3af;
  box-shadow: 0 0 0 2px rgba(156, 163, 175, 0.3);
}

/* Close Button */
.assistify-chat-close {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--assistify-transition);
}

.assistify-chat-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

.assistify-chat-close:focus {
  outline: 2px solid rgba(255, 255, 255, 0.5);
  outline-offset: 2px;
}

.assistify-chat-close svg {
  width: 18px;
  height: 18px;
}

/* Chat Messages */
.assistify-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: var(--assistify-bg-light);
  scroll-behavior: smooth;
}

.assistify-message {
  margin-bottom: 12px;
  max-width: 85%;
  animation: assistifySlideIn 0.2s ease;
}

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

.assistify-message.no-animation {
  animation: none;
}

.assistify-message-user {
  margin-left: auto;
}

.assistify-message-assistant {
  margin-right: auto;
}

.assistify-message-content {
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.6;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.assistify-message-user .assistify-message-content {
  background: var(--assistify-primary-color);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.assistify-message-assistant .assistify-message-content {
  background: #fff;
  color: var(--assistify-text-color);
  border: 1px solid var(--assistify-border-color);
  border-bottom-left-radius: 4px;
}

/* Message Footer (Copy button) */
.assistify-message-footer {
  display: flex;
  justify-content: flex-end;
  padding: 4px 8px 0;
  opacity: 0;
  transition: opacity var(--assistify-transition);
}

.assistify-message:hover .assistify-message-footer {
  opacity: 1;
}

.assistify-copy-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  color: var(--assistify-text-muted);
  transition: color var(--assistify-transition),
    background var(--assistify-transition);
}

.assistify-copy-btn:hover {
  color: var(--assistify-text-color);
  background: rgba(0, 0, 0, 0.05);
}

.assistify-copy-btn.is-copied {
  color: #4caf50;
}

/* Streaming Message */
.assistify-message-streaming .assistify-message-content {
  white-space: pre-wrap;
  word-wrap: break-word;
}

.assistify-stream-cursor {
  display: inline-block;
  width: 2px;
  height: 1.2em;
  background: var(--assistify-primary-color);
  margin-left: 2px;
  animation: assistifyBlink 0.6s ease-in-out infinite;
  vertical-align: text-bottom;
}

@keyframes assistifyBlink {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0;
  }
}

/* Quick Questions */
.assistify-quick-questions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  animation: assistifySlideIn 0.3s ease;
}

.assistify-quick-btn {
  background: #fff;
  border: 1px solid var(--assistify-primary-color);
  color: var(--assistify-primary-color);
  padding: 8px 14px;
  border-radius: 20px;
  font-size: 13px;
  cursor: pointer;
  transition: all var(--assistify-transition);
  white-space: nowrap;
}

.assistify-quick-btn:hover {
  background: var(--assistify-primary-color);
  color: #fff;
}

.assistify-quick-btn:focus {
  outline: 2px solid var(--assistify-primary-color);
  outline-offset: 2px;
}

/* Chat Form */
.assistify-chat-form {
  display: flex;
  padding: 12px;
  background: #fff;
  border-top: 1px solid var(--assistify-border-color);
  gap: 8px;
  flex-shrink: 0;
}

.assistify-chat-input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid var(--assistify-border-color);
  border-radius: 24px;
  font-size: 14px;
  transition: border-color var(--assistify-transition),
    box-shadow var(--assistify-transition);
  background: #fff;
}

.assistify-chat-input:focus {
  border-color: var(--assistify-primary-color);
  outline: none;
  box-shadow: 0 0 0 3px rgba(127, 84, 179, 0.15);
}

.assistify-chat-input:disabled {
  background: var(--assistify-bg-light);
  cursor: not-allowed;
}

.assistify-chat-send {
  width: 44px;
  height: 44px;
  padding: 0;
  background: var(--assistify-primary-color);
  color: #fff;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--assistify-transition),
    transform var(--assistify-transition);
  flex-shrink: 0;
}

.assistify-chat-send:hover {
  background: var(--assistify-primary-dark);
  transform: scale(1.05);
}

.assistify-chat-send:focus {
  outline: 2px solid var(--assistify-primary-color);
  outline-offset: 2px;
}

.assistify-chat-send:disabled {
  background: #ccc;
  cursor: not-allowed;
  transform: none;
}

.assistify-chat-send svg {
  width: 20px;
  height: 20px;
}

/* Chat Footer - AI Provider Info */
.assistify-chat-footer {
  padding: 8px 12px;
  background: var(--assistify-bg-light);
  border-top: 1px solid var(--assistify-border-color);
  text-align: center;
  flex-shrink: 0;
}

.assistify-powered-by {
  font-size: 11px;
  color: var(--assistify-text-muted);
  letter-spacing: 0.3px;
}

/* Typing Indicator */
.assistify-typing-indicator {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  background: #fff;
  border: 1px solid var(--assistify-border-color);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  width: fit-content;
}

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

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

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

@keyframes assistifyTyping {
  0%,
  60%,
  100% {
    transform: translateY(0);
  }
  30% {
    transform: translateY(-8px);
  }
}

/* Consent Modal */
.assistify-consent-modal {
  padding: 30px 20px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
}

.assistify-consent-icon {
  color: var(--assistify-primary-color);
  margin-bottom: 16px;
}

.assistify-consent-modal h4 {
  margin: 0 0 12px;
  font-size: 18px;
  font-weight: 600;
  color: var(--assistify-text-color);
}

.assistify-consent-modal p {
  margin: 0 0 24px;
  font-size: 14px;
  color: var(--assistify-text-muted);
  line-height: 1.6;
}

.assistify-consent-privacy {
  margin: -12px 0 24px;
}

.assistify-consent-privacy a {
  color: var(--assistify-primary-color);
  text-decoration: none;
  font-size: 13px;
}

.assistify-consent-privacy a:hover {
  text-decoration: underline;
}

.assistify-consent-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.assistify-consent-agree,
.assistify-consent-decline {
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--assistify-transition);
}

.assistify-consent-agree {
  background: var(--assistify-primary-color);
  color: #fff;
  border: none;
}

.assistify-consent-agree:hover {
  background: var(--assistify-primary-dark);
}

.assistify-consent-agree:focus {
  outline: 2px solid var(--assistify-primary-color);
  outline-offset: 2px;
}

.assistify-consent-decline {
  background: #fff;
  color: var(--assistify-text-muted);
  border: 1px solid var(--assistify-border-color);
}

.assistify-consent-decline:hover {
  background: var(--assistify-bg-light);
  color: var(--assistify-text-color);
}

/* Message Content - Markdown Styles */
.assistify-message-content code {
  background: rgba(0, 0, 0, 0.05);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: "SF Mono", Monaco, "Cascadia Code", monospace;
  font-size: 0.9em;
}

.assistify-message-content pre {
  background: #1e1e1e;
  color: #d4d4d4;
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 8px 0;
}

.assistify-message-content pre code {
  background: transparent;
  padding: 0;
  color: inherit;
}

.assistify-message-content strong {
  font-weight: 600;
}

.assistify-message-content em {
  font-style: italic;
}

.assistify-message-content a {
  color: var(--assistify-primary-color);
  text-decoration: underline;
}

.assistify-message-content ul,
.assistify-message-content ol {
  margin: 8px 0;
  padding-left: 20px;
}

.assistify-message-content li {
  margin: 4px 0;
}

/* Screen reader text */
.screen-reader-text {
  clip: rect(1px, 1px, 1px, 1px);
  position: absolute !important;
  height: 1px;
  width: 1px;
  overflow: hidden;
}

/* Mobile Responsive */
@media (max-width: 480px) {
  .assistify-chat-widget {
    bottom: 10px;
    right: 10px;
    left: 10px;
  }

  .assistify-position-bottom-right,
  .assistify-position-bottom-left {
    bottom: 10px;
    right: 10px;
    left: auto;
  }

  .assistify-chat-toggle {
    width: 56px;
    height: 56px;
  }

  .assistify-chat-container {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    border-radius: 0;
    max-height: none;
  }

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

  .assistify-chat-messages {
    padding: 12px;
  }

  .assistify-message {
    max-width: 90%;
  }

  .assistify-quick-questions {
    flex-direction: column;
  }

  .assistify-quick-btn {
    width: 100%;
    text-align: center;
  }
}

/* Tablet */
@media (min-width: 481px) and (max-width: 768px) {
  .assistify-chat-container {
    width: 340px;
    height: 480px;
  }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  .assistify-chat-widget *,
  .assistify-chat-widget *::before,
  .assistify-chat-widget *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
  .assistify-chat-container {
    background: #1a1a1a;
  }

  .assistify-chat-messages {
    background: #0d0d0d;
  }

  .assistify-message-assistant .assistify-message-content {
    background: #2d2d2d;
    color: #e0e0e0;
    border-color: #404040;
  }

  .assistify-chat-form {
    background: #1a1a1a;
    border-color: #404040;
  }

  .assistify-chat-input {
    background: #2d2d2d;
    border-color: #404040;
    color: #e0e0e0;
  }

  .assistify-chat-input:focus {
    border-color: var(--assistify-primary-color);
  }

  .assistify-quick-btn {
    background: #2d2d2d;
    color: var(--assistify-primary-color);
    border-color: var(--assistify-primary-color);
  }

  .assistify-quick-btn:hover {
    background: var(--assistify-primary-color);
    color: #fff;
  }

  .assistify-consent-modal h4 {
    color: #e0e0e0;
  }

  .assistify-consent-modal p {
    color: #a0a0a0;
  }

  .assistify-consent-privacy a {
    color: var(--assistify-primary-color);
  }

  .assistify-consent-decline {
    background: #2d2d2d;
    border-color: #404040;
    color: #a0a0a0;
  }

  .assistify-typing-indicator {
    background: #2d2d2d;
    border-color: #404040;
  }

  .assistify-message-content code {
    background: rgba(255, 255, 255, 0.1);
  }

  .assistify-chat-footer {
    background: #1a1a1a;
    border-color: #404040;
  }

  .assistify-powered-by {
    color: #808080;
  }
}
