/* ============================================================
   量化因子选股 · 暗色金融主题
   深蓝黑底 + A股配色（涨 #f0334a 跌 #09b96d）+ 金色点缀
   ============================================================ */
:root {
  --bg:        #0b1220;   /* 深蓝黑底 */
  --bg-grad:   radial-gradient(1200px 600px at 80% -10%, #13243f 0%, #0b1220 55%, #080e18 100%);
  --panel:     #0f1a2e;   /* 卡片/面板 */
  --panel-2:   #122138;   /* 次级面板 */
  --line:      #1e2c44;   /* 分隔线/边框 */
  --line-soft: #16223a;
  --text:      #e7eefb;   /* 主文字 */
  --sub:       #8a99b5;   /* 次要文字 */
  --sub-2:     #5f6f8c;   /* 更弱 */
  --red:       #f0334a;   /* 涨（A股红涨） */
  --red-soft:  rgba(240,51,74,.14);
  --green:     #09b96d;   /* 跌（A股绿跌） */
  --green-soft:rgba(9,185,109,.14);
  --gold:      #e7b94a;   /* 金色点缀 */
  --accent:    #4f8cff;   /* 交互蓝 */
  --accent-2:  #2bd6c4;   /* 青绿强调 */
  --shadow:    0 8px 30px rgba(0,0,0,.45);
  --radius:    14px;
  --radius-sm: 9px;
}

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

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

/* ---------- 顶部导航 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 18px;
  height: 56px;
  padding: 0 22px;
  background: rgba(11,18,32,.82);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar .brand {
  display: flex; align-items: center; gap: 9px;
  font-size: 16px; font-weight: 700; letter-spacing: .5px;
  color: var(--text); white-space: nowrap;
}
.topbar .brand .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: linear-gradient(135deg, var(--gold), #f6d98a);
  box-shadow: 0 0 10px rgba(231,185,74,.7);
}
.topbar .brand small { color: var(--sub); font-weight: 500; font-size: 11px; letter-spacing: 1px; }
.topbar nav { display: flex; gap: 4px; flex: 1; }
.topbar nav a {
  color: var(--sub);
  padding: 7px 13px;
  border-radius: 8px;
  font-size: 13.5px;
  white-space: nowrap;
  border: 1px solid transparent;
}
.topbar nav a:hover { color: var(--text); background: var(--panel); text-decoration: none; }
.topbar nav a.active {
  color: var(--text);
  background: linear-gradient(180deg, rgba(79,140,255,.18), rgba(79,140,255,.06));
  border-color: rgba(79,140,255,.35);
}
.topbar .user {
  display: flex; align-items: center; gap: 12px;
  font-size: 13px; color: var(--sub); white-space: nowrap;
}
.topbar .user .uname { color: var(--text); }
.topbar .user .role-tag {
  font-size: 11px; color: var(--gold);
  border: 1px solid rgba(231,185,74,.4);
  padding: 1px 6px; border-radius: 6px;
}
.topbar .user a { color: var(--sub); }
.topbar .user a:hover { color: var(--text); }

/* ---------- 页面容器 ---------- */
.page { max-width: 1280px; margin: 0 auto; padding: 22px; }
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; margin-bottom: 18px; flex-wrap: wrap;
}
.page-head h1 { font-size: 21px; font-weight: 700; letter-spacing: .5px; }
.page-head .sub { color: var(--sub); font-size: 13px; margin-top: 4px; }
.page-head .meta { color: var(--sub); font-size: 12.5px; }

/* ---------- 卡片 ---------- */
.card {
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card .card-h {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--line-soft);
}
.card .card-h h2 { font-size: 15px; font-weight: 600; }
.card .card-h .hint { color: var(--sub); font-size: 12px; }
.card .card-b { padding: 16px 18px; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 13px; cursor: pointer;
  transition: .15s;
}
.btn:hover { border-color: var(--accent); color: #fff; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary {
  background: linear-gradient(180deg, #5a93ff, #3f72e6);
  border-color: #3f72e6; color: #fff;
}
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.gold {
  background: linear-gradient(180deg, #f0c463, #d9a531);
  border-color: #d9a531; color: #1a1305; font-weight: 600;
}
.btn.gold:hover { filter: brightness(1.06); }

/* ---------- 表格 ---------- */
.table-wrap { width: 100%; overflow-x: auto; }
table.grid {
  width: 100%; border-collapse: collapse; font-size: 13.5px;
  min-width: 880px;
}
table.grid th {
  text-align: left; color: var(--sub);
  font-weight: 500; font-size: 12px;
  padding: 11px 14px; border-bottom: 1px solid var(--line);
  white-space: nowrap; background: rgba(255,255,255,.015);
  position: sticky; top: 0;
}
table.grid td {
  padding: 12px 14px; border-bottom: 1px solid var(--line-soft);
  white-space: nowrap;
}
table.grid tbody tr { transition: background .12s; cursor: pointer; }
table.grid tbody tr:hover { background: rgba(79,140,255,.07); }
table.grid tbody tr:last-child td { border-bottom: none; }
.col-num { text-align: right; font-variant-numeric: tabular-nums; }
.rank-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 7px;
  background: var(--panel-2); border: 1px solid var(--line);
  font-size: 12.5px; font-weight: 600; color: var(--sub);
}
.rank-badge.top1 { background: linear-gradient(135deg,#f0c463,#d9a531); color:#1a1305; border-color:#d9a531; }
.rank-badge.top2 { background: linear-gradient(135deg,#cfd8e6,#9fb0c6); color:#10151f; border-color:#9fb0c6; }
.rank-badge.top3 { background: linear-gradient(135deg,#e0a06a,#c07e44); color:#1a0f05; border-color:#c07e44; }
.code-cell { font-family: "SFMono-Regular", Consolas, monospace; color: var(--sub); font-size: 12.5px; }
.name-cell { font-weight: 600; color: var(--text); }
.score-cell { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--gold); }

/* 涨跌颜色（A股：红涨绿跌） */
.up   { color: var(--red); }
.down { color: var(--green); }
.flat { color: var(--sub); }

/* 方向标签 */
.tag {
  display: inline-block; padding: 2px 9px; border-radius: 20px;
  font-size: 12px; border: 1px solid var(--line); color: var(--sub);
}
.tag.long  { color: var(--red);   background: var(--red-soft);   border-color: rgba(240,51,74,.35); }
.tag.short { color: var(--green); background: var(--green-soft); border-color: rgba(9,185,109,.35); }
.tag.neutral { color: var(--sub); background: rgba(138,153,181,.1); }

/* 自选星标按钮 */
.wl-btn {
  background: transparent; border: 1px solid var(--line);
  color: var(--sub); border-radius: 8px; padding: 4px 10px;
  font-size: 12px; cursor: pointer; white-space: nowrap;
  transition: .15s;
}
.wl-btn:hover { border-color: var(--gold); color: var(--gold); }
.wl-btn.on { color: var(--gold); border-color: rgba(231,185,74,.5); background: rgba(231,185,74,.1); }
.wl-btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- 状态：加载 / 空 / 错误 ---------- */
.state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; padding: 56px 20px; color: var(--sub); text-align: center;
}
.state .ico { font-size: 30px; opacity: .8; }
.state .msg { font-size: 14px; }
.state .sub { font-size: 12.5px; color: var(--sub-2); }
.spinner {
  width: 30px; height: 30px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton {
  height: 14px; border-radius: 6px;
  background: linear-gradient(90deg, #15223a 25%, #1d2f4d 37%, #15223a 63%);
  background-size: 400% 100%; animation: sk 1.3s ease infinite;
}
@keyframes sk { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }

/* ---------- 网格布局 ---------- */
.grid-cards {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
}
.kpi {
  display: flex; flex-direction: column; gap: 6px;
  padding: 14px 16px;
}
.kpi .k-label { color: var(--sub); font-size: 12px; }
.kpi .k-val { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .k-sub { color: var(--sub-2); font-size: 11.5px; }

/* 因子监控维度卡 */
.dim-card { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.dim-card .dim-top { display: flex; align-items: center; justify-content: space-between; }
.dim-card .dim-name { font-size: 15px; font-weight: 700; }
.dim-card .dim-dir { font-size: 11px; padding: 2px 8px; border-radius: 20px; border: 1px solid var(--line); color: var(--sub); }
.dim-card .dim-dir.pos { color: var(--red); border-color: rgba(240,51,74,.4); }
.dim-card .dim-dir.neg { color: var(--green); border-color: rgba(9,185,109,.4); }
.dim-rows { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; }
.dim-rows .r { display: flex; justify-content: space-between; font-size: 12.5px; }
.dim-rows .r .l { color: var(--sub); }
.dim-rows .r .v { font-weight: 600; font-variant-numeric: tabular-nums; }
.dim-top-names { font-size: 11.5px; color: var(--sub); border-top: 1px dashed var(--line-soft); padding-top: 10px; }
.dim-top-names b { color: var(--text); font-weight: 600; }

/* 市场状态 */
.market-state { display: flex; gap: 14px; flex-wrap: wrap; }
.market-state .ms { flex: 1; min-width: 150px; padding: 14px 16px; }
.ms .ms-label { color: var(--sub); font-size: 12px; margin-bottom: 6px; }
.ms .ms-val { font-size: 18px; font-weight: 700; }

/* 图表容器 */
.chart { width: 100%; }
.chart.bars  { height: 320px; }
.chart.kline { height: 420px; }
.chart.flow  { height: 240px; }
.chart.macd  { height: 260px; }
.chart.kdj   { height: 260px; }
.chart.radar { height: 340px; }
.chart.pchart { height: 280px; }   /* 因子监控·组合回测图 */

/* ---------- 个股详情 ---------- */
.stock-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.stock-title h1 { font-size: 24px; font-weight: 700; }
.stock-title .code { color: var(--sub); font-family: Consolas, monospace; font-size: 13px; margin-left: 8px; }
.stock-title .ind { color: var(--sub); font-size: 13px; margin-top: 4px; }
.info-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-top: 14px; }
.info-item { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 14px; }
.info-item .l { color: var(--sub); font-size: 12px; }
.info-item .v { font-size: 18px; font-weight: 700; margin-top: 3px; font-variant-numeric: tabular-nums; }

/* 雷达弹层 */
.modal-mask {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(4,8,15,.6); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal {
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--line); border-radius: var(--radius);
  width: min(520px, 96vw); box-shadow: var(--shadow); overflow: hidden;
}
.modal .m-h {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
}
.modal .m-h h3 { font-size: 15px; font-weight: 600; }
.modal .m-h .x { cursor: pointer; color: var(--sub); font-size: 18px; line-height: 1; border: none; background: none; }
.modal .m-b { padding: 12px 14px 18px; }
.modal .m-chart { height: 320px; width: 100%; }

/* 用户管理弹层 */
.um-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.um-table th { text-align: left; color: var(--sub); font-weight: 500; font-size: 12px; padding: 8px; border-bottom: 1px solid var(--line); }
.um-table td { padding: 8px; border-bottom: 1px solid var(--line-soft); }
.um-input {
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px;
  font-size: 13px; background: var(--panel-2); color: var(--text); outline: none;
}
.um-input:focus { border-color: var(--accent); }

/* 表单/筛选 */
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; color: var(--sub); }
input[type="date"], input[type="text"], input[type="password"], select {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 11px; color: var(--text); font-size: 13px; outline: none;
}
input:focus, select:focus { border-color: var(--accent); }
.row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }

/* 迷你走势图 */
.spark { display: block; }

/* 提示条 */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  padding: 10px 18px; border-radius: 10px; font-size: 13px; box-shadow: var(--shadow);
  z-index: 200; opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }
.toast.err { border-color: rgba(240,51,74,.5); }
.toast.ok  { border-color: rgba(9,185,109,.5); }

/* 登录页 */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card {
  width: min(390px, 94vw);
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--line); border-radius: 16px; padding: 34px 32px;
  box-shadow: var(--shadow);
}
.login-card .logo { display: flex; align-items: center; gap: 9px; justify-content: center; margin-bottom: 6px; }
.login-card .logo .dot { width: 11px; height: 11px; border-radius: 50%; background: linear-gradient(135deg, var(--gold), #f6d98a); box-shadow: 0 0 12px rgba(231,185,74,.7); }
.login-card h1 { text-align: center; font-size: 19px; font-weight: 700; }
.login-card .sub { text-align: center; color: var(--sub); font-size: 12.5px; margin: 6px 0 24px; }
.login-card .fld { margin-bottom: 14px; }
.login-card .fld label { display: block; font-size: 12px; color: var(--sub); margin-bottom: 6px; }
.login-card .fld input {
  width: 100%; background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 11px 13px; font-size: 14px; color: var(--text); outline: none;
}
.login-card .fld input:focus { border-color: var(--accent); }
.login-card button.submit {
  width: 100%; margin-top: 8px; border: none; border-radius: 10px; padding: 12px;
  font-size: 14px; font-weight: 600; cursor: pointer; color: #fff;
  background: linear-gradient(180deg, #5a93ff, #3f72e6);
}
.login-card button.submit:hover { filter: brightness(1.08); }
.login-card button.submit:disabled { opacity: .6; cursor: not-allowed; }
.login-card .err { color: var(--red); font-size: 12.5px; min-height: 18px; margin-top: 10px; text-align: center; }
.login-card .foot { text-align: center; color: var(--sub-2); font-size: 11px; margin-top: 18px; line-height: 1.8; }

/* ---------- 响应式 ---------- */
@media (max-width: 1099px) {
  .page { padding: 16px; }
  .page-head h1 { font-size: 19px; }
}

/* 平板/手机：表格横滑兜底 + 隐藏次要列 + 触控友好 + 图表收紧 */
@media (max-width: 760px) {
  .topbar { gap: 10px; padding: 0 12px; flex-wrap: wrap; height: auto; padding-top: 8px; padding-bottom: 8px; }
  /* 导航独立成行并允许换行：5 个链接在窄屏全部可见，无需横向滑动；
     overflow-x 仅作超窄屏（<320px）兜底 */
  .topbar nav { order: 3; width: 100%; flex-wrap: wrap; gap: 2px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .topbar nav a { padding: 6px 9px; font-size: 12.5px; }
  .topbar .user { font-size: 12px; gap: 8px; margin-left: auto; }
  .dim-rows { grid-template-columns: 1fr 1fr; }
  .info-row { grid-template-columns: 1fr 1fr; }

  /* 卡片与页面收紧 */
  .page { padding: 12px; }
  .card .card-h { padding: 12px 14px; }
  .card .card-b { padding: 12px 14px; }
  .state { padding: 40px 14px; }

  /* 触控目标放大（wl-btn 默认偏小） */
  .wl-btn { padding: 7px 12px; font-size: 12.5px; }
  .btn { padding: 9px 15px; }

  /* 表格：缩字号/内距；选股榜( picks-grid )隐藏"成交额"列(第5列)；
     watchlist( wl-grid )隐藏"走势迷你图"列(第8列)；横滑兜底保留 */
  table.grid { min-width: 720px; font-size: 12.5px; }
  table.grid th, table.grid td { padding: 9px 10px; }
  .table-wrap { -webkit-overflow-scrolling: touch; }
  .picks-grid th:nth-child(5), .picks-grid td:nth-child(5) { display: none; }
  .wl-grid th:nth-child(8), .wl-grid td:nth-child(8) { display: none; }

  /* 图表高度收紧 */
  .chart.kline { height: 320px; }
  .chart.macd, .chart.kdj { height: 220px; }
  .chart.radar { height: 300px; }
  .chart.pchart { height: 220px; }
  .chart.flow { height: 200px; }
  .chart.bars { height: 260px; }
}

/* 手机竖屏：进一步压缩 */
@media (max-width: 480px) {
  .topbar { padding: 0 10px; }
  .topbar .brand { font-size: 15px; }
  .topbar .brand small { display: none; }   /* "QUANT FACTOR" 小字让位 */
  .topbar nav a { padding: 6px 8px; font-size: 12.5px; }
  .topbar .user .role-tag { display: none; }   /* "管理员"标签让位，username 已表明身份 */
  .topbar .user { gap: 6px; }
  .topbar .user .uname { max-width: 88px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .page-head h1 { font-size: 17px; }
  .page-head .sub { font-size: 12px; }
  .stock-title h1 { font-size: 19px; }
  .chart.kline { height: 280px; }
  .chart.macd, .chart.kdj { height: 200px; }
  .chart.radar { height: 260px; }
  .chart.pchart { height: 200px; }
  .kpi .k-val { font-size: 18px; }
  .info-item .v { font-size: 16px; }
  .market-state .ms { min-width: 0; }
  .dim-rows { grid-template-columns: 1fr; }
  .metric .val { font-size: 18px; }
}
