/* ==========================================================================
   Mua 网络验证系统 —— 控制台样式
   支持浅色 / 深色两套主题（跟随系统偏好）
   ========================================================================== */

:root {
  color-scheme: light dark;

  --bg: #f5f6f8;
  --bg-elev: #ffffff;
  --bg-sunken: #eceef2;
  --border: #e2e5ea;
  --border-strong: #cfd4dc;
  --text: #1c2024;
  --text-muted: #626b78;
  --text-faint: #8b94a1;
  --accent: #2f6feb;
  --accent-soft: #e8f0fe;
  --ok: #1a7f37;
  --ok-soft: #e6f4ea;
  --warn: #9a6700;
  --warn-soft: #fff8e5;
  --danger: #cf222e;
  --danger-soft: #ffebe9;
  --info: #0969da;
  --info-soft: #ddf4ff;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 12px rgba(16, 24, 40, .04);
  --radius: 10px;
  --radius-sm: 7px;
  --sidebar-w: 216px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
/* 系统是深色、且用户没手动选过浅色时才生效 */
  :root:not([data-theme="light"]) {
    --bg: #0d1117;
    --bg-elev: #161b22;
    --bg-sunken: #10151c;
    --border: #262d38;
    --border-strong: #333c4a;
    --text: #e6edf3;
    --text-muted: #9aa4b2;
    --text-faint: #6e7781;
    --accent: #4f8cff;
    --accent-soft: #17233b;
    --ok: #3fb950;
    --ok-soft: #12261a;
    --warn: #d29922;
    --warn-soft: #2a2113;
    --danger: #f85149;
    --danger-soft: #2d1416;
    --info: #58a6ff;
    --info-soft: #10243b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .24);
  }
}

/* 手动选深色（系统是浅色时也能用）*/
:root[data-theme="dark"] {
    --bg: #0d1117;
    --bg-elev: #161b22;
    --bg-sunken: #10151c;
    --border: #262d38;
    --border-strong: #333c4a;
    --text: #e6edf3;
    --text-muted: #9aa4b2;
    --text-faint: #6e7781;
    --accent: #4f8cff;
    --accent-soft: #17233b;
    --ok: #3fb950;
    --ok-soft: #12261a;
    --warn: #d29922;
    --warn-soft: #2a2113;
    --danger: #f85149;
    --danger-soft: #2d1416;
    --info: #58a6ff;
    --info-soft: #10243b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .24);
}

/* ---------------------------------------------------------------------------
   主题切换动画（View Transitions）
   ---------------------------------------------------------------------------
   浏览器做主题切换时会拍两张快照：`::view-transition-old(root)`（旧画面）
   和 `::view-transition-new(root)`（新画面），默认给它们一个**交叉淡入**。

   我们要的是「斜着扫过去」，所以：
     · 旧画面**保持不动**（`animation: none`）—— 它在底下当背景
     · 新画面用 `clip-path` 从**左下角**扩出去（动画在 JS 里加，因为半径
       要按窗口尺寸算）
     · 新画面**必须在上层**（`z-index`）—— 否则被旧画面盖住，看不到扫的效果

   不加这段的话，默认交叉淡入会叠在我们的 clip 动画上，出来是「又淡又扫」，
   反而更花。 */
::view-transition-old(root),
::view-transition-new(root) {
  animation: none;
  mix-blend-mode: normal;
}
::view-transition-old(root) { z-index: 1; }
::view-transition-new(root) { z-index: 2; }

/* 系统设了「减少动态效果」就不做扫过动画 —— 直接切 */
@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(root),
  ::view-transition-old(root),
  ::view-transition-new(root) { animation: none !important; }
}

* { box-sizing: border-box; }

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

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }

/* ---------------------------------------------------------------- 布局 */

.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--border);
}
.brand a { color: var(--text); font-weight: 700; font-size: 15px; letter-spacing: -.2px; }
.brand a:hover { text-decoration: none; }
.brand small { display: block; color: var(--text-faint); font-size: 11px; font-weight: 400; margin-top: 2px; }

.nav { padding: 12px 10px 24px; flex: 1; }
.nav-group { margin-bottom: 14px; }
.nav-group > .g-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-faint); padding: 6px 10px 4px; font-weight: 600;
}
.nav a {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 10px; border-radius: var(--radius-sm);
  color: var(--text-muted); font-size: 13.5px;
}
.nav a:hover { background: var(--bg-sunken); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav a .ic { width: 16px; text-align: center; opacity: .85; }

/* 侧栏底部：入口切换与返回首页 */
.side-foot {
  padding: 14px 18px 18px; border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 7px; font-size: 12.5px;
}
.side-foot a { color: var(--accent); }
.side-foot a.dim { color: var(--text-faint); }
.side-foot a:hover { text-decoration: none; opacity: .8; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: 56px; flex: 0 0 56px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px;
  padding: 0 22px;
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 15.5px; margin: 0; font-weight: 600; }
.topbar .spacer { flex: 1; }
.topbar .who { color: var(--text-muted); font-size: 13px; }
.topbar .who b { color: var(--text); font-weight: 600; }

.content { padding: 22px; flex: 1; }

/* ---------------------------------------------------------------- 卡片 */

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 18px;
  overflow: hidden;
}
.card-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
}
.card-head h2 { margin: 0; font-size: 14.5px; font-weight: 600; }
.card-head .spacer { flex: 1; }
.card-body { padding: 18px; }
.card-body.tight { padding: 0; }

.grid { display: grid; gap: 16px; }
.grid.c2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.c3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid.c4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }

/* 纵向堆叠：把多张卡片摞成 grid 的某一栏。
   为什么需要它 —— grid 的默认 `align-items: stretch` 会把**矮的那张卡片拉长**
   去跟高的对齐，内容只占上面一小截，底下留出一大片**卡片底色**的空区
   （浅色主题下就是「凭空多了一块白」）。
   把一栏拆成 .stack 之后，卡片各自保持自然高度，多余的空白落到**页面底色**上，
   看起来就是正常的留白而不是一块没用的白板。
   `min-width: 0` 必须写 —— 否则 grid 子项默认 `min-width: auto`，
   里面宽表格/代码块会把整栏撑破。 */
.stack { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.stack > .card { margin: 0; }

/* ---------------------------------------------------------------- 统计卡 */

.stat {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.stat .label { color: var(--text-muted); font-size: 12.5px; margin-bottom: 6px; }
.stat .value { font-size: 24px; font-weight: 700; letter-spacing: -.5px; line-height: 1.2; }
.stat .sub { color: var(--text-faint); font-size: 12px; margin-top: 4px; }
.stat.accent .value { color: var(--accent); }
.stat.ok .value { color: var(--ok); }
.stat.warn .value { color: var(--warn); }
.stat.danger .value { color: var(--danger); }

/* ---------------------------------------------------------------- 表格 */

.table-wrap { overflow-x: auto; }
table.tb { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.tb th, table.tb td {
  padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border);
  vertical-align: middle; white-space: nowrap;
}
table.tb th {
  background: var(--bg-sunken); color: var(--text-muted);
  font-weight: 600; font-size: 12.5px; position: sticky; top: 0;
}
table.tb tbody tr:hover { background: var(--bg-sunken); }
table.tb td.wrap { white-space: normal; min-width: 200px; }
table.tb td.mono { font-family: var(--mono); font-size: 12.5px; }
.empty { padding: 40px; text-align: center; color: var(--text-faint); }

/* ---------------------------------------------------------------- 徽章 */

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 500; line-height: 1.5;
  background: var(--bg-sunken); color: var(--text-muted); border: 1px solid var(--border);
}
.b-ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.b-warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.b-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.b-info { background: var(--info-soft); color: var(--info); border-color: transparent; }

/* ---------------------------------------------------------------- 按钮 */

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--bg-elev); color: var(--text);
  font-size: 13.5px; font-family: inherit; cursor: pointer; line-height: 1.5;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--bg-sunken); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn.ghost:hover { background: var(--bg-sunken); color: var(--text); }
.btn.sm { padding: 4px 9px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------------------------------------------------------------- 表单 */

.form-grid { display: grid; gap: 14px 18px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; color: var(--text-muted); font-weight: 500; }
.field label .req { color: var(--danger); }
.field .hint { font-size: 12px; color: var(--text-faint); }

input[type=text], input[type=password], input[type=email], input[type=number],
input[type=search], input[type=date], input[type=datetime-local], input[type=url],
select, textarea {
  width: 100%; padding: 8px 11px; font-size: 13.5px; font-family: inherit;
  color: var(--text); background: var(--bg);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  outline: none; transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { min-height: 96px; resize: vertical; font-family: var(--mono); font-size: 12.5px; }
select { cursor: pointer; }
input[type=checkbox] { width: auto; accent-color: var(--accent); }

.filters {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end;
  padding: 14px 18px; border-bottom: 1px solid var(--border); background: var(--bg-sunken);
}
.filters .field { min-width: 140px; }
.filters .field.grow { flex: 1; min-width: 180px; }

/* 「起 ~ 止」成对输入（时间区间 / 次数区间）。
   ★ 必须显式写 `min-width: 0`：`datetime-local` 这类原生控件有**固有最小宽**
   （本机实测 208px），而 flex 子项的 `min-width` 默认是 `auto` ——
   光写 `flex: 1` 是**缩不下去**的。两个并排就是 416px，320px 的手机上
   把整页撑宽 70~150px（实测右边界 461 vs 视口 320）。 */
.filters .pair { display: flex; gap: 6px; align-items: center; }
.filters .pair > input { flex: 1 1 0; min-width: 0; }

/* 窄屏再把「起 ~ 止」竖着摞起来：并排时每个只剩 ~140px，
   `datetime-local` 会把时间部分裁掉，不如各占一行看得全。 */
@media (max-width: 480px) {
  .filters .pair { flex-wrap: wrap; gap: 5px; }
  .filters .pair > input { flex: 1 1 100%; }
  .filters .pair > .faint { flex: 1 1 100%; text-align: center; line-height: 1; }
}

/* ------------------------------------------------------------ 自建弹窗
   替代原生 `window.confirm()` / `window.prompt()`。

   为什么不用原生：
     · 样式**完全不可控** —— 深色主题下弹出一个刺眼的白框，跟页面两个风格；
     · 手机上原生的按钮位置/字号/安全区都不归我们管，点起来费劲；
     · 原生 `prompt` 是明文输入框，不能加说明、不能限长、不能自动聚焦。

   布局：桌面居中卡片；≤480px 变**底部抽屉**（拇指够得到，也是现在的主流做法）。
   所有颜色走主题变量，深浅色自动适配。 */
.modal-mask {
  position: fixed; inset: 0; z-index: 90;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background: rgba(16, 24, 40, .48);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  opacity: 0; transition: opacity .16s ease;
}
.modal-mask.show { opacity: 1; }

.modal {
  width: 100%; max-width: 400px; max-height: calc(100vh - 40px);
  display: flex; flex-direction: column;
  background: var(--bg-elev); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .3);
  transform: translateY(8px) scale(.98);
  transition: transform .16s ease;
}
.modal-mask.show .modal { transform: none; }

.modal-head {
  display: flex; align-items: center; gap: 10px;
  padding: 15px 18px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 15px; font-weight: 600; }
.modal-x {
  margin-left: auto; width: 28px; height: 28px; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  background: none; border: 0; border-radius: 7px; cursor: pointer;
  color: var(--text-faint); font-size: 17px; line-height: 1;
}
.modal-x:hover { background: var(--bg-sunken); color: var(--text); }

.modal-body { padding: 16px 18px; overflow-y: auto; }
.modal-msg {
  margin: 0; font-size: 13.5px; line-height: 1.65; color: var(--text-muted);
  white-space: pre-line;   /* 确认文案里的换行要保留 */
}
.modal-msg strong { color: var(--text); }
.modal-body .field { margin-top: 14px; }

.modal-foot {
  display: flex; gap: 8px; justify-content: flex-end;
  padding: 13px 18px; border-top: 1px solid var(--border);
}
.modal-foot .btn { min-width: 88px; justify-content: center; }

/* 手机：底部抽屉 + 拇指友好的按钮 */
@media (max-width: 480px) {
  .modal-mask { align-items: flex-end; padding: 0; }
  .modal {
    max-width: none; max-height: 88vh;
    border-radius: 14px 14px 0 0; border-bottom: 0;
    transform: translateY(100%);
  }
  .modal-head { padding-top: calc(15px + env(safe-area-inset-top)); }
  .modal-body { padding-bottom: 4px; }
  .modal-foot {
    padding-bottom: calc(13px + env(safe-area-inset-bottom));
    /* 两个按钮平分整行 —— 单手操作时不用瞄准 */
  }
  .modal-foot .btn { flex: 1; min-width: 0; }
}

/* 键盘弹出的兜底：屏幕很矮时（横屏手机）弹窗内部可滚动 */
@media (max-height: 480px) {
  .modal { max-height: calc(100vh - 16px); }
  .modal-mask { padding: 8px; }
}

/* ---------------------------------------------------------------- 提示条 */

.alert {
  padding: 11px 15px; border-radius: var(--radius-sm); margin-bottom: 14px;
  font-size: 13.5px; border: 1px solid transparent;
}
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert.err { background: var(--danger-soft); color: var(--danger); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.info { background: var(--info-soft); color: var(--info); }

/* ------------------------------------------------------------ 浮动提示（toast）
   给**客户端**的即时反馈用（例如「备注保存失败」）。

   为什么不复用上面的 `.alert` 直接插进页面：`.alert` 是**服务端**渲染的，
   出现在文档流里（刷新后消失，位置固定）。而客户端事件（fetch 失败）发生时
   页面已经渲染完了，需要的是**不打断操作、几秒后自己消失**的浮动提示。

   配色直接复用 `.alert.*` 的变量，保证和服务端提示看起来是同一套东西。
   位置：桌面右上角；手机上顶部整宽（避开底部的手势区/安全区）。 */
.toast-wrap {
  position: fixed; z-index: 95;
  top: 16px; right: 16px; left: auto;
  display: flex; flex-direction: column; gap: 8px;
  max-width: min(380px, calc(100vw - 32px));
  pointer-events: none;   /* 容器不挡点击，只有提示本身可点 */
}
.toast {
  pointer-events: auto;
  padding: 11px 15px; border-radius: var(--radius-sm);
  font-size: 13.5px; line-height: 1.5;
  border: 1px solid var(--border);
  box-shadow: 0 6px 22px rgba(0, 0, 0, .18);
  cursor: pointer;
  opacity: 0; transform: translateY(-6px);
  transition: opacity .18s ease, transform .18s ease;
  word-break: break-word;
}
.toast.show { opacity: 1; transform: none; }

@media (max-width: 480px) {
  .toast-wrap {
    top: calc(8px + env(safe-area-inset-top));
    right: 8px; left: 8px; max-width: none;
  }
}

/* 尊重「减少动态效果」偏好 */
@media (prefers-reduced-motion: reduce) {
  .toast, .modal, .modal-mask { transition: none; }
}

/* ---------------------------------------------------------------- 分页 */

.pager { display: flex; gap: 5px; padding: 14px 18px; align-items: center; flex-wrap: wrap; }
.pg {
  min-width: 30px; height: 30px; padding: 0 9px; border-radius: var(--radius-sm);
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border-strong); color: var(--text-muted); font-size: 13px;
}
.pg:hover { background: var(--bg-sunken); text-decoration: none; }
.pg.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.pg.disabled { opacity: .45; pointer-events: none; }

/* ---------------------------------------------------------------- 登录页 */

/* 登录卡片容器：宽度约束 + 作为按钮的定位参照。
 *
 * 这里定义两个变量，**值要和 `.auth-card` 的 padding 一致** ——
 * 按钮（本容器的子元素）靠它们对齐到卡片内部的右上角。
 * 变量定义在 `.auth-box` 而不是 `.auth-card` 上，是因为
 * **按钮是卡片的兄弟节点**，`.auth-card` 上的变量它继承不到。
 */
.auth-box {
  width: 100%; max-width: 400px; position: relative;
  --auth-card-pad-y: 32px;
  --auth-card-pad-x: 30px;
}

/* 登录页的主题切换按钮：贴在**卡片内部**的右上角。
 *
 * 为什么不是 `top:-6px; right:-6px`（悬在卡片外角上）：
 *   卡片有 `border-radius: 14px` —— 按钮悬在圆角外会**看着像贴歪了**；
 *   而且它和卡内内容**不在同一个内边距**上，视觉上不对齐；
 *   小屏卡片撑满宽度时，负的 `right` 还可能**顶出视口**。
 *
 * 定位值直接引用卡片的 padding 变量 —— 这样以后调卡片内边距，
 * 按钮会**跟着走**，不用两处一起改（写死 32px/30px 就是下一个「漏改点」）。
 */
.theme-fab {
  position: absolute;
  top: var(--auth-card-pad-y, 32px);
  right: var(--auth-card-pad-x, 30px);
  z-index: 10;
  width: 34px; height: 34px; padding: 0; line-height: 1;
  font-size: 15px; cursor: pointer;
  color: var(--text-faint); background: transparent;
  border: 1px solid transparent; border-radius: 50%;
  transition: color .12s, border-color .12s, background .12s;
}
.theme-fab:hover {
  color: var(--text);
  background: var(--bg-sunken);
  border-color: var(--border);
}

.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 32px 20px; background:
    radial-gradient(900px 500px at 12% -8%, var(--accent-soft), transparent 62%),
    var(--bg);
}
.auth-card {
  width: 100%; max-width: 400px;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow); padding: 32px 30px;
}
.auth-card h1 { font-size: 19px; margin: 0 0 6px; }
.auth-card .sub { color: var(--text-muted); font-size: 13.5px; margin-bottom: 22px; }
.auth-card .btn { width: 100%; justify-content: center; padding: 9px; font-size: 14px; }

/* 登录页底部的入口切换（管理后台 / 用户中心 / 注册 / 首页） */
.auth-switch {
  margin-top: 22px; padding-top: 18px;
  border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  gap: 10px; flex-wrap: wrap; font-size: 13.5px;
}
.auth-switch a {
  padding: 6px 12px; border-radius: 7px;
  border: 1px solid var(--border-strong); color: var(--text-muted);
}
.auth-switch a:hover { background: var(--bg-sunken); color: var(--text); text-decoration: none; }
.auth-switch span { color: var(--border-strong); }
.auth-foot { margin-top: 20px; text-align: center; font-size: 13px; color: var(--text-faint); }

/* ---------------------------------------------------------------- 其它 */

.kv-list { display: grid; gap: 0; }
.kv-list .row {
  display: flex; gap: 16px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 13.5px;
  /* ★ grid 子项的 `min-width` 默认是 `auto` = **min-content 宽**。
     签名示例那一行里塞了 `white-space: pre` 的代码块，min-content 就是最长那行
     （实测 448px）—— 于是这一行把 336px 的 grid 撑破，整页横向溢出。
     写 `min-width: 0` 之后行会正常收缩，代码块靠自己的 `overflow-x: auto` 内部滚动。 */
  min-width: 0;
}
.kv-list .row:last-child { border-bottom: none; }
.kv-list .row .k { color: var(--text-muted); min-width: 130px; flex: 0 0 auto; }
.kv-list .row .v { color: var(--text); word-break: break-all; min-width: 0; }

.code-block {
  background: var(--bg-sunken); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 13px 15px; font-family: var(--mono); font-size: 12.5px;
  overflow-x: auto; white-space: pre; color: var(--text); margin: 0;
  /* 兜底：`white-space: pre` 的内容 min-content 宽 = 最长一行，
     不夹一下 max-width 就只靠祖先的 min-width:0 兜，少一层保险 */
  max-width: 100%;
}

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); padding: 0 18px; }
.tabs a {
  padding: 11px 14px; color: var(--text-muted); font-size: 13.5px; border-bottom: 2px solid transparent;
}
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.small { font-size: 12.5px; }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.mt0 { margin-top: 0; }
.mb0 { margin-bottom: 0; }

.trend { display: flex; align-items: flex-end; gap: 3px; height: 70px; }
.trend .bar { flex: 1; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; opacity: .8; }
.trend .bar:hover { opacity: 1; }

.progress { height: 6px; background: var(--bg-sunken); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); }

/* ==========================================================================
   响应式
   --------------------------------------------------------------------------
   两档断点：
     ≤1024px  平板 / 小笔记本 —— 内容收窄，侧栏改抽屉
     ≤720px   手机 —— 表格横滑、表单单列、触控目标放大

   侧栏在移动端不做成「横向滚动条」：后台导航有 10 个分组、几十个入口，
   横着排既看不清也点不准，改成汉堡按钮 + 抽屉更符合手机习惯。
   ========================================================================== */

/* 移动端专用元素：桌面下不占位 */
.nav-toggle,
.sidebar-mask { display: none; }

/* 抽屉打开时锁住背景滚动，否则手指一滑整页跟着动，体验很糟 */
body.drawer-open { overflow: hidden; }

@media (max-width: 1024px) {
  .layout { flex-direction: column; }

  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: min(78vw, 280px);
    height: 100%;
    z-index: 60;
    border-right: 1px solid var(--border);
    border-bottom: none;
    transform: translateX(-102%);
    transition: transform .22s ease;
    /* 抽屉里内容可能比屏幕高，允许独立滚动 */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    /* 刘海屏横屏时别把内容顶到圆角里 */
    padding-left: env(safe-area-inset-left);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .sidebar.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .001), var(--shadow); }

  /* 抽屉打开时的遮罩 */
  .sidebar-mask {
    display: block;
    position: fixed; inset: 0; z-index: 55;
    background: rgba(12, 16, 22, .48);
    opacity: 0; pointer-events: none;
    transition: opacity .22s ease;
    -webkit-tap-highlight-color: transparent;
  }
  .sidebar-mask.show { opacity: 1; pointer-events: auto; }

  .brand { padding: 16px 18px 13px; }

  /* 抽屉里的导航恢复成竖排，恢复分组标题 */
  .nav { display: block; padding: 10px 10px 20px; }
  .nav-group { margin-bottom: 14px; }
  .nav-group > .g-title { display: block; }
  .nav a { padding: 11px 12px; font-size: 14.5px; }

  .nav-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 38px; height: 38px; flex: 0 0 38px;
    margin-left: -6px;
    border: 1px solid var(--border-strong);
    background: var(--bg-elev); color: var(--text);
    border-radius: var(--radius-sm);
    font-size: 17px; line-height: 1; cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .nav-toggle:active { background: var(--bg-sunken); }

  .topbar { padding: 0 14px; gap: 10px; }
  .content { padding: 16px; }

  /* 平板宽度下 c4 的四列挤得难看，降到两列 */
  .grid.c4 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
}

@media (max-width: 720px) {
  html, body { font-size: 15px; }

  /* ---- 顶栏 ---- */
  .topbar {
    height: auto; min-height: 54px; flex: 0 0 auto;
    flex-wrap: wrap;
    padding: 8px 12px;
    padding-top: calc(8px + env(safe-area-inset-top));
    gap: 8px;
  }
  .topbar h1 { font-size: 15px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  /* 用户名/角色在手机上没地方放，直接让位给标题和按钮 */
  .topbar .who { display: none; }
  .topbar .spacer { display: none; }
  .topbar form { display: flex; }

  /* ---- 内容区 ---- */
  .content { padding: 12px; padding-bottom: calc(20px + env(safe-area-inset-bottom)); }

  /* ---- 卡片 ---- */
  .card { border-radius: var(--radius-sm); margin-bottom: 12px; }
  .card-head { padding: 12px 14px; flex-wrap: wrap; gap: 8px; }
  .card-body { padding: 14px; }
  .card-head .spacer { flex-basis: 100%; }

  /* ---- 栅格 ----
     c2 / c3 内容块较宽（表格、表单、图表），手机上单列。
     c4 用的全是统计卡，改成两列 —— 4 张卡竖着排要滑很久才能看到下面的内容，
     两列既够放数字也不会挤。 */
  .grid { gap: 12px; }
  .grid.c2, .grid.c3 { grid-template-columns: 1fr; }
  .grid.c4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat { padding: 13px 14px; }
  .stat .value { font-size: 21px; }
  .stat .label, .stat .sub { font-size: 12px; }

  /* ---- 卡片头部里的筛选表单 ----
     有些视图把 <form> 直接放在 .card-head 里，里面是 1~2 个带**内联 min-width**
     的下拉（内联样式优先级高于这里的任何规则，压不下去）。
     统计页就是「下拉 160px + 下拉 110px + 导出按钮」，320px 屏上排不下一行，
     整个表单会撑出卡片右边（实测右边界 348 / 视口 320）。
     解法不是去改内联样式，而是允许换行 + 让表单占满整行 ——
     排不下就自己折到下一行，内联的 min-width 也就不会再触发溢出。 */
  .card-head > form { width: 100%; flex-wrap: wrap; }
  .card-head > form > select { flex: 1 1 auto; }

  /* ---- 表格：横向滚动 + 触控友好 ---- */
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    /* 滚动到底时不要连带触发页面回弹 */
    overscroll-behavior-x: contain;
  }
  table.tb { font-size: 13px; }
  table.tb th, table.tb td { padding: 9px 11px; }
  /* 表头 sticky 在横向滚动容器里会把内容压出重影，手机上关掉 */
  table.tb th { position: static; }
  /* 手机上表格几乎必然超宽，给一条视觉提示，否则用户不知道能滑 */
  .table-wrap.scrollable { position: relative; }
  .table-wrap.scrollable::after {
    content: '';
    position: absolute; top: 0; right: 0; bottom: 0; width: 22px;
    background: linear-gradient(to right, transparent, var(--bg-elev));
    pointer-events: none;
  }

  /* ---- 表单 ---- */
  .form-grid { grid-template-columns: 1fr; gap: 12px; }
  .filters { padding: 12px; gap: 9px; }
  .filters .field,
  .filters .field.grow { min-width: 0; flex: 1 1 100%; }
  .filters .btn-row { width: 100%; }

  /* ---- 触控目标：手机上一律不小于 40px，否则很容易点错 ---- */
  .btn { padding: 9px 15px; font-size: 14px; min-height: 40px; }
  .btn.sm { padding: 7px 12px; font-size: 13px; min-height: 36px; }
  .pg { min-width: 38px; height: 38px; }

  /* 输入框字号必须 ≥16px，否则 iOS Safari 聚焦时会自动放大整页 */
  input[type=text], input[type=password], input[type=email], input[type=number],
  input[type=search], input[type=date], input[type=datetime-local], input[type=url],
  select, textarea {
    font-size: 16px;
    padding: 10px 12px;
  }
  textarea { font-family: var(--mono); font-size: 14px; }

  /* ---- 键值列表：手机上一行放不下「键 + 值」，改成上下两行 ---- */
  .kv-list .row { flex-direction: column; gap: 3px; }
  .kv-list .row .k { min-width: 0; font-size: 12.5px; }

  /* ---- 标签页：横向滚动 ---- */
  .tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0 12px;
    white-space: nowrap;
  }
  .tabs a { padding: 10px 12px; }

  /* ---- 分页 ---- */
  .pager { padding: 12px; gap: 6px; justify-content: center; }

  /* ---- 登录 / 注册页 ---- */
  .auth-wrap {
    /* ★ 手机端也要**垂直居中**，但不能用 `align-items: center`。
     *
     *   flex 居中有个经典坑：内容比容器高时（注册页字段多、或软键盘顶起后），
     *   `align-items: center` 会把**顶部裁掉**，而且**滚不到上面去** ✗。
     *   当初改成 `flex-start` 多半就是为了躲这个坑 —— 但代价是
     *   内容不长时也贴着顶，看着很别扭（用户这次指出的就是这个）。
     *
     *   正确解法：容器 `align-items: flex-start` + 卡片 `margin: auto`。
     *   内容短 → `auto` 上下平分，居中 ✓；
     *   内容长 → `auto` 归零，正常从顶部开始、能滚 ✓。
     *   两种情况都对，不用二选一。
     */
    align-items: flex-start;
    padding: 28px 14px;
    padding-top: calc(28px + env(safe-area-inset-top));
    padding-bottom: calc(28px + env(safe-area-inset-bottom));
    min-height: 100vh;
    min-height: 100dvh;   /* 移动端用 dvh：100vh 会把地址栏算进去，底部被顶掉 */
  }
  .auth-box { margin: auto; }
  .auth-card { padding: 24px 20px; border-radius: 12px; }
  .auth-card h1 { font-size: 18px; }
  .auth-switch { gap: 8px; }

  /* ---- 代码块 ---- */
  .code-block { font-size: 12px; padding: 11px 12px; }
}

/* 超窄屏（iPhone SE 一类，320~360px）再收一档 */
@media (max-width: 380px) {
  .content { padding: 10px; }
  .card-head { padding: 11px 12px; }
  .card-body { padding: 12px; }
  .stat .value { font-size: 19px; }
  .topbar h1 { font-size: 14px; }
}

/* 横屏矮屏（手机横放）：顶栏别占太高，抽屉内容要能滚 */
@media (max-height: 480px) and (orientation: landscape) {
  .sidebar { width: min(60vw, 300px); }
  .topbar { min-height: 46px; padding-top: 6px; }
}

/* 触屏设备：去掉 300ms 点击延迟与点击高亮，并禁用 hover 的粘滞效果 */
@media (hover: none) {
  a, button, .btn, .nav a, .pg { -webkit-tap-highlight-color: transparent; }
  .nav a:hover { background: transparent; color: var(--text-muted); }
  .nav a.active:hover { background: var(--accent-soft); color: var(--accent); }
  table.tb tbody tr:hover { background: transparent; }
  .btn:hover { background: var(--bg-elev); }
  .btn.primary:hover { background: var(--accent); }
  .btn.ghost:hover { background: transparent; }
  .btn.danger:hover { background: var(--danger); }
}

/* 打印：去掉侧栏与顶栏，只留正文 */
@media print {
  .sidebar, .topbar, .pager, .filters, .nav-toggle, .sidebar-mask { display: none !important; }
  .layout { display: block; }
  .content { padding: 0; }
  .card { box-shadow: none; border-color: #ccc; break-inside: avoid; }
}

/* 只在小屏 / 只在大屏显示的工具类 */
.show-sm { display: none; }
@media (max-width: 720px) {
  .show-sm { display: initial; }
  .hide-sm { display: none !important; }
}

