/**
 * AI学习助手 · 样式 v3.0
 * docs.yz520gzy.top
 *
 * v3.0 升级：
 * - 毛玻璃效果（glassmorphism）
 * - 精致排版与间距体系
 * - 高级骨架屏加载动画
 * - 连接状态指示器样式
 * - 消息搜索栏 + 高亮
 * - 代码块语言标签
 * - 完整平板适配（iPad/Android Tablet）
 * - 横屏/竖屏模式适配
 * - 44px 最小触控区域（WCAG标准）
 * - 更精致的滚动条
 * - 弹性动画（spring physics）
 * - 深色模式精调
 */

/* ═══════════════════════════════════════ */
/* CSS 变量                                 */
/* ═══════════════════════════════════════ */
:root {
  --ai-primary: #4361ee;
  --ai-primary-light: #6c83f5;
  --ai-primary-dark: #3250d6;
  --ai-primary-glow: rgba(67, 97, 238, 0.25);
  --ai-accent: #7c3aed;
  --ai-success: #10b981;
  --ai-warning: #f59e0b;
  --ai-error: #ef4444;
  --ai-bg: #ffffff;
  --ai-bg-secondary: #f8fafc;
  --ai-bg-tertiary: #f1f5f9;
  --ai-surface: rgba(255, 255, 255, 0.85);
  --ai-surface-hover: rgba(255, 255, 255, 0.95);
  --ai-text: #1e293b;
  --ai-text-secondary: #64748b;
  --ai-text-muted: #94a3b8;
  --ai-border: rgba(226, 232, 240, 0.8);
  --ai-border-strong: #cbd5e1;
  --ai-shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --ai-shadow-md: 0 4px 12px rgba(0,0,0,0.08), 0 2px 6px rgba(0,0,0,0.04);
  --ai-shadow-lg: 0 10px 40px rgba(0,0,0,0.12), 0 4px 16px rgba(0,0,0,0.06);
  --ai-shadow-xl: 0 20px 60px rgba(0,0,0,0.15), 0 8px 24px rgba(0,0,0,0.08);
  --ai-radius: 16px;
  --ai-radius-sm: 10px;
  --ai-radius-xs: 6px;
  --ai-panel-w: 420px;
  --ai-panel-h: 680px;
  --ai-toggle-size: 56px;
  --ai-header-h: 64px;
  --ai-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --ai-mono: 'JetBrains Mono', 'Fira Code', 'SF Mono', 'Cascadia Code', Consolas, monospace;
  --ai-transition: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ai-transition-smooth: cubic-bezier(0.4, 0, 0.2, 1);
  --ai-backdrop: blur(16px) saturate(180%);
  --ai-user-bg: linear-gradient(135deg, var(--ai-primary), var(--ai-accent));
  --ai-assistant-bg: var(--ai-bg-secondary);
  --ai-code-bg: #1e1e2e;
  --ai-code-text: #cdd6f4;
  --ai-skeleton-bg: linear-gradient(90deg, #e2e8f0 25%, #f1f5f9 50%, #e2e8f0 75%);
}

/* 深色模式 */
[data-md-color-scheme="slate"] {
  --ai-primary: #818cf8;
  --ai-primary-light: #a5b4fc;
  --ai-primary-dark: #6366f1;
  --ai-primary-glow: rgba(129, 140, 248, 0.2);
  --ai-accent: #a78bfa;
  --ai-bg: #1e1e2e;
  --ai-bg-secondary: #181825;
  --ai-bg-tertiary: #11111b;
  --ai-surface: rgba(30, 30, 46, 0.9);
  --ai-surface-hover: rgba(30, 30, 46, 0.95);
  --ai-text: #cdd6f4;
  --ai-text-secondary: #a6adc8;
  --ai-text-muted: #6c7086;
  --ai-border: rgba(69, 71, 90, 0.6);
  --ai-border-strong: #585b70;
  --ai-shadow-sm: 0 1px 3px rgba(0,0,0,0.2);
  --ai-shadow-md: 0 4px 12px rgba(0,0,0,0.3);
  --ai-shadow-lg: 0 10px 40px rgba(0,0,0,0.4);
  --ai-shadow-xl: 0 20px 60px rgba(0,0,0,0.5);
  --ai-assistant-bg: #181825;
  --ai-code-bg: #11111b;
  --ai-skeleton-bg: linear-gradient(90deg, #313244 25%, #45475a 50%, #313244 75%);
}

/* ═══════════════════════════════════════ */
/* 浮动按钮                                 */
/* ═══════════════════════════════════════ */
.ai-chat-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9998;
  width: var(--ai-toggle-size);
  height: var(--ai-toggle-size);
  border-radius: 50%;
  border: none;
  background: var(--ai-user-bg);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--ai-shadow-lg), 0 0 0 0 var(--ai-primary-glow);
  transition: all 0.4s var(--ai-transition);
  opacity: 0;
  transform: scale(0) rotate(-180deg);
  -webkit-tap-highlight-color: transparent;
  outline: none;
}

.ai-chat-toggle--ready {
  opacity: 1;
  transform: scale(1) rotate(0deg);
}

.ai-chat-toggle:hover {
  transform: scale(1.08);
  box-shadow: var(--ai-shadow-xl), 0 0 0 8px var(--ai-primary-glow);
}

.ai-chat-toggle:active {
  transform: scale(0.95);
}

.ai-chat-toggle:focus-visible {
  outline: 3px solid var(--ai-primary-light);
  outline-offset: 3px;
}

.ai-chat-icon {
  width: 26px;
  height: 26px;
  transition: all 0.4s var(--ai-transition);
  position: absolute;
}

.ai-chat-icon--chat {
  opacity: 1;
  transform: scale(1) rotate(0deg);
}

.ai-chat-icon--close {
  opacity: 0;
  transform: scale(0) rotate(90deg);
}

.ai-chat-toggle--open .ai-chat-icon--chat {
  opacity: 0;
  transform: scale(0) rotate(-90deg);
}

.ai-chat-toggle--open .ai-chat-icon--close {
  opacity: 1;
  transform: scale(1) rotate(0deg);
}

.ai-chat-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--ai-success);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 10px;
  letter-spacing: 0.5px;
  box-shadow: 0 2px 6px rgba(16, 185, 129, 0.4);
  animation: ai-badge-pulse 3s ease-in-out infinite;
}

@keyframes ai-badge-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

.ai-chat-toggle--open .ai-chat-badge {
  opacity: 0;
  transform: scale(0);
}

/* ═══════════════════════════════════════ */
/* 聊天面板                                 */
/* ═══════════════════════════════════════ */
.ai-chat-panel {
  position: fixed;
  bottom: 96px;
  right: 24px;
  z-index: 9999;
  width: var(--ai-panel-w);
  max-height: var(--ai-panel-h);
  height: calc(100vh - 140px);
  border-radius: var(--ai-radius);
  background: var(--ai-surface);
  backdrop-filter: var(--ai-backdrop);
  -webkit-backdrop-filter: var(--ai-backdrop);
  border: 1px solid var(--ai-border);
  box-shadow: var(--ai-shadow-xl);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px) scale(0.95);
  transform-origin: bottom right;
  transition: all 0.35s var(--ai-transition);
  font-family: var(--ai-font);
}

.ai-chat-panel--open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* ═══════════════════════════════════════ */
/* 头部                                     */
/* ═══════════════════════════════════════ */
.ai-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  min-height: var(--ai-header-h);
  background: var(--ai-surface);
  backdrop-filter: var(--ai-backdrop);
  border-bottom: 1px solid var(--ai-border);
  flex-shrink: 0;
  gap: 8px;
}

.ai-chat-header__info {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.ai-chat-avatar {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: var(--ai-user-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
  box-shadow: var(--ai-shadow-sm);
}

.ai-chat-avatar svg {
  width: 22px;
  height: 22px;
}

.ai-chat-header__name {
  font-size: 15px;
  font-weight: 700;
  color: var(--ai-text);
  line-height: 1.3;
  display: flex;
  align-items: center;
  gap: 6px;
}

.ai-chat-version {
  font-size: 10px;
  font-weight: 500;
  color: var(--ai-text-muted);
  background: var(--ai-bg-tertiary);
  padding: 1px 5px;
  border-radius: 4px;
  letter-spacing: 0.3px;
}

.ai-chat-header__status {
  font-size: 12px;
  color: var(--ai-text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
  line-height: 1.3;
}

/* 状态指示灯 */
.ai-chat-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: background 0.3s ease;
}

.ai-chat-status-dot[data-status="online"] {
  background: var(--ai-success);
  box-shadow: 0 0 6px rgba(16, 185, 129, 0.5);
  animation: ai-dot-pulse 2s ease-in-out infinite;
}

.ai-chat-status-dot[data-status="thinking"] {
  background: var(--ai-warning);
  box-shadow: 0 0 6px rgba(245, 158, 11, 0.5);
  animation: ai-dot-blink 0.8s ease-in-out infinite;
}

.ai-chat-status-dot[data-status="offline"] {
  background: var(--ai-error);
  box-shadow: 0 0 6px rgba(239, 68, 68, 0.4);
}

@keyframes ai-dot-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

@keyframes ai-dot-blink {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.8); }
}

.ai-chat-header__actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

.ai-chat-header__btn {
  width: 36px;
  height: 36px;
  min-width: 36px;
  border: none;
  background: transparent;
  color: var(--ai-text-secondary);
  cursor: pointer;
  border-radius: var(--ai-radius-xs);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.ai-chat-header__btn:hover {
  background: var(--ai-bg-tertiary);
  color: var(--ai-text);
}

.ai-chat-header__btn:active {
  transform: scale(0.9);
}

/* ═══════════════════════════════════════ */
/* 搜索栏                                   */
/* ═══════════════════════════════════════ */
.ai-chat-search {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--ai-bg-tertiary);
  border-bottom: 1px solid var(--ai-border);
  flex-shrink: 0;
  animation: ai-slide-down 0.2s ease;
}

@keyframes ai-slide-down {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.ai-chat-search__input {
  flex: 1;
  border: 1px solid var(--ai-border);
  border-radius: var(--ai-radius-xs);
  padding: 6px 10px;
  font-size: 13px;
  color: var(--ai-text);
  background: var(--ai-bg);
  outline: none;
  font-family: var(--ai-font);
  transition: border-color 0.2s ease;
}

.ai-chat-search__input:focus {
  border-color: var(--ai-primary);
  box-shadow: 0 0 0 3px var(--ai-primary-glow);
}

.ai-chat-search__count {
  font-size: 12px;
  color: var(--ai-text-muted);
  white-space: nowrap;
}

.ai-chat-search__close {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--ai-text-secondary);
  cursor: pointer;
  border-radius: var(--ai-radius-xs);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.ai-chat-search__close:hover {
  background: var(--ai-border);
}

/* 搜索高亮 */
.ai-chat-message--highlight {
  background: var(--ai-primary-glow) !important;
  border-left: 3px solid var(--ai-primary) !important;
  transition: all 0.3s ease;
}

/* ═══════════════════════════════════════ */
/* 快捷操作                                 */
/* ═══════════════════════════════════════ */
.ai-chat-actions {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 10px 14px;
  background: var(--ai-bg-secondary);
  border-bottom: 1px solid var(--ai-border);
  flex-shrink: 0;
}

.ai-chat-action {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 10px 4px 8px;
  border: 1px solid var(--ai-border);
  border-radius: var(--ai-radius-sm);
  background: var(--ai-bg);
  color: var(--ai-text);
  cursor: pointer;
  font-size: 11px;
  font-family: var(--ai-font);
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  min-height: 44px;
}

.ai-chat-action:hover {
  border-color: var(--ai-primary);
  background: var(--ai-primary-glow);
  transform: translateY(-1px);
  box-shadow: var(--ai-shadow-sm);
}

.ai-chat-action:active {
  transform: translateY(0) scale(0.97);
}

.ai-chat-action__icon {
  font-size: 18px;
  line-height: 1;
}

.ai-chat-action__text {
  font-size: 11px;
  font-weight: 500;
  color: var(--ai-text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* ═══════════════════════════════════════ */
/* 消息区域                                 */
/* ═══════════════════════════════════════ */
.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

/* 精致滚动条 */
.ai-chat-messages::-webkit-scrollbar {
  width: 5px;
}

.ai-chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.ai-chat-messages::-webkit-scrollbar-thumb {
  background: var(--ai-border-strong);
  border-radius: 10px;
}

.ai-chat-messages::-webkit-scrollbar-thumb:hover {
  background: var(--ai-text-muted);
}

/* ═══════════════════════════════════════ */
/* 欢迎界面                                 */
/* ═══════════════════════════════════════ */
.ai-chat-welcome {
  text-align: center;
  padding: 24px 12px;
  animation: ai-fade-up 0.5s ease;
}

@keyframes ai-fade-up {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

.ai-chat-welcome__icon {
  margin-bottom: 12px;
  color: var(--ai-primary);
  animation: ai-float 3s ease-in-out infinite;
}

@keyframes ai-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.ai-chat-welcome__title {
  font-size: 20px;
  font-weight: 700;
  color: var(--ai-text);
  margin-bottom: 6px;
}

.ai-chat-welcome__text {
  font-size: 14px;
  color: var(--ai-text-secondary);
  margin-bottom: 16px;
}

.ai-chat-welcome__grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 16px;
  text-align: left;
}

.ai-chat-welcome__item {
  font-size: 13px;
  color: var(--ai-text);
  padding: 8px 12px;
  background: var(--ai-bg-tertiary);
  border-radius: var(--ai-radius-xs);
  border: 1px solid var(--ai-border);
  transition: all 0.2s ease;
}

.ai-chat-welcome__item:hover {
  border-color: var(--ai-primary);
  background: var(--ai-primary-glow);
}

.ai-chat-welcome__hint {
  font-size: 12px;
  color: var(--ai-text-muted);
  padding: 8px;
  background: var(--ai-bg-tertiary);
  border-radius: var(--ai-radius-xs);
}

/* ═══════════════════════════════════════ */
/* 消息气泡                                 */
/* ═══════════════════════════════════════ */
.ai-chat-message {
  display: flex;
  gap: 10px;
  animation: ai-msg-in 0.35s var(--ai-transition);
  max-width: 100%;
}

@keyframes ai-msg-in {
  from { opacity: 0; transform: translateY(10px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* 用户消息 */
.ai-chat-message--user {
  flex-direction: column;
  align-items: flex-end;
}

.ai-chat-message--user .ai-chat-message__content {
  background: var(--ai-user-bg);
  color: #fff;
  border-radius: var(--ai-radius-sm) var(--ai-radius-sm) 4px var(--ai-radius-sm);
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.65;
  word-break: break-word;
  white-space: pre-wrap;
  max-width: 85%;
  box-shadow: var(--ai-shadow-sm);
}

.ai-chat-message--user .ai-chat-message__time {
  font-size: 11px;
  color: var(--ai-text-muted);
  margin-top: 3px;
  padding-right: 2px;
}

/* 助手消息 */
.ai-chat-message--assistant {
  align-items: flex-start;
}

.ai-chat-message__avatar {
  width: 30px;
  height: 30px;
  border-radius: 10px;
  background: var(--ai-user-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
  margin-top: 2px;
  box-shadow: var(--ai-shadow-sm);
}

.ai-chat-message__body {
  flex: 1;
  min-width: 0;
  max-width: calc(100% - 42px);
}

.ai-chat-message--assistant .ai-chat-message__content {
  background: var(--ai-assistant-bg);
  border-radius: 4px var(--ai-radius-sm) var(--ai-radius-sm) var(--ai-radius-sm);
  padding: 12px 14px;
  font-size: 14px;
  line-height: 1.7;
  color: var(--ai-text);
  border: 1px solid var(--ai-border);
  word-break: break-word;
}

/* 流式消息光标 */
.ai-chat-message--streaming .ai-chat-message__content::after {
  content: '▊';
  display: inline;
  animation: ai-cursor-blink 0.7s step-end infinite;
  color: var(--ai-primary);
  font-weight: 400;
  margin-left: 1px;
}

@keyframes ai-cursor-blink {
  50% { opacity: 0; }
}

/* 消息元信息 */
.ai-chat-message__meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  padding-left: 2px;
}

.ai-chat-message__meta .ai-chat-message__time {
  font-size: 11px;
  color: var(--ai-text-muted);
}

.ai-chat-message__action {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--ai-text-muted);
  cursor: pointer;
  border-radius: var(--ai-radius-xs);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.ai-chat-message__action:hover {
  background: var(--ai-bg-tertiary);
  color: var(--ai-primary);
}

.ai-chat-message__action:active {
  transform: scale(0.85);
}

/* ═══════════════════════════════════════ */
/* Markdown 渲染                            */
/* ═══════════════════════════════════════ */
.ai-chat-md h1, .ai-chat-md h2, .ai-chat-md h3,
.ai-chat-md h4, .ai-chat-md h5, .ai-chat-md h6 {
  margin: 14px 0 8px;
  font-weight: 700;
  color: var(--ai-text);
  line-height: 1.35;
}

.ai-chat-md h1 { font-size: 18px; }
.ai-chat-md h2 { font-size: 16px; }
.ai-chat-md h3 { font-size: 15px; }
.ai-chat-md h4, .ai-chat-md h5, .ai-chat-md h6 { font-size: 14px; }

.ai-chat-md p {
  margin: 6px 0;
  line-height: 1.7;
}

.ai-chat-md ul, .ai-chat-md ol {
  margin: 6px 0;
  padding-left: 20px;
}

.ai-chat-md li {
  margin: 3px 0;
  line-height: 1.6;
}

.ai-chat-md li::marker {
  color: var(--ai-primary);
}

.ai-chat-md code {
  font-family: var(--ai-mono);
  font-size: 0.88em;
  background: var(--ai-bg-tertiary);
  color: var(--ai-primary-dark);
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--ai-border);
  word-break: break-word;
}

[data-md-color-scheme="slate"] .ai-chat-md code {
  color: var(--ai-primary-light);
}

.ai-chat-md pre {
  margin: 10px 0;
  border-radius: var(--ai-radius-xs);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.ai-chat-md pre code {
  display: block;
  padding: 14px 16px;
  background: var(--ai-code-bg);
  color: var(--ai-code-text);
  border: none;
  font-size: 13px;
  line-height: 1.55;
  tab-size: 2;
  overflow-x: auto;
}

.ai-chat-md blockquote {
  margin: 8px 0;
  padding: 8px 14px;
  border-left: 3px solid var(--ai-primary);
  background: var(--ai-primary-glow);
  border-radius: 0 var(--ai-radius-xs) var(--ai-radius-xs) 0;
  color: var(--ai-text-secondary);
  font-size: 13px;
}

.ai-chat-md table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0;
  font-size: 13px;
  overflow-x: auto;
  display: block;
}

.ai-chat-md th, .ai-chat-md td {
  padding: 8px 10px;
  border: 1px solid var(--ai-border);
  text-align: left;
}

.ai-chat-md th {
  background: var(--ai-bg-tertiary);
  font-weight: 600;
  white-space: nowrap;
}

.ai-chat-md hr {
  border: none;
  height: 1px;
  background: var(--ai-border);
  margin: 12px 0;
}

.ai-chat-md a {
  color: var(--ai-primary);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s ease;
}

.ai-chat-md a:hover {
  border-bottom-color: var(--ai-primary);
}

.ai-chat-md strong {
  font-weight: 700;
  color: var(--ai-text);
}

.ai-chat-md em {
  font-style: italic;
  color: var(--ai-text-secondary);
}

.ai-chat-md img {
  max-width: 100%;
  border-radius: var(--ai-radius-xs);
}

/* ═══════════════════════════════════════ */
/* 代码块包装器                              */
/* ═══════════════════════════════════════ */
.ai-code-wrapper {
  position: relative;
  margin: 10px 0;
}

.ai-code-lang {
  position: absolute;
  top: 6px;
  left: 12px;
  font-size: 10px;
  font-family: var(--ai-mono);
  color: rgba(205, 214, 244, 0.5);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  pointer-events: none;
  z-index: 1;
}

.ai-code-copy {
  position: absolute;
  top: 6px;
  right: 8px;
  width: 30px;
  height: 30px;
  border: none;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(205, 214, 244, 0.6);
  cursor: pointer;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: all 0.2s ease;
  z-index: 2;
}

.ai-code-wrapper:hover .ai-code-copy {
  opacity: 1;
}

.ai-code-copy:hover {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
}

.ai-code-copy--done {
  color: var(--ai-success) !important;
  opacity: 1 !important;
}

/* ═══════════════════════════════════════ */
/* 思考指示器（骨架屏）                       */
/* ═══════════════════════════════════════ */
.ai-chat-thinking {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  animation: ai-msg-in 0.35s var(--ai-transition);
}

.ai-chat-thinking__body {
  flex: 1;
  background: var(--ai-assistant-bg);
  border: 1px solid var(--ai-border);
  border-radius: 4px var(--ai-radius-sm) var(--ai-radius-sm) var(--ai-radius-sm);
  padding: 14px;
  max-width: calc(100% - 42px);
}

.ai-chat-thinking__skeleton {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 8px;
}

.ai-chat-skeleton-line {
  height: 12px;
  border-radius: 6px;
  background: var(--ai-skeleton-bg);
  background-size: 200% 100%;
  animation: ai-skeleton-shimmer 1.5s ease-in-out infinite;
}

.ai-chat-skeleton-line--w80 { width: 80%; }
.ai-chat-skeleton-line--w60 { width: 60%; }
.ai-chat-skeleton-line--w40 { width: 40%; }

@keyframes ai-skeleton-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.ai-chat-thinking__text {
  font-size: 12px;
  color: var(--ai-text-muted);
  animation: ai-dot-blink 1.2s ease-in-out infinite;
}

/* ═══════════════════════════════════════ */
/* 滚到底部按钮                              */
/* ═══════════════════════════════════════ */
.ai-chat-scroll-btn {
  position: absolute;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--ai-border);
  background: var(--ai-surface);
  backdrop-filter: blur(8px);
  color: var(--ai-text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--ai-shadow-md);
  transition: all 0.2s ease;
  animation: ai-fade-up 0.25s ease;
}

.ai-chat-scroll-btn:hover {
  background: var(--ai-bg);
  color: var(--ai-primary);
  box-shadow: var(--ai-shadow-lg);
}

/* ═══════════════════════════════════════ */
/* 输入区域                                 */
/* ═══════════════════════════════════════ */
.ai-chat-input-area {
  padding: 12px 14px;
  border-top: 1px solid var(--ai-border);
  background: var(--ai-surface);
  flex-shrink: 0;
}

.ai-chat-input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--ai-bg);
  border: 1.5px solid var(--ai-border);
  border-radius: var(--ai-radius-sm);
  padding: 8px 10px;
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
  position: relative;
}

.ai-chat-input-wrapper:focus-within {
  border-color: var(--ai-primary);
  box-shadow: 0 0 0 3px var(--ai-primary-glow);
}

.ai-chat-input {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font-size: 14px;
  font-family: var(--ai-font);
  line-height: 1.55;
  color: var(--ai-text);
  background: transparent;
  max-height: 120px;
  min-height: 22px;
  padding: 2px 0;
}

.ai-chat-input::placeholder {
  color: var(--ai-text-muted);
}

.ai-chat-char-count {
  position: absolute;
  right: 56px;
  bottom: 10px;
  font-size: 11px;
  color: var(--ai-text-muted);
  pointer-events: none;
  transition: color 0.2s ease;
}

.ai-chat-char-count--warn {
  color: var(--ai-warning);
  font-weight: 600;
}

.ai-chat-send,
.ai-chat-stop {
  width: 36px;
  height: 36px;
  min-width: 36px;
  border: none;
  border-radius: var(--ai-radius-xs);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.ai-chat-send {
  background: var(--ai-user-bg);
  color: #fff;
}

.ai-chat-send:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none;
}

.ai-chat-send:not(:disabled):hover {
  transform: scale(1.05);
  box-shadow: var(--ai-shadow-sm);
}

.ai-chat-send:not(:disabled):active {
  transform: scale(0.92);
}

.ai-chat-stop {
  background: var(--ai-error);
  color: #fff;
  animation: ai-fade-up 0.2s ease;
}

.ai-chat-stop:hover {
  background: #dc2626;
}

.ai-chat-stop:active {
  transform: scale(0.92);
}

/* ═══════════════════════════════════════ */
/* 页脚                                     */
/* ═══════════════════════════════════════ */
.ai-chat-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: var(--ai-text-muted);
  padding-top: 8px;
  gap: 8px;
}

.ai-chat-engine {
  font-family: var(--ai-mono);
  font-size: 10px;
  color: var(--ai-text-muted);
  background: var(--ai-bg-tertiary);
  padding: 2px 6px;
  border-radius: 4px;
  white-space: nowrap;
}

/* ═══════════════════════════════════════ */
/* 移动端样式 (≤768px)                       */
/* ═══════════════════════════════════════ */
@media (max-width: 768px) {
  .ai-chat-toggle {
    bottom: 16px;
    right: 16px;
    width: 52px;
    height: 52px;
  }

  .ai-chat-icon {
    width: 24px;
    height: 24px;
  }

  .ai-chat-panel {
    bottom: 0;
    right: 0;
    left: 0;
    top: 0;
    width: 100%;
    max-height: 100%;
    height: 100%;
    border-radius: 0;
    transform: translateY(100%);
    transform-origin: bottom center;
  }

  .ai-chat-panel--open {
    transform: translateY(0);
  }

  .ai-chat-header {
    padding: 12px 14px;
    min-height: 58px;
    /* iOS safe area */
    padding-top: max(12px, env(safe-area-inset-top));
  }

  .ai-chat-header__btn {
    width: 44px;
    height: 44px;
    min-width: 44px;
  }

  .ai-chat-actions {
    grid-template-columns: repeat(4, 1fr);
    gap: 5px;
    padding: 8px 10px;
  }

  .ai-chat-action {
    padding: 8px 2px 6px;
    min-height: 44px;
  }

  .ai-chat-action__icon {
    font-size: 16px;
  }

  .ai-chat-action__text {
    font-size: 10px;
  }

  .ai-chat-messages {
    padding: 12px;
    gap: 12px;
  }

  .ai-chat-input-area {
    padding: 10px 12px;
    /* iOS safe area */
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }

  .ai-chat-send,
  .ai-chat-stop {
    width: 44px;
    height: 44px;
    min-width: 44px;
  }

  .ai-chat-message--user .ai-chat-message__content {
    max-width: 90%;
  }

  .ai-chat-welcome__grid {
    gap: 6px;
  }

  .ai-chat-welcome__item {
    padding: 6px 10px;
    font-size: 12px;
  }

  .ai-chat-scroll-btn {
    bottom: 90px;
    width: 40px;
    height: 40px;
  }
}

/* ═══════════════════════════════════════ */
/* 小屏手机 (≤380px)                         */
/* ═══════════════════════════════════════ */
@media (max-width: 380px) {
  .ai-chat-actions {
    grid-template-columns: repeat(2, 1fr);
    gap: 4px;
    padding: 6px 8px;
  }

  .ai-chat-action {
    flex-direction: row;
    gap: 6px;
    padding: 8px 10px;
  }

  .ai-chat-action__icon {
    font-size: 15px;
  }

  .ai-chat-welcome__grid {
    grid-template-columns: 1fr;
  }

  .ai-chat-header__name {
    font-size: 14px;
  }

  .ai-chat-avatar {
    width: 34px;
    height: 34px;
  }
}

/* ═══════════════════════════════════════ */
/* 平板 (769px ~ 1024px)                     */
/* ═══════════════════════════════════════ */
@media (min-width: 769px) and (max-width: 1024px) {
  .ai-chat-panel {
    --ai-panel-w: 400px;
    --ai-panel-h: 600px;
    bottom: 80px;
    right: 20px;
  }

  .ai-chat-toggle {
    bottom: 20px;
    right: 20px;
  }
}

/* ═══════════════════════════════════════ */
/* 横屏模式                                 */
/* ═══════════════════════════════════════ */
@media (max-height: 500px) and (orientation: landscape) {
  .ai-chat-panel {
    bottom: 0;
    right: 0;
    top: 0;
    width: 50vw;
    max-width: 450px;
    height: 100%;
    max-height: 100%;
    border-radius: var(--ai-radius) 0 0 var(--ai-radius);
    transform: translateX(100%);
  }

  .ai-chat-panel--open {
    transform: translateX(0);
  }

  .ai-chat-header {
    min-height: 48px;
    padding: 8px 14px;
  }

  .ai-chat-actions {
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    padding: 6px 10px;
  }

  .ai-chat-action {
    padding: 6px 2px;
    min-height: 36px;
  }

  .ai-chat-action__icon {
    font-size: 14px;
  }

  .ai-chat-action__text {
    font-size: 10px;
  }

  .ai-chat-messages {
    padding: 8px 12px;
    gap: 8px;
  }

  .ai-chat-input-area {
    padding: 6px 10px;
  }

  .ai-chat-toggle {
    bottom: 8px;
    right: 8px;
    width: 44px;
    height: 44px;
  }

  .ai-chat-icon {
    width: 20px;
    height: 20px;
  }
}

/* ═══════════════════════════════════════ */
/* 大屏桌面 (>1440px)                        */
/* ═══════════════════════════════════════ */
@media (min-width: 1441px) {
  .ai-chat-panel {
    --ai-panel-w: 460px;
    --ai-panel-h: 740px;
  }

  .ai-chat-toggle {
    width: 60px;
    height: 60px;
    bottom: 28px;
    right: 28px;
  }

  .ai-chat-icon {
    width: 28px;
    height: 28px;
  }
}

/* ═══════════════════════════════════════ */
/* 无障碍：减少动画                           */
/* ═══════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .ai-chat-panel {
    transition: opacity 0.15s ease;
    transform: none !important;
  }

  .ai-chat-panel--open {
    opacity: 1;
  }
}

/* ═══════════════════════════════════════ */
/* 高对比度模式                              */
/* ═══════════════════════════════════════ */
@media (prefers-contrast: high) {
  .ai-chat-panel {
    border-width: 2px;
  }

  .ai-chat-message--user .ai-chat-message__content {
    border: 2px solid #fff;
  }

  .ai-chat-message--assistant .ai-chat-message__content {
    border-width: 2px;
  }

  .ai-chat-header__btn:focus-visible,
  .ai-chat-send:focus-visible,
  .ai-chat-toggle:focus-visible {
    outline: 3px solid currentColor;
    outline-offset: 2px;
  }
}

/* ═══════════════════════════════════════ */
/* 打印样式                                 */
/* ═══════════════════════════════════════ */
@media print {
  .ai-chat-toggle,
  .ai-chat-panel {
    display: none !important;
  }
}
