/* 股市分析板块：个股关联 + 自选股同质化诊断
   配色/圆角沿用主站的 CSS 变量（--surface / --line / --accent 等），
   变量未定义时用回退值，保证单独打开也不难看。 */

.stock-panel {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  background: var(--bg, #f6f5f2);
  color: var(--text, #1b1b19);
  overflow: hidden;
}

.stock-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px 10px;
  border-bottom: 1px solid var(--line, #e2ded6);
  background: var(--surface, #fffdf9);
}

.stock-heading h2 {
  margin: 0;
  font-size: 19px;
  letter-spacing: .02em;
}

.stock-sub {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--muted, #7c7770);
}

.stock-tools { display: flex; gap: 8px; }

.stock-tabs {
  display: flex;
  gap: 6px;
  padding: 10px 18px 0;
  border-bottom: 1px solid var(--line, #e2ded6);
  background: var(--surface, #fffdf9);
}

.stock-tab {
  border: 0;
  background: transparent;
  padding: 8px 14px 10px;
  font-size: 14px;
  color: var(--muted, #7c7770);
  cursor: pointer;
  border-bottom: 2px solid transparent;
}

.stock-tab.active {
  color: var(--text, #1b1b19);
  font-weight: 600;
  border-bottom-color: var(--accent, #b4552d);
}

.stock-pane {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 18px 40px;
  -webkit-overflow-scrolling: touch;
}

.stock-search-wrap,
.watch-add {
  display: flex;
  gap: 8px;
  max-width: 720px;
}

.stock-search {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  font-size: 14px;
  border: 1px solid var(--line, #e2ded6);
  border-radius: 8px;
  background: var(--surface, #fff);
  color: inherit;
}

.stock-search:focus {
  outline: none;
  border-color: var(--accent, #b4552d);
}

.stock-suggest {
  max-width: 720px;
  margin-top: 6px;
  border: 1px solid var(--line, #e2ded6);
  border-radius: 8px;
  background: var(--surface, #fff);
  overflow: hidden;
  max-height: 320px;
  overflow-y: auto;
}

.stock-suggest-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 12px;
  border: 0;
  border-bottom: 1px solid var(--line-soft, #f0ece4);
  background: transparent;
  text-align: left;
  cursor: pointer;
  font-size: 13px;
  color: inherit;
}

.stock-suggest-item:last-child { border-bottom: 0; }
.stock-suggest-item:hover { background: var(--hover, #f7f2ea); }
.stock-suggest-code { font-variant-numeric: tabular-nums; color: var(--muted, #7c7770); min-width: 78px; }
.stock-suggest-name { font-weight: 600; }
.stock-suggest-ind { margin-left: auto; font-size: 12px; color: var(--muted, #7c7770); }

.stock-hint {
  max-width: 720px;
  margin-top: 22px;
  padding: 14px 16px;
  border: 1px dashed var(--line, #e2ded6);
  border-radius: 10px;
  color: var(--muted, #7c7770);
  font-size: 13px;
  line-height: 1.65;
}

.stock-note { margin-top: 8px; font-size: 12px; }

/* ---------- 个股详情 ---------- */

.stock-detail { max-width: 900px; }

.stock-card {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 16px 18px;
  border: 1px solid var(--line, #e2ded6);
  border-radius: 12px;
  background: var(--surface, #fffdf9);
}

.stock-card h3 { margin: 0; font-size: 20px; }
.stock-card .stock-code { font-variant-numeric: tabular-nums; color: var(--muted, #7c7770); font-size: 13px; }
.stock-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

.stock-tag {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  background: var(--chip, #f1ece3);
  color: var(--muted, #6c665e);
}

.stock-card-actions { display: flex; flex-direction: column; gap: 8px; flex: none; }

/* ---------- 自定义显示数量（TopK） ---------- */

.topk-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin: 10px 0 12px;
  padding: 9px 11px;
  border: 1px solid var(--line, #e2ded6);
  border-radius: 10px;
  background: var(--surface-soft, #fbf8f2);
}

.topk-label { font-size: 12px; color: var(--muted, #7c7770); }

.topk-chip {
  padding: 4px 11px;
  border: 1px solid var(--line, #e2ded6);
  border-radius: 999px;
  background: var(--surface, #fffdf9);
  color: var(--text-soft, #4a453e);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

.topk-chip:hover { border-color: var(--accent, #b4552d); color: var(--accent, #b4552d); }

.topk-chip.active {
  background: var(--accent, #b4552d);
  border-color: var(--accent, #b4552d);
  color: #fff;
  font-weight: 600;
}

.topk-input {
  width: 68px;
  padding: 4px 8px;
  border: 1px solid var(--line, #e2ded6);
  border-radius: 8px;
  background: var(--surface, #fffdf9);
  color: inherit;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.topk-input:focus { outline: 2px solid var(--accent, #b4552d); outline-offset: 1px; }

.topk-apply { padding: 4px 12px; font-size: 12px; }

.topk-note { margin-left: auto; font-size: 12px; color: var(--muted, #7c7770); }

/* 超过实际可显示数量的档位：置灰 + 禁止点击，避免"点了没变化"的困惑 */
.topk-chip.over {
  opacity: 0.42;
  border-style: dashed;
  cursor: not-allowed;
  color: var(--muted, #7c7770);
}

.topk-chip.over:hover {
  border-color: var(--line, #e2ded6);
  color: var(--muted, #7c7770);
}

.topk-capped {
  margin: 0 0 12px;
  padding: 7px 11px;
  border-left: 3px solid var(--accent, #b4552d);
  background: var(--surface-soft, #fbf8f2);
  border-radius: 0 8px 8px 0;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--text-soft, #4a453e);
}

.stock-section { margin-top: 22px; }

/* ---------- 达标计数说明 + 只看达标开关 ---------- */

.peer-counts {
  margin-bottom: 10px;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--muted, #7c7770);
}

.peer-counts b { color: var(--text-soft, #4a453e); }

.topk-filter {
  padding: 4px 11px;
  border: 1px dashed var(--line, #e2ded6);
  border-radius: 8px;
  background: var(--surface, #fffdf9);
  color: var(--muted, #7c7770);
  font-size: 12px;
  cursor: pointer;
}

.topk-filter:hover { border-color: var(--accent, #b4552d); color: var(--accent, #b4552d); }

.topk-filter.on {
  border-style: solid;
  border-color: var(--accent, #b4552d);
  background: var(--accent, #b4552d);
  color: #fff;
  font-weight: 600;
}

/* ---------- 未达标的关联股：标暗 ---------- */

.peer-row.sub,
.peer-ind.sub {
  opacity: 0.45;
}

.peer-row.sub:hover { opacity: 0.75; }
.peer-row.sub .peer-rho { color: var(--muted, #7c7770); font-weight: 400; }
.peer-row.sub .rho-bar > i { background: var(--muted, #b9b3aa); }

.peer-subtag {
  margin-left: 6px;
  padding: 1px 6px;
  border: 1px solid var(--line, #e2ded6);
  border-radius: 999px;
  font-size: 11px;
  color: var(--muted, #7c7770);
}

/* ---------- 与大盘的关联度 ---------- */

.mkt-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.mkt-cell {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 12px 14px;
  border: 1px solid var(--line, #e2ded6);
  border-radius: 10px;
  background: var(--surface, #fffdf9);
}

.mkt-label { font-size: 12px; color: var(--muted, #7c7770); }
.mkt-value { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.mkt-sub { font-size: 11.5px; color: var(--muted, #7c7770); }

.mkt-note {
  margin-top: 10px;
  font-size: 12.5px;
  line-height: 1.7;
  color: var(--text-soft, #4a453e);
}

.mkt-details { margin-top: 8px; }
.mkt-details summary { cursor: pointer; font-size: 12px; color: var(--accent, #b4552d); }
.mkt-details p {
  margin: 7px 0 0;
  padding: 9px 11px;
  border-left: 3px solid var(--line, #e2ded6);
  background: var(--surface-soft, #fbf8f2);
  border-radius: 0 8px 8px 0;
  font-size: 12.5px;
  line-height: 1.7;
}

.stock-section > h4 {
  margin: 0 0 10px;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.stock-section > h4 .stock-section-hint {
  font-size: 12px;
  font-weight: 400;
  color: var(--muted, #7c7770);
}

.stock-muted {
  color: var(--muted, #7c7770);
  font-size: 12px;
}

.peer-list { display: flex; flex-direction: column; gap: 8px; }

.peer-row {
  display: grid;
  grid-template-columns: 88px 1fr 96px 74px;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line, #e2ded6);
  border-radius: 9px;
  background: var(--surface, #fff);
  font-size: 13px;
}

.peer-row:hover { background: var(--hover, #faf7f1); }
.peer-code { font-variant-numeric: tabular-nums; color: var(--muted, #7c7770); }
.peer-name { font-weight: 600; }
.peer-ind { color: var(--muted, #7c7770); font-size: 12px; }
.peer-rho { font-variant-numeric: tabular-nums; font-weight: 600; text-align: right; }

.rho-bar {
  height: 6px;
  border-radius: 3px;
  background: var(--line-soft, #eee9e0);
  overflow: hidden;
}

.rho-bar > i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #d8a24a, #b4552d);
}

/* ---------- 业务关系 ---------- */

.rel-list { display: flex; flex-direction: column; gap: 10px; margin-top: 4px; }

.rel-row {
  padding: 12px 14px;
  border: 1px solid var(--line, #e2ded6);
  border-left-width: 3px;
  border-radius: 9px;
  background: var(--surface, #fff);
}

.rel-row.rel-upstream_downstream { border-left-color: #b4552d; }
.rel-row.rel-same_controller   { border-left-color: #8a5cd6; }
.rel-row.rel-same_chain        { border-left-color: #d8a24a; }
.rel-row.rel-competitor        { border-left-color: #3d7bbf; }
.rel-row.rel-same_theme        { border-left-color: #6fa87a; }
.rel-row.rel-none,
.rel-row.rel-unknown           { border-left-color: #cfc9bf; }

.rel-head {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-wrap: wrap;
  font-size: 13px;
}

.rel-name { font-weight: 600; }
.rel-code { color: var(--muted, #7c7770); font-variant-numeric: tabular-nums; }

.rel-badge {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: var(--chip, #f1ece3);
}

.rel-badge.b-upstream_downstream { background: #fbe6dc; color: #9c3f1c; }
.rel-badge.b-same_controller     { background: #eee2fb; color: #6a3fae; }
.rel-badge.b-same_chain          { background: #faf0d8; color: #8c6414; }
.rel-badge.b-competitor          { background: #e2eefb; color: #2f5f96; }
.rel-badge.b-same_theme          { background: #e6f3e8; color: #3f7a4c; }
.rel-badge.b-none,
.rel-badge.b-unknown             { background: #f0eee9; color: #77716a; }

.rel-reason {
  margin: 7px 0 0;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-soft, #4a453e);
}

.rel-meta {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted, #8b857c);
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.stock-loading {
  padding: 16px;
  color: var(--muted, #7c7770);
  font-size: 13px;
}

.stock-loading::after {
  content: "";
  display: inline-block;
  width: 8px;
  animation: stock-dots 1.2s steps(4, end) infinite;
}

@keyframes stock-dots {
  0%   { content: ""; }
  25%  { content: "."; }
  50%  { content: ".."; }
  75%  { content: "..."; }
}

/* ---------- 自选股 ---------- */

.watch-head { position: relative; }
.watch-list { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; max-width: 720px; }

.watch-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line, #e2ded6);
  border-radius: 9px;
  background: var(--surface, #fff);
  font-size: 13px;
}

.watch-item .peer-name { flex: 1; }

.watch-empty {
  max-width: 720px;
  padding: 20px;
  border: 1px dashed var(--line, #e2ded6);
  border-radius: 10px;
  color: var(--muted, #7c7770);
  font-size: 13px;
  text-align: center;
}

.watch-actions { margin-top: 16px; }

.watch-analyze {
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  border: 0;
  border-radius: 8px;
  background: var(--accent, #b4552d);
  color: #fff;
  cursor: pointer;
}

.watch-analyze:disabled { opacity: .55; cursor: not-allowed; }

.watch-result { margin-top: 20px; }

.score-box {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 16px 18px;
  border: 1px solid var(--line, #e2ded6);
  border-radius: 12px;
  background: var(--surface, #fffdf9);
  max-width: 720px;
}

.score-ring {
  flex: 0 0 auto;
  width: 76px;
  height: 76px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 22px;
  font-weight: 700;
  color: #fff;
  background: conic-gradient(#b4552d calc(var(--p) * 1%), #eee9e0 0);
  position: relative;
}

.score-ring > span {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--surface, #fffdf9);
  color: var(--text, #1b1b19);
  display: grid;
  place-items: center;
  font-size: 19px;
}

.score-notes { font-size: 13px; line-height: 1.75; }
.score-notes b { color: var(--accent, #b4552d); }

.sector-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
  font-size: 13px;
}

.sector-name { min-width: 110px; }
.sector-bar { flex: 1; height: 8px; border-radius: 4px; background: var(--line-soft, #eee9e0); overflow: hidden; }
.sector-bar > i { display: block; height: 100%; background: #b4552d; }
.sector-ratio { min-width: 48px; text-align: right; font-variant-numeric: tabular-nums; color: var(--muted, #7c7770); }

.pair-row {
  display: grid;
  grid-template-columns: 1fr 78px 1fr;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line, #e2ded6);
  border-radius: 9px;
  background: var(--surface, #fff);
  font-size: 13px;
  margin-bottom: 8px;
}

.pair-rho-cell { text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.pair-row.warn { border-left: 3px solid #b4552d; }

.stock-warn {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 9px;
  background: #fdf3e8;
  border: 1px solid #f0dcc4;
  font-size: 13px;
  line-height: 1.7;
}

/* ---------- 两只股票对比 ---------- */

.pair-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px;
  padding: 14px 16px;
  border: 1px solid var(--line, #e2ded6);
  border-radius: 12px;
  background: var(--surface, #fffdf9);
}

.pair-field { position: relative; flex: 1 1 220px; min-width: 180px; }
.pair-field label { display: block; margin-bottom: 5px; font-size: 12px; color: var(--muted, #7c7770); }
.pair-field .stock-search { width: 100%; }
/* 联想框挂在输入框下方 */
.pair-field .stock-suggest { position: absolute; z-index: 20; width: 100%; }

.pair-result:empty { display: none; }

.pair-head {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 18px;
  padding: 16px 18px;
  border: 1px solid var(--line, #e2ded6);
  border-radius: 12px;
  background: var(--surface, #fffdf9);
  text-align: center;
}

.pair-stock { flex: 1; min-width: 0; }
.pair-stock h3 { margin: 0; font-size: 18px; }
.pair-stock .stock-code { font-variant-numeric: tabular-nums; color: var(--muted, #7c7770); font-size: 13px; }
.pair-stock .stock-tags { justify-content: center; }
.pair-vs { flex: none; font-size: 22px; color: var(--accent, #b4552d); }

.pair-rho { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.pair-rho-num {
  font-size: 30px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.pair-rho-none {
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--chip, #f1ece3);
  color: var(--muted, #6c665e);
  font-size: 13px;
}

.pair-rho-bar {
  flex: 1 1 120px;
  max-width: 260px;
  height: 8px;
  border-radius: 999px;
  background: var(--chip, #f1ece3);
  overflow: hidden;
}

.pair-rho-bar > i { display: block; height: 100%; border-radius: 999px; background: var(--accent, #b4552d); }
.pair-rho-tag { font-size: 12px; color: var(--muted, #7c7770); }
.pair-rho-note { margin: 10px 0 0; font-size: 13px; line-height: 1.65; color: var(--text-soft, #4a453e); }

/* 市场分位：把裸 ρ 变成可读的"强于全市场多少股票对" */
.pair-pct {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  padding: 9px 12px;
  border-radius: 10px;
  background: var(--surface-soft, #fbf8f2);
}

.pair-pct-num { font-size: 15px; font-weight: 700; color: var(--accent, #b4552d); }
.pair-pct-label { font-size: 12px; color: var(--muted, #7c7770); }

.pair-pct-track {
  flex: 1 1 100px;
  height: 6px;
  border-radius: 999px;
  background: var(--chip, #f1ece3);
  overflow: hidden;
}

.pair-pct-track > i {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--accent, #b4552d);
}

.pair-verdict { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.pair-reason { margin: 10px 0 0; font-size: 14px; font-weight: 600; line-height: 1.6; }

.pair-detail-block {
  margin-top: 12px;
  padding: 10px 13px;
  border-left: 3px solid var(--line, #e2ded6);
  background: var(--surface-soft, #fbf8f2);
  border-radius: 0 8px 8px 0;
}

.pair-detail-label { display: block; margin-bottom: 4px; font-size: 12px; color: var(--muted, #7c7770); }
.pair-detail-block p { margin: 0; font-size: 13px; line-height: 1.7; color: var(--text-soft, #4a453e); }

.pair-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
  padding-top: 12px;
  border-top: 1px solid var(--line, #e2ded6);
}

/* 同行业（两只对比才有的关系类型） */
.rel-badge.b-same_industry { background: #e2eefb; color: #2f5f96; }

/* ---------- 移动端 ---------- */

@media (max-width: 720px) {
  .stock-header, .stock-tabs { padding-left: 12px; padding-right: 12px; }
  .stock-pane { padding: 12px 12px 32px; }
  .peer-row {
    grid-template-columns: 74px 1fr 66px;
    row-gap: 4px;
  }
  .peer-ind { grid-column: 1 / -1; }
  .rho-bar { display: none; }
  .pair-row { grid-template-columns: 1fr; gap: 4px; }
  .pair-rho-cell { text-align: left; }
  .score-box { flex-direction: column; align-items: flex-start; gap: 12px; }
  .topk-note { margin-left: 0; flex-basis: 100%; }
  .pair-head { flex-direction: column; gap: 8px; }
  .pair-vs { transform: rotate(90deg); }
  .pair-form { align-items: stretch; }
  .pair-field { flex-basis: 100%; }
  .mkt-grid { grid-template-columns: 1fr; }
  .mkt-value { font-size: 20px; }
}
