:root {
  --bg: #f5f6f8;
  --card: #fff;
  --text: #1f2329;
  --muted: #8a919c;
  --line: #e6e8eb;
  --primary: #2f6bff;
  --primary-weak: #eaf0ff;
  --ok: #18a058;
  --warn: #e6a23c;
  --danger: #e5484d;
  --radius: 8px;
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.6 -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif; color: var(--text); background: var(--bg); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.err { color: var(--danger); min-height: 1.4em; margin: 8px 0 0; }
a { color: var(--primary); cursor: pointer; text-decoration: none; }

button { font: inherit; border: 1px solid var(--line); background: #fff; color: var(--text); border-radius: 6px; padding: 6px 14px; cursor: pointer; }
button:hover { border-color: var(--primary); color: var(--primary); }
button.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
button.primary:hover { opacity: .9; color: #fff; }
button.danger { color: var(--danger); border-color: #f3c6c7; }
button.danger:hover { background: #fff1f1; }
button.ghost { border-color: transparent; background: transparent; }
button.small { padding: 2px 10px; font-size: 13px; }
button:disabled { opacity: .5; cursor: not-allowed; }

input, select, textarea { font: inherit; border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; background: #fff; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); }
textarea { width: 100%; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
label { display: block; margin: 0 0 12px; color: #4e5969; }
label > input, label > select, label > textarea { display: block; width: 100%; margin-top: 4px; }
label.inline { display: inline-flex; align-items: center; gap: 6px; margin: 0 16px 8px 0; color: var(--text); }
label.inline > input { width: auto; margin: 0; }
.hint { color: var(--muted); font-size: 12px; margin-top: 2px; }

.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card { width: 340px; }
.login-card h1 { font-size: 20px; margin: 0 0 20px; text-align: center; }
.login-card button { width: 100%; margin-top: 8px; padding: 9px; }

.top { height: 52px; display: flex; align-items: center; gap: 12px; padding: 0 20px; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.spacer { flex: 1; }
.layout { display: flex; min-height: calc(100vh - 52px); }
nav { width: 168px; background: #fff; border-right: 1px solid var(--line); padding: 12px 8px; flex-shrink: 0; }
nav a { display: block; padding: 8px 14px; border-radius: 6px; color: var(--text); margin-bottom: 2px; }
nav a:hover { background: var(--bg); }
nav a.on { background: var(--primary-weak); color: var(--primary); font-weight: 600; }
main { flex: 1; padding: 20px 24px 60px; min-width: 0; }
h2 { font-size: 18px; margin: 0 0 16px; }
h3 { font-size: 15px; margin: 0 0 12px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.tile .n { font-size: 26px; font-weight: 600; line-height: 1.2; font-variant-numeric: tabular-nums; }
.tile .l { color: var(--muted); font-size: 13px; }
.tile.hl .n { color: var(--primary); }

.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-start; }
.row > button { margin-top: 26px; }
.row > label { flex: 1; min-width: 160px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar input[type=search] { width: 280px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }

table { width: 100%; border-collapse: collapse; background: #fff; font-size: 13px; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-weight: 500; background: #fafbfc; white-space: nowrap; }
tr:hover td { background: #fafbfc; }
td.mono, .mono { font-family: ui-monospace, Consolas, monospace; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
.table-wrap th, .table-wrap td { white-space: nowrap; }
.table-wrap td.wrap { white-space: normal; min-width: 140px; max-width: 320px; word-break: break-all; }
.table-wrap table { border: 0; }
.table-wrap tr:last-child td { border-bottom: 0; }

.tag { display: inline-block; padding: 0 8px; border-radius: 10px; font-size: 12px; line-height: 20px; background: var(--bg); color: #4e5969; white-space: nowrap; }
.tag.ok { background: #e8f7ef; color: var(--ok); }
.tag.warn { background: #fdf3e2; color: #b7791f; }
.tag.bad { background: #fdecec; color: var(--danger); }
.tag.blue { background: var(--primary-weak); color: var(--primary); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #c9cdd4; margin-right: 6px; vertical-align: middle; }
.dot.on { background: var(--ok); }

.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 12px; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 20; overflow-y: auto; }
.modal-box { background: #fff; border-radius: 10px; width: 760px; max-width: 100%; padding: 24px; position: relative; }
.modal-x { position: absolute; right: 12px; top: 10px; border: 0; font-size: 22px; line-height: 1; padding: 4px 8px; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 12px; margin-bottom: 16px; }
.kv > div:nth-child(odd) { color: var(--muted); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0 20px; }

.toast { position: fixed; top: 64px; left: 50%; transform: translateX(-50%); background: #1f2329; color: #fff; padding: 8px 18px; border-radius: 6px; z-index: 30; max-width: 80vw; }
.toast.bad { background: var(--danger); }
.codes { min-height: 200px; }
.note-box { background: #fafbfc; border: 1px solid var(--line); border-radius: 6px; padding: 10px 14px; color: #4e5969; font-size: 13px; margin-bottom: 16px; }

@media (max-width: 760px) {
  .layout { flex-direction: column; }
  nav { width: auto; display: flex; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 6px; }
  nav a { white-space: nowrap; }
  main { padding: 16px 12px 60px; }
  .grid2 { grid-template-columns: 1fr; }
  .toolbar input[type=search] { width: 100%; }
}

/* 操作说明默认隐藏（别人看后台更简洁），右上角「说明」打开；.keep = 数据和警告，永远显示 */
body:not(.help) .note-box:not(.keep), body:not(.help) .hint:not(.keep) { display: none !important; }
body.help #helpBtn { color: var(--primary, #1677ff); }

/* 折叠的卡片（两级钥匙等不常用的） */
details.card.fold > summary { cursor: pointer; list-style: none; }
details.card.fold > summary::-webkit-details-marker { display: none; }
details.card.fold > summary::before { content: '▸ '; color: var(--muted); }
details.card.fold[open] > summary::before { content: '▾ '; }

/* v1.3 */
#qs { width: 300px; max-width: 40vw; margin-left: 16px; }
.nowrap { white-space: nowrap; }
tr.sel td { background: #eef4ff; }
#cBulk { background: #eef4ff; border: 1px solid #c9dbff; border-radius: 8px; padding: 6px 10px; }
.toolbar input[type=date] { padding: 4px 6px; }
.tile.click { cursor: pointer; transition: box-shadow 0.15s, transform 0.15s; }
.tile.click:hover { box-shadow: 0 2px 10px rgba(22, 93, 255, 0.18); transform: translateY(-1px); }

/* v1.3 手机上看后台：顶部查卡框占一整行，菜单横着滑，数字两列，表格左右滑 */
@media (max-width: 760px) {
  .top { height: auto; flex-wrap: wrap; padding: 8px 12px; gap: 6px; }
  #qs { order: 9; width: 100%; max-width: none; margin: 0 0 4px; font-size: 16px; }
  .layout { min-height: auto; }
  .tiles { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .tile { padding: 10px 12px; }
  .tile .n { font-size: 22px; }
  .kv { grid-template-columns: 84px 1fr; }
  .modal { padding: 0; }
  .modal-box { border-radius: 0; min-height: 100vh; padding: 16px 12px; }
  .row > label { min-width: 120px; }
  table { font-size: 13px; }
  .table-wrap { -webkit-overflow-scrolling: touch; }
  .toolbar select, .toolbar button { flex: 0 0 auto; }
  input, select, textarea { font-size: 16px; } /* 手机上不放大页面 */
}

/* v1.3 确认框（叠在别的弹窗上面）、改动对比、看板上能点的数字 */
.modal.cbox { z-index: 30; align-items: center; }
.cbox-box { width: 540px; }
.cbox-box h2 { margin-top: 0; font-size: 18px; }
.cbox-box .who { background: #fff8e1; border: 1px solid #f0d58a; border-radius: 8px; padding: 8px 12px; margin: 8px 0; }
.cbox-box .who.bad { background: #fff1f0; border-color: #f3b8b3; }
.diff { width: 100%; border-collapse: collapse; font-size: 13px; margin: 8px 0; }
.diff td, .diff th { border-bottom: 1px solid var(--line); padding: 5px 6px; vertical-align: top; text-align: left; }
.diff .old { color: #86909c; text-decoration: line-through; word-break: break-all; }
.diff .new { color: #1d2129; word-break: break-all; }
a.num { cursor: pointer; text-decoration: underline dotted; text-underline-offset: 3px; }

/* v1.3 代理子账号：只能看、只能发自己分类的卡；主账号才有的按钮藏起来（服务器那边也挡着） */
body.agent .owner-only { display: none !important; }

/* v1.3 合伙人：没开通的功能，按钮藏起来；只有主账号能用的也藏 */
body.staff .need-owner { display: none !important; }
body.no-cardEdit .need-cardEdit { display: none !important; }
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; }
.perm { display: flex; gap: 8px; align-items: flex-start; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff; cursor: pointer; margin: 0; }
.perm input[type=checkbox] { width: auto; flex: none; margin: 3px 0 0; }
.perm .pt { display: flex; flex-direction: column; gap: 2px; text-align: left; min-width: 0; }
.perm .pt small { font-size: 12px; line-height: 1.5; }
@media (max-width: 760px) {
  .cbox-box { width: 100%; border-radius: 10px; }
  .modal.cbox { padding: 12px; }
  .perm-grid { grid-template-columns: 1fr; }
  .diff th { white-space: nowrap; }
}
@media (max-width: 760px) { .cbox-box { min-height: 0 !important; } }
