:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --nav: #1f2a33;
  --nav-ink: #e9eef2;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 2px 8px rgba(0, 0, 0, .04);
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #242423;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --good-text: #0ca30c;
  --nav: #141414;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px; color: var(--ink); background: var(--page);
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; cursor: pointer; }
[v-cloak] { display: none; }

/* ---------- 布局 ---------- */
.topbar {
  display: flex; align-items: center; gap: 24px; height: 52px; padding: 0 20px;
  background: var(--nav); color: var(--nav-ink); position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 600; font-size: 16px; letter-spacing: .5px; white-space: nowrap; }
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.nav a { color: var(--nav-ink); opacity: .72; padding: 6px 12px; border-radius: 6px; white-space: nowrap; }
.nav a:hover { opacity: 1; background: rgba(255, 255, 255, .06); }
.nav a.on { opacity: 1; background: rgba(255, 255, 255, .12); }
.nav .badge { margin-left: 6px; }
.userbox { display: flex; align-items: center; gap: 12px; white-space: nowrap; }
.userbox button { background: none; border: 1px solid rgba(255, 255, 255, .2); color: var(--nav-ink);
  border-radius: 6px; padding: 4px 10px; cursor: pointer; }
.userbox button:hover { background: rgba(255, 255, 255, .08); }
main { max-width: 1400px; margin: 0 auto; padding: 20px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h2 { margin: 0; font-size: 20px; font-weight: 600; }
.page-head .sub { color: var(--ink-2); }
.page-head .spacer { flex: 1; }

/* ---------- 通用组件 ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); }
.card-pad { padding: 16px; }
.btn { border: 1px solid var(--border); background: var(--surface); border-radius: 6px; padding: 6px 14px;
  cursor: pointer; line-height: 1.4; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--critical); }
.btn.sm { padding: 3px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 5px 12px; cursor: pointer; border-right: 1px solid var(--border); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--accent); color: var(--accent-ink); }
.badge { display: inline-block; min-width: 18px; padding: 0 6px; border-radius: 9px; font-size: 12px; line-height: 18px;
  text-align: center; background: var(--critical); color: #fff; }
.muted { color: var(--muted); }
.ink2 { color: var(--ink-2); }
.err { color: var(--critical); }
.mono { font-family: ui-monospace, Consolas, monospace; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }

/* 状态：颜色 + 图标 + 文字，不单靠颜色 */
.status { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 500;
  padding: 1px 8px; border-radius: 10px; border: 1px solid currentColor; white-space: nowrap; }
.status .ico { font-size: 11px; }
.st-good { color: var(--good-text); }
.st-critical { color: var(--critical); }
.st-serious { color: var(--serious); }
.st-warning { color: #9a6a00; }
:root[data-theme="dark"] .st-warning { color: var(--warning); }
.st-muted { color: var(--muted); }

/* ---------- 汇总条 ---------- */
.stats { display: grid; grid-template-columns: repeat(4, minmax(140px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { padding: 14px 16px; }
.stat .label { color: var(--ink-2); font-size: 13px; }
.stat .num { font-size: 28px; font-weight: 600; margin-top: 4px; }

/* ---------- 设备卡片 ---------- */
.devices { display: grid; grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); gap: 16px; }
.dev-card { cursor: pointer; transition: border-color .15s; }
.dev-card:hover { border-color: var(--accent); }
.dev-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px 10px; }
.dev-head .name { font-weight: 600; font-size: 16px; }
.dev-head .loc { color: var(--muted); font-size: 13px; }
.dev-head .spacer { flex: 1; }
.dev-foot { padding: 8px 16px 12px; color: var(--muted); font-size: 12px; display: flex; justify-content: space-between; }

/* 通道读数砖块 */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; padding: 0 16px; }
.tile { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; border-left: 3px solid var(--tile-c, var(--axis)); }
.tile .t-name { font-size: 13px; color: var(--ink-2); display: flex; justify-content: space-between; gap: 6px; }
.tile .t-val { font-size: 26px; font-weight: 600; margin: 4px 0 2px; white-space: nowrap; }
.tile .t-val .unit { font-size: 14px; font-weight: 400; color: var(--ink-2); margin-left: 3px; }
.tile .t-sub { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.tile.off .t-val { color: var(--muted); }
.tile.stale { opacity: .55; }

/* ---------- 表格 ---------- */
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
.tbl th { color: var(--ink-2); font-weight: 500; font-size: 13px; background: var(--surface-2); }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl-wrap { overflow-x: auto; }
.empty { padding: 40px; text-align: center; color: var(--muted); }

/* ---------- 图表 ---------- */
.filters { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.filters input[type=datetime-local] { border: 1px solid var(--border); background: var(--surface); border-radius: 6px; padding: 4px 8px; }
.charts { display: grid; grid-template-columns: repeat(auto-fill, minmax(520px, 1fr)); gap: 16px; }
.chart-card { padding: 12px 12px 4px; }
.chart-card h4 { margin: 0 4px 2px; font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.chart-card h4 .swatch { width: 10px; height: 10px; border-radius: 2px; background: var(--c); }
.chart-card .chart-sub { margin: 0 4px; font-size: 12px; color: var(--muted); }
.chart { height: 260px; }
.loading-dim { opacity: .5; transition: opacity .2s; }

/* ---------- 表单 / 弹窗 ---------- */
.mask { position: fixed; inset: 0; background: rgba(0, 0, 0, .4); display: flex; align-items: flex-start;
  justify-content: center; padding-top: 8vh; z-index: 50; overflow-y: auto; }
.modal { width: 520px; max-width: calc(100vw - 32px); background: var(--surface); border-radius: 12px; margin-bottom: 40px; }
.modal h3 { margin: 0; padding: 16px 20px; border-bottom: 1px solid var(--grid); font-size: 16px; }
.modal .body { padding: 16px 20px; }
.modal .foot { padding: 12px 20px; border-top: 1px solid var(--grid); display: flex; justify-content: flex-end; gap: 8px; align-items: center; }
.modal .foot .err { flex: 1; }
.form-row { display: grid; grid-template-columns: 110px 1fr; gap: 10px; align-items: center; margin-bottom: 12px; }
.form-row > label { color: var(--ink-2); text-align: right; }
.form-row .hint { grid-column: 2; font-size: 12px; color: var(--muted); margin-top: -6px; }
.form-row input[type=text], .form-row input[type=password], .form-row input[type=number], .form-row select {
  width: 100%; border: 1px solid var(--border); background: var(--surface); border-radius: 6px; padding: 6px 10px; }
.form-row input:focus, .form-row select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.pair { display: flex; gap: 8px; align-items: center; }
.pair input { flex: 1; min-width: 0; }
.checks { display: flex; flex-direction: column; gap: 6px; }
.checks label { display: flex; gap: 6px; align-items: center; }
.dev-pick { max-height: 180px; overflow-y: auto; border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; }
fieldset { border: 1px solid var(--grid); border-radius: 8px; margin: 0 0 12px; padding: 10px 12px 2px; }
legend { color: var(--ink-2); padding: 0 6px; font-size: 13px; }

/* ---------- 登录 ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--nav); }
.login { width: 360px; padding: 32px 28px; }
.login h1 { margin: 0 0 4px; font-size: 22px; }
.login p { margin: 0 0 24px; color: var(--muted); }
.login input { width: 100%; border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 10px 12px; margin-bottom: 12px; }
.login .btn { width: 100%; padding: 10px; }

.toast { position: fixed; right: 20px; bottom: 20px; background: var(--ink); color: var(--surface);
  padding: 10px 16px; border-radius: 8px; z-index: 100; box-shadow: var(--shadow); }

@media (max-width: 720px) {
  .devices, .charts { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .topbar { gap: 10px; padding: 0 10px; }
  .brand { display: none; }
  main { padding: 12px; }
}

/* ================= 大屏看板 ================= */
.screen-viewport { position: fixed; inset: 0; background: #0a0d10; overflow: hidden; }
.screen-stage { position: absolute; left: 0; top: 0; width: 1920px; height: 1080px; transform-origin: 0 0;
  display: flex; flex-direction: column; padding: 0 28px 24px; color: var(--ink);
  background: radial-gradient(ellipse at 50% -20%, #16222c 0%, #0a0d10 60%); }
.screen-stage.flash::after { content: ""; position: absolute; inset: 0; pointer-events: none;
  border: 6px solid var(--critical); animation: scr-flash 1s steps(2) infinite; }
@keyframes scr-flash { 50% { border-color: transparent; } }

.scr-head { height: 84px; display: flex; align-items: center; gap: 20px; border-bottom: 1px solid #22303a; flex: none; }
.scr-title { font-size: 34px; font-weight: 600; letter-spacing: 6px; }
.scr-title small { font-size: 15px; font-weight: 400; letter-spacing: 1px; color: var(--muted); margin-left: 14px; }
.scr-head .spacer { flex: 1; }
.scr-clock { text-align: right; line-height: 1.25; }
.scr-clock .t { font-size: 30px; font-weight: 600; font-variant-numeric: tabular-nums; }
.scr-clock .d { font-size: 14px; color: var(--ink-2); }
.scr-btn { background: transparent; border: 1px solid #2f3e49; color: var(--ink-2); border-radius: 6px;
  padding: 6px 12px; cursor: pointer; font-size: 14px; }
.scr-btn:hover { color: var(--ink); border-color: var(--ink-2); }
.scr-btn.on { color: var(--good); border-color: var(--good); }

.scr-kpis { display: grid; grid-template-columns: repeat(6, 1fr); gap: 16px; margin: 14px 0; flex: none; }
.scr-kpi { background: #11181e; border: 1px solid #1f2b34; border-radius: 10px; padding: 14px 20px; }
.scr-kpi .l { font-size: 15px; color: var(--ink-2); }
.scr-kpi .n { font-size: 38px; font-weight: 600; line-height: 1.15; margin-top: 4px; }
.scr-kpi .n small { font-size: 16px; font-weight: 400; color: var(--muted); margin-left: 6px; }
.scr-kpi.alert { border-color: var(--critical); }
.scr-kpi.alert .n { color: var(--critical); }

.scr-body { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 470px; gap: 18px; }
.scr-left { display: flex; flex-direction: column; gap: 18px; min-height: 0; }
.scr-panel { background: #11181e; border: 1px solid #1f2b34; border-radius: 10px; display: flex; flex-direction: column; min-height: 0; }
.scr-panel > h3 { margin: 0; padding: 12px 18px; font-size: 18px; font-weight: 600; border-bottom: 1px solid #1f2b34;
  display: flex; align-items: center; gap: 10px; flex: none; }
.scr-panel > h3 .sub { font-size: 13px; font-weight: 400; color: var(--muted); }
.scr-scroll { overflow: hidden; flex: 1; min-height: 0; padding: 14px 18px; }

.scr-devs { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.scr-dev { background: #0d1318; border: 1px solid #1c272f; border-radius: 8px; padding: 12px 14px; }
.scr-dev.offline { opacity: .6; }
.scr-dev-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.scr-dev-head .nm { font-size: 19px; font-weight: 600; }
.scr-dev-head .loc { font-size: 13px; color: var(--muted); }
.scr-dev-head .spacer { flex: 1; }
.scr-tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.scr-tile { background: #151d24; border-radius: 6px; padding: 10px 12px; border-top: 3px solid var(--tile-c); }
.scr-tile .nm { font-size: 14px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scr-tile .v { font-size: 34px; font-weight: 600; line-height: 1.2; margin: 4px 0; white-space: nowrap; }
.scr-tile .v small { font-size: 15px; font-weight: 400; color: var(--ink-2); margin-left: 3px; }
.scr-tile.off .v { color: var(--muted); font-size: 24px; }
.scr-tile.alarm { background: rgba(208, 59, 59, .16); box-shadow: inset 0 0 0 1px var(--critical); animation: scr-pulse 1.6s ease-in-out infinite; }
.scr-tile.alarm .v { color: #ff8a8a; }
.scr-tile.warn { box-shadow: inset 0 0 0 1px var(--serious); }
@keyframes scr-pulse { 50% { background: rgba(208, 59, 59, .04); } }

.scr-trends { height: 214px; flex: none; }
.scr-trend-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; padding: 12px 18px; flex: 1; min-height: 0; }
.scr-trend { background: #0d1318; border: 1px solid #1c272f; border-radius: 8px; padding: 8px 12px 0; display: flex; flex-direction: column; min-height: 0; }
.scr-trend .hd { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 14px; color: var(--ink-2); }
.scr-trend .hd b { font-size: 20px; color: var(--ink); }
.scr-trend .ch { flex: 1; min-height: 0; }

.scr-alarm { padding: 10px 12px; border-radius: 6px; margin-bottom: 8px; background: #151d24; border-left: 3px solid var(--muted); }
.scr-alarm.on { border-left-color: var(--critical); background: rgba(208, 59, 59, .12); }
.scr-alarm .top { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--ink-2); }
.scr-alarm .msg { font-size: 15px; margin-top: 4px; line-height: 1.4; }
.scr-alarm .tag { font-size: 12px; padding: 0 6px; border-radius: 3px; border: 1px solid currentColor; }
.scr-empty { color: var(--muted); text-align: center; padding: 30px 0; font-size: 15px; }
.scr-sep { font-size: 13px; color: var(--muted); margin: 14px 0 8px; }

/* ================= 区域树 / 分组 ================= */
.with-side { display: grid; grid-template-columns: 240px 1fr; gap: 16px; align-items: start; }
.with-side.wide-side { grid-template-columns: 300px 1fr; }
.with-side > aside { position: sticky; top: 72px; max-height: calc(100vh - 92px); overflow-y: auto; }
.area-tree { padding: 6px 0; }
.at-row { display: flex; align-items: center; gap: 6px; padding: 7px 14px; cursor: pointer; border-left: 3px solid transparent; }
.at-row:hover { background: var(--surface-2); }
.at-row.on { background: var(--surface-2); border-left-color: var(--accent); font-weight: 500; }
.at-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.at-cnt { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.badge.gray { background: var(--muted); }
.stats-5 { grid-template-columns: repeat(5, minmax(110px, 1fr)); }
.num-crit { color: var(--critical); }
.search { border: 1px solid var(--border); background: var(--surface); border-radius: 6px; padding: 5px 10px; min-width: 240px; }
.dev-group { margin-bottom: 20px; }
.group-title { font-size: 15px; font-weight: 600; margin: 4px 0 10px; color: var(--ink-2); }
.dev-card.has-alarm { border-color: var(--critical); }
.notice { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 13px; }
.notice.warn { background: rgba(250, 178, 25, .14); border: 1px solid rgba(250, 178, 25, .5); }
.form-row textarea { width: 100%; border: 1px solid var(--border); background: var(--surface); border-radius: 6px; padding: 6px 10px; font: inherit; color: inherit; resize: vertical; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid .form-row { grid-template-columns: 80px 1fr; }
@media (max-width: 900px) {
  .with-side, .with-side.wide-side, .form-grid { grid-template-columns: 1fr; }
  .with-side > aside { position: static; max-height: none; }
  .stats-5 { grid-template-columns: repeat(2, 1fr); }
}

/* ================= 大屏补充 ================= */
.scr-head select.scr-btn { background: #11181e; }
.scr-areas { display: flex; gap: 12px; flex: none; overflow: hidden; }
.scr-area { flex: 1; min-width: 0; background: #11181e; border: 1px solid #1f2b34; border-left: 4px solid var(--good); border-radius: 8px; padding: 10px 14px; cursor: pointer; }
.scr-area.bad { border-left-color: var(--critical); background: rgba(208, 59, 59, .10); }
.scr-area .nm { font-size: 17px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scr-area .st { display: flex; justify-content: space-between; margin-top: 4px; font-size: 14px; color: var(--ink-2); }
.scr-area .st b { color: var(--ink); font-size: 16px; }
.scr-area .al { color: var(--critical); font-weight: 600; }
.scr-area .ok { color: var(--good); }
.scr-dev.bad { border-color: rgba(208, 59, 59, .6); }
.scr-tile .ss { font-size: 13px; }
.scr-trends { overflow: hidden; }
.scr-trend { overflow: hidden; }
.dev-card .tiles { grid-template-columns: repeat(2, 1fr); }

/* 设备列表视图 */
.dev-list td.val { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.dev-list td.val b { font-size: 15px; }
.dev-list td.val .u { color: var(--muted); font-size: 12px; margin-left: 2px; }
.dev-list td.val.bad b { color: var(--critical); }
.dev-list td.val.warn b { color: #9a6a00; }
:root[data-theme="dark"] .dev-list td.val.warn b { color: var(--warning); }
.dev-list td.val.off b { color: var(--muted); font-weight: 400; }
.dev-list tr { cursor: pointer; }
.dev-list tr:hover td { background: var(--surface-2); }
.dev-list .chn { display: block; font-size: 11px; color: var(--muted); font-weight: 400; }

/* 大屏设备卡片密度：lg ≤4 台（2 列，大字）；md ≤12 台（3 列，2×2 测点）；sm 更多（4 列，测点一行紧凑显示） */
.scr-devs.den-md .scr-tiles { grid-template-columns: repeat(2, 1fr); }
.scr-devs.den-md .scr-tile .v { font-size: 28px; }
.scr-devs.den-sm { gap: 10px; }
.scr-devs.den-sm .scr-dev { padding: 8px 10px; }
.scr-devs.den-sm .scr-dev-head { margin-bottom: 6px; gap: 6px; }
.scr-devs.den-sm .scr-dev-head .nm { font-size: 15px; }
.scr-devs.den-sm .scr-dev-head .loc { display: none; }
.scr-devs.den-sm .scr-dev-head .status { font-size: 11px; padding: 0 6px; }
.scr-devs.den-sm .scr-tiles { gap: 5px; }
.scr-devs.den-sm .scr-tile { padding: 5px 6px; border-top-width: 2px; }
.scr-devs.den-sm .scr-tile .nm { font-size: 12px; }
.scr-devs.den-sm .scr-tile .v { font-size: 20px; margin: 1px 0; }
.scr-devs.den-sm .scr-tile .v small { font-size: 11px; }
.scr-devs.den-sm .scr-tile .ss { font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scr-trend .hd span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
