:root {
  --bg: #f5f7fa;
  --card: #ffffff;
  --line: #e3e8ef;
  --text: #1f2933;
  --muted: #6b7785;
  --brand: #2f6df6;
  --brand-d: #1f55d0;
  --ok: #1f9d55;
  --err: #d64545;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
}
.wrap { max-width: 1080px; margin: 0 auto; padding: 32px 20px; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 28px;
  box-shadow: 0 1px 3px rgba(16, 24, 40, 0.04);
}
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 26px 0 10px; }
.sub { color: var(--muted); font-size: 13px; margin-bottom: 18px; }
label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 6px; }
input[type="text"], input[type="password"] {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  font-size: 14px;
  background: #fff;
  color: var(--text);
}
input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(47, 109, 246, 0.15); }
button {
  cursor: pointer;
  border: none;
  border-radius: 9px;
  padding: 11px 16px;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  background: var(--brand);
  transition: background 0.15s;
}
button:hover { background: var(--brand-d); }
button.ghost { background: #eef2f8; color: var(--text); }
button.ghost:hover { background: #e2e8f2; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.msg { font-size: 13px; margin-top: 12px; min-height: 18px; }
.msg.err { color: var(--err); }
.msg.ok { color: var(--ok); }
.bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.pill { font-size: 12px; color: var(--muted); background: #eef2f8; padding: 4px 10px; border-radius: 999px; }
.clients { list-style: none; padding: 0; margin: 0; }
.clients li { padding: 10px 0; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.clients a { color: var(--brand); text-decoration: none; font-weight: 600; }
.clients a:hover { text-decoration: underline; }
.note { font-size: 12px; color: var(--muted); background: #fbfcfe; border: 1px dashed var(--line); border-radius: 9px; padding: 10px 12px; margin-top: 10px; }

/* 配额进度条 */
.quota { font-size: 13px; color: var(--muted); margin: 6px 0 4px; }
.quota span { color: var(--text); font-weight: 600; }
.bar2 { height: 8px; background: #eef2f8; border-radius: 999px; margin-top: 6px; overflow: hidden; max-width: 320px; }
.bar2fill { height: 100%; width: 0; background: var(--brand); border-radius: 999px; transition: width 0.3s; }
.bar2fill.full { background: var(--err); }

/* 数据表格 */
/* 横向滚动容器：窄屏时表格可滑动，绝不撑破卡片 */
.tablewrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.grid { width: 100%; border-collapse: collapse; margin-top: 6px; font-size: 13px; table-layout: auto; }
.grid th, .grid td { text-align: left; padding: 10px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.grid th { color: var(--muted); font-weight: 600; font-size: 12px; white-space: nowrap; }
.grid td b { font-weight: 600; }
.grid tbody tr:last-child td { border-bottom: none; }
.grid tbody tr:hover { background: #fafbfd; }

/* 数字列表头：单位作为次要行显示 */
.grid th.num { text-align: right; }
.grid th .th-unit { font-weight: 400; font-size: 10px; color: var(--muted); text-transform: none; }

/* 数字列右对齐 + 等宽数字，保证竖直对齐 */
.grid td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* 设备名：过长时省略，避免撑破表格 */
.grid .c-name { max-width: 160px; }
.grid .c-name b { display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }

/* 设了显示名（别名）时，下面用小字露出真实证书名。
   它是排查问题、对 OpenVPN 日志、认下载文件名的锚点，所以必须可见但要让位给别名。
   同样做省略号，长设备名不会把列撑宽。 */
.grid .c-name .alias-real {
  font-size: 11px;
  line-height: 1.4;
  margin-top: 2px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 数字/时间列不换行，保证对齐 */
.grid .mono { font-variant-numeric: tabular-nums; white-space: nowrap; }
.grid .since { white-space: nowrap; font-size: 12px; color: var(--muted); }

/* 操作列表头 + 单元格 */
.grid th.th-acts { white-space: normal; min-width: 150px; }
.th-hint { display: block; font-weight: 400; font-size: 11px; color: var(--muted); }
.grid td .sub { margin-bottom: 0; }
/* 操作列：允许换行，避免链接挤出边界 */
.grid td.acts { white-space: normal; }

/* 双列表单 */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; align-items: end; }

/* 状态徽章 */
.badge { font-size: 12px; padding: 3px 9px; border-radius: 999px; font-weight: 600; }
.badge.ok { color: var(--ok); background: rgba(31, 157, 85, 0.12); }
.badge.off { color: var(--muted); background: #eef2f8; }

/* 设备名小标签 */
.chip { display: inline-block; font-size: 11px; color: var(--brand); background: #eaf1ff; padding: 2px 8px; border-radius: 999px; margin: 2px 4px 2px 0; }
.chips .sub { font-size: 12px; }

/* 行内操作：flex 布局，允许换行，避免链接挤出单元格边界 */
.grid td.acts { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; }
.acts a, .link {
  color: var(--brand);
  text-decoration: none;
  font-weight: 600;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 12px;
  padding: 0;
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  vertical-align: middle;
}
.acts a:hover, .link:hover { text-decoration: underline; }
.link.danger { color: var(--err); }

/* 撤销按钮推到行尾，与下载链接视觉分离 */
.grid td.acts .link.danger { margin-left: auto; }

/* 窄屏操作列：链接与撤销按钮统一成小药丸，避免挤压变形 */
@media (max-width: 860px) {
  .grid td.acts { gap: 6px; }
  .grid td.acts a, .grid td.acts .link {
    padding: 3px 8px;
    border-radius: 999px;
    background: #eef2f8;
  }
  .grid td.acts a.rec { background: rgba(31, 157, 85, 0.12); }
  .grid td.acts .link.danger { background: rgba(214, 69, 69, 0.1); margin-left: 0; }
}

/* 推荐标签 */
.tag {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  line-height: 1.4;
  padding: 1px 5px;
  border-radius: 4px;
  vertical-align: middle;
  white-space: nowrap;
}
.tag.rec { color: #0b7a3b; background: rgba(31, 157, 85, 0.14); }
.acts a.rec { color: var(--ok); }

/* 图例 */
.legend { font-size: 12px; color: var(--muted); margin-top: 12px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

/* 窄屏：表格横向滚动，避免文字溢出卡片 */
@media (max-width: 860px) {
  .grid { white-space: nowrap; }
  .grid .c-name { max-width: none; }
  .grid .c-name b { max-width: none; }
}

/* 行内配额输入 */
.qinput { width: 72px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; color: var(--text); }

/* 弹层 */
.modal { position: fixed; inset: 0; background: rgba(16, 24, 40, 0.45); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal.hidden { display: none; }
.modalbox { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 26px; width: 320px; box-shadow: 0 12px 40px rgba(16, 24, 40, 0.18); }
.modalbox h3 { margin: 0 0 14px; font-size: 16px; }

/* ===== 超级管理员：全局设备视图（按租户折叠分组 + 在线状态） ===== */
.devbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin: 2px 0 10px; }
.devstat { font-size: 13px; color: var(--muted); }
.devstat b { color: var(--text); font-variant-numeric: tabular-nums; }
.devstat b.on { color: var(--ok); }
button.small { padding: 7px 12px; font-size: 12px; }

/* 分组标题行：整行可点，箭头指示折叠状态 */
.devtable tr.ghead td { padding: 0; background: #f7f9fc; border-top: 1px solid var(--line); }
.devtable tr.ghead .gtoggle {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 11px 10px; margin: 0; border: none; border-radius: 0;
  background: none; color: var(--text);
  font-size: 13px; font-weight: 600; text-align: left; cursor: pointer;
}
.devtable tr.ghead .gtoggle:hover { background: #eef2f8; }
.gtoggle .caret {
  flex: none; width: 0; height: 0;
  border-left: 5px solid var(--muted);
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform 0.15s;
}
.gtoggle[aria-expanded="false"] .caret { transform: rotate(-90deg); }
.gtoggle .gname { flex: none; }
.gtoggle .gmeta { font-weight: 400; font-size: 12px; color: var(--muted); }
.gtoggle .gmeta b { color: var(--ok); font-variant-numeric: tabular-nums; }
.gtoggle .gright { margin-left: auto; font-weight: 400; font-size: 12px; color: var(--muted); white-space: nowrap; }

/* 折叠后隐藏设备行（分组标题行保留） */
.devtable tr.drow.hidden-row { display: none; }

/* 在线状态：圆点 + 文字 */
.st { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; white-space: nowrap; }
.st .dot { flex: none; width: 7px; height: 7px; border-radius: 50%; }
.st.on { color: var(--ok); }
.st.on .dot { background: var(--ok); }
.st.off { color: var(--muted); }
.st.off .dot { background: #c3ccd8; }
.stsub { font-size: 11px; color: var(--muted); margin-top: 2px; white-space: nowrap; }
.ls-on { color: var(--ok); font-weight: 600; }
.grid td.ls { white-space: nowrap; }

/* 窄屏：分组统计与「最近在线」换行，避免挤压 */
@media (max-width: 860px) {
  .devtable tr.ghead .gtoggle { flex-wrap: wrap; gap: 4px 8px; }
  .gtoggle .gright { margin-left: 0; width: 100%; }
}

