/* ============================================================
   Modern UI Components - shadcn-inspired styling
   ============================================================ */

:root {
  /* Colors */
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --primary-light: #60a5fa;
  --secondary: #8b5cf6;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --info: #0ea5e9;
  
  /* Neutrals */
  --bg: #ffffff;
  --bg-secondary: #f9fafb;
  --border: #e5e7eb;
  --text: #1f2937;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  
  /* Spacing */
  --gap-xs: 0.25rem;
  --gap-sm: 0.5rem;
  --gap-md: 1rem;
  --gap-lg: 1.5rem;
  --gap-xl: 2rem;
  
  /* Border Radius */
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  
  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

/* ============================================================
   Button Component
   ============================================================ */

.kb-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--gap-sm);
  padding: var(--gap-sm) var(--gap-md);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 200ms ease;
  background: var(--primary);
  color: white;
}

.kb-button:hover {
  background: var(--primary-dark);
  box-shadow: var(--shadow-md);
}

.kb-button:active {
  transform: scale(0.98);
}

.kb-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.kb-button.secondary {
  background: var(--bg-secondary);
  color: var(--text);
  border-color: var(--border);
}

.kb-button.secondary:hover {
  background: var(--border);
}

.kb-button.danger {
  background: var(--danger);
}

.kb-button.danger:hover {
  background: #dc2626;
}

/* ============================================================
   File Upload Component
   ============================================================ */

.kb-upload-container {
  display: flex;
  flex-direction: column;
  gap: var(--gap-md);
}

.kb-upload-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--gap-xl);
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-secondary);
  cursor: pointer;
  transition: all 200ms ease;
  min-height: 200px;
}

.kb-upload-zone:hover {
  border-color: var(--primary);
  background: #f0f9ff;
}

.kb-upload-zone.dragging {
  border-color: var(--primary);
  background: #eff6ff;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.kb-upload-icon {
  font-size: 2.5rem;
  color: var(--primary);
  margin-bottom: var(--gap-md);
}

.kb-upload-text {
  text-align: center;
}

.kb-upload-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: var(--gap-sm);
}

.kb-upload-subtitle {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.kb-file-list {
  display: flex;
  flex-direction: column;
  gap: var(--gap-sm);
}

.kb-file-item {
  display: flex;
  align-items: center;
  gap: var(--gap-md);
  padding: var(--gap-md);
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

.kb-file-icon {
  font-size: 1.5rem;
  color: var(--info);
}

.kb-file-info {
  flex: 1;
}

.kb-file-name {
  font-weight: 500;
  color: var(--text);
  margin-bottom: var(--gap-xs);
}

.kb-file-size {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.kb-file-progress {
  width: 100%;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-top: var(--gap-xs);
}

.kb-progress-bar {
  height: 100%;
  background: var(--success);
  transition: width 200ms ease;
}

.kb-file-status {
  display: flex;
  align-items: center;
  gap: var(--gap-sm);
  font-size: 0.75rem;
}

.kb-status-pending {
  color: var(--warning);
}

.kb-status-success {
  color: var(--success);
}

.kb-status-error {
  color: var(--danger);
}

/* ============================================================
   Chat Interface
   ============================================================ */

.kb-chat-container {
  display: flex;
  flex-direction: column;
  height: 600px;
  min-height: 500px;
  max-height: 80vh;
  background: var(--bg);
  border: none;
  border-radius: 0;
  overflow: hidden;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.kb-chat-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.kb-mode-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--gap-sm);
  padding: 0.5rem 1rem;
  background: rgba(255, 255, 255, 0.2);
  color: white;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 600;
  backdrop-filter: blur(10px);
}

.kb-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: var(--gap-md);
  background: #f9fafb;
}

.kb-chat-messages::-webkit-scrollbar {
  width: 8px;
}

.kb-chat-messages::-webkit-scrollbar-track {
  background: #f1f1f1;
}

.kb-chat-messages::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}

.kb-chat-messages::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

.kb-message {
  display: flex;
  gap: var(--gap-md);
  animation: slideIn 300ms ease;
}

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

.kb-message.user {
  justify-content: flex-end;
}

.kb-message-content {
  max-width: 75%;
  padding: 1rem 1.25rem;
  border-radius: 1rem;
  word-wrap: break-word;
  line-height: 1.6;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.kb-message.user .kb-message-content {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  margin-left: auto;
}

.kb-message.assistant .kb-message-content {
  background: white;
  color: var(--text);
  border: 1px solid #e5e7eb;
  margin-right: auto;
}

.kb-message-timestamp {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.kb-sources {
  margin-top: var(--gap-sm);
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.kb-source-toggle {
  cursor: pointer;
  color: var(--info);
  text-decoration: underline;
}

.kb-sources-list {
  margin-top: var(--gap-sm);
  display: flex;
  flex-direction: column;
  gap: var(--gap-sm);
}

.kb-source-item {
  padding: var(--gap-sm);
  background: var(--bg-secondary);
  border-left: 3px solid var(--info);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
}

.kb-chat-input-area {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 0.75rem;
  background: white;
  align-items: flex-end;
}

.kb-chat-input {
  flex: 1;
  padding: 0.75rem 1rem;
  border: 2px solid #e5e7eb;
  border-radius: 0.75rem;
  font-size: 0.9375rem;
  font-family: inherit;
  resize: none;
  max-height: 120px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.kb-chat-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.kb-send-button {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  height: 48px;
  padding: 0.75rem 1.25rem;
  border-radius: 0.75rem;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 2px 4px rgba(102, 126, 234, 0.3);
}

.kb-send-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(102, 126, 234, 0.4);
}

.kb-send-button:active {
  transform: translateY(0);
}

.kb-send-button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.kb-loading {
  display: inline-block;
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ============================================================
   Floating Chat Button
   ============================================================ */

.floating-chat-button {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  transition: all 0.3s ease;
  font-size: 1.5rem;
}

.floating-chat-button.bottom-left {
  right: auto;
  left: 2rem;
}

.floating-chat-button:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 20px rgba(102, 126, 234, 0.5);
}

.floating-chat-button:active {
  transform: scale(0.95);
}

.floating-chat-button.active {
  background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
}

.floating-chat-label {
  display: none;
}

.floating-chat-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  background: #ef4444;
  color: white;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  border: 2px solid white;
}

.floating-chat-dialog-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  z-index: 1000;
  padding: 1rem;
  animation: fadeIn 200ms ease;
}

.floating-chat-dialog-overlay.bottom-left {
  justify-content: flex-start;
}

.floating-chat-dialog {
  background: white;
  border-radius: 1rem 1rem 0 0;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
  width: 100%;
  max-width: 420px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideUp 300ms ease;
  position: relative;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(100%);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.floating-chat-dialog-header {
  padding: 1rem 1.5rem;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: none;
}

.floating-chat-dialog-title {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-weight: 600;
  font-size: 1.125rem;
}

.floating-chat-dialog-title i {
  font-size: 1.25rem;
}

.floating-chat-close {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s;
}

.floating-chat-close:hover {
  background: rgba(255, 255, 255, 0.3);
}

.floating-chat-dialog-body {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.floating-chat-dialog-body .kb-chat-container {
  height: 100%;
  min-height: 500px;
  max-height: calc(85vh - 60px);
  border-radius: 0;
  box-shadow: none;
  border: none;
}

.floating-chat-dialog-body .kb-chat-header {
  border-radius: 0;
}

.floating-chat-dialog-body .kb-chat-messages {
  flex: 1;
  min-height: 0;
}

.floating-chat-dialog-body .kb-chat-container {
  height: 100%;
  min-height: 500px;
  max-height: calc(85vh - 60px);
  border-radius: 0;
  box-shadow: none;
}

/* Mobile responsive */
@media (max-width: 768px) {
  .floating-chat-dialog {
    max-width: 100%;
    max-height: 90vh;
    border-radius: 1rem 1rem 0 0;
  }

  .floating-chat-button {
    width: 56px;
    height: 56px;
    bottom: 1.5rem;
    right: 1.5rem;
    font-size: 1.25rem;
  }

  .floating-chat-button.bottom-left {
    left: 1.5rem;
  }
}

/* ============================================================
   Dialog / Modal
   ============================================================ */

.kb-dialog-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 200ms ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.kb-dialog {
  background: var(--bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp 300ms ease;
}

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

.kb-dialog-header {
  padding: var(--gap-lg);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.kb-dialog-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text);
}

.kb-dialog-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-secondary);
  transition: color 200ms ease;
}

.kb-dialog-close:hover {
  color: var(--text);
}

.kb-dialog-content {
  padding: var(--gap-lg);
}

.kb-dialog-footer {
  padding: var(--gap-lg);
  border-top: 1px solid var(--border);
  display: flex;
  gap: var(--gap-md);
  justify-content: flex-end;
}

/* ============================================================
   Toast Notifications
   ============================================================ */

.kb-toast-container {
  position: fixed;
  bottom: var(--gap-md);
  right: var(--gap-md);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: var(--gap-sm);
}

.kb-toast {
  padding: var(--gap-md) var(--gap-lg);
  border-radius: var(--radius-md);
  background: white;
  color: var(--text);
  box-shadow: var(--shadow-lg);
  display: flex;
  gap: var(--gap-md);
  align-items: center;
  animation: slideInRight 300ms ease;
  max-width: 400px;
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.kb-toast.success {
  border-left: 4px solid var(--success);
}

.kb-toast.error {
  border-left: 4px solid var(--danger);
}

.kb-toast.warning {
  border-left: 4px solid var(--warning);
}

.kb-toast.info {
  border-left: 4px solid var(--info);
}

/* ============================================================
   Card Component
   ============================================================ */

.kb-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--gap-lg);
  transition: all 200ms ease;
}

.kb-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--primary-light);
}

.kb-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--gap-md);
  padding-bottom: var(--gap-md);
  border-bottom: 1px solid var(--border);
}

.kb-card-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text);
}

.kb-card-content {
  color: var(--text-secondary);
  font-size: 0.875rem;
}

/* ============================================================
   Chatbot Toggle Switch
   ============================================================ */

.chatbot-toggle-switch {
  position: relative;
  display: inline-block;
  width: 60px;
  height: 34px;
}

.chatbot-toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.chatbot-toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  transition: 0.4s;
  border-radius: 34px;
}

.chatbot-toggle-slider:before {
  position: absolute;
  content: "";
  height: 26px;
  width: 26px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  transition: 0.4s;
  border-radius: 50%;
}

.chatbot-toggle-switch input:checked + .chatbot-toggle-slider {
  background-color: var(--primary-color, #3b82f6);
}

.chatbot-toggle-switch input:focus + .chatbot-toggle-slider {
  box-shadow: 0 0 1px var(--primary-color, #3b82f6);
}

.chatbot-toggle-switch input:checked + .chatbot-toggle-slider:before {
  transform: translateX(26px);
}

/* ============================================================
   Knowledge Base Setup Section
   ============================================================ */

.kb-setup-toggle {
  transition: all 0.2s ease;
}

.kb-setup-toggle:hover {
  background: #f3f4f6 !important;
}

.kb-setup-content {
  animation: slideDown 0.3s ease-out;
}

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

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 768px) {
  .kb-upload-zone {
    padding: var(--gap-lg);
  }
  
  .kb-message-content {
    max-width: 100%;
  }
  
  .kb-dialog {
    max-width: 95%;
  }
  
  .kb-chat-container {
    height: 400px;
  }
}
