:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #e4e7ec;
  --text: #1d2433;
  --muted: #6b7385;
  --accent: #3b6ef5;
  --accent-text: #ffffff;
  --ok: #1f9d55;
  --warn: #d98a00;
  --bad: #d64545;
  --off: #a4abb8;
  --bar-bg: #eef0f4;
  --code-bg: #f1f3f6;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111318;
    --surface: #1a1d24;
    --border: #2a2e38;
    --text: #e6e8ee;
    --muted: #8d94a3;
    --accent: #5b86ff;
    --ok: #3cc173;
    --warn: #e6a23c;
    --bad: #ef6b6b;
    --off: #5d6472;
    --bar-bg: #262a33;
    --code-bg: #0f1116;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

h1, h2 { margin: 0 0 12px; font-weight: 600; }
h1 { font-size: 22px; letter-spacing: .5px; }
h2 { font-size: 17px; }
.muted { color: var(--muted); }
.error { color: var(--bad); min-height: 1.5em; margin: 4px 0; font-size: 13px; }

button {
  font: inherit;
  border-radius: 8px;
  padding: 7px 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
button:hover { filter: brightness(.97); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.ghost { background: transparent; }
button.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
button:disabled { opacity: .6; cursor: default; }

input {
  font: inherit;
  width: 100%;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  margin: 6px 0;
}
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* ---- 登录 / 设置 ---- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card {
  width: 100%;
  max-width: 340px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 24px;
  box-shadow: var(--shadow);
}
.auth-card button { width: 100%; margin-top: 4px; padding: 10px; }

/* ---- 顶栏 ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 17px; letter-spacing: .5px; }
.summary { color: var(--muted); flex: 1; }
.actions { display: flex; gap: 8px; }

.content { max-width: 1200px; margin: 0 auto; padding: 20px 24px 48px; }

/* ---- 服务器列表 ---- */
.server-list { display: flex; flex-direction: column; gap: 10px; }

.server {
  display: grid;
  grid-template-columns: minmax(160px, 1.1fr) minmax(190px, 1.3fr) minmax(330px, 2.6fr) minmax(110px, .8fr) auto;
  gap: 16px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.server.offline { opacity: .72; }

.name-cell { min-width: 0; }
.name-line { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 15px; }
.name-line span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sub { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--off); }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 20%, transparent); }

.ips { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.ip {
  display: flex;
  gap: 6px;
  align-items: center;
  font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  min-width: 0;
}
.ip .tag {
  flex: none;
  font: 600 10px/1 -apple-system, sans-serif;
  padding: 3px 5px;
  border-radius: 4px;
  background: var(--bar-bg);
  color: var(--muted);
}
.ip .addr { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ip-more { font-size: 11px; color: var(--muted); padding-left: 2px; }

.meters { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.meter { min-width: 0; }
.meter .label { display: flex; justify-content: space-between; gap: 6px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.meter .label b { color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.bar { height: 5px; background: var(--bar-bg); border-radius: 3px; overflow: hidden; margin-top: 4px; }
.bar i { display: block; height: 100%; background: var(--ok); border-radius: 3px; transition: width .4s; }
.bar i.warn { background: var(--warn); }
.bar i.bad { background: var(--bad); }

.net { font-size: 12px; display: flex; flex-direction: column; gap: 2px; font-variant-numeric: tabular-nums; }
.net .muted { font-size: 11px; }

.row-actions { display: flex; gap: 4px; }
.row-actions button { padding: 4px 8px; font-size: 12px; }

.empty { text-align: center; padding: 64px 16px; }

/* ---- 对话框 ---- */
dialog {
  width: min(520px, calc(100vw - 32px));
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
  background: var(--surface);
  color: var(--text);
}
dialog::backdrop { background: rgba(10, 12, 18, .45); }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.cmd {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font: 12px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
  word-break: break-all;
  user-select: all;
  margin: 10px 0 0;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 50;
}

/* ---- 窄屏 ---- */
@media (max-width: 1100px) {
  .server { grid-template-columns: 1fr auto; }
  .ips, .meters, .net { grid-column: 1 / -1; }
  .row-actions { grid-row: 1; grid-column: 2; }
  .net { flex-direction: row; gap: 14px; }
}
@media (max-width: 600px) {
  .topbar { flex-wrap: wrap; padding: 10px 16px; gap: 8px; }
  .summary { order: 3; flex-basis: 100%; }
  .actions button { padding: 6px 10px; }
  .content { padding: 14px 16px 40px; }
  .meters { grid-template-columns: 1fr; gap: 8px; }
}
