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

  /* 深色交易终端配色 */
  --bg: #0a0e17;
  --bg-grad: linear-gradient(135deg, #0a0e17 0%, #0d1320 100%);
  --surface: #131826;
  --surface-2: #1a2030;
  --surface-3: #212940;
  --border: #252d44;
  --border-light: #2d3654;
  --text: #e1e8f5;
  --text-secondary: #8b95b3;
  --muted: #5a6478;

  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-soft: rgba(59, 130, 246, 0.12);
  --primary-glow: rgba(59, 130, 246, 0.35);
  --secondary: #6366f1;
  --secondary-hover: #4f46e5;
  --secondary-soft: rgba(99, 102, 241, 0.12);
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --danger-soft: rgba(239, 68, 68, 0.12);
  --success: #10b981;
  --success-soft: rgba(16, 185, 129, 0.12);

  /* A 股红涨绿跌 */
  --up: #f23645;
  --up-bright: #ff4d5e;
  --up-soft: rgba(242, 54, 69, 0.12);
  --up-glow: rgba(242, 54, 69, 0.3);
  --down: #0ecb81;
  --down-bright: #2dd49a;
  --down-soft: rgba(14, 203, 129, 0.12);
  --down-glow: rgba(14, 203, 129, 0.3);
  --warn: #f59e0b;
  --warn-soft: rgba(245, 158, 11, 0.12);
  --gray: #64748b;
  --gray-soft: rgba(100, 116, 139, 0.12);

  --sidebar-bg: linear-gradient(180deg, #0d1320 0%, #0a0e17 100%);
  --sidebar-hover: rgba(59, 130, 246, 0.08);
  --sidebar-active-bg: rgba(59, 130, 246, 0.15);
  --sidebar-active-text: #60a5fa;
  --sidebar-text: #8b95b3;

  --gold: #fbbf24;

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 20px rgba(59, 130, 246, 0.15);

  --mono: "SF Mono", "Fira Code", "JetBrains Mono", "Cascadia Code", "Consolas", monospace;
}

* { 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-grad);
  background-attachment: fixed;
  color: var(--text);
  line-height: 1.6;
}

/* ── 背景网格装饰 ──────────────────────────────────── */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image:
    radial-gradient(circle at 20% 0%, rgba(59, 130, 246, 0.06) 0%, transparent 50%),
    radial-gradient(circle at 80% 100%, rgba(99, 102, 241, 0.05) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

/* ── 侧边栏 ────────────────────────────────────────── */
.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);
  backdrop-filter: blur(10px);
}

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

.brand::after {
  content: "";
  position: absolute;
  bottom: -1px;
  left: 24px;
  right: 24px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--primary-glow), transparent);
}

.brand-icon {
  width: 36px;
  height: 36px;
  color: var(--primary);
  flex-shrink: 0;
  filter: drop-shadow(0 0 8px var(--primary-glow));
  animation: pulse-glow 3s ease-in-out infinite;
}

@keyframes pulse-glow {
  0%, 100% { filter: drop-shadow(0 0 6px var(--primary-glow)); }
  50% { filter: drop-shadow(0 0 14px var(--primary-glow)); }
}

.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);
  letter-spacing: 0.05em;
}

.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;
  position: relative;
  transition: all 0.2s ease;
}

.side-item svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  transition: color 0.2s ease;
}

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

.side-item:hover svg {
  color: var(--primary);
}

.side-item.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-text);
  font-weight: 600;
}

.side-item.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 60%;
  background: var(--primary);
  border-radius: 0 3px 3px 0;
  box-shadow: 0 0 8px var(--primary-glow);
}

.side-item.active svg {
  color: var(--sidebar-active-text);
}

.sidebar-footer {
  padding: 18px 24px;
  font-size: 11px;
  color: var(--muted);
  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;
  position: relative;
  z-index: 1;
}

.topbar {
  height: var(--topbar-height);
  background: rgba(13, 19, 32, 0.85);
  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;
  backdrop-filter: blur(12px);
}

.page-title {
  font-size: 22px;
  font-weight: 800;
  margin: 0;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 12px;
}

.page-title::before {
  content: "";
  display: inline-block;
  width: 4px;
  height: 22px;
  background: var(--primary);
  border-radius: 2px;
  box-shadow: 0 0 10px var(--primary-glow);
}

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

/* 市场时钟 */
.market-clock {
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.market-clock .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--gray);
  transition: background 0.3s;
}

.market-clock .dot.open {
  background: var(--up);
  box-shadow: 0 0 8px var(--up-glow);
  animation: blink 2s ease-in-out infinite;
}

.market-clock .dot.closed {
  background: var(--muted);
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.version {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--surface-2);
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--border-light);
}

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

/* ── 页面副标题 ────────────────────────────────────── */
.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: border-color 0.2s ease, box-shadow 0.2s ease;
  position: relative;
  overflow: hidden;
}

.card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border-light), transparent);
}

.card:hover {
  border-color: var(--border-light);
  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;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-header h2::before,
.card h2::before {
  content: "";
  display: inline-block;
  width: 3px;
  height: 16px;
  background: var(--primary);
  border-radius: 2px;
}

.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: linear-gradient(135deg, var(--surface) 0%, var(--surface-2) 100%);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.metric:hover {
  transform: translateY(-2px);
  border-color: var(--border-light);
}

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

.metric::after {
  content: "";
  position: absolute;
  top: -50%;
  right: -20%;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--primary-soft) 0%, transparent 70%);
  opacity: 0.5;
  pointer-events: none;
}

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

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

.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;
  transition: all 0.15s ease;
  white-space: nowrap;
  position: relative;
  overflow: hidden;
}

button:hover, .btn:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px var(--primary-glow);
}

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

button:disabled, .btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
  filter: grayscale(0.5);
}

.btn-secondary {
  background: var(--surface-2);
  border-color: var(--border-light);
  color: var(--text);
}

.btn-secondary:hover {
  background: var(--surface-3);
  border-color: var(--secondary);
  color: var(--secondary);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.2);
}

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

.btn-danger:hover {
  background: var(--danger-hover);
  border-color: var(--danger-hover);
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

.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-2);
  color: var(--text);
  outline: none;
  transition: all 0.15s;
}

input::placeholder { color: var(--muted); }

input:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
  background: var(--surface-3);
}

input.short {
  width: 100px;
  font-family: var(--mono);
}
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.05em;
  color: var(--text-secondary);
  position: sticky;
  top: 0;
  z-index: 1;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(59, 130, 246, 0.04); }

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

td .up, td .down {
  font-family: var(--mono);
}

.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-light);
  color: var(--text-secondary);
}

.tag.up {
  background: var(--up-soft);
  border-color: rgba(242, 54, 69, 0.3);
  color: var(--up-bright);
}
.tag.down {
  background: var(--down-soft);
  border-color: rgba(14, 203, 129, 0.3);
  color: var(--down-bright);
}
.tag.warn {
  background: var(--warn-soft);
  border-color: rgba(245, 158, 11, 0.3);
  color: var(--warn);
}
.tag.gray {
  background: var(--gray-soft);
  border-color: rgba(100, 116, 139, 0.3);
  color: var(--gray);
}

/* ── 推荐卡片 ──────────────────────────────────────── */
.reco-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 14px;
  background: linear-gradient(135deg, var(--surface) 0%, var(--surface-2) 100%);
  box-shadow: var(--shadow);
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
}

.reco-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--primary), var(--secondary));
  opacity: 0.6;
}

.reco-card:hover {
  border-color: var(--border-light);
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

.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 .reason {
  color: var(--text-secondary);
}

.reco-card .risk {
  color: var(--up-bright);
  background: var(--up-soft);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--up);
}

/* ── 详情文本框 ────────────────────────────────────── */
.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);
  font-family: var(--mono);
}

/* 自定义滚动条 */
.detail-box::-webkit-scrollbar,
.side-nav::-webkit-scrollbar {
  width: 6px;
}
.detail-box::-webkit-scrollbar-track,
.side-nav::-webkit-scrollbar-track {
  background: transparent;
}
.detail-box::-webkit-scrollbar-thumb,
.side-nav::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: 3px;
}
.detail-box::-webkit-scrollbar-thumb:hover,
.side-nav::-webkit-scrollbar-thumb:hover {
  background: var(--muted);
}

/* ── 状态 / 提示 ───────────────────────────────────── */
.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 rgba(59, 130, 246, 0.3);
  color: #93c5fd;
  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.3);
  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(0, 0, 0, 0.6);
  z-index: 150;
  backdrop-filter: blur(4px);
}
.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,
  .topbar-right .market-clock { 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: repeat(2, 1fr); gap: 12px; }
  .metric { padding: 14px; }
  .metric .value { font-size: 22px; margin-top: 6px; }
  .metric .label { font-size: 12px; }

  .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; }
}
