/* ============================================================
 *  style.css —— 持仓分析页样式
 *  浅色专业金融风；A 股配色：涨红跌绿
 * ============================================================ */

:root {
  /* 中性色 */
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --border: #e6e8ec;
  --border-strong: #d5d9e0;

  /* 文字 */
  --text: #14181f;
  --text-2: #5a6270;
  --text-3: #8b93a1;

  /* A 股涨跌：涨红跌绿 */
  --up: #d93a2b;
  --up-bg: #fdf1ef;
  --down: #12855a;
  --down-bg: #eef8f3;
  --flat: #7a828f;

  /* 品牌色 */
  --brand: #1f4fd8;
  --brand-soft: #eef2fd;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(20, 24, 31, .04), 0 4px 16px rgba(20, 24, 31, .04);
  --shadow-lg: 0 2px 6px rgba(20, 24, 31, .05), 0 12px 32px rgba(20, 24, 31, .07);

  --mono: "SF Mono", "JetBrains Mono", Consolas, "Liberation Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
          "Hiragino Sans GB", "Microsoft YaHei", "Source Han Sans SC", sans-serif;
}

/* ---------- 基础重置 ---------- */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.6;
  /* 移动端用 dvh，避免 iOS 地址栏导致的跳动 */
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

/* 数字统一用等宽 + 表格数字，保证列对齐 */
.num {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  letter-spacing: -.01em;
}

.up   { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--flat); }

/* ---------- 布局骨架 ---------- */
.wrap {
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 20px 64px;
}

/* ---------- 页头 ---------- */
.page-head {
  padding: 36px 0 24px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 24px;
  flex-wrap: wrap;
}

.page-head h1 {
  margin: 0 0 4px;
  font-size: 26px;
  font-weight: 650;
  letter-spacing: -.02em;
}

.page-head .sub {
  margin: 0;
  color: var(--text-2);
  font-size: 13.5px;
}

.head-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: 100px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--text-2);
  white-space: nowrap;
}

.pill .dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--brand);
}

.pill--live .dot {
  background: var(--up);
  box-shadow: 0 0 0 3px var(--up-bg);
}

/* ---------- 顶部关键指标 ---------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 22px;
}

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

.kpi__label {
  font-size: 12.5px;
  color: var(--text-3);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.kpi__value {
  font-size: 25px;
  font-weight: 620;
  letter-spacing: -.02em;
  line-height: 1.2;
}

.kpi__foot {
  margin-top: 7px;
  font-size: 12.5px;
  color: var(--text-3);
  display: flex;
  align-items: center;
  gap: 6px;
}

/* 主指标加一条品牌色左饰条 */
.kpi--primary::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--brand);
}

/* ---------- 卡片 ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  overflow: hidden;
}

.card__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 17px 22px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.card__title {
  margin: 0;
  font-size: 15px;
  font-weight: 620;
  letter-spacing: -.01em;
}

.card__hint {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--text-3);
}

.card__body { padding: 22px; }
.card__body--flush { padding: 0; }

/* ---------- 图表区 ---------- */
.charts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 20px;
}

.chart-card .card__body {
  display: flex;
  align-items: center;
  gap: 22px;
  flex-wrap: wrap;
}

.donut-wrap {
  position: relative;
  flex-shrink: 0;
}

.donut-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  text-align: center;
}

.donut-center .dc-label {
  font-size: 11.5px;
  color: var(--text-3);
  line-height: 1.2;
}

.donut-center .dc-value {
  font-size: 17px;
  font-weight: 640;
  letter-spacing: -.02em;
  margin-top: 2px;
}

.donut-center .dc-sub {
  font-size: 11px;
  color: var(--text-3);
  margin-top: 1px;
}

/* 图例 */
.legend {
  flex: 1;
  min-width: 160px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.legend__item {
  display: grid;
  grid-template-columns: 9px 1fr auto auto;
  align-items: center;
  gap: 9px;
  font-size: 13px;
}

.legend__swatch {
  width: 9px; height: 9px;
  border-radius: 3px;
}

.legend__name {
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.legend__val {
  color: var(--text-2);
  font-size: 12.5px;
}

.legend__pct {
  color: var(--text-3);
  font-size: 12px;
  min-width: 44px;
  text-align: right;
}

/* ---------- 表格 ---------- */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table.holdings {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  min-width: 900px;
}

table.holdings thead th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  padding: 11px 14px;
  text-align: right;
  font-weight: 550;
  font-size: 12px;
  color: var(--text-3);
  white-space: nowrap;
  letter-spacing: .02em;
  z-index: 1;
}

table.holdings thead th:first-child,
table.holdings tbody td:first-child { text-align: left; padding-left: 22px; }

table.holdings thead th:last-child,
table.holdings tbody td:last-child { padding-right: 22px; }

table.holdings tbody td {
  padding: 13px 14px;
  text-align: right;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

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

table.holdings tbody tr {
  transition: background-color .12s ease;
}

table.holdings tbody tr:hover {
  background: var(--surface-2);
}

/* 表头排序按钮 */
.th-sort {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border-radius: 4px;
}

.th-sort:hover { color: var(--text); }

.th-sort:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 3px;
}

.th-sort .arrow {
  font-size: 9px;
  opacity: .35;
  transition: opacity .12s ease;
}

.th-sort[data-active="true"] { color: var(--brand); }
.th-sort[data-active="true"] .arrow { opacity: 1; }

/* 股票名称单元格 */
.stock-name {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.stock-name .nm {
  font-weight: 550;
  color: var(--text);
  font-size: 13.5px;
}

.stock-name .cd {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-3);
  letter-spacing: .02em;
}

/* 板块标签 */
.sector-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 5px;
  background: var(--brand-soft);
  color: #2748b0;
  font-size: 11.5px;
  font-weight: 500;
  white-space: nowrap;
}

/* 现金类标签与现金行 */
.sector-tag--cash {
  background: #eef0f4;
  color: #5f6a7d;
}

tr.row-cash td {
  background: #fbfcfd;
  color: var(--text-2);
}

tr.row-cash .nm { color: var(--text-2); }

.bar-cash { background: #9aa4b5 !important; opacity: .9 !important; }

/* 占比条 */
.weight-cell {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.weight-bar {
  width: 52px;
  height: 4px;
  border-radius: 2px;
  background: #eceef2;
  overflow: hidden;
  flex-shrink: 0;
}

.weight-bar > i {
  display: block;
  height: 100%;
  border-radius: 2px;
  background: var(--brand);
  opacity: .75;
}

/* 盈亏值等宽列 */
.neg { color: var(--down); }
.pos { color: var(--up); }

/* 涨跌箭头 */
.arrow-ind {
  font-size: 9px;
  margin-right: 2px;
  vertical-align: 1px;
}

/* 汇总行 */
tr.total-row td {
  background: var(--surface-2);
  font-weight: 600;
  border-top: 1px solid var(--border-strong);
  border-bottom: none !important;
  padding-top: 14px;
  padding-bottom: 14px;
}

/* ---------- 集中度条 ---------- */
.conc-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.conc-item__top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 7px;
  font-size: 13px;
}

.conc-item__top .lbl { color: var(--text-2); }
.conc-item__top .v { font-weight: 600; }

.conc-track {
  height: 7px;
  border-radius: 4px;
  background: #eceef2;
  overflow: hidden;
  display: flex;
}

.conc-fill {
  height: 100%;
  border-radius: 4px;
  background: var(--brand);
  transition: width .5s cubic-bezier(.4, 0, .2, 1);
}

.conc-fill--warn { background: #e08a2e; }
.conc-fill--risk { background: var(--up); }

.conc-note {
  margin: 4px 0 0;
  font-size: 12.5px;
  color: var(--text-3);
  line-height: 1.55;
}

/* ---------- 空状态 ---------- */
.empty {
  padding: 60px 20px;
  text-align: center;
  color: var(--text-3);
}

.empty h3 {
  margin: 0 0 6px;
  font-size: 15px;
  color: var(--text-2);
  font-weight: 550;
}

.empty p { margin: 0; font-size: 13px; }

.empty code {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--brand);
}

/* ---------- 页脚 ---------- */
.page-foot {
  margin-top: 32px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-3);
  line-height: 1.7;
}

.page-foot p { margin: 0 0 6px; }

/* ---------- 窄屏适配 ---------- */
@media (max-width: 1080px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .charts { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .wrap { padding: 0 14px 48px; }
  .page-head { padding: 24px 0 18px; }
  .page-head h1 { font-size: 21px; }
  .kpi-grid { grid-template-columns: 1fr; gap: 10px; }
  .kpi { padding: 15px 17px; }
  .kpi__value { font-size: 22px; }
  .card__head { padding: 14px 17px; }
  .card__body { padding: 17px; }
  .chart-card .card__body { justify-content: center; gap: 18px; }
  .legend { min-width: 100%; }
  .foot-meta { margin-top: 14px; }
}

/* ---------- 打印 / 导出 PDF ---------- */
@media print {
  body { background: #fff; }
  .card, .kpi { box-shadow: none; border-color: #ccc; break-inside: avoid; }
  .page-head { padding-top: 0; }
  .charts { grid-template-columns: 1fr 1fr; }
}

/* ---------- 尊重系统减弱动效偏好 ---------- */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}