/* =============================================================================
 * base.css —— 设计令牌 / 主题变量 / 基础元素 / 通用组件
 * 风格：科技简约、低饱和、浅色系、圆角卡片、柔和浅阴影、拒绝花哨装饰
 * ========================================================================== */

/* ---------- 1. 设计令牌：浅色主题（默认） ---------- */
:root {
  --bg:            #f4f6f8;
  --bg-grid:       rgba(15, 23, 42, 0.035);
  --surface:       #ffffff;
  --surface-2:     #f8f9fb;
  --surface-3:     #eef1f5;
  --line:          #e8eaee;
  --line-strong:   #d8dce3;
  /* 关闭态开关轨道色：与 --line-strong 同族但加深，确保侧边栏白底上开关关闭时仍清晰可见 */
  --switch-off:    #b3bcc7;

  --text:          #1d2129;
  --text-2:        #5a6472;
  --text-3:        #98a1ad;

  --brand:         #4a68e0;
  --brand-hover:   #3f5bd0;
  --brand-soft:    #eef2ff;
  --brand-line:    #d9e1fb;

  --ok:            #2e9e6b;
  --ok-soft:       #e8f6ef;
  --warn:          #c98014;
  --warn-soft:     #fdf3e3;
  --danger:        #d9534f;
  --danger-soft:   #fdeceb;

  --radius:        14px;
  --radius-sm:     9px;
  --radius-xs:     6px;
  --radius-pill:   999px;

  --shadow-1:      0 1px 2px rgba(16, 24, 40, .04), 0 4px 12px rgba(16, 24, 40, .05);
  --shadow-2:      0 2px 6px rgba(16, 24, 40, .06), 0 16px 40px rgba(16, 24, 40, .09);
  --shadow-pop:    0 8px 32px rgba(16, 24, 40, .14);

  --ease:          cubic-bezier(.22, .61, .36, 1);
  --dur:           .22s;

  --topbar-h:      56px;
  --sidebar-w:     248px;
  --rail-w:        8px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
          "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* ---------- 层级令牌（2026-10-03 · 全站 z-index 单一来源）----------
   * 背景：原先 z-index 是各文件硬编码的散数（60/88/320/9500/9999…），既说不清
   *       谁该压住谁，也无法在评审时发现「值改了但没生效」的假象。
   * 重要：本次【数值一个都没动】，只是把散数搬进令牌，避免任何行为变化。
   *
   * ⚠ 层叠上下文陷阱（复审 #26 的真正根因，务必记住）：
   *    .topbar 带 backdrop-filter → 自成层叠上下文（等价于在根层只有 z-index:90）。
   *    所以 .notify-dropdown 虽然在它内部写了 9999，【跨上下文时永远不可能】盖过
   *    根层的 .skin-panel(320)。这类问题靠调数字是治不好的：
   *    · 同一上下文内两个浮层 → 用互斥（谁开另一个就得关）而不是比大小；
   *    · 需要长期比较的浮层 → 放到同一层，再用令牌排序。
   */
  --z-dot:        10;      /* 铃铛红点等角标 */
  --z-snapline:   60;      /* 画布吸附参考线 */
  --z-fab:        88;      /* 悬浮按钮（必须在顶栏 90 之下） */
  --z-topbar:     90;      /* 顶栏（注意：它创建了层叠上下文） */
  --z-rail:       95;      /* 左侧触发条 */
  --z-sidebar:    96;      /* 左侧悬浮侧边栏 */
  --z-in-topbar:  9999;    /* 仅供 .topbar 内部之子元素排序，跨上下文无效 */
  --z-pop:        320;     /* 根层浮层：风格面板等下拉（须低于模态） */
  --z-gate:       500;     /* 未登录闸门遮罩 */
  --z-modal:      200;     /* 居中模态（同层比较时按此序） */
  --z-toast:      300;     /* 轻提示 */
  --z-overlay:    9500;    /* 个人设置等居中遮罩（index.html 内联同值） */
  --z-max:        9999;    /* 兜底层（bind 遮罩 / wb-tip） */
}

/* ---------- 2. 深色主题（一键切换 data-theme="dark"） ---------- */
[data-theme="dark"] {
  --bg:            #14161a;
  --bg-grid:       rgba(255, 255, 255, 0.035);
  --surface:       #1b1e24;
  --surface-2:     #21252c;
  --surface-3:     #272c34;
  --line:          #2c313a;
  --line-strong:   #3a414c;
  --switch-off:    #5a6470;

  --text:          #e6e9ee;
  --text-2:        #a4adba;
  --text-3:        #737d8b;

  --brand:         #7d93ef;
  --brand-hover:   #8ea2f3;
  --brand-soft:    #232a40;
  --brand-line:    #33406b;

  --ok:            #4cb98a;
  --ok-soft:       #1d2c26;
  --warn:          #d9a04a;
  --warn-soft:     #2e271a;
  --danger:        #e2716d;
  --danger-soft:   #33211f;

  --shadow-1:      0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .28);
  --shadow-2:      0 2px 8px rgba(0, 0, 0, .34), 0 18px 44px rgba(0, 0, 0, .4);
  --shadow-pop:    0 10px 36px rgba(0, 0, 0, .5);
}

/* ---------- 3. Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}

h1, h2, h3, h4, p, figure { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
input, textarea, select { font: inherit; color: inherit; }
img { display: block; max-width: 100%; }

::selection { background: var(--brand-soft); color: var(--brand); }

/* 细滚动条（克制） */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border-radius: var(--radius-pill);
  border: 2px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background-color: var(--text-3); background-clip: content-box; }

/* ---------- 4. 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-2);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease),
              border-color var(--dur) var(--ease), transform .12s var(--ease);
}
.btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--text-3); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn--primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}
.btn--primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); color: #fff; }

.btn--ghost { background: transparent; border-color: transparent; }
.btn--ghost:hover { background: var(--surface-3); border-color: transparent; }

.btn--sm { height: 26px; padding: 0 9px; font-size: 12px; border-radius: var(--radius-xs); }
.btn--block { width: 100%; height: 38px; font-size: 14px; }

/* 顶部图标按钮（界面风格 / 通知 / 全局设置齿轮 等）：去掉 .btn 默认遗留的 1px 透明外框占位，
   纯图标无边框，与首页图标样式完全一致（全局设置入口图标外框修复） */
.topbar__right .btn.btn--ghost { border: none; }
.topbar__right .btn.btn--ghost:hover { border: none; }
.btn--danger { color: var(--danger); }
.btn--danger:hover { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }

/* 锁定按钮：与顶部其余图标按钮（界面风格 / 切换主题 / 通知）统一为纯图标按钮，
   尺寸、内边距、间距、hover 全部沿用 .btn.btn--ghost 基线，不再做单独覆盖，
   保证顶部图标按钮排列整齐一致；状态说明由 title 悬浮提示与点击 toast 承担。 */

/* 外链按钮：所有跳转完整业务页的按钮都用 <a target="_blank">，天然是用户手动点击 */
.btn--ext::after {
  content: "";
  width: 9px; height: 9px;
  margin-left: 1px;
  background: currentColor;
  opacity: .55;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M14 3h7v7M21 3l-9 9M19 14v5a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V7a2 2 0 0 1 2-2h5' fill='none' stroke='%23000' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M14 3h7v7M21 3l-9 9M19 14v5a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V7a2 2 0 0 1 2-2h5' fill='none' stroke='%23000' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/contain no-repeat;
}

/* ---------- 5. 表单 ---------- */
.field { display: block; margin-bottom: 14px; }
.field__label {
  display: block;
  margin-bottom: 6px;
  font-size: 12.5px;
  color: var(--text-2);
}
.input, .textarea {
  width: 100%;
  max-width: 460px;   /* 输入框/按钮不拉满整卡，松紧适度 */
  padding: 8px 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.input:focus, .textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.textarea { resize: vertical; min-height: 84px; line-height: 1.7; }

/* ---------- 6. 通用小组件 ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: var(--radius-pill);
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
}
.badge--hidden { display: none; }

/* [P0-10] 补齐被引用但从未定义的徽标状态类
 * submod.js 使用 badge--ok / badge--err，但全站 CSS 中这两个类此前并不存在，
 * 导致「使用中 / 管理员已回复」与「已到期」全部退化为同一个基础 .badge 外观，
 * 正常状态被渲染成与告警完全相同的红色徽标。
 * 以下为纯新增规则：沿用 .badge 既有基底（形状/字号/内距均不变），仅覆盖配色，
 * 配色全部取自既有语义令牌，未引入任何新设计值。 */
.badge--ok   { background: var(--ok-soft);      color: var(--ok); }
.badge--warn { background: var(--warn-soft);    color: var(--warn); }
.badge--err  { background: var(--danger-soft);  color: var(--danger); }
.badge--mute { background: var(--surface-3);    color: var(--text-3); }

.tag {
  display: inline-flex;
  align-items: center;
  height: 19px;
  padding: 0 7px;
  border-radius: var(--radius-xs);
  background: var(--surface-3);
  color: var(--text-2);
  font-size: 11.5px;
}
.tag--ok { background: var(--ok-soft); color: var(--ok); }
.tag--warn { background: var(--warn-soft); color: var(--warn); }
.tag--brand { background: var(--brand-soft); color: var(--brand); }

.icon { width: 16px; height: 16px; flex: none; stroke: currentColor; fill: none;
        stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon--sm { width: 14px; height: 14px; }

/* 刷新按钮的旋转态（顶栏与卡片通用） */
.is-spin svg { animation: wb-spin .8s linear infinite; }
@keyframes wb-spin { to { transform: rotate(360deg); } }

.muted { color: var(--text-3); }
.tiny { font-size: 12px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clamp2 {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.clamp3 {
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
  overflow: hidden; word-break: break-word;
}
/* 通用弹性占位：把其后元素推到容器右侧（卡片脚 / 工具条通用） */
.spacer { margin-left: auto; }

/* 空态 / 骨架 */
.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; padding: 26px 12px; color: var(--text-3); font-size: 12.5px; text-align: center;
}
.skeleton {
  height: 12px; border-radius: var(--radius-xs);
  background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 37%, var(--surface-3) 63%);
  background-size: 400% 100%;
  animation: sk 1.3s ease infinite;
}
@keyframes sk { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ---------- 7. 弹窗 ---------- */
.modal {
  position: fixed; inset: 0; z-index: var(--z-modal);
  display: none; align-items: center; justify-content: center;
  padding: 20px;
  background: rgba(20, 24, 32, .32);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
.modal.is-open { display: flex; animation: fade .18s var(--ease); }
.modal__panel {
  width: 100%; max-width: 420px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-pop);
  animation: pop .22s var(--ease);
}
.modal__title { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.modal__desc { font-size: 12.5px; color: var(--text-3); margin-bottom: 16px; }
.modal__foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.985); } to { opacity: 1; transform: none; } }

/* ---------- 8. 轻提示 Toast ---------- */
#wb-toast {
  position: fixed; left: 50%; bottom: 34px; z-index: var(--z-toast);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  transform: translateX(-50%); pointer-events: none;
}
.toast {
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--surface);
  box-shadow: var(--shadow-2);
  font-size: 13px;
  animation: toastIn .22s var(--ease);
}
.toast--ok { color: var(--ok); }
.toast--err { color: var(--danger); }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* 尊重系统「减少动态效果」偏好 */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* [PATCH 20260824] 全局气泡提示（WB.tip 挂 body，避开卡片裁切） */
.wb-tip {
  position: fixed; z-index: var(--z-max); max-width: 260px;
  padding: 6px 10px; border-radius: 8px;
  background: rgba(15, 23, 42, .92); color: #f8fafc;
  font-size: 12px; line-height: 1.5; pointer-events: none;
  opacity: 0; transform: translateY(3px);
  transition: opacity .12s ease, transform .12s ease;
}
.wb-tip.on { opacity: 1; transform: translateY(0); }
@media (prefers-reduced-motion: reduce) { .wb-tip { transition: none; } }
