/* ============================================================
 * SN-ERP 统一顶栏 + 导航 / 账户 / 功能 / 说明 弹窗
 * ------------------------------------------------------------
 * 约定：
 * 1) 顶栏只有三样东西：页面标题（≤4 字）、姓名、导航/功能两颗图标按钮；
 * 2) 所有按钮 44×44 热区，图标之间 gap 6px（视觉胶囊间距 18px），防误触；
 * 3) 顶栏不放"会写数据 / 会打上游"的动作，误触也不会产生后果；
 * 4) 各页只传 --ab-accent 做识别色，不改结构；
 * 5) 弹窗层级 40 > 页面内弹窗 30，打开前先收起页内弹窗。
 * ============================================================ */

:root {
  /* 各页通过 SN_PAGE.accent 覆盖；默认看板青 */
  --ab-accent: #22d3ee;
  --ab-bg: #05080f;
}

/* ---------------- 顶栏 ---------------- */

/* 顶栏自带盒模型，避免嵌到没有全局 reset 的页面里横向溢出 */
#appbar, .ab, .ab *, .ab-sheet, .ab-sheet * { box-sizing: border-box; }

.ab {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  max-width: 540px;
  margin: 0 auto;
  padding: 5px 12px;
  padding-top: calc(5px + env(safe-area-inset-top));
  background: linear-gradient(180deg, var(--ab-bg) 70%, rgba(5, 8, 15, 0.92) 88%, rgba(5, 8, 15, 0));
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

.ab-title {
  margin: 0;
  flex: 1;
  min-width: 0;
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: 0.01em;
  color: #e9f4ff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ab-right {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px; /* 两颗 52px 热区之间净空 8px = 视觉胶囊间距 20px */
}

/* 姓名胶囊：点开账户弹窗（倒计时在弹窗里，顶栏不抖） */
.ab-user {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  max-width: 84px;
  margin-right: 8px; /* 与图标组留分组缝：视觉 18px+ */
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.05);
  color: #e6edf3;
  font: 12px/1 -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  cursor: pointer;
}
.ab-user:active {
  border-color: var(--ab-accent);
  color: #fff;
}
.ab-user .ab-name {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-weight: 600;
}
.ab-avatar {
  display: none;
  flex: none;
  width: 22px;
  height: 22px;
  place-items: center;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 600;
  color: #04121a;
  background: var(--ab-accent);
}

/* 图标按钮：52px 高热区，视觉为「图标 + 文字」胶囊，互不重叠 */
.ab-icon {
  position: relative;
  appearance: none;
  flex: none;
  width: auto;
  height: 56px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}
.ab-ico {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  gap: 5px;
  height: 44px;
  min-width: 44px;
  padding: 0 11px 0 10px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.05);
  color: #c9d6e4;
}
.ab-lab {
  color: #aebccb;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.5px;
  line-height: 1;
  white-space: nowrap;
}
.ab-icon:active .ab-ico {
  border-color: var(--ab-accent);
  color: var(--ab-accent);
}
.ab-icon:active .ab-lab { color: var(--ab-accent); }
.ab-icon:focus-visible .ab-ico {
  outline: 2px solid var(--ab-accent);
  outline-offset: 2px;
}
.ab-count {
  position: absolute;
  top: -3px;
  right: -5px;
  min-width: 17px;
  height: 17px;
  height: 17px;
  display: grid;
  place-items: center;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--ab-accent);
  color: #04121a;
  font: 600 10.5px/1 "SF Mono", ui-monospace, Menlo, monospace;
}
.ab-count[hidden] { display: none; }

/* ≤369px：姓名退化为首字圆头像 —— 带文字标签后按钮更宽，360 宽留给标题 */
@media (max-width: 369px) {
  .ab-avatar { display: grid; }
  .ab-user .ab-name { display: none; }
  .ab-user { padding: 0 6px; max-width: none; }
}

/* 管理后台这类桌面页：顶栏与内容同宽（980） */
.ab-wide {
  max-width: 980px;
  padding-left: 18px;
  padding-right: 18px;
}

/* ---------------- 弹窗（导航 / 账户 / 功能 / 说明） ---------------- */

.ab-sheet {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.ab-sheet[hidden] { display: none; }

.ab-mask {
  position: absolute;
  inset: 0;
  background: rgba(2, 5, 10, 0.62);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

.ab-panel {
  position: relative;
  width: 100%;
  max-width: 540px;
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  border: 1px solid rgba(94, 234, 255, 0.18);
  border-bottom: 0;
  border-radius: 18px 18px 0 0;
  background: linear-gradient(160deg, #0b1420, #070d16);
  box-shadow: 0 -18px 40px -24px #000;
  padding-bottom: env(safe-area-inset-bottom);
  animation: abUp 0.18s ease both;
}
@keyframes abUp {
  from { transform: translateY(14px); opacity: 0.6; }
  to { transform: none; opacity: 1; }
}

.ab-grab {
  flex: none;
  width: 38px;
  height: 4px;
  margin: 8px auto 2px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
}

.ab-head {
  flex: none;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 16px 4px;
}
.ab-kicker {
  margin: 0 0 3px;
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #7d90a8;
}
.ab-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: #e9f4ff;
}
.ab-close {
  appearance: none;
  flex: none;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  color: #7d90a8;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}
.ab-close:active { color: var(--ab-accent); }

.ab-body {
  padding: 6px 16px calc(18px + env(safe-area-inset-bottom));
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

.ab-group {
  margin: 12px 0 8px;
  font-size: 11px;
  letter-spacing: 0.08em;
  color: #7d90a8;
}
.ab-group:first-child { margin-top: 4px; }

.ab-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.ab-cell {
  position: relative;
  appearance: none;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
  min-height: 60px;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.035);
  color: inherit;
  font: inherit;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.ab-cell:active { border-color: var(--ab-accent); }
.ab-cell:focus-visible { outline: 2px solid var(--ab-accent); outline-offset: 2px; }
.ab-cell.wide { grid-column: 1 / -1; }
.ab-cell.current {
  cursor: default;
  opacity: 0.55;
}
.ab-cell-t {
  font-size: 13.5px;
  font-weight: 600;
  color: #eaf4ff;
  line-height: 1.3;
}
.ab-cell-d {
  font-size: 11px;
  line-height: 1.4;
  color: #7d90a8;
}
.ab-now {
  position: absolute;
  top: 8px;
  right: 10px;
  font-style: normal;
  font-size: 10px;
  color: var(--ab-accent);
}
.ab-cell-count {
  position: absolute;
  top: 8px;
  right: 10px;
  min-width: 16px;
  height: 16px;
  display: grid;
  place-items: center;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--ab-accent);
  color: #04121a;
  font: 600 10px/1 "SF Mono", ui-monospace, Menlo, monospace;
}

/* 状态类小字行（Token 状态 / 健康探针） */
.ab-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-top: 12px;
  font-size: 12px;
}
.ab-links a {
  color: #8fa3bb;
  text-decoration: none;
}
.ab-links a:active { color: var(--ab-accent); }

/* 账户弹窗：只读信息行 + 操作 */
.ab-rows {
  display: grid;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  overflow: hidden;
}
.ab-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 12px;
  background: rgba(255, 255, 255, 0.03);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 12.5px;
  color: #8fa3bb;
}
.ab-row:first-child { border-top: 0; }
.ab-row b {
  font-weight: 600;
  color: #e9f4ff;
}
.ab-row b.mono {
  font-family: "SF Mono", ui-monospace, Menlo, monospace;
  font-variant-numeric: tabular-nums;
}

.ab-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
}
.ab-link {
  flex: 1;
  display: grid;
  place-items: center;
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.04);
  color: #c9d6e4;
  font-size: 13px;
  text-decoration: none;
}
.ab-danger {
  appearance: none;
  flex: 1;
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid rgba(248, 113, 113, 0.4);
  background: rgba(248, 113, 113, 0.1);
  color: #f87171;
  font: 13px inherit;
  cursor: pointer;
}
.ab-link[hidden] { display: none; }

/* 说明弹窗：段落 */
.ab-info p {
  margin: 0 0 10px;
  font-size: 12.5px;
  line-height: 1.7;
  color: #c3cfe8;
}
.ab-info p b { color: #eaf4ff; }
.ab-info code {
  font-family: "SF Mono", ui-monospace, Menlo, monospace;
  font-size: 11.5px;
  color: #8fe9f7;
}
