/* ===== 全局变量与重置 ===== */
:root {
  --bg-primary: #0a0e14;
  --bg-secondary: #141b22;
  --bg-card: #161e28;
  --bg-input: #1c2533;
  --border: #21262d;
  --border-light: #2d3540;
  --text-primary: #c9d1d9;
  --text-secondary: #8b949e;
  --text-muted: #5c6570;
  --green: #26a641;
  --green-bright: #3fb950;
  --red: #e5534b;
  --red-bright: #f77873;
  --yellow: #d2991d;
  --orange: #f0883e;
  --blue: #58a6ff;
  --purple: #a371f7;

  --radius: 8px;
  --radius-sm: 4px;
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

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;
  min-height: 100vh;
  font-size: 14px;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

input[type="number"] {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  width: 100px;
}
input[type="number"]:focus { border-color: var(--blue); outline: none; }

button {
  cursor: pointer;
  border: none;
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
}

/* ===== 导航栏 ===== */
.navbar {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  display: flex;
  align-items: center;
  height: 50px;
  gap: 20px;
}
.navbar .logo { font-weight: 700; font-size: 16px; color: var(--orange); }
.navbar .nav-links { display: flex; gap: 4px; }
.navbar .nav-link {
  color: var(--text-secondary);
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  transition: all 0.15s;
}
.navbar .nav-link:hover { color: var(--text-primary); background: var(--bg-card); text-decoration: none; }
.navbar .nav-link.active { color: var(--text-primary); background: var(--bg-card); }

/* ===== 顶部状态栏 ===== */
.top-bar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 20px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  font-size: 13px;
}
.top-bar .info-item { white-space: nowrap; }
.top-bar .info-item .label { color: var(--text-secondary); margin-right: 4px; }
.top-bar .spacer { flex: 1; }
.top-bar .btn-refresh {
  background: var(--blue);
  color: #fff;
  padding: 6px 14px;
  font-size: 12px;
}
.top-bar .btn-refresh:hover { opacity: 0.85; }
.top-bar .btn-refresh.spinning { animation: spin 1s linear infinite; pointer-events: none; opacity: 0.6; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ===== 信号卡片网格 ===== */
.signal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
  gap: 14px;
  padding: 16px 20px;
}

/* ===== 信号卡片 ===== */
.signal-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.2s;
}
.signal-card:hover { border-color: var(--border-light); }

.signal-card.card-strong-buy { border-left: 3px solid var(--green-bright); }
.signal-card.card-buy { border-left: 3px solid var(--green); }
.signal-card.card-hold { border-left: 3px solid var(--yellow); }
.signal-card.card-reduce { border-left: 3px solid var(--orange); }
.signal-card.card-clear { border-left: 3px solid var(--red-bright); }

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 12px 14px 8px;
}
.card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.stock-name { font-weight: 600; font-size: 15px; }
.stock-code { color: var(--text-muted); font-size: 12px; font-family: monospace; }
.card-price { text-align: right; }
.card-price .price { font-size: 18px; font-weight: 700; font-family: monospace; display: block; }
.card-price .change { font-size: 13px; }

/* 信号灯 */
.signal-dot {
  width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex-shrink: 0;
}
.dot-strong-buy { background: var(--green-bright); box-shadow: 0 0 6px var(--green-bright); }
.dot-buy { background: var(--green); }
.dot-hold { background: var(--yellow); }
.dot-reduce { background: var(--orange); }
.dot-clear { background: var(--red-bright); box-shadow: 0 0 6px var(--red-bright); }
.dot-no-data { background: var(--text-muted); }

/* 徽章 */
.badge-holding {
  background: var(--blue);
  color: #fff;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 10px;
  font-weight: 500;
}
.badge-switch {
  background: var(--purple);
  color: #fff;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 10px;
  font-weight: 500;
  animation: pulse 1.5s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* 卡片主体 */
.card-body { padding: 4px 14px 10px; }

.signal-row {
  display: flex;
  gap: 12px;
  margin-bottom: 8px;
}
.signal-item {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.signal-item .label { color: var(--text-muted); font-size: 11px; white-space: nowrap; }
.signal-item .score { font-weight: 700; font-size: 16px; font-family: monospace; min-width: 30px; }
.signal-item .tag {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 3px;
  font-weight: 500;
  white-space: nowrap;
}

.score-strong_buy { color: var(--green-bright); }
.score-watch_buy { color: var(--green); }
.score-hold { color: var(--yellow); }
.score-reduce { color: var(--orange); }
.score-clear { color: var(--red-bright); }
.score-no_data { color: var(--text-muted); }

.tag.signal-buy-strong { background: rgba(63,185,80,0.15); color: var(--green-bright); }
.tag.signal-buy-watch { background: rgba(38,166,65,0.12); color: var(--green); }
.tag.signal-hold { background: rgba(210,153,29,0.12); color: var(--yellow); }
.tag.signal-reduce { background: rgba(240,136,62,0.12); color: var(--orange); }
.tag.signal-clear { background: rgba(247,120,115,0.12); color: var(--red-bright); }
.tag.signal-no-data { background: rgba(92,101,112,0.1); color: var(--text-muted); }

.info-row {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-secondary);
  padding: 2px 0;
}
.info-row .stop-loss { color: var(--red); font-family: monospace; }
.position-row { border-top: 1px solid var(--border); margin-top: 4px; padding-top: 4px; }

.switch-alert {
  margin-top: 8px;
  padding: 8px 10px;
  background: rgba(163,113,247,0.08);
  border: 1px solid rgba(163,113,247,0.2);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--purple);
}

/* 卡片底部 */
.card-footer { border-top: 1px solid var(--border); padding: 6px 14px; }
.btn-expand {
  background: none;
  color: var(--text-muted);
  font-size: 11px;
  padding: 2px 0;
  width: 100%;
  text-align: center;
}
.btn-expand:hover { color: var(--text-primary); }

.detail-panel { padding: 8px 0; }
.detail-panel.hidden { display: none; }
.detail-content { font-size: 12px; }
.detail-section h4 { color: var(--text-secondary); margin-bottom: 4px; font-size: 12px; }
.detail-section table { width: 100%; border-collapse: collapse; }
.detail-section td {
  padding: 2px 6px;
  border-bottom: 1px solid var(--border);
}
.detail-section td:first-child { color: var(--text-muted); width: 40%; }
.detail-section td:last-child { font-family: monospace; }

/* ===== 底部概览面板 ===== */
.summary-panel {
  margin: 0 20px 20px;
  padding: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.summary-section { margin-bottom: 16px; }
.summary-section:last-child { margin-bottom: 0; }
.summary-section h3 {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}

.asset-row {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}
.asset-item { display: flex; flex-direction: column; }
.asset-item .label { font-size: 11px; color: var(--text-muted); }
.asset-item .value { font-size: 18px; font-weight: 700; font-family: monospace; }

.signal-bar {
  display: flex;
  gap: 2px;
  height: 28px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  font-size: 11px;
  line-height: 28px;
  text-align: center;
}
.bar-seg { color: #fff; min-width: 30px; }
.bar-strong-buy { background: var(--green-bright); }
.bar-buy-watch { background: var(--green); }
.bar-hold { background: var(--yellow); color: #000; }
.bar-reduce { background: var(--orange); }
.bar-clear { background: var(--red-bright); }

.switch-list { font-size: 12px; }
.switch-item { padding: 4px 0; border-bottom: 1px solid var(--border); }
.switch-item:last-child { border-bottom: none; }

.heatmap { display: flex; flex-wrap: wrap; gap: 4px; }
.heat-item {
  padding: 4px 8px;
  border-radius: 3px;
  font-size: 11px;
  font-weight: 500;
  color: #fff;
  cursor: default;
}

/* ===== 持仓管理页面 ===== */
.page-container {
  max-width: 1300px;
  margin: 0 auto;
  padding: 20px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.page-header h2 { font-size: 20px; font-weight: 600; }

.btn-group { display: flex; gap: 8px; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { opacity: 0.85; }
.btn-secondary { background: var(--bg-input); color: var(--text-primary); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--border-light); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { opacity: 0.85; }

.table-container {
  overflow-x: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
thead th {
  background: var(--bg-secondary);
  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;
}
tbody td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody tr:hover { background: rgba(255,255,255,0.02); }
.code-cell { font-family: monospace; font-size: 12px; color: var(--text-muted); }
.price-cell { font-family: monospace; font-weight: 500; }
.value-cell { font-family: monospace; }
.empty { text-align: center; color: var(--text-muted); padding: 40px !important; }

.btn-remove {
  background: none;
  color: var(--red);
  font-size: 12px;
  padding: 4px 10px;
  border: 1px solid transparent;
}
.btn-remove:hover { border-color: var(--red); }

/* ===== 状态色 ===== */
.up { color: var(--green-bright); }
.down { color: var(--red-bright); }
.muted { color: var(--text-muted); }

/* ===== 滚动条 ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }

/* ===== 响应式 ===== */
@media (max-width: 768px) {
  .signal-grid { grid-template-columns: 1fr; padding: 10px; }
  .top-bar { gap: 10px; padding: 8px 10px; font-size: 12px; }
  .asset-row { flex-direction: column; gap: 8px; }
  .navbar { padding: 0 10px; gap: 10px; }
}
