:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e5e9f0;
  --text: #16203a;
  --muted: #6b7a99;
  --primary: #2563eb;
  --primary-soft: #e8efff;
  --up: #dc2626;      /* 涨价 红 */
  --down: #16a34a;    /* 降价 绿 */
  --warn: #d97706;
  --shadow: 0 2px 10px rgba(20, 35, 70, .05), 0 12px 32px rgba(20, 35, 70, .05);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1220; --surface: #151c2e; --surface-2: #1b2438;
    --border: #28324a; --text: #e8edf8; --muted: #8b9ab8;
    --primary: #5b8cff; --primary-soft: #1c2c4d;
    --up: #f87171; --down: #4ade80; --warn: #fbbf24;
    --shadow: 0 2px 10px rgba(0,0,0,.25), 0 12px 32px rgba(0,0,0,.25);
  }
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px; line-height: 1.6;
}
.app { max-width: 1560px; margin: 0 auto; padding: 22px 26px 40px; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 20px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  width: 46px; height: 46px; border-radius: 13px; display: grid; place-items: center;
  background: linear-gradient(135deg, #2563eb, #7c3aed); color: #fff; font-size: 24px; font-weight: 700;
  box-shadow: 0 6px 18px rgba(37,99,235,.28);
}
.brand h1 { margin: 0; font-size: 20px; letter-spacing: .3px; }
.brand p { margin: 1px 0 0; color: var(--muted); font-size: 12px; }
.topbar-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.conn { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; padding: 6px 13px; font-size: 12px; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); box-shadow: 0 0 0 3px rgba(217,119,6,.15); }
.dot.on { background: var(--down); box-shadow: 0 0 0 3px rgba(22,163,74,.15); }
.dot.off { background: var(--up); box-shadow: 0 0 0 3px rgba(220,38,38,.15); }
.token-wrap { display: flex; gap: 6px; }
.token-wrap input { width: 210px; }

.offline-banner { background: #fff4e5; color: #92400e; border: 1px solid #fcd9a4; border-radius: 10px;
  padding: 10px 16px; margin-bottom: 16px; font-size: 13px; }
@media (prefers-color-scheme: dark) { .offline-banner { background: #3a2a13; color: #fbbf24; border-color: #6b4a1c; } }

.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 15px 18px; box-shadow: var(--shadow); }
.stat .k { color: var(--muted); font-size: 12px; }
.stat .v { font-size: 24px; font-weight: 700; letter-spacing: -.5px; margin-top: 2px; }
.stat .v small { font-size: 12px; font-weight: 500; color: var(--muted); margin-left: 4px; }
.stat.accent .v { color: var(--down); }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 16px; align-items: start; }
.col-main, .col-side { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.panel-head h2 { margin: 0; font-size: 15px; font-weight: 650; }
.panel-note { color: var(--muted); font-size: 12px; margin: -6px 0 12px; }
.muted { color: var(--muted); font-size: 12px; }
.count { background: var(--primary-soft); color: var(--primary); border-radius: 999px;
  padding: 1px 9px; font-size: 11px; font-weight: 700; margin-left: 4px; }
.head-actions { display: flex; gap: 8px; }
.live-tag { font-size: 10px; font-weight: 700; letter-spacing: .8px; color: var(--down);
  border: 1px solid currentColor; border-radius: 5px; padding: 1px 6px; }

input, select, textarea {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 9px; padding: 9px 12px; font-size: 13px; outline: none; font-family: inherit;
}
input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.btn { border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  border-radius: 9px; padding: 9px 15px; font-size: 13px; cursor: pointer; font-family: inherit;
  white-space: nowrap; transition: transform .1s, filter .15s; }
.btn:hover { filter: brightness(.96); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.btn-ghost { background: transparent; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-danger { color: var(--up); }

.add-form { display: grid; grid-template-columns: minmax(220px, 2fr) 130px 160px auto; gap: 9px; }
.quick-row { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; margin-top: 12px; }
.chip { border: 1px dashed var(--border); background: transparent; color: var(--muted);
  border-radius: 999px; padding: 4px 11px; font-size: 12px; cursor: pointer; font-family: inherit; }
.chip:hover { color: var(--primary); border-color: var(--primary); }
.probe-row { display: flex; gap: 9px; margin-top: 14px; padding-top: 14px; border-top: 1px dashed var(--border); }
.probe-row input { flex: 1; }
.probe-result { background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px;
  padding: 12px; font-size: 12px; overflow-x: auto; white-space: pre-wrap; margin: 12px 0 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); gap: 12px; }
.card { border: 1px solid var(--border); border-radius: 12px; padding: 14px; background: var(--surface-2);
  cursor: pointer; transition: border-color .15s, transform .15s; position: relative; overflow: hidden; }
.card:hover { border-color: var(--primary); transform: translateY(-2px); }
.card.selected { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft); }
.card.error { border-left: 3px solid var(--warn); }
.card-top { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.badge { color: #fff; border-radius: 6px; padding: 2px 8px; font-size: 11px; font-weight: 700; }
.card-title { font-weight: 650; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.card-price { display: flex; align-items: baseline; gap: 9px; flex-wrap: wrap; }
.price-now { font-size: 27px; font-weight: 750; letter-spacing: -1px; }
.price-target { color: var(--muted); font-size: 12px; }
.delta { font-size: 12px; font-weight: 700; padding: 2px 7px; border-radius: 6px; }
.delta.down { color: var(--down); background: rgba(22,163,74,.1); }
.delta.up { color: var(--up); background: rgba(220,38,38,.1); }
.hit-badge { color: var(--down); font-size: 11px; font-weight: 700; border: 1px solid currentColor;
  border-radius: 5px; padding: 1px 6px; }
.card-meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 9px; }
.tag { background: var(--surface); border: 1px solid var(--border); border-radius: 5px;
  padding: 2px 7px; font-size: 10.5px; color: var(--muted); }
.tag.warn { color: var(--warn); border-color: rgba(217,119,6,.35); }
.spark { margin-top: 10px; height: 42px; }
.card-actions { display: flex; gap: 6px; margin-top: 11px; flex-wrap: wrap; }
.card-err { margin-top: 9px; font-size: 11.5px; color: var(--warn); background: rgba(217,119,6,.08);
  border-radius: 7px; padding: 6px 9px; }
.empty { color: var(--muted); text-align: center; padding: 30px 10px; font-size: 13px; }

.chart-box { min-height: 190px; }
.chart-box svg { width: 100%; height: auto; display: block; }
.chart-legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); margin-top: 8px; flex-wrap: wrap; }
.chart-legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 5px; }

.platform-list { max-height: 420px; overflow-y: auto; display: flex; flex-direction: column; gap: 7px; }
.platform-item { display: flex; align-items: center; gap: 9px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 9px; background: var(--surface-2); }
.platform-item .pdot { width: 9px; height: 9px; border-radius: 3px; flex: none; }
.platform-item .pname { font-weight: 650; font-size: 12.5px; min-width: 74px; }
.platform-item .pdomains { color: var(--muted); font-size: 11px; flex: 1; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.risk { font-size: 10px; font-weight: 700; border-radius: 5px; padding: 1px 6px; flex: none; }
.risk.low { color: var(--down); background: rgba(22,163,74,.12); }
.risk.medium { color: var(--warn); background: rgba(217,119,6,.12); }
.risk.high { color: var(--up); background: rgba(220,38,38,.1); }
.risk.none { color: var(--primary); background: var(--primary-soft); }
.platform-item:hover .pdomains { white-space: normal; }

.feed { max-height: 260px; overflow-y: auto; display: flex; flex-direction: column; gap: 7px; }
.feed-item { border-left: 2px solid var(--border); padding: 4px 0 4px 10px; font-size: 12px; }
.feed-item .t { color: var(--muted); font-size: 10.5px; display: block; }
.feed-item.ok { border-left-color: var(--down); }
.feed-item.warn { border-left-color: var(--warn); }
.feed-item.err { border-left-color: var(--up); }
.feed-item b { font-weight: 650; }
.task-box { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 8px; }
.task-line { display: flex; justify-content: space-between; gap: 10px; }
.task-line b { color: var(--text); font-weight: 650; }
.dead-item { background: rgba(217,119,6,.08); border-radius: 7px; padding: 6px 9px; font-size: 11.5px; }

.dlg { border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text);
  padding: 22px; width: min(420px, 92vw); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.dlg::backdrop { background: rgba(10,18,35,.5); backdrop-filter: blur(2px); }
.dlg h3 { margin: 0 0 4px; font-size: 16px; }
.dlg label { display: block; font-size: 12px; color: var(--muted); margin-top: 12px; }
.dlg label input { display: block; width: 100%; margin-top: 5px; }
.dlg label.inline { display: flex; align-items: center; gap: 8px; }
.dlg label.inline input { width: auto; margin: 0; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

.toast { position: fixed; right: 24px; bottom: 24px; z-index: 99; max-width: 400px;
  background: var(--text); color: var(--surface); border-radius: 10px; padding: 12px 16px;
  font-size: 13px; box-shadow: 0 12px 36px rgba(0,0,0,.28); }
.toast.err { background: #b91c1c; color: #fff; }
.toast.ok { background: #15803d; color: #fff; }
.footer { color: var(--muted); font-size: 11.5px; text-align: center; margin-top: 26px; line-height: 1.8; }

::-webkit-scrollbar { width: 7px; height: 7px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 5px; }
@media (max-width: 1180px) {
  .layout { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(3, 1fr); }
  .add-form { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 640px) {
  .app { padding: 14px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .add-form { grid-template-columns: 1fr; }
}
