:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --ink: #1f2933;
  --muted: #7b8794;
  --line: #e3e8ef;
  --brand: #2f6df6;
  --brand-d: #1f53c7;
  --up: #d93025;     /* 涨：红（A股习惯） */
  --down: #1a8f4d;   /* 跌：绿 */
  --danger: #d93025;
  --shadow: 0 1px 3px rgba(16,24,40,.08);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", Segoe UI, sans-serif;
  background: var(--bg);
  color: var(--ink);
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.err { color: var(--danger); min-height: 1.2em; font-size: 13px; }
.up { color: var(--up); }
.down { color: var(--down); }
.hint { color: var(--muted); font-size: 12px; }
.tag {
  background: #eef2ff; color: var(--brand); border-radius: 4px;
  padding: 1px 6px; font-size: 11px; margin-left: 4px;
}

/* 登录 */
.view { min-height: 100vh; }
#loginView { display: flex; align-items: center; justify-content: center; }
.login-card {
  background: var(--card); padding: 32px; border-radius: 14px;
  box-shadow: var(--shadow); width: 340px; text-align: center;
}
.login-card h1 { font-size: 19px; margin: 0 0 6px; }
.login-card form { display: flex; flex-direction: column; gap: 10px; margin: 18px 0 10px; }
.login-card input { padding: 11px 12px; border: 1px solid var(--line); border-radius: 9px; font-size: 14px; }
.login-card button { padding: 11px; border: 0; border-radius: 9px; background: var(--brand); color: #fff; font-size: 15px; cursor: pointer; }
.login-card button:hover { background: var(--brand-d); }

/* 顶栏 */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 22px; background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 16px; }
.user { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 14px; }

/* 标签页 */
.tabs { display: flex; gap: 4px; padding: 0 18px; background: var(--card); border-bottom: 1px solid var(--line); }
.tab {
  border: 0; background: transparent; padding: 12px 16px; cursor: pointer;
  font-size: 14px; color: var(--muted); border-bottom: 2px solid transparent;
}
.tab.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }

main { max-width: none; margin: 16px 20px; padding: 0; }
.panel { background: transparent; }

/* 卡片 */
.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; box-shadow: var(--shadow); }
.card-label { color: var(--muted); font-size: 13px; }
.card-val { font-size: 22px; font-weight: 700; margin-top: 6px; }

/* 表格 */
.tbl { width: 100%; border-collapse: collapse; background: var(--card); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); }
.tbl th, .tbl td { padding: 11px 12px; text-align: left; border-bottom: 1px solid var(--line); font-size: 14px; }
.tbl th { background: #fafbfc; color: var(--muted); font-weight: 600; font-size: 13px; }
.tbl tr:last-child td { border-bottom: 0; }

/* 表单 */
.row { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; align-items: center; }
input, select {
  padding: 10px 11px; border: 1px solid var(--line); border-radius: 9px; font-size: 14px; background: #fff;
}
input:focus, select:focus { outline: none; border-color: var(--brand); }
button { font-family: inherit; }
button:not(.ghost) {
  background: var(--brand); color: #fff; border: 0; padding: 10px 16px; border-radius: 9px; cursor: pointer; font-size: 14px;
}
button:not(.ghost):hover { background: var(--brand-d); }
.ghost { background: transparent; border: 1px solid var(--line); color: var(--muted); padding: 6px 12px; border-radius: 8px; cursor: pointer; font-size: 13px; }
.ghost:hover { border-color: var(--danger); color: var(--danger); }
.nav-input { width: 110px; padding: 6px 8px; }
.preview { color: var(--brand); font-size: 14px; min-height: 20px; margin: 4px 0; }

.txform { background: var(--card); padding: 16px; border-radius: 12px; box-shadow: var(--shadow); margin-bottom: 18px; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.txform select, .txform input { flex: 1 1 140px; }

.calcbox { background: var(--card); padding: 20px; border-radius: 12px; box-shadow: var(--shadow); max-width: 560px; }
.calcbox h3 { margin: 0 0 14px; }

/* 大盘指数条（多市场分组） */
.indices {
  display: flex; gap: 8px; padding: 10px 18px; background: var(--card);
  border-bottom: 1px solid var(--line); overflow-x: auto;
  flex-wrap: wrap; align-items: flex-start;
}
.idx-group { display: inline-flex; align-items: center; gap: 6px; background: #fafbfc; border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px 6px 0; }
.idx-group-label {
  font-size: 11px; font-weight: 700; color: var(--brand);
  background: #eef2ff; padding: 2px 8px; border-radius: 5px;
  white-space: nowrap; margin-right: 2px;
}
.idx-group-items { display: flex; gap: 4px; align-items: center; }
.idx {
  flex: 0 0 auto; min-width: 90px; text-align: center;
}
.idx-name { font-size: 11px; color: var(--muted); white-space: nowrap; }
.idx-price { font-size: 14px; font-weight: 700; margin-top: 1px; }
.idx-pct { font-size: 11px; margin-top: 1px; }

/* 图表 */
.charts { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 18px; }
.chart-card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; box-shadow: var(--shadow); }
.chart-card.wide { grid-column: 1 / -1; }
.chart-card h4 { margin: 0 0 10px; font-size: 14px; color: var(--ink); }
.canvas-wrap { position: relative; height: 220px; }
.chart-card.wide .canvas-wrap { height: 240px; }

/* 持仓管理 */
.holding-controls { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; align-items: flex-end; }
.holding-controls select, .holding-controls input { flex: 1 1 130px; }
.holding-controls .chk { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }

/* 净值估算看板 */
.est-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 16px; }
.est-bar select { padding: 8px 10px; }
.est-bar .updated { color: var(--muted); font-size: 13px; }
.badge { display: inline-block; border-radius: 4px; padding: 1px 7px; font-size: 11px; font-weight: 600; }
.badge.halted { background: #fff4e5; color: #b45309; }
.badge.limit_up { background: #fde8e8; color: var(--up); }
.badge.limit_down { background: #e6f4ea; color: var(--down); }
.badge.no_data { background: #eef2f7; color: var(--muted); }
.badge.normal { background: #eef2ff; color: var(--brand); }
.special { background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 14px 16px; margin-top: 18px; }
.special h4 { margin: 0 0 10px; font-size: 14px; }
.special ul { margin: 0; padding-left: 18px; }
.special li { font-size: 13px; margin: 4px 0; color: var(--ink); }
.special .none { color: var(--muted); font-size: 13px; }

/* 持仓按基金分组区块 */
.fund-block { border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; margin-bottom: 18px; background: var(--card); box-shadow: var(--shadow); }
.fund-block h3 { margin: 0 0 10px; font-size: 16px; }
.fund-block .holding-controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.fund-block .holding-controls input[type="number"] { width: 120px; }
.holding-tbl { margin-top: 12px; }
.holding-tbl th, .holding-tbl td { font-size: 13px; }
/* 净值估算：持仓股展开按钮 */
.est-hold-btn { margin-left: 8px; font-size: 12px; padding: 2px 9px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: #333; cursor: pointer; }
.est-hold-btn:hover { border-color: var(--up); color: var(--up); }
#est_hold_detail { margin-top: 14px; }
#est_hold_detail h4 { margin: 0 0 8px; font-size: 14px; }

/* 总览：卡片网格（4列并列左对齐，窄屏降级） */
#est_body { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; align-items: start; }
#est_body > .cards { grid-column: 1 / -1; }
@media (max-width: 1400px) { #est_body { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 1080px) { #est_body { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 680px)  { #est_body { grid-template-columns: 1fr; } }

/* 净值估算：卡片布局（匹配基金App风格，紧凑化） */
.est-card {
  background: #1e2330; border-radius: 14px; padding: 14px 16px;
  margin-bottom: 0; color: #e8eaed;
}
.est-card-head {
  display: flex; align-items: center; gap: 8px; margin-bottom: 12px;
}
.est-card-title { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.est-fund-name { font-size: 15px; font-weight: 700; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.est-fund-code { font-size: 12px; color: #8b949e; }
.est-date { font-size: 12px; color: #8b949e; margin-left: auto; white-space: nowrap; }
.est-card-actions { display: flex; gap: 6px; }
.est-collapse-btn, .est-del-btn {
  background: transparent; border: 1px solid #3d4455; color: #8b949e;
  width: 26px; height: 26px; border-radius: 6px; cursor: pointer; font-size: 12px;
  display: inline-flex; align-items: center; justify-content: center; padding: 0;
}
.est-collapse-btn:hover, .est-del-btn:hover { border-color: #8b949e; color: #e8eaed; }
.est-del-btn:hover { border-color: var(--up); color: var(--up); }

/* 核心指标行 */
.est-metrics-row {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px;
}
.est-metric { text-align: center; }
.est-metric-label { font-size: 11px; color: #8b949e; margin-bottom: 3px; }
.est-metric-val { font-size: 17px; font-weight: 600; color: #e8eaed; }
.est-metric-highlight .est-metric-val { font-size: 19px; font-weight: 700; }
/* 涨跌颜色在深色卡上更醒目 */
.est-card .up { color: #f5554a !important; }
.est-card .down { color: #00c777 !important; }

/* 只读信息行（总览卡片：份额/成本价展示，不可编辑） */
.est-info-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px;
}
.est-info-item { display: flex; flex-direction: column; gap: 2px; }
.est-info-label { font-size: 11px; color: #8b949e; }
.est-info-val { font-size: 15px; font-weight: 600; color: #e8eaed; }

/* 收起状态：仅隐藏卡片内容，头部与按钮保留 */
.est-card.collapsed .est-metrics-row,
.est-card.collapsed .est-track-note,
.est-card.collapsed .est-info-row,
.est-card.collapsed .est-profit-section,
.est-card.collapsed .est-holdings-detail,
.est-card.collapsed .est-meta { display: none; }

/* 收益区域 */
.est-profit-section { margin-bottom: 10px; }
.est-profit-header { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.est-profit-label { font-size: 13px; color: #8b949e; }
.est-ret-badge {
  display: inline-block; padding: 2px 10px; border-radius: 8px;
  font-size: 14px; font-weight: 700;
}
.ret-badge-up { background: rgba(245,85,74,.15); color: #f5554a; }
.ret-badge-down { background: rgba(0,199,119,.15); color: #00c777; }

.est-profit-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px;
}
.est-profit-item { display: flex; justify-content: space-between; align-items: center; }
.est-pi-label { font-size: 12px; color: #8b949e; }
.est-pi-val { font-size: 13px; font-weight: 600; color: #e8eaed; }

/* 持仓明细折叠区 */
.est-holdings-detail {
  margin-top: 4px; border-top: 1px solid #2a3040; padding-top: 8px;
  overflow-x: auto;
  /* 隐藏滚动条但保留横向滚动能力（Webkit / Firefox / IE） */
  -ms-overflow-style: none; scrollbar-width: none;
}
.est-holdings-detail::-webkit-scrollbar { display: none !important; }
.est-holdings-detail summary {
  cursor: pointer; font-size: 12px; color: #8b949e; outline: none;
  user-select: none; list-style: none;
}
.est-holdings-detail summary::-webkit-details-marker { display: none; }
.est-holdings-detail summary:hover { color: #b0b8c4; }
.est-hold-tbl { background: transparent; box-shadow: none; border: none; border-radius: 0; overflow: visible; width: 100%; min-width: 520px; }
.est-hold-tbl th, .est-hold-tbl td {
  padding: 4px 7px; border-color: #2a3040; font-size: 11.5px; color: #c0c8d0;
  background: transparent; white-space: nowrap;
}
.est-hold-tbl th { color: #8b949e; font-weight: 600; background: transparent; }

/* 披露信息 */
.est-meta { font-size: 10.5px; margin-top: 6px; padding-top: 4px; color: #6b7280; }

/* 跟踪指数提示（联接/指数基金） */
.est-track-note {
  font-size: 12px; font-weight: 600; margin: -6px 0 10px; padding: 4px 10px;
  border-radius: 8px; background: #2a3040; display: inline-block;
}
.est-card .est-track-note.up { color: #f5554a !important; }
.est-card .est-track-note.down { color: #00c777 !important; }

/* 基金代码 → 名称自动关联 */
.fund-match { font-size: 12px; line-height: 1; flex: 0 1 auto; margin-left: -4px; }
.fund-match.ok { color: var(--up); }
.fund-match.err { color: var(--down); }
#f_code { flex: 0 0 150px; }
#fundMatch:empty { display: none; }

/* 持仓管理：联网同步相关 */
.hold-toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-bottom: 16px; }
.hold-toolbar .muted { font-size: 13px; }
.fb-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.fb-head h3 { margin: 0; font-size: 16px; }
.h_sync { background: #eef2ff; color: var(--brand); border: 1px solid #d6e0ff; padding: 7px 12px; border-radius: 8px; cursor: pointer; font-size: 13px; }
.h_sync:hover { background: #dbe4ff; }
.h_sync:disabled { opacity: .6; cursor: default; }
.fb-meta { margin: 4px 0 10px; font-size: 12px; }
.manual-add { margin-bottom: 12px; }
.manual-add summary { cursor: pointer; font-size: 13px; color: var(--muted); }
.manual-add .holding-controls { margin-top: 10px; }
