@layer existing {
/* ============================================================
   auth.css — 账号系统组件样式（Apple 风格）
   版本：v2 · 2026-09-22
   职责：登录/注册弹窗、用户按钮、用户菜单 Popover、Toast、
         笔记页用户角标、无导航页浮动按钮
   约束：
     - 全部颜色取自 design.css 的设计令牌（--fg / --surface /
       --accent / --ln-hair …），浅色深色自动切换
     - 菜单开合使用 opacity / visibility / transform /
       pointer-events，不使用 display 突变
     - 本文件是唯一允许覆盖 auth 组件的地方；旧版 auth.js
       内联注入样式已移除
   ============================================================ */

/* ---------- 本组件私有的主题变量 ---------- */
:root,
html[data-theme="dark"] {
  --auth-glass: rgba(30, 30, 32, 0.86);
  --auth-glass-solid: #1e1e20;
  --auth-card-bg: #1c1c1e;
  --auth-field-bg: rgba(255, 255, 255, 0.06);
  --auth-menu-shadow: 0 12px 40px rgba(0, 0, 0, 0.55),
    0 2px 8px rgba(0, 0, 0, 0.4);
  --auth-card-shadow: 0 24px 70px rgba(0, 0, 0, 0.6),
    0 4px 16px rgba(0, 0, 0, 0.4);
  --auth-overlay-bg: rgba(0, 0, 0, 0.48);
}
html[data-theme="light"] {
  --auth-glass: rgba(255, 255, 255, 0.86);
  --auth-glass-solid: #ffffff;
  --auth-card-bg: #ffffff;
  --auth-field-bg: rgba(0, 0, 0, 0.03);
  --auth-menu-shadow: 0 12px 40px rgba(0, 0, 0, 0.16),
    0 2px 8px rgba(0, 0, 0, 0.06);
  --auth-card-shadow: 0 24px 70px rgba(0, 0, 0, 0.22),
    0 4px 16px rgba(0, 0, 0, 0.08);
  --auth-overlay-bg: rgba(0, 0, 0, 0.36);
}

/* ============================================================
   1. 导航栏用户按钮（已登录）
   ============================================================ */
.auth-usermenu { position: relative; display: inline-block; }

.auth-trigger {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 2px 10px 2px 2px;
  border: none;
  border-radius: var(--r-pill, 980px);
  background: transparent;
  color: var(--fg);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: -0.01em;
  cursor: pointer;
  white-space: nowrap;
  transition: background 140ms var(--ease, ease);
}
.auth-trigger:hover { background: color-mix(in srgb, var(--fg) 8%, transparent); }
.auth-trigger:active { transform: scale(0.97); }
.auth-trigger:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.auth-avatar {
  width: 30px;
  height: 30px;
  flex: none;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--fg);
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  user-select: none;
}
.auth-avatar-lg { width: 38px; height: 38px; font-size: 16px; }

.auth-name {
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.auth-chev {
  width: 8px;
  height: 5px;
  flex: none;
  opacity: 0.55;
  transition: transform 160ms var(--ease, ease);
}
.auth-usermenu.open .auth-chev { transform: rotate(180deg); }

/* ============================================================
   2. 用户菜单 Popover
   ============================================================ */
.auth-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  width: 244px;
  padding: 6px;
  border-radius: 16px;
  border: 1px solid var(--ln-hair);
  background: var(--auth-glass);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  backdrop-filter: blur(20px) saturate(160%);
  box-shadow: var(--auth-menu-shadow);
  z-index: 100;
  transform-origin: top right;
  /* 开合：不使用 display 突变 */
  opacity: 0;
  visibility: hidden;
  transform: scale(0.96) translateY(-4px);
  pointer-events: none;
  transition:
    opacity 160ms var(--ease, ease),
    transform 160ms var(--ease, ease),
    visibility 0s linear 160ms;
}
/* 不支持毛玻璃时退回纯色 */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .auth-menu { background: var(--auth-glass-solid); }
}
/* 隐形桥：覆盖按钮与菜单之间的 8px 缝隙，指针经过不算离开 */
.auth-menu::before {
  content: "";
  position: absolute;
  top: -10px;
  left: 0;
  right: 0;
  height: 10px;
}
.auth-usermenu.open .auth-menu {
  opacity: 1;
  visibility: visible;
  transform: none;
  pointer-events: auto;
  transition:
    opacity 160ms var(--ease, ease),
    transform 160ms var(--ease, ease);
}

/* 菜单头部：头像 + 用户名 */
.auth-menu-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px 12px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--ln-hair);
}
.auth-menu-meta { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.auth-menu-meta b {
  font-size: 14px;
  font-weight: 600;
  color: var(--fg);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.auth-menu-meta i {
  font-style: normal;
  font-size: 11.5px;
  color: var(--muted);
}

/* 菜单项 */
.auth-menu a,
.auth-menu button.auth-mi {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  box-sizing: border-box;
  padding: 8px 12px;
  border: none;
  border-radius: 10px;
  background: none;
  color: var(--fg);
  font-family: inherit;
  font-size: 13px;
  font-weight: 400;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition: background 120ms var(--ease, ease);
}
.auth-menu a:hover,
.auth-menu button.auth-mi:hover,
.auth-menu a:focus-visible,
.auth-menu button.auth-mi:focus-visible {
  background: color-mix(in srgb, var(--fg) 7%, transparent);
  outline: none;
}
.auth-mi-ico {
  width: 16px;
  height: 16px;
  flex: none;
  color: var(--muted);
}
.auth-menu a:hover .auth-mi-ico,
.auth-menu button.auth-mi:hover .auth-mi-ico { color: var(--fg); }
.auth-menu .auth-logout { color: var(--danger); }
.auth-menu .auth-logout .auth-mi-ico { color: var(--danger); }

/* 外观三段式 */
.auth-menu-seg {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 12px;
  margin: 4px 0;
  border-top: 1px solid var(--ln-hair);
}
.auth-seg-label { font-size: 12.5px; color: var(--muted); }
.auth-seg {
  display: inline-flex;
  padding: 2px;
  border-radius: 9px;
  background: color-mix(in srgb, var(--fg) 7%, transparent);
}
.auth-seg button {
  border: none;
  border-radius: 7px;
  padding: 4px 10px;
  background: transparent;
  color: var(--fg-2);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: background 140ms var(--ease, ease), color 140ms var(--ease, ease),
    box-shadow 140ms var(--ease, ease);
}
.auth-seg button[aria-pressed="true"] {
  background: var(--auth-card-bg);
  color: var(--fg);
  font-weight: 500;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
}

/* ============================================================
   3. 登录 / 注册弹窗
   ============================================================ */
.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal, 9800);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--auth-overlay-bg) ; /* 覆盖 design.css 1715 行的  */
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 200ms var(--ease, ease), visibility 0s linear 200ms;
}
.auth-overlay.show {
  opacity: 1;
  visibility: visible;
  transition: opacity 200ms var(--ease, ease);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  max-height: calc(100dvh - 40px);
  overflow-y: auto;
  padding: 28px 28px 24px;
  position: relative;
  border-radius: 18px;
  border: 1px solid var(--ln-hair);
  background: var(--auth-card-bg);
  color: var(--fg);
  box-shadow: var(--auth-card-shadow);
  transform: scale(0.96) translateY(8px);
  transition: transform 220ms var(--ease, ease);
}
.auth-overlay.show .auth-card { transform: none; }

.auth-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 120ms var(--ease, ease), color 120ms var(--ease, ease);
}
.auth-close:hover { background: color-mix(in srgb, var(--fg) 8%, transparent); color: var(--fg); }
.auth-close svg { width: 13px; height: 13px; display: block; }

.auth-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin: 0 0 4px;
}
.auth-sub {
  font-size: 13px;
  color: var(--muted);
  margin: 0 0 18px;
}

/* 登录 / 注册切换：分段控件 */
.auth-tabs {
  display: flex;
  padding: 2px;
  margin-bottom: 18px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--fg) 7%, transparent);
}
.auth-tab {
  flex: 1;
  border: none;
  border-radius: 8px;
  padding: 7px 0;
  background: transparent;
  color: var(--fg-2);
  font-family: inherit;
  font-size: 13.5px;
  cursor: pointer;
  transition: background 160ms var(--ease, ease), color 160ms var(--ease, ease),
    box-shadow 160ms var(--ease, ease);
}
.auth-tab.active {
  background: var(--auth-card-bg);
  color: var(--fg);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.16);
}

.auth-field { margin-bottom: 14px; }
.auth-field label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}
.auth-field input {
  width: 100%;
  box-sizing: border-box;
  font-family: inherit;
  font-size: 15px;
  color: var(--fg);
  padding: 11px 12px;
  border: 1px solid var(--ln-strong);
  border-radius: 10px;
  background: var(--auth-field-bg);
  outline: none;
  transition: border-color 140ms var(--ease, ease), box-shadow 140ms var(--ease, ease);
}
.auth-field input::placeholder { color: var(--muted-2); }
.auth-field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3.5px var(--accent-soft);
}

.auth-err {
  min-height: 18px;
  font-size: 12.5px;
  color: var(--danger);
  margin: 2px 0 8px;
}

.auth-submit {
  display: block;
  width: 100%;
  border: none;
  border-radius: 12px;
  padding: 12px 0;
  background: var(--accent);
  color: var(--accent-ink);
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  cursor: pointer;
  transition: background 140ms var(--ease, ease), transform 120ms var(--ease, ease),
    opacity 140ms var(--ease, ease);
}
.auth-submit:hover { background: var(--accent-hover); }
.auth-submit:active { transform: scale(0.98); }
.auth-submit[disabled] { opacity: 0.55; cursor: wait; }

.auth-foot {
  margin-top: 16px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.6;
  text-align: center;
}

/* ============================================================
   4. Toast 提示
   ============================================================ */
.auth-toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translateX(-50%) translateY(8px);
  z-index: var(--z-toast, 9900);
  max-width: min(90vw, 420px);
  padding: 10px 18px;
  border-radius: var(--r-pill, 980px);
  border: 1px solid var(--ln-hair);
  background: var(--auth-glass);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  backdrop-filter: blur(20px) saturate(160%);
  color: var(--fg);
  font-size: 13px;
  box-shadow: var(--auth-menu-shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms var(--ease, ease), transform 200ms var(--ease, ease);
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .auth-toast { background: var(--auth-glass-solid); }
}
.auth-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ============================================================
   5. 笔记页角标 / 无导航页浮动按钮
   ============================================================ */
.auth-notechip {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  font-size: 13px;
  color: var(--fg-2, inherit);
  text-decoration: none;
  white-space: nowrap;
}
.auth-float {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 8700;
}

/* ============================================================
   6. 响应式：窄屏只留头像
   ============================================================ */
@media (max-width: 767px) {
  .auth-name,
  .auth-chev { display: none; }
  .auth-trigger { padding: 2px; }
  .auth-menu { position: fixed; top: 54px; right: 10px; left: auto; }
  .auth-card { padding: 24px 20px 20px; }
}

}
