/**
 * main.css - AI 量化交易系统主样式
 * 设计：深色玻璃拟态 + A 股配色（红涨绿跌）
 */

/* ========== 基础变量 ========== */
:root {
  /* 主色 */
  --color-primary: #00d4ff;       /* 科技蓝 */
  --color-primary-dim: #00a8e8;
  --color-up: #ff4757;            /* 红=涨（A 股惯例） */
  --color-up-dim: #ff6b81;
  --color-down: #00ff88;          /* 绿=跌（A 股惯例） */
  --color-down-dim: #2ed573;
  --color-warning: #ffb547;
  --color-info: #00d4ff;
  --color-critical: #ff4757;

  /* 背景 */
  --bg-1: #0a0e27;                /* 最深底 */
  --bg-2: #131829;                /* 卡片 */
  --bg-3: #1a2138;                /* 浮层 */
  --bg-hover: #232b45;

  /* 文字 */
  --text-1: #e6f1ff;
  --text-2: #8892b0;
  --text-3: #5a6380;

  /* 边框 */
  --border-1: #232b45;
  --border-glow: rgba(0, 212, 255, 0.3);

  /* 阴影 */
  --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.4);
  --shadow-glow: 0 0 24px rgba(0, 212, 255, 0.2);

  /* 圆角 */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;

  /* 尺寸 */
  --topbar-h: 56px;
  --sidebar-w: 220px;
  --sidebar-collapsed-w: 60px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  background: var(--bg-1);
  color: var(--text-1);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--color-primary); text-decoration: none; transition: 0.2s; }
a:hover { color: var(--color-primary-dim); text-shadow: 0 0 8px var(--border-glow); }

/* ========== 布局 ========== */
.layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  height: var(--topbar-h);
  background: var(--bg-2);
  border-bottom: 1px solid var(--border-1);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  position: sticky; top: 0; z-index: 100;
  backdrop-filter: blur(12px);
}

.topbar-left, .topbar-right { display: flex; align-items: center; gap: 16px; }

.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 16px; }
.brand-icon { font-size: 20px; color: var(--color-primary); text-shadow: 0 0 12px var(--border-glow); }
.brand-text { color: var(--text-1); }
.brand-ver {
  font-size: 11px;
  padding: 2px 6px;
  background: var(--bg-3);
  border: 1px solid var(--border-1);
  border-radius: var(--r-sm);
  color: var(--text-2);
}

.sidebar-toggle {
  background: transparent;
  border: 1px solid var(--border-1);
  color: var(--text-2);
  width: 32px; height: 32px;
  border-radius: var(--r-sm);
  cursor: pointer;
  font-size: 18px;
}
.sidebar-toggle:hover { background: var(--bg-hover); color: var(--color-primary); }

/* 移动端：默认收起，需要 .open 才能显示 */
.sidebar-toggle-mobile { display: none; }
.sidebar-overlay { display: none; }
@media (max-width: 768px) {
  .sidebar { position: fixed; left: -220px; height: calc(100vh - var(--topbar-h)); z-index: 99; box-shadow: var(--shadow-card); }
  .sidebar.open,
  .sidebar.collapsed { left: 0; }
  .sidebar-overlay.open { display: block; position: fixed; inset: var(--topbar-h) 0 0 0; background: rgba(0,0,0,0.5); z-index: 98; }
  .card-grid, .card-grid-2 { grid-template-columns: 1fr; }

  /* 大盘晴雨表三格竖排 */
  .regime-summary { grid-template-columns: 1fr; }

  /* 候选池评分网格：5列→2列→1列 */
  [style*="repeat(5,1fr)"] { grid-template-columns: repeat(2, 1fr) !important; }
  [style*="repeat(4,1fr)"] { grid-template-columns: repeat(2, 1fr) !important; }
  [style*="repeat(5,1fr)"] > div,
  [style*="repeat(4,1fr)"] > div { overflow: hidden; min-width: 0; }
  [style*="repeat(5,1fr)"] > div > div:last-child,
  [style*="repeat(4,1fr)"] > div > div:last-child {
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }

  /* 候选池手机端强制单列，避免极端宽度溢出 */
  @media (max-width: 480px) {
    [style*="repeat(5,1fr)"],
    [style*="repeat(4,1fr)"],
    [style*="repeat(2,1fr)"] { grid-template-columns: 1fr !important; }
  }

  .topbar { padding: 0 12px; }
  .brand-text { display: none; }
  .market-status { display: none; }
}

.market-status {
  padding: 4px 12px;
  border-radius: var(--r-sm);
  background: var(--bg-3);
  border: 1px solid var(--border-1);
  font-size: 12px;
  color: var(--text-2);
}

.user-info { display: flex; align-items: center; gap: 6px; color: var(--text-2); font-size: 13px; }

.btn-link {
  padding: 4px 12px;
  border-radius: var(--r-sm);
  background: var(--bg-3);
  color: var(--text-2);
}
.btn-link:hover { background: var(--bg-hover); color: var(--color-primary); }

.main { display: flex; flex: 1; min-height: calc(100vh - var(--topbar-h)); }

.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-2);
  border-right: 1px solid var(--border-1);
  padding: 16px 0;
  overflow-y: auto;
  transition: width 0.25s;
}
.sidebar.collapsed { width: var(--sidebar-collapsed-w); }
.sidebar.collapsed .nav-title,
.sidebar.collapsed .nav-item span:last-child { display: none; }

.nav-group { margin-bottom: 16px; }
.nav-title {
  padding: 6px 20px;
  font-size: 11px;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: var(--text-2);
  border-left: 3px solid transparent;
  transition: 0.2s;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text-1); }
.nav-item.active {
  background: linear-gradient(90deg, rgba(0,212,255,0.1), transparent);
  color: var(--color-primary);
  border-left-color: var(--color-primary);
  text-shadow: 0 0 8px var(--border-glow);
}
.nav-icon { font-size: 16px; width: 20px; text-align: center; }

.content {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
  background: var(--bg-1);
}

.footer {
  height: 36px;
  background: var(--bg-2);
  border-top: 1px solid var(--border-1);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-size: 12px;
  color: var(--text-3);
}
.footer code { background: var(--bg-3); padding: 1px 6px; border-radius: 4px; color: var(--color-primary); }

/* ========== 卡片 ========== */
.card {
  background: var(--bg-2);
  border: 1px solid var(--border-1);
  border-radius: var(--r-md);
  padding: 20px;
  margin-bottom: 16px;
  position: relative;
  overflow: hidden;
}
.card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--color-primary), transparent);
  opacity: 0.4;
}

.card-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-1);
}
.card-title .icon { margin-right: 8px; color: var(--color-primary); }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
}
.card-grid-2 { grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); }

/* 晴雨表大状态卡 */
.regime-card {
  text-align: center;
  padding: 32px 20px;
}
.regime-card .emoji { font-size: 64px; line-height: 1; }
.regime-card .label { font-size: 22px; font-weight: 600; margin-top: 12px; }
.regime-card .stars { color: var(--color-warning); font-size: 24px; margin-top: 6px; letter-spacing: 4px; }
.regime-card .advice {
  margin-top: 12px;
  padding: 8px 14px;
  background: var(--bg-3);
  border-radius: var(--r-sm);
  font-size: 13px;
  color: var(--text-2);
  display: inline-block;
}

/* 情绪温度计 */
.sentiment-state {
  text-align: center;
  padding: 24px;
}
.sentiment-emoji { font-size: 56px; }
.sentiment-z {
  font-size: 36px;
  font-weight: 700;
  margin-top: 8px;
}
.sentiment-z.up { color: var(--color-up); }
.sentiment-z.down { color: var(--color-down); }

.chart-box { height: 240px; }
.chart-box-lg { height: 320px; }
.chart-box-sm { height: 180px; }

/* 板块/主题排名 */
.rank-list { list-style: none; }
.rank-list li {
  display: flex;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px dashed var(--border-1);
  gap: 12px;
}
.rank-list li:last-child { border-bottom: none; }
.rank-medal {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600;
  font-size: 12px;
  flex-shrink: 0;
}
.rank-medal.gold   { background: linear-gradient(135deg, #ffd700, #ff9500); color: #0a0e27; }
.rank-medal.silver { background: linear-gradient(135deg, #c0c0c0, #808080); color: #0a0e27; }
.rank-medal.bronze { background: linear-gradient(135deg, #cd7f32, #8b4513); color: #fff; }
.rank-medal.normal { background: var(--bg-3); color: var(--text-2); }

.rank-name { flex: 1; font-weight: 500; color: var(--text-1); }
.rank-bar  { flex: 2; height: 8px; background: var(--bg-3); border-radius: 4px; overflow: hidden; }
.rank-bar-fill { height: 100%; background: linear-gradient(90deg, var(--color-primary), var(--color-primary-dim)); transition: 0.4s; }
.rank-pct  { width: 70px; text-align: right; font-weight: 600; font-family: 'Consolas', monospace; }
.rank-pct.up   { color: var(--color-up); }
.rank-pct.down { color: var(--color-down); }

/* ========== 通用 ========== */
.text-up   { color: var(--color-up); }
.text-down { color: var(--color-down); }
.text-warn { color: var(--color-warning); }
.text-muted{ color: var(--text-2); }
.text-mono { font-family: 'Consolas', 'Monaco', monospace; }

.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--r-sm);
  font-size: 12px;
  background: var(--bg-3);
  color: var(--text-2);
  border: 1px solid var(--border-1);
}
/* 提示/告警类 tag —— A 股语义：success=涨/看多/正向，danger=跌/看空/反向 */
.tag.success { background: rgba(255,71,87,0.15); color: var(--color-up); border-color: rgba(255,71,87,0.3); }
.tag.danger  { background: rgba(0,255,136,0.15); color: var(--color-down); border-color: rgba(0,255,136,0.3); }
.tag.warning { background: rgba(255,181,71,0.15); color: var(--color-warning); border-color: rgba(255,181,71,0.3); }
.tag.info    { background: rgba(0,212,255,0.15); color: var(--color-primary); border-color: rgba(0,212,255,0.3); }

.btn {
  display: inline-block;
  padding: 8px 16px;
  border-radius: var(--r-sm);
  background: var(--color-primary);
  color: var(--bg-1);
  font-weight: 600;
  font-size: 13px;
  border: none;
  cursor: pointer;
  transition: 0.2s;
}
.btn:hover { background: var(--color-primary-dim); box-shadow: var(--shadow-glow); transform: translateY(-1px); }
.btn-secondary { background: var(--bg-3); color: var(--text-1); border: 1px solid var(--border-1); }
.btn-secondary:hover { background: var(--bg-hover); }
.btn-danger { background: var(--color-up); color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* 表格 */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border-1); }
.table th { background: var(--bg-3); font-size: 12px; color: var(--text-2); font-weight: 500; }
.table tr:hover td { background: var(--bg-hover); }

/* 表单 */
input, textarea, select {
  background: var(--bg-3);
  border: 1px solid var(--border-1);
  border-radius: var(--r-sm);
  padding: 8px 12px;
  color: var(--text-1);
  font-size: 14px;
  width: 100%;
  transition: 0.2s;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(0,212,255,0.15);
}

/* Toast */
.toast-container {
  position: fixed;
  top: 70px; right: 20px;
  z-index: 9999;
  display: flex; flex-direction: column;
  gap: 8px;
}
.toast {
  padding: 12px 20px;
  border-radius: var(--r-md);
  background: var(--bg-3);
  border: 1px solid var(--border-1);
  color: var(--text-1);
  box-shadow: var(--shadow-card);
  min-width: 240px;
  animation: slideIn 0.3s;
}
.toast.success { border-left: 3px solid var(--color-up); }
.toast.error   { border-left: 3px solid var(--color-critical); }
.toast.warning { border-left: 3px solid var(--color-warning); }
.toast.info    { border-left: 3px solid var(--color-primary); }
/* A 股语境：涨=up=红(看多=好事)，用红；跌=down=绿(看空=坏事)，用绿 */

@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* 空状态 */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-2);
}
.empty-state .emoji { font-size: 64px; margin-bottom: 12px; opacity: 0.5; }
.empty-state .title { font-size: 16px; margin-bottom: 6px; color: var(--text-1); }
.empty-state .desc  { font-size: 13px; margin-bottom: 16px; }

/* 演示数据浮窗 */
.demo-banner {
  position: fixed;
  bottom: 50px; right: 20px;
  background: var(--bg-3);
  border: 1px solid var(--color-primary);
  border-radius: var(--r-md);
  padding: 14px 18px;
  box-shadow: var(--shadow-glow);
  z-index: 9000;
  max-width: 320px;
  animation: slideIn 0.4s;
}
.demo-banner .demo-title { font-weight: 600; margin-bottom: 6px; color: var(--color-primary); }
.demo-banner .demo-desc  { font-size: 12px; color: var(--text-2); margin-bottom: 10px; }
.demo-banner .demo-close { position: absolute; top: 6px; right: 10px; cursor: pointer; color: var(--text-3); }

/* 滚动条 */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-1); }
::-webkit-scrollbar-thumb { background: var(--bg-3); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--bg-hover); }

/* 自动抓取横幅（首次访问数据库为空时显示） */
.auto-fetch-banner {
  text-align: center;
  padding: 48px 24px;
  border: 1px dashed var(--color-primary);
  background: linear-gradient(135deg, var(--bg-2), rgba(0,212,255,0.05));
  animation: pulse-border 2s infinite;
}
.auto-fetch-banner .emoji { font-size: 64px; animation: spin 3s linear infinite; display: inline-block; }
.auto-fetch-banner .title { font-size: 18px; margin: 12px 0 6px; color: var(--text-1); }
.auto-fetch-banner .desc { color: var(--text-2); font-size: 13px; margin-bottom: 16px; line-height: 1.8; }
.auto-fetch-tips {
  display: inline-block;
  text-align: left;
  background: var(--bg-3);
  border-radius: var(--r-sm);
  padding: 12px 16px;
  font-size: 12px;
  color: var(--text-2);
  line-height: 1.8;
  max-width: 580px;
  margin-top: 8px;
  word-wrap: break-word;
}
.auto-fetch-tips strong { color: var(--color-primary); }
.auto-fetch-tips code {
  background: rgba(0,212,255,0.1);
  color: var(--color-primary);
  padding: 1px 6px;
  border-radius: 3px;
  font-family: 'Consolas', monospace;
  font-size: 11px;
  word-break: break-all;
}
/* 自动抓取按钮组（响应式） */
.auto-fetch-actions {
  margin-top: 16px;
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}
.auto-fetch-actions .btn { white-space: nowrap; }

/* 手机端适配 */
@media (max-width: 768px) {
  .auto-fetch-banner { padding: 32px 16px; }
  .auto-fetch-banner .emoji { font-size: 48px; }
  .auto-fetch-banner .title { font-size: 16px; }
  .auto-fetch-actions { flex-direction: column; align-items: stretch; }
  .auto-fetch-actions .btn { width: 100%; padding: 12px 16px; font-size: 14px; }
  .auto-fetch-tips { padding: 10px 12px; font-size: 11px; }
}
@media (max-width: 480px) {
  .auto-fetch-banner .emoji { font-size: 40px; }
  .auto-fetch-banner .title { font-size: 15px; }
}

@keyframes pulse-border {
  0%, 100% { border-color: var(--color-primary); box-shadow: 0 0 0 0 rgba(0,212,255,0.3); }
  50%      { border-color: var(--color-primary-dim); box-shadow: 0 0 0 8px rgba(0,212,255,0); }
}
@keyframes spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}
