/* Floating rag Widget with AI Portal Theme */

/* Floating container */
.rag-floating-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 1000;
  width: 400px;
  height: 600px;
  transition: all 0.3s ease;
}

.rag-floating-container.minimized {
  width: 60px;
  height: 60px;
}

/* Toggle button */
.rag-toggle-btn {
  position: absolute;
  top: -50px;
  right: 0;
  width: 60px;
  height: 60px;
  background: var(--primary-color, #0A6190);
  border: none;
  border-radius: 50%;
  color: white;
  font-size: 24px;
  cursor: pointer;
  box-shadow: var(--shadow-large, 0 20px 25px -5px rgba(15, 23, 42, 0.12));
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1002; /* Higher than resize handles */
}

.rag-toggle-btn:hover {
  background: var(--primary-dark, #084d73);
  transform: scale(1.05);
}

/* Widget styling to match AI Portal theme */
.rag-widget {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  background: var(--bg-primary, #ffffff);
  border: 1px solid var(--border-color, #e2e8f0);
  border-radius: 12px;
  box-shadow: var(--shadow-large, 0 20px 25px -5px rgba(15, 23, 42, 0.12));
  font-family: var(--font-family, 'Inter', -apple-system, BlinkMacSystemFont, sans-serif);
  font-size: var(--font-size-base, 1rem);
  overflow: hidden;
  opacity: 1;
  transform: translateY(0);
  transition: all 0.3s ease;
}

.rag-floating-container.minimized .rag-widget {
  opacity: 0;
  transform: translateY(20px);
  pointer-events: none;
}

.rag-widget * {
  box-sizing: border-box;
}

/* Header with AI Portal theme */
.rag-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--spacing-md, 1rem) var(--spacing-lg, 1.5rem);
  background: var(--primary-color, #0A6190);
  color: white;
  border-radius: 12px 12px 0 0;
}

.rag-title {
  font-weight: 600;
  font-size: var(--font-size-lg, 1.125rem);
  margin: 0;
}

.rag-mode-indicator {
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: var(--font-size-xs, 0.75rem);
  font-weight: 500;
}

/* Messages Container */
.rag-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--spacing-md, 1rem);
  background: var(--bg-primary, #ffffff);
}

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

.rag-messages::-webkit-scrollbar-track {
  background: var(--bg-tertiary, #f1f5f9);
}

.rag-messages::-webkit-scrollbar-thumb {
  background: var(--border-color, #e2e8f0);
  border-radius: 3px;
}

.rag-messages::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted, #94a3b8);
}

/* Message bubbles */
.rag-message {
  margin-bottom: var(--spacing-md, 1rem);
  display: flex;
  align-items: flex-start;
  gap: var(--spacing-sm, 0.75rem);
}

.rag-message.user {
  flex-direction: row-reverse;
}

.rag-message-content {
  max-width: 80%;
  padding: var(--spacing-sm, 0.75rem) var(--spacing-md, 1rem);
  border-radius: 12px;
  line-height: 1.5;
  font-size: var(--font-size-sm, 0.875rem);
}

.rag-message.user .rag-message-content {
  background: var(--primary-color, #0A6190);
  color: white;
  border-bottom-right-radius: 4px;
}

.rag-message.assistant .rag-message-content {
  background: var(--bg-tertiary, #f1f5f9);
  color: var(--text-primary, #0f172a);
  border: 1px solid var(--border-color, #e2e8f0);
  border-bottom-left-radius: 4px;
}

/* Input area */
.rag-input-container {
  padding: var(--spacing-md, 1rem);
  background: var(--bg-primary, #ffffff);
  border-top: 1px solid var(--border-color, #e2e8f0);
}

.rag-input-group {
  display: flex;
  gap: var(--spacing-sm, 0.75rem);
  align-items: flex-end;
}

.rag-input {
  flex: 1;
  padding: var(--spacing-sm, 0.75rem) var(--spacing-md, 1rem);
  border: 1px solid var(--border-color, #e2e8f0);
  border-radius: 8px;
  font-size: var(--font-size-sm, 0.875rem);
  font-family: inherit;
  resize: none;
  min-height: 40px;
  max-height: 120px;
  background: var(--bg-primary, #ffffff);
  color: var(--text-primary, #0f172a);
  transition: border-color 0.2s ease;
}

.rag-input:focus {
  outline: none;
  border-color: var(--primary-color, #0A6190);
  box-shadow: 0 0 0 3px rgba(10, 97, 144, 0.1);
}

.rag-send-btn {
  padding: var(--spacing-sm, 0.75rem);
  background: var(--primary-color, #0A6190);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: var(--font-size-base, 1rem);
  min-width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.rag-send-btn:hover:not(:disabled) {
  background: var(--primary-dark, #084d73);
  transform: translateY(-1px);
}

.rag-send-btn:disabled {
  background: var(--text-muted, #94a3b8);
  cursor: not-allowed;
  transform: none;
}

/* Login form */
.rag-login-form {
  padding: var(--spacing-xl, 2rem);
  background: var(--bg-primary, #ffffff);
  display: flex;
  flex-direction: column;
  gap: var(--spacing-md, 1rem);
  height: 100%;
  justify-content: center;
}

.rag-login-form h3 {
  color: var(--text-primary, #0f172a);
  font-size: var(--font-size-xl, 1.25rem);
  margin-bottom: var(--spacing-md, 1rem);
  text-align: center;
}

.rag-login-form input {
  padding: var(--spacing-sm, 0.75rem) var(--spacing-md, 1rem);
  border: 1px solid var(--border-color, #e2e8f0);
  border-radius: 8px;
  font-size: var(--font-size-sm, 0.875rem);
  font-family: inherit;
  background: var(--bg-primary, #ffffff);
  color: var(--text-primary, #0f172a);
  transition: border-color 0.2s ease;
}

.rag-login-form input:focus {
  outline: none;
  border-color: var(--primary-color, #0A6190);
  box-shadow: 0 0 0 3px rgba(10, 97, 144, 0.1);
}

.rag-login-form button {
  padding: var(--spacing-sm, 0.75rem) var(--spacing-md, 1rem);
  background: var(--primary-color, #0A6190);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: var(--font-size-sm, 0.875rem);
  font-weight: 500;
  transition: all 0.2s ease;
}

.rag-login-form button:hover:not(:disabled) {
  background: var(--primary-dark, #084d73);
  transform: translateY(-1px);
}

/* Loading indicator */
.rag-loading {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm, 0.75rem);
  color: var(--text-secondary, #475569);
  font-size: var(--font-size-sm, 0.875rem);
  padding: var(--spacing-sm, 0.75rem) var(--spacing-md, 1rem);
  background: var(--bg-tertiary, #f1f5f9);
  border: 1px solid var(--border-color, #e2e8f0);
  border-radius: 12px;
  border-bottom-left-radius: 4px;
  max-width: 80%;
}

.rag-loading-dots {
  display: flex;
  gap: 3px;
}

.rag-loading-dot {
  width: 6px;
  height: 6px;
  background: var(--primary-color, #0A6190);
  border-radius: 50%;
  animation: rag-bounce 1.4s ease-in-out infinite both;
}

.rag-loading-dot:nth-child(1) { animation-delay: -0.32s; }
.rag-loading-dot:nth-child(2) { animation-delay: -0.16s; }
.rag-loading-dot:nth-child(3) { animation-delay: 0s; }

.rag-loading span {
  font-weight: 500;
  color: var(--text-secondary, #475569);
}

@keyframes rag-bounce {
  0%, 80%, 100% {
    transform: scale(0);
    opacity: 0.5;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

/* Responsive design */
@media (max-width: 768px) {
  .rag-floating-container {
    width: 320px;
    height: 500px;
    bottom: 10px;
    right: 10px;
  }
  
  .rag-toggle-btn {
    width: 50px;
    height: 50px;
    font-size: 20px;
    top: -40px;
  }
}

@media (max-width: 480px) {
  .rag-floating-container {
    width: 300px;
    height: 450px;
  }
}

/* Resize handles */
.rag-resize-handle {
  position: absolute;
  background: rgba(10, 97, 144, 0.1);
  transition: background-color 0.2s ease;
  z-index: 1001;
  pointer-events: auto;
}

.rag-resize-handle:hover {
  background: rgba(10, 97, 144, 0.2);
}

.rag-floating-container.rag-resizing .rag-resize-handle {
  background: rgba(10, 97, 144, 0.3);
}

/* Corner handles */
.rag-resize-se {
  bottom: 0;
  right: 0;
  width: 12px;
  height: 12px;
  cursor: se-resize;
  border-radius: 0 0 12px 0;
}

.rag-resize-sw {
  bottom: 0;
  left: 0;
  width: 12px;
  height: 12px;
  cursor: sw-resize;
  border-radius: 0 0 0 12px;
}

.rag-resize-ne {
  top: 0;
  right: 0;
  width: 12px;
  height: 12px;
  cursor: ne-resize;
  border-radius: 0 12px 0 0;
  /* Create space for toggle button */
  clip-path: polygon(0 0, 100% 0, 100% 50%, 0 100%);
}

.rag-resize-nw {
  top: 0;
  left: 0;
  width: 12px;
  height: 12px;
  cursor: nw-resize;
  border-radius: 12px 0 0 0;
}

/* Edge handles */
.rag-resize-n {
  top: 0;
  left: 12px;
  right: 12px;
  height: 6px;
  cursor: n-resize;
}

.rag-resize-s {
  bottom: 0;
  left: 12px;
  right: 12px;
  height: 6px;
  cursor: s-resize;
}

.rag-resize-e {
  right: 0;
  top: 12px;
  bottom: 12px;
  width: 6px;
  cursor: e-resize;
  /* Reduce height to avoid toggle button */
  max-height: calc(100% - 70px);
}

.rag-resize-w {
  left: 0;
  top: 12px;
  bottom: 12px;
  width: 6px;
  cursor: w-resize;
}

/* Hide resize handles when minimized */
.rag-floating-container.minimized .rag-resize-handle {
  display: none;
}

/* Ensure toggle button area is clear of resize handles */
.rag-toggle-btn {
  pointer-events: auto !important;
  z-index: 1002 !important;
}

/* Create exclusion zone for toggle button */
.rag-floating-container::before {
  content: '';
  position: absolute;
  top: -60px;
  right: -10px;
  width: 80px;
  height: 80px;
  pointer-events: none;
  z-index: 1003;
}

/* Visual feedback during resize */
.rag-floating-container.rag-resizing {
  transition: none;
}

.rag-floating-container.rag-resizing .rag-widget {
  transition: none;
}

/* Resize handles visibility on hover */
.rag-floating-container:not(.minimized):hover .rag-resize-handle {
  opacity: 1;
}

.rag-resize-handle {
  opacity: 0;
  transition: opacity 0.2s ease, background-color 0.2s ease;
}

.rag-floating-container:not(.minimized).rag-resizing .rag-resize-handle {
  opacity: 1;
}

/* Mobile resize handles - make them larger for touch */
@media (max-width: 768px) {
  .rag-resize-se,
  .rag-resize-sw,
  .rag-resize-ne,
  .rag-resize-nw {
    width: 20px;
    height: 20px;
  }
  
  .rag-resize-n,
  .rag-resize-s {
    height: 12px;
    left: 20px;
    right: 20px;
  }
  
  .rag-resize-e,
  .rag-resize-w {
    width: 12px;
    top: 20px;
    bottom: 20px;
  }
  
  .rag-resize-handle {
    opacity: 0.3;
  }
}