/* ============================================================
   Java 面试知识库 - 样式表
   ============================================================ */

/* CSS Variables */
:root {
  --primary: #2563eb;
  --primary-light: #3b82f6;
  --primary-dark: #1d4ed8;
  --bg: #ffffff;
  --bg-secondary: #f8fafc;
  --bg-tertiary: #f1f5f9;
  --text: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  --radius: 8px;
  --radius-sm: 4px;
  --radius-lg: 12px;
  --sidebar-width: 300px;
  --header-height: 60px;
  --transition: 0.2s ease;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SF Mono", "Fira Code", "Fira Mono", "Roboto Mono", monospace;
}

[data-theme="dark"] {
  --primary: #3b82f6;
  --primary-light: #60a5fa;
  --primary-dark: #2563eb;
  --bg: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --text: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --border: #334155;
  --border-light: #1e293b;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
}

/* Reset */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ============================================================
   Header
   ============================================================ */
.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  z-index: 1000;
  backdrop-filter: blur(8px);
  background: rgba(255, 255, 255, 0.9);
}

[data-theme="dark"] .header {
  background: rgba(15, 23, 42, 0.9);
}

.menu-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 36px;
  height: 36px;
  border: none;
  background: none;
  cursor: pointer;
  gap: 5px;
  margin-right: 12px;
}

.menu-toggle span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: var(--transition);
}

.menu-toggle.active span:nth-child(1) {
  transform: rotate(45deg) translate(5px, 5px);
}

.menu-toggle.active span:nth-child(2) {
  opacity: 0;
}

.menu-toggle.active span:nth-child(3) {
  transform: rotate(-45deg) translate(5px, -5px);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  flex-shrink: 0;
}

.header-logo {
  font-size: 24px;
}

.header-brand h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
}

/* Search */
.search-box {
  position: relative;
}

.search-box input {
  width: 280px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 14px;
  background: var(--bg-secondary);
  color: var(--text);
  outline: none;
  transition: var(--transition);
}

.search-box input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
  width: 320px;
}

.search-results {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  min-width: 360px;
  max-height: 400px;
  overflow-y: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  display: none;
  z-index: 1001;
}

.search-results.active {
  display: block;
}

.search-result-item {
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-light);
  transition: var(--transition);
}

.search-result-item:hover {
  background: var(--bg-secondary);
}

.search-result-item .result-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

.search-result-item .result-module {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Theme Toggle */
.theme-toggle {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--bg-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: var(--transition);
}

.theme-toggle:hover {
  background: var(--bg-tertiary);
}

.theme-icon-dark {
  display: none;
}

[data-theme="dark"] .theme-icon-light {
  display: none;
}

[data-theme="dark"] .theme-icon-dark {
  display: inline;
}

/* ============================================================
   Main Container
   ============================================================ */
.main-container {
  display: flex;
  margin-top: var(--header-height);
  min-height: calc(100vh - var(--header-height));
}

/* ============================================================
   Sidebar
   ============================================================ */
.sidebar {
  position: fixed;
  top: var(--header-height);
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 900;
  transition: transform 0.3s ease;
}

.sidebar-header {
  padding: 20px 16px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  background: var(--bg-secondary);
  z-index: 1;
}

.sidebar-header h2 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.module-count {
  font-size: 12px;
  background: var(--primary);
  color: #fff;
  padding: 2px 8px;
  border-radius: 10px;
}

.sidebar-nav {
  padding: 0 8px 20px;
}

/* Module Item */
.module-item {
  margin-bottom: 2px;
}

.module-header {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  user-select: none;
}

.module-header:hover {
  background: var(--bg-tertiary);
}

.module-header.active {
  background: rgba(37, 99, 235, 0.08);
  color: var(--primary);
}

.module-icon {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 10px;
  flex-shrink: 0;
}

.module-name {
  font-size: 14px;
  font-weight: 500;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.module-badge {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg);
  padding: 1px 6px;
  border-radius: 10px;
  margin-left: 8px;
  flex-shrink: 0;
}

.module-arrow {
  margin-left: 6px;
  font-size: 10px;
  color: var(--text-muted);
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.module-header.expanded .module-arrow {
  transform: rotate(90deg);
}

/* Article List */
.module-articles {
  display: none;
  padding: 2px 0 6px 30px;
}

.module-articles.expanded {
  display: block;
}

.article-item {
  padding: 6px 10px;
  font-size: 13px;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-left: 2px solid transparent;
}

.article-item:hover {
  background: var(--bg-tertiary);
  color: var(--text);
}

.article-item.active {
  background: rgba(37, 99, 235, 0.08);
  color: var(--primary);
  border-left-color: var(--primary);
  font-weight: 500;
}

/* Sidebar Overlay */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: var(--header-height);
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 899;
}

/* ============================================================
   Content
   ============================================================ */
.content {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding: 24px 32px;
  max-width: 900px;
  min-height: calc(100vh - var(--header-height));
}

/* Breadcrumb */
.breadcrumb {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  padding: 8px 0;
  margin-bottom: 20px;
  font-size: 13px;
}

.breadcrumb-item {
  color: var(--text-secondary);
  text-decoration: none;
  transition: var(--transition);
  cursor: pointer;
}

.breadcrumb-item:hover {
  color: var(--primary);
}

.breadcrumb-separator {
  color: var(--text-muted);
  margin: 0 4px;
}

.breadcrumb-current {
  color: var(--text);
  font-weight: 500;
}

/* ============================================================
   Home Page
   ============================================================ */
.home-hero {
  text-align: center;
  padding: 40px 20px;
  margin-bottom: 40px;
}

.home-hero h2 {
  font-size: 32px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 12px;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.home-hero p {
  font-size: 16px;
  color: var(--text-secondary);
  max-width: 500px;
  margin: 0 auto;
  line-height: 1.7;
}

.home-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin: 30px 0;
  max-width: 500px;
  margin-left: auto;
  margin-right: auto;
}

.stat-card {
  text-align: center;
  padding: 20px;
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}

.stat-number {
  font-size: 28px;
  font-weight: 800;
  color: var(--primary);
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Module Groups Grid */
.module-groups {
  margin-top: 40px;
}

.module-groups h3 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 20px;
  text-align: center;
}

.group-section {
  margin-bottom: 28px;
}

.group-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 10px;
  padding-left: 4px;
  border-left: 3px solid var(--primary);
  padding-left: 10px;
}

.group-modules {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
}

.group-module-card {
  padding: 12px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 8px;
}

.group-module-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.group-module-card .card-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.group-module-card .card-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.group-module-card .card-count {
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* ============================================================
   Module Page (Article List)
   ============================================================ */
.module-page-header {
  margin-bottom: 24px;
}

.module-page-header h2 {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
}

.module-page-header .module-desc {
  font-size: 14px;
  color: var(--text-secondary);
}

.article-list {
  list-style: none;
}

.article-list-item {
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 10px;
}

.article-list-item:hover {
  border-color: var(--primary);
  background: var(--bg-secondary);
  box-shadow: var(--shadow);
}

.article-list-item .article-num {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  width: 28px;
  text-align: center;
  flex-shrink: 0;
}

.article-list-item .article-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  flex: 1;
}

.article-list-item .article-read-badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 10px;
  background: #dcfce7;
  color: #166534;
  flex-shrink: 0;
}

[data-theme="dark"] .article-list-item .article-read-badge {
  background: #064e3b;
  color: #6ee7b7;
}

/* ============================================================
   Article Content Page
   ============================================================ */
.article-header {
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.article-header h2 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.4;
}

.article-meta {
  margin-top: 8px;
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  gap: 16px;
}

/* Markdown Content Styles */
.markdown-body {
  font-size: 15px;
  line-height: 1.8;
  color: var(--text);
}

.markdown-body h1 {
  font-size: 24px;
  font-weight: 700;
  margin: 28px 0 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.markdown-body h2 {
  font-size: 20px;
  font-weight: 700;
  margin: 24px 0 12px;
}

.markdown-body h3 {
  font-size: 17px;
  font-weight: 600;
  margin: 20px 0 10px;
}

.markdown-body h4, .markdown-body h5, .markdown-body h6 {
  font-size: 15px;
  font-weight: 600;
  margin: 16px 0 8px;
}

.markdown-body p {
  margin: 12px 0;
}

.markdown-body ul, .markdown-body ol {
  margin: 12px 0;
  padding-left: 24px;
}

.markdown-body li {
  margin: 6px 0;
}

.markdown-body blockquote {
  margin: 16px 0;
  padding: 12px 16px;
  border-left: 4px solid var(--primary);
  background: var(--bg-secondary);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-secondary);
}

.markdown-body blockquote p {
  margin: 4px 0;
}

.markdown-body code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  padding: 2px 6px;
  background: var(--bg-tertiary);
  border-radius: 3px;
  color: #e11d48;
}

[data-theme="dark"] .markdown-body code {
  color: #fb7185;
}

.markdown-body pre {
  margin: 16px 0;
  border-radius: var(--radius);
  overflow-x: auto;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
}

.markdown-body pre code {
  display: block;
  padding: 16px;
  background: none;
  color: var(--text);
  font-size: 13px;
  line-height: 1.6;
  border-radius: 0;
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: 14px;
  overflow-x: auto;
  display: block;
}

.markdown-body th, .markdown-body td {
  padding: 10px 14px;
  border: 1px solid var(--border);
  text-align: left;
}

.markdown-body th {
  background: var(--bg-secondary);
  font-weight: 600;
}

.markdown-body img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
  margin: 12px 0;
}

.markdown-body a {
  color: var(--primary);
  text-decoration: none;
}

.markdown-body a:hover {
  text-decoration: underline;
}

.markdown-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 24px 0;
}

.markdown-body strong {
  font-weight: 600;
  color: var(--text);
}

/* Article Navigation */
.article-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 40px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  gap: 12px;
}

.article-nav-btn {
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  transition: var(--transition);
  max-width: 45%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.article-nav-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

/* ============================================================
   Back to Top
   ============================================================ */
.back-to-top {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 18px;
  display: none;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-md);
  transition: var(--transition);
  z-index: 800;
}

.back-to-top.visible {
  display: flex;
}

.back-to-top:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

/* ============================================================
   Scrollbar
   ============================================================ */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ============================================================
   Responsive Design
   ============================================================ */
@media (max-width: 1024px) {
  .content {
    padding: 20px 24px;
  }

  .search-box input {
    width: 200px;
  }

  .search-box input:focus {
    width: 240px;
  }
}

@media (max-width: 768px) {
  .menu-toggle {
    display: flex;
  }

  .sidebar {
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay.active {
    display: block;
  }

  .content {
    margin-left: 0;
    padding: 16px;
  }

  .header-brand h1 {
    font-size: 15px;
  }

  .search-box input {
    width: 140px;
    font-size: 13px;
    padding: 6px 12px;
  }

  .search-box input:focus {
    width: 180px;
  }

  .search-results {
    min-width: 280px;
    right: -40px;
    left: auto;
  }

  .home-hero h2 {
    font-size: 24px;
  }

  .home-stats {
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
  }

  .stat-number {
    font-size: 22px;
  }

  .group-modules {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }

  .article-nav {
    flex-direction: column;
  }

  .article-nav-btn {
    max-width: 100%;
  }

  .markdown-body pre code {
    font-size: 12px;
  }
}

@media (max-width: 480px) {
  .header {
    padding: 0 12px;
  }

  .header-brand h1 {
    font-size: 14px;
  }

  .search-box input {
    width: 110px;
  }

  .search-box input:focus {
    width: 150px;
  }

  .home-hero {
    padding: 24px 12px;
  }

  .home-hero h2 {
    font-size: 20px;
  }

  .group-modules {
    grid-template-columns: 1fr 1fr;
  }

  .content {
    padding: 12px;
  }

  .markdown-body {
    font-size: 14px;
  }
}

/* ============================================================
   Animations
   ============================================================ */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.content-body {
  animation: fadeIn 0.3s ease;
}

/* Loading */
.loading {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
}

.loading::after {
  content: '';
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-top: 12px;
}

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

/* Empty State */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state .empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

/* ============================================================
   Print Styles
   ============================================================ */
@media print {
  .header, .sidebar, .sidebar-overlay, .back-to-top, .breadcrumb, .article-nav, .ai-toggle-btn, .ai-panel {
    display: none !important;
  }

  .content {
    margin-left: 0 !important;
    padding: 0 !important;
    max-width: 100% !important;
  }

  .markdown-body pre {
    white-space: pre-wrap;
    word-wrap: break-word;
  }
}

/* ============================================================
   AI Assistant Panel
   ============================================================ */

/* Toggle Button */
.ai-toggle-btn {
  position: fixed;
  bottom: 80px;
  right: 24px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
  z-index: 1100;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  gap: 1px;
}

.ai-toggle-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.5);
}

.ai-toggle-btn.hidden {
  display: none;
}

.ai-toggle-icon {
  font-size: 20px;
  line-height: 1;
}

.ai-toggle-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

/* Panel */
.ai-panel {
  position: fixed;
  top: var(--header-height);
  right: 0;
  bottom: 0;
  width: 420px;
  max-width: 100vw;
  background: var(--bg);
  border-left: 1px solid var(--border);
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.1);
  z-index: 1200;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.3s ease;
}

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

/* Panel Header */
.ai-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.ai-panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ai-panel-title span {
  font-size: 20px;
}

.ai-panel-title h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.ai-panel-actions {
  display: flex;
  gap: 4px;
}

.ai-header-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: none;
  cursor: pointer;
  border-radius: var(--radius-sm);
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: var(--transition);
}

.ai-header-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text);
}

.ai-close-btn {
  font-size: 22px;
  font-weight: 300;
}

/* Panel Options */
.ai-panel-options {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.ai-option-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.ai-option-row:last-child {
  margin-bottom: 0;
}

.ai-option-row label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  width: 32px;
  flex-shrink: 0;
}

.ai-option-row select {
  flex: 1;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  background: var(--bg-secondary);
  color: var(--text);
  outline: none;
  cursor: pointer;
  max-width: 100%;
}

.ai-option-row select:focus {
  border-color: var(--primary);
}

/* Article Search Dropdown */
.ai-article-search-wrap {
  flex: 1;
  position: relative;
  min-width: 0;
}

.ai-article-search-input {
  width: 100%;
  padding: 5px 28px 5px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  background: var(--bg-secondary);
  color: var(--text);
  outline: none;
  cursor: text;
  box-sizing: border-box;
}

.ai-article-search-input:focus {
  border-color: var(--primary);
}

.ai-article-search-input.has-value {
  color: var(--text);
  font-weight: 500;
}

.ai-article-search-clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  cursor: pointer;
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1;
  display: none;
  z-index: 2;
}

.ai-article-search-clear:hover {
  color: var(--text);
}

.ai-article-search-wrap.has-value .ai-article-search-clear {
  display: block;
}

.ai-article-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 4px;
  max-height: 300px;
  overflow-y: auto;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  z-index: 1000;
}

.ai-article-dropdown.open {
  display: block;
}

.ai-article-dropdown-group {
  padding: 6px 10px 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
}

.ai-article-dropdown-item {
  padding: 6px 10px;
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ai-article-dropdown-item:hover {
  background: var(--primary);
  color: #fff;
}

.ai-article-dropdown-item.active {
  background: color-mix(in srgb, var(--primary) 15%, transparent);
  font-weight: 500;
}

.ai-article-dropdown-empty {
  padding: 12px 10px;
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
}

.ai-article-dropdown-item-free {
  padding: 6px 10px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  font-style: italic;
  border-bottom: 1px solid var(--border);
}

.ai-article-dropdown-item-free:hover {
  background: var(--primary);
  color: #fff;
}

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

/* Welcome */
.ai-welcome {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.ai-welcome-icon {
  font-size: 40px;
  margin-bottom: 12px;
}

.ai-welcome h4 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.ai-welcome p {
  font-size: 13px;
  line-height: 1.6;
}

/* Message Bubbles */
.ai-msg {
  display: flex;
  width: 100%;
}

.ai-msg-user {
  justify-content: flex-end;
}

.ai-msg-assistant {
  justify-content: flex-start;
}

.ai-msg-bubble {
  max-width: 88%;
  position: relative;
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  font-size: 13px;
  line-height: 1.7;
  word-break: break-word;
}

.ai-msg-user .ai-msg-bubble {
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.ai-msg-assistant .ai-msg-bubble {
  background: var(--bg-secondary);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.ai-msg-content {
  overflow-wrap: break-word;
}

.ai-msg-content p {
  margin: 4px 0;
}

.ai-msg-content p:first-child {
  margin-top: 0;
}

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

.ai-msg-content pre {
  margin: 8px 0;
  padding: 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-tertiary);
  overflow-x: auto;
  font-size: 12px;
}

.ai-msg-content code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  padding: 1px 4px;
  background: var(--bg-tertiary);
  border-radius: 3px;
}

.ai-msg-content pre code {
  padding: 0;
  background: none;
}

.ai-msg-user .ai-msg-content code {
  background: rgba(255,255,255,0.2);
}

.ai-msg-user .ai-msg-content pre {
  background: rgba(255,255,255,0.1);
}

/* Streaming typing cursor indicator */
.ai-msg-streaming {
  contain: content;
}

.ai-msg-streaming::after {
  content: '\25CA';
  display: inline-block;
  animation: ai-cursor-blink 0.7s step-end infinite;
  color: var(--primary-color, #3b82f6);
  font-weight: bold;
  margin-left: 2px;
  font-size: 0.9em;
}

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

/* Loading indicator (AI thinking) */
.ai-loading-dots {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 4px;
}

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

.ai-loading-dots span:nth-child(1) {
  animation-delay: 0s;
}

.ai-loading-dots span:nth-child(2) {
  animation-delay: 0.16s;
}

.ai-loading-dots span:nth-child(3) {
  animation-delay: 0.32s;
}

@keyframes ai-loading-bounce {
  0%, 80%, 100% {
    transform: scale(0.6);
    opacity: 0.4;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

/* Delete button */
.ai-msg-delete {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 18px;
  height: 18px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-muted);
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.ai-msg-bubble:hover .ai-msg-delete {
  display: flex;
}

.ai-msg-delete:hover {
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
}

/* Input Area */
.ai-panel-input {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.ai-panel-input textarea {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: var(--font-sans);
  line-height: 1.5;
  resize: none;
  outline: none;
  background: var(--bg-secondary);
  color: var(--text);
  max-height: 120px;
  transition: border-color 0.2s;
}

.ai-panel-input textarea:focus {
  border-color: var(--primary);
}

.ai-panel-input button {
  padding: 8px 16px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: var(--transition);
  flex-shrink: 0;
}

.ai-panel-input button:hover {
  background: var(--primary-dark);
}

.ai-panel-input button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* API Key Dialog */
.ai-key-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 20px;
}

.ai-key-dialog {
  background: var(--bg);
  border-radius: var(--radius-lg);
  padding: 28px;
  max-width: 400px;
  width: 100%;
  box-shadow: var(--shadow-lg);
}

.ai-key-dialog h3 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 10px;
}

.ai-key-dialog p {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 16px;
}

.ai-key-dialog p a {
  color: var(--primary);
  text-decoration: none;
}

.ai-key-dialog p a:hover {
  text-decoration: underline;
}

.ai-key-dialog input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  background: var(--bg-secondary);
  color: var(--text);
  outline: none;
  margin-bottom: 16px;
  transition: border-color 0.2s;
}

.ai-key-dialog input:focus {
  border-color: var(--primary);
}

.ai-key-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.ai-key-cancel {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 13px;
  transition: var(--transition);
}

.ai-key-cancel:hover {
  background: var(--bg-secondary);
}

.ai-key-save {
  padding: 8px 20px;
  border: none;
  border-radius: var(--radius);
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: var(--transition);
}

.ai-key-save:hover {
  background: var(--primary-dark);
}

/* ============================================================
   AI History Panel
   ============================================================ */
.ai-history-panel {
  position: absolute;
  top: 49px;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg);
  z-index: 10;
  overflow-y: auto;
  padding: 12px;
  display: none;
  border-top: 1px solid var(--border);
}

.ai-history-panel.open {
  display: block;
}

.ai-history-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 20px;
  font-size: 0.9rem;
}

.ai-history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 6px;
  cursor: pointer;
  transition: var(--transition);
  border: 1px solid var(--border);
}

.ai-history-item:hover {
  background: var(--bg-secondary);
  border-color: var(--primary);
}

.ai-history-item.active {
  background: var(--bg-tertiary);
  border-color: var(--primary);
}

.ai-history-info {
  flex: 1;
  min-width: 0;
  margin-right: 8px;
}

.ai-history-title {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ai-history-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.ai-history-delete {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1;
  flex-shrink: 0;
  transition: var(--transition);
}

.ai-history-delete:hover {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
}

/* ============================================================
   AI Panel Responsive
   ============================================================ */
@media (max-width: 768px) {
  .ai-panel {
    width: 100vw;
    top: var(--header-height);
  }

  .ai-toggle-btn {
    bottom: 70px;
    right: 16px;
    width: 46px;
    height: 46px;
  }
}

@media (max-width: 480px) {
  .ai-panel-options {
    padding: 8px 12px;
  }

  .ai-panel-messages {
    padding: 12px;
  }

  .ai-panel-input {
    padding: 10px 12px;
  }

  .ai-msg-bubble {
    max-width: 92%;
  }
}

/* ============================================================
   AI Summary Box (collapsible)
   ============================================================ */
.ai-summary-box {
  margin: 16px 0 24px 0;
  border: 1px solid var(--border-color, #e2e8f0);
  border-radius: 10px;
  background: linear-gradient(135deg, #f0f9ff 0%, #f8fafc 100%);
  overflow: hidden;
  transition: box-shadow 0.3s ease;
}

[data-theme="dark"] .ai-summary-box {
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  border-color: #334155;
}

.ai-summary-box:hover {
  box-shadow: 0 2px 12px rgba(59, 130, 246, 0.1);
}

.ai-summary-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  cursor: pointer;
  user-select: none;
  transition: background 0.2s;
}

.ai-summary-toggle:hover {
  background: rgba(59, 130, 246, 0.05);
}

[data-theme="dark"] .ai-summary-toggle:hover {
  background: rgba(59, 130, 246, 0.1);
}

.ai-summary-icon {
  font-size: 1.3em;
  flex-shrink: 0;
}

.ai-summary-title {
  font-weight: 600;
  font-size: 0.95rem;
  color: #1e40af;
  flex-shrink: 0;
}

[data-theme="dark"] .ai-summary-title {
  color: #60a5fa;
}

.ai-summary-hint {
  font-size: 0.82rem;
  color: #64748b;
  margin-left: 4px;
}

[data-theme="dark"] .ai-summary-hint {
  color: #94a3b8;
}

.ai-summary-arrow {
  margin-left: auto;
  font-size: 0.75rem;
  color: #94a3b8;
  transition: transform 0.3s ease;
  flex-shrink: 0;
}

.ai-summary-box.expanded .ai-summary-arrow {
  transform: rotate(90deg);
}

.ai-summary-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.4s ease, padding 0.3s ease;
  padding: 0 16px;
}

.ai-summary-box.expanded .ai-summary-content {
  max-height: 2000px;
  padding: 0 16px 16px 16px;
  border-top: 1px solid var(--border-color, #e2e8f0);
}

[data-theme="dark"] .ai-summary-box.expanded .ai-summary-content {
  border-top-color: #334155;
}

.ai-summary-content ul {
  margin: 8px 0;
  padding-left: 20px;
}

.ai-summary-content li {
  margin-bottom: 6px;
  line-height: 1.6;
  font-size: 0.9rem;
  color: #334155;
}

[data-theme="dark"] .ai-summary-content li {
  color: #cbd5e1;
}

.ai-summary-content p {
  margin: 8px 0;
  font-size: 0.9rem;
  line-height: 1.6;
  color: #334155;
}

[data-theme="dark"] .ai-summary-content p {
  color: #cbd5e1;
}

.ai-summary-content code {
  background: rgba(59, 130, 246, 0.1);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 0.85em;
}

[data-theme="dark"] .ai-summary-content code {
  background: rgba(96, 165, 250, 0.15);
}

@media (max-width: 768px) {
  .ai-summary-hint {
    display: none;
  }

  .ai-summary-toggle {
    padding: 10px 12px;
  }

  .ai-summary-content {
    padding: 0 12px;
  }

  .ai-summary-box.expanded .ai-summary-content {
    padding: 0 12px 12px 12px;
  }
}
