/* PA 交易管理系统 —— 设计令牌与版式
   配色取自经校验的数据可视化调色板：分类槽位固定顺序，浅/深色各自选定步进。 */

:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);

  --series-1: #2a78d6;  /* 港股 */
  --series-2: #eb6834;  /* 美股 */
  --series-3: #1baf7a;  /* A股 */
  --series-4: #eda100;  /* 现金 */
  --series-5: #e87ba4;  /* 其他 */
  /* 6–10 档是后加的：原来只有 5 档，而策略分类/账户的桶数由数据决定，
     取色一旦超出就被钳在第 5 档上，一长串全是粉色。新增这几档刻意在
     **明度上也拉开**（紫偏深、青居中、棕偏深、蓝灰压暗、红最深），
     只换色相的话深色模式下相邻两档会糊成一片。 */
  --series-6: #7b5ea7;
  --series-7: #12909e;
  --series-8: #9c6b3f;
  --series-9: #5c6f8a;
  --series-10: #b43a52;

  --seq-200: #9ec5f4;
  --seq-450: #2a78d6;

  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --critical: #d03b3b;

  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", "PingFang SC",
          "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  /* 数字用等宽体，金额列才对得齐；中文标签仍走 --font */
  --font-num: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono",
              Menlo, Consolas, monospace;

  --brand: #6d28d9;          /* 与 logo 同源，只用于强调，不用于涨跌 */
  --elevate: 0 1px 2px rgba(11, 11, 11, 0.04), 0 1px 8px rgba(11, 11, 11, 0.03);
  --elevate-hi: 0 2px 4px rgba(11, 11, 11, 0.06), 0 6px 20px rgba(11, 11, 11, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #9b7fc9;
    --series-7: #1aa8b8;
    --series-8: #b8834f;
    --series-9: #7d90ab;
    --series-10: #d1596f;
    --seq-200: #184f95;
    --seq-450: #3987e5;
    --good-text: #0ca30c;
    --brand: #a78bfa;
    /* 深色下阴影几乎不可见，层次靠边框提亮 */
    --elevate: 0 1px 2px rgba(0, 0, 0, 0.4);
    --elevate-hi: 0 4px 18px rgba(0, 0, 0, 0.5);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --page: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #9b7fc9;
  --series-7: #1aa8b8;
  --series-8: #b8834f;
  --series-9: #7d90ab;
  --series-10: #d1596f;
  --seq-200: #184f95;
  --seq-450: #3987e5;
  --good-text: #0ca30c;
  --brand: #a78bfa;
  --elevate: 0 1px 2px rgba(0, 0, 0, 0.4);
  --elevate-hi: 0 4px 18px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--page);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
}

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

/* ---------------- 布局 ---------------- */

.topbar {
  display: flex; align-items: center; gap: 12px 20px;
  /* 用 min-height + padding 而非固定 height：窄屏换行时不会互相压住 */
  padding: 8px 24px; min-height: 52px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
  flex-wrap: wrap;
}
.brand {
  display: flex; align-items: center; gap: 9px;
  font-weight: 650; letter-spacing: -0.01em; white-space: nowrap;
  color: var(--text-primary); text-decoration: none;
}
.brand:hover { text-decoration: none; }
/* 标记本身自带深色刃，浅底也压得住，不用给它加底板 */
.brand img { display: block; flex: none; }
.brand small { color: var(--text-muted); font-weight: 400; margin-left: 6px; }
/* 汉堡按钮只在窄屏出现——宽屏本来就放得下 */
.nav-burger {
  display: none; cursor: pointer; font-size: 20px; line-height: 1;
  padding: 4px 10px; border-radius: 7px; color: var(--text-secondary);
  margin-bottom: 0;
}
.nav-burger:hover { background: var(--page); color: var(--text-primary); }

.nav { display: flex; gap: 2px; flex-wrap: wrap; }
.nav a {
  padding: 6px 11px; border-radius: 7px; color: var(--text-secondary);
  font-size: 13px; text-decoration: none; white-space: nowrap;
}
.nav a:hover { background: var(--page); color: var(--text-primary); text-decoration: none; }
.nav a.active { background: var(--series-1); color: #fff; }
.topbar .spacer { flex: 1; }

/* 分组下拉：纯 CSS，hover 或键盘 focus 都能展开，不引 JS。
   用 :focus-within 而不是 :focus，否则 Tab 进子项时菜单会先收起来。 */
.menu { position: relative; }
.menu > button {
  padding: 6px 11px; border-radius: 7px; border: none; background: none;
  color: var(--text-secondary); font: inherit; font-size: 13px;
  cursor: pointer; white-space: nowrap; display: flex; align-items: center; gap: 4px;
}
.menu > button:hover { background: var(--page); color: var(--text-primary); }
.menu > button.active { background: var(--series-1); color: #fff; }
.menu .caret { font-size: 9px; opacity: .65; }

.menu-pop {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 30;
  min-width: 230px; padding: 6px;
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--elevate-hi);
  display: none;
}
.menu:hover .menu-pop, .menu:focus-within .menu-pop { display: block; }
/* **把按钮与浮层之间那道缝接上。** 浮层往下让了 6px 留白，而那 6px 既不在按钮上、
   也不在浮层上——鼠标往下移经过它时 `.menu:hover` 就断了，浮层在你够到之前收掉，
   于是非得先点一下一级标题（点击产生 `:focus-within`，能扛过这道缝）才点得到二级。
   这个 ::before 是浮层的后代、完全透明，只负责在那 6px 上接住指针。
   浮层没展开时它跟着 `display:none`，不会挡住底下的东西。
   高度比缝多 1px，避免缩放时的亚像素漏缝。 */
.menu-pop::before {
  content: ""; position: absolute; left: 0; right: 0; top: -7px; height: 7px;
}
.menu-pop a {
  display: block; padding: 7px 10px; border-radius: 7px;
  color: var(--text-primary); text-decoration: none;
}
.menu-pop a:hover { background: var(--page); text-decoration: none; }
.menu-pop a.on { background: var(--page); }
.menu-pop a.on b { color: var(--series-1); }
.menu-pop b { display: block; font-size: 13px; font-weight: 560; }
.menu-pop span { display: block; font-size: 11.5px; color: var(--text-muted); margin-top: 1px; }

/* 窄屏：导航**默认收起**，点汉堡才展开。

   原来是把三个下拉全部永久摊开成分组列表——考虑是「触屏没有 hover，
   摊开免得点不动」，方向对，但结果是十个入口加十条说明文字堆满一屏，
   正文被挤到屏幕最底下只剩一行。手机上打开看到的就是那个。

   展开之后仍然摊平（触屏没有 hover），但**说明文字藏掉**：
   小屏上那十行灰字只是让列表长一倍，真要看说明的时候人已经在页面里了。 */
@media (max-width: 760px) {
  .nav-burger { display: block; }
  .topbar { gap: 8px 12px; }
  .brand span { font-size: 15px; }

  .nav { display: none; width: 100%; flex-direction: column; gap: 0; }
  #nav-toggle:checked ~ .topbar .nav { display: flex; }

  .nav > a, .menu > button { width: 100%; justify-content: flex-start; padding: 10px 12px; }
  .menu { width: 100%; }
  .menu > button { font-weight: 600; }
  .menu .caret { display: none; }
  .menu-pop {
    display: block; position: static; box-shadow: none; border: none;
    background: none; padding: 0 0 6px 12px; min-width: 0;
  }
  .menu-pop a { padding: 9px 10px; }
  .menu-pop span { display: none; }
}

main { padding: 22px 24px 60px; max-width: 1440px; margin: 0 auto; }

h1 { font-size: 20px; font-weight: 650; margin: 0 0 4px; letter-spacing: -0.015em; }
h2 { font-size: 14px; font-weight: 620; margin: 0 0 12px; letter-spacing: -0.005em; }
h3 { font-size: 13px; font-weight: 620; margin: 0 0 10px; color: var(--text-secondary); }
.subtitle { color: var(--text-muted); font-size: 12.5px; margin: 0 0 20px; }

/* 分区标题：一条短竖线做锚点，比纯文字更容易在长页面里扫到 */
.section-head {
  display: flex; align-items: baseline; gap: 10px;
  margin: 26px 0 12px;
}
.section-head::before {
  content: ""; width: 3px; height: 14px; border-radius: 2px;
  background: var(--brand); flex: none; align-self: center;
}
.section-head h2 { margin: 0; }
.section-head .hint { font-size: 12px; color: var(--text-muted); }

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: var(--elevate);
}
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: 1.35fr 1fr; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------------- KPI ----------------
   一张卡一个主数字。副信息最多一行，且只放**读懂这个数字必需**的东西；
   口径解释一律下沉到页尾的 .notes，不塞进卡片——卡片挤成三行小字就没人看了。 */

.kpi-row {
  display: grid; gap: 12px; margin-bottom: 16px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}
/* 固定 4 列而非 auto-fit：auto-fit 下最后一张卡常常独占一行，看着像坏了。
   hero 占 2 格，于是 1+6 个指标恰好铺满两行。 */
.kpi.hero { grid-column: span 2; }
@media (max-width: 1180px) { .kpi-row { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px)  {
  .kpi-row { grid-template-columns: 1fr; }
  .kpi.hero { grid-column: span 1; }
}

.kpi {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 15px 17px;
  box-shadow: var(--elevate);
  display: flex; flex-direction: column; gap: 4px;
  transition: box-shadow .15s ease, transform .15s ease;
}
.kpi:hover { box-shadow: var(--elevate-hi); transform: translateY(-1px); }
.kpi .label {
  font-size: 11.5px; color: var(--text-muted); font-weight: 500;
  letter-spacing: .02em; display: flex; align-items: center; gap: 6px;
}
.kpi .value {
  /* 大号数字用无衬线 + 制表数字：既对得齐，又不像表格里的等宽那样显得呆板。
     等宽留给表格的窄列，那里对齐比字形更重要。 */
  font-size: 26px; font-weight: 620; letter-spacing: -0.03em; line-height: 1.15;
  font-variant-numeric: tabular-nums;
}
.kpi.hero { background: linear-gradient(180deg, var(--surface-1), var(--page)); }
.kpi.hero .value { font-size: 38px; }

/* hero 里的迷你配置条：把「钱都在哪」压缩成一条，省得为它单开一张卡 */
.minibar { display: flex; height: 6px; border-radius: 3px; overflow: hidden; margin: 10px 0 2px; }
.minibar i { display: block; height: 100%; }
.minibar i + i { margin-left: 1px; }
.kpi .sub {
  font-size: 12px; color: var(--text-secondary); margin-top: auto; padding-top: 2px;
}
/* 卡片里的次级数字也走等宽，跟主数字对齐 */
.kpi .sub .n { font-family: var(--font-num); font-variant-numeric: tabular-nums; }

/* 一行 键—值 的紧凑列表，用来替代卡片里那种堆三行小字的写法 */
.kpi .facts { display: flex; flex-wrap: wrap; gap: 3px 14px; font-size: 12px; }
.kpi .facts span { color: var(--text-muted); }
.kpi .facts b {
  font-weight: 550; color: var(--text-secondary);
  font-family: var(--font-num); font-variant-numeric: tabular-nums;
}

.pos { color: var(--good-text); }
.neg { color: var(--critical); }
.flat { color: var(--text-secondary); }

/* ---------------- 页尾口径注解 ----------------
   用户原话：「如有需要备注放在文后」。卡片和表格只放数字，
   「这个数怎么算出来的」统一收到这里，想深究的人才看。 */
.notes {
  margin-top: 28px; padding: 16px 18px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: transparent;
}
.notes > .t {
  font-size: 11.5px; font-weight: 600; color: var(--text-muted);
  letter-spacing: .04em; margin-bottom: 10px;
}
.notes dl { margin: 0; display: grid; grid-template-columns: max-content 1fr; gap: 7px 16px; }
.notes dt { font-size: 12.5px; font-weight: 580; color: var(--text-secondary); white-space: nowrap; }
.notes dd { margin: 0; font-size: 12.5px; color: var(--text-muted); line-height: 1.6; }
.notes dd b { color: var(--text-secondary); font-weight: 580; }
@media (max-width: 720px) {
  .notes dl { grid-template-columns: 1fr; gap: 2px; }
  .notes dt { margin-top: 8px; }
}

/* ---------------- 表格 ---------------- */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; font-weight: 560; font-size: 11px;
  color: var(--text-muted); letter-spacing: .03em;
  padding: 8px 10px; border-bottom: 1px solid var(--axis); white-space: nowrap;
  /* 宽表横向滚动时表头要跟着留在视野里 */
  position: sticky; top: 0; background: var(--surface-1); z-index: 1;
}
td { padding: 9px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
tbody tr:hover td { background: var(--page); }
/* 数字列一律等宽 + 制表数字，否则「1,408,957」和「357,156」的位数对不齐 */
.num {
  text-align: right; font-family: var(--font-num);
  font-variant-numeric: tabular-nums; letter-spacing: -0.01em;
}
tfoot td {
  font-weight: 620; border-top: 1px solid var(--axis); border-bottom: none;
  background: var(--surface-1);
}

/* 一格里的第二行：把天然成对的字段（市值/成本、汇兑/分红、金额/百分比）
   上下摞起来，列数减半而一个数都不用删。次要的那个压暗、缩小，
   主数仍是一眼扫过去的那一行。表头里也用，标注这一格的下半行是什么。 */
.sub2 {
  display: block; margin-top: 2px;
  font-size: 11.5px; font-weight: 400; color: var(--text-muted);
}
th .sub2 { font-size: 10.5px; margin-top: 1px; }
tfoot .sub2 { font-weight: 500; }

.chip {
  display: inline-block; padding: 1px 7px; border-radius: 5px;
  font-size: 11px; background: var(--page); color: var(--text-secondary);
  border: 1px solid var(--border); white-space: nowrap;
}
.chip.warn { color: var(--critical); border-color: var(--critical); }
.chip.mute { color: var(--text-muted); border-style: dashed; }

/* 权重条：单色序列，越大越深 */
.wbar { display: block; height: 4px; border-radius: 2px; background: var(--seq-450); }
.wbar-track { background: var(--grid); border-radius: 2px; width: 56px; height: 4px; }

/* ---------------- 图表 ---------------- */

.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 12px; font-size: 12px; }
.legend .item { display: flex; align-items: center; gap: 6px; color: var(--text-secondary); }
.legend .swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }

svg { display: block; max-width: 100%; }
/* 空图不要占满整张卡：一块 230px 高的空白比一行提示更像故障 */
.chart-empty {
  color: var(--text-muted); font-size: 12.5px; padding: 18px 0; text-align: center;
}
.chart-empty code {
  font-family: var(--font-num); font-size: 11.5px;
  background: var(--page); padding: 1px 5px; border-radius: 4px;
}

/* ---------------- 表单 ---------------- */

form .row { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); margin-bottom: 14px; }
label { display: block; font-size: 12px; color: var(--text-secondary); margin-bottom: 4px; }
/* **复选框与单选框必须排除在外。** 它们是固定尺寸的原生控件，套上
   `width: 100%` 会撑满整行——在 flex 行里（`.write-item` 那种「方框 + 说明文字」）
   还叠加了 `flex: none`（不许收缩），于是复选框占掉全部宽度，旁边的文字被挤成
   零宽，一个字一列竖着排、方框高几百像素。用户看到的「上传结单后页面显示错乱」
   就是这条，而且它是全局规则：任何页面新加一个复选框都会中招。 */
input:not([type="checkbox"]):not([type="radio"]), select, textarea {
  width: 100%; padding: 7px 9px; font-size: 13px; font-family: var(--font);
  background: var(--page); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 7px;
}
input:not([type="checkbox"]):not([type="radio"]):focus, select:focus, textarea:focus { outline: 2px solid var(--series-1); outline-offset: -1px; }

/* 复选框/单选框**显式钉住尺寸**。上面的 :not() 已经把它们排除在外了，这条是
   第二道保险：属性选择器的优先级（0,2,0）压得过任何裸 `input`（0,0,1），
   将来谁再写一条通用规则也撑不坏它。踩过一次——撑满整行时同一 flex 行里的
   文字被挤成零宽，一个字一列竖着排。 */
input[type="checkbox"], input[type="radio"] {
  width: 15px; height: 15px; padding: 0; flex: none;
  accent-color: var(--series-1); cursor: pointer;
}
textarea { min-height: 66px; resize: vertical; }

.btn {
  display: inline-block; padding: 8px 16px; font-size: 13px; font-weight: 550;
  background: var(--series-1); color: #fff; border: none;
  border-radius: 7px; cursor: pointer; font-family: var(--font);
}
.btn:hover { filter: brightness(1.07); }
.btn.ghost { background: transparent; color: var(--text-secondary); border: 1px solid var(--border); }
.btn.danger { background: var(--critical); }
.btn-sm { padding: 4px 10px; font-size: 12px; }

.banner {
  padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 16px;
  border: 1px solid var(--border);
}
.banner.ok { border-left: 3px solid var(--good); }
.banner.warn { border-left: 3px solid var(--warning); }
.banner.err { border-left: 3px solid var(--critical); }

.toolbar { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar .field { min-width: 130px; }
.toolbar label { margin-bottom: 3px; }

/* ---------------- SVG 图表着色 ----------------
   颜色写在样式表而非 SVG 表现属性里：表现属性不保证解析 CSS 变量，
   样式表规则则对内联 SVG 一律生效，深色模式也跟着一起切。 */
.seg-1 { fill: var(--series-1); }
.seg-2 { fill: var(--series-2); }
.seg-3 { fill: var(--series-3); }
.seg-4 { fill: var(--series-4); }
.seg-5 { fill: var(--series-5); }
.seg-6 { fill: var(--series-6); }
.seg-7 { fill: var(--series-7); }
.seg-8 { fill: var(--series-8); }
.seg-9 { fill: var(--series-9); }
.seg-10 { fill: var(--series-10); }

.svg-label { fill: var(--text-secondary); }
.svg-tick  { fill: var(--text-muted); font-variant-numeric: tabular-nums; }
.svg-grid  { stroke: var(--grid); }
.svg-axis  { stroke: var(--axis); }
.svg-line  { stroke: var(--series-1); }
.svg-dot   { fill: var(--series-1); stroke: var(--surface-1); }

/* ---------------- 结单写入清单 ----------------
   每一项是一个可点的大块（label 包着 checkbox），不是一行小字加个方框——
   这张单子是「按下去会发生什么」的唯一说明，得让人愿意逐条读完。 */
.write-item {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 10px 12px; margin-bottom: 6px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-1); cursor: pointer; font-weight: 400;
}
.write-item:hover { border-color: var(--axis); }
.write-item input { margin-top: 2px; flex: none; }
.write-item b { font-weight: 600; font-size: 13px; }
.write-item .sub {
  margin-top: 4px; color: var(--text-muted);
  font-family: var(--font-num); font-size: 11.5px; line-height: 1.6;
}
.write-item.blocked { opacity: .62; cursor: not-allowed; background: var(--page); }

/* 折叠区标题。默认的三角小得看不见，也不像可点的东西 */
summary.fold {
  cursor: pointer; list-style: none;
  font-size: 15px; font-weight: 600; color: var(--text-primary);
  display: flex; align-items: center; gap: 8px;
}
summary.fold::-webkit-details-marker { display: none; }
summary.fold::before {
  content: "›"; display: inline-block; font-size: 17px; line-height: 1;
  color: var(--text-muted); transition: transform .15s ease;
}
details[open] > summary.fold::before { transform: rotate(90deg); }
summary.fold:hover { color: var(--brand); }
