/* ============================================================================
   AI CHAT PANEL - Exercise Help Chat
   Updated to match new site design
   ============================================================================ */

/* AI Help Button Styles */
.ai-help {
  background: var(--color-bg, #fff);
  color: var(--color-text, #0f172a);
  border: 1px solid var(--color-border, #e2e8f0);
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 500;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.ai-help:hover {
  background: var(--color-primary, #3b82f6);
  color: #fff;
  border-color: var(--color-primary, #3b82f6);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.ai-help svg {
  fill: var(--color-text, #0f172a);
}

.ai-help:hover svg {
  fill: #fff;
}

/* Side Panel Container */
.ai-chat-panel {
  position: fixed;
  top: 0;
  right: -520px;
  width: 500px;
  height: 100vh;
  background: var(--color-bg, #fff);
  box-shadow: -5px 0 30px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  z-index: 10000;
  transition: right 0.3s ease;
}

.ai-chat-panel.open {
  right: 0;
}

/* Resize handle on left edge */
.ai-chat-resize-handle {
  position: absolute;
  left: 0;
  top: 0;
  width: 6px;
  height: 100%;
  background: transparent;
  cursor: ew-resize;
  z-index: 10001;
  transition: background 0.2s;
}

.ai-chat-resize-handle:hover,
.ai-chat-resize-handle:active {
  background: var(--color-primary, #3b82f6);
}

/* Visual indicator on hover */
.ai-chat-resize-handle::after {
  content: '';
  position: absolute;
  left: 1px;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 40px;
  background: transparent;
  border-radius: 2px;
  transition: background 0.2s;
}

.ai-chat-resize-handle:hover::after {
  background: rgba(255, 255, 255, 0.5);
}

/* Push main content when panel is open - now controlled by JS */
body {
  transition: margin-right 0.3s ease;
}

/* Header */
.ai-chat-header {
  background: var(--color-bg-subtle, #f8fafc);
  border-bottom: 1px solid var(--color-border, #e2e8f0);
  color: var(--color-text, #0f172a);
  padding: 14px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.ai-chat-header h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  text-align: center;
  flex: 1;
}

.ai-chat-close {
  background: var(--color-bg-muted, #f1f5f9);
  border: 1px solid var(--color-border, #e2e8f0);
  color: var(--color-text-secondary, #64748b);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.ai-chat-close:hover {
  background: var(--color-bg-muted, #f1f5f9);
  border-color: var(--color-text-muted, #94a3b8);
}

/* Style Mode Selector (3 buttons with labels) */
.style-selector {
  display: flex;
  align-items: center;
  gap: 4px;
}

.style-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  border: 1px solid var(--color-border, #e2e8f0);
  border-radius: 8px;
  background: var(--color-bg, #fff);
  color: var(--color-text-secondary, #64748b);
  cursor: pointer;
  font-size: 0.75rem;
  transition: all 0.15s;
}

.style-btn:hover {
  background: var(--color-bg-muted, #f1f5f9);
  border-color: var(--color-text-muted, #94a3b8);
}

.style-btn.active {
  background: var(--color-primary, #3b82f6);
  color: #fff;
  border-color: var(--color-primary, #3b82f6);
  font-weight: 600;
}

.style-emoji {
  font-size: 0.9rem;
}

.style-label {
  font-size: 0.75rem;
  font-weight: 500;
  white-space: nowrap;
}

/* Spacer between selector and close button */
.header-spacer {
  width: 16px;
  flex-shrink: 0;
}

/* Context Banner */
.ai-chat-context {
  background: var(--color-primary-soft, #dbeafe);
  border-bottom: 1px solid var(--color-border, #e2e8f0);
  padding: 10px 16px;
  font-size: 13px;
  color: var(--color-text, #0f172a);
  max-height: 150px;
  overflow-y: auto;
  flex-shrink: 0;
  text-align: left;
  line-height: 1.5;
}

/* Messages Area */
.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--color-bg-subtle, #f8fafc);
}

/* Individual Messages */
.ai-chat-message {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.6;
  overflow: visible;
  overflow-wrap: break-word;
  word-wrap: break-word;
  flex-shrink: 0;
}

/* Paragraphs in messages */
.ai-chat-message p {
  margin: 0 0 10px 0;
}

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

/* Lists in messages */
.ai-chat-message ul,
.ai-chat-message ol {
  margin: 8px 0;
  padding-left: 20px;
}

.ai-chat-message li {
  margin: 4px 0;
}

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

/* Headers in messages */
.ai-chat-message h4,
.ai-chat-message h5 {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-primary, #3b82f6);
  margin: 12px 0 8px 0;
}

.ai-chat-message h4:first-child,
.ai-chat-message h5:first-child {
  margin-top: 0;
}

.ai-chat-message h5 {
  font-size: 14px;
}

.ai-chat-message.assistant {
  background: var(--color-bg, #fff);
  color: var(--color-text, #0f172a);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  border: 1px solid var(--color-border, #e2e8f0);
}

.ai-chat-message.user {
  background: var(--color-primary, #3b82f6);
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.ai-chat-message.error {
  background: var(--color-error-soft, #fee2e2);
  color: var(--color-error, #ef4444);
  align-self: center;
  font-size: 13px;
}

/* Typing Indicator */
.ai-typing-indicator {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  background: var(--color-bg, #fff);
  border: 1px solid var(--color-border, #e2e8f0);
  border-radius: 12px;
  border-bottom-left-radius: 4px;
  align-self: flex-start;
}

.ai-typing-indicator span {
  width: 8px;
  height: 8px;
  background: var(--color-primary, #3b82f6);
  border-radius: 50%;
  animation: ai-typing 1.4s infinite ease-in-out;
}

.ai-typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.ai-typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes ai-typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* Intent Chips - at top */
.ai-chat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 16px;
  background: var(--color-bg, #fff);
  border-bottom: 1px solid var(--color-border, #e2e8f0);
  flex-shrink: 0;
}

.ai-chip {
  background: var(--color-bg, #fff);
  border: 1px solid var(--color-border, #e2e8f0);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--color-text-secondary, #64748b);
}

.ai-chip:hover {
  background: var(--color-primary, #3b82f6);
  color: #fff;
  border-color: var(--color-primary, #3b82f6);
  transform: translateY(-1px);
}

/* Welcome tip */
.ai-chat-tip {
  font-size: 12px;
  color: var(--color-text-muted, #94a3b8);
  margin-top: 8px;
}

/* Input Area */
.ai-chat-input-area {
  padding: 12px 16px;
  background: var(--color-bg, #fff);
  border-top: 1px solid var(--color-border, #e2e8f0);
  display: flex;
  gap: 10px;
  flex-shrink: 0;
}

.ai-chat-input-area input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid var(--color-border, #e2e8f0);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
  background: var(--color-bg, #fff);
  color: var(--color-text, #0f172a);
}

.ai-chat-input-area input:focus {
  border-color: var(--color-primary, #3b82f6);
}

.ai-chat-send {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--color-primary, #3b82f6);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  flex-shrink: 0;
}

.ai-chat-send:hover {
  background: var(--color-primary-hover, #2563eb);
}

.ai-chat-send svg {
  fill: #fff;
}

/* Welcome Message */
.ai-chat-welcome {
  text-align: center;
  padding: 16px 12px;
  color: var(--color-text-muted, #94a3b8);
}

.ai-chat-welcome p {
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
}

/* Mobile Responsiveness */
@media (max-width: 600px) {
  .ai-chat-panel {
    width: 100% !important;
    right: -100% !important;
  }

  .ai-chat-panel.open {
    right: 0 !important;
  }

  .ai-chat-resize-handle {
    display: none;
  }
}

/* MathJax in chat */
.ai-chat-message .MathJax {
  font-size: 100% !important;
}

.ai-chat-message mjx-container {
  overflow-x: visible;
  overflow-y: visible;
  max-width: 100%;
  display: inline-block;
  vertical-align: middle !important;
}

.ai-chat-message mjx-container[jax="CHTML"] {
  vertical-align: middle !important;
}

.ai-chat-message mjx-math {
  vertical-align: middle !important;
}

/* Context Switch Notification */
.ai-context-switch-notice {
  background: var(--color-primary-soft, #dbeafe);
  border: 1px solid var(--color-border, #e2e8f0);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 10px;
  font-size: 13px;
  color: var(--color-primary, #3b82f6);
  text-align: center;
  font-weight: 500;
  transition: opacity 0.5s ease;
}


/* ============================================================================
   DARK MODE SUPPORT
   ============================================================================ */

[data-theme="dark"] .ai-chat-panel {
  background: var(--color-bg);
  box-shadow: -5px 0 30px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .ai-chat-header {
  background: var(--color-bg);
  border-color: var(--color-border);
}

[data-theme="dark"] .ai-chat-close {
  background: var(--color-bg-subtle);
  border-color: var(--color-border);
  color: var(--color-text-secondary);
}

[data-theme="dark"] .style-btn {
  background: var(--color-bg);
  border-color: var(--color-border);
  color: var(--color-text-secondary);
}

[data-theme="dark"] .style-btn:hover {
  background: var(--color-bg-muted);
}

[data-theme="dark"] .style-btn.active {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}

[data-theme="dark"] .ai-chat-context {
  background: var(--color-primary-soft);
  border-color: var(--color-border);
}

[data-theme="dark"] .ai-chat-messages {
  background: var(--color-bg);
}

[data-theme="dark"] .ai-chat-message.assistant {
  background: var(--color-bg-subtle);
  border-color: var(--color-border);
}

[data-theme="dark"] .ai-typing-indicator {
  background: var(--color-bg-subtle);
  border-color: var(--color-border);
}

[data-theme="dark"] .ai-chat-chips {
  background: var(--color-bg-subtle);
  border-color: var(--color-border);
}

[data-theme="dark"] .ai-chip {
  background: var(--color-bg);
  border-color: var(--color-border);
}

[data-theme="dark"] .ai-chat-input-area {
  background: var(--color-bg-subtle);
  border-color: var(--color-border);
}

[data-theme="dark"] .ai-chat-input-area input {
  background: var(--color-bg);
  border-color: var(--color-border);
  color: var(--color-text);
}


[data-theme="dark"] .ai-context-switch-notice {
  background: var(--color-primary-soft);
  border-color: var(--color-border);
}
