/**
 * OpenLibx402 RAG Chatbot Widget Styles
 */

/* Floating Action Button */
.chatbot-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, #7E3FF2 0%, #5C68E8 50%, #44E0D6 100%);
  color: white;
  border: none;
  font-size: 28px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  transition: transform 0.2s, box-shadow 0.2s;
}

.chatbot-fab:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

/* Chat Widget Container */
.chatbot-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 400px;
  height: 600px;
  max-width: calc(100vw - 48px);
  max-height: calc(100vh - 48px);
  background: white;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  display: none;
  flex-direction: column;
  z-index: 1000;
  overflow: hidden;
}

.chatbot-widget-open {
  display: flex;
}

/* Header */
.chatbot-header {
  background: linear-gradient(135deg, #7E3FF2 0%, #5C68E8 50%, #44E0D6 100%);
  color: white;
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chatbot-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  flex: 1;
}

.chatbot-header button {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 16px;
  margin-left: 8px;
  transition: background 0.2s;
}

.chatbot-header button:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* Rate Limit Info */
.chatbot-rate-limit {
  padding: 8px 16px;
  background: #f8f9fa;
  border-bottom: 1px solid #e9ecef;
  font-size: 13px;
}

.rate-limit-info {
  color: #28a745;
}

.rate-limit-warning {
  color: #dc3545;
}

.rate-limit-warning a {
  color: #dc3545;
  text-decoration: underline;
  font-weight: 600;
}

/* Messages Container */
.chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: #f8f9fa;
}

/* Individual Message */
.chatbot-message {
  margin-bottom: 16px;
  max-width: 85%;
  animation: fadeIn 0.3s ease-in;
}

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

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

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

.chatbot-message-content {
  padding: 12px 16px;
  border-radius: 12px;
  word-wrap: break-word;
  line-height: 1.6;
}

/* Markdown Styling */
.chatbot-message-content p {
  margin: 0;
  margin-bottom: 8px;
}

.chatbot-message-content p:last-child {
  margin-bottom: 0;
}

.chatbot-message-content code {
  background: rgba(0, 0, 0, 0.05);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Roboto Mono', 'Courier New', monospace;
  font-size: 0.9em;
}

.chatbot-message-user .chatbot-message-content code {
  background: rgba(255, 255, 255, 0.2);
}

.chatbot-message-content pre {
  margin: 8px 0;
  padding: 12px;
  background: #2d2d2d;
  border-radius: 6px;
  overflow-x: auto;
}

.chatbot-message-content pre code {
  background: none;
  padding: 0;
  color: #f8f8f2;
  font-size: 0.85em;
  line-height: 1.5;
}

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

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

.chatbot-message-content a {
  color: #7E3FF2;
  text-decoration: underline;
}

.chatbot-message-user .chatbot-message-content a {
  color: rgba(255, 255, 255, 0.9);
}

.chatbot-message-user .chatbot-message-content {
  background: linear-gradient(135deg, #7E3FF2 0%, #5C68E8 50%, #44E0D6 100%);
  color: white;
  border-bottom-right-radius: 4px;
}

.chatbot-message-assistant .chatbot-message-content {
  background: white;
  color: #333;
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

/* Sources */
.chatbot-sources {
  margin-top: 8px;
  padding: 8px 12px;
  background: #e9ecef;
  border-radius: 6px;
  font-size: 12px;
}

.chatbot-sources strong {
  display: block;
  margin-bottom: 4px;
  color: #495057;
}

.chatbot-sources ul {
  margin: 0;
  padding-left: 20px;
}

.chatbot-sources li {
  margin-bottom: 4px;
  color: #6c757d;
}

.chatbot-sources a {
  color: #7E3FF2;
  text-decoration: none;
  font-weight: 500;
}

.chatbot-sources a:hover {
  text-decoration: underline;
}

/* Loading Indicator */
.chatbot-loading {
  padding: 12px 16px;
  background: white;
  border-radius: 12px;
  border-bottom-left-radius: 4px;
  color: #6c757d;
  font-style: italic;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.chatbot-loading::after {
  content: '...';
  animation: dots 1.5s steps(4, end) infinite;
}

@keyframes dots {
  0%, 20% {
    content: '.';
  }
  40% {
    content: '..';
  }
  60%, 100% {
    content: '...';
  }
}

/* Input Container */
.chatbot-input-container {
  padding: 16px;
  background: white;
  border-top: 1px solid #e9ecef;
  display: flex;
  gap: 8px;
}

.chatbot-input-container input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid #ced4da;
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.chatbot-input-container input:focus {
  border-color: #7E3FF2;
}

.chatbot-input-container button {
  padding: 10px 20px;
  background: linear-gradient(135deg, #7E3FF2 0%, #5C68E8 50%, #44E0D6 100%);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.chatbot-input-container button:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(126, 63, 242, 0.3);
}

.chatbot-input-container button:active {
  transform: translateY(0);
}

/* Mobile Responsive */
@media (max-width: 768px) {
  .chatbot-widget {
    width: calc(100vw - 32px);
    height: calc(100vh - 32px);
    bottom: 16px;
    right: 16px;
  }

  .chatbot-fab {
    bottom: 16px;
    right: 16px;
  }
}

/* Payment Modal */
.payment-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  z-index: 10000;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

.payment-modal-content {
  background: white;
  border-radius: 16px;
  width: 90%;
  max-width: 450px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
  animation: modalSlideIn 0.3s ease-out;
}

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

.payment-modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid #e9ecef;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.payment-modal-header h3 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  color: #333;
}

.payment-modal-close {
  background: #f8f9fa;
  border: none;
  color: #6c757d;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 18px;
  transition: background 0.2s;
}

.payment-modal-close:hover {
  background: #e9ecef;
}

.payment-modal-body {
  padding: 24px;
}

.payment-info {
  text-align: center;
  margin-bottom: 24px;
}

.payment-info p {
  margin: 8px 0;
  color: #495057;
  font-size: 15px;
}

.payment-info strong {
  color: #7E3FF2;
  font-size: 18px;
}

.payment-details {
  background: #f8f9fa;
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 20px;
}

.payment-detail-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  font-size: 14px;
}

.payment-detail-row:not(:last-child) {
  border-bottom: 1px solid #e9ecef;
}

.payment-detail-row span:first-child {
  color: #6c757d;
}

.payment-detail-row span:last-child {
  color: #333;
  font-weight: 500;
}

.payment-status {
  min-height: 24px;
  margin-bottom: 16px;
  padding: 12px;
  border-radius: 8px;
  font-size: 14px;
  text-align: center;
}

.payment-status-info {
  background: #e7f3ff;
  color: #0066cc;
}

.payment-status-success {
  background: #d4edda;
  color: #155724;
}

.payment-status-success a {
  color: #7E3FF2;
  text-decoration: underline;
  font-weight: 600;
  transition: color 0.2s;
}

.payment-status-success a:hover {
  color: #5C68E8;
}

.payment-status-error {
  background: #f8d7da;
  color: #721c24;
}

.payment-button {
  width: 100%;
  padding: 14px 24px;
  background: linear-gradient(135deg, #7E3FF2 0%, #5C68E8 50%, #44E0D6 100%);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.payment-button:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(126, 63, 242, 0.4);
}

.payment-button:active:not(:disabled) {
  transform: translateY(0);
}

.payment-button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.payment-note {
  margin-top: 16px;
  text-align: center;
  color: #6c757d;
}

.payment-note small {
  font-size: 12px;
}

/* Dark Mode Support (optional) */
@media (prefers-color-scheme: dark) {
  .chatbot-widget {
    background: #1e1e1e;
  }

  .chatbot-messages {
    background: #2d2d2d;
  }

  .chatbot-message-assistant .chatbot-message-content {
    background: #3a3a3a;
    color: #e0e0e0;
  }

  .chatbot-sources {
    background: #2a2a2a;
  }

  .chatbot-sources strong {
    color: #b0b0b0;
  }

  .chatbot-sources li {
    color: #888;
  }

  .chatbot-sources a {
    color: #44E0D6;
  }

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

  .chatbot-message-content pre {
    background: #1a1a1a;
  }

  .chatbot-message-content a {
    color: #44E0D6;
  }

  .chatbot-loading {
    background: #3a3a3a;
    color: #888;
  }

  .chatbot-input-container {
    background: #1e1e1e;
    border-top-color: #3a3a3a;
  }

  .chatbot-input-container input {
    background: #2d2d2d;
    border-color: #3a3a3a;
    color: #e0e0e0;
  }

  .chatbot-rate-limit {
    background: #2d2d2d;
    border-bottom-color: #3a3a3a;
  }

  .payment-modal-content {
    background: #1e1e1e;
  }

  .payment-modal-header {
    border-bottom-color: #3a3a3a;
  }

  .payment-modal-header h3 {
    color: #e0e0e0;
  }

  .payment-modal-close {
    background: #2d2d2d;
    color: #b0b0b0;
  }

  .payment-modal-close:hover {
    background: #3a3a3a;
  }

  .payment-info p {
    color: #b0b0b0;
  }

  .payment-details {
    background: #2d2d2d;
  }

  .payment-detail-row {
    border-bottom-color: #3a3a3a;
  }

  .payment-detail-row span:first-child {
    color: #888;
  }

  .payment-detail-row span:last-child {
    color: #e0e0e0;
  }

  .payment-status-success a {
    color: #44E0D6;
  }

  .payment-status-success a:hover {
    color: #6BF1C0;
  }

  .payment-note {
    color: #888;
  }
}
