:root, [data-theme="dark"] {
  --bg: #0f1419;
  --panel: #161d26;
  --panel-2: #1b2430;
  --line: #28313d;
  --text: #e7ecf1;
  --muted: #8b9aab;
  --accent: #3d9cf0;
  --critical: #e85d4c;
  --system: #f0a030;
  --normal: #5bbf7a;
  --warning: #f5b843;
  --warning-bg: #33270f;
  --alert-bg: #121820;
  --alert-unread-bg: var(--panel-2);
  --alert-zero-bg: #1c1810;
  --alert-body: #cdd6e0;
  --input-bg: #0e141b;
  --top-bg: color-mix(in srgb, var(--bg) 94%, black);
  --login-glow: #1c2a3a;
  --btn-sec-border: #3b4756;
  --shadow-watch: rgba(88, 166, 255, 0.35);
  --toast-bg: #223040;
  --toast-bad-border: #6b3229;
  --toast-bad-text: #ffb4a8;
  --modal-scrim: rgba(0, 0, 0, 0.62);
  color-scheme: dark;
}

/* 白天：贴近 App 的 iOS 浅色 */
[data-theme="light"] {
  --bg: #f2f2f7;
  --panel: #ffffff;
  --panel-2: #f7f7fa;
  --line: #e3e3e8;
  --text: #1c1c1e;
  --muted: #8e8e93;
  --accent: #007aff;
  --critical: #ff3b30;
  --system: #ff9500;
  --normal: #34c759;
  --warning: #b25000;
  --warning-bg: #fff4d6;
  --alert-bg: #ebebf0;
  --alert-unread-bg: #ffffff;
  --alert-zero-bg: #fff4d6;
  --alert-body: #3c3c43;
  --input-bg: #ffffff;
  --top-bg: rgba(242, 242, 247, 0.92);
  --login-glow: #dce8f8;
  --btn-sec-border: #c7c7cc;
  --shadow-watch: rgba(0, 122, 255, 0.28);
  --toast-bg: #ffffff;
  --toast-bad-border: #ff3b30;
  --toast-bad-text: #c41e16;
  --modal-scrim: rgba(0, 0, 0, 0.35);
  color-scheme: light;
}
* { box-sizing: border-box; }
:root {
  --page-pad-left: 20px;
  --page-pad-right: 20px;
}
html, body {
  background: var(--bg);
  color: var(--text);
}
body {
  margin: 0;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  min-height: 100vh;
  font-size: 14px;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.err { color: var(--critical); }
.ok { color: var(--normal); }
a { color: var(--accent); }

/* ---------- 登录 ---------- */
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: radial-gradient(900px 500px at 50% -10%, var(--login-glow), var(--bg));
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 2rem;
  width: min(360px, 92vw);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.login-card h1 { margin: 0; font-size: 1.3rem; }
.login-card p { margin: 0; }
.login-card button.sec { background: transparent; border: 1px solid var(--btn-sec-border); color: var(--muted); }

/* ---------- 布局 ---------- */
.top {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--top-bg);
  border-bottom: 1px solid var(--line);
  padding: 0.75rem 1.25rem 0;
  backdrop-filter: blur(10px);
}
#app .top {
  padding: 0.75rem var(--page-pad-right) 0 var(--page-pad-left);
}
.brand {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.brand h1 { margin: 0; font-size: 1.15rem; letter-spacing: 0.02em; }
.theme-toggle {
  margin-left: auto;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 999px;
  padding: 0.28rem 0.75rem;
  font-size: 0.78rem;
  cursor: pointer;
  line-height: 1.2;
}
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); }
.conn { font-size: 0.78rem; color: var(--muted); }
.conn.live { color: var(--normal); }
.conn.down { color: var(--critical); }
.tabs { display: flex; gap: 0.25rem; margin-top: 0.6rem; overflow-x: auto; }
.tabs button, .tabs a {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  font-size: 0.92rem;
  white-space: nowrap;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.tabs button:hover, .tabs a:hover { color: var(--text); }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }
/* 第一个靠右的项目把剩下的都推过去，后面的紧跟着排 */
.tabs .ghost { margin-left: auto; color: var(--muted); }
.tabs .ghost ~ .ghost { margin-left: 0; }
.badge {
  background: var(--critical);
  color: #fff;
  border-radius: 10px;
  padding: 0 0.35rem;
  font-size: 0.72rem;
}
main { padding: 1rem 1.25rem 3rem; max-width: 1200px; }
#app main {
  padding: 1rem var(--page-pad-right) 3rem var(--page-pad-left);
  max-width: none;
  width: 100%;
}
.page-gutter {
  display: none;
  position: fixed;
  top: 0;
  bottom: 0;
  width: 12px;
  z-index: 30;
  cursor: ew-resize;
  touch-action: none;
}
#app.gutter-on .page-gutter { display: block; }
.page-gutter-left {
  left: var(--page-pad-left);
  transform: translateX(-50%);
}
.page-gutter-right {
  right: var(--page-pad-right);
  transform: translateX(50%);
}
.page-gutter::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 3px;
  transform: translateX(-50%);
  background: color-mix(in srgb, var(--accent) 28%, transparent);
  border-radius: 2px;
}
.page-gutter:hover::after,
.page-gutter.dragging::after {
  width: 4px;
  background: var(--accent);
}

/* ---------- 通用块 ---------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem 1.1rem;
  margin-bottom: 1rem;
}
.panel > h2 {
  margin: 0 0 0.85rem;
  font-size: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.panel > h2 .muted { font-weight: 400; font-size: 0.82rem; }
.cards { display: grid; gap: 0.75rem; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.8rem 0.9rem;
}
.card .k { color: var(--muted); font-size: 0.8rem; }
.card .v { font-size: 1.45rem; margin-top: 0.2rem; font-variant-numeric: tabular-nums; }
.card .s { font-size: 0.78rem; color: var(--muted); margin-top: 0.15rem; }

/* ---------- 控件 ---------- */
input, select, textarea, button {
  font-family: inherit;
  font-size: 0.9rem;
}
input, select, textarea {
  background: var(--input-bg);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 0.45rem 0.6rem;
  width: 100%;
  color-scheme: inherit;
}
input::placeholder, textarea::placeholder {
  color: var(--muted);
  opacity: 1;
}
textarea { min-height: 110px; resize: vertical; font-family: ui-monospace, Consolas, monospace; }
input:focus, select:focus, textarea:focus { outline: 1px solid var(--accent); border-color: var(--accent); }
button {
  background: var(--accent);
  border: 1px solid transparent;
  color: #fff;
  border-radius: 8px;
  padding: 0.45rem 0.8rem;
  cursor: pointer;
  white-space: nowrap;
}
button:hover { filter: brightness(1.1); }
button:disabled { opacity: 0.5; cursor: default; }
button.sec { background: transparent; border-color: var(--btn-sec-border); color: var(--text); }
button.danger { background: transparent; border-color: #7a3b34; color: var(--critical); }
button.tiny { padding: 0.2rem 0.5rem; font-size: 0.8rem; }
.row { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.row > .grow { flex: 1; min-width: 160px; }
.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
  min-width: 160px;
}
.search-wrap input {
  width: 100%;
  padding-right: 2.15rem;
}
.search-wrap input[type="search"]::-webkit-search-cancel-button,
.search-wrap input[type="search"]::-webkit-search-decoration {
  -webkit-appearance: none;
  appearance: none;
}
.search-clear {
  position: absolute;
  right: 0.28rem;
  top: 50%;
  transform: translateY(-50%);
  width: 1.55rem;
  height: 1.55rem;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
}
.search-wrap.has-value .search-clear { display: flex; }
.search-clear:hover {
  color: var(--text);
  background: color-mix(in srgb, var(--muted) 18%, transparent);
  filter: none;
}
.chk { display: flex; align-items: center; gap: 0.4rem; color: var(--muted); white-space: nowrap; }
.chk input { width: auto; }
.field { margin-bottom: 0.9rem; }
.field label { display: block; margin-bottom: 0.3rem; }
.field .help { color: var(--muted); font-size: 0.8rem; margin-top: 0.25rem; line-height: 1.5; }
.field.changed input, .field.changed select { border-color: var(--warning); }

/* ---------- 表格 ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 500; font-size: 0.82rem; }
tbody tr:hover { background: var(--panel-2); }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 0.85rem; }
.pill {
  display: inline-block;
  font-size: 0.75rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
}
.pill.on { color: var(--normal); border-color: #2f5c3f; }
.pill.off { color: var(--muted); }
.pill.bad { color: var(--critical); border-color: #6b3229; }
.pill.warn { color: var(--warning); border-color: #6b5423; }

/* ---------- 型号（前台） ---------- */
.part-list { list-style: none; padding: 0; margin: 0; }
.part-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--line);
}
.part-main { flex: 1; min-width: 0; }
.part-no { word-break: break-all; }
.part-meta { font-size: 0.78rem; margin-top: 0.15rem; }
.switch { display: flex; align-items: center; gap: 0.35rem; color: var(--muted); white-space: nowrap; cursor: pointer; }
.switch input { width: auto; }
.switch:has(input:checked) { color: var(--warning); }

/* ---------- 键值行 ---------- */
.kv {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
}
.kv > span:last-child { text-align: right; }
a.btn {
  display: inline-block;
  border-radius: 8px;
  padding: 0.45rem 0.8rem;
  text-decoration: none;
  background: var(--accent);
  color: #fff;
}
a.btn.sec { background: transparent; border: 1px solid var(--btn-sec-border); color: var(--text); }

/* ---------- 提醒 ---------- */
.alert-list { list-style: none; padding: 0; margin: 0; }
.alert-swipe-host {
  position: relative;
  overflow: hidden;
  margin-bottom: 0.5rem;
  border-radius: 10px;
}
.alert-swipe-host.has-disable { touch-action: pan-y; }
.alert-swipe-disable {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 76px;
  margin: 0;
  border: 0;
  border-radius: 0 10px 10px 0;
  background: #636366;
  color: #fff;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.02em;
  cursor: pointer;
}
.alert-swipe-host .alert-item {
  position: relative;
  z-index: 1;
  margin-bottom: 0;
  transition: transform 0.18s ease;
}
.alert-swipe-host.open .alert-item { transform: translateX(-76px); }
.alert-item {
  border: 1px solid var(--line);
  border-left: 3px solid var(--line);
  border-radius: 10px;
  padding: 0.7rem 0.85rem;
  margin-bottom: 0.5rem;
  /* 已读：更深一档；未读：亮一档，一眼能分清 */
  background: var(--alert-bg);
}
.alert-item.unread { background: var(--alert-unread-bg); border-left-color: var(--accent); }
.alert-item.zero { border-left-color: var(--warning); background: var(--alert-zero-bg); }
.alert-item.zero.unread { background: var(--warning-bg); }
.alert-item.watched { box-shadow: inset 0 0 0 1px var(--shadow-watch); }
.alert-item .title-row {
  display: flex;
  align-items: baseline;
  gap: 0.55rem;
  margin: 0 0 0.15rem;
}
.alert-item .title-row .title {
  font-weight: 600;
  margin: 0;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.alert-item .title-row .meta-inline {
  flex: 0 0 auto;
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
  line-height: 1.35;
}
.recent-zero-tag {
  display: inline-block;
  margin-top: 0.2rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--warning);
}
.alert-item .meta-side {
  display: none;
}
.alert-item .body {
  white-space: pre-wrap;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.84rem;
  color: var(--alert-body);
  margin: 0.25rem 0 0.4rem;
  line-height: 1.55;
}
/* 卡片：正文 | 曲线(固定宽) | 右侧大复制区 */
.alert-item { display: flex; gap: 0.75rem; align-items: stretch; cursor: default; }
.alert-item.unread { cursor: pointer; }
.alert-body { flex: 1; min-width: 0; }
.alert-side {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  flex: 0 0 2.75rem;
  width: 2.75rem;
  min-height: 4.5rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: color-mix(in srgb, var(--panel-2) 80%, transparent);
}
.copy-zone {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  line-height: 0;
  -webkit-user-select: none;
  user-select: none;
}
.copy-zone svg,
.copy-zone path {
  pointer-events: none;
}
.copy-zone:hover {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
}
.copy-zone:active {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
}
.copy-zone-pn {
  flex: 0 0 2rem;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
}
.copy-zone-pn:hover { color: var(--accent); }
.copy-zone-full {
  flex: 1 1 auto;
  min-height: 2.75rem;
}
.spark-btn {
  align-self: center;
  background: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.25rem;
  cursor: pointer;
  flex: 0 0 auto;
  width: 96px;
  max-width: 96px;
  overflow: hidden;
  line-height: 0;
}
.spark-btn:hover { border-color: var(--accent); }
.spark {
  display: block;
  width: 96px;
  height: 30px;
  max-width: 100%;
}
.note-line { display: flex; align-items: center; gap: 0.45rem; margin-top: 0.4rem; font-size: 0.82rem; }
.note-line .note-text { word-break: break-word; }
.imported-at { margin-top: 0.15rem; font-size: 0.7rem; color: var(--muted); }
.note-input { font-size: 0.82rem; padding: 0.25rem 0.4rem; }

/* ---------- 大图弹窗 ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: var(--modal-scrim);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.2rem;
  z-index: 50;
}
.modal-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1.1rem 1.2rem 1.3rem;
  width: min(980px, 100%);
  max-height: 92vh;
  overflow: auto;
}
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; }
.modal-head h2 { margin: 0 0 0.2rem; font-size: 1.05rem; }
.modal-head p { margin: 0; font-size: 0.82rem; }
.chart { width: 100%; height: auto; margin-top: 0.6rem; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .ylab { fill: var(--muted); font-size: 11px; text-anchor: end; dominant-baseline: middle; }
.chart .xlab { fill: var(--muted); font-size: 11px; text-anchor: middle; }
.chart .xlab.head { text-anchor: start; }
.chart .xlab.tail { text-anchor: end; }
.chart .cursor { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .dot { fill: var(--accent); }

.level.critical { color: var(--critical); }
.level.system { color: var(--system); }
.level.normal { color: var(--normal); }
.level.zero { color: var(--warning); }

/* ---------- 日志 ---------- */
.log-list { font-family: ui-monospace, Consolas, monospace; font-size: 0.82rem; }
.log-list div { padding: 0.25rem 0; border-bottom: 1px solid var(--line); display: flex; gap: 0.6rem; }
.log-list .t { color: var(--muted); white-space: nowrap; }
.log-list .s { color: var(--accent); white-space: nowrap; min-width: 68px; }
.log-list .m { white-space: pre-wrap; word-break: break-word; }
.log-list .WARNING .m { color: var(--warning); }
.log-list .ERROR .m { color: var(--critical); }

/* ---------- 提示 ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%);
  background: var(--toast-bg);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 0.6rem 1rem;
  border-radius: 10px;
  z-index: 100;
  max-width: 90vw;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}
.toast.bad { border-color: var(--toast-bad-border); color: var(--toast-bad-text); }
.empty { color: var(--muted); text-align: center; padding: 2rem 0; }
.empty-cell { color: var(--muted); text-align: center; padding: 2rem 0.6rem; }

/* ---------- 变动表 ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
.changes-table { table-layout: fixed; width: 100%; }
.changes-table th, .changes-table td { padding: 0.22rem 0.45rem; }
.changes-table col.time-col { width: 9.5rem; }
.changes-table col.src-col { width: 3.2rem; }
/* 现货列宽由 JS 设为「最宽文字 ×2」；期货列 width:100% 吃掉剩余，避免摊宽到现货 */
.changes-table col.stock-col { width: 4rem; }
.changes-table col.order-col { width: 100%; }
.changes-table col.lead-col { width: 4.8rem; }
.changes-table th, .changes-table td { text-align: center; white-space: nowrap; }
/* 现货、期货、货期数据列左对齐，其余居中 */
.changes-table th:nth-child(3), .changes-table td:nth-child(3),
.changes-table th:nth-child(4), .changes-table td:nth-child(4),
.changes-table th:nth-child(5), .changes-table td:nth-child(5) { text-align: left; }
.changes-table th.num, .changes-table td.num { font-variant-numeric: tabular-nums; }
.changes-table .delta.up { color: var(--normal); }
.changes-table .delta.down { color: var(--critical); }
.changes-table td { white-space: nowrap; }
.changes-table td.mono { white-space: normal; word-break: break-all; }
/* 期货列允许折行，否则到货日/货期会被 nowrap 裁掉 */
.changes-table td.order-cell { white-space: normal; word-break: break-word; line-height: 1.35; }

@media (max-width: 700px) {
  main { padding: 0.75rem; }
  #app main {
    padding: 0.75rem var(--page-pad-right) 3rem var(--page-pad-left);
  }
  .page-gutter { display: none !important; }
  #a-gutter { display: none !important; }
  .panel { padding: 0.85rem; }
  th, td { padding: 0.4rem; }
}
