/**
 * AI Chat Widget Styles
 * Matches Postura UI design system
 */

/* Chat Toggle Button */
.ai-chat-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(99, 102, 241, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  z-index: 9998;
}

.ai-chat-toggle:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 25px rgba(99, 102, 241, 0.5);
}

.ai-chat-toggle:active {
  transform: scale(0.98);
}

.ai-chat-toggle svg {
  width: 24px;
  height: 24px;
  color: white;
}

.ai-chat-toggle .close-icon {
  display: none;
}

.ai-chat-toggle.active .chat-icon {
  display: none;
}

.ai-chat-toggle.active .close-icon {
  display: block;
}

/* Badge for new messages */
.ai-chat-toggle .badge {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 20px;
  height: 20px;
  background: #ef4444;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 600;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Chat Container */
.ai-chat-container {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 380px;
  max-width: calc(100vw - 48px);
  height: 520px;
  max-height: calc(100vh - 140px);
  background: white;
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 9999;
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px) scale(0.95);
  transition: all 0.3s ease;
}

.ai-chat-container.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* Chat Header */
.ai-chat-header {
  padding: 16px 20px;
  background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
  color: white;
  display: flex;
  align-items: center;
  gap: 12px;
}

.ai-chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
}

.ai-chat-avatar svg {
  width: 22px;
  height: 22px;
}

.ai-chat-info {
  flex: 1;
}

.ai-chat-title {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
}

.ai-chat-status {
  font-size: 12px;
  opacity: 0.85;
  display: flex;
  align-items: center;
  gap: 6px;
}

.ai-chat-status::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #10b981;
}

.ai-chat-close {
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  transition: background 0.2s;
}

.ai-chat-close:hover {
  background: rgba(255, 255, 255, 0.1);
}

.ai-chat-close svg {
  width: 20px;
  height: 20px;
}

/* Messages Container */
.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #f8fafc;
}

.ai-chat-messages::-webkit-scrollbar {
  width: 6px;
}

.ai-chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.ai-chat-messages::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}

/* Message Bubbles */
.ai-message {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
  animation: messageSlide 0.3s ease;
}

@keyframes messageSlide {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.ai-message.user {
  align-self: flex-end;
  background: #6366f1;
  color: white;
  border-bottom-right-radius: 4px;
}

.ai-message.assistant {
  align-self: flex-start;
  background: white;
  color: #1e293b;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.ai-message.assistant p {
  margin: 0 0 8px 0;
}

.ai-message.assistant p:last-child {
  margin-bottom: 0;
}

.ai-message.assistant ul,
.ai-message.assistant ol {
  margin: 8px 0;
  padding-left: 20px;
}

.ai-message.assistant li {
  margin: 4px 0;
}

.ai-message.assistant strong {
  color: #4f46e5;
}

.ai-message.assistant code {
  background: #f1f5f9;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
}

/* Typing Indicator */
.ai-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
  background: white;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  align-self: flex-start;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.ai-typing span {
  width: 8px;
  height: 8px;
  background: #94a3b8;
  border-radius: 50%;
  animation: typingDot 1.4s infinite ease-in-out;
}

.ai-typing span:nth-child(2) {
  animation-delay: 0.2s;
}

.ai-typing span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typingDot {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

/* Error Message */
.ai-message.error {
  background: #fef2f2;
  color: #dc2626;
  border: 1px solid #fecaca;
}

/* Input Area */
.ai-chat-input-area {
  padding: 16px;
  background: white;
  border-top: 1px solid #e2e8f0;
}

.ai-chat-form {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.ai-chat-input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  font-size: 14px;
  resize: none;
  max-height: 100px;
  font-family: inherit;
  transition:
    border-color 0.2s,
    box-shadow 0.2s;
}

.ai-chat-input:focus {
  outline: none;
  border-color: #6366f1;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.ai-chat-input::placeholder {
  color: #94a3b8;
}

.ai-chat-send {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: #6366f1;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}

.ai-chat-send:hover:not(:disabled) {
  background: #4f46e5;
}

.ai-chat-send:disabled {
  background: #cbd5e1;
  cursor: not-allowed;
}

.ai-chat-send svg {
  width: 20px;
  height: 20px;
  color: white;
}

/* Rate Limit Info */
.ai-chat-limits {
  font-size: 11px;
  color: #94a3b8;
  text-align: center;
  margin-top: 8px;
}

/* Welcome Message */
.ai-welcome {
  text-align: center;
  padding: 20px;
}

.ai-welcome-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 12px;
  background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ai-welcome-icon svg {
  width: 24px;
  height: 24px;
  color: white;
}

.ai-welcome h3 {
  font-size: 16px;
  font-weight: 600;
  color: #1e293b;
  margin: 0 0 8px 0;
}

.ai-welcome p {
  font-size: 13px;
  color: #64748b;
  margin: 0 0 16px 0;
}

/* Quick Suggestions */
.ai-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.ai-suggestion {
  padding: 8px 14px;
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 20px;
  font-size: 12px;
  color: #475569;
  cursor: pointer;
  transition: all 0.2s;
}

.ai-suggestion:hover {
  background: #6366f1;
  color: white;
  border-color: #6366f1;
}

/* Powered by footer */
.ai-chat-powered {
  font-size: 10px;
  color: #94a3b8;
  text-align: center;
  margin-top: 6px;
}

.ai-chat-powered a {
  color: #6366f1;
  text-decoration: none;
  font-weight: 500;
}

.ai-chat-powered a:hover {
  text-decoration: underline;
}

/* AI Response — Product Cards */
.ai-product-cards {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 8px 0;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
}

.ai-product-card {
  display: flex;
  flex-direction: column;
  min-width: 160px;
  max-width: 180px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
  scroll-snap-align: start;
  flex-shrink: 0;
}

.ai-product-card:hover {
  border-color: #6366f1;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.15);
}

.ai-product-card img {
  width: 100%;
  height: 100px;
  object-fit: cover;
  background: #e2e8f0;
}

.ai-product-info {
  padding: 10px;
}

.ai-product-name {
  font-size: 13px;
  font-weight: 600;
  color: #1e293b;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.ai-product-price {
  font-size: 12px;
  font-weight: 700;
  color: #6366f1;
  margin-top: 4px;
}

/* AI Response — Suggestion Pills */
.ai-suggest-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.ai-suggest-pill {
  padding: 6px 14px;
  background: #eef2ff;
  border: 1px solid #c7d2fe;
  border-radius: 20px;
  font-size: 12px;
  color: #4338ca;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.ai-suggest-pill:hover {
  background: #6366f1;
  color: white;
  border-color: #6366f1;
}

/* AI Response — Action Buttons */
.ai-action-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.ai-action-btn {
  padding: 8px 16px;
  background: #6366f1;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.2s;
}

.ai-action-btn:hover {
  background: #4f46e5;
}

/* AI Response — Compare Table */
.ai-compare-table {
  overflow-x: auto;
  margin: 8px 0;
}

.ai-compare-table table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.ai-compare-table th {
  background: #f1f5f9;
  padding: 6px 10px;
  text-align: left;
  font-weight: 600;
  color: #475569;
  border-bottom: 2px solid #e2e8f0;
  white-space: nowrap;
}

.ai-compare-table td {
  padding: 6px 10px;
  border-bottom: 1px solid #e2e8f0;
  color: #1e293b;
}

/* AI Response — Inline Images */
.ai-inline-img {
  max-width: 100%;
  border-radius: 8px;
  margin: 8px 0;
}

/* AI Response — Links inside messages */
.ai-message.assistant a {
  color: #6366f1;
  text-decoration: underline;
  text-decoration-color: rgba(99, 102, 241, 0.3);
  text-underline-offset: 2px;
}

.ai-message.assistant a:hover {
  text-decoration-color: #6366f1;
}

/* AI Response — Headings inside messages */
.ai-message.assistant h3 {
  font-size: 15px;
  font-weight: 600;
  color: #1e293b;
  margin: 12px 0 6px 0;
}

.ai-message.assistant h4 {
  font-size: 14px;
  font-weight: 600;
  color: #475569;
  margin: 10px 0 4px 0;
}

/* Lead Capture Form */
.ai-lead-capture {
  background: linear-gradient(135deg, #eef2ff 0%, #e0e7ff 100%) !important;
  border: 1px solid #c7d2fe;
  padding: 16px !important;
}

.ai-lead-header {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin-bottom: 12px;
}

.ai-lead-icon {
  width: 32px;
  height: 32px;
  min-width: 32px;
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ai-lead-icon svg {
  width: 16px;
  height: 16px;
  color: white;
}

.ai-lead-header strong {
  display: block;
  font-size: 14px;
  color: #1e293b;
  margin-bottom: 2px;
}

.ai-lead-header p {
  font-size: 12px;
  color: #64748b;
  margin: 0;
  line-height: 1.4;
}

.ai-lead-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ai-lead-form input {
  padding: 10px 12px;
  border: 1px solid #c7d2fe;
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  background: white;
  color: #1e293b;
  transition: border-color 0.2s;
}

.ai-lead-form input:focus {
  outline: none;
  border-color: #6366f1;
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.1);
}

.ai-lead-form input::placeholder {
  color: #94a3b8;
}

.ai-lead-submit {
  padding: 10px;
  background: #6366f1;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.ai-lead-submit:hover:not(:disabled) {
  background: #4f46e5;
}

.ai-lead-submit:disabled {
  background: #a5b4fc;
  cursor: wait;
}

.ai-lead-skip {
  padding: 6px;
  background: none;
  border: none;
  color: #94a3b8;
  font-size: 12px;
  cursor: pointer;
  text-align: center;
}

.ai-lead-skip:hover {
  color: #64748b;
}

.ai-lead-status {
  padding: 10px;
  border-radius: 8px;
  font-size: 13px;
  text-align: center;
}

.ai-lead-success {
  background: #ecfdf5;
  color: #059669;
  border: 1px solid #a7f3d0;
}

.ai-lead-error {
  background: #fef2f2;
  color: #dc2626;
  border: 1px solid #fecaca;
}

/* Mobile Responsive */
@media (max-width: 480px) {
  .ai-chat-toggle {
    bottom: 80px; /* Above bottom nav */
    right: 16px;
    width: 52px;
    height: 52px;
  }

  .ai-chat-container {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-width: 100%;
    height: calc(100vh - 60px);
    max-height: calc(100vh - 60px);
    border-radius: 16px 16px 0 0;
  }

  .ai-chat-container.open {
    transform: translateY(0);
  }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  .ai-chat-container {
    background: #1e293b;
  }

  .ai-chat-messages {
    background: #0f172a;
  }

  .ai-message.assistant {
    background: #334155;
    color: #f1f5f9;
  }

  .ai-chat-input-area {
    background: #1e293b;
    border-top-color: #334155;
  }

  .ai-chat-input {
    background: #0f172a;
    border-color: #334155;
    color: #f1f5f9;
  }

  .ai-suggestion {
    background: #334155;
    border-color: #475569;
    color: #e2e8f0;
  }

  .ai-product-card {
    background: #1e293b;
    border-color: #334155;
  }

  .ai-product-name {
    color: #f1f5f9;
  }

  .ai-suggest-pill {
    background: #312e81;
    border-color: #4338ca;
    color: #c7d2fe;
  }

  .ai-compare-table th {
    background: #334155;
    color: #e2e8f0;
    border-bottom-color: #475569;
  }

  .ai-compare-table td {
    color: #f1f5f9;
    border-bottom-color: #334155;
  }

  .ai-chat-powered {
    color: #64748b;
  }

  .ai-lead-capture {
    background: linear-gradient(135deg, #1e1b4b 0%, #312e81 100%) !important;
    border-color: #4338ca;
  }

  .ai-lead-header strong {
    color: #e2e8f0;
  }

  .ai-lead-header p {
    color: #94a3b8;
  }

  .ai-lead-form input {
    background: #1e293b;
    border-color: #4338ca;
    color: #f1f5f9;
  }
}
