/* ============================================
   AI电子工程师新手助手 — 全局样式
   ============================================ */

/* --- CSS 变量 --- */
:root {
  --primary: #2563eb;
  --primary-dark: #1e40af;
  --primary-light: #dbeafe;
  --accent: #f59e0b;
  --accent-dark: #d97706;
  --bg: #f1f5f9;
  --bg-card: #ffffff;
  --text: #1e293b;
  --text-secondary: #64748b;
  --border: #e2e8f0;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --max-width: 960px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Microsoft YaHei", "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* --- 导航栏 --- */
.navbar {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 0 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.navbar-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
}

.navbar-brand {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.navbar-brand .icon {
  font-size: 1.4rem;
}

.navbar-links {
  display: flex;
  gap: 1.5rem;
  list-style: none;
}

.navbar-links a {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: color 0.15s;
}

.navbar-links a:hover,
.navbar-links a.active {
  color: var(--primary);
}

/* --- 主容器 --- */
.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 2rem 1rem;
}

/* --- Hero 区域 --- */
.hero {
  text-align: center;
  padding: 3rem 1rem 2rem;
}

.hero h1 {
  font-size: 2rem;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 0.75rem;
}

.hero p {
  font-size: 1.1rem;
  color: var(--text-secondary);
  max-width: 480px;
  margin: 0 auto 1.5rem;
}

.hero-buttons {
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
}

/* --- 按钮 --- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.6rem 1.4rem;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
}

.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 2px solid var(--primary);
}

.btn-outline:hover {
  background: var(--primary-light);
}

.btn-accent {
  background: var(--accent);
  color: #fff;
}

.btn-accent:hover {
  background: var(--accent-dark);
}

.btn-sm {
  padding: 0.35rem 0.9rem;
  font-size: 0.85rem;
}

/* --- 卡片 --- */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  border: 1px solid var(--border);
  transition: box-shadow 0.2s, transform 0.2s;
}

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

.card-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.card-desc {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

/* --- 工具网格 --- */
.tools-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  margin: 2rem 0;
}

.tool-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  border: 1px solid var(--border);
  text-decoration: none;
  color: var(--text);
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.5rem;
}

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

.tool-card .tool-icon {
  font-size: 2.5rem;
  margin-bottom: 0.25rem;
}

.tool-card .tool-name {
  font-weight: 700;
  font-size: 0.95rem;
}

.tool-card .tool-desc {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* --- 产品卡片 --- */
.products-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
}

.product-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  padding: 1.5rem;
  text-align: center;
}

.product-card .product-cover {
  width: 100%;
  height: 140px;
  background: linear-gradient(135deg, #1e293b, #334155);
  border-radius: 8px;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 2.5rem;
}

.product-card .product-name {
  font-weight: 700;
  font-size: 1rem;
  margin-bottom: 0.25rem;
}

.product-card .product-price {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--danger);
  margin-bottom: 1rem;
}

/* --- 节标题 --- */
.section-title {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* --- 计算器页面通用 --- */
.calc-page {
  max-width: 640px;
  margin: 0 auto;
  padding: 2rem 1rem;
}

.calc-page h1 {
  font-size: 1.5rem;
  font-weight: 800;
  text-align: center;
  margin-bottom: 0.5rem;
}

.calc-page .subtitle {
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.95rem;
  margin-bottom: 2rem;
}

.calc-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.calc-card h3 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 1rem;
}

/* --- 表单 --- */
.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
  color: var(--text);
}

.form-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.form-row input {
  flex: 1;
}

.form-row select {
  width: 80px;
}

input[type="number"],
input[type="text"],
select {
  padding: 0.55rem 0.75rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--text);
  background: var(--bg-card);
  transition: border-color 0.15s;
  width: 100%;
}

input[type="number"]:focus,
input[type="text"]:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

/* --- 结果区 --- */
.result-box {
  background: #f0fdf4;
  border: 2px solid var(--success);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-top: 1rem;
}

.result-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0;
  border-bottom: 1px solid rgba(0,0,0,0.05);
}

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

.result-label {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.result-value {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
}

.result-value.big {
  font-size: 1.5rem;
  color: var(--primary);
}

/* --- 提示 --- */
.tip {
  background: #fffbeb;
  border-left: 4px solid var(--warning);
  padding: 0.75rem 1rem;
  border-radius: 0 8px 8px 0;
  margin-top: 1rem;
  font-size: 0.9rem;
  color: #92400e;
}

.tip a {
  color: var(--primary);
  font-weight: 600;
}

.warning {
  background: #fef2f2;
  border-left: 4px solid var(--danger);
  padding: 0.75rem 1rem;
  border-radius: 0 8px 8px 0;
  margin-top: 0.5rem;
  font-size: 0.85rem;
  color: #991b1b;
}

/* --- 折叠区 --- */
.collapsible {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.collapsible-header {
  background: #f8fafc;
  padding: 0.75rem 1rem;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  user-select: none;
}

.collapsible-header:hover {
  background: #f1f5f9;
}

.collapsible-body {
  padding: 1rem;
  font-size: 0.9rem;
  line-height: 1.8;
  background: #fff;
}

.collapsible-body.hidden {
  display: none;
}

/* --- AI 聊天区 --- */
.chat-container {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 480px;
  margin: 1.5rem 0;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.chat-msg {
  max-width: 85%;
  padding: 0.65rem 0.9rem;
  border-radius: 12px;
  font-size: 0.92rem;
  line-height: 1.55;
  word-break: break-word;
}

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

.chat-msg.ai {
  align-self: flex-start;
  background: #f1f5f9;
  color: var(--text);
  border-bottom-left-radius: 4px;
}

.chat-input-row {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem;
  border-top: 1px solid var(--border);
}

.chat-input-row input {
  flex: 1;
}

.chat-input-row button {
  flex-shrink: 0;
}

.chat-loading {
  align-self: flex-start;
  padding: 0.5rem 0.9rem;
  color: var(--text-secondary);
  font-size: 0.85rem;
}

/* --- 建议问题 --- */
.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 1rem 0;
}

.suggestion-chip {
  background: var(--primary-light);
  color: var(--primary-dark);
  padding: 0.4rem 0.8rem;
  border-radius: 20px;
  font-size: 0.85rem;
  cursor: pointer;
  border: none;
  transition: background 0.15s;
}

.suggestion-chip:hover {
  background: #bfdbfe;
}

/* --- 色环选择器 --- */
.color-selector {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.color-band {
  text-align: center;
}

.color-band label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
  color: var(--text-secondary);
}

.color-band select {
  width: 100px;
}

.band-preview {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  justify-content: center;
  margin: 1.5rem 0;
  flex-wrap: wrap;
}

.band-color {
  width: 32px;
  height: 32px;
  border-radius: 4px;
  border: 2px solid #333;
  display: inline-block;
}

.result-display {
  text-align: center;
  padding: 1.5rem;
  background: #f8fafc;
  border-radius: var(--radius);
  margin: 1rem 0;
}

.result-display .value {
  font-size: 2rem;
  font-weight: 800;
  color: var(--primary-dark);
}

.result-display .tolerance {
  font-size: 1rem;
  color: var(--text-secondary);
}

/* --- 电路示意图 --- */
.circuit-diagram {
  text-align: center;
  margin: 1rem 0 2rem;
  padding: 1.5rem;
  background: #f8fafc;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.circuit-diagram svg {
  max-width: 100%;
  height: auto;
}

/* --- 页脚 --- */
.footer {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-secondary);
  font-size: 0.85rem;
  border-top: 1px solid var(--border);
  margin-top: 3rem;
}

/* --- 响应式 --- */
@media (max-width: 640px) {
  .hero h1 {
    font-size: 1.5rem;
  }

  .tools-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .products-grid {
    grid-template-columns: 1fr;
  }

  .navbar-links {
    gap: 0.8rem;
    font-size: 0.8rem;
  }

  .navbar-brand {
    font-size: 0.95rem;
  }

  .calc-page {
    padding: 1rem 0.75rem;
  }

  .form-row {
    flex-direction: column;
  }

  .form-row select {
    width: 100%;
  }

  .color-selector {
    justify-content: center;
  }
}
