/**
 * AI Chatbot Widget Styles
 * 
 * @package AI\Chatbot
 */

/* CSS Variables */
:root {
  --ai-bg: #0b1b2b;
  --ai-primary: #b62025;
  --ai-primary-600: #9a1a1f;
  --ai-text: #0f172a;
  --ai-muted: #64748b;
  --ai-surface: #ffffff;
  --ai-bot: #f1f5f9;
  --ai-bot-gradient: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
  --ai-surface-overlay: rgba(255, 255, 255, 0.95);
  --radius: 16px;
  --shadow: 0 10px 30px rgba(2, 6, 23, .12);
  --shadow-elevated: 0 20px 60px rgba(2, 6, 23, .18);
}

/* Dark Mode */
@media (prefers-color-scheme: dark) {
  :root {
    --ai-bg: #0b1220;
    --ai-surface: #0f172a;
    --ai-text: #e2e8f0;
    --ai-bot: #141c2c;
    --ai-bot-gradient: linear-gradient(135deg, #1a2332 0%, #141c2c 100%);
    --ai-surface-overlay: rgba(15, 23, 42, 0.95);
    --ai-muted: #94a3b8;
  }
}

/* Root Container */
#ai-chatbot-root {
  position: fixed;
  z-index: 999999;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

#ai-chatbot-root.ai-position-bottom-right {
  right: 24px;
  bottom: 24px;
}

#ai-chatbot-root.ai-position-bottom-left {
  left: 24px;
  bottom: 24px;
}

/* Launcher Button */
.ai-launcher {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--ai-primary) 0%, var(--ai-primary-600) 100%);
  color: #fff;
  box-shadow: var(--shadow);
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  border: 0;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  will-change: transform, box-shadow;
}

.ai-launcher:hover {
  background: linear-gradient(135deg, var(--ai-primary-600) 0%, #7a1519 100%);
  transform: translateY(-2px);
  box-shadow: var(--shadow-elevated);
}

.ai-launcher:focus-visible {
  outline: 3px solid var(--ai-primary);
  outline-offset: 3px;
}

.ai-launcher svg {
  flex-shrink: 0;
}

.ai-launcher-text {
  white-space: nowrap;
}

.ai-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  background: #ef4444;
  color: #fff;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 700;
  min-width: 20px;
  text-align: center;
}

/* Widget Container */
.ai-widget {
  position: fixed;
  width: 360px;
  max-height: 70vh;
  background: var(--ai-surface-overlay);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  color: var(--ai-text);
  border-radius: 20px;
  box-shadow: var(--shadow-elevated);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: ai-slide-up 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  will-change: transform, opacity;
}

@keyframes ai-slide-up {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.ai-position-bottom-right .ai-widget {
  right: 24px;
  bottom: 94px;
}

.ai-position-bottom-left .ai-widget {
  left: 24px;
  bottom: 94px;
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  .ai-widget,
  .ai-launcher {
    animation: none;
    transition: none;
  }
}

/* Header */
.ai-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  background: linear-gradient(135deg, var(--ai-primary) 0%, var(--ai-primary-600) 100%);
  color: #fff;
  box-shadow: 0 2px 12px rgba(182, 32, 37, 0.2);
  position: relative;
}

.ai-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.2);
  color: var(--ai-primary);
  overflow: hidden;
}

.ai-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.ai-header-info {
  flex: 1;
  min-width: 0;
}

.ai-header-info h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.2;
}

.ai-subline {
  margin: 2px 0 0;
  font-size: 11px;
  opacity: 0.85;
  font-weight: 400;
}

.ai-header-actions {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.ai-reload,
.ai-close {
  background: rgba(255, 255, 255, 0.2);
  border: 0;
  color: #fff;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
}

.ai-reload:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.05);
}

.ai-close:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.05);
}

.ai-reload:active {
  transform: rotate(180deg) scale(0.95);
}

.ai-reload:focus-visible,
.ai-close:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.ai-reload svg,
.ai-close svg {
  width: 18px;
  height: 18px;
  display: block;
  flex-shrink: 0;
}

/* Body / Messages */
.ai-body {
  flex: 1;
  padding: 14px;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 transparent;
}

.ai-body::-webkit-scrollbar {
  width: 6px;
}

.ai-body::-webkit-scrollbar-track {
  background: transparent;
}

.ai-body::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}

.ai-body::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* Message Bubbles */
.ai-bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: var(--radius);
  margin: 10px 0;
  line-height: 1.45;
  font-size: 14px;
  word-wrap: break-word;
  animation: ai-fade-in 0.2s ease-out;
}

@keyframes ai-fade-in {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

.ai-bubble.bot {
  background: var(--ai-bot-gradient);
  color: var(--ai-text);
  border-top-left-radius: 4px;
  align-self: flex-start;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.ai-bubble.user {
  background: linear-gradient(135deg, var(--ai-primary) 0%, var(--ai-primary-600) 100%);
  color: #fff;
  margin-left: auto;
  border-top-right-radius: 4px;
  align-self: flex-end;
  box-shadow: 0 2px 8px rgba(182, 32, 37, 0.15);
}

/* Quick Replies */
.ai-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0 4px;
}

.ai-chip {
  background: #e2e8f0;
  color: var(--ai-text);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 0;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.ai-chip:hover {
  background: #cbd5e1;
  transform: translateY(-1px);
}

.ai-chip:focus-visible {
  outline: 2px solid var(--ai-primary);
  outline-offset: 2px;
}

@media (prefers-color-scheme: dark) {
  .ai-chip {
    background: #1e293b;
    color: #e2e8f0;
  }
  .ai-chip:hover {
    background: #334155;
  }
}

/* Typing Indicator */
.ai-typing {
  display: flex;
  gap: 4px;
  padding: 10px 14px;
  background: var(--ai-bot-gradient);
  border-radius: var(--radius);
  border-top-left-radius: 4px;
  max-width: fit-content;
  margin: 10px 0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.ai-typing span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ai-muted);
  animation: ai-typing 1.2s ease-in-out infinite;
}

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

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

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

/* Footer / Input */
.ai-footer {
  border-top: 1px solid #e5e7eb;
  background: var(--ai-surface);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

@media (prefers-color-scheme: dark) {
  .ai-footer {
    border-top-color: #1e293b;
  }
}

.ai-input-form {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 12px;
}

.ai-input {
  flex: 1;
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  padding: 10px 16px;
  font-size: 14px;
  color: var(--ai-text);
  background: var(--ai-surface);
  outline: none;
  transition: border-color 0.2s;
}

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

@media (prefers-color-scheme: dark) {
  .ai-input {
    border-color: #334155;
    background: #0f172a;
  }
}

.ai-send {
  border: 0;
  padding: 10px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--ai-primary) 0%, var(--ai-primary-600) 100%);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(182, 32, 37, 0.2);
  will-change: transform;
}

.ai-send:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--ai-primary-600) 0%, #7a1519 100%);
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(182, 32, 37, 0.3);
}

.ai-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.ai-send:focus-visible {
  outline: 2px solid var(--ai-primary);
  outline-offset: 2px;
}

/* CTA Buttons in Messages */
.ai-cta {
  display: inline-block;
  margin-top: 8px;
  background: #16a34a;
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  text-decoration: none;
  font-weight: 500;
  font-size: 13px;
  transition: background 0.2s;
}

.ai-cta:hover {
  background: #15803d;
}

/* Error Toast */
.ai-error {
  background: #fef2f2;
  color: #991b1b;
  padding: 12px 16px;
  border-radius: 12px;
  margin: 10px 0;
  font-size: 13px;
  border: 1px solid #fee2e2;
}

@media (prefers-color-scheme: dark) {
  .ai-error {
    background: #450a0a;
    color: #fca5a5;
    border-color: #7f1d1d;
  }
}

/* Lead Form */
.ai-lead-form {
  background: var(--ai-bot-gradient);
  padding: 14px;
  border-radius: var(--radius);
  margin: 10px 0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.ai-lead-form input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  margin: 6px 0;
  font-size: 14px;
  background: var(--ai-surface);
  color: var(--ai-text);
}

.ai-lead-form label {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 12px;
  margin: 10px 0 6px;
  cursor: pointer;
}

.ai-lead-form input[type="checkbox"] {
  width: auto;
  margin: 2px 0 0;
}

.ai-lead-form button {
  width: 100%;
  padding: 10px;
  background: linear-gradient(135deg, var(--ai-primary) 0%, var(--ai-primary-600) 100%);
  color: #fff;
  border: 0;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
  transition: all 0.2s;
  box-shadow: 0 2px 8px rgba(182, 32, 37, 0.2);
}

.ai-lead-form button:hover {
  background: linear-gradient(135deg, var(--ai-primary-600) 0%, #7a1519 100%);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(182, 32, 37, 0.3);
}

/* Mobile Responsive */
@media (max-width: 480px) {
  #ai-chatbot-root.ai-position-bottom-right,
  #ai-chatbot-root.ai-position-bottom-left {
    right: 0;
    left: 0;
    bottom: 0;
  }
  
  .ai-launcher {
    margin: 0 auto;
    display: flex;
    width: fit-content;
  }
  
  .ai-widget {
    position: fixed !important;
    top: 0 !important;
    right: 0 !important;
    left: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    max-height: 100vh !important;
    border-radius: 0 !important;
    z-index: 999999;
  }
  
  .ai-header {
    border-radius: 0;
  }
  
  .ai-chip {
    padding: 10px 16px;
    font-size: 14px;
    min-height: 44px;
    display: flex;
    align-items: center;
  }
}

/* Branding Footer */
.ai-branding {
  padding: 8px 12px;
  text-align: center;
  font-size: 11px;
  color: #94a3b8;
  border-top: 1px solid #f1f5f9;
  background: #fafafa;
}

.ai-branding a {
  color: var(--ai-primary);
  text-decoration: none;
  font-weight: 600;
  transition: opacity 0.2s;
}

.ai-branding a:hover {
  opacity: 0.8;
  text-decoration: underline;
}

@media (prefers-color-scheme: dark) {
  .ai-branding {
    background: #0a0a0a;
    border-top-color: #1e293b;
    color: #64748b;
  }
}

/* Focus Visible - Global */
*:focus-visible {
  outline: 3px solid var(--ai-primary);
  outline-offset: 2px;
}
