/* 币安永续 · EMA 回踩监控 —— 深色交易终端风格
   ============================================================
   本文件是**基础层**：设计令牌（:root）、reset、html/body 基础、
   顶栏与侧栏骨架，以及按钮 / 表单 / 表格 / 标签等通用组件。
   外壳布局与各页特有样式在 app.css —— index.html 里它在本文件**之后**加载，
   所以那一层可以覆盖本层。
   ⚠️ 新增样式请按上述分工归位；同一个选择器不要在两份文件里各定义一遍
      （历史上 html / body / .topbar 就重复过一次，已清理）。
   ⚠️ 令牌是颜色的唯一来源 —— 别在别处硬编码色值。 */

:root {
  --bg:        #0b0e14;
  --bg-2:      #11151f;
  --panel:     #131822;
  --panel-2:   #171d29;
  --line:      #1f2635;
  --line-2:    #2a3346;
  --tx:        #d6dae4;
  --tx-2:      #8b93a7;
  --tx-3:      #5d6478;
  --up:        #f6465d;   /* 涨 = 红（中式） */
  --down:      #0ecb81;   /* 跌 = 绿 */
  /* ⚠️ 交易**方向**色与"涨跌色"是两套语义，别混用（用户 2026-09-24 明确要求）：
       做多/买入 = 绿、做空/卖出 = 红 —— 与币安 / OKX 的下单按钮一致。
       行情涨跌、盈亏正负仍走上面的 --up / --down（红涨绿跌）。 */
  --side-long:  #0ecb81;  /* 做多 / 开多 / 买入 */
  --side-short: #f6465d;  /* 做空 / 开空 / 卖出 */
  --amber:     #f0b90b;   /* EMA99 */
  --violet:    #7d8cff;   /* EMA200 */
  --cyan:      #22c3d6;
  --danger:    #ff6b6b;
  /* 持仓标记（EMA 监控页交易对列）—— 三档「炫彩」色。
     ⚠️ 这是这三个颜色的**唯一**定义处；前端 JS（js/holdings.js）只放语义，
        不放色值，免得改色要改两处。 */
  --hold-paper: #00ff9c;   /* 炫绿：只有模拟盘有仓 */
  --hold-real:  #ffd24a;   /* 炫金：只有实盘有仓 */
  --hold-both:  #ff4d5e;   /* 炫红：模拟盘与实盘都有仓 */
  --hold-paper-glow: rgba(0, 255, 156, .45);
  --hold-real-glow:  rgba(255, 210, 74, .45);
  --hold-both-glow:  rgba(255, 77, 94, .45);
  --radius:    10px;
  --mono: "JetBrains Mono", "SF Mono", "Cascadia Mono", Consolas,
          "Noto Sans Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

/* body 必须允许随内容增高: 若用 height:100% 钉死为视口高度,
   sticky 元素会被"推出"包含块而在滚动一屏后集体失效 */
html { height: 100%; }
body { min-height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--tx);
  font: 13px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI",
        "Microsoft YaHei UI", "Microsoft YaHei", "PingFang SC",
        system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

b, .num { font-variant-numeric: tabular-nums; }
b { font-weight: 600; }

.muted { color: var(--tx-2); }

/* ------------------------------------------------------------- topbar */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 18px;
  padding: 0 18px; height: 54px;
  background: rgba(11, 14, 20, .88);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.logo { width: 25px; height: 25px; border-radius: 6px; display: block; }
.brand h1 {
  margin: 0; font-size: 14.5px; font-weight: 650; letter-spacing: .2px;
  white-space: nowrap;
}

.chip {
  font-size: 10.5px; font-weight: 700; letter-spacing: .6px;
  padding: 2px 6px; border-radius: 4px;
}
.chip-tf { background: rgba(240,185,11,.14); color: var(--amber);
           border: 1px solid rgba(240,185,11,.3); }

.status {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--tx-2);
  flex: 1; min-width: 0; overflow: hidden;
}
.status b { color: var(--tx); font-family: var(--mono); font-size: 12px; }
.status .sep { width: 1px; height: 12px; background: var(--line-2); flex-shrink: 0; }
.status > span { white-space: nowrap; }

.dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--tx-3); flex-shrink: 0;
  transition: background .3s, box-shadow .3s;
}
.dot.live   { background: var(--down); box-shadow: 0 0 0 3px rgba(14,203,129,.15); }
.dot.busy   { background: var(--amber); box-shadow: 0 0 0 3px rgba(240,185,11,.18);
              animation: pulse 1s ease-in-out infinite; }
.dot.err    { background: var(--up); box-shadow: 0 0 0 3px rgba(246,70,93,.18); }
@keyframes pulse { 50% { opacity: .35; } }

.countdown { color: var(--cyan) !important; }

/* 检测阶段标识：盘中预判 vs 最终判定 */
.phase {
  font-size: 10.5px; font-weight: 700; letter-spacing: .3px;
  padding: 2px 7px; border-radius: 4px; white-space: nowrap;
  font-family: -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
  flex-shrink: 0;
}
.phase-final { background: rgba(14,203,129,.14); color: var(--down);
               border: 1px solid rgba(14,203,129,.32); }
.phase-intraday { background: rgba(240,185,11,.16); color: var(--amber);
                  border: 1px solid rgba(240,185,11,.38); }
tr.row-intraday .c-sym .sym-sub::after { content: " · 未收盘"; color: var(--amber); }

.actions { display: flex; gap: 8px; flex-shrink: 0; }

.btn {
  font: inherit; font-size: 12px; font-weight: 550;
  padding: 6px 12px; border-radius: 7px; cursor: pointer;
  border: 1px solid var(--line-2); background: var(--panel-2); color: var(--tx);
  transition: background .15s, border-color .15s, opacity .15s;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: #1e2637; border-color: #37415a; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-ghost { background: transparent; }
.btn-ghost:hover:not(:disabled) { background: var(--panel-2); }

/* ------------------------------------------------------------- 图标 */
/* Icon 组件渲染 <span class="ico"><svg/></span>。
   ⚠️ 这里必须有全局默认尺寸：svg 不写 width/height 时按 CSS 默认 300x150 渲染，
   在 flex 容器里会被挤压侥幸正常，在普通容器（如 .btn）里会把卡片撑爆 ——
   设置页「退出登录」按钮实翻过车。具体场景按需覆盖 .ico 的宽高即可。 */
.ico { display: inline-flex; width: 15px; height: 15px; flex-shrink: 0; }
.ico svg { width: 100%; height: 100%; }

/* ------------------------------------------------------------- kpi row */
.kpirow {
  display: grid; grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 1px; background: var(--line);
  border-bottom: 1px solid var(--line);
}
.kpi {
  background: var(--bg-2); padding: 9px 16px;
  display: flex; flex-direction: column; gap: 1px;
  border-left: 2px solid transparent;
}
.kpi .k-v {
  font-family: var(--mono); font-size: 19px; font-weight: 700;
  line-height: 1.15; letter-spacing: -.3px;
}
.kpi .k-l { font-size: 11px; color: var(--tx-3); letter-spacing: .3px; }
.kpi-a { border-left-color: var(--amber); }
.kpi-a .k-v { color: var(--amber); }
.kpi-b { border-left-color: var(--violet); }
.kpi-b .k-v { color: var(--violet); }
.kpi-warn .k-v { color: var(--tx-2); }
.kpi-warn.has .k-v { color: var(--danger); }

/* ------------------------------------------------------------- controls */
.controls {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 11px 18px; border-bottom: 1px solid var(--line);
  background: var(--bg-2); position: sticky;
  top: var(--topbar-h, 54px); z-index: 20;
}

.tabs { display: flex; gap: 3px; background: #0d121b;
        padding: 3px; border-radius: 9px; border: 1px solid var(--line); }
.tab {
  font: inherit; font-size: 12.5px; font-weight: 550;
  padding: 5px 12px; border-radius: 6px; cursor: pointer;
  border: 0; background: transparent; color: var(--tx-2);
  transition: background .15s, color .15s;
  display: flex; align-items: center; gap: 6px; white-space: nowrap;
}
.tab:hover { color: var(--tx); }
.tab.is-active { background: var(--panel-2); color: var(--tx); }
.tab .cnt {
  font-family: var(--mono); font-size: 10.5px; font-weight: 700;
  padding: 1px 5px; border-radius: 20px;
  background: #232c3e; color: var(--tx-2);
}
.tab.is-active .cnt { background: var(--amber); color: #1a1205; }
.tab[data-tab="ema99"].is-active .cnt  { background: var(--amber);  color: #1a1205; }
.tab[data-tab="ema200"].is-active .cnt { background: var(--violet); color: #0b0e14; }

.filters { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }

.rng { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.rng b { color: var(--amber); font-family: var(--mono); min-width: 38px; }
input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 108px; height: 4px; border-radius: 3px; outline: none;
  background: linear-gradient(90deg, var(--amber) 0%, var(--amber) 45%,
                              var(--line-2) 45%, var(--line-2) 100%);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 13px; height: 13px; border-radius: 50%;
  background: var(--amber); cursor: pointer; border: 2px solid var(--bg-2);
  box-shadow: 0 0 0 1px var(--amber);
}
input[type="range"]::-moz-range-thumb {
  width: 11px; height: 11px; border-radius: 50%; background: var(--amber);
  cursor: pointer; border: 2px solid var(--bg-2);
}

.chk { display: flex; align-items: center; gap: 6px; font-size: 12px;
       color: var(--tx-2); cursor: pointer; user-select: none; }
.chk input { accent-color: var(--amber); width: 13px; height: 13px; cursor: pointer; }
.chk:hover { color: var(--tx); }

/* ---------------------------------------------------------- 视图切换 */
.vswitch {
  display: flex; gap: 2px; background: #0d121b; padding: 3px;
  border-radius: 8px; border: 1px solid var(--line); flex-shrink: 0;
}
.vs {
  font: inherit; font-size: 12px; font-weight: 550;
  padding: 4px 11px; border-radius: 6px; cursor: pointer;
  border: 0; background: transparent; color: var(--tx-2);
  transition: background .15s, color .15s; white-space: nowrap;
}
.vs:hover { color: var(--tx); }
.vs.is-active { background: var(--panel-2); color: var(--amber); }

/* ---------------------------------------------------------- 记录视图 */
/* 记录页的「日期 + 时段」双选择栏。
 * ⚠️ 候选基于全量批次，不随选中项收缩（否则选了 08:00 就再也切不回 12:00）。 */
.sel { display: flex; align-items: center; gap: 8px; font-size: 12px; flex-shrink: 0; }
.sel select { width: auto; min-width: 108px; font-family: var(--mono); }
.sel select:first-of-type { min-width: 150px; }
.sel .btn { flex-shrink: 0; }
.rec-note { font-size: 11.5px; color: var(--tx-3); font-family: var(--mono);
            white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
            min-width: 0; flex: 1 1 auto; }
.kpi-up { border-left-color: var(--up); }
.kpi-up .k-v { color: var(--up); }
.kpi-down { border-left-color: var(--down); }
.kpi-down .k-v { color: var(--down); }
.rel-strong { font-weight: 700; }

input[type="search"], select {
  font: inherit; font-size: 12px; color: var(--tx);
  background: #0d121b; border: 1px solid var(--line-2);
  border-radius: 7px; padding: 6px 10px; outline: none;
}
input[type="search"] { width: 168px; }
input[type="search"]:focus, select:focus { border-color: #3d4c6b; }
select { cursor: pointer; }
input[type="search"]::placeholder { color: var(--tx-3); }

/* ------------------------------------------------------------- table */
.wrap { padding: 0 0 30px; }

.grid {
  width: 100%; border-collapse: separate; border-spacing: 0;
  font-size: 12.5px;
}

.grid thead th {
  position: sticky; top: var(--thead-top, 114px); z-index: 10;
  background: #0d121b; color: var(--tx-3);
  font-size: 10.5px; font-weight: 600; letter-spacing: .5px;
  text-transform: uppercase; text-align: right;
  padding: 8px 10px; border-bottom: 1px solid var(--line-2);
  white-space: nowrap; user-select: none;
}
.grid thead th.sortable { cursor: pointer; }
.grid thead th.sortable:hover { color: var(--tx); }
.grid thead th.c-sym, .grid thead th.c-hit { text-align: left; }
.grid thead th.c-fav { text-align: center; width: 38px; }
.grid thead th.on { color: var(--amber); }
.grid thead th.on::after { content: " ▾"; font-size: 9px; }

.grid tbody td {
  padding: 7px 10px; text-align: right;
  border-bottom: 1px solid #161c28;
  font-family: var(--mono); font-size: 12px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.grid tbody tr { transition: background .1s; }
.grid tbody tr:hover { background: #131a26; }
.grid tbody tr.hit-a { box-shadow: inset 3px 0 0 var(--amber); }
.grid tbody tr.hit-b { box-shadow: inset 3px 0 0 var(--violet); }
.grid tbody tr.hit-ab {
  box-shadow: inset 3px 0 0 var(--violet), inset 6px 0 0 var(--amber);
}
.grid tbody tr.is-fav td.c-fav .star { color: var(--amber); }

td.c-fav { text-align: center !important; cursor: pointer; width: 38px; }
.star { font-size: 14px; color: #333d52; transition: color .15s, transform .1s;
        display: inline-block; line-height: 1; }
td.c-fav:hover .star { transform: scale(1.18); }
tr.is-fav .star { color: var(--amber); }

.c-sym { text-align: left !important; }
.sym {
  font-family: -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-size: 13px; font-weight: 600; letter-spacing: .1px;
}
.sym .base { color: var(--tx); }
.sym .quote { color: var(--tx-3); font-weight: 500; font-size: 11.5px; }

/* 持仓标记（EMA 监控页「交易对」列）：当交易后回头看一眼「这个标的是不是我买的」。
   只染币种主体，USDT 后缀保持灰 —— 整串彩色在长列表里会糊成一片、反而更难扫。
   ⚠️ 选择器必须带 .sym 前缀（只作用于交易对单元格），
      否则将来别处用 hold-both 这种通用类名会误伤。
   色值全部来自 --hold-* 令牌，别在这里写死。 */
.sym.hold-paper .base { color: var(--hold-paper); text-shadow: 0 0 6px var(--hold-paper-glow); }
.sym.hold-real  .base { color: var(--hold-real);  text-shadow: 0 0 6px var(--hold-real-glow); }
.sym.hold-both  .base { color: var(--hold-both);  text-shadow: 0 0 6px var(--hold-both-glow); }

/* 状态条里的图例（点 + 文案），与上面的三档一一对应 */
.hold-legend { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.hold-legend .hl-dot {
  width: 7px; height: 7px; border-radius: 2px; display: inline-block;
  vertical-align: middle;
}
.hold-legend .hl-dot.d-paper { background: var(--hold-paper); }
.hold-legend .hl-dot.d-real  { background: var(--hold-real); }
.hold-legend .hl-dot.d-both  { background: var(--hold-both); }
.hold-legend .hl-sep { width: 1px; height: 10px; background: var(--line-2); }
.hold-legend .hl-warn { color: var(--amber); }

.sym-sub { font-size: 10.5px; color: var(--tx-3); font-weight: 400;
           font-family: var(--mono); margin-top: 1px; }

.c-hit { text-align: left !important; }
.pill {
  display: inline-block; font-size: 10px; font-weight: 700;
  padding: 1.5px 6px; border-radius: 4px; letter-spacing: .3px;
  font-family: -apple-system, "Segoe UI", sans-serif;
  margin-right: 3px;
}
.pill-a { background: rgba(240,185,11,.16); color: var(--amber);
          border: 1px solid rgba(240,185,11,.32); }
.pill-b { background: rgba(125,140,255,.16); color: var(--violet);
          border: 1px solid rgba(125,140,255,.32); }
.pill-bear { background: rgba(93,100,120,.16); color: var(--tx-3);
             border: 1px solid var(--line-2); }
.pill-warm { background: rgba(255,107,107,.13); color: #ff9a9a;
             border: 1px solid rgba(255,107,107,.3); }

.up   { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--tx-2); }

.dev { position: relative; font-weight: 650; }
.dev-hit  { color: var(--amber); }
.dev-near { color: #d8b45c; }
.dev-far  { color: var(--tx-3); font-weight: 400; }
/* 跌穿回踩带下界：已不是「回踩」，压暗以区别于 dev-hit */
.dev-draw { color: #b06a78; font-weight: 400; }

.vol { color: var(--tx-2); }

.gap { color: var(--tx-2); }

/* ------------------------------------------------------------- empty */
.empty { padding: 70px 20px; text-align: center; color: var(--tx-3); }
.empty-ico { width: 52px; height: 52px; color: var(--tx-3); margin-bottom: 10px; }
.empty p { margin: 0; font-size: 13px; }

/* ------------------------------------------------------------- footer */
.foot {
  border-top: 1px solid var(--line); padding: 14px 18px 22px;
  background: var(--bg-2); font-size: 11.5px; color: var(--tx-3);
}
.rule { display: flex; flex-wrap: wrap; gap: 6px 18px; align-items: baseline; }
.rule b { color: var(--tx-2); font-size: 11.5px; letter-spacing: .3px; }
.rule span { font-family: var(--mono); font-size: 11px; }
.rule u { text-decoration-color: var(--amber); text-underline-offset: 2px; }
.meta { display: flex; gap: 18px; margin-top: 8px; flex-wrap: wrap;
        font-family: var(--mono); font-size: 11px; }

/* ------------------------------------------------------------- toast */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--line-2);
  color: var(--tx); padding: 9px 16px; border-radius: 9px;
  font-size: 12.5px; box-shadow: 0 8px 28px rgba(0,0,0,.5); z-index: 90;
  animation: rise .2s ease-out;
}
.toast.err { border-color: rgba(246,70,93,.5); color: #ffb4be; }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } }

/* ------------------------------------------------------------- responsive */
@media (max-width: 1280px) {
  .kpirow { grid-template-columns: repeat(3, minmax(0,1fr)); }
}
@media (max-width: 980px) {
  .topbar { height: auto; flex-wrap: wrap; padding: 9px 14px; gap: 10px; }
  .status { order: 3; flex-basis: 100%; }
  .controls { position: static; }
  .hide-md { display: none; }
  .filters { width: 100%; }
  input[type="search"] { flex: 1; min-width: 120px; }
}
@media (max-width: 720px) {
  .kpirow { grid-template-columns: repeat(2, minmax(0,1fr)); }
}
