/* Flip Signal 纸面监控 — 深色终端风格，手机浏览器兼容（≥14px 字体） */
:root {
  --bg: #0d1117;
  --card: #161b22;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #58a6ff;
  --pos: #3fb950;
  --neg: #f85149;
  --up: #3fb950;
  --down: #d29922;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

/* ── 顶栏 ── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: rgba(13, 17, 23, 0.92);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 18px; font-weight: 700; }
.dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--neg);
  transition: background 0.3s;
}
.dot.live { background: var(--pos); box-shadow: 0 0 8px var(--pos); }
.badge {
  font-size: 12px; padding: 2px 8px; border-radius: 10px;
  background: var(--accent); color: #0d1117; font-weight: 600;
}
.uptime { font-size: 13px; color: var(--muted); }

/* ── 布局 ── */
main {
  max-width: 960px;
  margin: 0 auto;
  padding: 14px 12px calc(60px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}
.card h2 { font-size: 15px; font-weight: 600; margin-bottom: 10px; color: var(--muted); }

/* ── 统计 ── */
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.stat { text-align: center; padding: 12px 6px; }
.stat-val { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-lbl { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat-val.pos { color: var(--pos); }
.stat-val.neg { color: var(--neg); }

/* 实盘执行摘要条（mode=live 显示；paper 隐藏） */
.livebar {
  font-size: 13px;
  padding: 8px 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.livebar.pos { border-color: var(--pos); color: var(--pos); }
.livebar.neg { border-color: var(--neg); color: var(--neg); }

/* 日亏熔断摘要（两模式都显示; paper = 影子, 闸只标记不拦 POST） */
.riskbar {
  font-size: 13px;
  padding: 8px 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.riskbar.neg { border-color: var(--neg); color: var(--neg); }

/* ── 当前窗口 ── */
.win-head { display: flex; justify-content: space-between; align-items: center; }
.engine-state { font-size: 13px; padding: 2px 10px; border-radius: 10px; background: #21262d; }
.engine-state.watching { background: #21262d; color: var(--muted); }
.engine-state.done { background: #001f14; color: var(--pos); }
.win-slug {
  font-size: 13px; color: var(--muted);
  margin: 6px 0 12px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.win-slug a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px dashed var(--accent);
}
.win-slug a:active { opacity: 0.7; }
/* 三列: UP 卡 / TWAP 差（定宽窄列——数值位数变化时不推挤两侧卡片） / DOWN 卡 */
.win-grid { display: grid; grid-template-columns: 1fr 96px 1fr; gap: 12px; }
.win-mid {
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums;
  white-space: nowrap;
  color: var(--muted); /* 无数据（无推送/锚缺失）时显示「—」的灰 */
}
.win-mid.pos { color: var(--pos); }
.win-mid.neg { color: var(--neg); }
.side {
  border: 1px solid var(--border); border-radius: 10px;
  padding: 10px; text-align: center;
}
.side.up { border-color: rgba(63, 185, 80, 0.4); }
.side.down { border-color: rgba(210, 153, 34, 0.4); }
.side-name { font-size: 12px; color: var(--muted); font-weight: 600; }
.side-bid { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }
.side.up .side-bid { color: var(--up); }
.side.down .side-bid { color: var(--down); }
.side-ask { font-size: 12px; color: var(--muted); }
.win-meta {
  display: flex; flex-wrap: wrap; gap: 14px;
  margin-top: 12px; font-size: 13px; color: var(--muted);
}
.win-meta b { color: var(--text); font-variant-numeric: tabular-nums; }
.win-meta b.stale { color: var(--neg); }
/* 数据源本地接收龄（spot / twap 共用）: 无推送或超阈标红 */
.src-age { font-size: 12px; }
.src-age.stale { color: var(--neg); }

/* 本窗 tick 健康度（图表/阈值标红之外的诊断行） */
.win-health {
  display: flex; flex-wrap: wrap; gap: 14px;
  margin-top: 8px; padding-top: 8px; font-size: 12px; color: var(--muted);
  border-top: 1px solid var(--border);
}
.win-health b { color: var(--text); font-variant-numeric: tabular-nums; }
.win-health .lost { margin-left: auto; }
.win-health .lost.warn { color: var(--down); }

/* ── 列表 ── */
.list-head { display: flex; justify-content: space-between; align-items: center; }
.refresh {
  background: #21262d; color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 4px 12px; font-size: 13px; cursor: pointer;
}
.refresh:active { background: #30363d; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left; color: var(--muted); font-weight: 500;
  font-size: 12px; padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td { padding: 7px 8px; border-bottom: 1px solid #21262d; font-variant-numeric: tabular-nums; white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }

.side-tag {
  display: inline-block; min-width: 34px; text-align: center;
  font-size: 12px; font-weight: 700; padding: 1px 6px; border-radius: 6px;
}
.side-tag.up { background: rgba(63, 185, 80, 0.15); color: var(--up); }
.side-tag.down { background: rgba(210, 153, 34, 0.15); color: var(--down); }
/* 狗侧记录标签: yes(=UP) 绿 / no(=DOWN) 金（v4 记录侧语义，颜色沿用 up/down） */
.side-tag.yes { background: rgba(63, 185, 80, 0.15); color: var(--up); }
.side-tag.no { background: rgba(210, 153, 34, 0.15); color: var(--down); }

.won { color: var(--pos); font-weight: 600; }
.lost { color: var(--neg); font-weight: 600; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.muted { color: var(--muted); }

.empty { text-align: center; color: var(--muted); font-size: 13px; padding: 16px 0; }

/* ── 分页条 ── */
.pager {
  display: flex; align-items: center; justify-content: center;
  flex-wrap: wrap; gap: 6px; padding-top: 10px;
}
/* display:flex 会覆盖 [hidden] 的默认 display:none——必须显式补回（同 modal-mask） */
.pager[hidden] { display: none; }
.pg {
  min-width: 32px; height: 28px; padding: 0 8px;
  background: #21262d; color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  font-size: 13px; line-height: 1; cursor: pointer;
}
.pg:active { background: #30363d; }
.pg:disabled { opacity: 0.35; cursor: default; }
.pg-info { font-size: 12px; color: var(--muted); padding: 0 6px; }

/* ── 底部 ── */
.foot {
  position: fixed; bottom: 0; left: 0; right: 0;
  text-align: center; font-size: 12px; color: var(--muted);
  padding: 8px;
  background: rgba(13, 17, 23, 0.92);
  border-top: 1px solid var(--border);
}

/* ── 手机适配：宽屏 6 列统计/紧凑列表，窄屏 3 列堆叠 ── */
@media (min-width: 640px) {
  .stats { grid-template-columns: repeat(6, 1fr); }
}
@media (max-width: 480px) {
  body { font-size: 14px; }
  .stats { gap: 8px; }
  .stat-val { font-size: 18px; }
  .side-bid { font-size: 24px; }
  /* 窄屏: 中间列收窄（字号同步降）给两侧卡片让宽度 */
  .win-grid { grid-template-columns: 1fr 80px 1fr; }
  .win-mid { font-size: 16px; }
  table { font-size: 13px; }
  /* 窄屏隐藏次要列（m45），保持可读性 */
  #signalsTable th:nth-child(5), #signalsTable td:nth-child(5),
  #obsTable th:nth-child(5), #obsTable td:nth-child(5) { display: none; }
}
/* ── 逐日盈利弹窗（点击「逐日盈利」卡片打开）── */
.clickable { cursor: pointer; }
.stat.clickable:hover { outline: 1px solid var(--accent); }

.modal-mask {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0, 0, 0, 0.62);
  display: flex; align-items: center; justify-content: center;
  padding: 12px;
}
/* display:flex 会覆盖浏览器对 hidden 属性的默认 display:none——必须显式补回 */
.modal-mask[hidden] { display: none; }
.modal {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 100%; max-width: 640px;
  max-height: 86vh;
  display: flex; flex-direction: column;
  overflow: hidden;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.55);
  animation: modal-pop 0.18s ease-out;
}
@keyframes modal-pop {
  from { opacity: 0; transform: translateY(10px) scale(0.985); }
  to   { opacity: 1; transform: none; }
}
.modal-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 12px; padding: 14px 16px 10px;
  border-bottom: 1px solid #21262d;
  background: #12161d;
}
.modal-title { flex: 1; min-width: 0; }
.modal-head h2 { font-size: 15px; font-weight: 700; margin: 0; }
.modal-sub { margin-top: 3px; font-size: 12px; color: var(--muted); }
.modal-close {
  background: #21262d; border: none; color: var(--muted);
  font-size: 14px; line-height: 1; cursor: pointer;
  width: 26px; height: 26px; border-radius: 8px;
  flex: none;
}
.modal-close:hover { background: #2d333b; color: #fff; }
/* 表格滚动区: 行多时纵向滚动, 表头/合计行吸在两端 */
.modal-body {
  overflow: auto;
  flex: 1; min-height: 0;
  -webkit-overflow-scrolling: touch;
}
/* collapse 下 sticky 表头/表脚在部分浏览器失效——单独开 separate */
#dailyTable { border-collapse: separate; border-spacing: 0; }
#dailyTable thead th {
  position: sticky; top: 0; z-index: 2;
  background: #0d1117;
  border-bottom: 1px solid var(--border);
}
#dailyTable tfoot td {
  position: sticky; bottom: 0; z-index: 1;
  background: #12161d;
  border-top: 1px solid var(--border);
  font-weight: 700;
}
/* 数值列右对齐; 日期列左对齐 */
#dailyTable th { text-align: right; }
#dailyTable td { text-align: right; }
#dailyTable th:first-child, #dailyTable td:first-child { text-align: left; }
#dailyTable tbody tr:hover { background: rgba(255, 255, 255, 0.03); }
#dailyTable tbody td, #dailyTable tfoot td { padding: 6px 10px; }

/* 窄屏（手机）: 全屏面板, 表头少占位 */
@media (max-width: 480px) {
  .modal-mask { padding: 0; }
  .modal { max-width: none; max-height: 100vh; height: 100%; border-radius: 0; border: none; }
}
