/* ============================================================
   我的持仓 · 风险监控   |  浅色主题 · A股习惯（涨红跌绿）
   ============================================================ */

:root {
  --bg:            #f2f4f7;
  --surface:       #ffffff;
  --surface-2:     #fafbfc;
  --border:        #e5e9ef;
  --border-2:      #d6dce5;

  --text:          #1a1f2b;
  --text-2:        #5a6472;
  --text-3:        #97a0ae;

  --up:            #e63232;
  --up-bg:         #fdecec;
  --down:          #0aa06e;
  --down-bg:       #e6f7f1;

  --l1:            #d99400;   --l1-bg: #fdf6e5;
  --l2:            #ea6c1c;   --l2-bg: #fdf0e7;
  --l3:            #dc2626;   --l3-bg: #fdeaea;
  --ok:            #0aa06e;   --ok-bg: #e6f7f1;

  --accent:        #2563eb;   --accent-bg: #eaf1fe;

  --r:  10px;
  --rs: 6px;
  --sh: 0 1px 2px rgba(16,24,40,.04), 0 1px 3px rgba(16,24,40,.06);
  --sh-lg: 0 12px 32px rgba(16,24,40,.16);
  --mono: "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg); color: var(--text);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input { font-family: inherit; font-size: 13px; color: var(--text); }

.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--text-3); }
.sep { color: var(--text-3); margin: 0 5px; }
.up { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--text-2); }

/* ---------------- 顶栏 ---------------- */

.topbar {
  position: sticky; top: 0; z-index: 60;
  display: flex; align-items: center; gap: 22px; padding: 11px 22px;
  background: rgba(255,255,255,.9); backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 29px; height: 29px; border-radius: 8px; flex: none; position: relative;
  background: linear-gradient(145deg, #e63232, #ea6c1c);
  box-shadow: 0 2px 6px rgba(230,50,50,.25);
}
.brand-mark::after {
  content: ""; position: absolute; inset: 8px 7px;
  border-left: 2px solid #fff; border-bottom: 2px solid #fff;
}
.brand h1 { font-size: 15px; font-weight: 650; letter-spacing: -.2px; }
.brand-sub { font-size: 11px; color: var(--text-3); }

.market-state {
  display: flex; align-items: center; font-size: 12.5px; color: var(--text-2);
  padding: 5px 13px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 20px;
}
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); margin-right: 7px; flex: none; }
.dot.live { background: var(--up); box-shadow: 0 0 0 3px var(--up-bg); animation: pulse 2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .3 } }
#mkt-time { font-size: 12px; }

.topbar-actions { margin-left: auto; display: flex; gap: 6px; }
.icon-btn {
  padding: 6px 11px; border-radius: var(--rs); font-size: 12.5px; color: var(--text-2);
  border: 1px solid var(--border); background: var(--surface); transition: .15s; white-space: nowrap;
}
.icon-btn:hover { border-color: var(--border-2); color: var(--text); }
.icon-btn.on { background: var(--accent-bg); border-color: #bcd3fb; color: var(--accent); }
.icon-btn.primary { background: var(--text); color: #fff; border-color: var(--text); }
.icon-btn.primary:hover { opacity: .88; }

/* ---------------- 资产概览 ---------------- */

.summary {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px;
  margin: 16px 22px 0; background: var(--border);
  border: 1px solid var(--border); border-radius: var(--r); overflow: hidden;
}
.sum-item { background: var(--surface); padding: 13px 18px; }
.sum-label { font-size: 11.5px; color: var(--text-3); }
.sum-value { font-size: 21px; font-weight: 640; letter-spacing: -.4px; margin-top: 2px; }
.risk-summary .sum-value { font-size: 15px; font-weight: 600; padding-top: 5px; }
.risk-chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px;
  border-radius: 5px; font-size: 12.5px; font-weight: 600;
}
.risk-chip.ok { background: var(--ok-bg); color: var(--ok); }
.risk-chip.l1 { background: var(--l1-bg); color: var(--l1); }
.risk-chip.l2 { background: var(--l2-bg); color: var(--l2); }
.risk-chip.l3 { background: var(--l3-bg); color: var(--l3); }
.risk-chip.data { background: var(--l1-bg); color: #96690a; }

@media (max-width: 820px) { .summary { grid-template-columns: repeat(2, 1fr); } }

/* ---------------- 列表 ---------------- */

.main { padding: 14px 22px 20px; }

.list-head { display: flex; align-items: center; margin-bottom: 10px; }
.lh-title { font-size: 14px; font-weight: 620; }
.count {
  display: inline-block; margin-left: 6px; padding: 0 7px; border-radius: 9px;
  background: var(--border); color: var(--text-2); font-size: 11.5px; font-weight: 600;
}
.lh-tools { margin-left: auto; display: flex; gap: 2px; background: var(--surface); border: 1px solid var(--border); border-radius: 7px; padding: 2px; }
.sort-btn { padding: 4px 11px; border-radius: 5px; font-size: 12px; color: var(--text-2); transition: .14s; }
.sort-btn.active { background: var(--text); color: #fff; font-weight: 550; }

.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); overflow: hidden; }

.thead, .trow {
  display: grid;
  grid-template-columns: 1.6fr .85fr .85fr 1fr .95fr 1.1fr 2.3fr 1.5fr;
  gap: 10px; align-items: center;
}
.thead {
  padding: 9px 18px; background: var(--surface-2); border-bottom: 1px solid var(--border);
  font-size: 11.5px; color: var(--text-3); font-weight: 600;
}
.thead > div:not(.c-name):not(.c-risk):not(.c-act) { text-align: right; }

.trow {
  padding: 13px 18px; border-bottom: 1px solid #f2f4f7; cursor: pointer;
  transition: background .14s; position: relative;
}
.trow:last-child { border-bottom: none; }
.trow:hover { background: var(--surface-2); }
.trow::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: transparent; }
.trow.lv-1::before { background: var(--l1); }
.trow.lv-2::before { background: var(--l2); }
.trow.lv-3::before { background: var(--l3); }
.trow.lv-3 { background: linear-gradient(90deg, var(--l3-bg), transparent 40%); }
.trow.lv-2 { background: linear-gradient(90deg, var(--l2-bg), transparent 40%); }
.trow.data-bad { background: linear-gradient(90deg, var(--l1-bg), transparent 40%); }
.trow.data-bad::before { background: var(--l1); }

.loading-row { padding: 40px; text-align: center; color: var(--text-3); font-size: 13px; }

.c-name { min-width: 0; }
.cn-name { font-size: 14.5px; font-weight: 620; letter-spacing: -.2px; display: flex; align-items: center; gap: 6px; }
.cn-code { font-size: 11px; color: var(--text-3); font-family: var(--mono); margin-top: 1px; }
.tag-etf { font-size: 9.5px; padding: 0 4px; border-radius: 3px; background: var(--accent-bg); color: var(--accent); font-weight: 600; }

.c-price, .c-chg, .c-pos, .c-mv, .c-pl { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.c-price { font-size: 16px; font-weight: 620; letter-spacing: -.3px; }
.c-chg { font-size: 13.5px; font-weight: 580; }
.c-chg .amt { display: block; font-size: 11px; opacity: .75; font-weight: 400; }
.c-pos { font-size: 12.5px; color: var(--text-2); }
.c-pos .cost { display: block; font-size: 11px; color: var(--text-3); }
.c-mv { font-size: 13.5px; }
.c-pl { font-size: 13.5px; font-weight: 580; }
.c-pl .rate { display: block; font-size: 11px; font-weight: 400; opacity: .8; }

/* 风险信号列 */
.c-risk { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.sig {
  display: inline-flex; align-items: center; gap: 3px; padding: 2px 7px;
  border-radius: 4px; font-size: 11.5px; font-weight: 560; white-space: nowrap;
  border: 1px solid transparent;
}
.sig.s1 { background: var(--l1-bg); color: #96690a; border-color: #f0e0b8; }
.sig.s2 { background: var(--l2-bg); color: var(--l2); border-color: #f7d3ba; }
.sig.s3 { background: var(--l3-bg); color: var(--l3); border-color: #f5c2c2; }
.sig.data { background: var(--l1-bg); color: #96690a; border-color: #f0e0b8; }
.sig-none { font-size: 12px; color: var(--text-3); }
.sig-more { font-size: 11px; color: var(--text-3); }

/* 建议动作列 */
.c-act { display: flex; align-items: center; gap: 7px; }
.act-chip {
  padding: 4px 10px; border-radius: 5px; font-size: 12px; font-weight: 600; white-space: nowrap;
}
.act-chip.ok { background: var(--ok-bg); color: var(--ok); }
.act-chip.l1 { background: var(--l1-bg); color: #96690a; }
.act-chip.l2 { background: var(--l2); color: #fff; }
.act-chip.l3 { background: var(--l3); color: #fff; animation: blink 1.6s infinite; }
.act-chip.data { background: var(--l1-bg); color: #96690a; }
@keyframes blink { 0%,100% { opacity: 1 } 50% { opacity: .62 } }
.arrow { margin-left: auto; color: var(--text-3); font-size: 15px; }

@media (max-width: 1280px) {
  .thead, .trow { grid-template-columns: 1.5fr .8fr .8fr 0 0 1fr 2.2fr 1.4fr; }
  .c-pos, .c-mv { display: none; }
}
@media (max-width: 980px) {
  .thead { display: none; }
  .trow { grid-template-columns: 1.4fr .8fr .8fr 1.2fr; row-gap: 8px; }
  .c-pos, .c-mv, .c-pl { display: none; }
  .c-risk { grid-column: 1 / -1; }
  .c-act { grid-column: 1 / -1; }
}

/* 口诀条 */
.mantra-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  margin-top: 12px; padding: 11px 18px; font-size: 12.5px; color: var(--text-2);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r);
}
.mb-label {
  font-size: 10.5px; font-weight: 650; color: var(--text-3); letter-spacing: 1px;
  padding: 2px 8px; background: var(--bg); border-radius: 4px;
}
.mantra-bar i { width: 1px; height: 12px; background: var(--border-2); display: inline-block; }

.foot { padding: 6px 22px 26px; text-align: center; font-size: 11.5px; color: var(--text-3); }

/* ---------------- 抽屉 ---------------- */

.mask {
  position: fixed; inset: 0; background: rgba(16,24,40,.34); z-index: 90;
  opacity: 0; pointer-events: none; transition: .22s;
}
.mask.open { opacity: 1; pointer-events: auto; }

.detail-drawer, .set-drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 100;
  background: var(--surface); box-shadow: var(--sh-lg);
  transform: translateX(100%); transition: transform .26s cubic-bezier(.4,0,.2,1);
  display: flex; flex-direction: column;
}
.detail-drawer { width: 620px; max-width: 96vw; }
.set-drawer { width: 470px; max-width: 94vw; }
.detail-drawer.open, .set-drawer.open { transform: none; }

.dd-head {
  display: flex; align-items: center; gap: 14px; padding: 14px 18px;
  border-bottom: 1px solid var(--border); flex: none;
}
.dd-title { min-width: 0; }
.dd-name { font-size: 17px; font-weight: 650; letter-spacing: -.3px; }
.dd-meta { font-size: 11.5px; color: var(--text-3); margin-top: 1px; }
.dd-price { margin-left: auto; text-align: right; }
.dd-p { font-size: 21px; font-weight: 650; letter-spacing: -.4px; }
.dd-c { font-size: 12.5px; font-weight: 560; }

.dd-verdict {
  display: flex; align-items: center; gap: 13px; padding: 13px 18px;
  border-bottom: 1px solid var(--border); flex: none; border-left: 4px solid transparent;
}
.dd-verdict.lv-0 { background: var(--ok-bg); border-left-color: var(--ok); }
.dd-verdict.lv-1 { background: var(--l1-bg); border-left-color: var(--l1); }
.dd-verdict.lv-2 { background: var(--l2-bg); border-left-color: var(--l2); }
.dd-verdict.lv-3 { background: var(--l3-bg); border-left-color: var(--l3); }
.dd-verdict.data { background: var(--l1-bg); border-left-color: var(--l1); }
.ddv-tag {
  padding: 5px 12px; border-radius: 6px; font-size: 13px; font-weight: 650;
  background: #fff; white-space: nowrap; flex: none;
}
.dd-verdict.lv-0 .ddv-tag { color: var(--ok); }
.dd-verdict.lv-1 .ddv-tag { color: #96690a; }
.dd-verdict.lv-2 .ddv-tag { color: var(--l2); }
.dd-verdict.lv-3 .ddv-tag { background: var(--l3); color: #fff; }
.dd-verdict.data .ddv-tag { color: #96690a; }
.ddv-action { font-size: 15px; font-weight: 620; letter-spacing: -.2px; }
.ddv-reason { font-size: 12px; color: var(--text-2); margin-top: 1px; }

.dd-metrics {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(104px,1fr)); gap: 1px;
  background: var(--border); border-bottom: 1px solid var(--border); flex: none;
}
.ddm { background: var(--surface); padding: 9px 13px; }
.ddm-l { font-size: 10.5px; color: var(--text-3); }
.ddm-v { font-size: 14px; font-weight: 600; font-family: var(--mono); margin-top: 1px; }
.ddm-v.warn { color: var(--l2); }
.ddm-v.danger { color: var(--l3); }

.dd-chart-box { flex: none; border-bottom: 1px solid var(--border); }
.ddc-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 18px; font-size: 12px; color: var(--text-2); font-weight: 570;
}
.chart-tabs { display: flex; gap: 2px; background: var(--bg); border-radius: 6px; padding: 2px; }
.tab { padding: 3px 10px; border-radius: 4px; font-size: 11.5px; color: var(--text-2); }
.tab.active { background: var(--surface); color: var(--text); font-weight: 560; box-shadow: var(--sh); }
.dd-chart { height: 260px; }

.dd-body { overflow-y: auto; flex: 1; }

/* checklist 分组 */
.sec { border-bottom: 8px solid var(--bg); }
.sec-head {
  display: flex; align-items: center; gap: 8px; padding: 11px 18px;
  background: var(--surface-2); border-bottom: 1px solid var(--border);
  font-size: 12.5px; font-weight: 620; position: sticky; top: 0; z-index: 2;
}
.sec-count { font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 9px; margin-left: auto; }
.sec-count.zero { background: var(--border); color: var(--text-3); }
.sec-count.hit { background: var(--l2); color: #fff; }

.chk { display: flex; gap: 9px; padding: 8px 18px; border-bottom: 1px solid #f4f6f9; }
.chk:last-child { border-bottom: none; }
.chk.hit { background: var(--l2-bg); }
.chk.na { opacity: .38; }
.chk.pre { background: var(--accent-bg); }
.box {
  width: 15px; height: 15px; border-radius: 4px; flex: none; margin-top: 2px;
  border: 1.5px solid var(--border-2); background: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 10px; color: #fff; font-weight: 700;
}
.chk.hit .box { background: var(--l2); border-color: var(--l2); }
.chk.hit .box::after { content: "✓"; }
.chk.pre.hit .box { background: var(--accent); border-color: var(--accent); }
.chk-l { font-size: 12.5px; }
.chk.hit .chk-l { font-weight: 570; }
.chk-d { font-size: 11px; color: var(--text-3); margin-top: 1px; font-family: var(--mono); }

.acts { background: var(--surface-2); border-top: 1px solid var(--border); padding: 3px 0 5px; }
.acts-t { padding: 7px 18px 3px; font-size: 10.5px; font-weight: 640; color: var(--text-3); letter-spacing: .5px; }
.act { padding: 6px 18px; font-size: 12.5px; }
.act:not(.hit) { opacity: .45; }
.act.hit { background: var(--surface); font-weight: 570; }
.act.hit.a1 { box-shadow: inset 3px 0 0 var(--l1); }
.act.hit.a2 { box-shadow: inset 3px 0 0 var(--l2); color: var(--l2); }
.act.hit.a3 { box-shadow: inset 3px 0 0 var(--l3); color: var(--l3); }

/* ---------------- 设置 ---------------- */

.set-body { overflow-y: auto; padding: 16px 18px 40px; }
.set-block { margin-bottom: 22px; }
.set-block h3 {
  font-size: 10.5px; font-weight: 640; color: var(--text-3);
  letter-spacing: .6px; margin-bottom: 10px; text-transform: uppercase;
}
.field { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 9px; font-size: 13px; }
.field > span { color: var(--text-2); }
.field input[type=number], .field input[type=text], .field select {
  padding: 5px 9px; border: 1px solid var(--border); border-radius: var(--rs);
  background: #fff; width: 138px; text-align: right;
}
.field select { text-align: left; }
.field.cb { justify-content: flex-start; gap: 8px; }
.field.cb input { width: auto; }
.field input:focus, .field select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg); }

.stock-cfg { border: 1px solid var(--border); border-radius: var(--r); padding: 13px 14px; margin-bottom: 10px; background: var(--surface-2); }
.sc-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.sc-name { font-weight: 620; font-size: 13.5px; }
.sc-code { font-size: 11px; color: var(--text-3); font-family: var(--mono); }
.sc-del { margin-left: auto; font-size: 11.5px; color: var(--text-3); }
.sc-del:hover { color: var(--l3); }
.hint { font-size: 11px; color: var(--text-3); line-height: 1.6; margin: 4px 0 8px; }

.add-row { display: flex; gap: 8px; }
.add-row input { flex: 1; padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--rs); }
.btn-row { display: flex; gap: 8px; }
.mini-btn {
  padding: 4px 10px; border-radius: var(--rs); font-size: 12px;
  border: 1px solid var(--border); background: #fff; color: var(--text-2); transition: .14s;
}
.mini-btn:hover { border-color: var(--border-2); color: var(--text); }
.mini-btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.mini-btn.danger { color: var(--l3); border-color: #f3c9c9; }

/* ---------------- 提醒 ---------------- */

.alert-fab {
  position: fixed; right: 22px; bottom: 22px; z-index: 80;
  width: 46px; height: 46px; border-radius: 50%; background: var(--surface);
  border: 1px solid var(--border); box-shadow: var(--sh-lg); font-size: 18px;
}
.fab-badge {
  position: absolute; top: -3px; right: -3px; min-width: 18px; height: 18px;
  border-radius: 9px; background: var(--l3); color: #fff;
  font-size: 10.5px; font-weight: 700; line-height: 18px; padding: 0 5px;
  display: none;
}
.fab-badge.show { display: block; }

.alert-panel {
  position: fixed; right: 22px; bottom: 78px; z-index: 81;
  width: 340px; max-height: 440px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--sh-lg);
  display: none; flex-direction: column; overflow: hidden;
}
.alert-panel.open { display: flex; }
.ap-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
  font-size: 12.5px; font-weight: 620; background: var(--surface-2);
}
.ap-list { overflow-y: auto; }
.ap-list .empty { padding: 26px; text-align: center; color: var(--text-3); font-size: 12.5px; }
.alert {
  padding: 9px 14px; border-bottom: 1px solid #f4f6f9; border-left: 3px solid transparent;
  animation: slideIn .28s ease;
}
@keyframes slideIn { from { opacity: 0; transform: translateX(8px) } to { opacity: 1; transform: none } }
.alert.a1 { border-left-color: var(--l1); }
.alert.a2 { border-left-color: var(--l2); }
.alert.a3 { border-left-color: var(--l3); background: var(--l3-bg); }
.al-h { display: flex; align-items: center; gap: 6px; }
.al-s { font-size: 12.5px; font-weight: 620; }
.al-t { margin-left: auto; font-size: 10.5px; color: var(--text-3); font-family: var(--mono); }
.al-m { font-size: 12px; margin-top: 2px; line-height: 1.5; }

.toast-wrap { position: fixed; right: 22px; bottom: 80px; z-index: 200; display: flex; flex-direction: column; gap: 10px; max-width: 350px; }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--l2);
  border-radius: var(--r); padding: 12px 15px; box-shadow: var(--sh-lg);
  animation: toastIn .3s cubic-bezier(.2,.9,.3,1.3); cursor: pointer;
}
@keyframes toastIn { from { opacity: 0; transform: translateY(14px) scale(.97) } to { opacity: 1; transform: none } }
.toast.a3 { border-left-color: var(--l3); }
.toast.a1 { border-left-color: var(--l1); }
.toast-t { font-size: 13.5px; font-weight: 640; }
.toast-m { font-size: 12.5px; color: var(--text-2); margin-top: 3px; line-height: 1.5; }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: #d8dde5; border-radius: 5px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: #c3cad4; }
::-webkit-scrollbar-track { background: transparent; }
