/* ========== 基础变量 ========== */
:root {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-card: #1c2128;
  --border: #30363d;
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #484f58;
  --accent: #58a6ff;
  --red: #f85149;
  --green: #3fb950;
  --yellow: #d29922;
  --orange: #db6d28;
  --radius: 8px;
}

/* ========== 重置 & 全局 ========== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
    'Helvetica Neue', Arial, 'Noto Sans SC', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 20px;
}

/* ========== 顶部标题 ========== */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.header h1 {
  font-size: 1.5rem;
  font-weight: 600;
}

.header .subtitle {
  color: var(--text-secondary);
  font-size: 0.875rem;
}

/* ========== 概览卡片区 ========== */
.summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.card .label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.card .value {
  font-size: 1.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ========== 持仓明细表 ========== */
.table-wrapper {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  margin-bottom: 24px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

thead th {
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  padding: 12px 16px;
  text-align: right;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}

thead th:first-child {
  text-align: left;
}

tbody td {
  padding: 14px 16px;
  text-align: right;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

tbody td:first-child {
  text-align: left;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover {
  background: rgba(88, 166, 255, 0.04);
}

/* 股票名称列 */
.stock-name {
  font-weight: 600;
}

.stock-symbol {
  color: var(--text-secondary);
  font-size: 0.8rem;
  margin-left: 6px;
}

/* ========== 涨跌颜色 (A股: 涨红跌绿) ========== */
.price-up {
  color: var(--red);
}

.price-down {
  color: var(--green);
}

.price-flat {
  color: var(--text-secondary);
}

.change-tag {
  font-size: 0.8rem;
  margin-left: 4px;
}

/* ========== 偏离度颜色 ========== */
.deviation-normal {
  color: var(--text-primary);
}

.deviation-warn {
  color: var(--yellow);
  font-weight: 600;
}

.deviation-danger {
  color: var(--red);
  font-weight: 600;
}

/* ========== 操作标签 ========== */
.action-tag {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 0.8rem;
  font-weight: 600;
}

.action-buy {
  background: rgba(63, 185, 80, 0.15);
  color: var(--green);
}

.action-sell {
  background: rgba(248, 81, 73, 0.15);
  color: var(--red);
}

.action-hold {
  background: rgba(139, 148, 158, 0.15);
  color: var(--text-secondary);
}

/* ========== 底部警告 ========== */
.alerts {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  border-left: 4px solid;
}

.alert-warning {
  background: rgba(210, 153, 34, 0.1);
  border-color: var(--yellow);
  color: var(--yellow);
}

.alert-error {
  background: rgba(248, 81, 73, 0.1);
  border-color: var(--red);
  color: var(--red);
}

.alert-info {
  background: rgba(88, 166, 255, 0.1);
  border-color: var(--accent);
  color: var(--accent);
}

/* ========== 加载状态 ========== */
.loading {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}

.loading .spinner {
  display: inline-block;
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 16px;
}

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

/* ========== 汇总行 ========== */
.row-total {
  font-weight: 700;
  background: var(--bg-secondary);
}

/* ========== 响应式 ========== */
@media (max-width: 768px) {
  .container {
    padding: 16px 12px;
  }

  .summary-cards {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .card {
    padding: 14px;
  }

  .card .value {
    font-size: 1.2rem;
  }

  table {
    font-size: 0.82rem;
  }

  thead th,
  tbody td {
    padding: 10px 10px;
  }
}

@media (max-width: 480px) {
  .summary-cards {
    grid-template-columns: 1fr;
  }

  .header h1 {
    font-size: 1.2rem;
  }
}
