/* ─── AI Chat Page Styles ───
 * Extracted from academy.css and enhanced.
 * Uses CSS variables from tokens.css.
 */

/* ── Container ── */
.ai-chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--header-h) - 32px);
  margin: calc(-1 * var(--page-padding));
  margin-top: calc(-1 * var(--page-padding));
}

/* ── Messages area ── */
.ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-lg);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  -webkit-overflow-scrolling: touch;
}

/* ── Single message row ── */
.ai-msg {
  display: flex;
  gap: 10px;
  max-width: 90%;
}

.ai-msg-user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.ai-msg-bot {
  align-self: flex-start;
}

/* ── Avatar ── */
.ai-msg-avatar {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  border-radius: 50%;
  background: var(--bg-panel);
}

/* ── Content column ── */
.ai-msg-content {
  flex: 1;
  min-width: 0;
}

/* ── Text bubble ── */
.ai-msg-text {
  padding: var(--space-md) 14px;
  border-radius: var(--radius-btn);
  font-size: var(--font-base);
  line-height: var(--line-height-relaxed);
  word-break: break-word;
}

.ai-msg-user .ai-msg-text {
  background: rgba(201,169,98,0.15);
  border: 1px solid var(--border-gold);
  color: var(--text-primary);
  white-space: pre-wrap;
}

.ai-msg-bot .ai-msg-text {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
}

/* Markdown inside bot messages */
.ai-msg-bot .ai-msg-text strong {
  color: var(--brand-gold);
  font-weight: var(--font-weight-semibold);
}

.ai-msg-bot .ai-msg-text code {
  background: rgba(255,255,255,0.06);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 0.92em;
  font-family: "SF Mono", "Menlo", monospace;
  color: var(--color-info);
}

.ai-msg-bot .ai-msg-text .md-list-item {
  display: block;
  padding-left: 1em;
  text-indent: -0.7em;
  margin-top: 2px;
}

.ai-msg-bot .ai-msg-text .md-list-item::before {
  content: "\2022\00a0";
  color: var(--brand-gold);
}

/* ── Message enter animation ── */
.ai-msg-enter {
  animation: ai-msg-slide-in var(--transition-slow) ease-out;
}

@keyframes ai-msg-slide-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ── Sources section ── */
.ai-sources {
  margin-top: var(--space-sm);
  padding: 10px var(--space-md);
  background: rgba(96,165,250,0.06);
  border: 1px solid rgba(96,165,250,0.15);
  border-radius: var(--radius-btn);
  font-size: var(--font-sm);
}

.ai-sources-title {
  font-size: var(--font-xs);
  color: var(--color-info);
  font-weight: var(--font-weight-semibold);
  margin-bottom: var(--space-xs);
}

.ai-source-item {
  color: var(--text-secondary);
  padding: 2px 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── TTS button ── */
.ai-tts-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  margin-top: 6px;
  padding: var(--space-xs) 10px;
  background: rgba(201,169,98,0.08);
  border: 1px solid var(--border-gold);
  border-radius: var(--radius-pill);
  font-size: var(--font-xs);
  color: var(--brand-gold);
  cursor: pointer;
  transition: background var(--transition-fast);
}

.ai-tts-btn:active {
  background: rgba(201,169,98,0.2);
}

/* ── Feedback stars ── */
.ai-feedback-row {
  display: flex;
  gap: var(--space-xs);
  margin-top: var(--space-sm);
}

.ai-star-btn {
  width: 28px;
  height: 28px;
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  opacity: 0.3;
  transition: opacity var(--transition-base);
}

.ai-star-btn:hover,
.ai-star-btn.active {
  opacity: 1;
}

/* ── Typing indicator ── */
.ai-typing-dots {
  display: flex;
  gap: var(--space-xs);
  padding: 14px;
}

.ai-typing-dots span {
  width: 8px;
  height: 8px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: ai-typing-bounce 1.4s infinite;
}

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

@keyframes ai-typing-bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-6px); }
}

/* ── Input area ── */
.ai-input-area {
  padding: var(--space-md) var(--space-lg);
  border-top: 1px solid var(--border-subtle);
  background: rgba(2,4,8,0.95);
}

.ai-input-row {
  display: flex;
  gap: var(--space-sm);
  align-items: center;
}

.ai-input {
  flex: 1;
  min-height: var(--btn-min-h);
  padding: 0 14px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-btn);
  color: var(--text-primary);
  font-size: var(--font-base);
  outline: none;
  transition: border-color var(--transition-fast);
}

.ai-input:focus {
  border-color: var(--brand-gold);
}

.ai-input::placeholder {
  color: var(--text-muted);
}

.ai-send-btn {
  min-width: 60px;
  padding: 0 var(--space-lg);
}

/* ── Voice button ── */
.ai-voice-btn {
  width: var(--touch-target);
  height: var(--touch-target);
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--transition-base);
}

.ai-voice-btn.recording {
  background: rgba(248,113,113,0.15);
  border-color: var(--color-danger);
  animation: ai-pulse-recording 1s infinite;
}

@keyframes ai-pulse-recording {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

/* ── History items ── */
.ai-history-item {
  padding: var(--space-md) 0;
  border-bottom: 1px solid var(--border-subtle);
}

.ai-history-item:last-child {
  border-bottom: none;
}

.ai-history-q {
  font-size: var(--font-base);
  font-weight: var(--font-weight-semibold);
  color: var(--brand-gold);
  margin-bottom: var(--space-xs);
}

.ai-history-a {
  font-size: var(--font-sm);
  color: var(--text-secondary);
  line-height: var(--line-height-normal);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.ai-history-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: var(--font-xs);
  color: var(--text-muted);
}

.ai-history-time { }

.ai-history-stars {
  letter-spacing: 2px;
}

/* ── Auto-resize textarea ── */
.ai-input {
  resize: none;
  overflow-y: hidden;
  min-height: var(--btn-min-h);
  max-height: 120px;
  padding: 12px 14px;
  line-height: 1.4;
  font-family: inherit;
}

/* ── Message timestamp ── */
.ai-msg-time {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ── Send button spinner ── */
.btn-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(2,4,8,0.3);
  border-top-color: var(--bg-deep);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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