/**
 * AI Assistant Sidebar Styles
 */

/* =========================================================================
   AI Toggle Button in Action Bar
   ========================================================================= */

.btn-ai-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: white;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-ai-toggle:hover {
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.btn-ai-toggle.active {
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
}

.ai-toggle-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
}

.ai-toggle-text {
  font-size: 0.85rem;
}

/* =========================================================================
   AI Sidebar Container
   ========================================================================= */

.ai-sidebar {
  display: flex;
  flex-direction: row;
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  overflow: hidden;
  transition: width 0.3s ease, min-width 0.3s ease, opacity 0.3s ease;
  height: 100%;
  width: 380px;
  min-width: 380px;
}

/* Collapsed/Hidden state - completely hidden */
.ai-sidebar.collapsed {
  width: 0;
  min-width: 0;
  border: none;
  opacity: 0;
  pointer-events: none;
}

/* Hide the collapsed strip - we don't need it anymore */
.ai-sidebar-collapsed-strip {
  display: none;
}

/* =========================================================================
   Sidebar Content (Expanded)
   ========================================================================= */

.ai-sidebar-content {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  height: 100%;
}

/* Header */
.ai-sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: white;
  flex-shrink: 0;
}

.ai-sidebar-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 14px;
}

.ai-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 5px;
  font-size: 11px;
  font-weight: 700;
}

.ai-sidebar-actions {
  display: flex;
  gap: 4px;
}

.ai-header-btn {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: white;
  width: 30px;
  height: 30px;
  border-radius: 5px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

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

/* Status Bar */
.ai-sidebar-status {
  padding: 8px 14px;
  background: rgba(245, 158, 11, 0.1);
  border-bottom: 1px solid var(--border-color);
  font-size: 12px;
  flex-shrink: 0;
}

.ai-status-warning {
  color: #f59e0b;
}

.ai-status-link {
  background: none;
  border: none;
  color: var(--accent-color);
  cursor: pointer;
  text-decoration: underline;
  font-size: inherit;
  padding: 0;
  margin-left: 4px;
}

/* Messages Area */
.ai-sidebar-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

/* Input Area */
.ai-sidebar-input {
  display: flex;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--border-color);
  background: var(--bg-light);
  flex-shrink: 0;
}

.ai-input-field {
  flex: 1;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  resize: none;
  background: var(--bg-dark);
  color: var(--text-primary);
  font-family: inherit;
  max-height: 100px;
  min-height: 40px;
}

.ai-input-field:focus {
  outline: none;
  border-color: #6366f1;
}

.ai-send-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 8px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, opacity 0.2s;
  flex-shrink: 0;
}

.ai-send-btn:hover {
  transform: scale(1.05);
}

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

/* =========================================================================
   Message Styles
   ========================================================================= */

.ai-message {
  display: flex;
  flex-direction: column;
  max-width: 95%;
}

.ai-message-user {
  align-self: flex-end;
}

.ai-message-assistant {
  align-self: flex-start;
}

.ai-message-content {
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.5;
}

.ai-message-content p {
  margin: 0 0 8px 0;
}

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

.ai-message-user .ai-message-content {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: white;
  border-bottom-right-radius: 4px;
}

.ai-message-assistant .ai-message-content {
  background: var(--bg-light);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

.ai-message-content code {
  background: rgba(0, 0, 0, 0.15);
  padding: 2px 5px;
  border-radius: 3px;
  font-family: monospace;
  font-size: 12px;
}

.ai-message-content pre {
  background: rgba(0, 0, 0, 0.15);
  padding: 8px;
  border-radius: 5px;
  overflow-x: auto;
  margin: 6px 0;
}

.ai-message-content ul {
  margin: 6px 0;
  padding-left: 18px;
}

.ai-message-content li {
  margin: 3px 0;
  font-size: 12px;
}

/* Typing Indicator */
.ai-typing .ai-message-content {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
}

.ai-typing-dot {
  width: 7px;
  height: 7px;
  background: var(--text-secondary);
  border-radius: 50%;
  animation: aiTypingBounce 1.4s infinite ease-in-out both;
}

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

@keyframes aiTypingBounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* =========================================================================
   Form Data Card (AI suggestions)
   ========================================================================= */

.ai-form-card {
  margin-top: 10px;
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  overflow: hidden;
}

.ai-form-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  background: rgba(99, 102, 241, 0.1);
  border-bottom: 1px solid var(--border-color);
}

.ai-form-card-title {
  font-weight: 600;
  font-size: 12px;
}

.ai-confidence-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 3px;
  text-transform: uppercase;
}

.ai-confidence-badge.confidence-high {
  background: rgba(76, 175, 80, 0.2);
  color: #4CAF50;
}

.ai-confidence-badge.confidence-medium {
  background: rgba(255, 152, 0, 0.2);
  color: #FF9800;
}

.ai-confidence-badge.confidence-low {
  background: rgba(244, 67, 54, 0.2);
  color: #F44336;
}

.ai-form-card-body {
  padding: 10px;
}

.ai-form-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
  font-size: 12px;
}

.ai-form-label {
  color: var(--text-secondary);
}

.ai-form-value {
  font-weight: 500;
  font-family: monospace;
  font-size: 11px;
}

.ai-form-card-actions {
  display: flex;
  gap: 6px;
  padding: 10px;
  border-top: 1px solid var(--border-color);
}

.ai-form-card-actions .btn {
  font-size: 12px;
  padding: 6px 10px;
}

.ai-form-source {
  padding: 6px 10px;
  font-size: 10px;
  color: var(--text-secondary);
  background: rgba(0, 0, 0, 0.1);
}

/* =========================================================================
   Credentials List (Settings Modal)
   ========================================================================= */

.ai-credentials-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ai-credentials-empty {
  padding: 1rem;
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.ai-credential-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: var(--bg-light);
  border: 1px solid var(--border-color);
  border-radius: 6px;
}

.ai-credential-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ai-credential-name {
  font-weight: 500;
  font-size: 13px;
}

.ai-credential-hint {
  font-size: 11px;
  color: var(--text-secondary);
  font-family: monospace;
}

.ai-credential-actions {
  display: flex;
  gap: 6px;
}

.ai-credential-actions .btn {
  padding: 4px 8px;
  font-size: 11px;
}

/* =========================================================================
   Light Theme Overrides
   ========================================================================= */

[data-theme="light"] .ai-sidebar {
  background: #ffffff;
}

[data-theme="light"] .ai-message-assistant .ai-message-content {
  background: #f3f4f6;
}

[data-theme="light"] .ai-input-field {
  background: #ffffff;
}

[data-theme="light"] .ai-sidebar-input {
  background: #f9fafb;
}

[data-theme="light"] .ai-form-card {
  background: #ffffff;
}

[data-theme="light"] .ai-credential-row {
  background: #f9fafb;
}

[data-theme="light"] .ai-sidebar-collapsed-strip {
  background: linear-gradient(180deg, rgba(99, 102, 241, 0.05), transparent);
}

/* =========================================================================
   Streaming Message Styles
   ========================================================================= */

.ai-message-streaming {
  position: relative;
}

.ai-streaming-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.1), rgba(139, 92, 246, 0.1));
  border-radius: 8px;
  margin-bottom: 8px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  animation: pulse-subtle 2s ease-in-out infinite;
}

@keyframes pulse-subtle {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.7;
  }
}

.ai-status-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(99, 102, 241, 0.3);
  border-top-color: #6366f1;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

.ai-status-text {
  flex: 1;
}

.ai-message-streaming .ai-message-content {
  opacity: 0.9;
}

/* Tool call indicators */
.ai-streaming-status[data-tool="true"] {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.1), rgba(5, 150, 105, 0.1));
}

.ai-streaming-status[data-tool="true"] .ai-status-spinner {
  border-color: rgba(16, 185, 129, 0.3);
  border-top-color: #10b981;
}

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

@media (max-width: 1200px) {
  .ai-sidebar:not(.collapsed) {
    width: 320px;
    min-width: 320px;
  }
}

@media (max-width: 900px) {
  /* On smaller screens, sidebar overlays content */
  .ai-sidebar:not(.collapsed) {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    z-index: 100;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.2);
  }
  
  .ai-toggle-text {
    display: none;
  }
}
