/* ===== 全局变量 ===== */
:root {
  --bg: #f0f2f5;
  --bg-card: #ffffff;
  --bg-sidebar: #1e2a3a;
  --bg-sidebar-hover: #2d3e52;
  --text-primary: #1a1a2e;
  --text-secondary: #6b7280;
  --text-light: #9ca3af;
  --text-on-dark: #e2e8f0;
  --text-on-dark-muted: #94a3b8;
  --border: #e5e7eb;
  --border-dark: #374151;
  --accent: #3b82f6;
  --accent-dark: #2563eb;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --stock-up: #dc2626;
  --stock-down: #16a34a;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
  --radius: 10px;
  --radius-sm: 6px;
  --sidebar-w: 240px;
}

/* ===== Reset ===== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 14px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
a { text-decoration: none; color: inherit; }
input, select, button { font-family: inherit; font-size: inherit; }

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

/* ===== 侧边栏 ===== */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-sidebar);
  color: var(--text-on-dark);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}
.sidebar-header {
  padding: 24px 20px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.logo { display: flex; align-items: center; gap: 10px; }
.logo-icon { font-size: 28px; }
.logo-text { font-size: 17px; font-weight: 700; color: #fff; }
.logo-subtitle {
  font-size: 11px; color: var(--text-on-dark-muted);
  margin-top: 6px; line-height: 1.4;
}
.nav { flex: 1; padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 16px; border-radius: var(--radius-sm);
  color: var(--text-on-dark-muted); font-size: 14px;
  transition: all 0.15s; cursor: pointer;
}
.nav-item:hover { background: var(--bg-sidebar-hover); color: #fff; }
.nav-item.active { background: var(--accent); color: #fff; font-weight: 600; }
.nav-icon { font-size: 18px; width: 22px; text-align: center; }
.sidebar-footer { padding: 16px 20px; border-top: 1px solid rgba(255,255,255,0.08); }
.data-update-info { font-size: 12px; color: var(--text-on-dark-muted); }
.update-label { color: #cbd5e1; margin-bottom: 2px; }
.update-value { color: var(--success); font-weight: 600; margin-bottom: 8px; }
.update-date { margin-top: 4px; }

/* ===== 主内容 ===== */
.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.topbar {
  height: 60px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
  position: sticky; top: 0; z-index: 50;
}
.topbar h1 { font-size: 18px; font-weight: 700; }
.calc-date { display: flex; align-items: center; gap: 8px; }
.calc-date label { font-size: 13px; color: var(--text-secondary); }
.calc-date input {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 5px 10px; font-size: 13px;
}

.content { padding: 24px; flex: 1; }

/* ===== 页面切换 ===== */
.page { display: none; }
.page.active { display: block; }

/* ===== 卡片 ===== */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  overflow: hidden;
}
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.card-header h3 { font-size: 15px; font-weight: 700; }
.card-body { padding: 20px; }
.card-actions { display: flex; align-items: center; gap: 10px; }
.card-badge {
  background: var(--danger); color: #fff;
  font-size: 12px; padding: 2px 10px; border-radius: 20px; font-weight: 600;
}

/* ===== 统计卡片 ===== */
.stats-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.stat-card {
  background: var(--bg-card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 20px;
  display: flex; align-items: center; gap: 16px;
}
.stat-icon {
  width: 48px; height: 48px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; flex-shrink: 0;
}
.stat-blue { background: #dbeafe; }
.stat-green { background: #dcfce7; }
.stat-red { background: #fee2e2; }
.stat-amber { background: #fef3c7; }
.stat-label { font-size: 12px; color: var(--text-secondary); margin-bottom: 4px; }
.stat-value { font-size: 22px; font-weight: 700; }
.stat-input {
  width: 70px; font-size: 22px; font-weight: 700;
  border: none; border-bottom: 2px solid var(--accent);
  background: transparent; text-align: center; outline: none;
}

/* ===== 仪表盘布局 ===== */
.dashboard-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px; }

/* ===== 仓位变动提示 ===== */
.alert-list { display: flex; flex-direction: column; gap: 8px; max-height: 320px; overflow-y: auto; }
.alert-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); transition: all 0.15s;
}
.alert-item:hover { box-shadow: var(--shadow-sm); }
.alert-item.alert-buy { border-left: 4px solid var(--stock-down); background: #f0fdf4; }
.alert-item.alert-sell { border-left: 4px solid var(--stock-up); background: #fef2f2; }
.alert-item.alert-hold { border-left: 4px solid var(--text-light); background: #f9fafb; }
.alert-icon { font-size: 20px; }
.alert-name { font-weight: 600; font-size: 14px; min-width: 80px; }
.alert-detail { font-size: 12px; color: var(--text-secondary); flex: 1; }
.alert-pct { font-size: 15px; font-weight: 700; min-width: 70px; text-align: right; }
.alert-pct.up { color: var(--stock-up); }
.alert-pct.down { color: var(--stock-down); }
.alert-empty { text-align: center; padding: 40px 20px; color: var(--text-light); }

/* ===== 表格 ===== */
.table-wrap { overflow-x: auto; }
.data-table {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
.data-table th {
  background: #f8fafc; padding: 10px 12px; text-align: left;
  font-weight: 600; color: var(--text-secondary);
  border-bottom: 2px solid var(--border); white-space: nowrap;
  position: sticky; top: 0;
}
.data-table td {
  padding: 10px 12px; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table tbody tr:hover { background: #f8fafc; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.tag {
  display: inline-block; padding: 2px 8px; border-radius: 4px;
  font-size: 11px; font-weight: 600;
}
.tag-pass { background: #dcfce7; color: #15803d; }
.tag-fail { background: #fee2e2; color: #b91c1c; }
.tag-buy { background: #dcfce7; color: #15803d; }
.tag-sell { background: #fee2e2; color: #b91c1c; }
.tag-hold { background: #f3f4f6; color: #6b7280; }
.tag-shift { background: #fef3c7; color: #92400e; }
.tag-cyclical { background: #e0e7ff; color: #4338ca; }
.tag-growth { background: #fce7f3; color: #9f1239; }

/* ===== 策略说明页 ===== */
.strategy-section { margin-bottom: 36px; }
.section-title {
  font-size: 17px; font-weight: 700; margin-bottom: 10px;
  padding-left: 12px; border-left: 4px solid var(--accent);
}
.section-desc { font-size: 14px; color: var(--text-secondary); margin-bottom: 16px; line-height: 1.8; }
.buffett-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.buffett-item {
  background: var(--bg-card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px;
  border-top: 3px solid var(--accent);
}
.buffett-item .buffett-name { font-size: 14px; font-weight: 600; margin-bottom: 8px; }
.buffett-item .buffett-threshold {
  font-size: 20px; font-weight: 700; color: var(--accent-dark); margin-bottom: 4px;
}
.buffett-item .buffett-desc { font-size: 12px; color: var(--text-secondary); }
.formula-box {
  background: #1e293b; color: #e2e8f0;
  border-radius: var(--radius); padding: 24px; margin: 16px 0;
  font-family: 'Fira Code', 'Consolas', monospace;
}
.formula-line { display: flex; align-items: center; gap: 12px; padding: 8px 0; font-size: 16px; }
.formula-label { min-width: 80px; color: #94a3b8; }
.formula-eq { color: #f59e0b; font-weight: 700; }
.formula-expr { color: #60a5fa; }
.strategy-note {
  background: #eff6ff; border-left: 4px solid var(--accent);
  padding: 12px 16px; border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin-top: 12px; font-size: 14px; line-height: 1.8; color: var(--text-primary);
}
.strategy-table { width: 100%; border-collapse: collapse; margin-top: 12px; }
.strategy-table th, .strategy-table td {
  padding: 12px 16px; border: 1px solid var(--border); text-align: left;
}
.strategy-table th { background: #f8fafc; font-weight: 600; }
.strategy-table .coeff { font-weight: 700; color: var(--accent-dark); font-size: 16px; }
.paradigm-examples { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin: 16px 0; }
.paradigm-card {
  background: var(--bg-card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px;
  border: 1px solid var(--border);
}
.paradigm-name { font-size: 16px; font-weight: 700; margin-bottom: 10px; }
.paradigm-flow { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.paradigm-tag {
  background: #f3f4f6; padding: 4px 10px; border-radius: 4px;
  font-size: 12px; color: var(--text-secondary);
}
.paradigm-tag.paradigm-highlight {
  background: #fef3c7; color: #92400e; font-weight: 600;
}
.paradigm-arrow { color: var(--text-light); }
.paradigm-note { font-size: 12px; color: var(--text-secondary); font-family: monospace; }

/* ===== 单标的计算 ===== */
.single-layout { display: grid; grid-template-columns: 360px 1fr; gap: 20px; align-items: start; }
.form-group { margin-bottom: 18px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text-secondary); }
.form-control {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-size: 14px; outline: none; transition: border-color 0.15s;
}
.form-control:focus { border-color: var(--accent); }
.form-slider { width: 100%; -webkit-appearance: none; height: 6px; border-radius: 3px; background: #e5e7eb; outline: none; }
.form-slider::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%; background: var(--accent); cursor: pointer; }
.slider-row { display: flex; align-items: center; gap: 12px; }
.slider-label { min-width: 50px; text-align: right; font-weight: 600; font-size: 15px; }

/* ===== 按钮 ===== */
.btn {
  padding: 9px 20px; border: none; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 600; cursor: pointer; transition: all 0.15s;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #059669; }
.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-block { width: 100%; justify-content: center; }
.input-sm { width: 70px; padding: 5px 8px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 13px; }
.muted-text { font-size: 13px; color: var(--text-secondary); }
.checkbox-label { display: flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }

/* ===== 单标的计算结果 ===== */
.result-stock-header { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.result-stock-name { font-size: 20px; font-weight: 700; }
.result-stock-code { font-size: 14px; color: var(--text-secondary); }
.result-stock-sector { background: #eff6ff; color: var(--accent-dark); padding: 3px 10px; border-radius: 4px; font-size: 12px; }

.result-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 20px; }
.result-item {
  background: #f8fafc; border-radius: var(--radius-sm); padding: 14px 16px;
}
.result-item-label { font-size: 12px; color: var(--text-secondary); margin-bottom: 4px; }
.result-item-value { font-size: 18px; font-weight: 700; }
.result-item-value.highlight { color: var(--accent-dark); }

.position-gauge {
  text-align: center; padding: 20px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: var(--radius); color: #fff; margin-bottom: 20px;
}
.position-gauge-label { font-size: 14px; opacity: 0.8; margin-bottom: 8px; }
.position-gauge-value { font-size: 48px; font-weight: 800; }
.position-gauge-change { font-size: 16px; margin-top: 8px; }

.buffett-checks { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.buffett-check {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; border-radius: var(--radius-sm); font-size: 13px;
}
.buffett-check.pass { background: #f0fdf4; color: #15803d; }
.buffett-check.fail { background: #fef2f2; color: #b91c1c; }
.check-icon { font-size: 16px; }

.calc-flow {
  background: #f8fafc; border-radius: var(--radius); padding: 16px; margin-bottom: 16px;
}
.calc-flow-step {
  display: flex; align-items: center; gap: 12px; padding: 6px 0;
  font-size: 13px; border-bottom: 1px dashed var(--border);
}
.calc-flow-step:last-child { border-bottom: none; }
.calc-flow-label { min-width: 100px; color: var(--text-secondary); }
.calc-flow-value { font-weight: 600; font-family: monospace; }

/* ===== 批量测算 ===== */
.batch-summary {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 20px;
}
.summary-item {
  background: #f8fafc; border-radius: var(--radius-sm); padding: 12px 16px; text-align: center;
}
.summary-label { font-size: 12px; color: var(--text-secondary); margin-bottom: 4px; }
.summary-value { font-size: 20px; font-weight: 700; }
.summary-value.buy { color: var(--stock-down); }
.summary-value.sell { color: var(--stock-up); }

/* ===== 股票池 ===== */
.pool-summary {
  display: flex; gap: 24px; margin-bottom: 16px; padding: 12px 16px;
  background: #f8fafc; border-radius: var(--radius-sm); font-size: 14px;
}
.pool-summary strong { color: var(--accent-dark); }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%) translateY(100px);
  background: #1e293b; color: #fff; padding: 12px 28px; border-radius: var(--radius-sm);
  font-size: 14px; z-index: 9999; transition: transform 0.3s; box-shadow: var(--shadow-lg);
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* ===== 滚动条 ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ===== 响应式 ===== */
@media (max-width: 1200px) {
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .buffett-grid { grid-template-columns: repeat(2, 1fr); }
  .batch-summary { grid-template-columns: repeat(3, 1fr); }
  .paradigm-examples { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .sidebar { width: 60px; }
  .logo-text, .logo-subtitle, .nav-item span:not(.nav-icon), .sidebar-footer { display: none; }
  .main { margin-left: 60px; }
  .single-layout { grid-template-columns: 1fr; }
  .result-grid { grid-template-columns: 1fr; }
  .stats-row { grid-template-columns: 1fr; }
}
