/* ========================================
   电子元器件知识网站 - CSS样式文件
   ======================================== */

/* CSS变量定义 */
:root {
  /* 主色调 - 科技蓝 */
  --primary-color: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #dbeafe;
  
  /* 辅助色 */
  --accent-color: #06b6d4;
  --success-color: #10b981;
  --warning-color: #f59e0b;
  --danger-color: #ef4444;
  
  /* 文字颜色 - 浅色主题 */
  --text-primary: #1f2937;
  --text-secondary: #4b5563;
  --text-muted: #9ca3af;
  
  /* 背景颜色 - 浅色主题 */
  --bg-primary: #ffffff;
  --bg-secondary: #f3f4f6;
  --bg-tertiary: #e5e7eb;
  --bg-card: #ffffff;
  
  /* 边框颜色 */
  --border-color: #e5e7eb;
  --border-light: #f3f4f6;
  
  /* 阴影 */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  
  /* 布局 */
  --sidebar-width: 280px;
  --header-height: 60px;
  --content-max-width: 1200px;
  
  /* 圆角 */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  
  /* 过渡 */
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
  --transition-slow: 0.35s ease;
  
  /* 代码高亮 */
  --code-bg: #1e293b;
  --code-text: #e2e8f0;
}

/* 深色主题 */
[data-theme="dark"] {
  --text-primary: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted: #64748b;
  
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --bg-card: #1e293b;
  
  --border-color: #334155;
  --border-light: #1e293b;
  
  --code-bg: #0f172a;
  --code-text: #e2e8f0;
}

/* ========================================
   基础样式重置
   ======================================== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  font-size: 16px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  line-height: 1.6;
  color: var(--text-primary);
  background-color: var(--bg-secondary);
  min-height: 100vh;
}

a {
  color: var(--primary-color);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--primary-hover);
}

ul, ol {
  list-style: none;
}

img {
  max-width: 100%;
  height: auto;
}

button {
  font-family: inherit;
  cursor: pointer;
}

/* ========================================
   布局结构
   ======================================== */
.app-container {
  display: flex;
  min-height: 100vh;
}

/* 侧边栏 */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-primary);
  border-right: 1px solid var(--border-color);
  overflow-y: auto;
  z-index: 100;
  transition: transform var(--transition-normal);
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--border-color);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-logo svg {
  width: 32px;
  height: 32px;
  color: var(--primary-color);
}

.sidebar-logo h1 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
}

/* 搜索框 */
.search-box {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
}

.search-input {
  width: 100%;
  padding: 10px 16px;
  padding-left: 40px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 0.875rem;
  transition: all var(--transition-fast);
}

.search-input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.search-wrapper {
  position: relative;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--text-muted);
}

/* 导航菜单 */
.sidebar-nav {
  padding: 16px 0;
}

.nav-section {
  margin-bottom: 8px;
}

.nav-section-title {
  padding: 8px 20px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.nav-item {
  display: flex;
  align-items: center;
  padding: 10px 20px;
  color: var(--text-secondary);
  font-size: 0.875rem;
  transition: all var(--transition-fast);
}

.nav-item:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.nav-item.active {
  background: var(--primary-light);
  color: var(--primary-color);
  border-right: 3px solid var(--primary-color);
}

.nav-item svg {
  width: 18px;
  height: 18px;
  margin-right: 12px;
  flex-shrink: 0;
}

/* 主题切换按钮 */
.theme-toggle {
  position: absolute;
  bottom: 20px;
  left: 20px;
  right: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 0.875rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

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

.theme-toggle svg {
  width: 18px;
  height: 18px;
}

/* 主内容区 */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
}

/* 顶部栏 */
.topbar {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  padding: 0 24px;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-color);
  z-index: 50;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.breadcrumb a {
  color: var(--text-muted);
}

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

.breadcrumb-separator {
  color: var(--text-muted);
}

.breadcrumb-current {
  color: var(--text-primary);
}

/* 内容区域 */
.content-wrapper {
  max-width: var(--content-max-width);
  margin: 0 auto;
  padding: 32px 24px;
}

.page-title {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.page-subtitle {
  font-size: 1.125rem;
  color: var(--text-secondary);
  margin-bottom: 32px;
}

/* 章节标题 */
.section {
  margin-bottom: 48px;
}

.section-title {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--primary-color);
}

.section-subtitle {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 12px;
  margin-top: 24px;
}

/* 卡片网格 */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  transition: all var(--transition-normal);
}

.card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.card-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.card-description {
  font-size: 0.875rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.card-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 12px;
  font-size: 0.875rem;
  font-weight: 500;
}

/* 表格样式 */
.data-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 24px;
  font-size: 0.875rem;
}

.data-table th,
.data-table td {
  padding: 12px 16px;
  text-align: left;
  border: 1px solid var(--border-color);
}

.data-table th {
  background: var(--bg-secondary);
  font-weight: 600;
  color: var(--text-primary);
}

.data-table tr:nth-child(even) {
  background: var(--bg-secondary);
}

.data-table tr:hover {
  background: var(--primary-light);
}

/* 代码块样式 */
.code-block {
  background: var(--code-bg);
  border-radius: var(--radius-md);
  padding: 16px;
  margin: 16px 0;
  overflow-x: auto;
}

.code-block pre {
  margin: 0;
  font-family: "Fira Code", "Consolas", "Monaco", monospace;
  font-size: 0.875rem;
  color: var(--code-text);
  line-height: 1.5;
}

.code-block code {
  font-family: inherit;
}

/* 内联代码 */
code {
  background: var(--bg-tertiary);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-family: "Fira Code", "Consolas", "Monaco", monospace;
  font-size: 0.875em;
  color: var(--primary-color);
}

/* 列表样式 */
.content-list {
  padding-left: 20px;
}

.content-list li {
  position: relative;
  padding-left: 16px;
  margin-bottom: 8px;
  color: var(--text-secondary);
  line-height: 1.6;
}

.content-list li::before {
  content: "•";
  position: absolute;
  left: 0;
  color: var(--primary-color);
  font-weight: bold;
}

.numbered-list {
  padding-left: 24px;
}

.numbered-list li {
  position: relative;
  padding-left: 8px;
  margin-bottom: 12px;
  color: var(--text-secondary);
  line-height: 1.6;
  list-style-type: decimal;
}

.numbered-list li::marker {
  color: var(--primary-color);
  font-weight: 600;
}

/* 提示框样式 */
.alert {
  padding: 16px 20px;
  border-radius: var(--radius-md);
  margin: 16px 0;
  border-left: 4px solid;
}

.alert-info {
  background: var(--primary-light);
  border-color: var(--primary-color);
  color: var(--text-primary);
}

.alert-warning {
  background: #fef3c7;
  border-color: var(--warning-color);
  color: #92400e;
}

.alert-success {
  background: #d1fae5;
  border-color: var(--success-color);
  color: #065f46;
}

.alert-danger {
  background: #fee2e2;
  border-color: var(--danger-color);
  color: #991b1b;
}

[data-theme="dark"] .alert-warning {
  background: #451a03;
  color: #fef3c7;
}

[data-theme="dark"] .alert-success {
  background: #064e3b;
  color: #d1fae5;
}

[data-theme="dark"] .alert-danger {
  background: #7f1d1d;
  color: #fee2e2;
}

/* 标签/徽章 */
.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 500;
}

.badge-primary {
  background: var(--primary-light);
  color: var(--primary-color);
}

.badge-success {
  background: #d1fae5;
  color: #059669;
}

.badge-warning {
  background: #fef3c7;
  color: #d97706;
}

.badge-danger {
  background: #fee2e2;
  color: #dc2626;
}

/* 返回顶部按钮 */
.back-to-top {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary-color);
  color: white;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-normal);
  z-index: 99;
  box-shadow: var(--shadow-lg);
}

.back-to-top.visible {
  opacity: 1;
  visibility: visible;
}

.back-to-top:hover {
  background: var(--primary-hover);
  transform: translateY(-2px);
}

.back-to-top svg {
  width: 24px;
  height: 24px;
}

/* 搜索结果 */
.search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  max-height: 400px;
  overflow-y: auto;
  z-index: 200;
  display: none;
}

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

.search-result-item {
  display: block;
  padding: 12px 16px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-light);
  transition: background var(--transition-fast);
}

.search-result-item:last-child {
  border-bottom: none;
}

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

.search-result-title {
  font-weight: 500;
  color: var(--text-primary);
}

.search-result-path {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.search-no-results {
  padding: 20px;
  text-align: center;
  color: var(--text-muted);
}

/* 移动端菜单按钮 */
.menu-toggle {
  display: none;
  padding: 8px;
  background: none;
  border: none;
  color: var(--text-primary);
}

.menu-toggle svg {
  width: 24px;
  height: 24px;
}

/* 页脚 */
.footer {
  padding: 24px;
  text-align: center;
  border-top: 1px solid var(--border-color);
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* 响应式设计 */
@media (max-width: 1024px) {
  :root {
    --sidebar-width: 260px;
  }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  
  .sidebar.open {
    transform: translateX(0);
  }
  
  .main-content {
    margin-left: 0;
  }
  
  .menu-toggle {
    display: flex;
  }
  
  .card-grid {
    grid-template-columns: 1fr;
  }
  
  .data-table {
    font-size: 0.75rem;
  }
  
  .data-table th,
  .data-table td {
    padding: 8px 12px;
  }
  
  .page-title {
    font-size: 1.5rem;
  }
  
  .content-wrapper {
    padding: 20px 16px;
  }
  
  .theme-toggle {
    bottom: 16px;
    left: 16px;
    right: 16px;
  }
}

/* 遮罩层 */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 99;
}

@media (max-width: 768px) {
  .sidebar-overlay.active {
    display: block;
  }
}

/* 分类图标 */
.category-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  margin-bottom: 12px;
}

.category-icon.blue {
  background: var(--primary-light);
  color: var(--primary-color);
}

.category-icon.green {
  background: #d1fae5;
  color: #059669;
}

.category-icon.purple {
  background: #ede9fe;
  color: #7c3aed;
}

.category-icon.orange {
  background: #fef3c7;
  color: #d97706;
}

.category-icon svg {
  width: 24px;
  height: 24px;
}

/* 打印样式 */
@media print {
  .sidebar,
  .topbar,
  .back-to-top,
  .theme-toggle {
    display: none !important;
  }
  
  .main-content {
    margin-left: 0;
  }
  
  body {
    background: white;
    color: black;
  }
}
