/* renderer/ai-chat-interface.css */
/* Enhanced AI Chat Interface Styling */

.ai-chat-interface {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 90%;
  max-width: 900px;
  height: 80vh;
  background: var(--background-color, #ffffff);
  border: 1px solid var(--border-color, #e0e0e0);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  z-index: 10000;
  display: flex;
  flex-direction: column;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  overflow: hidden;
}

/* Dark theme support */
[data-theme="dark"] .ai-chat-interface {
  background: #2b2b2b;
  border-color: #404040;
  color: #ffffff;
}

/* Header */
.ai-chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color, #e0e0e0);
  background: var(--primary-color, #f8f9fa);
  border-radius: 12px 12px 0 0;
}

[data-theme="dark"] .ai-chat-header {
  background: #333333;
  border-bottom-color: #404040;
}

.ai-chat-tabs {
  display: flex;
  gap: 10px;
}

.ai-tab {
  padding: 8px 16px;
  border: none;
  background: transparent;
  color: var(--text-color, #666);
  cursor: pointer;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s ease;
}

.ai-tab:hover {
  background: rgba(0, 123, 255, 0.1);
  color: var(--primary-blue, #007bff);
}

.ai-tab.active {
  background: var(--primary-blue, #007bff);
  color: white;
}

.ai-chat-close {
  width: 30px;
  height: 30px;
  border: none;
  background: #ff4757;
  color: white;
  border-radius: 50%;
  cursor: pointer;
  font-size: 18px;
  font-weight: bold;
  transition: background 0.2s ease;
}

.ai-chat-close:hover {
  background: #ff3838;
}

/* Content */
.ai-chat-content {
  flex: 1;
  overflow: hidden;
  position: relative;
  min-width: 0;
}

.ai-tab-content {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 20px;
  overflow-y: auto;
  display: none;
  min-width: 0;
}

.ai-tab-content.active {
  display: block;
}

/* Search */
.ai-chat-search {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}

.ai-chat-intro {
  margin-bottom: 16px;
}

.ai-chat-intro h3 {
  margin: 0 0 6px 0;
  color: var(--text-color, #1a1f23);
}

.ai-chat-intro p {
  margin: 0;
  color: var(--text-muted, #6c757d);
  font-size: 14px;
}

.ai-chat-search input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border-color, #ddd);
  border-radius: 6px;
  font-size: 14px;
  background: var(--input-background, #ffffff);
  color: var(--text-color, #333);
}

[data-theme="dark"] .ai-chat-search input {
  background: #404040;
  border-color: #555;
  color: #ffffff;
}

.ai-chat-search button {
  padding: 8px 16px;
  border: 1px solid var(--primary-blue, #007bff);
  background: var(--primary-blue, #007bff);
  color: white;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.2s ease;
}

.ai-chat-search button:hover {
  background: #0056b3;
}

/* Conversation Items */
.ai-conversation-item {
  margin-bottom: 16px;
  padding: 16px;
  border: 1px solid var(--border-color, #e0e0e0);
  border-radius: 8px;
  background: var(--card-background, #ffffff);
  transition: box-shadow 0.2s ease;
}

.ai-conversation-item:hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.ai-conversation-item.success {
  border-left: 4px solid #28a745;
}

.ai-conversation-item.error {
  border-left: 4px solid #dc3545;
}

[data-theme="dark"] .ai-conversation-item {
  background: #404040;
  border-color: #555;
}

.ai-conv-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-color, #f0f0f0);
}

[data-theme="dark"] .ai-conv-header {
  border-bottom-color: #555;
}

.ai-conv-action {
  font-weight: 600;
  color: var(--primary-blue, #007bff);
  font-size: 14px;
}

.ai-conv-time {
  font-size: 12px;
  color: var(--text-muted, #6c757d);
}

.ai-conv-content > div {
  margin-bottom: 8px;
  line-height: 1.5;
}

.ai-user-input {
  color: var(--text-color, #333);
}

.ai-response {
  color: var(--success-color, #28a745);
  background: rgba(40, 167, 69, 0.05);
  padding: 8px;
  border-radius: 4px;
  margin-top: 8px;
}

[data-theme="dark"] .ai-response {
  background: rgba(40, 167, 69, 0.15);
}

.ai-result {
  color: var(--info-color, #17a2b8);
  background: rgba(23, 162, 184, 0.05);
  padding: 8px;
  border-radius: 4px;
  margin-top: 8px;
}

[data-theme="dark"] .ai-result {
  background: rgba(23, 162, 184, 0.15);
}

.ai-conv-actions {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border-color, #f0f0f0);
}

[data-theme="dark"] .ai-conv-actions {
  border-top-color: #555;
}

/* Reports */
.ai-reports-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.ai-reports-header h3 {
  margin: 0;
  color: var(--text-color, #333);
}

.ai-report-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  margin-bottom: 12px;
  border: 1px solid var(--border-color, #e0e0e0);
  border-radius: 8px;
  background: var(--card-background, #ffffff);
  transition: box-shadow 0.2s ease;
}

.ai-report-item:hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] .ai-report-item {
  background: #404040;
  border-color: #555;
}

.ai-report-info h4 {
  margin: 0 0 8px 0;
  color: var(--text-color, #333);
  font-size: 16px;
}

.ai-report-meta {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted, #6c757d);
}

.ai-report-actions {
  display: flex;
  gap: 8px;
}

.ai-proposal-item {
  margin-bottom: 16px;
  padding: 16px;
  border: 1px solid var(--border-color, #e0e0e0);
  border-radius: 8px;
  background: var(--card-background, #ffffff);
  transition: box-shadow 0.2s ease;
}

.ai-proposal-item:hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.ai-proposal-item.pending_approval {
  border-left: 4px solid #f59e0b;
}

.ai-proposal-item.executed {
  border-left: 4px solid #16a34a;
}

.ai-proposal-item.rejected,
.ai-proposal-item.failed {
  border-left: 4px solid #dc2626;
}

[data-theme="dark"] .ai-proposal-item {
  background: #404040;
  border-color: #555;
}

.ai-proposal-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border-color, #f0f0f0);
}

.ai-mail-draft-preview {
  margin-top: 10px;
  padding: 10px;
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 8px;
  background: rgba(37, 99, 235, 0.05);
}

.ai-mail-draft-preview pre {
  margin: 8px 0 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.5;
}

[data-theme="dark"] .ai-proposal-actions {
  border-top-color: #555;
}

.ai-section-block {
  margin-bottom: 24px;
}

.ai-section-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-color, #1a1f23);
  margin-bottom: 10px;
}

.ai-suggestion-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}

.ai-worklist-composer {
  margin-bottom: 20px;
  padding: 16px;
  border: 1px solid var(--border-color, #e0e0e0);
  border-radius: 10px;
  background: var(--card-background, #ffffff);
}

.ai-worklist-grid {
  display: grid;
  grid-template-columns: minmax(220px, 1.5fr) minmax(140px, 0.7fr) minmax(140px, 0.7fr);
  gap: 10px;
  margin-bottom: 10px;
}

.ai-worklist-composer input,
.ai-worklist-composer select,
.ai-worklist-composer textarea {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  border: 1px solid var(--border-color, #d1d5db);
  border-radius: 8px;
  background: var(--input-background, #ffffff);
  color: var(--text-color, #111827);
  font: inherit;
}

.ai-worklist-composer textarea {
  min-height: 110px;
  resize: vertical;
}

.ai-worklist-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 10px;
}

.ai-worklist-item-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.ai-worklist-item {
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--border-color, #e5e7eb);
  background: rgba(148, 163, 184, 0.08);
}

.ai-worklist-item.completed {
  border-left: 4px solid #16a34a;
}

.ai-worklist-item.awaiting_approval {
  border-left: 4px solid #f59e0b;
}

.ai-worklist-item.needs_review,
.ai-worklist-item.failed {
  border-left: 4px solid #dc2626;
}

.ai-worklist-item-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
  font-weight: 600;
}

.ai-worklist-status {
  text-transform: capitalize;
  color: var(--text-muted, #6b7280);
  font-size: 12px;
  white-space: nowrap;
}

.ai-worklist-item-body {
  color: var(--text-color, #111827);
  line-height: 1.5;
}

.ai-worklist-item-note {
  margin-top: 6px;
  color: var(--text-muted, #6b7280);
  font-size: 12px;
}

.ai-suggestion-card {
  border: 1px solid var(--border-color, #e0e0e0);
  border-radius: 10px;
  padding: 14px;
  background: var(--card-background, #ffffff);
}

.ai-save-function-btn {
  padding: 6px 12px;
  border: 1px solid var(--border-color, #d1d5db);
  border-radius: 8px;
  background: var(--card-background, #ffffff);
  color: var(--text-color, #1a1f23);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}

.ai-save-function-btn:hover {
  border-color: #22c55e;
  color: #16a34a;
}

.ai-saved-function-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.ai-saved-function-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(34, 197, 94, 0.12);
  color: #166534;
  font-size: 13px;
  font-weight: 600;
}

.ai-unsave-function-btn {
  border: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
}

[data-theme="dark"] .ai-suggestion-card {
  background: #404040;
  border-color: #555;
}

[data-theme="dark"] .ai-worklist-composer,
[data-theme="dark"] .ai-worklist-item {
  background: #404040;
  border-color: #555;
}

[data-theme="dark"] .ai-worklist-composer input,
[data-theme="dark"] .ai-worklist-composer select,
[data-theme="dark"] .ai-worklist-composer textarea {
  background: #2b2b2b;
  border-color: #555;
  color: #ffffff;
}

/* Buttons */
.ai-download-btn,
.ai-view-btn,
.ai-approve-btn,
.ai-reject-btn {
  padding: 6px 12px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: background 0.2s ease;
  white-space: nowrap;
}

.ai-download-btn {
  background: #28a745;
  color: white;
}

.ai-download-btn:hover {
  background: #218838;
}

.ai-view-btn {
  background: var(--primary-blue, #007bff);
  color: white;
}

.ai-view-btn:hover {
  background: #0056b3;
}

.ai-approve-btn {
  background: #16a34a;
  color: white;
}

.ai-approve-btn:hover {
  background: #15803d;
}

.ai-reject-btn {
  background: #dc2626;
  color: white;
}

.ai-reject-btn:hover {
  background: #b91c1c;
}

/* Pagination */
.ai-pagination {
  margin-top: 20px;
  text-align: center;
}

.ai-pagination-controls {
  display: inline-flex;
  gap: 10px;
  align-items: center;
}

.ai-pagination-controls button {
  padding: 6px 12px;
  border: 1px solid var(--border-color, #ddd);
  background: var(--background-color, #ffffff);
  color: var(--text-color, #333);
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.2s ease;
}

.ai-pagination-controls button:hover {
  background: var(--hover-color, #f8f9fa);
}

[data-theme="dark"] .ai-pagination-controls button {
  background: #404040;
  border-color: #555;
  color: #ffffff;
}

[data-theme="dark"] .ai-pagination-controls button:hover {
  background: #4a4a4a;
}

/* Loading & Empty States */
.ai-loading,
.ai-error,
.ai-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted, #6c757d);
  font-size: 16px;
}

.ai-error {
  color: #dc3545;
}

.ai-empty {
  color: var(--text-muted, #999);
}

.ai-empty-state {
  margin-top: 12px;
  padding: 20px;
  border: 1px solid var(--border-color, #e0e0e0);
  border-radius: 10px;
  background: var(--card-background, #ffffff);
  color: var(--text-color, #1a1f23);
}

.ai-empty-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-color, #1a1f23);
  margin-bottom: 10px;
}

.ai-empty-body {
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-muted, #6c757d);
  margin-bottom: 10px;
}

.ai-empty-body:last-child {
  margin-bottom: 0;
}

[data-theme="dark"] .ai-empty-state {
  background: #404040;
  border-color: #555;
}

/* Scrollbar styling */
.ai-tab-content::-webkit-scrollbar {
  width: 8px;
}

.ai-tab-content::-webkit-scrollbar-track {
  background: var(--scrollbar-track, #f1f1f1);
}

.ai-tab-content::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb, #c1c1c1);
  border-radius: 4px;
}

.ai-tab-content::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-thumb-hover, #a8a8a8);
}

[data-theme="dark"] .ai-tab-content::-webkit-scrollbar-track {
  background: #2b2b2b;
}

[data-theme="dark"] .ai-tab-content::-webkit-scrollbar-thumb {
  background: #555;
}

[data-theme="dark"] .ai-tab-content::-webkit-scrollbar-thumb:hover {
  background: #666;
}

/* Responsive design */
@media (max-width: 768px) {
  .ai-chat-interface {
    inset: 8px;
    width: auto;
    max-width: none;
    height: auto;
    top: auto;
    left: auto;
    transform: none;
    border-radius: 14px;
  }
  
  .ai-chat-header {
    padding: 12px 16px;
    align-items: flex-start;
    gap: 10px;
  }

  .ai-chat-tabs {
    flex: 1 1 auto;
    gap: 8px;
    max-width: calc(100% - 42px);
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: thin;
  }

  .ai-tab {
    flex: 0 0 auto;
    white-space: nowrap;
  }
  
  .ai-tab-content {
    padding: 14px;
  }

  .ai-chat-search {
    flex-direction: column;
  }
  
  .ai-report-item {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }
  
  .ai-report-actions {
    justify-content: flex-end;
  }

  .ai-worklist-grid {
    grid-template-columns: 1fr;
  }

  .ai-conversation-item,
  .ai-report-item,
  .ai-suggestion-card,
  .ai-empty-state {
    overflow-wrap: anywhere;
  }
}

@media (max-width: 520px) {
  .ai-chat-interface {
    inset: 6px;
  }

  .ai-chat-header {
    padding: 10px 12px;
  }

  .ai-tab-content {
    padding: 12px 10px;
  }
}

/* Animation */
.ai-chat-interface {
  animation: aiChatSlideIn 0.3s ease-out;
}

@keyframes aiChatSlideIn {
  from {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.9);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

/* Trigger button styling (draggable floating button) */
.ai-chat-trigger,
.voice-trigger-btn {
  position: fixed;
  left: 50vw; /* Start centered horizontally */
  top: 70vh;  /* Start near bottom, but allow full movement */
  width: 60px;
  height: 60px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, #16a34a, #22c55e) !important;
  color: white;
  font-size: 24px;
  cursor: move;
  box-shadow: 0 6px 16px rgba(34, 197, 94, 0.55) !important;
  z-index: 9999;
  transition: all 0.2s ease;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

.ai-chat-trigger:hover {
  transform: scale(1.05);
  box-shadow: 0 8px 20px rgba(34, 197, 94, 0.7) !important;
}

.ai-chat-trigger.dragging,
.voice-trigger-btn.dragging {
  transform: scale(1.1);
  box-shadow: 0 8px 20px rgba(34, 197, 94, 0.6);
  z-index: 10001;
}

/* Remove conflicting bottom/right for full movement */
.ai-chat-trigger,
.voice-trigger-btn {
  bottom: auto !important;
  right: auto !important;
}

/* Voice trigger button (also draggable) */
.voice-trigger-btn {
  background: linear-gradient(135deg, #16a34a, #22c55e);
  box-shadow: 0 6px 16px rgba(34, 197, 94, 0.55) !important;
  z-index: 9998;
}

.voice-trigger-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 8px 20px rgba(34, 197, 94, 0.7) !important;
}
