/* D4C AI Chat Component Styles */

/* Main Container */
.d4c-ai-chat {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  overflow: hidden;
}

/* Mode variations */
.d4c-ai-chat--full {
  height: calc(100vh - 100px);
  max-width: 1200px;
  margin: 20px auto;
}

.d4c-ai-chat--sidebar {
  height: 100%;
  max-height: 600px;
}

.d4c-ai-chat--embedded {
  height: 400px;
  border-radius: 4px;
}

/* Header */
.d4c-ai-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 20px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.d4c-ai-chat-header-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  font-weight: 600;
}

.d4c-ai-chat-header-title i {
  font-size: 20px;
}

.d4c-ai-chat-header-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

/* Add padding when inside dialog to avoid overlap with dialog controls */
.d4c-ai-chat-dialog .d4c-ai-chat-header-actions {
  padding-right: 90px;
}

/* Messages Container */
.d4c-ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: #f8f9fa;
}

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

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

.d4c-ai-chat-messages::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 4px;
}

.d4c-ai-chat-messages::-webkit-scrollbar-thumb:hover {
  background: #999;
}

/* Empty State */
.d4c-ai-chat-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #999;
  text-align: center;
}

.d4c-ai-chat-empty i {
  margin-bottom: 20px;
  opacity: 0.3;
}

.d4c-ai-chat-empty p {
  font-size: 16px;
  margin: 0;
}

/* Message */
.d4c-ai-chat-message {
  display: flex;
  margin-bottom: 20px;
  animation: messageSlideIn 0.3s ease-out;
}

.d4c-ai-chat-message--user {
  justify-content: flex-end;
}

.d4c-ai-chat-message--assistant {
  justify-content: flex-start;
}

.d4c-ai-chat-message--system {
  justify-content: center;
}

.d4c-ai-chat-message--system .d4c-ai-chat-message-content {
  background: #d1ecf1;
  color: #0c5460;
  text-align: center;
  max-width: 80%;
}

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

/* Message Content */
.d4c-ai-chat-message-content {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: 12px;
  position: relative;
  word-wrap: break-word;
}

.d4c-ai-chat-message--user .d4c-ai-chat-message-content {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-radius: 12px 12px 4px 12px;
}

.d4c-ai-chat-message--assistant .d4c-ai-chat-message-content {
  background: white;
  color: #333;
  border-radius: 12px 12px 12px 4px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.d4c-ai-chat-message-text {
  line-height: 1.5;
  white-space: pre-wrap;
}

/* Streaming Indicator */
.d4c-ai-chat-message-streaming {
  margin-top: 8px;
}

.d4c-ai-chat-cursor {
  display: inline-block;
  animation: blink 1s infinite;
  font-weight: bold;
}

@keyframes blink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0; }
}

/* Error Indicator */
.d4c-ai-chat-message-error {
  margin-top: 8px;
  color: #dc3545;
  font-size: 14px;
}

.d4c-ai-chat-message--assistant .d4c-ai-chat-message-error {
  color: #dc3545;
}

/* Timestamp */
.d4c-ai-chat-message-time {
  font-size: 11px;
  opacity: 0.6;
  margin-top: 4px;
}

.d4c-ai-chat-message--user .d4c-ai-chat-message-time {
  text-align: right;
}

/* Input Area */
.d4c-ai-chat-input {
  display: flex;
  gap: 10px;
  padding: 15px 20px;
  background: white;
  border-top: 1px solid #e0e0e0;
}

.d4c-ai-chat-input-field {
  flex: 1;
  padding: 10px 15px;
  border: 1px solid #ddd;
  border-radius: 20px;
  resize: none;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
  max-height: 120px;
  overflow-y: auto;
  transition: border-color 0.2s;
}

.d4c-ai-chat-input-field:focus {
  outline: none;
  border-color: #667eea;
}

.d4c-ai-chat-input-field:disabled {
  background: #f5f5f5;
  cursor: not-allowed;
}

/* Buttons */
.d4c-ai-chat-btn {
  padding: 10px 16px;
  border: none;
  border-radius: 20px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.d4c-ai-chat-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.d4c-ai-chat-btn:active:not(:disabled) {
  transform: translateY(0);
}

.d4c-ai-chat-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.d4c-ai-chat-btn--icon {
  width: 36px;
  height: 36px;
  padding: 0;
  background: rgba(255, 255, 255, 0.2);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.d4c-ai-chat-btn--icon:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.1);
}

.d4c-ai-chat-btn--clear {
  background: rgba(255, 255, 255, 0.2);
  color: white;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.d4c-ai-chat-btn--clear:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.1);
}

.d4c-ai-chat-btn--send {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.d4c-ai-chat-btn--send:hover:not(:disabled) {
  background: linear-gradient(135deg, #5568d3 0%, #653a8b 100%);
}

/* Dialog Styles */
.d4c-ai-chat-dialog-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.2s ease-out;
}

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

.d4c-ai-chat-dialog {
  position: relative;
  width: 100%;
  max-width: 1200px;
  height: 85vh;
  max-height: 800px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
  animation: slideUp 0.3s ease-out;
  overflow: hidden;
  transition: all 0.3s ease;
}

.d4c-ai-chat-dialog.maximized {
  max-width: 95vw;
  height: 95vh;
  max-height: 95vh;
}

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

.d4c-ai-chat-dialog .d4c-ai-chat {
  height: 100%;
  box-shadow: none;
  border-radius: 0;
}

.d4c-ai-chat-dialog-controls {
  position: absolute;
  top: 15px;
  right: 15px;
  display: flex;
  gap: 8px;
  z-index: 100;
  pointer-events: none;
}

.d4c-ai-chat-dialog-controls > * {
  pointer-events: auto;
}

.d4c-ai-chat-dialog-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: rgba(255, 255, 255, 0.2);
  color: white;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: all 0.2s;
}

.d4c-ai-chat-dialog-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.1);
}

.d4c-ai-chat-dialog-close:hover {
  transform: rotate(90deg) scale(1.1);
}

/* Prevent body scroll when dialog is open */
body.d4c-ai-chat-dialog-open {
  overflow: hidden;
}

/* AI Chat Button Icon Style (similar to data-analysis button) */
/* Data Analysis Icon Button */
.btn-icon-ai-chat {
  background: white;
  color: #666;
  border: 1px solid #ddd;
  border-radius: 4px;
  width: 35px;
  height: 35px;
  min-width: 35px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 18px;
  flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.btn-icon-ai-chat:hover {
  background: #f5f5f5;
  color: #333;
  border-color: #999;
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
}

.btn-icon-ai-chat i {
  display: none;
}

/* AI Icon Image */
.btn-icon-ai-chat-img {
  width: 20px;
  height: 20px;
  display: block;
  transition: transform 0.2s;
}

.btn-icon-ai-chat:hover .btn-icon-ai-chat-img {
  transform: scale(1.1);
}

/* Status Message Container (outside regular messages) */
.d4c-ai-chat-status-container {
  display: flex;
  justify-content: flex-start;
  margin: 12px 0;
  animation: fadeIn 0.3s ease-out;
}

.d4c-ai-chat-status {
  display: inline-flex;
  align-items: center;
  padding: 8px 16px;
  background: #e3f2fd;
  border: 1px solid #90caf9;
  border-radius: 20px;
  font-size: 13px;
  color: #1976d2;
  max-width: 80%;
}

.d4c-ai-chat-status i {
  margin-right: 8px;
  font-size: 14px;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* Suggestions Container (above input) */
.d4c-ai-chat-suggestions-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 20px 8px;
  background: #fff;
  border-top: 1px solid #e0e0e0;
  animation: slideDown 0.3s ease-out;
}

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

.d4c-ai-chat-suggestion-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: #f5f5f5;
  border: 1px solid #e0e0e0;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 14px;
  color: #333;
}

.d4c-ai-chat-suggestion-chip:hover {
  background: #667eea;
  color: white;
  border-color: #667eea;
  transform: translateY(-2px);
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.d4c-ai-chat-suggestion-chip i {
  font-size: 12px;
}

/* Code/Visualization */
.d4c-ai-chat-code,
.d4c-ai-chat-visualization,
.d4c-ai-chat-dataset {
  margin-top: 12px;
  border-radius: 8px;
  overflow: hidden;
  background: white;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Full width for messages containing visualizations */
.d4c-ai-chat-message:has(.d4c-ai-chat-visualization) .d4c-ai-chat-message-content,
.d4c-ai-chat-message:has(.d4c-ai-chat-code) .d4c-ai-chat-message-content {
  min-width: 85%;
}

.d4c-ai-chat-code-header,
.d4c-ai-chat-viz-header,
.d4c-ai-chat-dataset-header {
  padding: 12px 16px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.d4c-ai-chat-code-header h4,
.d4c-ai-chat-viz-header h4,
.d4c-ai-chat-dataset-header h4 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.d4c-ai-chat-code-content,
.d4c-ai-chat-viz-content,
.d4c-ai-chat-dataset-content {
  padding: 16px;
}

.d4c-ai-chat-image {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
  margin-bottom: 12px;
  display: block;
}

.d4c-ai-chat-viz-content iframe {
  border-radius: 4px;
  display: block;
  height: 500px;
  min-height: 500px;
}

/* Larger height for maps */
.d4c-ai-chat-visualization--map .d4c-ai-chat-viz-content iframe {
  height: 600px;
  min-height: 600px;
}

/* Smaller height for KPIs */
.d4c-ai-chat-visualization--kpi .d4c-ai-chat-viz-content iframe {
  height: 300px;
  min-height: 300px;
}

.d4c-ai-chat-dataset-title {
  font-weight: 600;
  margin-bottom: 8px;
  color: #333;
}

.d4c-ai-chat-dataset-meta {
  font-size: 13px;
  color: #666;
}

/* Responsive */
@media (max-width: 768px) {
  .d4c-ai-chat--full {
    height: calc(100vh - 60px);
    margin: 10px;
  }
  
  .d4c-ai-chat-message-content {
    max-width: 85%;
  }
  
  .d4c-ai-chat-header {
    padding: 12px 15px;
  }
  
  .d4c-ai-chat-messages {
    padding: 15px;
  }
  
  .d4c-ai-chat-input {
    padding: 12px 15px;
  }
  
  .d4c-ai-chat-dialog {
    max-width: 100%;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
  }
  
  .d4c-ai-chat-dialog-overlay {
    padding: 0;
  }
}
