:root {
  --ink: #1f2329;
  --muted: #6b7280;
  --line: #e3e8ee;
  --bg: #ffffff;
  --soft: #f4f6f9;
  --primary: #0f2b46;
  --accent: #1f6f5c;
  /* A 股习惯：红涨绿跌 */
  --up: #c62828;
  --down: #1b7f3a;
  --up-soft: #fdecec;
  --down-soft: #ecf6ef;
  --r1: #8a94a6;
  --r2: #2f6f9f;
  --r3: #b1700e;
  --r4: #c0392b;
  --r5: #7a3f9c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: saturate(150%) blur(8px);
  z-index: 10;
}

.brand { font-size: 17px; font-weight: 600; color: var(--primary); letter-spacing: 0.3px; }
.status { font-size: 12px; color: var(--muted); }

/* 顶部加载进度条：宽度对应已完成张数 */
.progress { height: 3px; background: var(--line); opacity: 0; transition: opacity 0.2s ease; }
.progress.on { opacity: 1; }
.progress-bar { height: 100%; width: 0; background: var(--accent); transition: width 0.35s ease; }
.progress-bar.indeterminate { width: 35%; animation: slide 1.1s ease-in-out infinite; }
@keyframes slide {
  0% { margin-left: -35%; }
  100% { margin-left: 100%; }
}

/* 骨架屏 */
.skel { padding: 6px 0; }
.skel span {
  display: block;
  height: 15px;
  border-radius: 6px;
  margin: 12px 0;
  background: linear-gradient(90deg, #eff2f5 25%, #e3e8ee 37%, #eff2f5 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
}
.skel span:nth-child(1) { width: 72%; }
.skel span:nth-child(2) { width: 50%; }
.skel span:nth-child(3) { width: 62%; }
.skel span:nth-child(4) { width: 44%; }
@keyframes shimmer {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}

main { padding: 14px 16px 8px; max-width: 860px; margin: 0 auto; }

/* 指标条：四格紧排，不再是三张占满屏的大卡 */
.kpis {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 14px;
}

.kpi {
  background: var(--bg);
  padding: 11px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.kpi .label { font-size: 11px; color: var(--muted); letter-spacing: 0.2px; }
.kpi strong { font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; }
.kpi .kpi-sub { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* 持仓分布：市值占比横条 */
.dist {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px 14px;
  margin-bottom: 14px;
  background: var(--bg);
}
.dist-head { font-size: 13px; font-weight: 600; color: var(--primary); margin-bottom: 10px; }
.dist-head .sub { font-weight: 400; color: var(--muted); font-size: 11px; margin-left: 6px; }

.bar-row { margin-bottom: 9px; }
.bar-top {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  margin-bottom: 4px;
  gap: 8px;
}
.bar-top .nm { color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-top .vl { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar-track { height: 6px; background: var(--soft); border-radius: 3px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 3px; }

/* 页签行：右侧塞"记一笔" */
.tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 12px;
}
.tab {
  border: none;
  background: none;
  padding: 10px 12px;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.tab-spacer { flex: 1; }

.btn-add {
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #fff;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 7px;
  cursor: pointer;
  margin-bottom: 6px;
}
.btn-add:hover { opacity: 0.9; }

.btn-ghost {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-size: 13px;
  padding: 7px 14px;
  border-radius: 7px;
  cursor: pointer;
}
.btn-primary {
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #fff;
  font-size: 13px;
  padding: 7px 14px;
  border-radius: 7px;
  cursor: pointer;
}

.panel { display: none; }
.panel.active { display: block; }

.search-row { margin-bottom: 10px; }
.search-row input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  background: var(--soft);
}
.search-row input:focus { border-color: var(--primary); background: #fff; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

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

th {
  background: var(--soft);
  color: var(--muted);
  font-weight: 500;
  position: sticky;
  top: 0;
  font-size: 12px;
}
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--primary); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:nth-child(even) { background: #fcfdfe; }

td.num { text-align: right; font-variant-numeric: tabular-nums; }
td .sub { font-size: 11px; color: var(--muted); font-weight: 400; }
td.name { white-space: normal; min-width: 104px; max-width: 150px; word-break: break-word; }

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

/* 单元格内的占比条 */
.mini-track { height: 4px; background: var(--soft); border-radius: 2px; margin-top: 5px; overflow: hidden; }
.mini-fill { height: 100%; background: var(--accent); border-radius: 2px; }

/* 风险档色标 */
.risk {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  line-height: 1.6;
  border: 1px solid transparent;
}
.risk.r1 { color: var(--r1); background: #f2f4f7; border-color: #dfe4ea; }
.risk.r2 { color: var(--r2); background: #eef4fa; border-color: #d5e3f0; }
.risk.r3 { color: var(--r3); background: #fdf4e3; border-color: #f3e2bf; }
.risk.r4 { color: var(--r4); background: #fdeceb; border-color: #f5d3cf; }
.risk.r5 { color: var(--r5); background: #f4ecf9; border-color: #e3d3ef; }
.risk.none { color: var(--muted); background: var(--soft); border-color: var(--line); }

.op-buy { color: var(--r2); font-weight: 500; }
.op-sell { color: var(--r3); font-weight: 500; }

.empty, .err {
  padding: 30px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}
.err { color: var(--up); }

.retry {
  margin-left: 6px;
  padding: 4px 12px;
  font-size: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--primary);
  cursor: pointer;
}

/* 流水小计条 */
.stat-line {
  display: flex;
  gap: 14px;
  font-size: 12px;
  color: var(--muted);
  padding: 8px 2px 10px;
  font-variant-numeric: tabular-nums;
}
.stat-line b { color: var(--ink); font-weight: 600; }

.foot {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 18px 16px 28px;
}

/* 记一笔弹层 */
/* 弹层开关用 class 控制：.modal 的 display 不能写 flex，否则会盖掉 [hidden] 导致关不掉 */
.modal {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(15, 27, 40, 0.42);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 20;
}

.modal.open { display: flex; }

[hidden] { display: none !important; }
.modal-card {
  background: #fff;
  width: 100%;
  max-width: 460px;
  border-radius: 14px 14px 0 0;
  padding: 14px 16px 18px;
  max-height: 88vh;
  overflow-y: auto;
}
@media (min-width: 560px) {
  .modal { align-items: center; }
  .modal-card { border-radius: 14px; }
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 15px;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 12px;
}
.modal-x {
  border: none;
  background: none;
  font-size: 20px;
  color: var(--muted);
  cursor: pointer;
  line-height: 1;
}

.form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.field select, .field input {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  font-size: 14px;
  color: var(--ink);
  background: #fff;
  outline: none;
  width: 100%;
}
.field select:focus, .field input:focus { border-color: var(--primary); }
.field.wide { grid-column: 1 / -1; }

.modal-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
}
.modal-msg { flex: 1; font-size: 12px; color: var(--muted); }
.modal-msg.bad { color: var(--up); }

/* 基金详情抽屉 */
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(15, 27, 40, 0.42);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 24;
}
.drawer.open { display: flex; }

.drawer-card {
  background: #fff;
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  overflow-y: auto;
  border-radius: 14px 14px 0 0;
}

@media (min-width: 560px) {
  .drawer { align-items: center; }
  .drawer-card { border-radius: 14px; }
}

.drawer-head {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #fff;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.drawer-title strong { display: block; font-size: 15px; color: var(--primary); line-height: 1.4; }
.drawer-title .sub { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }
.drawer-body { padding: 14px 16px 26px; }

.d-nav { display: flex; align-items: baseline; gap: 10px; }
.d-nav .big { font-size: 27px; font-weight: 600; letter-spacing: -0.5px; font-variant-numeric: tabular-nums; color: var(--primary); }
.d-nav .chg { font-size: 14px; font-weight: 600; }

.d-sec { margin-top: 18px; }
.d-sec h4 { font-size: 12px; font-weight: 500; color: var(--muted); margin: 0 0 8px; letter-spacing: 0.3px; }

.d-stage { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.d-stage .cell { background: var(--soft); border-radius: 9px; padding: 9px 10px; }
.d-stage .cell span { display: block; font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.d-stage .cell b { font-size: 14px; font-variant-numeric: tabular-nums; }

.spark { width: 100%; height: 158px; background: var(--soft); border-radius: 10px; display: block; }
.spark-area.up { fill: rgba(198, 40, 40, 0.1); }
.spark-area.down { fill: rgba(27, 127, 58, 0.1); }
.spark-line.up { stroke: #c62828; }
.spark-line.down { stroke: #1b7f3a; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 7px 14px; font-size: 13px; }
.kv .k { color: var(--muted); }
.d-tip { font-size: 13px; color: var(--muted); line-height: 1.7; }
.d-foot { font-size: 11px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 10px; }

.row-link { cursor: pointer; }
.row-link:hover td { background: #f5f8fb; }

@media (max-width: 560px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .kpi strong { font-size: 16px; }
  th, td { padding: 8px; font-size: 12px; }
  .form { grid-template-columns: 1fr; }
  .d-stage { grid-template-columns: repeat(2, 1fr); }
  .d-nav .big { font-size: 23px; }
}
