/* ==================== 个人资管平台 · 暗色科技主题 ==================== */
:root {
  --bg-primary: #0a0e1a;
  --bg-secondary: #111827;
  --bg-card: #1a2138;
  --bg-card-hover: #232b47;
  --bg-glass: rgba(26, 33, 56, 0.85);
  --bg-input: #0f1526;

  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --primary: #6366f1;
  --primary-light: #818cf8;
  --primary-dark: #4f46e5;
  --primary-glow: rgba(99, 102, 241, 0.15);

  --gain: #f43f5e;
  --gain-bg: rgba(244, 63, 94, 0.12);
  --gain-glow: rgba(244, 63, 94, 0.25);
  --loss: #10b981;
  --loss-bg: rgba(16, 185, 129, 0.12);
  --loss-glow: rgba(16, 185, 129, 0.25);

  --warn: #f59e0b;
  --border: #1e293b;
  --border-light: #2a3654;

  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.45);
  --radius: 14px;
  --radius-sm: 9px;

  --font-num: 'JetBrains Mono', 'DM Mono', 'SF Mono', Consolas, monospace;
}

/* ==================== 浅色主题（v2.12，设置页可切换） ==================== */
[data-theme="light"] {
  --bg-primary: #eef2f7;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f1f5f9;
  --bg-glass: rgba(255, 255, 255, 0.88);
  --bg-input: #f6f8fb;

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #8a94a6;

  --primary: #6366f1;
  --primary-light: #4f46e5;
  --primary-dark: #4338ca;
  --primary-glow: rgba(99, 102, 241, 0.10);

  --gain: #e11d48;
  --gain-bg: rgba(225, 29, 72, 0.08);
  --gain-glow: rgba(225, 29, 72, 0.16);
  --loss: #059669;
  --loss-bg: rgba(5, 150, 105, 0.08);
  --loss-glow: rgba(5, 150, 105, 0.16);

  --warn: #d97706;
  --border: #e3e8ef;
  --border-light: #d4dce6;

  --shadow: 0 4px 24px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 8px 40px rgba(15, 23, 42, 0.12);
}

/* 主题切换过渡（仅背景与文字颜色，避免布局抖动） */
body, .sidebar, .chart-card, .stat-card, .topbar, input, select, textarea, .modal, .period-select {
  transition: background-color 0.25s ease, color 0.25s ease, border-color 0.25s ease;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

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

.sidebar {
  width: 220px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  z-index: 90;
  transition: width 0.2s ease, transform 0.25s ease;
}
.sidebar.collapsed { width: 64px; }
.sidebar.collapsed .nav-label, .sidebar.collapsed .logo-text { display: none; }

.sidebar-logo {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 16px;
  font-weight: 700; font-size: 1.05rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap; overflow: hidden;
}
/* logo 旁主题切换按钮（v2.13） */
.theme-toggle {
  margin-left: auto;
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); padding: 6px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  transition: color 0.2s, background 0.2s;
  flex-shrink: 0;
}
.theme-toggle:hover { color: var(--primary-light); background: var(--primary-glow); }
.sidebar.collapsed .theme-toggle { display: none; }
.sidebar-logo .logo-icon {
  width: 32px; height: 32px; border-radius: 8px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 0 16px var(--primary-glow);
  flex-shrink: 0;
}

.nav-menu { flex: 1; padding: 12px 8px; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px;
  margin-bottom: 2px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  border-left: 3px solid transparent;
  font-size: 0.92rem;
}
.nav-item:hover { background: var(--bg-card); color: var(--text-primary); }
.nav-item.active {
  background: var(--primary-glow);
  color: var(--primary-light);
  border-left-color: var(--primary);
}
.nav-item .nav-icon { font-size: 1.1rem; width: 22px; text-align: center; flex-shrink: 0; }

.nav-divider { height: 1px; background: var(--border); margin: 10px 12px; }
.sidebar-footer { padding: 10px 8px; border-top: 1px solid var(--border); }

.main-area {
  flex: 1;
  margin-left: 220px;
  transition: margin-left 0.2s ease;
  min-width: 0;
}
.sidebar.collapsed ~ .main-area { margin-left: 64px; }

.topbar {
  height: 58px;
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
  position: sticky; top: 0; z-index: 80;
}
.topbar-title { font-size: 1.05rem; font-weight: 600; }
.topbar-actions { display: flex; align-items: center; gap: 6px; }

.content { padding: 24px; max-width: 1280px; }

/* ==================== 按钮 ==================== */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  border: none; border-radius: var(--radius-sm);
  font-size: 0.88rem; font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  color: var(--text-primary);
  background: var(--bg-card);
  border: 1px solid var(--border-light);
}
.btn:hover { background: var(--bg-card-hover); }
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 0 14px var(--primary-glow); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--gain); border-color: var(--gain); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--bg-card); color: var(--text-primary); }
.btn-sm { padding: 5px 10px; font-size: 0.8rem; }
.btn-icon { padding: 8px; border-radius: 50%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

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

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  position: relative;
  overflow: hidden;
  transition: transform 0.15s, border-color 0.2s;
}
.stat-card:hover { transform: translateY(-2px); border-color: var(--border-light); }
.stat-card::before {
  content: '';
  position: absolute; inset: 0;
  background: radial-gradient(circle at top right, var(--primary-glow), transparent 60%);
  pointer-events: none;
}
.stat-card.gain-glow::before { background: radial-gradient(circle at top right, var(--gain-glow), transparent 60%); }
.stat-card.loss-glow::before { background: radial-gradient(circle at top right, var(--loss-glow), transparent 60%); }
.stat-label { font-size: 0.8rem; color: var(--text-secondary); margin-bottom: 8px; }
.stat-value { font-family: var(--font-num); font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; }
.stat-sub { font-size: 0.78rem; color: var(--text-muted); margin-top: 6px; font-family: var(--font-num); }

.gain { color: var(--gain); }
.loss { color: var(--loss); }

/* ==================== 涨跌胶囊 ==================== */
.pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-family: var(--font-num);
  font-size: 0.82rem;
  font-weight: 600;
}
.pill-gain { background: var(--gain-bg); color: var(--gain); }
.pill-loss { background: var(--loss-bg); color: var(--loss); }
.pill-flat { background: var(--bg-card-hover); color: var(--text-secondary); }

/* 市场页：紧凑指数条（v2.10 替代原整表展示） */
.idx-strip { display: flex; flex-wrap: wrap; gap: 8px; }
.idx-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 7px;
  padding: 7px 12px;
  border-radius: 10px;
  background: var(--bg-card-hover);
  border: 1px solid var(--border-light);
  font-size: 0.8rem;
  white-space: nowrap;
}
.idx-chip .idx-name { color: var(--text-secondary); font-weight: 600; }
.idx-chip .idx-price { color: var(--text-muted); font-family: var(--font-num); font-size: 0.74rem; }
.idx-chip .idx-chg { font-family: var(--font-num); font-weight: 700; }
.idx-chip-mine { background: var(--primary-glow); border-color: var(--primary); }
.idx-chip-mine .idx-name { color: var(--primary-light); }

/* 报告中心：涨跌幅超阈值的高亮行（v2.10） */
.tr-fluct { background: var(--gain-bg); }
.tr-fluct:hover { background: var(--gain-bg); }

/* ==================== 徽章 ==================== */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 5px;
  font-size: 0.75rem;
  font-weight: 500;
}
.badge-fund { background: rgba(245, 158, 11, 0.15); color: #fbbf24; }
.badge-astock { background: rgba(244, 63, 94, 0.15); color: #fb7185; }
.badge-hkstock { background: rgba(59, 130, 246, 0.15); color: #60a5fa; }

/* ==================== 表格 ==================== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th {
  text-align: left;
  padding: 10px 14px;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.78rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky; top: 0;
  background: var(--bg-card);
}
td { padding: 12px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
tbody tr { transition: background 0.12s; }
tbody tr:hover { background: var(--bg-card-hover); }
tbody tr:last-child td { border-bottom: none; }
.num { text-align: right; font-family: var(--font-num); }

/* ==================== 表单 ==================== */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 0.85rem; font-weight: 500; margin-bottom: 6px; color: var(--text-secondary); }
.form-group .req { color: var(--gain); }
.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-hint { font-size: 0.75rem; color: var(--text-muted); margin-top: 4px; }

/* 开关 */
.switch { position: relative; width: 42px; height: 24px; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0;
  background: var(--border-light);
  border-radius: 24px;
  cursor: pointer;
  transition: 0.2s;
}
.switch .slider::before {
  content: '';
  position: absolute;
  width: 18px; height: 18px;
  left: 3px; top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: 0.2s;
}
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::before { transform: translateX(18px); }

.setting-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.setting-row:last-child { border-bottom: none; }
.setting-info { flex: 1; padding-right: 20px; }
.setting-title { font-size: 0.9rem; font-weight: 500; }
.setting-desc { font-size: 0.78rem; color: var(--text-muted); margin-top: 2px; }
.setting-control { width: 260px; flex-shrink: 0; }

/* ==================== 弹窗 ==================== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(4, 6, 14, 0.7);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn 0.15s ease;
}
.modal {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 16px;
  width: 92%;
  max-width: 580px;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.2s ease;
}
.modal-sm { max-width: 420px; }
.modal-lg { max-width: 760px; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1.02rem; font-weight: 600; }
.modal-close {
  border: none; background: transparent;
  color: var(--text-muted); font-size: 1.1rem;
  cursor: pointer; padding: 4px 8px;
  border-radius: 6px;
  transition: all 0.2s;
}
.modal-close:hover { background: var(--bg-card-hover); transform: rotate(90deg); }
.modal-body { padding: 20px; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}
@keyframes fadeIn { from { opacity: 0; } }
@keyframes slideUp { from { transform: translateY(16px); opacity: 0; } }

/* ==================== 类型选择器 ==================== */
.type-selector { display: flex; gap: 8px; }
.type-option { flex: 1; position: relative; }
.type-option input { position: absolute; opacity: 0; }
.type-option span {
  display: flex; align-items: center; justify-content: center;
  padding: 11px;
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.88rem; font-weight: 500;
  color: var(--text-secondary);
  transition: all 0.15s;
}
.type-option input:checked + span {
  border-color: var(--primary);
  background: var(--primary-glow);
  color: var(--primary-light);
}

/* ==================== 周期选择器 ==================== */
.period-bar {
  display: flex; align-items: center; gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.period-group { display: flex; gap: 4px; background: var(--bg-card); border: 1px solid var(--border); padding: 4px; border-radius: var(--radius-sm); }
.period-btn {
  padding: 6px 14px;
  border: none; background: transparent;
  color: var(--text-secondary);
  font-size: 0.85rem; font-weight: 500;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
}
.period-btn:hover { color: var(--text-primary); }
.period-btn.active { background: var(--primary); color: #fff; }
.period-select {
  padding: 7px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.85rem;
}

/* ==================== Toast ==================== */
.toast {
  position: fixed;
  bottom: 28px; left: 50%;
  transform: translateX(-50%);
  background: var(--bg-card-hover);
  border: 1px solid var(--border-light);
  color: var(--text-primary);
  padding: 11px 22px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  z-index: 300;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.25s ease;
}
.toast.success { border-color: var(--loss); }
.toast.error { border-color: var(--gain); }
@keyframes toastIn { from { transform: translate(-50%, 16px); opacity: 0; } }

/* ==================== 登录页 ==================== */
.auth-page {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 30% 20%, rgba(99, 102, 241, 0.12), transparent 55%),
              radial-gradient(ellipse at 70% 80%, rgba(244, 63, 94, 0.06), transparent 55%),
              var(--bg-primary);
  padding: 20px;
}
.auth-card {
  width: 100%; max-width: 400px;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 18px;
  padding: 36px 32px;
  box-shadow: var(--shadow-lg);
}
.auth-logo { text-align: center; margin-bottom: 28px; }
.auth-logo .logo-icon {
  width: 52px; height: 52px;
  margin: 0 auto 12px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem;
  box-shadow: 0 0 28px var(--primary-glow);
}
.auth-logo h1 { font-size: 1.25rem; font-weight: 700; }
.auth-logo p { color: var(--text-muted); font-size: 0.85rem; margin-top: 4px; }
.auth-switch { text-align: center; margin-top: 18px; font-size: 0.85rem; color: var(--text-secondary); }
.auth-switch a { color: var(--primary-light); cursor: pointer; text-decoration: none; }

/* ==================== 空状态 / 加载 ==================== */
.empty-state { padding: 56px 20px; text-align: center; color: var(--text-muted); }
.empty-state .empty-icon { font-size: 2.6rem; margin-bottom: 12px; }
.loading { padding: 40px; text-align: center; color: var(--text-muted); }
.spinner {
  width: 26px; height: 26px;
  border: 3px solid var(--border-light);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
  vertical-align: middle;
  margin-right: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ==================== 建议卡片 ==================== */
.advice-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 16px 18px;
  margin-bottom: 12px;
}
.advice-card.unread { border-left-color: var(--warn); }
.advice-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 8px; }
.advice-title { font-weight: 600; font-size: 0.95rem; }
.advice-confidence { font-family: var(--font-num); font-size: 0.75rem; color: var(--text-muted); }
.advice-content { font-size: 0.87rem; color: var(--text-secondary); line-height: 1.6; }
.advice-foot { display: flex; justify-content: space-between; margin-top: 10px; font-size: 0.75rem; color: var(--text-muted); }

/* ==================== 分析组件 ==================== */
.chart-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 18px; }
.chart-title { font-size: 0.95rem; font-weight: 600; margin-bottom: 14px; display: flex; align-items: center; gap: 8px; }
.chart-wrap { position: relative; height: 260px; }
.chart-wrap-lg { position: relative; height: 320px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-2-1 { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; }

.markdown-body { font-size: 0.9rem; line-height: 1.8; color: var(--text-secondary); }
.markdown-body h1, .markdown-body h2, .markdown-body h3 { color: var(--text-primary); margin: 16px 0 8px; font-size: 1rem; }
.markdown-body table { font-size: 0.85rem; margin: 10px 0; }
.markdown-body ul, .markdown-body ol { padding-left: 20px; }
.markdown-body strong { color: var(--text-primary); }
.markdown-body blockquote { border-left: 3px solid var(--primary); padding-left: 12px; color: var(--text-muted); margin: 10px 0; }

/* 日历热力图 */
.heatmap { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.heatmap-cell {
  aspect-ratio: 1;
  border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.68rem;
  font-family: var(--font-num);
  background: var(--bg-input);
  color: var(--text-muted);
}
.heatmap-cell.gain { background: var(--gain-bg); color: var(--gain); }
.heatmap-cell.loss { background: var(--loss-bg); color: var(--loss); }
.heatmap-label { font-size: 0.7rem; color: var(--text-muted); text-align: center; padding-bottom: 4px; }

/* ==================== 响应式 ==================== */
.mobile-menu-btn { display: none; }
.sidebar-mask { display: none; }

@media (max-width: 900px) {
  .grid-2, .grid-2-1 { grid-template-columns: 1fr; }
  .mobile-menu-btn { display: inline-flex; }
  .sidebar { transform: translateX(-100%); width: 240px !important; }
  .sidebar.open { transform: translateX(0); }
  .sidebar.open .nav-label, .sidebar.open .logo-text { display: inline; }
  .sidebar-mask.open {
    display: block;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 85;
  }
  .main-area, .sidebar.collapsed ~ .main-area { margin-left: 0; }
  .content { padding: 16px; }
  .form-row { grid-template-columns: 1fr; }
  .setting-control { width: 180px; }
}
