/* ============================================================================
   Signal Scanner — 量化投资监控 · Cloudflare Web 版
   ----------------------------------------------------------------------------
   设计基调：SpaceX 式硬边控制台。
   · 纯黑底 + 发丝线，无圆角、无渐变、无阴影堆叠 —— 结构靠分隔线而不是容器。
   · 色彩只属于数据：外壳全灰阶，红/绿/金/橙只表达市场语义；强调色退化为反白
     （暗=白，亮=黑），不再引入第二种色相。
   · 字阶固定：显示 46 / 标题 21 / 正文 15 / 数据 14 / 元信息 12.5 / 标签 11.5，
     拉丁字母一律大写 + 宽字距，数字一律等宽。
   · 所有模块共用一条 24px 左基线（--gutter），标题在上、正文在下、留白克制。
   两套主题：深色（默认）/ 浅色，结构完全一致，只有明度不同；侧栏底部单个图标切换。
   ========================================================================== */

/* ---------- 字体（自托管，仅拉丁子集；中文字形回落系统） ---------- */
@font-face {
  font-family: 'Inter';
  src: url('/fonts/inter-latin-400-normal.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Inter';
  src: url('/fonts/inter-latin-500-normal.woff2') format('woff2');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Inter';
  src: url('/fonts/inter-latin-600-normal.woff2') format('woff2');
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'JetBrains Mono';
  src: url('/fonts/jetbrains-mono-latin-400-normal.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'JetBrains Mono';
  src: url('/fonts/jetbrains-mono-latin-500-normal.woff2') format('woff2');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'JetBrains Mono';
  src: url('/fonts/jetbrains-mono-latin-700-normal.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

/* ============================== 令牌 ============================== */

/* 深色（默认）—— 纯黑，只有明度层次 */
:root,
[data-theme='dark'] {
  color-scheme: dark;

  --bg: #000000;
  --surface: #050505;
  --surface-2: #0a0a0a;
  --surface-3: #141414;
  --modal-bg: #0a0a0a;
  --line: #1f1f1f;
  --line-2: #3a3a3a;

  --text: #ffffff;
  --text-2: #b4b4b4;
  --text-3: #8c8c8c;

  /* 强调色 = 反白。不引入第二种色相，把色相全部留给数据 */
  --accent: #ffffff;
  --accent-dim: rgba(255, 255, 255, 0.08);

  --key: #ffffff;
  --key-fg: #000000;

  /* 市场语义：涨/买 = 红，跌/险 = 绿、强关注 = 金，弱关注 = 橙，停牌 = 中性 */
  --up: #ff5f5f;
  --up-bg: rgba(255, 72, 72, 0.16);
  --up-line: rgba(255, 72, 72, 0.34);

  --dn: #35d07f;
  --dn-bg: rgba(38, 208, 128, 0.14);
  --dn-line: rgba(38, 208, 128, 0.32);

  --w1: #f2c53d;
  --w1-bg: rgba(242, 197, 61, 0.14);

  --w2: #ff9a4d;
  --w2-bg: rgba(255, 154, 77, 0.14);

  /* 止盈：唯一新增的色相（中性蓝），与红/绿/金/橙互不混淆 */
  --tp: #6aa9ff;
  --tp-bg: rgba(80, 150, 255, 0.14);

  --na: #9a9a9a;
  --na-bg: rgba(154, 154, 154, 0.12);

  /* 图表均线：同色相，用明度 + 虚线节奏区分，不抢数据色 */
  --ma-1: #c4c4c4;
  --ma-2: #8a8a8a;
  --ma-3: #666666;

  --sel-bg: rgba(255, 255, 255, 0.86);
  --sel-fg: #000000;
  --grid: rgba(255, 255, 255, 0.05);

  --shadow-modal: 0 40px 80px -32px rgba(0, 0, 0, 0.9);
}

/* 浅色 —— 结构与深色完全一致，只换明度 */
[data-theme='light'] {
  color-scheme: light;

  --bg: #f1f1f1;
  --surface: #ffffff;
  --surface-2: #fafafa;
  --surface-3: #f0f0f0;
  --modal-bg: #ffffff;
  --line: #dedede;
  --line-2: #b4b4b4;

  --text: #000000;
  --text-2: #4a4a4a;
  --text-3: #666666;

  --accent: #000000;
  --accent-dim: rgba(0, 0, 0, 0.06);

  --key: #000000;
  --key-fg: #ffffff;

  --up: #b81414;
  --up-bg: #fbe9e9;
  --up-line: rgba(184, 20, 20, 0.24);

  --dn: #0a6b3c;
  --dn-bg: #e8f5ee;
  --dn-line: rgba(10, 107, 60, 0.24);

  --w1: #7a5400;
  --w1-bg: #fbf2d4;

  --w2: #94450a;
  --w2-bg: #fdece0;

  --tp: #0a4f9e;
  --tp-bg: #e6f0fb;

  --na: #5b5b5b;
  --na-bg: #ececec;

  --ma-1: #2e2e2e;
  --ma-2: #6b6b6b;
  --ma-3: #858585;

  --sel-bg: rgba(0, 0, 0, 0.84);
  --sel-fg: #ffffff;
  --grid: rgba(0, 0, 0, 0.06);

  --shadow-modal: 0 32px 64px -28px rgba(0, 0, 0, 0.28);
}

/* 尺寸与字阶 —— 固定值，不随视口缩放；相邻两级至少差 1px 且字号外还差字重/字距 */
:root {
  --font-sans: 'Inter', -apple-system, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', 'Noto Sans SC',
    system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', 'Cascadia Mono', Consolas, monospace;

  --fs-label: 11.5px; /* 大写标签、表头、字段名 */
  --fs-meta: 12.5px; /* 元信息、日志时间、脚注 */
  --fs-sm: 14px; /* 次级正文、按钮、表格主数据 */
  --fs-md: 15px; /* 正文基准 */
  --fs-lg: 17px; /* 小节标题、空态标题 */
  --fs-xl: 21px; /* 页面标题、弹窗标题 */
  --fs-2xl: 28px; /* 登录标题、统计数值 */
  --fs-stat: 28px;
  --fs-dense: 13px; /* 密集数字列：股票代码、历史日 */
  --fs-display: 46px; /* 登录页主标 */

  /* 间距：4 基数；同一模块内的节奏只用这几档 */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 20px;
  --s-6: 24px;
  --s-7: 32px;
  --s-8: 40px;
  --s-9: 56px;

  /* 全局栏距：侧栏、命令栏、统计条、表格首列、日志共用同一条左基线 */
  --gutter: 24px;

  /* 硬边：全域零圆角，只有状态点与转圈是圆的 */
  --r1: 0px;
  --r2: 0px;
  --r3: 0px;

  --rail-w: 260px;
  --ctl-h: 36px;
  --row-h: 40px;
  --bar-h: 64px;
  --stats-h: 76px;

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --dur-1: 140ms;
  --dur-2: 220ms;
  --dur-3: 320ms;
}

/* ============================== 基础 ============================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-feature-settings: 'cv05' 1, 'ss01' 1;
}

h1,
h2,
h3,
p,
dl,
dd,
ul {
  margin: 0;
}
ul {
  padding: 0;
  list-style: none;
}

/* 数字一律等宽对齐 */
.num,
.tabular,
.mono,
input[type='number'],
#result-table td,
#result-table th,
.stats,
.jobs-list,
.log-box,
.meta-list dd {
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum' 1;
}

.mono {
  font-family: var(--font-mono);
}

/* 浏览器表面：选区、光标、滚动条、焦点环 —— 属于设计的一部分 */
::selection {
  background: var(--sel-bg);
  color: var(--sel-fg);
}

input,
button,
textarea,
select {
  font: inherit;
  color: inherit;
  caret-color: var(--accent);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 0;
}

::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--line-2);
  border: 4px solid transparent;
  background-clip: content-box;
  border-radius: 0;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-3);
  border: 4px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-corner {
  background: transparent;
}

/* 图标：inline SVG 精灵，统一 1.5 描边 */
svg.icon {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}
.i-16 {
  width: 16px;
  height: 16px;
}

/* ============================== 控件 ============================== */

/* 描边按钮：hover 直接反相填充 —— 硬、干脆，没有渐变过渡 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: var(--ctl-h);
  padding: 0 14px;
  border: 1px solid var(--line-2);
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font-size: var(--fs-sm);
  font-weight: 500;
  letter-spacing: 0.04em;
  white-space: nowrap;
  cursor: pointer;
  transition: background var(--dur-1) var(--ease-out), border-color var(--dur-1) var(--ease-out),
    color var(--dur-1) var(--ease-out);
}
.btn:hover:not(:disabled) {
  background: var(--key);
  border-color: var(--key);
  color: var(--key-fg);
}
.btn:active:not(:disabled) {
  transform: translateY(1px);
}
.btn:disabled {
  color: var(--text-3);
  border-color: var(--line);
  cursor: not-allowed;
}
.btn svg {
  width: 15px;
  height: 15px;
  flex: none;
}

/* 主操作：反相键（暗=白底黑字，亮=黑底白字），不占用语义色 */
.btn-key {
  background: var(--key);
  border-color: var(--key);
  color: var(--key-fg);
  font-weight: 600;
}
.btn-key:hover:not(:disabled) {
  background: var(--key);
  border-color: var(--key);
  color: var(--key-fg);
  filter: brightness(1.08);
}
.btn-key:disabled {
  background: transparent;
  border-color: var(--line);
  color: var(--text-3);
  filter: none;
}

/* 幽灵按钮：工具栏里的低频操作，hover 才显形 */
.btn-ghost {
  border-color: transparent;
  color: var(--text-2);
}
.btn-ghost:hover:not(:disabled) {
  background: transparent;
  border-color: var(--line-2);
  color: var(--text);
}
.btn-ghost:disabled {
  border-color: transparent;
  color: var(--text-3);
  opacity: 0.55;
}

.btn-block {
  width: 100%;
  height: 46px;
  font-size: var(--fs-md);
  letter-spacing: 0.08em;
}

.link-btn {
  border: 0;
  padding: 0;
  background: none;
  color: var(--text-2);
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  transition: color var(--dur-1);
}
.link-btn:hover {
  color: var(--text);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 0;
  background: none;
  color: var(--text-3);
  cursor: pointer;
  transition: color var(--dur-1), background var(--dur-1), border-color var(--dur-1);
}
.icon-btn:hover {
  color: var(--text);
  border-color: var(--line-2);
}
.icon-btn svg {
  width: 16px;
  height: 16px;
}

input[type='text'],
input[type='password'],
input[type='number'] {
  height: var(--ctl-h);
  padding: 0 11px;
  border: 1px solid var(--line-2);
  border-radius: 0;
  background: var(--surface-2);
  color: var(--text);
  font-size: var(--fs-sm);
  transition: border-color var(--dur-1), background var(--dur-1), box-shadow var(--dur-1);
}
input[type='number'] {
  font-family: var(--font-mono);
  text-align: right;
}
input::placeholder {
  color: var(--text-3);
  opacity: 1;
}
input:hover:not(:disabled) {
  border-color: var(--text-3);
}
/* 输入框的焦点就是 2px 反白描边：边框 + 1px 外环，不要再叠一层 outline */
input:focus,
input:focus-visible {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 1px var(--accent);
}

/* 主题切换：单个图标按钮。图标画的是「将要切到的那一边」，标签同步 */
.theme-btn .t-moon {
  display: none;
}
[data-theme='light'] .theme-btn .t-sun {
  display: none;
}
[data-theme='light'] .theme-btn .t-moon {
  display: block;
}

/* 微型状态点 */
.dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}
.dot-live {
  animation: pulse 1.8s var(--ease-out) infinite;
}
@keyframes pulse {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.3;
    transform: scale(0.65);
  }
}

/* ============================== 应用外壳 ============================== */

.app {
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr);
  height: 100dvh;
  overflow: hidden;
}

/* ---------- 左侧栏 ---------- */
.rail {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--line);
  background: var(--surface-2);
}

.rail-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 22px var(--gutter) 20px;
}
.rail-mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1px solid var(--line-2);
  border-radius: 0;
  color: var(--text);
  background: transparent;
}
.rail-mark svg {
  width: 16px;
  height: 16px;
}
.rail-title {
  font-size: var(--fs-sm);
  font-weight: 600;
  letter-spacing: 0.14em;
  line-height: 1.2;
  text-transform: uppercase;
}
.rail-sub {
  margin-top: 6px;
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-3);
}

.rail-block {
  padding: 20px var(--gutter);
  border-top: 1px solid var(--line);
}
.rail-grow {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  /* 记录多到需要滚动时，底边淡出，避免出现半截行 */
  mask-image: linear-gradient(to bottom, #000 calc(100% - 20px), transparent);
  -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 20px), transparent);
}
.rail-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-3);
}
.rail-label .count {
  font-family: var(--font-mono);
  letter-spacing: 0;
  color: var(--text-2);
}

.meta-list {
  display: grid;
  gap: 7px;
}
.meta-list div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}
.meta-list dt {
  font-size: var(--fs-meta);
  color: var(--text-2);
}
.meta-list dd {
  font-family: var(--font-mono);
  font-size: var(--fs-meta);
  color: var(--text);
}
.meta-list dd .u {
  color: var(--text-3);
  margin-left: 3px;
}

.jobs-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow-y: auto;
  margin: 0 calc(var(--s-2) * -1);
  padding: 0 var(--s-2);
}
.jobs-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 8px;
  border-left: 2px solid transparent;
  font-family: var(--font-mono);
  font-size: var(--fs-meta);
  color: var(--text-2);
  cursor: pointer;
  transition: background var(--dur-1), color var(--dur-1), border-color var(--dur-1);
}
.jobs-list li:hover {
  background: var(--surface-3);
  color: var(--text);
}
.jobs-list li[aria-current='true'] {
  background: var(--accent-dim);
  border-left-color: var(--accent);
  color: var(--text);
}
.jobs-list li .jobs-n {
  color: var(--text-3);
}
.jobs-list .jobs-empty {
  justify-content: flex-start;
  border-left-color: transparent;
  color: var(--text-3);
  cursor: default;
  font-family: var(--font-sans);
  font-size: var(--fs-meta);
}
.jobs-list .jobs-empty:hover {
  background: none;
  color: var(--text-3);
}

.rail-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px var(--gutter);
  border-top: 1px solid var(--line);
}
.who {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: var(--fs-meta);
  color: var(--text-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.who b {
  font-weight: 500;
  color: var(--text);
}
.who .dot {
  color: var(--text);
}

/* ---------- 主区 ---------- */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
}

/* 命令栏 */
.cmdbar {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  flex: none;
  padding: 0 var(--gutter);
  height: var(--bar-h);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.cmd-space {
  flex: 1;
}
.cmd-group {
  display: flex;
  align-items: center;
  gap: 4px;
  padding-right: 12px;
  margin-right: 6px;
  border-right: 1px solid var(--line);
}

.file-chip {
  display: block;
  max-width: 260px;
  padding: 0 10px;
  height: 28px;
  line-height: 26px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  font-family: var(--font-mono);
  font-size: var(--fs-meta);
  color: var(--text-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-chip[data-empty='true'] {
  border-style: dashed;
  color: var(--text-3);
}
.file-chip[data-state='ok'] {
  border-color: var(--line-2);
  color: var(--text);
}

.scan-meta {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-right: 2px;
  font-size: var(--fs-meta);
  color: var(--text-2);
  white-space: nowrap;
}
.scan-meta .pct {
  font-family: var(--font-mono);
  font-size: var(--fs-meta);
  color: var(--text);
}
.scan-meta .pct[data-idle='true'] {
  color: var(--text-3);
}

/* 进度发丝线：空闲时隐形 */
.progress-rail {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  overflow: hidden;
  pointer-events: none;
}
.progress-bar {
  height: 100%;
  width: 0;
  background: var(--accent);
  opacity: 0;
  transition: width var(--dur-3) var(--ease-out), opacity var(--dur-2);
}
.progress-bar[data-active='true'] {
  opacity: 1;
}
.progress-bar[data-active='true']::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.6), transparent);
  animation: sweep 1.4s linear infinite;
}
[data-theme='light'] .progress-bar[data-active='true']::after {
  background: linear-gradient(90deg, transparent, rgba(0, 0, 0, 0.35), transparent);
}
@keyframes sweep {
  from {
    transform: translateX(-100%);
  }
  to {
    transform: translateX(100%);
  }
}

/* 统计条 */
.stats {
  display: flex;
  align-items: stretch;
  flex: none;
  height: var(--stats-h);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.stat {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  padding: 0 var(--gutter);
  min-width: 0;
  border: 0;
  border-right: 1px solid var(--line);
  background: none;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
  transition: background var(--dur-1);
}
.stat:hover {
  background: var(--surface-2);
}
/* 筛选态：底色抬起 + 底部一道反白，和「硬边控制台」的语法一致 */
.stat[data-active='true'] {
  background: var(--surface-3);
  box-shadow: inset 0 -2px 0 var(--text);
}
.stat:first-child {
  padding-left: var(--gutter);
}
.stat-k {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  letter-spacing: 0.1em;
  color: var(--text-3);
  white-space: nowrap;
}
.stat-v {
  font-family: var(--font-mono);
  font-size: var(--fs-stat);
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.03em;
  color: var(--text);
  transition: color var(--dur-2);
}
.stat[data-tone='up'] .stat-v {
  color: var(--up);
}
.stat[data-tone='dn'] .stat-v {
  color: var(--dn);
}
.stat[data-tone='w1'] .stat-v {
  color: var(--w1);
}
.stat[data-tone='w2'] .stat-v {
  color: var(--w2);
}
.stat[data-tone='tp'] .stat-v {
  color: var(--tp);
}
.stat[data-tone='up'] .dot {
  color: var(--up);
}
.stat[data-tone='dn'] .dot {
  color: var(--dn);
}
.stat[data-tone='w1'] .dot {
  color: var(--w1);
}
.stat[data-tone='w2'] .dot {
  color: var(--w2);
}
.stat[data-tone='tp'] .dot {
  color: var(--tp);
}
.stat[data-tone='none'] .dot {
  color: var(--line-2);
}
.stat-aside {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  padding: 0 var(--gutter);
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  letter-spacing: 0.08em;
  color: var(--text-3);
  white-space: nowrap;
}

/* 数据面 */
.surface {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  background: var(--surface);
}

.table-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
}

/* 空态 */
.empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: var(--s-7);
  text-align: center;
  background: var(--surface);
}
.empty[hidden] {
  display: none;
}
.empty-icon {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  margin-bottom: 8px;
  border: 1px solid var(--line-2);
  border-radius: 0;
  color: var(--text-3);
  background: transparent;
}
.empty-icon svg {
  width: 22px;
  height: 22px;
}
.empty-title {
  font-size: var(--fs-lg);
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text);
  text-wrap: balance;
}
.empty-hint {
  max-width: 30rem;
  font-size: var(--fs-sm);
  line-height: 1.7;
  color: var(--text-2);
  text-wrap: pretty;
}
.empty .btn {
  margin-top: 12px;
}

/* ---------- 控制台抽屉 ---------- */
.console {
  flex: none;
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
}
.console-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 40px;
  padding: 0 var(--gutter);
  border: 0;
  background: none;
  color: var(--text-3);
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  text-align: left;
  cursor: pointer;
  transition: color var(--dur-1), background var(--dur-1);
}
.console-bar:hover {
  color: var(--text);
  background: var(--surface-3);
}
.console-bar svg {
  width: 14px;
  height: 14px;
  transition: transform var(--dur-2) var(--ease-out);
}
.console[data-open='true'] .console-bar svg {
  transform: rotate(90deg);
}
.console-last {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  letter-spacing: 0;
  text-transform: none;
  color: var(--text-2);
}
.console[data-open='true'] .console-last {
  opacity: 0;
}
.console-body {
  height: 0;
  overflow: hidden;
  transition: height var(--dur-3) var(--ease-out);
}
.console[data-open='true'] .console-body {
  height: 200px;
}

.log-box {
  height: 200px;
  overflow-y: auto;
  padding: 12px var(--gutter) 16px;
  border-top: 1px solid var(--line);
  background: var(--surface);
  font-family: var(--font-mono);
  font-size: var(--fs-meta);
  line-height: 1.85;
  color: var(--text-2);
}
.log-box > div {
  display: flex;
  gap: 12px;
  animation: log-in var(--dur-2) var(--ease-out) both;
}
.log-box .t {
  color: var(--text-3);
  flex: none;
}
.log-box .m {
  color: var(--text-2);
  word-break: break-all;
}
.log-box > div[data-level='err'] .m {
  color: var(--up);
}
.log-box > div[data-level='ok'] .m {
  color: var(--text);
}
@keyframes log-in {
  from {
    opacity: 0;
    transform: translateY(3px);
  }
}

/* ============================== 数据表 ============================== */

#result-table {
  border-collapse: separate;
  border-spacing: 0;
  width: max-content;
  min-width: 100%;
  font-size: var(--fs-sm);
}

#result-table th,
#result-table td {
  height: var(--row-h);
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  text-align: center;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

#result-table thead th {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--row-h);
  background: var(--surface-3);
  border-bottom: 1px solid var(--line-2);
  color: var(--text-3);
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
#result-table thead th:first-child {
  z-index: 50;
  left: 0;
}
#result-table thead th:nth-child(2) {
  z-index: 50;
  left: 128px;
}

/* 可排序表头：只给基础列，历史日期列不参与排序 */
#result-table thead th[data-sort] {
  cursor: pointer;
  transition: color var(--dur-1);
}
#result-table thead th[data-sort]:hover,
#result-table thead th[aria-sort='ascending'],
#result-table thead th[aria-sort='descending'] {
  color: var(--text);
}
#result-table thead th[aria-sort='ascending']::after {
  content: ' ↑';
}
#result-table thead th[aria-sort='descending']::after {
  content: ' ↓';
}

#result-table tbody td {
  color: var(--text);
  background: var(--surface);
}

/* 冻结前两列 */
#result-table tbody td:nth-child(1),
#result-table tbody td:nth-child(2) {
  position: sticky;
  z-index: 20;
  background: var(--surface);
  text-align: left;
}
#result-table tbody td:nth-child(1) {
  left: 0;
  width: 128px;
  min-width: 128px;
  padding-left: var(--gutter);
  font-family: var(--font-mono);
  font-size: var(--fs-dense);
  color: var(--text-2);
}
#result-table tbody td:nth-child(2) {
  left: 128px;
  width: 112px;
  min-width: 112px;
  border-right: 1px solid var(--line-2);
  font-size: var(--fs-md);
  font-weight: 500;
  /* 横向滚动时给冻结列一点厚度，说明后面的内容被盖住了 */
  box-shadow: 14px 0 16px -12px rgba(0, 0, 0, 0.95);
}
[data-theme='light'] #result-table tbody td:nth-child(2) {
  box-shadow: 14px 0 16px -12px rgba(0, 0, 0, 0.22);
}
#result-table thead th:first-child {
  width: 128px;
  min-width: 128px;
  padding-left: var(--gutter);
  text-align: left;
}
#result-table thead th:nth-child(2) {
  width: 112px;
  min-width: 112px;
  text-align: left;
  border-right: 1px solid var(--line-2);
}

/* 基础列数值右对齐；信号列居中；历史列右对齐（数字列一律右齐） */
#result-table tbody td:nth-child(3),
#result-table tbody td:nth-child(4),
#result-table tbody td:nth-child(5),
#result-table tbody td:nth-child(6),
#result-table tbody td:nth-child(7),
#result-table tbody td:nth-child(8),
#result-table tbody td:nth-child(9),
#result-table tbody td:nth-child(11),
#result-table tbody td:nth-child(12) {
  text-align: right;
  font-family: var(--font-mono);
}
#result-table th:nth-child(3),
#result-table th:nth-child(4),
#result-table th:nth-child(5),
#result-table th:nth-child(6),
#result-table th:nth-child(7),
#result-table th:nth-child(8),
#result-table th:nth-child(9),
#result-table th:nth-child(11),
#result-table th:nth-child(12) {
  text-align: right;
}
/* 历史列（第 14 列起）单值双读数，右对齐更容易纵向比对 */
#result-table tbody td:nth-child(n + 14),
#result-table thead th:nth-child(n + 14) {
  text-align: right;
  font-family: var(--font-mono);
  font-size: var(--fs-dense);
  padding: 0 12px;
}
#result-table thead th:nth-child(n + 14) {
  font-size: var(--fs-label);
  color: var(--text-3);
}

#result-table tbody tr {
  cursor: pointer;
}
#result-table tbody tr:hover td {
  background: var(--surface-3);
}
#result-table tbody tr.selected td {
  background: var(--accent-dim);
}
#result-table tbody tr.selected td:nth-child(1) {
  box-shadow: inset 2px 0 0 var(--accent);
  color: var(--text);
}
#result-table tbody tr.selected td:nth-child(2) {
  color: var(--text);
}

/* 行入场：仅扫描流式追加时使用 */
@keyframes row-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
}
#result-table tbody tr.row-in td {
  animation: row-in var(--dur-2) var(--ease-out) both;
}

/* 语义单元格（颜色只表达市场含义） */
.cell-up {
  background: var(--up-bg) !important;
  color: var(--up) !important;
}
.cell-dn {
  background: var(--dn-bg) !important;
  color: var(--dn) !important;
}
.cell-w1 {
  background: var(--w1-bg) !important;
  color: var(--w1) !important;
}
.cell-w2 {
  background: var(--w2-bg) !important;
  color: var(--w2) !important;
}
.cell-tp {
  background: var(--tp-bg) !important;
  color: var(--tp) !important;
}
.cell-na {
  background: var(--na-bg) !important;
  color: var(--na) !important;
}
.cell-em {
  font-weight: 700;
}
.txt-up {
  color: var(--up) !important;
}
.txt-dn {
  color: var(--dn) !important;
}
.txt-na {
  color: var(--text-3) !important;
}

/* 分节竖线：基础列 / 信号 / 历史 */
#result-table th:nth-child(13),
#result-table td:nth-child(13) {
  border-right: 1px solid var(--line-2);
}

/* ============================== 弹窗 ============================== */

.modal-mask {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s-6);
  background: rgba(0, 0, 0, 0.82);
  animation: mask-in var(--dur-2) var(--ease-out) both;
}
[data-theme='light'] .modal-mask {
  background: rgba(20, 20, 20, 0.45);
}
.modal-mask[hidden] {
  display: none;
}
@keyframes mask-in {
  from {
    opacity: 0;
  }
}

.modal {
  width: 440px;
  max-width: 100%;
  max-height: 88vh;
  overflow: auto;
  padding: var(--s-7);
  border: 1px solid var(--line-2);
  border-radius: 0;
  background: var(--modal-bg);
  box-shadow: var(--shadow-modal);
  animation: modal-in var(--dur-3) var(--ease-out) both;
}
@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}
.modal-wide {
  width: 960px;
}
.modal h3 {
  margin-bottom: 8px;
  font-size: var(--fs-xl);
  font-weight: 600;
  letter-spacing: -0.01em;
}
.modal-sub {
  margin-bottom: var(--s-6);
  padding-bottom: var(--s-4);
  border-bottom: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-3);
}

.form-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}
.form-row:first-of-type {
  border-top: 0;
}
.form-row label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: var(--fs-md);
  color: var(--text);
}
.form-row label .hint {
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
}
.form-row input {
  width: 132px;
  height: 38px;
  font-size: var(--fs-md);
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: var(--s-5);
  padding-top: var(--s-5);
  border-top: 1px solid var(--line);
}

#kline-chart {
  width: 100%;
  height: 420px;
}

/* ============================== 登录页 ============================== */

.login-body {
  min-height: 100dvh;
  background: var(--bg);
}

.login-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  min-height: 100dvh;
}

/* 品牌面板 */
.login-brand {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: var(--s-9) 48px;
  overflow: hidden;
  border-right: 1px solid var(--line);
  background: var(--surface-2);
}
.login-brand::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: linear-gradient(to right, var(--grid) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid) 1px, transparent 1px);
  background-size: 32px 32px;
  mask-image: radial-gradient(110% 80% at 18% 0%, #000 18%, transparent 76%);
  -webkit-mask-image: radial-gradient(110% 80% at 18% 0%, #000 18%, transparent 76%);
  pointer-events: none;
}
.login-brand > * {
  position: relative;
}
[data-theme='light'] .login-brand {
  background: var(--surface);
}

.brand-top {
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-2);
}
.brand-top .rail-mark {
  width: 28px;
  height: 28px;
}
.brand-top svg {
  width: 15px;
  height: 15px;
}

.brand-mid {
  padding: var(--s-8) 0;
}
.brand-mid h1 {
  font-size: var(--fs-display);
  font-weight: 600;
  line-height: 1.08;
  letter-spacing: -0.02em;
  color: var(--text);
  text-wrap: balance;
}
.brand-mid h1 span {
  display: block;
  margin-top: 16px;
  font-family: var(--font-mono);
  font-size: 17px;
  font-weight: 400;
  line-height: 1.3;
  letter-spacing: 0.26em;
  text-transform: uppercase;
  color: var(--text-3);
}
.brand-mid p {
  margin-top: var(--s-6);
  max-width: 26rem;
  font-size: var(--fs-md);
  line-height: 1.75;
  color: var(--text-2);
  text-wrap: pretty;
}

/* 面板底部的规格行 —— 说明这套系统的实际能力，不是装饰性数字 */
.brand-spec {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  border: 1px solid var(--line);
  background: var(--line);
  border-radius: 0;
  overflow: hidden;
}
.brand-spec div {
  padding: 14px 16px;
  background: var(--surface-2);
}
[data-theme='light'] .brand-spec div {
  background: var(--surface);
}
.brand-spec dt {
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-3);
}
.brand-spec dd {
  margin-top: 8px;
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  color: var(--text);
}

/* 表单面板 */
.login-pane {
  display: flex;
  flex-direction: column;
  padding: var(--s-6) 48px var(--s-7);
  background: var(--bg);
}
.login-pane-top {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}
.login-form-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  width: 100%;
  max-width: 360px;
  margin: 0 auto;
  animation: rise var(--dur-3) var(--ease-out) both;
}
@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
}
.login-form-wrap h2 {
  font-size: var(--fs-2xl);
  font-weight: 600;
  letter-spacing: -0.01em;
}
.login-sub {
  margin: 10px 0 var(--s-7);
  font-size: var(--fs-sm);
  color: var(--text-2);
}

.field {
  display: block;
  margin-bottom: var(--s-5);
}
.field > span {
  display: block;
  margin-bottom: 8px;
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-3);
}
.field input {
  height: 44px;
  width: 100%;
  padding: 0 13px;
  font-size: var(--fs-md);
}

.login-error {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: var(--s-4);
  padding: 10px 12px;
  border: 1px solid var(--up-line);
  border-left-width: 2px;
  border-radius: 0;
  background: var(--up-bg);
  color: var(--up);
  font-size: var(--fs-sm);
  line-height: 1.6;
  animation: rise var(--dur-2) var(--ease-out) both;
}
.login-error[hidden] {
  display: none;
}
.login-error svg {
  width: 15px;
  height: 15px;
  flex: none;
  margin-top: 2px;
}

.login-note {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: var(--s-5);
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  letter-spacing: 0.06em;
  color: var(--text-3);
}
.login-note svg {
  width: 14px;
  height: 14px;
}
.login-foot {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-top: var(--s-5);
  border-top: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  letter-spacing: 0.1em;
  color: var(--text-3);
}

/* 提交中 */
.btn[data-busy='true'] {
  cursor: progress;
  color: transparent;
  position: relative;
}
.btn[data-busy='true']::after {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  border: 1.5px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  color: var(--key-fg);
  animation: spin 0.7s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ============================== 响应式 ============================== */

/* 平板：登录页合并成上下两段 */
@media (max-width: 1180px) {
  .login-grid {
    grid-template-columns: 1fr;
  }
  .login-brand {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: var(--s-6) var(--gutter) var(--s-5);
  }
  .brand-mid {
    padding: var(--s-5) 0 var(--s-3);
  }
  .brand-mid h1 {
    font-size: 30px;
  }
  .brand-mid h1 span {
    margin-top: 10px;
    font-size: 13px;
    letter-spacing: 0.22em;
  }
  .brand-mid p {
    margin-top: var(--s-4);
    max-width: 32rem;
    font-size: var(--fs-sm);
    line-height: 1.65;
  }
  .brand-spec {
    display: none;
  }
  .login-pane {
    padding: var(--s-4) var(--gutter) var(--s-6);
  }
  .login-form-wrap {
    max-width: 420px;
    justify-content: flex-start;
    padding: var(--s-2) 0 var(--s-5);
  }
}

/* 窄桌面 / 平板横屏：侧栏变成顶部横条 */
@media (max-width: 1080px) {
  .app {
    display: block;
    height: auto;
    overflow: visible;
  }
  .rail {
    flex-direction: row;
    align-items: center;
    gap: 0;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 10px var(--gutter);
    overflow-x: auto;
  }
  .rail-brand {
    padding: 0 var(--s-4) 0 0;
    flex: none;
  }
  .rail-block {
    padding: 0 var(--s-4);
    border-top: 0;
    border-left: 1px solid var(--line);
    flex: none;
  }
  .rail-label {
    margin-bottom: 6px;
  }
  /* 策略参数在窄屏收成一行：标签 + 调整 */
  .rail-params {
    display: flex;
    align-items: center;
    align-self: stretch;
  }
  .rail-params .rail-label {
    gap: 10px;
    margin-bottom: 0;
    white-space: nowrap;
  }
  .rail-params .meta-list {
    display: none;
  }
  .rail-grow {
    display: none;
  }
  .rail-foot {
    border-top: 0;
    border-left: 1px solid var(--line);
    padding: 0 0 0 var(--s-4);
    flex: none;
  }
  .main {
    min-height: calc(100dvh - 61px);
  }
  .surface {
    min-height: 62vh;
  }
  .cmdbar {
    position: sticky;
    top: 0;
    z-index: 60;
    flex-wrap: wrap;
    height: auto;
    padding: 12px var(--gutter);
    gap: 10px;
  }
  .cmd-group {
    border-right: 0;
    padding-right: 0;
    margin-right: 0;
    margin-left: auto;
  }
  .cmd-space {
    display: none;
  }
  .stats {
    overflow-x: auto;
    height: var(--stats-h);
  }
  .stat {
    padding: 0 var(--s-5);
  }
  .stat:first-child {
    padding-left: var(--gutter);
  }
  .console[data-open='true'] .console-body {
    height: 40vh;
  }
  .log-box {
    height: 40vh;
  }
}

/* 手机：单列。字阶不缩水，只压缩容器与栏距，保证和桌面同一套视觉语言 */
@media (max-width: 640px) {
  :root {
    --gutter: 16px;
    --rail-w: 0;
    --ctl-h: 40px;
  }

  /* 顶栏折成两行：品牌 / 主题 / 退出，第二行是策略参数入口 */
  .rail {
    flex-wrap: wrap;
    row-gap: 10px;
    padding: 8px var(--gutter) 12px;
    overflow-x: visible;
  }
  .rail-brand {
    flex: 1 1 auto;
    padding: 0 8px 0 0;
  }
  .rail-mark {
    width: 26px;
    height: 26px;
  }
  .rail-title {
    font-size: var(--fs-meta);
    letter-spacing: 0.1em;
  }
  .rail-sub {
    display: none;
  }
  .rail-foot {
    order: 2;
    border-left: 0;
    padding: 0;
  }
  /* 手机上不显示账号名，只留主题与退出：一行放得下品牌 + 两个图标 */
  .who {
    display: none;
  }
  .rail-params {
    order: 4;
    flex: 1 0 100%;
    align-items: center;
    border-left: 0;
    border-top: 1px solid var(--line);
    padding: 10px 0 0;
  }
  .rail-params .rail-label {
    width: 100%;
    margin-bottom: 0;
  }

  /* 命令栏两行网格：上传/文件/扫描，工具与状态在下一行 */
  .cmdbar {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas:
      'upload file scan'
      'tools tools meta';
    align-items: center;
    gap: 10px 8px;
    padding: 12px var(--gutter);
  }
  #upload-btn {
    grid-area: upload;
  }
  #file-label {
    grid-area: file;
    justify-self: stretch;
    max-width: 100%;
    min-width: 0;
  }
  #scan-btn {
    grid-area: scan;
  }
  .cmd-group {
    grid-area: tools;
    margin: 0;
    padding: 0;
    border: 0;
    justify-content: flex-start;
  }
  /* 工具按钮在手机上收窄内距，避免和第二行右侧的状态挤在一起 */
  .cmd-group .btn {
    padding: 0 8px;
    gap: 6px;
  }
  .scan-meta {
    grid-area: meta;
    justify-self: end;
    margin-right: 0;
  }

  /* 统计条：隐藏「总标的」（进度区已有 N/M）；去掉色点、收窄内距，六格压在一屏内 */
  .stats {
    overflow: visible;
    height: 68px;
  }
  .stat {
    padding: 0 10px;
    gap: 4px;
  }
  .stat:first-child {
    display: none;
  }
  .stat:nth-child(2) {
    padding-left: var(--gutter);
  }
  .stat-k {
    font-size: 11px;
    letter-spacing: 0.04em;
    gap: 0;
  }
  .stat-k .dot {
    display: none;
  }
  .stat-v {
    font-size: 24px;
  }
  .stat-aside {
    display: none;
  }

  /* 表格：只冻结代码列 */
  #result-table tbody td:nth-child(2),
  #result-table thead th:nth-child(2) {
    position: static;
    width: auto;
    min-width: 104px;
    box-shadow: none;
  }
  #result-table tbody td:nth-child(1),
  #result-table thead th:first-child {
    width: 112px;
    min-width: 112px;
  }

  .file-chip {
    order: 0;
  }
  .brand-spec {
    grid-template-columns: 1fr;
  }
  .brand-mid h1 {
    font-size: 26px;
  }
  .login-foot {
    flex-wrap: wrap;
    row-gap: 4px;
    font-size: 11px;
    letter-spacing: 0.06em;
  }
  .modal {
    padding: var(--s-5);
  }
  .modal-wide {
    width: 100%;
  }
  #kline-chart {
    height: 320px;
  }
  .empty {
    padding: var(--s-5);
  }
}

/* 尊重系统的减弱动效偏好 */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============================== 主题切换过渡 ============================== */
/* 只在切换瞬间挂 200ms，避免给全表单元格常驻 transition（大表会掉帧） */
html.is-theming body,
html.is-theming .rail,
html.is-theming .cmdbar,
html.is-theming .stats,
html.is-theming .surface,
html.is-theming .console,
html.is-theming .log-box,
html.is-theming .modal,
html.is-theming .login-brand,
html.is-theming .login-pane,
html.is-theming .btn,
html.is-theming .theme-btn,
html.is-theming .file-chip,
html.is-theming .empty,
html.is-theming input,
html.is-theming #result-table thead th,
html.is-theming .stat-v {
  transition: background-color 200ms var(--ease-out), border-color 200ms var(--ease-out),
    color 200ms var(--ease-out);
}
