/**
 * RegGFX AI Chatbot Widget
 * Version: 1.0.0
 * Author: RegGFX LLC
 * 
 * Brand Colors:
 * --Primary Deep Navy: #031733
 * --Royal Blue: #0E4DA7
 * --Accent Red: #F04D4D
 * --Complementary Light Blue: #E8F0FE
 * --Complementary Soft Navy: #1A3A5C
 */

/* =============================================
   CSS Custom Properties (Design Tokens)
   ============================================= */
:root {
  /* Primary Palette */
  --rgfx-primary: #031733;
  --rgfx-primary-light: #1A3A5C;
  --rgfx-royal: #0E4DA7;
  --rgfx-royal-light: #2563EB;
  --rgfx-accent: #F04D4D;
  --rgfx-accent-light: #F87171;
  
  /* Neutral Palette */
  --rgfx-white: #FFFFFF;
  --rgfx-gray-50: #F8FAFC;
  --rgfx-gray-100: #F1F5F9;
  --rgfx-gray-200: #E2E8F0;
  --rgfx-gray-300: #CBD5E1;
  --rgfx-gray-400: #94A3B8;
  --rgfx-gray-500: #64748B;
  --rgfx-gray-600: #475569;
  --rgfx-gray-700: #334155;
  --rgfx-gray-800: #1E293B;
  
  /* Semantic Colors */
  --rgfx-success: #10B981;
  --rgfx-info: #3B82F6;
  
  /* Shadows */
  --rgfx-shadow-sm: 0 1px 2px rgba(3, 23, 51, 0.05);
  --rgfx-shadow-md: 0 4px 12px rgba(3, 23, 51, 0.1);
  --rgfx-shadow-lg: 0 10px 40px rgba(3, 23, 51, 0.15);
  --rgfx-shadow-xl: 0 20px 60px rgba(3, 23, 51, 0.2);
  --rgfx-shadow-glow: 0 0 20px rgba(14, 77, 167, 0.3);
  
  /* Animation */
  --rgfx-transition-fast: 0.15s ease;
  --rgfx-transition-normal: 0.25s ease;
  --rgfx-transition-smooth: 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  
  /* Sizing */
  --rgfx-toggle-size: 60px;
  --rgfx-panel-width: 400px;
  --rgfx-panel-height: 620px;
  --rgfx-border-radius: 16px;
  --rgfx-border-radius-lg: 24px;
  --rgfx-border-radius-full: 9999px;
}

/* =============================================
   Base Reset for Widget Scope
   ============================================= */
.rgfx-widget-container,
.rgfx-widget-container * {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.rgfx-widget-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 999999;
  font-size: 14px;
  line-height: 1.5;
}

/* =============================================
   Floating Toggle Button
   ============================================= */
.rgfx-toggle-btn {
  position: relative;
  width: var(--rgfx-toggle-size);
  height: var(--rgfx-toggle-size);
  border-radius: var(--rgfx-border-radius-full);
  background: linear-gradient(135deg, var(--rgfx-royal) 0%, var(--rgfx-primary) 100%);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--rgfx-shadow-lg), var(--rgfx-shadow-glow);
  transition: transform var(--rgfx-transition-smooth), box-shadow var(--rgfx-transition-smooth);
  outline: none;
}

.rgfx-toggle-btn:hover {
  transform: scale(1.08);
  box-shadow: var(--rgfx-shadow-xl), 0 0 30px rgba(14, 77, 167, 0.4);
}

.rgfx-toggle-btn:focus {
  outline: 3px solid var(--rgfx-royal-light);
  outline-offset: 3px;
}

.rgfx-toggle-btn:active {
  transform: scale(0.95);
}

/* Toggle Icon */
.rgfx-toggle-icon {
  width: 28px;
  height: 28px;
  fill: var(--rgfx-white);
  transition: transform var(--rgfx-transition-normal), opacity var(--rgfx-transition-normal);
}

.rgfx-toggle-btn[aria-expanded="true"] .rgfx-icon-chat {
  opacity: 0;
  transform: rotate(90deg) scale(0.5);
}

.rgfx-toggle-btn[aria-expanded="true"] .rgfx-icon-close {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

.rgfx-icon-close {
  position: absolute;
  opacity: 0;
  transform: rotate(-90deg) scale(0.5);
}

/* Tooltip */
.rgfx-tooltip {
  position: absolute;
  right: calc(100% + 12px);
  top: 50%;
  transform: translateY(-50%);
  background: var(--rgfx-primary);
  color: var(--rgfx-white);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--rgfx-transition-normal), visibility var(--rgfx-transition-normal);
  pointer-events: none;
  box-shadow: var(--rgfx-shadow-md);
}

.rgfx-tooltip::after {
  content: '';
  position: absolute;
  right: -6px;
  top: 50%;
  transform: translateY(-50%);
  border: 6px solid transparent;
  border-left-color: var(--rgfx-primary);
}

.rgfx-toggle-btn:hover .rgfx-tooltip,
.rgfx-toggle-btn:focus .rgfx-tooltip {
  opacity: 1;
  visibility: visible;
}

.rgfx-toggle-btn[aria-expanded="true"] .rgfx-tooltip {
  opacity: 0;
  visibility: hidden;
}

/* Pulse Animation for Attention */
.rgfx-toggle-btn::before {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: var(--rgfx-border-radius-full);
  background: linear-gradient(135deg, var(--rgfx-royal), var(--rgfx-royal-light));
  opacity: 0;
  z-index: -1;
  animation: rgfxPulse 2.5s ease-in-out infinite;
}

@keyframes rgfxPulse {
  0%, 100% { opacity: 0; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(1.15); }
}

/* =============================================
   Chat Panel
   ============================================= */
.rgfx-chat-panel {
  position: absolute;
  bottom: calc(var(--rgfx-toggle-size) + 16px);
  right: 0;
  width: var(--rgfx-panel-width);
  height: var(--rgfx-panel-height);
  max-height: calc(100vh - 140px);
  background: var(--rgfx-white);
  border-radius: var(--rgfx-border-radius-lg);
  box-shadow: var(--rgfx-shadow-xl);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px) scale(0.95);
  transform-origin: bottom right;
  transition: opacity var(--rgfx-transition-smooth), 
              visibility var(--rgfx-transition-smooth), 
              transform var(--rgfx-transition-smooth);
}

.rgfx-chat-panel.rgfx-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* =============================================
   Panel Header
   ============================================= */
.rgfx-header {
  background: linear-gradient(135deg, var(--rgfx-primary) 0%, var(--rgfx-primary-light) 100%);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
}

.rgfx-header-avatar {
  width: 44px;
  height: 44px;
  border-radius: var(--rgfx-border-radius-full);
  background: linear-gradient(135deg, var(--rgfx-royal) 0%, var(--rgfx-royal-light) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.rgfx-header-avatar svg {
  width: 24px;
  height: 24px;
  fill: var(--rgfx-white);
}

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

.rgfx-header-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--rgfx-white);
  margin: 0;
}

.rgfx-header-subtitle {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.75);
  margin: 2px 0 0 0;
}

.rgfx-header-actions {
  display: flex;
  gap: 8px;
}

.rgfx-header-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.15);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--rgfx-transition-fast);
}

.rgfx-header-btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

.rgfx-header-btn:focus {
  outline: 2px solid rgba(255, 255, 255, 0.5);
  outline-offset: 2px;
}

.rgfx-header-btn svg {
  width: 16px;
  height: 16px;
  fill: var(--rgfx-white);
}

/* =============================================
   Messages Container
   ============================================= */
.rgfx-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--rgfx-gray-50);
  scroll-behavior: smooth;
}

.rgfx-messages::-webkit-scrollbar {
  width: 6px;
}

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

.rgfx-messages::-webkit-scrollbar-thumb {
  background: var(--rgfx-gray-300);
  border-radius: 3px;
}

.rgfx-messages::-webkit-scrollbar-thumb:hover {
  background: var(--rgfx-gray-400);
}

/* =============================================
   Message Bubbles
   ============================================= */
.rgfx-message {
  display: flex;
  gap: 10px;
  max-width: 88%;
  animation: rgfxSlideIn 0.3s ease-out;
}

.rgfx-message.rgfx-bot {
  align-self: flex-start;
}

.rgfx-message.rgfx-user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

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

.rgfx-message-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--rgfx-border-radius-full);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
}

.rgfx-bot .rgfx-message-avatar {
  background: linear-gradient(135deg, var(--rgfx-royal) 0%, var(--rgfx-primary) 100%);
}

.rgfx-bot .rgfx-message-avatar svg {
  width: 18px;
  height: 18px;
  fill: var(--rgfx-white);
}

.rgfx-user .rgfx-message-avatar {
  background: var(--rgfx-gray-200);
  color: var(--rgfx-gray-600);
}

.rgfx-message-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.rgfx-bubble {
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
}

.rgfx-bot .rgfx-bubble {
  background: var(--rgfx-white);
  color: var(--rgfx-gray-700);
  border-bottom-left-radius: 6px;
  box-shadow: var(--rgfx-shadow-sm);
}

.rgfx-user .rgfx-bubble {
  background: linear-gradient(135deg, var(--rgfx-royal) 0%, var(--rgfx-royal-light) 100%);
  color: var(--rgfx-white);
  border-bottom-right-radius: 6px;
}

.rgfx-message-source {
  font-size: 11px;
  color: var(--rgfx-gray-400);
  padding-left: 4px;
}

/* CTA Button in Messages */
.rgfx-cta-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding: 10px 16px;
  background: linear-gradient(135deg, var(--rgfx-accent) 0%, var(--rgfx-accent-light) 100%);
  color: var(--rgfx-white);
  border: none;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: transform var(--rgfx-transition-fast), box-shadow var(--rgfx-transition-fast);
}

.rgfx-cta-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(240, 77, 77, 0.3);
}

.rgfx-cta-btn svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

/* Email CTA */
.rgfx-email-btn {
  background: linear-gradient(135deg, var(--rgfx-primary) 0%, var(--rgfx-primary-light) 100%);
}

.rgfx-email-btn:hover {
  box-shadow: 0 4px 12px rgba(3, 23, 51, 0.3);
}

/* =============================================
   Typing Indicator
   ============================================= */
.rgfx-typing {
  display: flex;
  gap: 10px;
  align-self: flex-start;
  max-width: 88%;
}

.rgfx-typing-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--rgfx-border-radius-full);
  background: linear-gradient(135deg, var(--rgfx-royal) 0%, var(--rgfx-primary) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.rgfx-typing-avatar svg {
  width: 18px;
  height: 18px;
  fill: var(--rgfx-white);
}

.rgfx-typing-bubble {
  background: var(--rgfx-white);
  padding: 14px 18px;
  border-radius: 18px;
  border-bottom-left-radius: 6px;
  box-shadow: var(--rgfx-shadow-sm);
  display: flex;
  align-items: center;
  gap: 4px;
}

.rgfx-typing-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--rgfx-gray-400);
  animation: rgfxTypingBounce 1.4s ease-in-out infinite;
}

.rgfx-typing-dot:nth-child(1) { animation-delay: 0s; }
.rgfx-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.rgfx-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes rgfxTypingBounce {
  0%, 60%, 100% {
    transform: translateY(0);
    background: var(--rgfx-gray-400);
  }
  30% {
    transform: translateY(-6px);
    background: var(--rgfx-royal);
  }
}

/* =============================================
   Suggested Questions Chips
   ============================================= */
.rgfx-chips-container {
  padding: 12px 16px;
  background: var(--rgfx-white);
  border-top: 1px solid var(--rgfx-gray-100);
  flex-shrink: 0;
}

.rgfx-chips-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--rgfx-gray-500);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.rgfx-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.rgfx-chip {
  padding: 8px 14px;
  background: var(--rgfx-gray-100);
  color: var(--rgfx-gray-700);
  border: 1px solid var(--rgfx-gray-200);
  border-radius: var(--rgfx-border-radius-full);
  font-size: 12px;
  cursor: pointer;
  transition: all var(--rgfx-transition-fast);
}

.rgfx-chip:hover {
  background: var(--rgfx-royal);
  color: var(--rgfx-white);
  border-color: var(--rgfx-royal);
  transform: translateY(-1px);
}

.rgfx-chip:focus {
  outline: 2px solid var(--rgfx-royal-light);
  outline-offset: 2px;
}

/* =============================================
   Input Area
   ============================================= */
.rgfx-input-area {
  padding: 14px 16px;
  background: var(--rgfx-white);
  border-top: 1px solid var(--rgfx-gray-100);
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-shrink: 0;
}

.rgfx-input-wrapper {
  flex: 1;
  position: relative;
}

.rgfx-input {
  width: 100%;
  padding: 12px 16px;
  background: var(--rgfx-gray-50);
  border: 1px solid var(--rgfx-gray-200);
  border-radius: var(--rgfx-border-radius);
  font-size: 14px;
  color: var(--rgfx-gray-700);
  resize: none;
  min-height: 46px;
  max-height: 100px;
  transition: border-color var(--rgfx-transition-fast), box-shadow var(--rgfx-transition-fast);
}

.rgfx-input::placeholder {
  color: var(--rgfx-gray-400);
}

.rgfx-input:focus {
  outline: none;
  border-color: var(--rgfx-royal);
  box-shadow: 0 0 0 3px rgba(14, 77, 167, 0.1);
}

.rgfx-send-btn {
  width: 46px;
  height: 46px;
  border-radius: var(--rgfx-border-radius);
  background: linear-gradient(135deg, var(--rgfx-royal) 0%, var(--rgfx-royal-light) 100%);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform var(--rgfx-transition-fast), box-shadow var(--rgfx-transition-fast);
}

.rgfx-send-btn:hover {
  transform: scale(1.05);
  box-shadow: var(--rgfx-shadow-md);
}

.rgfx-send-btn:focus {
  outline: 2px solid var(--rgfx-royal-light);
  outline-offset: 2px;
}

.rgfx-send-btn:active {
  transform: scale(0.95);
}

.rgfx-send-btn svg {
  width: 20px;
  height: 20px;
  fill: var(--rgfx-white);
}

.rgfx-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* =============================================
   Mobile Responsive
   ============================================= */
@media (max-width: 480px) {
  .rgfx-widget-container {
    bottom: 0;
    right: 0;
    left: 0;
  }
  
  .rgfx-toggle-btn {
    position: fixed;
    bottom: 16px;
    right: 16px;
  }
  
  .rgfx-toggle-btn[aria-expanded="true"] {
    opacity: 0;
    pointer-events: none;
  }
  
  .rgfx-tooltip {
    display: none;
  }
  
  .rgfx-chat-panel {
    position: fixed;
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    height: 85vh;
    max-height: 85vh;
    border-radius: var(--rgfx-border-radius-lg) var(--rgfx-border-radius-lg) 0 0;
    transform: translateY(100%);
  }
  
  .rgfx-chat-panel.rgfx-open {
    transform: translateY(0);
  }
}

/* =============================================
   Accessibility: Reduced Motion
   ============================================= */
@media (prefers-reduced-motion: reduce) {
  .rgfx-toggle-btn,
  .rgfx-chat-panel,
  .rgfx-message,
  .rgfx-chip,
  .rgfx-send-btn,
  .rgfx-cta-btn {
    transition: none;
    animation: none;
  }
  
  .rgfx-toggle-btn::before {
    animation: none;
  }
  
  .rgfx-typing-dot {
    animation: none;
    background: var(--rgfx-gray-400);
  }
}

/* =============================================
   Focus Visible for Keyboard Navigation
   ============================================= */
.rgfx-toggle-btn:focus-visible,
.rgfx-header-btn:focus-visible,
.rgfx-chip:focus-visible,
.rgfx-send-btn:focus-visible,
.rgfx-input:focus-visible,
.rgfx-cta-btn:focus-visible {
  outline: 3px solid var(--rgfx-royal-light);
  outline-offset: 2px;
}

/* =============================================
   Print Styles (hide widget)
   ============================================= */
@media print {
  .rgfx-widget-container {
    display: none !important;
  }
}
