/* ── 设计系统 ─────────────────────────────────────── */
:root {
  --sidebar-width: 250px;
  --topbar-height: 70px;

  /* VS Code 现代白配色 */
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f6f8fa;
  --border: #d1d9e0;
  --text: #1f2328;
  --text-secondary: #656d76;
  --muted: #8c959f;

  --primary: #0969da;
  --primary-hover: #0550ae;
  --primary-soft: #ddf4ff;
  --secondary: #0969da;
  --secondary-hover: #0550ae;
  --secondary-soft: #ddf4ff;
  --danger: #cf222e;
  --danger-hover: #a40e26;
  --danger-soft: #ffebe9;
  --success: #1a7f37;
  --success-soft: #dafbe1;

  /* A 股红涨绿跌，保持可读性 */
  --up: #cf222e;
  --down: #1a7f37;
  --warn: #9a6700;
  --gray: #6e7781;

  --sidebar-bg: #ffffff;
  --sidebar-bg-light: #f6f8fa;
  --sidebar-text: #656d76;
  --sidebar-active: #0969da;

  --radius-sm: 8px;
  --radius: 12px;
  --shadow-sm: 0 1px 2px rgba(31, 35, 40, 0.04);
  --shadow: 0 1px 3px rgba(31, 35, 40, 0.08);
  --shadow-lg: 0 8px 24px rgba(31, 35, 40, 0.1);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial,
               "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

/* ── 侧边栏 ────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--sidebar-bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  z-index: 100;
  border-right: 1px solid var(--border);
  box-shadow: 1px 0 0 rgba(31, 35, 40, 0.04);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 26px 24px 22px;
  text-decoration: none;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}

.brand-icon {
  width: 36px;
  height: 36px;
  color: var(--primary);
  flex-shrink: 0;
}

.brand-text {
  font-size: 18px;
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.brand-text small {
  font-size: 13px;
  font-weight: 500;
  color: var(--sidebar-text);
}

.side-nav {
  flex: 1;
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
}

.side-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s ease, color 0.15s ease;
}

.side-item svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.side-item:hover {
  background: var(--surface-2);
  color: var(--text);
}

.side-item.active {
  background: var(--primary-soft);
  color: var(--primary);
  border-left: 3px solid var(--primary);
  margin-left: -3px;
}

.sidebar-footer {
  padding: 18px 24px;
  font-size: 11px;
  color: var(--sidebar-text);
  border-top: 1px solid var(--border);
}

.sidebar-footer p { margin: 2px 0; }

/* ── 主区域 ────────────────────────────────────────── */
.main-wrap {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: var(--topbar-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  position: sticky;
  top: 0;
  z-index: 90;
}

.page-title {
  font-size: 22px;
  font-weight: 800;
  margin: 0;
  letter-spacing: -0.02em;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.version {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface-2);
  padding: 5px 10px;
  border-radius: 999px;
}

.main {
  flex: 1;
  padding: 28px 32px 60px;
  margin: 0 auto;
  width: 100%;
}

/* ── 页面副标题 ────────────────────────────────────── */
.page-subtitle {
  margin: 6px 0 22px;
  color: var(--text-secondary);
  font-size: 14px;
}

/* ── 卡片 ──────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
  transition: box-shadow 0.2s ease;
}

.card:hover { box-shadow: var(--shadow-lg); }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
  gap: 14px;
}

.card-header h2,
.card h2 {
  font-size: 16px;
  font-weight: 700;
  margin: 0;
}

.card h2 { margin: 20px 0 12px; }
.card h2:first-child { margin-top: 0; }

.card h3 {
  font-size: 14px;
  font-weight: 600;
  margin: 16px 0 10px;
  color: var(--text-secondary);
}

/* ── 指标卡 ────────────────────────────────────────── */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 18px;
}

.metric {
  position: relative;
  padding: 24px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.metric::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: var(--primary);
}

.metric .label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.04em;
}

.metric .value {
  font-size: 34px;
  font-weight: 800;
  margin-top: 10px;
  letter-spacing: -0.03em;
}

.metric .sub {
  font-size: 13px;
  color: var(--muted);
  margin-top: 8px;
}

.metric.primary::before { background: var(--primary); }
.metric.secondary::before { background: var(--secondary); }
.metric.success::before { background: var(--success); }
.metric.danger::before { background: var(--danger); }

/* ── 按钮 ──────────────────────────────────────────── */
button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  background: var(--primary);
  color: #fff;
  text-decoration: none;
  box-shadow: none;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
  white-space: nowrap;
}

button:hover, .btn:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  transform: translateY(-1px);
}

button:active, .btn:active { transform: translateY(0); }

button:disabled, .btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
  filter: grayscale(0.3);
}

.btn-secondary {
  background: var(--secondary);
  border-color: var(--secondary);
}
.btn-secondary:hover {
  background: var(--secondary-hover);
  border-color: var(--secondary-hover);
}

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
}
.btn-danger:hover {
  background: var(--danger-hover);
  border-color: var(--danger-hover);
}

.btn-sm {
  padding: 7px 12px;
  font-size: 13px;
  border-radius: 8px;
}

/* ── 工具栏 / 表单 ─────────────────────────────────── */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.toolbar label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--text-secondary);
  cursor: pointer;
}

.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
  margin-bottom: 14px;
}

.form-row label {
  min-width: 130px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
}

input[type="text"],
input[type="number"],
input[type="password"],
select {
  padding: 10px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, select:focus {
  border-color: var(--secondary);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.12);
}

input.short { width: 100px; }
input.medium { width: 260px; }
input.long { width: 420px; max-width: 100%; }

/* ── 表格 ──────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  font-size: 14px;
}

th, td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

th {
  background: var(--surface-2);
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  position: sticky;
  top: 0;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(241, 245, 249, 0.6); }

/* ── 颜色 / 标签 ───────────────────────────────────── */
.up { color: var(--up); font-weight: 700; }
.down { color: var(--down); font-weight: 700; }
.warn { color: var(--warn); font-weight: 700; }
.gray { color: var(--gray); }

.tag {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.tag.up { background: var(--danger-soft); border-color: #fecaca; }
.tag.down { background: var(--success-soft); border-color: #a7f3d0; }
.tag.warn { background: #fffbeb; border-color: #fde68a; }
.tag.gray { background: #f1f5f9; border-color: #e2e8f0; }

/* ── 推荐卡片 ──────────────────────────────────────── */
.reco-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
  transition: box-shadow 0.2s ease;
}

.reco-card:hover { box-shadow: var(--shadow-lg); }

.reco-card h4 {
  margin: 0 0 10px;
  font-size: 16px;
  font-weight: 700;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.reco-card .reason,
.reco-card .risk {
  font-size: 14px;
  line-height: 1.7;
  margin: 8px 0;
}

.reco-card .risk {
  color: var(--danger);
  background: var(--danger-soft);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
}

/* ── 详情文本框 ────────────────────────────────────── */
.detail-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 18px;
  font-size: 14px;
  line-height: 1.8;
  white-space: pre-wrap;
  max-height: 360px;
  overflow-y: auto;
  color: var(--text-secondary);
}

/* ── 状态 / 提示 ───────────────────────────────────── */
.status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  font-size: 14px;
  color: var(--text-secondary);
  min-height: 22px;
}

.empty-tip {
  color: var(--muted);
  font-size: 14px;
  padding: 36px 0;
  text-align: center;
}

.flashes { margin-bottom: 20px; }

.flash {
  background: var(--primary-soft);
  border: 1px solid #b6e3ff;
  color: var(--primary-hover);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
  font-weight: 500;
}

/* ── 加载动画 ──────────────────────────────────────── */
.spinner::after {
  content: "";
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ── 移动端菜单 ─────────────────────────────────────── */
.menu-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 6px;
  margin-right: 10px;
  border-radius: var(--radius-sm);
  box-shadow: none;
}
.menu-toggle:hover { background: var(--surface-2); transform: none; }
.menu-toggle svg { width: 24px; height: 24px; }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 150;
  backdrop-filter: blur(2px);
}
.sidebar-overlay.show { display: block; }

/* ── 响应式 ─────────────────────────────────────────── */
@media (max-width: 768px) {
  .menu-toggle { display: inline-flex; }
  .topbar {
    justify-content: center;
    position: relative;
    padding: 0 14px;
    gap: 0;
  }
  .menu-toggle {
    position: absolute;
    left: 14px;
    top: 0;
    bottom: 0;
    margin: auto 0;
  }
  .topbar-right {
    position: absolute;
    right: 14px;
    top: 0;
    bottom: 0;
    display: flex;
    align-items: center;
  }
  .topbar-right .version { display: none; }
  .page-title {
    font-size: 18px;
    text-align: center;
    margin: 0;
  }

  .sidebar {
    width: 260px;
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    flex-direction: column;
    padding: 18px 14px;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 200;
    box-shadow: none;
  }
  .sidebar.open { transform: translateX(0); }
  .side-nav { display: flex; }
  .sidebar-footer { display: block; }
  .sidebar-overlay.show { display: block; }

  .main-wrap { margin-left: 0; }
  .main { padding: 16px; max-width: 100%; }

  .card { padding: 16px; margin-bottom: 16px; }
  .card-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 14px;
  }
  .card-header h2,
  .card h2 { font-size: 15px; }

  .toolbar {
    width: 100%;
    flex-wrap: wrap;
  }
  .toolbar button,
  .toolbar .btn {
    flex: 1 1 auto;
    min-width: 0;
    padding: 9px 14px;
  }

  .grid { grid-template-columns: 1fr; }
  .metric { padding: 18px; }
  .metric .value { font-size: 28px; }

  .form-row {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    margin-bottom: 12px;
  }
  .form-row label { min-width: auto; }
  input.short,
  input.medium,
  input.long { width: 100%; }

  .table-wrap {
    -webkit-overflow-scrolling: touch;
    border-radius: 12px;
  }
  table { font-size: 13px; }
  th, td { padding: 10px 12px; }

  .reco-card { padding: 16px; }
  .reco-card h4 {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  .reco-card h4 .tag { margin-left: 0 !important; }
  .reco-card .risk { padding: 10px 12px; }

  .page-subtitle {
    font-size: 13px;
    margin: 4px 0 14px;
  }
  .detail-box {
    font-size: 13px;
    padding: 14px;
    max-height: 280px;
  }
  .status { font-size: 13px; }
}
