:root {
  color-scheme: light;
  --bg: #f4f2ee;
  --side: #fbfaf7;
  --card: #fffefc;
  --line: #e9e4dc;
  --line-soft: #f1ede7;
  --text: #29302d;
  --muted: #88908b;
  --accent: #5f8a7c;
  --accent-soft: #e5eeea;
  --accent-ink: #ffffff;
  --up: #3f8a67;
  --down: #bf6d63;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(60, 52, 40, 0.04), 0 10px 30px rgba(60, 52, 40, 0.05);
  font-family: "PingFang SC", "Microsoft YaHei UI", "Segoe UI", sans-serif;
  font-size: 15px;
}
body[data-book="demo"] {
  --accent: #a9855f;
  --accent-soft: #f3ebe1;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; white-space: nowrap; }
input, select, textarea {
  width: 100%; background: #fff; border: 1px solid var(--line); border-radius: 12px;
  padding: 0.65rem 0.8rem; outline: none; transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
label { display: grid; gap: 0.4rem; color: var(--muted); font-size: 0.85rem; }
h1 { margin: 0; font-size: 1.7rem; font-weight: 600; letter-spacing: -0.02em; }
h2 { margin: 0; font-size: 1rem; font-weight: 600; }
.hidden { display: none !important; }
.muted { color: var(--muted); margin: 0.25rem 0 0; font-size: 0.88rem; line-height: 1.55; }
.eyebrow { margin: 0 0 0.3rem; font-size: 0.75rem; letter-spacing: 0.14em; color: var(--accent); font-weight: 600; }
.error { color: var(--down); min-height: 1.2em; margin: 0; font-size: 0.88rem; }
.status { margin: 0; color: var(--muted); font-size: 0.88rem; }
.up { color: var(--up); } .down { color: var(--down); }
.num { font-variant-numeric: tabular-nums; }

.primary { background: var(--accent); color: var(--accent-ink); border-radius: 12px; padding: 0.7rem 1.3rem; font-weight: 600; transition: filter 0.15s; white-space: nowrap; flex-shrink: 0; }
.primary:hover { filter: brightness(1.06); }
.soft { background: var(--accent-soft); color: var(--accent); border-radius: 10px; padding: 0.5rem 0.95rem; font-weight: 600; font-size: 0.88rem; }
.link { color: var(--muted); font-size: 0.88rem; padding: 0.3rem 0; }
.link:hover { color: var(--accent); }
.pill { background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 0.3rem 0.7rem; font-size: 0.8rem; font-weight: 600; white-space: nowrap; }

.brand { display: flex; align-items: center; gap: 0.6rem; font-size: 1.05rem; }
.mark { width: 26px; height: 26px; border-radius: 8px; background: linear-gradient(140deg, #7fa597, #c3a37d); position: relative; }
.mark::after { content: ""; position: absolute; inset: 7px 6px 8px; border-left: 2px solid #fff; border-bottom: 2px solid #fff; transform: skewY(-18deg); opacity: 0.9; }

/* Login */
.gate { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; position: relative; overflow: hidden; }
.gate-art { position: absolute; inset: auto 0 0; height: 45vh; opacity: 0.5; }
.gate-art svg { width: 100%; height: 100%; }
.gate-art path { fill: none; stroke: #c9d8d1; stroke-width: 2; }
.gate-card { position: relative; width: min(400px, 100%); background: var(--card); border: 1px solid var(--line); border-radius: 24px; box-shadow: var(--shadow); padding: 2rem; display: grid; gap: 1rem; }
.gate-card h1 { margin-top: 0.6rem; }

/* Portal */
.portal { min-height: 100vh; }
.portal-head { display: flex; justify-content: space-between; align-items: center; padding: 1.3rem 2rem; }
.portal-body { width: min(920px, calc(100% - 2rem)); margin: 6vh auto 3rem; }
.portal-body h1 { font-size: 2.1rem; }
.doors { display: grid; grid-template-columns: 1fr 1fr; gap: 1.2rem; margin-top: 2rem; }
.door {
  text-align: left; border-radius: 24px; padding: 1.6rem; min-height: 230px; display: flex; flex-direction: column; gap: 0.4rem;
  background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow); transition: transform 0.2s, box-shadow 0.2s; position: relative; overflow: hidden;
}
.door::before { content: ""; position: absolute; inset: 0 0 auto; height: 6px; }
.door.live::before { background: #6f9a8b; }
.door.demo::before { background: #c09a70; }
.door:hover { transform: translateY(-3px); box-shadow: 0 18px 40px rgba(60, 52, 40, 0.1); }
.door-tag { font-size: 0.78rem; color: var(--muted); letter-spacing: 0.08em; }
.door strong { font-size: 1.8rem; font-weight: 600; }
.door-eq { font-size: 1.1rem; color: var(--muted); font-variant-numeric: tabular-nums; margin-top: 1.4rem; }
.door-go { margin-top: auto; font-weight: 600; }
.door.live .door-go { color: #5f8a7c; }
.door.demo .door-go { color: #a9855f; }

/* Shell */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.side { background: var(--side); border-right: 1px solid var(--line); padding: 1.4rem 1rem; display: flex; flex-direction: column; gap: 1.4rem; position: sticky; top: 0; height: 100vh; }
.side .brand { padding: 0 0.5rem; }
.book-card { display: flex; align-items: center; gap: 0.7rem; padding: 0.8rem; border-radius: 14px; background: var(--accent-soft); }
.book-card small { display: block; color: var(--muted); font-size: 0.75rem; }
.book-card strong { color: var(--accent); }
.book-card .link { margin-left: auto; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px rgba(255,255,255,0.7); }
nav { display: grid; gap: 0.25rem; }
nav button { display: flex; align-items: center; gap: 0.7rem; padding: 0.7rem 0.8rem; border-radius: 12px; color: var(--muted); font-weight: 500; text-align: left; }
nav button svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
nav button:hover { background: var(--line-soft); color: var(--text); }
nav button.active { background: var(--card); color: var(--text); box-shadow: var(--shadow); }
nav button.active svg { stroke: var(--accent); }
.side-foot { margin-top: auto; display: grid; gap: 0.4rem; padding: 0 0.5rem; justify-items: start; }
.sync { font-size: 0.8rem; color: var(--muted); display: flex; align-items: center; gap: 0.45rem; }
.sync::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #c9c3b8; }
.sync.ok::before { background: var(--up); }
.sync.bad::before { background: var(--down); }

main { padding: 1.8rem 2.2rem 3rem; min-width: 0; }
.view { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1.1rem; max-width: 1180px; }
.view > *, .grid > *, .kpis > * { min-width: 0; }
.page-head { display: flex; justify-content: space-between; align-items: end; gap: 1rem; margin-bottom: 0.3rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel { padding: 1.2rem 1.3rem; }
.panel > header { display: flex; justify-content: space-between; align-items: start; gap: 1rem; margin-bottom: 1rem; }
.label { color: var(--muted); font-size: 0.84rem; }

/* Hero */
.hero { padding: 1.4rem 1.5rem 0.8rem; }
.hero-top { display: flex; justify-content: space-between; align-items: start; gap: 1rem; flex-wrap: wrap; }
.big { display: block; font-size: 2.6rem; font-weight: 600; letter-spacing: -0.03em; margin: 0.2rem 0; font-variant-numeric: tabular-nums; }
.change { font-size: 0.9rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.range { display: flex; background: var(--line-soft); border-radius: 10px; padding: 3px; }
.range button { padding: 0.4rem 0.8rem; border-radius: 8px; font-size: 0.82rem; color: var(--muted); }
.range button.active { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,0.06); }
.line-chart { height: 210px; margin-top: 0.6rem; position: relative; }
.line-chart svg { width: 100%; height: 100%; display: block; overflow: visible; }
.line-chart .area { fill: url(#eqfill); }
.line-chart .stroke { fill: none; stroke: var(--accent); stroke-width: 2.2; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.line-chart .grid-line { stroke: var(--line-soft); stroke-width: 1; vector-effect: non-scaling-stroke; }
.axis { display: flex; justify-content: space-between; color: var(--muted); font-size: 0.75rem; margin-top: 0.3rem; font-variant-numeric: tabular-nums; }
.chart-empty { height: 100%; display: grid; place-items: center; color: var(--muted); font-size: 0.88rem; text-align: center; border: 1px dashed var(--line); border-radius: 14px; padding: 1rem; }

/* KPI */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1.1rem; }
.kpi { padding: 1.1rem 1.2rem; display: grid; gap: 0.25rem; }
.kpi strong { font-size: 1.45rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.kpi small { color: var(--muted); font-size: 0.78rem; }

.grid { display: grid; grid-template-columns: 1.1fr 0.9fr; gap: 1.1rem; }
.alloc { display: grid; grid-template-columns: 170px 1fr; gap: 1.4rem; align-items: center; }
.donut svg { width: 170px; height: 170px; display: block; }
.donut text { font-size: 11px; fill: var(--muted); }
.donut .donut-num { font-size: 17px; font-weight: 600; fill: var(--text); }
.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.55rem; }
.legend li { display: grid; grid-template-columns: 10px 1fr auto; gap: 0.6rem; align-items: center; font-size: 0.9rem; }
.legend i { width: 10px; height: 10px; border-radius: 3px; }
.legend span:last-child { color: var(--muted); font-variant-numeric: tabular-nums; }

.pnl-row { display: grid; grid-template-columns: 7.5rem 1fr 5.5rem; gap: 0.7rem; align-items: center; margin: 0.6rem 0; font-size: 0.88rem; }
.pnl-track { height: 8px; border-radius: 99px; background: var(--line-soft); position: relative; overflow: hidden; }
.pnl-track span { position: absolute; top: 0; bottom: 0; border-radius: 99px; }
.pnl-track::after { content: ""; position: absolute; left: 50%; top: -2px; bottom: -2px; width: 1px; background: var(--line); }
.pnl-row strong { text-align: right; font-variant-numeric: tabular-nums; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.8rem 0.4rem; border-bottom: 1px solid var(--line-soft); font-variant-numeric: tabular-nums; }
th { color: var(--muted); font-weight: 500; font-size: 0.8rem; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fcfbf8; }
.coin { display: flex; align-items: center; gap: 0.6rem; font-weight: 600; }
.coin i { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-style: normal; font-size: 0.72rem; color: #fff; }
.share { display: flex; align-items: center; gap: 0.5rem; }
.share-bar { width: 64px; height: 6px; background: var(--line-soft); border-radius: 99px; overflow: hidden; }
.share-bar span { display: block; height: 100%; background: var(--accent); }

/* Chat */
.chat-view { height: calc(100vh - 4.8rem); grid-template-rows: auto 1fr auto; }
.model-pick { display: flex; align-items: center; gap: 0.6rem; }
.model-pick select { min-width: 220px; }
.chat-card { display: grid; grid-template-rows: auto 1fr auto; min-height: 0; overflow: hidden; }
.chat-empty { padding: 1.4rem 1.5rem 0; }
.chips { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.8rem; }
.chip { background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 0.5rem 0.9rem; font-size: 0.86rem; }
#messages { overflow: auto; padding: 1.2rem 1.5rem; display: flex; flex-direction: column; gap: 0.9rem; min-height: 0; }
.bubble { max-width: min(720px, 85%); padding: 0.8rem 1rem; border-radius: 16px; white-space: pre-wrap; line-height: 1.65; }
.bubble.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 5px; }
.bubble.assistant { align-self: flex-start; background: #f7f5f1; border-bottom-left-radius: 5px; }
.bubble.assistant:empty::after { content: "思考中…"; color: var(--muted); }
.composer { display: flex; gap: 0.7rem; align-items: end; padding: 0.9rem; border-top: 1px solid var(--line-soft); background: #fdfcfa; }
.composer textarea { resize: none; border-radius: 14px; max-height: 180px; }

/* Strategy */
.trade-status { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.trade-state { display: flex; align-items: center; gap: 0.8rem; }
.trade-state p { margin: 0.2rem 0 0; max-width: 560px; }
.dot.idle { background: #c9c3b8; box-shadow: none; }
.trade-actions { display: flex; gap: 0.6rem; align-items: center; }
.strategy-form { display: grid; grid-template-columns: 1fr 1fr; gap: 0.8rem; }
.strategy-form .check { display: flex; flex-direction: row; align-items: center; gap: 0.5rem; grid-column: 1 / -1; color: var(--down); }
.strategy-form .check input { width: auto; }
.save-row { display: flex; justify-content: flex-end; align-items: center; gap: 1rem; grid-column: 1 / -1; }
.sym-pick { position: relative; display: grid; gap: 0.4rem; color: var(--muted); font-size: 0.85rem; }
.sym-btn { display: flex; justify-content: space-between; align-items: center; gap: 0.6rem; width: 100%; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 0.65rem 0.8rem; color: var(--text); text-align: left; }
.sym-btn:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.sym-caret { color: var(--muted); font-size: 0.8rem; }
.sym-panel { position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 40; background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 0.8rem; }
.sym-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.25rem; max-height: 260px; overflow: auto; }
.sym-opt { display: flex; flex-direction: row; align-items: center; gap: 0.55rem; padding: 0.45rem 0.5rem; border-radius: 9px; color: var(--text); cursor: pointer; font-size: 0.88rem; }
.sym-opt:hover { background: var(--line-soft); }
.sym-opt input { width: auto; accent-color: var(--accent); }
.sym-custom { display: flex; gap: 0.5rem; margin-top: 0.7rem; }

/* Settings */
#settings-form { display: grid; gap: 1.1rem; }
.llm-list { display: grid; gap: 0.8rem; }
.llm-card { border: 1px solid var(--line); border-radius: 14px; padding: 1rem; display: grid; gap: 0.8rem; background: #fdfcfa; }
.llm-card.on { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.llm-head { display: flex; align-items: center; gap: 0.7rem; }
.llm-head input { font-weight: 600; max-width: 260px; }
.llm-head .link { margin-left: auto; }
.llm-fields { display: grid; grid-template-columns: 1.6fr 1fr 0.8fr 1.2fr; gap: 0.7rem; }
.okx-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.okx-card { border: 1px solid var(--line); border-radius: 14px; padding: 1rem; display: grid; gap: 0.75rem; background: #fdfcfa; }
.okx-card h3 { margin: 0; font-size: 0.95rem; display: flex; align-items: center; gap: 0.5rem; }
.okx-card h3 i { width: 8px; height: 8px; border-radius: 50%; }
.narrow { max-width: 220px; }
.save-bar { display: flex; justify-content: flex-end; align-items: center; gap: 1rem; position: sticky; bottom: 1rem; padding: 0.8rem 1rem; background: rgba(255, 254, 252, 0.9); backdrop-filter: blur(8px); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); }
.empty-note { color: var(--muted); font-size: 0.88rem; padding: 0.4rem 0; }

@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .grid { grid-template-columns: 1fr; }
  .llm-fields { grid-template-columns: 1fr 1fr; }
}
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

@media (max-width: 760px) {
  :root { font-size: 14px; --radius: 16px; }
  input, select, textarea { font-size: 16px; }
  h1 { font-size: 1.4rem; }

  .gate { padding: 1rem; align-items: start; padding-top: 12vh; }
  .gate-card { padding: 1.5rem; border-radius: 20px; }
  .portal-head { padding: 1rem 1.1rem; }
  .portal-body { margin-top: 2vh; }
  .portal-body h1 { font-size: 1.6rem; }
  .doors { grid-template-columns: 1fr; gap: 0.9rem; margin-top: 1.4rem; }
  .door { min-height: 150px; padding: 1.3rem; }
  .door-eq { margin-top: 0.6rem; }

  .shell { display: block; }
  .side {
    position: sticky; top: 0; z-index: 20; height: auto; flex-direction: row; align-items: center; gap: 0.6rem;
    padding: calc(0.6rem + env(safe-area-inset-top)) 1rem 0.6rem; background: var(--side);
    border-right: 0; border-bottom: 1px solid var(--line);
  }
  .side .brand { padding: 0; }
  .side .brand strong { display: none; }
  .book-card { flex: 1; padding: 0.45rem 0.7rem; gap: 0.55rem; }
  .book-card small { display: none; }
  .side-foot { margin: 0; padding: 0; }
  .sync { display: none; }
  nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; grid-template-columns: repeat(5, 1fr); gap: 0;
    padding: 0.35rem 0.5rem calc(0.35rem + env(safe-area-inset-bottom)); background: rgba(255, 254, 252, 0.96);
    backdrop-filter: blur(10px); border-top: 1px solid var(--line);
  }
  nav button { flex-direction: column; gap: 0.2rem; padding: 0.45rem 0; font-size: 0.75rem; justify-content: center; align-items: center; }
  nav button.active { background: none; box-shadow: none; color: var(--accent); }
  nav button svg { width: 22px; height: 22px; }

  main { padding: 1rem 0.9rem calc(5.5rem + env(safe-area-inset-bottom)); }
  .view { gap: 0.8rem; }
  .page-head { align-items: center; flex-wrap: wrap; }

  .hero { padding: 1.1rem 1.1rem 0.6rem; }
  .big { font-size: 2rem; }
  .range { width: 100%; }
  .range button { flex: 1; }
  .line-chart { height: 170px; }
  .axis span:nth-child(2) { display: none; }

  .kpis { grid-template-columns: 1fr 1fr; gap: 0.8rem; }
  .kpi { padding: 0.9rem 1rem; }
  .kpi strong { font-size: 1.2rem; }
  .kpi small { display: none; }
  .grid { gap: 0.8rem; }
  .panel { padding: 1rem; }
  .alloc { grid-template-columns: 1fr; gap: 1rem; }
  .donut { justify-self: center; }
  .pnl-row { grid-template-columns: 5.5rem 1fr 4.8rem; font-size: 0.82rem; }
  table { min-width: 520px; }
  th, td { padding: 0.7rem 0.35rem; }

  .chat-view { height: calc(100dvh - 10.3rem - env(safe-area-inset-top) - env(safe-area-inset-bottom)); min-height: 360px; }
  .chat-view .page-head h1 { display: none; }
  .model-pick { width: 100%; }
  .model-pick select { min-width: 0; flex: 1; }
  #messages { padding: 1rem; }
  .bubble { max-width: 88%; }
  .chat-empty { padding: 1rem 1rem 0; }
  .composer { padding: 0.6rem; }

  .llm-fields, .okx-grid, .strategy-form { grid-template-columns: 1fr; }
  .trade-status { align-items: stretch; flex-direction: column; }
  .llm-head input { max-width: none; }
  .narrow { max-width: none; }
  .save-bar { bottom: calc(4.8rem + env(safe-area-inset-bottom)); padding: 0.6rem 0.8rem; }
  .save-bar .primary { flex-shrink: 0; }
}
