/* perp-system 监控看板
   手机优先、深色为主、信息密度高。状态永远同时用文字、图标和颜色表达，
   所以在黑白截图或色觉障碍下依然可读。 */

:root, :root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0f14;
  --panel: #121821;
  --panel-2: #0e141c;
  --line: #1e2836;
  --line-soft: #172130;
  --text: #dbe4ef;
  --muted: #93a5bb;
  --dim: #63758b;
  --up: #3fb950;
  --down: #f0616d;
  --flat: #8ea0b6;
  --normal: #3fb950;
  --caution: #e3b341;
  --risk: #f0883e;
  --data_error: #f0616d;
  --prod: #4493f8;
  --research: #e3b341;
  --shadow: #a371f7;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
          "Liberation Mono", monospace;
}

/* 深色是这块看板的默认外观，不随系统偏好切换；浅色是读者主动切出来的，
   所以用 data-theme 显式选择，而不是 prefers-color-scheme。 */
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f7fa;
  --panel: #ffffff;
  --panel-2: #eef2f7;
  --line: #d8e0ea;
  --line-soft: #e6ecf3;
  --text: #16202c;
  --muted: #4a5b70;
  --dim: #6b7c92;
  --up: #1a7f37;
  --down: #cf222e;
  --flat: #5b6b80;
  --normal: #1a7f37;
  --caution: #9a6700;
  --risk: #bc4c00;
  --data_error: #cf222e;
  --prod: #0969da;
  --research: #9a6700;
  --shadow: #8250df;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  -webkit-text-size-adjust: 100%;
  padding-bottom: env(safe-area-inset-bottom);
}

a { color: var(--prod); text-decoration: none; }
h1, h2, h3 { margin: 0; font-weight: 650; }
h1 { font-size: 17px; }
h2 { font-size: 15px; }
h3 { font-size: 14px; }
code, .mono, .num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ---------- 顶栏与导航 ---------- */

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--panel); border-bottom: 1px solid var(--line);
  padding: 10px 12px calc(10px + env(safe-area-inset-top)) 12px;
  padding-top: calc(10px + env(safe-area-inset-top));
}
.topbar-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.topbar .title { font-size: 16px; font-weight: 700; }
.topbar .sub { color: var(--dim); font-size: 12px; }

.riskstrip {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
  margin-top: 8px; font-size: 13px;
}
.riskstrip .item {
  background: var(--panel-2); border: 1px solid var(--line-soft);
  border-radius: 999px; padding: 3px 10px; white-space: nowrap;
}
.riskstrip .item b { font-weight: 650; }

.tabs {
  position: sticky; top: 0; z-index: 10;
  display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none;
  background: var(--panel-2); border-bottom: 1px solid var(--line);
  padding: 6px 8px;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  color: var(--muted); font-size: 13px; white-space: nowrap;
  padding: 6px 11px; border-radius: 999px; border: 1px solid transparent;
}
.tabs a.on {
  color: var(--text); background: var(--panel);
  border-color: var(--line);
}
.tabs a .dot { font-size: 10px; margin-right: 3px; }

main { padding: 12px 12px 40px 12px; max-width: 1440px; margin: 0 auto; }

/* ---------- 面板 ---------- */

.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px; margin-bottom: 12px;
}
.panel > header {
  display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap;
  margin-bottom: 8px;
}
.panel > header .hint { color: var(--dim); font-size: 12px; }
.note {
  color: var(--muted); font-size: 12.5px; line-height: 1.6;
  background: var(--panel-2); border-left: 3px solid var(--line);
  border-radius: 4px; padding: 7px 10px; margin: 8px 0;
}
.note.warn { border-left-color: var(--caution); }
.note.stop { border-left-color: var(--data_error); }
.empty { color: var(--dim); font-size: 13px; padding: 10px 2px; }

/* ---------- 生产 / 研究 / 影子 ---------- */

.track { border-left: 4px solid var(--prod); }
.track-production { border-left-color: var(--prod); }
.track-research { border-left-color: var(--research); }
.track-shadow {
  border-left-color: var(--shadow);
  border-style: dashed; border-width: 1px 1px 1px 4px;
}
.tag {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 11px; padding: 1px 7px; border-radius: 999px;
  border: 1px solid currentColor; white-space: nowrap;
}
.tag-production { color: var(--prod); }
.tag-research { color: var(--research); }
.tag-shadow { color: var(--shadow); }

/* ---------- 状态 ---------- */

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12.5px; font-weight: 650; padding: 2px 9px;
  border-radius: 999px; border: 1px solid currentColor;
  white-space: nowrap;
}
.badge .ic { font-size: 11px; }
.lv-normal { color: var(--normal); }
.lv-caution { color: var(--caution); }
.lv-risk { color: var(--risk); }
.lv-data_error { color: var(--data_error); }
.big-status {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  font-size: 20px; font-weight: 700;
}

.up { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--flat); }
.stale { color: var(--data_error); font-weight: 650; }

/* ---------- 指标格 ---------- */

.grid {
  display: grid; gap: 8px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.metric {
  background: var(--panel-2); border: 1px solid var(--line-soft);
  border-radius: 8px; padding: 8px 10px;
}
.metric .k { color: var(--dim); font-size: 11.5px; }
.metric .v { font-size: 18px; font-weight: 650; font-family: var(--mono);
             font-variant-numeric: tabular-nums; }
.metric .s { color: var(--muted); font-size: 11.5px; }

/* ---------- 卡片 ---------- */

.cards { display: grid; gap: 10px;
         grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); }
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px 11px;
}
.card > header {
  display: flex; align-items: center; gap: 7px; flex-wrap: wrap;
  margin-bottom: 6px;
}
.card .sym { font-size: 16px; font-weight: 700; letter-spacing: .2px; }
.card .tf {
  font-size: 11.5px; color: var(--muted); border: 1px solid var(--line);
  border-radius: 4px; padding: 0 5px;
}
.kv {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 3px 10px; font-size: 12.5px;
}
@media (min-width: 560px) {
  .kv { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
.kv > div { display: flex; justify-content: space-between; gap: 6px;
            border-bottom: 1px dotted var(--line-soft); padding: 2px 0; }
.kv .k { color: var(--dim); }
.kv .v { font-family: var(--mono); font-variant-numeric: tabular-nums; }

.plan {
  margin-top: 8px; padding: 8px 9px; border-radius: 8px;
  background: var(--panel-2); border: 1px solid var(--line-soft);
}
.plan.research { border-color: var(--research); border-style: dashed; }
.plan > header { display: flex; gap: 7px; flex-wrap: wrap;
                 align-items: center; margin-bottom: 5px; font-size: 12.5px; }
.flags { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 6px; }
.flag {
  font-size: 11px; color: var(--risk); border: 1px solid var(--risk);
  border-radius: 4px; padding: 0 5px;
}
.reason { font-size: 11px; color: var(--muted);
          border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; }

/* ---------- 表格：宽屏是表，手机是卡 ---------- */

.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 12.5px; }
th, td { text-align: right; padding: 6px 7px; white-space: nowrap;
         border-bottom: 1px solid var(--line-soft); }
th:first-child, td:first-child { text-align: left; }
th { color: var(--dim); font-weight: 600; font-size: 11.5px; }
th[data-sort] { cursor: pointer; }
th[data-sort]:hover { color: var(--text); }
td.num, td .num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
tbody tr:hover { background: var(--panel-2); }

@media (max-width: 640px) {
  table.responsive, table.responsive tbody, table.responsive tr,
  table.responsive td { display: block; width: 100%; }
  table.responsive thead { display: none; }
  table.responsive tr {
    background: var(--panel-2); border: 1px solid var(--line-soft);
    border-radius: 8px; padding: 7px 9px; margin-bottom: 8px;
  }
  table.responsive td {
    display: flex; justify-content: space-between; gap: 10px;
    text-align: right; border-bottom: 1px dotted var(--line-soft);
    padding: 3px 0; white-space: normal;
  }
  table.responsive td:last-child { border-bottom: 0; }
  table.responsive td::before {
    content: attr(data-k); color: var(--dim); text-align: left;
    font-size: 11.5px; flex: 0 0 auto;
  }
}

/* ---------- 筛选条 ---------- */

.filters {
  display: flex; gap: 6px; flex-wrap: wrap; align-items: center;
  margin-bottom: 10px;
}
.filters input, .filters select {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 7px;
  padding: 6px 9px; font-size: 13px; font-family: inherit;
}
.filters input { min-width: 120px; flex: 1 1 130px; }
.filters .count { color: var(--dim); font-size: 12px; margin-left: auto; }
.hidden { display: none !important; }

/* ---------- 条形图（内联 SVG，无外部依赖） ---------- */

.bars { display: grid; gap: 4px; }
.bar-row { display: grid; grid-template-columns: 74px 1fr 76px;
           gap: 8px; align-items: center; font-size: 12px; }
.bar-row .lab { color: var(--muted); }
.bar-row .val { text-align: right; font-family: var(--mono); }
.bar-track { background: var(--panel-2); border-radius: 3px; height: 12px;
             position: relative; overflow: hidden;
             border: 1px solid var(--line-soft); }
.bar-fill { position: absolute; top: 0; bottom: 0; }
.bar-zero { position: absolute; top: 0; bottom: 0; width: 1px;
            background: var(--line); }

/* ---------- 页脚 ---------- */

footer {
  color: var(--dim); font-size: 11.5px; line-height: 1.7;
  padding: 14px 12px 30px; border-top: 1px solid var(--line);
  max-width: 1440px; margin: 0 auto;
}
footer b { color: var(--muted); font-weight: 600; }

.freshness { display: grid; gap: 3px; font-size: 11.5px; }
.freshness .row { display: flex; gap: 8px; justify-content: space-between; }

/* 导航圆点与标签：颜色由类决定，不用行内 style（CSP 禁止行内样式）。 */
.dot-production { color: var(--prod); }
.dot-research { color: var(--research); }
.dot-shadow { color: var(--shadow); }
.tag-alarm { color: var(--data_error); }
.subtle { color: var(--dim); font-size: 11px; }
h3.group { margin: 12px 0 6px; }

.ghost {
  margin-left: auto; background: var(--panel-2); color: var(--muted);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 3px 10px; font-size: 13px; line-height: 1.4; cursor: pointer;
  font-family: inherit;
}
.ghost:hover { color: var(--text); }

