/* ETF 交易系统 —— 深色金融风格,移动端优先自适应 */
:root {
  --bg: #0d1117;
  --bg2: #11161d;
  --card: #161c24;
  --card2: #1c232d;
  --border: #26303c;
  --text: #e6edf3;
  --muted: #8b98a5;
  --dim: #62707e;
  --up: #f0475a;        /* 中国市场惯例:涨=红 */
  --down: #2fbf71;      /* 跌=绿 */
  --accent: #4c8dff;
  --amber: #e8a33d;
  --blue: #4c8dff;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0);
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { color-scheme: dark; }
body {
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  font-size: 15px; line-height: 1.5;
  padding-bottom: calc(40px + var(--safe-b));
}

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: rgba(13,17,23,.88); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1080px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand .logo { color: var(--accent); font-size: 20px; }
.brand h1 { font-size: 17px; font-weight: 700; letter-spacing: .5px; }
.market-state { font-size: 12px; color: var(--muted); border: 1px solid var(--border); padding: 2px 8px; border-radius: 20px; }
.market-state.open { color: var(--up); border-color: rgba(240,71,90,.4); }
.nav { display: flex; gap: 4px; }
.nav a {
  color: var(--muted); text-decoration: none; font-size: 14px;
  padding: 6px 14px; border-radius: 8px; transition: .15s;
}
.nav a.active, .nav a:hover { color: var(--text); background: var(--card2); }

.container { max-width: 1080px; margin: 0 auto; padding: 16px; }

/* ---------- 首页 ---------- */
.home-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.home-head .sub { color: var(--dim); font-size: 13px; }
.filters { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 14px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.filters button {
  flex-shrink: 0; background: var(--card); color: var(--muted); border: 1px solid var(--border);
  padding: 6px 14px; border-radius: 20px; font-size: 13px; cursor: pointer; transition: .15s;
}
.filters button.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }

.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; cursor: pointer; transition: .15s; position: relative; overflow: hidden;
}
.card:hover { border-color: #3a4756; transform: translateY(-1px); }
.card .row1 { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.card .name { font-weight: 600; font-size: 15px; }
.card .code { color: var(--dim); font-size: 12px; font-family: ui-monospace, Consolas, monospace; }
.card .strat { display: inline-block; margin-top: 4px; font-size: 11px; color: var(--accent);
  background: rgba(76,141,255,.1); padding: 1px 8px; border-radius: 4px; }
.card .price-row { display: flex; align-items: baseline; gap: 8px; margin: 10px 0 8px; }
.card .price { font-size: 22px; font-weight: 700; font-family: ui-monospace, Consolas, monospace; }
.card .pct { font-size: 14px; font-weight: 600; font-family: ui-monospace, monospace; }
.pos { color: var(--up); } .neg { color: var(--down); } .flat { color: var(--muted); }

.badge { font-size: 12px; padding: 3px 10px; border-radius: 6px; font-weight: 600; white-space: nowrap; }
.badge.buy_signal { background: rgba(240,71,90,.16); color: var(--up); }
.badge.sell_signal { background: rgba(47,191,113,.14); color: var(--down); }
.badge.near_buy { background: rgba(232,163,61,.14); color: var(--amber); }
.badge.near_sell { background: rgba(232,163,61,.14); color: var(--amber); }
.badge.holding { background: rgba(76,141,255,.13); color: var(--blue); }
.badge.watching { background: rgba(139,152,165,.12); color: var(--muted); }

.dist { margin-top: 6px; }
.dist .lbl { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.dist .lbl b { font-family: ui-monospace, monospace; }
.bar { height: 6px; border-radius: 3px; background: var(--card2); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 3px; transition: width .4s; }
.bar.buy > i { background: linear-gradient(90deg, #7a2c37, var(--up)); }
.bar.sell > i { background: linear-gradient(90deg, #1d5c3c, var(--down)); }
.card .entry { margin-top: 8px; font-size: 12px; color: var(--dim); }

/* ---------- 详情页 ---------- */
.back { color: var(--muted); text-decoration: none; font-size: 14px; display: inline-block; margin-bottom: 12px; }
.back:hover { color: var(--text); }
.detail-head { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 14px; }
.detail-head .t { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; }
.detail-head .t h2 { font-size: 20px; }
.detail-head .t .code { color: var(--dim); font-size: 14px; margin-left: 8px; font-family: monospace; }
.detail-head .price-row { margin-top: 8px; display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.detail-head .price { font-size: 30px; font-weight: 700; font-family: ui-monospace, monospace; }
.meta-line { color: var(--dim); font-size: 12.5px; margin-top: 6px; }

.panel { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.panel h3 { font-size: 15px; margin-bottom: 12px; color: var(--text); }
.panel h3 .tag { font-size: 11px; color: var(--dim); font-weight: 400; margin-left: 8px; }
.chart-box { width: 100%; }
.chart-box svg { width: 100%; height: auto; display: block; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 3px; border-radius: 2px; margin-right: 4px; vertical-align: middle; }

.check-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 640px) { .check-grid { grid-template-columns: 1fr; } }
.check-col h4 { font-size: 13px; margin-bottom: 8px; color: var(--muted); }
.check-item { display: flex; align-items: flex-start; gap: 8px; padding: 8px 10px; border-radius: 8px; background: var(--card2); margin-bottom: 6px; font-size: 13px; }
.check-item .mark { font-weight: 700; width: 18px; text-align: center; flex-shrink: 0; }
.check-item.ok .mark { color: var(--up); }
.check-item.no .mark { color: var(--dim); }
.check-item .v { color: var(--muted); font-size: 12px; display: block; font-family: ui-monospace, monospace; }
.check-col.inactive { opacity: .45; }

.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.kv .item { background: var(--card2); border-radius: 8px; padding: 8px 10px; }
.kv .k { font-size: 12px; color: var(--dim); }
.kv .v { font-size: 14px; font-weight: 600; font-family: ui-monospace, monospace; margin-top: 2px; }

.rules-list { font-size: 13.5px; color: var(--muted); }
.rules-list li { margin: 6px 0 6px 18px; }
.rules-list b { color: var(--text); }
.param-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.param-chips span { font-size: 12px; background: var(--card2); border: 1px solid var(--border); padding: 2px 10px; border-radius: 12px; color: var(--muted); font-family: monospace; }

.bt-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.bt-grid .item { background: var(--card2); border-radius: 8px; padding: 10px; text-align: center; }
.bt-grid .v { font-size: 17px; font-weight: 700; font-family: ui-monospace, monospace; }
.bt-grid .k { font-size: 12px; color: var(--dim); margin-top: 2px; }
.bt-note { font-size: 12px; color: var(--dim); margin-top: 10px; line-height: 1.6; }

/* ---------- 信号页 ---------- */
.sig-item { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.sig-item .left { display: flex; flex-direction: column; gap: 2px; }
.sig-item .title { font-weight: 600; font-size: 14px; }
.sig-item .msg { color: var(--muted); font-size: 12.5px; }
.sig-item .when { color: var(--dim); font-size: 12px; font-family: monospace; }
.sig-type { font-size: 12px; padding: 3px 10px; border-radius: 6px; font-weight: 600; white-space: nowrap; }
.sig-type.buy, .sig-type.warn_buy { background: rgba(240,71,90,.16); color: var(--up); }
.sig-type.sell, .sig-type.stop_sell, .sig-type.warn_sell { background: rgba(47,191,113,.14); color: var(--down); }

/* ---------- 设置页 ---------- */
.form { display: flex; flex-direction: column; gap: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.field input {
  width: 100%; background: var(--card2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 9px 12px; font-size: 14px; outline: none;
}
.field input:focus { border-color: var(--accent); }
.field .hint { font-size: 12px; color: var(--dim); margin-top: 4px; line-height: 1.5; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--accent); color: #fff; border: none; border-radius: 9px;
  padding: 10px 18px; font-size: 14px; font-weight: 600; cursor: pointer; transition: .15s;
}
.btn:hover { filter: brightness(1.1); }
.btn.ghost { background: var(--card2); color: var(--text); border: 1px solid var(--border); }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- Toast ---------- */
.toast-wrap { position: fixed; top: 14px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; width: min(92vw, 420px); }
.toast { background: var(--card2); border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: 10px; padding: 11px 14px; font-size: 13.5px; box-shadow: 0 6px 24px rgba(0,0,0,.45); animation: slideIn .25s ease; }
.toast.buy { border-left-color: var(--up); }
.toast.sell { border-left-color: var(--down); }
.toast.err { border-left-color: var(--amber); }
@keyframes slideIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; } }

.empty { text-align: center; color: var(--dim); padding: 40px 0; font-size: 14px; }
.loading { text-align: center; color: var(--dim); padding: 60px 0; }
.spin { display: inline-block; width: 22px; height: 22px; border: 2.5px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: rot 0.8s linear infinite; }
@keyframes rot { to { transform: rotate(360deg); } }

@media (max-width: 560px) {
  .topbar-inner { padding: 8px 12px; }
  .container { padding: 12px; }
  .brand h1 { font-size: 15px; }
  .nav a { padding: 5px 10px; font-size: 13px; }
  .detail-head .price { font-size: 24px; }
}

/* ---------- v6.0 BOLL 位置面板 ---------- */
.rules-note {
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 14px; font-size: 13px; color: var(--muted); line-height: 1.7; margin-bottom: 14px;
}
.rules-note b { color: var(--text); }
.band-block { margin: 10px 0 4px; }
.band-title { font-size: 12px; color: var(--dim); margin-bottom: 6px; }
.band-track {
  position: relative; height: 14px; border-radius: 7px; margin: 14px 0 4px;
  background: linear-gradient(90deg, #2fbf7133, #4c8dff22, #f0475a33);
  border: 1px solid var(--border);
}
.band-track::before {
  content: ""; position: absolute; left: 25%; right: 25%; top: 0; bottom: 0;
  border-left: 1px dashed var(--dim); border-right: 1px dashed var(--dim); opacity: .4;
}
.band-track::after {
  content: ""; position: absolute; left: 50%; top: 0; bottom: 0;
  border-left: 1px dashed var(--dim); opacity: .4;
}
.band-ptr { position: absolute; top: -7px; transform: translateX(-50%); text-align: center; z-index: 2; }
.band-ptr i {
  display: block; width: 12px; height: 12px; border-radius: 50%;
  background: #ffd166; border: 2px solid #0d1117; margin: 0 auto; box-shadow: 0 0 6px #ffd16688;
}
.band-ptr b {
  display: block; font-size: 11px; color: #ffd166; font-family: ui-monospace, monospace;
  white-space: nowrap; margin-top: 1px;
}
.band-ptr.low-out i { background: #2fbf71; box-shadow: 0 0 6px #2fbf7188; }
.band-ptr.low-out b { color: #2fbf71; }
.band-ptr.up-out i { background: #f0475a; box-shadow: 0 0 6px #f0475a88; }
.band-ptr.up-out b { color: #f0475a; }
.band-ticks {
  display: flex; justify-content: space-between; font-size: 11px; color: var(--dim);
  font-family: ui-monospace, monospace; margin-top: 2px;
}
.dist-line {
  display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted);
  margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--border);
}
.dist-line b { font-family: ui-monospace, monospace; }

/* ---------- v7 动态自选 + 交易记录 ---------- */
.page-title { font-size: 18px; font-weight: 700; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.badges { display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }
.add-panel { margin-bottom: 14px; }
.add-form { display: grid; grid-template-columns: 1.3fr 1.2fr 1fr auto; gap: 8px; }
.add-form input {
  width: 100%; background: var(--card2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 9px 12px; font-size: 14px; outline: none;
}
.add-form input:focus { border-color: var(--accent); }
@media (max-width: 720px) { .add-form { grid-template-columns: 1fr; } }
.hint { font-size: 12px; color: var(--dim); margin-top: 8px; line-height: 1.6; }
.card-actions { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 10px; padding-top: 8px; border-top: 1px dashed var(--border); }
.detail-link { color: var(--dim); font-size: 12px; }
.card:hover .detail-link { color: var(--accent); }
.btn.tiny { padding: 5px 10px; font-size: 12px; border-radius: 7px; }
.btn.buy { background: var(--up); }
.btn.sell { background: var(--down); }
.five-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.five-grid > div { background: var(--card2); border-radius: 8px; padding: 8px 10px; text-align: center; }
.five-grid span { display: block; color: var(--dim); font-size: 11px; }
.five-grid b { font-family: ui-monospace, monospace; font-size: 14px; }
.pos-summary { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; margin-bottom: 10px; }
.pos-summary > div { background: var(--card2); border-radius: 8px; padding: 8px 10px; }
.pos-summary span { display: block; color: var(--dim); font-size: 11px; }
.pos-summary b { font-family: ui-monospace, monospace; font-size: 14px; }
.table-wrap { width: 100%; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 12.5px; white-space: nowrap; }
.table th { text-align: left; color: var(--dim); font-weight: 500; padding: 7px 8px; border-bottom: 1px solid var(--border); }
.table td { padding: 8px; border-bottom: 1px solid rgba(38,48,60,.55); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table a { color: var(--text); text-decoration: none; }
.table a:hover { color: var(--accent); }
.empty.small { padding: 12px 0; font-size: 12px; }
.sig-actions { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.modal-overlay {
  position: fixed; inset: 0; z-index: 200; background: rgba(0,0,0,.62);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal {
  width: min(96vw, 460px); max-height: 90vh; overflow-y: auto;
  background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  padding: 16px; box-shadow: 0 18px 60px rgba(0,0,0,.55);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.modal-head h3 { font-size: 16px; }
.modal-x { background: transparent; border: none; color: var(--muted); font-size: 24px; line-height: 1; cursor: pointer; }
.trade-form label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); }
.trade-form input, .trade-form select {
  background: var(--card2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 9px 12px; font-size: 14px; outline: none;
}
.trade-form input:focus, .trade-form select:focus { border-color: var(--accent); }
.trade-target { font-weight: 700; color: var(--text); font-size: 15px; }
.trade-target .code { color: var(--dim); font-weight: 400; font-family: ui-monospace, monospace; font-size: 12px; }
@media (max-width: 560px) {
  .five-grid { grid-template-columns: repeat(3, 1fr); }
  .badges { align-items: flex-start; }
  .card .row1 { flex-wrap: wrap; }
}
