/* AI Chat Panel — right-side sliding panel */

.ai-chat-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: var(--ai-chat-width, 400px);
  max-width: 95vw;
  min-width: 300px;
  height: 100vh;
  background: #fff;
  border-left: 1px solid #e2e8f0;
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.12);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  z-index: 200;
}

.ai-chat-panel.resizing {
  transition: none;
  user-select: none;
}

/* Resize Handle */
.ai-chat-resize {
  position: absolute;
  top: 0;
  left: -3px;
  width: 6px;
  height: 100%;
  cursor: col-resize;
  z-index: 10;
}

.ai-chat-resize:hover,
.ai-chat-resize.active {
  background: #4299e1;
  opacity: 0.4;
}

.ai-chat-panel.open {
  transform: translateX(0);
}

/* Header */
.ai-chat-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid #e2e8f0;
  background: #f7fafc;
  flex-shrink: 0;
}

.ai-chat-header h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: #1a202c;
  flex: 1;
}

.ai-chat-header-btn {
  background: none;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #718096;
  font-size: 1.1rem;
  transition: all 0.15s;
}

.ai-chat-header-btn:hover {
  background: #edf2f7;
  color: #2d3748;
}

/* Verbosity Select */
.ai-chat-select {
  padding: 4px 8px;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  font-size: 0.75rem;
  color: #4a5568;
  background: #fff;
  cursor: pointer;
  outline: none;
}

.ai-chat-select:focus {
  border-color: #4299e1;
}

/* API Key Prompt */
.ai-chat-key-prompt {
  padding: 16px;
  background: #fffff0;
  border-bottom: 1px solid #f6e05e;
  flex-shrink: 0;
}

.ai-chat-key-prompt p {
  font-size: 0.85rem;
  color: #744210;
  margin-bottom: 8px;
}

.ai-chat-key-row {
  display: flex;
  gap: 8px;
}

.ai-chat-key-input {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  font-size: 0.85rem;
  font-family: monospace;
}

.ai-chat-key-input:focus {
  outline: none;
  border-color: #4299e1;
  box-shadow: 0 0 0 2px rgba(66, 153, 225, 0.15);
}

/* Messages Area */
.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ai-chat-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  color: #a0aec0;
  text-align: center;
  padding: 32px;
}

.ai-chat-empty-icon {
  font-size: 2rem;
  margin-bottom: 8px;
}

.ai-chat-empty p {
  font-size: 0.9rem;
  margin: 0;
}

.ai-chat-empty small {
  font-size: 0.8rem;
  margin-top: 4px;
}

/* Message Bubbles */
.ai-chat-msg {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 0.875rem;
  line-height: 1.5;
  word-wrap: break-word;
}

.ai-chat-msg.user {
  align-self: flex-end;
  background: #3182ce;
  color: #fff;
  border-bottom-right-radius: 4px;
}

.ai-chat-msg.assistant {
  align-self: flex-start;
  background: #f7fafc;
  color: #1a202c;
  border: 1px solid #e2e8f0;
  border-bottom-left-radius: 4px;
}

/* Markdown inside assistant messages */
.ai-chat-msg.assistant p {
  margin: 0 0 8px;
}

.ai-chat-msg.assistant p:last-child {
  margin-bottom: 0;
}

.ai-chat-msg.assistant strong {
  font-weight: 600;
}

.ai-chat-msg.assistant code {
  background: #edf2f7;
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 0.8rem;
}

.ai-chat-msg.assistant pre {
  background: #1a202c;
  color: #e2e8f0;
  padding: 10px 12px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 8px 0;
  font-size: 0.8rem;
}

.ai-chat-msg.assistant pre code {
  background: none;
  padding: 0;
  color: inherit;
}

.ai-chat-msg.assistant ul,
.ai-chat-msg.assistant ol {
  margin: 4px 0 8px 18px;
  padding: 0;
}

.ai-chat-msg.assistant li {
  margin-bottom: 2px;
}

/* Streaming indicator */
.ai-chat-msg.assistant.streaming::after {
  content: '';
  display: inline-block;
  width: 6px;
  height: 14px;
  background: #4299e1;
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink 0.8s infinite;
}

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

/* Input Area */
.ai-chat-input-area {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid #e2e8f0;
  background: #fff;
  flex-shrink: 0;
  align-items: flex-end;
}

.ai-chat-input-area textarea {
  flex: 1;
  resize: none;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.875rem;
  font-family: inherit;
  line-height: 1.4;
  max-height: 120px;
  outline: none;
  transition: border-color 0.15s;
}

.ai-chat-input-area textarea:focus {
  border-color: #4299e1;
  box-shadow: 0 0 0 2px rgba(66, 153, 225, 0.15);
}

.ai-chat-send-btn {
  background: #3182ce;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}

.ai-chat-send-btn:hover {
  background: #2c5282;
}

.ai-chat-send-btn:disabled {
  background: #a0aec0;
  cursor: not-allowed;
}

/* Header toggle button */
.ai-chat-toggle-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 8px;
  padding: 6px 14px;
  color: #fff;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  margin-right: 8px;
}

.ai-chat-toggle-btn:hover {
  background: rgba(255, 255, 255, 0.22);
  border-color: rgba(255, 255, 255, 0.5);
}

.ai-chat-toggle-btn svg {
  flex-shrink: 0;
}

/* Error message */
.ai-chat-error {
  padding: 8px 12px;
  background: #fff5f5;
  border: 1px solid #fed7d7;
  border-radius: 6px;
  color: #c53030;
  font-size: 0.8rem;
  margin: 0 16px;
}

/* History Panel */
.ai-chat-history {
  border-bottom: 1px solid #e2e8f0;
  background: #fff;
  flex-shrink: 0;
  max-height: 50vh;
  display: flex;
  flex-direction: column;
}

.ai-chat-history-search {
  width: 100%;
  padding: 10px 16px;
  border: none;
  border-bottom: 1px solid #e2e8f0;
  font-size: 0.85rem;
  outline: none;
  background: #f7fafc;
}

.ai-chat-history-search:focus {
  background: #fff;
}

.ai-chat-history-search::placeholder {
  color: #a0aec0;
}

.ai-chat-history-list {
  overflow-y: auto;
  flex: 1;
}

.ai-chat-history-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 16px;
  cursor: pointer;
  border-bottom: 1px solid #f0f0f0;
  position: relative;
  transition: background 0.1s;
}

.ai-chat-history-item:hover {
  background: #f7fafc;
}

.ai-chat-history-item.active {
  background: #ebf8ff;
  border-left: 3px solid #3182ce;
}

.ai-chat-history-title {
  font-size: 0.85rem;
  font-weight: 500;
  color: #1a202c;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 24px;
}

.ai-chat-history-meta {
  font-size: 0.75rem;
  color: #a0aec0;
}

.ai-chat-history-delete {
  position: absolute;
  top: 8px;
  right: 8px;
  background: none;
  border: none;
  color: #cbd5e0;
  font-size: 1rem;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1;
  transition: all 0.15s;
  display: none;
}

.ai-chat-history-item:hover .ai-chat-history-delete {
  display: block;
}

.ai-chat-history-delete:hover {
  color: #e53e3e;
  background: #fff5f5;
}

.ai-chat-history-empty {
  padding: 24px 16px;
  text-align: center;
  color: #a0aec0;
  font-size: 0.85rem;
}

/* Inline Charts */
.ai-chat-chart {
  margin: 8px 0;
  padding: 8px;
  background: #fff;
  border-radius: 6px;
  border: 1px solid #e2e8f0;
}

.ai-chat-chart canvas {
  max-width: 100%;
  max-height: 220px;
}
