:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --line: #e8ebf1;
  --text: #1f2329;
  --muted: #6b7280;
  --faint: #9aa0aa;
  --primary: #2563eb;
  --primary-soft: #eef2ff;
  --green: #059669;
  --green-soft: #ecfdf5;
  --red: #dc2626;
  --red-soft: #fef2f2;
  --orange: #b45309;
  --orange-soft: #fffbeb;
  --radius: 14px;
}

* { box-sizing: border-box; }

/* 关键：.login-wrap 等类选择器带 display:flex，会覆盖浏览器默认的 [hidden]{display:none}，
   导致登录卡片在进入后台后仍然占满首屏、看似「点了没反应」。这里强制 hidden 生效。 */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: #f4f6fa;
  color: #1f2329;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

button, input, select, textarea { font-family: inherit; font-size: inherit; }

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 28px;
  background: #fff;
  border-bottom: 1px solid #e8ebf1;
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; align-items: baseline; gap: 10px; }
.brand-title { font-size: 17px; font-weight: 600; letter-spacing: 0.5px; }
.brand-sub { font-size: 12px; color: #9aa0aa; }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #059669; display: inline-block; margin-right: 6px;
}

/* ---------- 登录 ---------- */
.login-wrap {
  min-height: calc(100vh - 60px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: #ffffff;
  border-radius: 18px;
  padding: 36px 32px 30px;
  box-shadow: 0 18px 50px rgba(23, 37, 84, 0.09);
}

.login-card h1 { margin: 0 0 6px; font-size: 22px; }
.login-card p { margin: 0 0 24px; color: #6b7280; font-size: 13px; }

/* 登录 / 注册 切换 */
.login-tabs {
  display: flex; gap: 4px; padding: 4px; margin: 0 0 18px;
  background: #f3f5f9; border-radius: 10px;
}
.login-tab {
  flex: 1; border: none; background: transparent; cursor: pointer;
  padding: 8px 0; border-radius: 8px; font-size: 13.5px; color: #6b7280;
  font-family: inherit; transition: background .15s, color .15s;
}
.login-tab.active { background: #fff; color: #1f2329; font-weight: 600; box-shadow: 0 1px 3px rgba(23,37,84,.08); }

/* 顶栏当前账号 */
.acct-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px;
  background: #eef2ff; color: #2563eb;
  font-size: 12.5px; font-weight: 600; white-space: nowrap;
}

.login-card p.login-error {
  margin: 12px 0 0;
  font-size: 13px;
  color: #dc2626;
  background: #fef2f2;
  border-radius: 8px;
  padding: 9px 12px;
  line-height: 1.5;
}

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: #6b7280; margin-bottom: 6px; }

input[type="text"],
input[type="password"],
input[type="date"],
input[type="search"],
textarea,
select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid #e8ebf1;
  border-radius: 10px;
  background: #fbfcfe;
  color: #1f2329;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

input:focus, textarea:focus, select:focus {
  border-color: #9db8f5;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .1);
  background: #fff;
}

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 8px 16px;
  background: #f1f3f7;
  color: #4b5563;
  cursor: pointer;
  transition: filter .15s, background .15s;
  white-space: nowrap;
}
.btn:hover { filter: brightness(.97); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: #2563eb; color: #fff; }
.btn-danger { background: #fef2f2; color: #dc2626; }
.btn-solid-danger { background: #dc2626; color: #fff; }
.btn-ghost { background: #fff; border-color: #e8ebf1; color: #1f2329; }
.btn-sm { padding: 5px 11px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; padding: 11px 16px; }

/* ---------- 布局 ---------- */
.page { max-width: 1280px; margin: 0 auto; padding: 22px 24px 60px; }

.tabs {
  display: inline-flex;
  background: #fff;
  border: 1px solid #e8ebf1;
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 18px;
}
.tab {
  padding: 7px 22px;
  border-radius: 9px;
  color: #6b7280;
  cursor: pointer;
  border: none;
  background: transparent;
}
.tab.active { background: #2563eb; color: #fff; }

.card {
  background: #ffffff;
  border: 1px solid #e8ebf1;
  border-radius: 14px;
  padding: 18px 20px;
  margin-bottom: 16px;
}

.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-title { font-size: 15px; font-weight: 600; }

.filters { display: flex; flex-wrap: wrap; align-items: flex-end; margin: 0 -6px; }
.filters .field { flex: 1 1 180px; min-width: 150px; margin: 0 6px 12px; }
.filters .actions { flex: 1 1 100%; display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; margin: 0 6px; }
.filters .actions .btn { margin-left: 8px; }

.stats { display: flex; gap: 18px; color: #6b7280; font-size: 13px; margin: 4px 2px 12px; }
.stats b { color: #1f2329; font-size: 15px; }

/* ---------- 表格 ---------- */
.table-wrap { background: #fff; border: 1px solid #e8ebf1; border-radius: 14px; overflow: hidden; }
.table-scroll { overflow-x: auto; }

/* border-collapse:separate：collapse 模型会使 Chromium 系内核 th 的 position:sticky 失效（表头随内容滚走）。
   单元格仅用 border-bottom 画线，separate 模型下视觉与 collapse 完全一致，不会出现双线。 */
table { width: 100%; border-collapse: separate; border-spacing: 0; min-width: 1080px; }
th, td { padding: 11px 14px; text-align: left; vertical-align: top; border-bottom: 1px solid #f1f3f7; }
th {
  font-size: 12.5px; font-weight: 600; color: #6b7280;
  background: #fafbfd; white-space: nowrap; position: sticky; top: 0;
  z-index: 2;
}
tbody tr:hover { background: #fbfcfe; }
tbody tr:last-child td { border-bottom: none; }

.cell-strong { font-weight: 600; }
.cell-muted { color: #6b7280; }
.cell-mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: #6b7280; word-break: break-all; }
.cell-nowrap { white-space: nowrap; }
.truncate { display: block; max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 产品名称 / 状态：内容过长时自动换行（不截断、不横向撑破表格） */
.cell-wrap { white-space: normal; word-break: break-word; overflow-wrap: break-word; }
/* 换行后印章/原因各自占行，避免糊在一起 */
.col-status .tag { white-space: normal; }
.col-status .stamp { max-width: 100%; white-space: normal; }
.col-status .stamp-reason { word-break: break-word; overflow-wrap: break-word; line-height: 1.35; }

/* ---------- 列宽可调（测试记录表） ---------- */
.table-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 9px 14px; border-bottom: 1px solid #f1f3f7; background: #fcfdff;
}
.table-bar-hint { font-size: 12px; color: #6b7280; }
.table-bar .btn { flex: none; }

/* 固定表格布局：列宽由 colgroup 精确控制，内容超宽时在单元格内换行 */
.test-table { table-layout: fixed; width: auto; min-width: 0; }
.test-table th { overflow: hidden; text-overflow: ellipsis; }
.test-table td { white-space: normal; word-break: break-word; overflow-wrap: break-word; }
/* 操作列（删除按钮）保持单行 */
.test-table td.action-cell { white-space: nowrap; }

/* 表头右边缘的拖拽手柄 */
.col-resizer {
  position: absolute; top: 0; right: 0; width: 9px; height: 100%;
  cursor: col-resize; touch-action: none; z-index: 3;
  border-right: 1px solid transparent;
}
.col-resizer:hover,
.col-resizer.dragging { border-right: 2px solid #2563eb; background: rgba(37, 99, 235, .07); }
body.col-resizing, body.col-resizing * { cursor: col-resize !important; user-select: none !important; -ms-user-select: none !important; }

.row-deleted { background: #fcfcfd; color: #8b909a; }
.row-deleted .cell-strong { color: #8b909a; }

/* 操作列固定在右侧：宽表横向滚动时「删除」按钮始终可见 */
.table-scroll th:last-child,
.table-scroll td:last-child {
  position: sticky;
  right: 0;
  background: #fff;
  box-shadow: -8px 0 10px -8px rgba(31, 35, 41, .25);
}
.table-scroll th:last-child { background: #fafbfd; z-index: 3; }
.row-deleted td:last-child { background: #fcfcfd; }
tbody tr:hover td:last-child { background: #fbfcfe; }

.stamp {
  display: inline-block;
  border: 1.5px solid rgba(220, 38, 38, .55);
  color: rgba(220, 38, 38, .85);
  border-radius: 6px;
  padding: 1px 8px;
  font-size: 12px;
  line-height: 1.4;
  transform: rotate(-6deg);
  background: rgba(255, 255, 255, .7);
}
.stamp-reason { display: block; font-size: 11px; margin-top: 4px; color: #dc2626; opacity: .85; }

/* ---------- 标签 ---------- */
.tag {
  display: inline-block;
  font-size: 12px;
  padding: 1px 8px;
  border-radius: 6px;
  margin: 0 4px 4px 0;
  white-space: nowrap;
}
.tag-blue { background: #eef2ff; color: #2563eb; }
.tag-green { background: #ecfdf5; color: #059669; }
.tag-gray { background: #f3f4f6; color: #6b7280; }
.tag-red { background: #fef2f2; color: #dc2626; }
.tag-orange { background: #fffbeb; color: #b45309; }

/* ---------- 用户行 ---------- */
.user-name { font-weight: 600; }
.user-wx { display: block; font-size: 11.5px; color: #9aa0aa; word-break: break-all; margin-top: 2px; }
.user-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.logs-panel { background: #fafbfd; }
.logs-panel td { padding: 4px 18px 14px; }
.log-row { display: flex; align-items: flex-start; gap: 10px; padding: 7px 0; border-bottom: 1px dashed #eceff4; }
.log-row:last-child { border-bottom: none; }
.log-time { color: #9aa0aa; font-size: 12px; white-space: nowrap; min-width: 120px; }
.log-detail { flex: 1; word-break: break-word; }

/* ---------- 空态 ---------- */
.empty { text-align: center; color: #9aa0aa; padding: 48px 0; }

/* ---------- 弹窗 ---------- */
.modal-mask {
  position: fixed;
  /* 不用 inset 简写：IE 内核不支持，遮罩会丢失偏移导致弹窗跑到视口外（表现为点击无响应） */
  left: 0; top: 0; right: 0; bottom: 0;
  background: rgba(15, 23, 42, .45);
  display: flex; align-items: center; justify-content: center;
  padding: 24px; z-index: 100;
}
.modal {
  width: 100%; max-width: 440px;
  background: #fff; border-radius: 16px;
  padding: 24px 24px 20px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, .25);
}
.modal h3 { margin: 0 0 6px; font-size: 16px; }
.modal .modal-sub { margin: 0 0 16px; color: #6b7280; font-size: 13px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.checkbox-line { display: flex; align-items: center; gap: 8px; padding: 7px 0; cursor: pointer; }
.checkbox-line input { width: 16px; height: 16px; }

/* ---------- 提示 ---------- */
.toast {
  position: fixed; left: 50%; bottom: 42px; transform: translateX(-50%);
  background: #111827; color: #fff; padding: 9px 18px; border-radius: 10px;
  font-size: 13px; z-index: 200; opacity: 0; transition: opacity .2s, transform .2s;
  pointer-events: none; max-width: 80vw;
}
.toast.show { opacity: .95; transform: translateX(-50%) translateY(-6px); }
.toast.error { background: #b91c1c; }

.hint { color: #9aa0aa; font-size: 12px; }
.spacer { flex: 1; }

@media (max-width: 900px) {
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .page { padding: 16px 14px 50px; }
  .topbar { padding: 12px 16px; }
}

/* ---------- 已登录视图：表格区占满剩余高度，横向滚动条固定在页面底部 ----------
   页面本身不滚动（body 锁高），纵向滚动发生在表格内部，
   这样左右滚动条始终贴在浏览器可视区底部，不会随上下滚动跑掉。 */
body.app-mode {
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

body.app-mode .topbar { flex: 0 0 auto; }

body.app-mode main.page {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  padding-bottom: 10px;
}

body.app-mode #pane-tests,
body.app-mode #pane-users {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

body.app-mode #pane-tests > .table-wrap,
body.app-mode #pane-users > .table-wrap {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

body.app-mode .table-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
}

/* ---------- 已登录视图：列表区独立滚动（v5 加固） ----------
   html/body 锁高不滚动；#pane-* 不产生溢出；
   .table-scroll 同时由 CSS flex 与 JS 精确算高双保险，
   纵向滚动只发生在列表内部，表头随列表滚动、筛选区与横向滚动条固定。 */
html { height: 100%; }

body.app-mode {
  height: 100%;
  max-height: 100vh;
  overflow: hidden;
}

body.app-mode #appView { overflow: hidden; }

body.app-mode #pane-tests,
body.app-mode #pane-users { overflow: hidden; }

body.app-mode .table-wrap { min-height: 0; }

body.app-mode .table-scroll {
  overflow: auto;
  overscroll-behavior: contain;
}

.ver-chip {
  font-size: 11px;
  color: #9aa0aa;
  border: 1px solid #e8ebf1;
  border-radius: 999px;
  padding: 1px 8px;
  white-space: nowrap;
}

/* 修改用户名：行内编辑输入框与用户名占位等宽风格 */
.name-edit-input {
  width: 180px;
  max-width: 100%;   /* 用户列表改为固定表格布局（v28）：列拖窄时输入框不溢出单元格 */
  box-sizing: border-box;
  padding: 4px 8px;
  font-size: 13px;
  font-weight: 600;
}

/* 邀请码：当前值展示 + 随机生成按钮 */
.invite-current {
  display: flex; align-items: center; min-height: 36px;
  padding: 0 12px; border: 1px dashed #e8ebf1; border-radius: 8px;
  background: #fafbfe;
}
.invite-current code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 14px; letter-spacing: .5px; color: #1f2329; word-break: break-all;
}
.field .invite-gen { margin-top: 8px; }

/* ---------- 用户列表（v16：管理员列表已移为独立标签页） ---------- */
.users-grid {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.users-grid > .table-wrap {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* 管理员操作记录弹窗 */
.ops-list {
  max-height: 420px;
  overflow: auto;
  border: 1px solid #e8ebf1;
  border-radius: 8px;
  background: #fff;
}
.ops-item {
  display: flex;
  gap: 10px;
  align-items: baseline;
  padding: 8px 12px;
  border-bottom: 1px solid #f1f3f7;
  font-size: 13px;
}
.ops-item:last-child { border-bottom: 0; }
.ops-time { flex: none; color: #9aa0aa; font-size: 12px; min-width: 78px; }
.ops-action { flex: none; font-weight: 600; }
.ops-detail { color: #6b7280; word-break: break-word; }

/* ---------- IE10/11 兼容补丁：flex gap / sticky 不被支持 ---------- */
@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
  .topbar > * + * { margin-left: 16px; }
  .topbar-right > * + * { margin-left: 10px; }
  .brand > * + * { margin-left: 10px; }
  .login-tabs > * + * { margin-left: 4px; }
  .acct-chip > * + * { margin-left: 6px; }
  .card-head > * + * { margin-left: 12px; }
  .filters .actions > * + * { margin-left: 8px; }
  .stats > * + * { margin-left: 18px; }
  .table-bar > * + * { margin-left: 12px; }
  .user-actions > * + * { margin-left: 6px; }
  .log-row > * + * { margin-left: 10px; }
  .modal-actions > * + * { margin-left: 10px; }
  .checkbox-line > * + * { margin-left: 8px; }
  .ops-item > * + * { margin-left: 10px; }
  /* IE 不支持 position:sticky：表头吸顶由 app.js 的「外置克隆表头」方案接管
     （.fixed-head 独立于滚动容器，见下方样式），这里不再改 thead 定位 */
  .topbar { position: static !important; }
  /* v26 列宽拖拽修复：IE 丢弃上方 th 的 position:sticky 声明后，th 回落为 static，
     绝对定位的拖拽手柄 .col-resizer 失去定位基准，全部错位到表头右上角 → 拖拽失效。
     这里补回 relative 定位基准（top:0 对 relative 无位移），手柄回到各列表头右缘；
     现代内核不进本媒体查询，sticky 吸顶不受影响。 */
  .test-table th { position: relative; }
}

/* ---------- 外置固定表头（IE/旧内核兜底，v25） ----------
   表头克隆为独立表格置于滚动容器上方：纵向滚动天然吸顶、
   无 relative 同步造成的空隙与抖动；横向滚动由 JS 同步 margin-left。
   z-index 30：高于表格内容与阴影，低于弹窗(100)/toast(200)，不会穿透浮层 */
.fixed-head {
  position: relative;
  z-index: 30;
  flex: none;
  overflow: hidden;               /* 横向超出部分由下方滚动区接管 */
  background: #fafbfd;
  border-bottom: 1px solid #f1f3f7;
}
.fixed-head-table { margin: 0; }
.fixed-head-table th { border-bottom: none; }

/* ---------- 日期选择兜底日历（v24，仅 IE 等不支持 type=date 的内核启用） ---------- */
#wbCal {
  position: absolute; display: none; z-index: 60;
  width: 224px; padding: 8px;
  background: #fff; border: 1px solid #e8ebf1; border-radius: 10px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, .18);
  font-size: 12.5px; color: #1f2329;
  user-select: none;
}
.wbcal-head { display: flex; align-items: center; justify-content: space-between; padding: 2px 2px 6px; }
.wbcal-title { font-weight: 600; }
.wbcal-nav {
  cursor: pointer; line-height: 1; padding: 4px 10px; border-radius: 6px;
  color: #2563eb; border: 1px solid #e8ebf1; background: #fafbfd;
}
.wbcal-nav:hover { background: #eef2ff; }
.wbcal-grid { display: table; width: 100%; border-collapse: separate; border-spacing: 0; table-layout: fixed; }
.wbcal-row { display: table-row; }
.wbcal-grid span {
  display: table-cell; text-align: center; padding: 4px 0;
}
.wbcal-wd { color: #9aa0aa; }
.wbcal-day { cursor: pointer; border-radius: 6px; }
.wbcal-day:hover { background: #eef2ff; }
.wbcal-blank { cursor: default; }
.wbcal-sel { background: #2563eb; color: #fff; }
.wbcal-foot { text-align: right; padding-top: 4px; }
.wbcal-clear { cursor: pointer; color: #6b7280; padding: 2px 8px; border-radius: 6px; }
.wbcal-clear:hover { background: #f3f4f6; }

/* ---------- 手机端适配（<=900px）：整页可滚动，表格按内容自然展开 ----------
   电脑端沿用「整页锁高 + 表格内部滚动」；手机浏览器地址栏会占用视口高度，
   100vh 锁高会把表格挤得很矮、看不到记录。手机端改为正常文档流滚动。 */
@media (max-width: 900px) {
  html, body { height: auto !important; }
  body.app-mode {
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
    display: block !important;
  }
  /* 注意：这里不能用 display:block !important，否则会压过 [hidden]{display:none!important}，
     把普通管理员无权查看的「用户权限 / 后台管理员」面板也强制显示出来。
     普通 display:block 已能覆盖上面的 flex 布局，且保留 hidden 生效。 */
  body.app-mode #appView,
  body.app-mode main.page,
  body.app-mode #pane-tests,
  body.app-mode #pane-users,
  body.app-mode #pane-admins {
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
    display: block;
  }
  body.app-mode .table-wrap { overflow: visible !important; }
  /* 手机端不要再形成「纵向嵌套滚动」：
     overflow:visible + overflow-x:auto 会被浏览器算成 overflow-y:auto，
     再叠加 overscroll-behavior:contain，手指滑动会被表格容器吃掉，表现为卡顿/滑不动。
     这里明确改成只横向可滚、纵向交给整页，并关掉吸顶元素减少重绘。 */
  body.app-mode .table-scroll {
    height: auto !important;
    max-height: none !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    overscroll-behavior: auto !important;
    -webkit-overflow-scrolling: auto !important;
  }
  body.app-mode th,
  body.app-mode td:last-child {
    position: static !important;
    box-shadow: none !important;
  }
  /* 表头在手机端跟随正常滚动即可，避免外置克隆表头占高 */
  body.app-mode .fixed-head { display: none !important; }
  /* 顶栏在手机端随页面滚动，避免 sticky 与文档流冲突 */
  .topbar { position: static !important; }
  /* 顶栏改为两行：品牌标题独占一行，状态与按钮自动换行。
     否则窄屏下 flex 子项被压窄，中文标题会逐字竖排。 */
  .topbar {
    flex-wrap: wrap !important;
    gap: 8px 12px !important;
    padding: 10px 14px !important;
  }
  .topbar .brand {
    flex: 1 1 auto;
    min-width: 0;
    align-items: center;
  }
  .topbar .brand-title {
    white-space: nowrap;
    font-size: 15px;
  }
  .topbar .brand-sub { display: none !important; }
  .topbar .topbar-right {
    flex: 1 1 100%;
    min-width: 0;
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 8px;
  }
  .topbar .topbar-right > * { flex: 0 0 auto; }
  .topbar .ver-chip { display: none !important; }
  .topbar .hint,
  .topbar .acct-chip { white-space: nowrap; }
}
