:root {
  --bg-0: #eef2f8; --bg-1: #ffffff; --bg-2: #ffffff; --bg-3: #eef2f7; --surface: #ffffff;
  --line: #e4e9f1; --line-soft: #eef1f6;
  --text: #1f2a3a; --muted: #69748a; --dim: #9aa6b8;
  --long: #11a06a; --long-dim: #0d8a5b; --short: #e2495f; --short-dim: #c93a50;
  --accent: #2f76e6; --accent-2: #8a5cf0; --gold: #d9952a; --warn: #e08a2b; --bad: #e2495f;
  --long-bg: rgba(17,160,106,0.12); --short-bg: rgba(226,73,95,0.12);
  --mono: "JetBrains Mono", "SF Mono", "Roboto Mono", ui-monospace, Menlo, monospace;
  --sans: "Inter", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --radius: 12px; --shadow: 0 6px 22px rgba(40,60,90,0.07); --shadow-lg: 0 14px 40px rgba(40,60,90,0.12);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: radial-gradient(1100px 640px at 85% -12%, #e7eefb 0%, var(--bg-0) 58%); color: var(--text); font-family: var(--sans); -webkit-font-smoothing: antialiased; }
#app { height: 100vh; }
button { font-family: inherit; cursor: pointer; }
a { color: var(--accent); }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.long { color: var(--long); } .short { color: var(--short); } .muted { color: var(--muted); } .dim { color: var(--dim); }
.pos { color: var(--long); } .neg { color: var(--short); }

/* ---------- login ---------- */
.login-wrap { height: 100vh; display: grid; place-items: center; }
.login-card { width: 360px; background: linear-gradient(180deg, var(--bg-2), var(--bg-1)); border: 1px solid var(--line); border-radius: 16px; padding: 32px; box-shadow: var(--shadow); }
.login-card h1 { font-size: 20px; margin: 0 0 4px; letter-spacing: .5px; }
.login-card .sub { color: var(--muted); font-size: 13px; margin-bottom: 22px; }
.login-card .brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--long); display: inline-block; margin-right: 8px; box-shadow: 0 0 12px var(--long); }
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12px; color: var(--muted); }
input, select { background: #f6f8fc; border: 1px solid var(--line); color: var(--text); border-radius: 9px; padding: 11px 12px; font-family: var(--mono); font-size: 14px; outline: none; }
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47,118,230,0.12); }
.btn { background: var(--accent); color: #fff; border: 0; border-radius: 9px; padding: 11px 14px; font-weight: 700; font-size: 14px; width: 100%; transition: filter .15s; }
.btn:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); width: auto; }
.btn.ghost:hover { border-color: var(--accent); }
.btn.danger { background: var(--short); color: #fff; }
.btn.sm { padding: 6px 10px; font-size: 12px; }
.err-line { color: var(--bad); font-size: 12px; min-height: 16px; margin-top: 6px; }

/* ---------- app shell ---------- */
.shell { display: grid; grid-template-columns: 64px 1fr; height: 100vh; }
.rail { background: var(--bg-1); border-right: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; padding: 14px 0; gap: 6px; }
.rail .logo { width: 34px; height: 34px; border-radius: 9px; background: linear-gradient(135deg, #2f76e6, #8a5cf0); display: grid; place-items: center; font-weight: 800; color: #fff; margin-bottom: 14px; }
.rail .logo svg { width: 18px; height: 18px; display: block; }
.rail .nav-btn { width: 44px; height: 44px; border-radius: 11px; background: transparent; border: 0; color: var(--muted); display: grid; place-items: center; position: relative; }
.rail .nav-btn svg { width: 22px; height: 22px; }
.rail .nav-btn:hover { background: var(--bg-3); color: var(--text); }
.rail .nav-btn.active { background: var(--bg-3); color: var(--accent); }
.rail .nav-btn.active::before { content: ""; position: absolute; left: -14px; top: 11px; height: 22px; width: 3px; border-radius: 2px; background: var(--accent); }
.rail .nav-btn .tip { position: absolute; left: 52px; white-space: nowrap; background: var(--bg-3); border: 1px solid var(--line); padding: 4px 8px; border-radius: 7px; font-size: 12px; opacity: 0; pointer-events: none; transition: opacity .12s; z-index: 40; }
.rail .nav-btn:hover .tip { opacity: 1; }
.rail .spacer { flex: 1; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar { height: 52px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 14px; padding: 0 16px; background: var(--bg-1); }
.topbar .title { font-weight: 700; font-size: 15px; }
.topbar .crumbs { color: var(--muted); font-size: 13px; }
.topbar .grow { flex: 1; }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--bg-2); color: var(--muted); }
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--dim); }
.pill.ok .dot { background: var(--long); box-shadow: 0 0 8px var(--long); }
.pill.bad .dot { background: var(--short); box-shadow: 0 0 8px var(--short); }
.pill.warn .dot { background: var(--warn); }
.content { flex: 1; overflow: auto; padding: 16px; }

/* ---------- cards / grid ---------- */
.card { background: linear-gradient(180deg, var(--bg-2), var(--bg-1)); border: 1px solid var(--line); border-radius: var(--radius); }
.card .hd { display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-bottom: 1px solid var(--line-soft); font-size: 13px; font-weight: 600; }
.card .hd .grow { flex: 1; }
.card .bd { padding: 12px 14px; }
.grid { display: grid; gap: 14px; }
.kpi { display: grid; gap: 3px; }
.kpi .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.kpi .v { font-size: 22px; font-weight: 700; font-family: var(--mono); }
.kpi .v.sm { font-size: 17px; }
.chip { font-size: 11px; padding: 2px 8px; border-radius: 6px; background: var(--bg-3); color: var(--muted); border: 1px solid var(--line-soft); }
.chip.long { background: var(--long-bg); color: var(--long); border-color: transparent; }
.chip.short { background: var(--short-bg); color: var(--short); border-color: transparent; }
.chip.on { background: rgba(47,118,230,.12); color: var(--accent); border-color: transparent; }
.chip.toggle { cursor: pointer; user-select: none; transition: background .12s, color .12s; }
.chip.toggle:hover { border-color: var(--accent); color: var(--text); }
.chip.toggle.on:hover { color: var(--accent); }

/* tables */
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th { text-align: left; color: var(--muted); font-weight: 500; font-size: 11px; text-transform: uppercase; letter-spacing: .4px; padding: 8px 10px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--bg-1); }
table.tbl td { padding: 8px 10px; border-bottom: 1px solid var(--line-soft); font-family: var(--mono); }
table.tbl tr:hover td { background: var(--bg-3); }
.num { text-align: right; font-family: var(--mono); }

/* k-line layout */
.kline-layout { display: grid; grid-template-columns: 1fr 320px; gap: 14px; height: calc(100vh - 52px - 32px); }
.kline-main { display: flex; flex-direction: column; min-width: 0; }
.kline-toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.kchart { position: relative; flex: 1; min-height: 0; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--bg-1); }
.chart-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--dim); font-size: 13px; pointer-events: none; }
.side-col { display: flex; flex-direction: column; gap: 14px; overflow: auto; }
.seg { display: inline-flex; background: var(--bg-2); border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg button { background: transparent; border: 0; color: var(--muted); padding: 6px 11px; font-size: 12px; font-family: var(--mono); }
.seg button.on { background: var(--bg-3); color: var(--text); }
.pair-select { min-width: 150px; }

/* gate chain (why-trade explainer) */
.gate-row { display: flex; align-items: center; gap: 8px; padding: 7px 4px; border-bottom: 1px solid var(--line-soft); font-size: 13px; }
.gate-row .ic { width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; flex: 0 0 auto; }
.gate-row .ic.pass { background: var(--long-bg); color: var(--long); }
.gate-row .ic.fail { background: var(--short-bg); color: var(--short); }
.gate-row .ic.idle { background: var(--bg-3); color: var(--dim); }
.gate-row .lbl { flex: 1; }
.gate-row .val { font-family: var(--mono); color: var(--muted); font-size: 12px; }

/* factor inspector */
.factor-search { width: 100%; margin-bottom: 8px; }
.factor-group { margin-bottom: 6px; }
.factor-group .gh { font-size: 11px; color: var(--accent-2); text-transform: uppercase; letter-spacing: .5px; padding: 6px 2px 3px; position: sticky; top: 0; background: var(--bg-1); }
.factor-item { display: flex; justify-content: space-between; gap: 8px; padding: 3px 4px; font-size: 12px; border-bottom: 1px solid var(--line-soft); }
.factor-item .fl { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.factor-item .fv { font-family: var(--mono); flex: 0 0 auto; }

/* heatmap cells (cockpit) */
.weight-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 8px; }
.wcell { border-radius: 10px; padding: 10px; border: 1px solid var(--line); background: var(--bg-2); position: relative; overflow: hidden; transition: transform .1s; }
.wcell:hover { transform: translateY(-2px); border-color: var(--accent); }
.wcell .p { font-size: 12px; font-weight: 700; }
.wcell .w { font-size: 18px; font-family: var(--mono); margin-top: 3px; }
.wcell .meta { font-size: 10px; color: var(--muted); margin-top: 4px; display: flex; gap: 6px; }
.wcell .bar { position: absolute; left: 0; bottom: 0; height: 3px; }

/* toast */
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--bg-3); border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 9px; padding: 10px 14px; font-size: 13px; min-width: 220px; box-shadow: var(--shadow); animation: slidein .2s ease; }
.toast.bad { border-left-color: var(--short); }
.toast.good { border-left-color: var(--long); }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(28,42,66,.38); backdrop-filter: blur(2px); display: grid; place-items: center; z-index: 90; }
.modal { width: 420px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 14px; padding: 22px; box-shadow: var(--shadow); }
.modal h3 { margin: 0 0 6px; }
.modal p { color: var(--muted); font-size: 13px; margin: 0 0 16px; }
.row { display: flex; gap: 10px; }
.row.end { justify-content: flex-end; }
.spin { width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: sp .7s linear infinite; display: inline-block; }
@keyframes sp { to { transform: rotate(360deg); } }
.loading-block { display: grid; place-items: center; padding: 40px; color: var(--muted); gap: 10px; }
.empty-block { display: grid; place-items: center; padding: 30px; color: var(--dim); font-size: 13px; gap: 6px; }
