/* 线上机器监控 · 面板。没有 JS，CSP 只放行这一份样式表（不许内联样式，进度条的宽度用 .w0 … .w100）。 */

:root {
  color-scheme: light dark;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fa;
  --border: #e2e5e9;
  --line: #eceef1;
  --text: #1c2024;
  --muted: #69727d;
  --faint: #a3abb5;
  --link: #0a5fc2;
  --ok: #18794e;
  --bad: #cd2b31;
  --warn: #ad5700;
  --mute: #4f6a92;
  --idle: #8b949e;
  --track: #e6e9ed;
  --bar: #3e7ec6;
  --p0-bg: #d1242f; --p0-fg: #ffffff;
  --p1-bg: #ffe9e8; --p1-fg: #b8232a;
  --p2-bg: #fff2cc; --p2-fg: #8a5100;
  --dg-bg: #edeff2; --dg-fg: #5c6670;
  --hot-bg: #fff6f6;
  --top-bg: #1d232b;
  --top-fg: #f1f3f5;
  --top-muted: #9aa5b1;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --surface: #161a20;
    --surface-2: #1b2027;
    --border: #2a3039;
    --line: #232931;
    --text: #e2e6eb;
    --muted: #8c96a2;
    --faint: #5e6873;
    --link: #6eb0ff;
    --ok: #46c27d;
    --bad: #ff6b6f;
    --warn: #e5a24a;
    --mute: #8da8d0;
    --idle: #6c7682;
    --track: #2a3039;
    --bar: #5b98d9;
    --p0-bg: #e5484d; --p0-fg: #ffffff;
    --p1-bg: #3d1d20; --p1-fg: #ff8f92;
    --p2-bg: #3a2c10; --p2-fg: #f1c063;
    --dg-bg: #252b33; --dg-fg: #9aa5b1;
    --hot-bg: #22171a;
    --top-bg: #0a0d11;
    --top-fg: #e2e6eb;
    --top-muted: #8c96a2;
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", "Source Han Sans SC", sans-serif;
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono, pre { font-family: var(--mono); font-size: 12.5px; }
h1, h2, h3 { margin: 0; }

/* ―― 顶栏 ―― */

.top { background: var(--top-bg); color: var(--top-fg); }
.top .in {
  max-width: 1320px; margin: 0 auto; padding: 0 20px;
  display: flex; align-items: center; gap: 28px; height: 48px;
}
.brand { color: inherit; font-weight: 600; letter-spacing: .02em; display: inline-flex; align-items: center; gap: 10px; }
.brand:hover { text-decoration: none; }
.brand::before {
  content: ""; width: 9px; height: 9px; border-radius: 50%;
  background: #46c27d; box-shadow: 0 0 0 3px rgba(70, 194, 125, .22);
}
.top nav { display: flex; gap: 20px; align-self: stretch; }
.top nav a {
  color: var(--top-muted); display: flex; align-items: center;
  border-bottom: 2px solid transparent; padding-top: 2px;
}
.top nav a:hover { color: var(--top-fg); text-decoration: none; }
.top nav a[aria-current] { color: var(--top-fg); border-bottom-color: var(--top-fg); }
.clock { margin-left: auto; color: var(--top-muted); font-size: 12px; font-variant-numeric: tabular-nums; }
/* 顶栏右边：登录着的人、退出 */
.top .who { display: flex; align-items: center; gap: 10px; margin: 0; color: var(--top-fg); font-size: 13px; }
.top .who span { max-width: 14em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top .who button { padding: 2px 10px; font-size: 12px; background: transparent; color: var(--top-muted); border-color: rgba(255, 255, 255, .22); }
.top .who button:hover { color: var(--top-fg); border-color: rgba(255, 255, 255, .5); }

main { max-width: 1320px; margin: 0 auto; padding: 4px 20px 24px; }
footer { max-width: 1320px; margin: 0 auto; padding: 8px 20px 32px; color: var(--faint); font-size: 12px; }

/* ―― 小部件 ―― */

.sub { color: var(--muted); font-size: 12px; }
.none { color: var(--faint); }
.ok { color: var(--ok); }
.bad { color: var(--bad); }
.warn { color: var(--warn); }
.mute { color: var(--mute); }
.idle { color: var(--idle); }
.pad { padding: 12px 16px; margin: 0; }

.dot { display: inline-block; flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--idle); }
.dot.ok { background: var(--ok); }
.dot.bad { background: var(--bad); }
.dot.warn { background: var(--warn); }
.dot.mute { background: var(--mute); }

.st { display: inline-flex; align-items: center; gap: 7px; font-weight: 500; white-space: nowrap; }
.st.big { font-size: 15px; }

.lv {
  display: inline-block; flex: none; min-width: 34px; padding: 0 6px; border-radius: 4px;
  font-size: 12px; font-weight: 600; line-height: 20px; text-align: center; white-space: nowrap;
  background: var(--dg-bg); color: var(--dg-fg);
}
.lv.p0 { background: var(--p0-bg); color: var(--p0-fg); }
.lv.p1 { background: var(--p1-bg); color: var(--p1-fg); }
.lv.p2 { background: var(--p2-bg); color: var(--p2-fg); }
.lv.zero { background: transparent; color: var(--faint); box-shadow: inset 0 0 0 1px var(--border); }

.gauge { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.bar { display: inline-block; flex: none; width: 64px; height: 6px; border-radius: 3px; background: var(--track); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 3px; background: var(--bar); }
.bar > i.warn { background: var(--warn); }
.bar > i.bad { background: var(--bad); }
.pct { font-variant-numeric: tabular-nums; min-width: 2.6em; }
.w0 { width: 0; } .w5 { width: 5%; } .w10 { width: 10%; } .w15 { width: 15%; } .w20 { width: 20%; }
.w25 { width: 25%; } .w30 { width: 30%; } .w35 { width: 35%; } .w40 { width: 40%; } .w45 { width: 45%; }
.w50 { width: 50%; } .w55 { width: 55%; } .w60 { width: 60%; } .w65 { width: 65%; } .w70 { width: 70%; }
.w75 { width: 75%; } .w80 { width: 80%; } .w85 { width: 85%; } .w90 { width: 90%; } .w95 { width: 95%; }
.w100 { width: 100%; }

/* ―― 总览 ―― */

.strip { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 28px; margin: 18px 0 14px; }
.chips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; padding: 3px 12px 3px 10px;
  border-radius: 999px; background: var(--surface); border: 1px solid var(--border); font-size: 13px;
}
.chip b { font-variant-numeric: tabular-nums; }
.levels { color: var(--text); }
.levels:hover { text-decoration: none; }
.levels .label { color: var(--muted); font-size: 13px; margin-right: 4px; }

.banner {
  display: flex; align-items: center; gap: 10px; margin: 0 0 12px; padding: 10px 14px;
  border-radius: 8px; border: 1px solid var(--border); background: var(--hot-bg); color: var(--text);
}
.banner:hover { text-decoration: none; }

.group { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; margin: 0 0 14px; overflow: hidden; }
.group > header {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  background: var(--surface-2); border-bottom: 1px solid var(--border);
}
.group.folded > header { border-bottom: 0; }
.fold { color: var(--text); font-weight: 600; font-size: 15px; display: inline-flex; align-items: center; gap: 6px; }
.fold:hover { text-decoration: none; }
.fold::before { content: "▾"; color: var(--muted); width: 1em; font-size: 12px; }
.group.folded .fold::before { content: "▸"; }
.trouble { margin-left: auto; color: var(--bad); font-size: 12px; font-weight: 600; }

.scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 16px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
th { font-size: 12px; font-weight: 500; color: var(--muted); white-space: nowrap; background: var(--surface); }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* 每个分组一张表：列宽定死，各组的列才对得齐 */
table.machines { table-layout: fixed; min-width: 1080px; }
table.machines .c-name { width: 17%; }
table.machines .c-state { width: 13%; }
table.machines .c-load { width: 7%; }
table.machines .c-mem { width: 12%; }
table.machines .c-disk { width: 15%; }
table.machines .c-seen { width: 8%; }
table.machines td { vertical-align: middle; overflow-wrap: anywhere; }
table.machines td.name a { font-weight: 600; color: var(--text); }
table.machines td.name a:hover { color: var(--link); }
table.machines td.use { white-space: nowrap; }
table.machines td.alert { overflow: hidden; }
table.machines td.stale > * { opacity: .45; }
table.machines tr.hot { background: var(--hot-bg); }
table.machines tr.hot td:first-child { box-shadow: inset 3px 0 0 var(--bad); }
.seen { color: var(--muted); }

.al { display: flex; align-items: center; gap: 8px; min-width: 0; color: var(--text); }
.al:hover { text-decoration: none; }
.al:hover .sum { text-decoration: underline; }
.al .rule { flex: none; color: var(--muted); font-size: 12px; font-family: var(--mono); }
.al .sum { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.empty { padding: 48px 16px; text-align: center; color: var(--muted); }

/* ―― 单台详情、告警 ―― */

.crumbs { display: flex; gap: 8px; margin: 18px 0 6px; color: var(--muted); font-size: 13px; }
.crumbs span { color: var(--faint); }
.head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin: 0 0 8px; }
.head h1 { font-size: 22px; font-weight: 600; overflow-wrap: anywhere; }
.meta { display: flex; flex-wrap: wrap; gap: 6px 22px; list-style: none; margin: 0 0 18px; padding: 0; font-size: 13px; }
.meta li { display: inline-flex; gap: 6px; min-width: 0; }
.meta span { color: var(--muted); white-space: nowrap; }
.meta b { font-weight: 500; overflow-wrap: anywhere; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(440px, 1fr)); gap: 16px; margin: 0 0 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; margin: 0 0 16px; min-width: 0; }
.grid > .card { margin: 0; }
.card.wide { grid-column: 1 / -1; }
.card > h2 {
  display: flex; align-items: baseline; gap: 10px; padding: 11px 16px;
  font-size: 14px; font-weight: 600; border-bottom: 1px solid var(--border); background: var(--surface-2);
}
.card h2 .n { color: var(--muted); font-weight: 500; font-variant-numeric: tabular-nums; }
.card h2 .when { margin-left: auto; color: var(--muted); font-size: 12px; font-weight: 400; }
.card h2 .when.warn { color: var(--warn); }
.card h3 { padding: 12px 16px 0; font-size: 12px; font-weight: 600; color: var(--muted); }
.card h3.bad { color: var(--bad); }
.hotcard { border-color: var(--p1-fg); }
.hotcard > h2 { background: var(--hot-bg); color: var(--bad); }

.facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 7px 18px; margin: 0; padding: 12px 16px; }
.facts dt { color: var(--muted); white-space: nowrap; }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.row { display: flex; align-items: center; gap: 18px; padding: 0 16px 12px; overflow-wrap: anywhere; }
.row .label { color: var(--muted); flex: none; }
.note { margin: 0; padding: 8px 16px; font-size: 13px; color: var(--muted); border-top: 1px solid var(--line); overflow-wrap: anywhere; }
.note.warn { color: var(--warn); }

table.disks td, table.logs td, table.daemons td { vertical-align: middle; }
table.disks td .sub { margin-left: 8px; }
td.mono, td.cmd { overflow-wrap: anywhere; }
table.daemons td.cmd { max-width: 640px; }

table.alerts td { vertical-align: middle; }
table.alerts td.time { white-space: nowrap; color: var(--muted); font-variant-numeric: tabular-nums; }
table.alerts td.machine { white-space: nowrap; }
table.alerts td.rule { font-family: var(--mono); font-size: 12px; color: var(--muted); white-space: nowrap; }
table.alerts td.summary { min-width: 260px; overflow-wrap: anywhere; }
table.alerts td.summary a { color: var(--text); }
table.alerts td.summary a:hover { color: var(--link); }

.tabs { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 18px 0 14px; }
.tabs a { padding: 4px 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.tabs a:hover { text-decoration: none; border-color: var(--faint); }
.tabs a[aria-current] { background: var(--text); border-color: var(--text); color: var(--bg); }
.tabs .sub { margin-left: 10px; }

pre.evidence {
  margin: 0; padding: 14px 16px; max-height: 520px; overflow: auto;
  white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.6;
}

.oops { padding: 72px 16px; text-align: center; }
.oops h1 { font-size: 18px; font-weight: 600; margin-bottom: 12px; }

/* ―― 管理：表单、按钮、命令 ―― */

button, .btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 14px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-size: 13px; line-height: 20px; cursor: pointer; white-space: nowrap;
}
button:hover, .btn:hover { border-color: var(--faint); text-decoration: none; }
button.primary, .btn.primary { background: var(--link); border-color: var(--link); color: #fff; }
button.danger, .btn.danger { color: var(--bad); border-color: var(--bad); }
button.danger:hover, .btn.danger:hover { background: var(--bad); color: #fff; }
/* 深色模式下按钮底色是浅的（--link、--bad 调亮了），白字看不清，换成深色字 */
@media (prefers-color-scheme: dark) {
  button.primary, .btn.primary, button.danger:hover, .btn.danger:hover { color: var(--bg); }
}
.push { margin-left: auto; }

input[type=text], textarea, select {
  font: inherit; font-size: 13px; padding: 5px 10px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); color: var(--text); min-width: 0;
}
textarea { font-family: var(--mono); font-size: 12.5px; width: 100%; resize: vertical; }
input[type=text]:focus, textarea:focus, select:focus { outline: 2px solid var(--link); outline-offset: -1px; }

.form { display: grid; gap: 16px; padding: 16px; max-width: 760px; }
.form.inner { padding: 12px 0 0; }
.form label { display: grid; gap: 6px; font-weight: 500; }
.form label input[type=text] { max-width: 360px; }
.form details summary { cursor: pointer; color: var(--muted); }
.form .buttons { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; }
.hint { color: var(--muted); font-size: 12px; font-weight: 400; }
p.hint { margin: 0; }
.err, .done, .warnbox { margin: 0 0 14px; padding: 10px 14px; border-radius: 8px; border: 1px solid var(--border); }
.form .err { margin: 0; }
.err { color: var(--bad); background: var(--hot-bg); }
.done { color: var(--ok); background: var(--surface); }
.warnbox { color: var(--warn); background: var(--surface); }

form.inline { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0; }
button.small, .btn.small { padding: 2px 10px; font-size: 12px; }

/* 单台详情标题右边管这台机器的几个按钮。静音是 details 做的小弹层（没有 JS）：点一下打开，再点一下收起 */
.head .tools { margin-left: auto; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
details.pop { position: relative; }
details.pop > summary { list-style: none; }
details.pop > summary::-webkit-details-marker { display: none; }
details.pop > summary::after { content: "▾"; font-size: 11px; color: var(--muted); }
details.pop[open] > summary { background: var(--surface-2); border-color: var(--faint); }
.popbox {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 5; width: 320px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 10px 28px rgba(0, 0, 0, .14);
}
.popbox .form { padding: 14px; gap: 12px; }
.popbox .form label input[type=text], .popbox select { width: 100%; max-width: none; }

.card h3.split { display: flex; align-items: baseline; gap: 10px; }
.card h3 .edit { margin-left: auto; font-size: 12px; font-weight: 400; }
table.conf td { vertical-align: middle; }
table.conf td.sub { white-space: nowrap; }
table.conf td.mono { overflow-wrap: anywhere; }
.form label select { max-width: 360px; }
.next { display: grid; gap: 12px; justify-items: start; }

/* 登录那几页：一张窄卡片居中 */
.gate { max-width: 480px; margin: 48px auto 16px; }
.gatebody { display: grid; gap: 14px; justify-items: start; }
.gatebody > p { margin: 0; }
.gatebody .err, .gatebody .warnbox, .gatebody .done { margin: 0; justify-self: stretch; }
.form.tight { padding: 0; width: 100%; }
.form.tight label input[type=text] { max-width: 12em; font-size: 18px; letter-spacing: .2em; font-family: var(--mono); }
.qrbox { padding: 8px; background: #fff; border-radius: 8px; border: 1px solid var(--border); }
.qrbox svg.qr { display: block; width: 224px; height: 224px; }
code.secret { word-spacing: .3em; font-size: 13px; overflow-wrap: anywhere; }
.next p { margin: 0; }

/* 命令、转交说明点一下就全选（整段复制、整段发过去） */
pre.cmd {
  margin: 8px 16px 12px; padding: 12px 14px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--line);
  white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.6; -webkit-user-select: all; user-select: all;
}
.lead { margin: 0; padding: 12px 16px 0; }
ul.list { margin: 0; padding: 12px 16px 4px 34px; display: grid; gap: 6px; }

@media (max-width: 720px) {
  .top .in { gap: 16px; padding: 0 16px; }
  .clock { display: none; }
  .top .who { margin-left: auto; }
  .top .who span { max-width: 7em; }
  .gate { margin-top: 24px; }
  main, footer { padding-left: 16px; padding-right: 16px; }
  .grid { grid-template-columns: minmax(0, 1fr); }
  th, td { padding: 8px 12px; }
  .strip { gap: 10px; }
  .head .tools { margin-left: 0; width: 100%; }
  .popbox { left: 0; right: auto; width: min(320px, calc(100vw - 32px)); }

  /* 项目配置：种类和状态一行，路径另起一行 */
  table.conf tbody { display: block; }
  table.conf tr { display: grid; grid-template-columns: auto minmax(0, 1fr); grid-template-areas: "label state" "value value"; gap: 2px 12px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
  table.conf tr:last-child { border-bottom: 0; }
  table.conf td { display: block; padding: 0; border: 0; min-width: 0; }
  table.conf td:nth-child(1) { grid-area: label; }
  table.conf td:nth-child(2) { grid-area: value; }
  table.conf td:nth-child(3) { grid-area: state; text-align: right; }

  /* 窄屏上机器、告警一行排成一张小卡片，不用横着拖 */
  table.machines, table.alerts { min-width: 0; table-layout: auto; }
  table.machines colgroup, table.machines thead, table.alerts thead { display: none; }
  table.machines tbody, table.alerts tbody { display: block; }
  table.machines tr, table.alerts tr { display: grid; gap: 6px 14px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
  table.machines tr:last-child, table.alerts tr:last-child { border-bottom: 0; }
  table.machines td, table.alerts td { display: block; padding: 0; border: 0; min-width: 0; }
  table.machines tr {
    grid-template-columns: auto auto minmax(0, 1fr);
    grid-template-areas: "name name seen" "state state state" "load mem disk" "alert alert alert";
  }
  table.machines tr.hot { box-shadow: inset 3px 0 0 var(--bad); }
  table.machines tr.hot td:first-child { box-shadow: none; }
  table.machines td.name { grid-area: name; }
  table.machines td.seen { grid-area: seen; text-align: right; }
  table.machines td.state { grid-area: state; }
  table.machines td.state .sub { display: inline; margin-left: 8px; }
  table.machines td.load { grid-area: load; text-align: left; }
  table.machines td.load .sub { display: inline; margin-left: 4px; }
  table.machines td.mem { grid-area: mem; }
  table.machines td.disk { grid-area: disk; }
  table.machines td.alert { grid-area: alert; }
  table.machines .bar { width: 40px; }
  table.alerts tr {
    grid-template-columns: 40px 44px minmax(0, 1fr) auto;
    grid-template-areas: "level rule time id" "summary summary summary summary" "machine machine state state";
  }
  table.alerts td.id { grid-area: id; }
  table.alerts td.level { grid-area: level; }
  table.alerts td.rule { grid-area: rule; }
  table.alerts td.time { grid-area: time; }
  table.alerts td.summary { grid-area: summary; min-width: 0; }
  table.alerts td.machine { grid-area: machine; }
  table.alerts td.state { grid-area: state; text-align: right; }
}
