/*
 * SmartChat AI - Modern Chatbot Widget
 * Version: 1.0.0
 * A beautiful, accessible chatbot widget with glass-morphism design
 */

/* ========================================
   CSS VARIABLES
   ======================================== */

:root {
  /* Brand Colors */
  --smartchat-primary: #6366f1;
  --smartchat-primary-hover: #4f46e5;
  --smartchat-primary-light: #e0e7ff;

  /* Background Colors */
  --smartchat-bg: #ffffff;
  --smartchat-bg-secondary: #f8fafc;

  /* Text Colors */
  --smartchat-text: #1e293b;
  --smartchat-text-muted: #64748b;

  /* UI Elements */
  --smartchat-border: #e2e8f0;
  --smartchat-user-bubble: #6366f1;
  --smartchat-bot-bubble: #f1f5f9;

  /* Effects */
  --smartchat-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  --smartchat-radius: 16px;
  --smartchat-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ========================================
   DARK MODE SUPPORT
   ======================================== */

@media (prefers-color-scheme: dark) {
  :root {
    --smartchat-bg: #1e293b;
    --smartchat-bg-secondary: #0f172a;
    --smartchat-text: #f8fafc;
    --smartchat-text-muted: #94a3b8;
    --smartchat-border: #334155;
    --smartchat-bot-bubble: #334155;
  }
}

/* ========================================
   ANIMATIONS
   ======================================== */

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

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

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.4);
  }
  70% {
    box-shadow: 0 0 0 15px rgba(99, 102, 241, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(99, 102, 241, 0);
  }
}

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

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ========================================
   FLOATING TRIGGER BUTTON
   ======================================== */

.smartchat-trigger {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--smartchat-primary);
  color: #ffffff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--smartchat-shadow);
  transition: var(--smartchat-transition);
  z-index: 999999;
  animation: pulse 2s infinite;
}

.smartchat-trigger:hover {
  background: var(--smartchat-primary-hover);
  transform: scale(1.1);
  animation: none;
}

.smartchat-trigger:focus {
  outline: 3px solid var(--smartchat-primary-light);
  outline-offset: 2px;
}

.smartchat-trigger:active {
  transform: scale(0.95);
}

.smartchat-trigger svg,
.smartchat-trigger i {
  font-size: 24px;
  width: 24px;
  height: 24px;
}

/* ========================================
   CHAT WIDGET CONTAINER
   ======================================== */

.smartchat-widget {
  position: fixed;
  bottom: 90px;
  right: 20px;
  width: 400px;
  height: 550px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: var(--smartchat-radius);
  box-shadow: var(--smartchat-shadow);
  border: 1px solid var(--smartchat-border);
  display: none;
  flex-direction: column;
  overflow: hidden;
  z-index: 999998;
  transition: var(--smartchat-transition);
}

@media (prefers-color-scheme: dark) {
  .smartchat-widget {
    background: rgba(30, 41, 59, 0.95);
  }
}

.smartchat-widget.open {
  display: flex;
  animation: slideUp 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ========================================
   WIDGET HEADER
   ======================================== */

.smartchat-header {
  background: linear-gradient(135deg, var(--smartchat-primary) 0%, var(--smartchat-primary-hover) 100%);
  color: #ffffff;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  flex-shrink: 0;
}

.smartchat-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

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

.smartchat-header-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.smartchat-header-text {
  flex: 1;
  min-width: 0;
}

.smartchat-header-title {
  font-weight: 600;
  font-size: 16px;
  margin: 0 0 2px 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.smartchat-header-name {
  font-weight: 600;
  font-size: 16px;
  margin: 0 0 2px 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.smartchat-header-status {
  font-size: 12px;
  opacity: 0.9;
  display: flex;
  align-items: center;
  gap: 6px;
}

.smartchat-status-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #10b981;
  display: inline-block;
  animation: pulse 2s infinite;
}

.smartchat-close,
.smartchat-close-button {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: #ffffff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--smartchat-transition);
  flex-shrink: 0;
}

.smartchat-close:hover,
.smartchat-close-button:hover {
  background: rgba(255, 255, 255, 0.2);
}

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

/* ========================================
   MESSAGES CONTAINER
   ======================================== */

.smartchat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  scroll-behavior: smooth;
  background: var(--smartchat-bg);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Custom Scrollbar */
.smartchat-messages::-webkit-scrollbar {
  width: 6px;
}

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

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

.smartchat-messages::-webkit-scrollbar-thumb:hover {
  background: var(--smartchat-text-muted);
}

/* ========================================
   MESSAGE BUBBLES
   ======================================== */

.smartchat-message {
  display: flex;
  gap: 8px;
  animation: fadeIn 0.3s ease-out;
  max-width: 100%;
}

.smartchat-message.user {
  flex-direction: row-reverse;
  justify-content: flex-start;
}

.smartchat-message.bot {
  flex-direction: row;
  justify-content: flex-start;
}

.smartchat-message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--smartchat-primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}

.smartchat-message-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.smartchat-message.user .smartchat-message-avatar {
  background: var(--smartchat-user-bubble);
  color: #ffffff;
}

.smartchat-message.bot .smartchat-message-avatar {
  background: var(--smartchat-bot-bubble);
  color: var(--smartchat-text);
}

.smartchat-message-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 85%;
}

.smartchat-message-bubble {
  padding: 12px 16px;
  border-radius: var(--smartchat-radius);
  word-wrap: break-word;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  line-height: 1.5;
  font-size: 14px;
}

.smartchat-message.user .smartchat-message-bubble {
  background: var(--smartchat-user-bubble);
  color: #ffffff;
  border-bottom-right-radius: 4px;
  margin-left: auto;
}

.smartchat-message.bot .smartchat-message-bubble {
  background: var(--smartchat-bot-bubble);
  color: var(--smartchat-text);
  border-bottom-left-radius: 4px;
}

.smartchat-message-timestamp {
  font-size: 11px;
  color: var(--smartchat-text-muted);
  padding: 0 4px;
}

.smartchat-message.user .smartchat-message-timestamp {
  text-align: right;
}

.smartchat-message.bot .smartchat-message-timestamp {
  text-align: left;
}

/* ========================================
   TYPING INDICATOR
   ======================================== */

.smartchat-typing {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.smartchat-typing-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--smartchat-bot-bubble);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.smartchat-typing-bubble {
  background: var(--smartchat-bot-bubble);
  padding: 12px 16px;
  border-radius: var(--smartchat-radius);
  border-bottom-left-radius: 4px;
  display: flex;
  gap: 4px;
  align-items: center;
}

.smartchat-typing-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--smartchat-text-muted);
  animation: bounce 1.4s infinite ease-in-out;
}

.smartchat-typing-dot:nth-child(1) {
  animation-delay: -0.32s;
}

.smartchat-typing-dot:nth-child(2) {
  animation-delay: -0.16s;
}

/* ========================================
   INPUT AREA
   ======================================== */

.smartchat-input-area {
  border-top: 1px solid var(--smartchat-border);
  padding: 16px;
  background: var(--smartchat-bg-secondary);
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-shrink: 0;
}

.smartchat-input-wrapper {
  flex: 1;
  position: relative;
  display: flex;
  align-items: flex-end;
}

.smartchat-input-label {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

.screen-reader-text {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

.smartchat-input {
  width: 100%;
  min-height: 44px;
  max-height: 120px;
  padding: 12px 56px 12px 16px;
  border: 1px solid var(--smartchat-border);
  border-radius: 12px;
  background: var(--smartchat-bg);
  color: var(--smartchat-text);
  font-size: 14px;
  font-family: inherit;
  resize: none;
  overflow-y: auto;
  transition: var(--smartchat-transition);
}

.smartchat-input:focus {
  outline: none;
  border-color: var(--smartchat-primary);
  box-shadow: 0 0 0 3px var(--smartchat-primary-light);
}

.smartchat-input::placeholder {
  color: var(--smartchat-text-muted);
}

.smartchat-input::-webkit-scrollbar {
  width: 4px;
}

.smartchat-input::-webkit-scrollbar-track {
  background: transparent;
}

.smartchat-input::-webkit-scrollbar-thumb {
  background: var(--smartchat-border);
  border-radius: 2px;
}

.smartchat-send,
.smartchat-send-button {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--smartchat-primary);
  color: #ffffff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--smartchat-transition);
  flex-shrink: 0;
  position: absolute;
  right: 4px;
  bottom: 4px;
}

.smartchat-send:hover:not(:disabled),
.smartchat-send-button:hover:not(:disabled) {
  background: var(--smartchat-primary-hover);
  transform: scale(1.05);
}

.smartchat-send:focus,
.smartchat-send-button:focus {
  outline: 3px solid var(--smartchat-primary-light);
  outline-offset: 2px;
}

.smartchat-send:active:not(:disabled),
.smartchat-send-button:active:not(:disabled) {
  transform: scale(0.95);
}

.smartchat-send:disabled,
.smartchat-send-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.smartchat-send.loading svg,
.smartchat-send.loading i,
.smartchat-send-button.smartchat-loading svg,
.smartchat-send-button.smartchat-loading i {
  animation: spin 0.8s linear infinite;
}

/* ========================================
   EMPTY STATE
   ======================================== */

.smartchat-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 20px;
  gap: 16px;
  height: 100%;
}

.smartchat-empty-avatar {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--smartchat-primary) 0%, var(--smartchat-primary-hover) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  font-size: 32px;
  margin-bottom: 8px;
  box-shadow: 0 8px 16px rgba(99, 102, 241, 0.3);
}

.smartchat-empty-greeting {
  font-size: 24px;
  font-weight: 600;
  color: var(--smartchat-text);
  margin: 0;
}

.smartchat-empty-subtitle {
  font-size: 14px;
  color: var(--smartchat-text-muted);
  margin: 0 0 16px 0;
  max-width: 280px;
}

.smartchat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  max-width: 100%;
}

.smartchat-suggestion,
.smartchat-suggestion-chip {
  padding: 8px 16px;
  border-radius: 20px;
  background: var(--smartchat-bg-secondary);
  border: 1px solid var(--smartchat-border);
  color: var(--smartchat-text);
  font-size: 13px;
  cursor: pointer;
  transition: var(--smartchat-transition);
}

.smartchat-suggestion:hover,
.smartchat-suggestion-chip:hover {
  background: var(--smartchat-primary-light);
  border-color: var(--smartchat-primary);
  color: var(--smartchat-primary);
  transform: translateY(-2px);
}

.smartchat-suggestion:focus,
.smartchat-suggestion-chip:focus {
  outline: 2px solid var(--smartchat-primary);
  outline-offset: 2px;
}

/* ========================================
   FOOTER
   ======================================== */

.smartchat-footer {
  padding: 12px 16px;
  text-align: center;
  font-size: 11px;
  color: var(--smartchat-text-muted);
  background: var(--smartchat-bg-secondary);
  border-top: 1px solid var(--smartchat-border);
  flex-shrink: 0;
}

.smartchat-footer a {
  color: var(--smartchat-primary);
  text-decoration: none;
  transition: var(--smartchat-transition);
}

.smartchat-footer a:hover {
  text-decoration: underline;
}

/* ========================================
   POSITION MODIFIERS
   ======================================== */

.smartchat-position-left .smartchat-trigger {
  left: 20px;
  right: auto;
}

.smartchat-position-left .smartchat-widget {
  left: 20px;
  right: auto;
}

/* ========================================
   MOBILE RESPONSIVE
   ======================================== */

@media (max-width: 768px) {
  .smartchat-widget {
    width: 100vw;
    height: 100vh;
    bottom: 0;
    right: 0;
    left: 0;
    top: 0;
    border-radius: 0;
    border: none;
  }

  .smartchat-position-left .smartchat-widget {
    left: 0;
  }

  .smartchat-trigger {
    width: 56px;
    height: 56px;
    bottom: 16px;
    right: 16px;
  }

  .smartchat-trigger svg,
  .smartchat-trigger i {
    font-size: 22px;
    width: 22px;
    height: 22px;
  }

  .smartchat-position-left .smartchat-trigger {
    left: 16px;
    right: auto;
  }

  .smartchat-messages {
    padding: 16px;
  }

  .smartchat-message-content {
    max-width: 80%;
  }
}

/* ========================================
   ACCESSIBILITY
   ======================================== */

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
  .smartchat-widget {
    border: 2px solid var(--smartchat-border);
  }

  .smartchat-input:focus,
  .smartchat-trigger:focus,
  .smartchat-close:focus,
  .smartchat-send:focus {
    outline-width: 3px;
  }
}

/* Focus Visible */
.smartchat-trigger:focus-visible,
.smartchat-close:focus-visible,
.smartchat-send:focus-visible,
.smartchat-suggestion:focus-visible,
.smartchat-input:focus-visible {
  outline: 3px solid var(--smartchat-primary);
  outline-offset: 2px;
}

/* Screen Reader Only */
.smartchat-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* ========================================
   UTILITY CLASSES
   ======================================== */

.smartchat-hidden {
  display: none !important;
}

.smartchat-visible {
  display: block !important;
}

.smartchat-fade-in {
  animation: fadeIn 0.3s ease-out;
}

/* ========================================
   MESSAGE CONTENT FORMATTING
   ======================================== */

.smartchat-message-user {
  flex-direction: row-reverse;
  justify-content: flex-start;
}

.smartchat-message-assistant {
  flex-direction: row;
  justify-content: flex-start;
}

.smartchat-message-user .smartchat-message-bubble {
  background: var(--smartchat-user-bubble);
  color: #ffffff;
  border-bottom-right-radius: 4px;
  margin-left: auto;
}

.smartchat-message-assistant .smartchat-message-bubble {
  background: var(--smartchat-bot-bubble);
  color: var(--smartchat-text);
  border-bottom-left-radius: 4px;
}

.smartchat-message-text {
  line-height: 1.5;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.smartchat-message-time {
  font-size: 10px;
  opacity: 0.7;
  margin-top: 4px;
}

.smartchat-message-user .smartchat-message-time {
  text-align: right;
}

.smartchat-message-assistant .smartchat-message-time {
  text-align: left;
}

.smartchat-message-error {
  display: flex;
  justify-content: center;
  padding: 8px 16px;
}

.smartchat-error-content {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fef2f2;
  color: #991b1b;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
}

@media (prefers-color-scheme: dark) {
  .smartchat-error-content {
    background: #450a0a;
    color: #fecaca;
  }
}

.smartchat-message-bubble p {
  margin: 0 0 8px 0;
}

.smartchat-message-bubble p:last-child {
  margin-bottom: 0;
}

.smartchat-message-bubble a {
  color: inherit;
  text-decoration: underline;
}

.smartchat-message-bubble code {
  background: rgba(0, 0, 0, 0.1);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  font-size: 0.9em;
}

.smartchat-message-bubble pre {
  background: rgba(0, 0, 0, 0.1);
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 8px 0;
}

.smartchat-message-bubble pre code {
  background: none;
  padding: 0;
}

/* ========================================
   NOTIFICATION BADGE
   ======================================== */

.smartchat-notification-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  background: #ef4444;
  color: #ffffff;
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  border: 2px solid var(--smartchat-bg);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* ========================================
   LOADING STATES
   ======================================== */

.smartchat-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  color: var(--smartchat-text-muted);
}

.smartchat-spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--smartchat-border);
  border-top-color: var(--smartchat-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ========================================
   ERROR STATES
   ======================================== */

.smartchat-error {
  padding: 12px 16px;
  background: #fee2e2;
  border: 1px solid #fecaca;
  border-radius: 8px;
  color: #991b1b;
  font-size: 13px;
  margin: 8px 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

@media (prefers-color-scheme: dark) {
  .smartchat-error {
    background: #7f1d1d;
    border-color: #991b1b;
    color: #fecaca;
  }
}

/* ========================================
   END OF STYLESHEET
   ======================================== */
