:root {
  --blue: #1A6DFF;
  --blue-dark: #0f57cf;
  --bg: #f5f6fa;
  --card: #fff;
  --text: #222;
  --text2: #666;
  --text3: #999;
  --line: #eee;
  --up: #e8756f;    /* 红涨（柔和珊瑚红） */
  --down: #2e9e5b;  /* 绿跌 */
  --danger: #e53935;
  --radius: 14px;
  --tabbar-h: 56px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg); color: var(--text); font-size: 16px;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0));
}
button { font-family: inherit; }
.hidden { display: none !important; }
.boot-loading { text-align: center; color: var(--text3); padding: 40vh 0; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 8px; min-height: 46px;
  padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top, 0));
  background: #fff; border-bottom: 1px solid var(--line);
}
.topbar .title {
  font-size: 17px; font-weight: 600; position: absolute; left: 64px; right: 64px;
  text-align: center; pointer-events: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar .spacer { flex: 1; }
.topbar .btn-back, .topbar .btn-text {
  background: none; border: none; color: var(--blue); font-size: 15px; padding: 6px 8px; cursor: pointer;
  min-width: 36px;
}
/* 右侧操作按钮（编辑/新建/添加）固定到右上角，与返回键分开，避免误触 */
.topbar .btn-text { margin-left: auto; }
.topbar .btn-text:disabled { color: var(--text3); }

/* ---------- 首页头部 ---------- */
.hero {
  background: linear-gradient(135deg, #1A6DFF 0%, #4e9aff 100%);
  color: #fff; padding: 20px 18px 22px; border-radius: var(--radius);
  width: calc(100% - 24px); max-width: 616px; margin: 14px auto 0;
  box-shadow: 0 4px 14px rgba(26,109,255,.22);
}
.hero .label { font-size: 13px; opacity: .85; display: flex; justify-content: space-between; align-items: center; }
.hero .amount { font-size: 30px; font-weight: 700; margin: 4px 0 2px; letter-spacing: .5px; }
.hero .row { display: flex; gap: 12px; margin-top: 12px; flex-wrap: wrap; }
.hero .cell .label { font-size: 12px; opacity: .8; }
.hero .cell .val { font-size: 17px; font-weight: 600; margin-top: 3px; }

/* ---------- 卡片与列表 ---------- */
.page { padding: 14px 12px 20px; max-width: 640px; margin: 0 auto; }
.card {
  background: var(--card); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 12px;
  box-shadow: 0 1px 3px rgba(20, 40, 80, .06);
}
.card-title { display: flex; align-items: center; justify-content: space-between; font-size: 15px; font-weight: 600; margin-bottom: 10px; }
.card-title .more { font-size: 13px; color: var(--text3); font-weight: 400; cursor: pointer; }
.list-item {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 2px; border-bottom: 1px solid var(--line); cursor: pointer;
}
.list-item:last-child { border-bottom: none; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .name { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .sub { font-size: 12px; color: var(--text3); margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .right { text-align: right; flex-shrink: 0; margin-left: 6px; }
.list-item .right .v1 { font-size: 15px; font-weight: 600; white-space: nowrap; }
.list-item .right .v2 { font-size: 12px; margin-top: 3px; }
.muted { color: var(--text3); } .small { font-size: 12px; }
.up { color: var(--up); } .down { color: var(--down); }
.empty { text-align: center; color: var(--text3); padding: 26px 0; font-size: 13px; }

/* ---------- 表单 ---------- */
.form-sec {
  font-size: 12px; font-weight: 600; color: var(--text3);
  margin: 16px 0 10px; padding-left: 8px; border-left: 3px solid var(--blue);
}
.form-sec:first-of-type { margin-top: 2px; }
.af-live { font-size: 11px; color: var(--down); margin-top: 4px; min-height: 14px; }
.form-row { margin-bottom: 13px; }
.form-row label { display: block; font-size: 13px; color: var(--text2); margin-bottom: 6px; }
.form-row input, .form-row select, .form-row textarea {
  width: 100%; padding: 10px 12px; border: 1px solid #ddd; border-radius: 10px;
  font-size: 15px; background: #fafbfc; color: var(--text); outline: none; font-family: inherit;
}
.form-row input:focus, .form-row select:focus { border-color: var(--blue); background: #fff; }
.form-grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: none; border-radius: 10px; background: var(--blue); color: #fff;
  font-size: 15px; padding: 11px 18px; cursor: pointer;
}
.btn:active { background: var(--blue-dark); }
.btn.block { width: 100%; }
.btn.ghost { background: #eef4ff; color: var(--blue); }
.btn.gray { background: #f0f1f5; color: var(--text2); }
.btn.danger { background: #fdecec; color: var(--danger); }
.btn.sm { padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.btn-row { display: flex; gap: 10px; margin-top: 6px; }
.btn-row .btn { flex: 1; }

/* ---------- 底部弹层 ---------- */
.sheet-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 90;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: #fff; width: 100%; max-width: 640px;
  border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom, 0));
  max-height: 88vh; overflow-y: auto;
}
.sheet .sheet-title { font-size: 16px; font-weight: 600; margin-bottom: 14px; display: flex; justify-content: space-between; }
.sheet .close { background: none; border: none; font-size: 20px; color: var(--text3); cursor: pointer; }

/* ---------- Toast ---------- */
#toast-root { position: fixed; top: 15vh; left: 0; right: 0; z-index: 200; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast {
  background: rgba(30,30,30,.88); color: #fff; font-size: 14px;
  padding: 9px 18px; border-radius: 20px; max-width: 80vw;
  animation: toast-in .2s ease;
}
.toast.err { background: rgba(200,40,40,.92); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- TabBar / FAB ---------- */
#tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0));
  padding-bottom: env(safe-area-inset-bottom, 0);
  background: #fff; border-top: 1px solid var(--line);
  display: flex; z-index: 40;
}
#tabbar button {
  flex: 1; border: none; background: none; color: var(--text3);
  font-size: 11px; display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer; padding-top: 7px;
}
#tabbar button.active { color: var(--blue); }
#tabbar .tab-ico { font-size: 20px; line-height: 1; }
#fab {
  position: fixed; right: 18px; bottom: calc(var(--tabbar-h) + 18px + env(safe-area-inset-bottom, 0));
  width: 52px; height: 52px; border-radius: 50%; border: none; z-index: 45;
  background: var(--blue); color: #fff; font-size: 28px; line-height: 1;
  box-shadow: 0 4px 14px rgba(26,109,255,.45); cursor: pointer;
}

/* ---------- 徽标 / chips ---------- */
.badge {
  display: inline-block; font-size: 11px; padding: 2px 7px; border-radius: 6px;
  background: #eef4ff; color: var(--blue); margin-right: 4px; vertical-align: middle;
}
.badge.gray { background: #f0f1f5; color: var(--text2); }
.badge.red { background: #fdecec; color: var(--up); }
.badge.green { background: #e6f6ec; color: var(--down); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  border: 1px solid var(--line); background: #fff; color: var(--text2);
  font-size: 13px; padding: 6px 14px; border-radius: 16px; white-space: nowrap; cursor: pointer;
  transition: all .15s;
}
.chip.active { background: var(--blue); border-color: var(--blue); color: #fff; }

/* ---------- 指标格 ---------- */
.metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 12px; }
.metrics .m { background: #fff; border-radius: var(--radius); padding: 12px 8px; text-align: center; box-shadow: 0 1px 3px rgba(20,40,80,.06); }
.metrics .m .k { font-size: 11px; color: var(--text3); }
.metrics .m .v { font-size: 15px; font-weight: 600; margin-top: 4px; }

.chart-box { width: 100%; height: 180px; }
.chart-box.tall { height: 210px; }

/* ---------- 进度条(占比) ---------- */
.ratio-bar { height: 6px; background: #eef0f4; border-radius: 3px; overflow: hidden; margin-top: 6px; }
.ratio-bar > div { height: 100%; background: var(--blue); border-radius: 3px; }
.ratio-bar > div.warn { background: #ff9800; }

/* ---------- 资产搜索选择器 ---------- */
.pick-list { max-height: 240px; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; margin-top: 8px; background: #fafbfc; }
.pick-list:empty { display: none; }
.pick-group { font-size: 12px; color: var(--text3); padding: 8px 12px 3px; }
.pick-item { display: flex; align-items: center; gap: 8px; padding: 9px 12px; cursor: pointer; border-bottom: 1px solid #f2f3f7; }
.pick-item:active, .pick-item:hover { background: #eef4ff; }
.pick-item.sel { background: #eef4ff; }
.pick-item .n { font-size: 14px; }
.pick-item .c { font-size: 11px; color: var(--text3); margin-top: 2px; }
.pick-item .mv { font-size: 12px; color: var(--text2); }
.pick-empty { padding: 16px; text-align: center; color: var(--text3); font-size: 13px; }
.chosen-box { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: #eef4ff; border-radius: 10px; margin-bottom: 13px; }
.chosen-box .badge { font-size: 14px; padding: 5px 12px; }

/* ---------- 市场徽标（A股红/港股橙/美股蓝） ---------- */
.badge.mkt-a { background: #fdeaea; color: #d32f2f; }
.badge.mkt-hk { background: #fff3e0; color: #ef6c00; }
.badge.mkt-us { background: #e8f0fe; color: #1a56db; }
.badge.mkt { padding: 1px 6px; font-weight: 600; }

/* ---------- 收益日历 ---------- */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-wk { text-align: center; font-size: 11px; color: var(--text3); padding: 2px 0 4px; }
.cal-cell {
  border-radius: 8px; min-height: 46px; padding: 4px 5px;
  display: flex; flex-direction: column; justify-content: space-between;
  font-size: 10px; color: #444; overflow: hidden; cursor: pointer;
}
.cal-cell.off { background: #f5f6fa; color: var(--text3); }
.cal-cell .d { font-size: 11px; font-weight: 600; opacity: .85; }
.cal-cell .p { white-space: nowrap; }
.cal-grid.cols4 { grid-template-columns: repeat(4, 1fr); }
.cal-cell.big { min-height: 54px; }
.cal-cell.big .d { font-size: 10px; font-weight: 500; opacity: .85; }

/* ---------- 首页币种分卡（紧凑行式，三列对齐） ---------- */
.ccy-split { display: flex; flex-direction: column; gap: 2px; margin-top: 10px; }
.ccy-card {
  display: grid; grid-template-columns: minmax(0, 1fr) 5ch minmax(9ch, auto) minmax(9ch, auto);
  align-items: center; gap: 10px;
  padding: 7px 2px; cursor: pointer; border-bottom: 1px solid rgba(255,255,255,.14);
}
.ccy-card:last-child { border-bottom: none; }
.ccy-card .ccy-left { font-size: 13px; display: flex; align-items: center; gap: 6px; min-width: 0; }
.ccy-card .ccy-pct { font-size: 11px; opacity: .7; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ccy-card .ccy-main { font-size: 14px; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ccy-card .ccy-sub { font-size: 12px; opacity: .8; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.dot.cny { background: #ff8a80; } .dot.usd { background: #82b1ff; } .dot.hkd { background: #ffcc80; }

/* 首页组合行的展开按钮与右侧金额对齐 */
.list-item > .btn.sm.gray { flex: 0 0 auto; align-self: center; margin-left: 4px; padding: 4px 9px; }
.hero .label { white-space: nowrap; }
.hero .label #btn-eye { flex: 0 0 auto; }
.hero .label > span:first-child { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }

/* ---------- 标签芯片 ---------- */
.tag-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.tag-chip {
  border: 1px solid var(--line); background: #fff; color: var(--text2);
  font-size: 13px; padding: 5px 13px; border-radius: 15px; cursor: pointer; user-select: none;
}
.tag-chip.on { background: #eef4ff; border-color: var(--blue); color: var(--blue); font-weight: 500; }

.sync-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.sync-dot.ok { background: #2e9e5b; } .sync-dot.off { background: #bbb; } .sync-dot.err { background: var(--danger); }

@media (min-width: 900px) {
  body { font-size: 16px; }
  #tabbar { left: 50%; transform: translateX(-50%); width: 480px; border-radius: 18px 18px 0 0; border: 1px solid var(--line); border-bottom: none; }
  .hero { max-width: 1064px; margin: 20px auto 0; border-radius: 18px; width: calc(100% - 24px); }
  .hero .amount { font-size: 40px; }
  .topbar { max-width: 1080px; margin: 0 auto; }
  .page { max-width: 1080px; columns: 2; column-gap: 14px; }
  .page .card, .page .btn-row, .page .metrics { break-inside: avoid; margin-bottom: 14px; }
  .page .card.wide { column-span: all; }
  .page.narrow { columns: 1; max-width: 720px; }
  .chart-box { height: 220px; }
  .chart-box.tall { height: 250px; }
  .sheet { border-radius: 16px; margin: 6vh auto 0; max-width: 560px; }
  .sheet-mask { align-items: flex-start; overflow-y: auto; }
  .metrics { column-span: all; grid-template-columns: repeat(4, 1fr); }
  .metrics .m .v { font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #fab { right: max(18px, calc(50% - 540px + 18px)); }
  #chart-rank { height: 340px !important; }
  #chart-pie { height: 340px !important; }
}

@media (min-width: 700px) and (max-width: 899px) {
  .page { max-width: 760px; }
  .hero { max-width: 736px; }
  .sheet { border-radius: 18px; margin-bottom: 8vh; }
}

@media (max-width: 480px) {
  .cal-grid.cols4 { grid-template-columns: repeat(3, 1fr); }
  .cal-cell { min-height: 42px; }
  .cal-cell.big { min-height: 50px; }
  .cal-cell .p { font-size: 9px; }
  /* 指标方块 2×2，不再挤压 */
  .metrics { grid-template-columns: 1fr 1fr; }
  .metrics .m { padding: 10px 8px; }
  .metrics .m .v { font-size: 14px; }
  /* 卡片标题允许换行，按钮组独立成行 */
  .card-title { flex-wrap: wrap; gap: 6px; }
  /* 手机上币种卡竖排，金额完整显示 */
  .ccy-split { flex-direction: column; }
}
