:root {
  --global-sidebar-width: 80px;
  --global-sidebar-width-xl: 96px;
  --global-sidebar-bg: rgba(255, 255, 255, 0.94);
  --global-sidebar-line: rgba(0, 0, 0, 0.08);
  --global-sidebar-ink: #1d1d1f;
  --global-sidebar-muted: #667085;
  --global-sidebar-active: #0071e3;
  --global-sidebar-active-bg: #eaf4ff;
  --global-sidebar-hover-bg: #f5f7fb;
}

.global-sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 3000;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: var(--global-sidebar-width);
  padding: 32px 0 24px;
  background: var(--global-sidebar-bg) !important;
  border-right: 1px solid var(--global-sidebar-line) !important;
  box-shadow: 12px 0 34px rgba(15, 23, 42, 0.04) !important;
  backdrop-filter: saturate(180%) blur(22px) !important;
  -webkit-backdrop-filter: saturate(180%) blur(22px) !important;
}

@media (min-width: 1280px) {
  .global-sidebar {
    width: var(--global-sidebar-width-xl);
  }
}

.global-logo {
  width: 40px;
  height: 40px;
  margin: 0 auto 32px;
  display: grid !important;
  grid-template-columns: 1fr !important;
  grid-template-rows: 1fr !important;
  gap: 0 !important;
  place-items: center;
  border-radius: 12px;
  border: 1px solid rgba(0, 113, 227, 0.16);
  background: #ffffff !important;
  box-shadow: 0 10px 26px rgba(15, 23, 42, 0.08);
  color: var(--global-sidebar-active) !important;
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
}

.global-logo i {
  display: none !important;
}

.global-logo::after {
  content: "AI";
}

.global-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 0 8px;
}

.global-nav a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 56px;
  min-height: 56px;
  margin: 0 auto;
  padding: 8px 4px;
  border-radius: 16px;
  background: transparent !important;
  box-shadow: none !important;
  color: var(--global-sidebar-muted) !important;
  font-size: 10px;
  font-weight: 500;
  text-decoration: none;
  transition: all 0.2s ease;
}

.global-nav a:hover {
  background: var(--global-sidebar-hover-bg) !important;
  color: var(--global-sidebar-ink) !important;
}

.global-nav a.active {
  background: var(--global-sidebar-active-bg) !important;
  color: var(--global-sidebar-active) !important;
  box-shadow: inset 0 0 0 1px rgba(0, 113, 227, 0.12) !important;
}

.global-nav svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.global-nav a svg[fill="currentColor"] {
  fill: currentColor;
  stroke: none;
}

.global-avatar-link {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  margin: 0;
  padding: 0;
  text-decoration: none;
}

.global-avatar {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  margin: 0;
  border: 2px solid #ffffff !important;
  border-radius: 50%;
  background: #0062ff;
  color: #ffffff !important;
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0;
  white-space: nowrap;
  text-decoration: none;
  object-fit: cover;
  box-shadow:
    0 0 0 1px rgba(0, 113, 227, 0.16),
    0 8px 22px rgba(15, 23, 42, 0.12);
  transition: transform 0.2s ease;
}

.global-avatar:hover {
  transform: scale(1.05);
}

.global-user-header {
  position: fixed;
  top: 0;
  right: 0;
  left: var(--global-sidebar-width);
  z-index: 2950;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 12px 40px 12px 24px;
  background: rgba(247, 248, 250, 0.85);
  border-bottom: 1px solid rgba(229, 231, 235, 0.55);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.45) inset;
  backdrop-filter: saturate(180%) blur(24px);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
}

.global-user-dock {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Microsoft YaHei", sans-serif;
}

/* 登录态切换：未登录（data-auth="out"）时只显示"登录/注册"入口，
   隐藏点数/会员/通知/头像等已登录组件；默认（含判定中）隐藏登录入口防闪烁 */
.global-user-dock .global-login-pill {
  display: none;
  align-items: center;
  padding: 8px 18px;
  border-radius: 999px;
  background: #0062ff;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.18s ease, transform 0.18s ease;
}
.global-user-dock .global-login-pill:hover {
  background: #0051d6;
  transform: translateY(-1px);
}
.global-user-dock[data-auth="out"] .global-login-pill {
  display: inline-flex;
}
.global-user-dock[data-auth="out"] > :not(.global-login-pill) {
  display: none !important;
}

.global-dock-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.global-user-dock button,
.global-user-dock a {
  font-family: inherit;
}

.global-credit-pill,
.global-member-pill,
.global-bell-button,
.global-avatar-button {
  appearance: none;
  border: 0;
  text-decoration: none;
  cursor: pointer;
  transition:
    transform 0.18s ease,
    box-shadow 0.18s ease,
    border-color 0.18s ease,
    background 0.18s ease;
}

.global-credit-pill:focus,
.global-member-pill:focus,
.global-bell-button:focus,
.global-avatar-button:focus {
  outline: none;
}

.global-credit-pill:focus-visible,
.global-member-pill:focus-visible,
.global-bell-button:focus-visible,
.global-avatar-button:focus-visible {
  outline: 2px solid rgba(0, 98, 255, 0.38);
  outline-offset: 3px;
}

.global-credit-pill {
  min-width: 94px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid rgba(0, 98, 255, 0.3);
  border-radius: 999px;
  background: #ffffff;
  color: #0062ff;
  box-shadow: none;
  font-size: 14px;
  line-height: 20px;
  font-weight: 500;
}

.global-credit-pill svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.global-member-pill {
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 20px;
  border-radius: 999px;
  background: #0062ff;
  color: #ffffff;
  box-shadow: 0 1px 2px rgba(0, 98, 255, 0.2);
  font-size: 14px;
  line-height: 20px;
  font-weight: 500;
  white-space: nowrap;
}

.global-user-separator {
  width: 1px;
  height: 20px;
  margin: 0 4px;
  background: #e5e7eb;
}

.global-bell-button {
  position: relative;
  width: 40px;
  height: 40px;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  background: transparent;
  color: #6b7280;
}

.global-bell-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.global-notice-dot {
  position: absolute;
  top: 8px;
  right: 10px;
  width: 8px;
  height: 8px;
  border: 2px solid #ffffff;
  border-radius: 50%;
  background: #ff3b30;
}

.global-avatar-button {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  border: 2px solid transparent;
  overflow: hidden;
  background: #0062ff;
  color: #ffffff;
  box-shadow: none;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0;
  margin-left: 4px;
}

.global-credit-pill:hover,
.global-credit-pill[aria-expanded="true"] {
  border-color: rgba(0, 98, 255, 0.3);
  background: #e6f0ff;
  box-shadow: none;
}

.global-member-pill:hover {
  background: #0052d9;
  box-shadow: 0 1px 2px rgba(0, 98, 255, 0.2);
}

.global-bell-button:hover,
.global-bell-button[aria-expanded="true"] {
  background: #f3f4f6;
  color: #1f2937;
}

.global-avatar-button:hover,
.global-avatar-button[aria-expanded="true"] {
  border-color: #e6f0ff;
}

.global-user-popover {
  position: absolute;
  top: calc(100% + 12px);
  right: 0;
  z-index: 50;
  overflow: hidden;
  border: 1px solid #f3f4f6;
  border-radius: 16px;
  background: #ffffff;
  color: #1f2937;
  opacity: 0;
  visibility: hidden;
  transform: scale(0.95) translateY(-5px);
  transform-origin: top right;
  transition:
    opacity 0.2s ease,
    visibility 0.2s ease,
    transform 0.2s ease;
}

.global-user-popover.is-open {
  opacity: 1;
  visibility: visible;
  transform: scale(1) translateY(0);
}

.global-user-popover[hidden] {
  display: none !important;
}

.global-points-popover {
  width: 256px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

.global-points-top {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px;
  border-bottom: 1px solid #f9fafb;
}

.global-points-top span {
  margin-bottom: 4px;
  color: #6b7280;
  font-size: 12px;
  line-height: 16px;
}

.global-points-top strong {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 16px;
  color: #0062ff;
  font-size: 30px;
  line-height: 36px;
  font-weight: 700;
  letter-spacing: 0;
}

.global-recharge-button {
  width: 100%;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 12px;
  border-radius: 12px;
  background: #0062ff;
  color: #ffffff;
  box-shadow: 0 1px 2px rgba(0, 98, 255, 0.2);
  font-size: 14px;
  line-height: 20px;
  font-weight: 500;
}

.global-points-links {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 8px;
}

.global-points-links a,
.global-profile-menu a,
.global-profile-menu button {
  color: inherit;
  text-decoration: none;
}

.global-points-links a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  transition:
    background 0.2s ease,
    color 0.2s ease;
}

.global-points-links a:hover {
  background: #f9fafb;
}

.global-menu-icon {
  width: 32px;
  height: 32px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 32px;
  border-radius: 50%;
}

.global-menu-icon.blue {
  background: #eff6ff;
  color: #0062ff;
}

.global-menu-icon.orange {
  background: #fff7ed;
  color: #f97316;
}

.global-menu-icon svg,
.global-profile-menu svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.global-points-links strong {
  display: block;
  color: #374151;
  font-size: 14px;
  line-height: 20px;
  font-weight: 500;
}

.global-points-links small {
  display: block;
  color: #9ca3af;
  font-size: 12px;
  line-height: 16px;
}

.global-notifications-popover {
  width: 420px;
  max-width: calc(100vw - 80px);
  max-height: min(620px, calc(100vh - 96px));
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
}

.global-notifications-popover header {
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: 53px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid #f9fafb;
  border-radius: 16px 16px 0 0;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.global-notifications-popover h3 {
  margin: 0;
  color: #1f2937;
  font-size: 14px;
  line-height: 20px;
  font-weight: 700;
}

.global-notifications-popover header button {
  border: 0;
  background: transparent;
  color: #0062ff;
  font-size: 12px;
  line-height: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.2s ease;
}

.global-notifications-popover header button:hover {
  color: #0052d9;
}

.global-notice-list {
  overflow: auto;
  max-height: 480px;
  padding: 8px 16px;
}

.global-notice-item {
  position: relative;
  display: flex;
  gap: 12px;
  padding: 0 0 24px;
  margin-bottom: 24px;
  border-bottom: 1px solid #f9fafb;
}

.global-notice-item:last-child {
  margin-bottom: 0;
  border-bottom: 0;
}

.global-notice-icon {
  width: 40px;
  height: 40px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 40px;
  border-radius: 50%;
  background: #839dfd;
  color: #ffffff;
}

.global-notice-icon svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.global-notice-content {
  min-width: 0;
  flex: 1;
  padding-top: 2px;
}

.global-notice-meta {
  margin-bottom: 8px;
}

.global-notice-meta strong {
  display: block;
  margin-bottom: 2px;
  color: #1f2937;
  font-size: 15px;
  line-height: 20px;
  font-weight: 700;
}

.global-notice-meta time {
  color: #9ca3af;
  font-size: 12px;
  line-height: 16px;
}

.global-notice-content h4 {
  margin: 0 0 6px;
  color: #111827;
  font-size: 14px;
  line-height: 1.375;
  font-weight: 700;
}

.global-notice-content p {
  margin: 0;
  color: #4b5563;
  font-size: 13px;
  line-height: 1.625;
}

.global-notice-content img {
  display: block;
  width: 100%;
  aspect-ratio: 2 / 1;
  height: auto;
  margin-top: 12px;
  border-radius: 12px;
  object-fit: cover;
}

.global-notice-link {
  display: inline-flex;
  margin-top: 8px;
  color: #0062ff;
  font-size: 13px;
  line-height: 18px;
  font-weight: 500;
}

.global-notice-unread {
  position: absolute;
  left: 30px;
  top: 30px;
  width: 12px;
  height: 12px;
  border: 2px solid #ffffff;
  border-radius: 50%;
  background: #ff3b30;
}

.global-notice-empty {
  min-height: 240px;
  display: grid;
  place-items: center;
  color: #9ca3af;
  font-size: 13px;
  line-height: 18px;
}

.global-notice-all {
  min-height: 45px;
  display: grid;
  place-items: center;
  padding: 12px;
  border-top: 1px solid #f9fafb;
  border-radius: 0 0 16px 16px;
  background: rgba(249, 250, 251, 0.5);
  color: #6b7280;
  font-size: 13px;
  line-height: 18px;
  font-weight: 500;
  text-decoration: none;
}

.global-profile-popover {
  width: 192px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

.global-profile-head {
  padding: 16px;
  border-bottom: 1px solid #f9fafb;
}

.global-profile-head strong {
  display: block;
  color: #1f2937;
  font-size: 14px;
  line-height: 20px;
  font-weight: 700;
}

.global-profile-head span {
  display: block;
  margin-top: 2px;
  color: #9ca3af;
  font-size: 12px;
  line-height: 16px;
}

.global-profile-head em {
  font-style: normal;
}

.global-profile-menu {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px;
}

.global-profile-menu a,
.global-profile-menu button {
  min-height: 36px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 12px;
  border: 0;
  background: transparent;
  color: #4b5563;
  font-size: 14px;
  line-height: 20px;
  font-weight: 400;
  text-align: left;
  cursor: pointer;
  transition:
    background 0.2s ease,
    color 0.2s ease;
}

.global-profile-menu button {
  position: relative;
  margin-top: 9px;
  color: #ef4444;
}

.global-profile-menu button::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: -5px;
  height: 1px;
  background: #f9fafb;
}

.global-profile-menu a:hover,
.global-profile-menu button:hover,
.global-points-links a:hover,
.global-notice-all:hover {
  color: #111827;
  background: #f9fafb;
}

.global-profile-menu a:nth-child(2):hover {
  color: #0062ff;
  background: #e6f0ff;
}

.global-profile-menu button:hover {
  color: #ef4444;
  background: #fef2f2;
}

body.has-global-user-dock .portal-shell,
body.has-global-user-dock .tools-shell,
body.has-global-user-dock .library-shell,
body.has-global-user-dock .tutorial-shell,
body.has-global-user-dock .membership-shell,
body.has-global-user-dock .account-shell,
body.has-global-user-dock > .main {
  padding-top: 72px !important;
}

body.has-global-sidebar {
  padding-left: var(--global-sidebar-width) !important;
}

@media (min-width: 1280px) {
  .global-user-header {
    left: var(--global-sidebar-width-xl);
  }

  body.has-global-sidebar {
    padding-left: var(--global-sidebar-width-xl) !important;
  }
}

.has-global-sidebar .editor-topbar,
.has-global-sidebar .compose-topbar {
  margin-left: 0;
}

.has-global-sidebar .editor-shell,
.has-global-sidebar .compose-shell {
  width: 100%;
}

@media (max-width: 700px) {
  .global-user-header {
    left: 0;
    height: 46px;
    padding: 6px 12px;
  }

  .global-user-dock {
    gap: 8px;
  }

  .global-credit-pill {
    min-width: 88px;
    height: 34px;
    padding: 7px 12px;
    font-size: 14px;
  }

  .global-member-pill {
    height: 34px;
    padding: 0 14px;
    font-size: 13px;
  }

  .global-bell-button,
  .global-avatar-button {
    width: 34px;
    height: 34px;
  }

  .global-points-popover {
    width: min(256px, calc(100vw - 24px));
  }

  .global-notifications-popover {
    width: min(420px, calc(100vw - 24px));
    max-width: calc(100vw - 24px);
  }

  .global-profile-popover {
    width: min(192px, calc(100vw - 24px));
  }

  .global-notifications-popover {
    max-height: calc(100vh - 132px);
  }

  .global-notice-item {
    gap: 12px;
  }

  .global-notice-icon {
    width: 40px;
    height: 40px;
  }

  .global-notice-content img {
    height: auto;
  }

  body.has-global-user-dock .portal-shell,
  body.has-global-user-dock .tools-shell,
  body.has-global-user-dock .library-shell,
  body.has-global-user-dock .tutorial-shell,
  body.has-global-user-dock .membership-shell,
  body.has-global-user-dock .account-shell,
  body.has-global-user-dock > .main {
    padding-top: 52px !important;
  }

  body.has-global-sidebar {
    padding-left: 0 !important;
    padding-bottom: 72px !important;
  }

  .global-sidebar {
    inset: auto 0 0;
    width: 100% !important;
    height: 68px;
    flex-direction: row;
    align-items: center;
    padding: 8px 12px;
    border-right: 0 !important;
    border-top: 1px solid var(--global-sidebar-line) !important;
    box-shadow: 0 -12px 32px rgba(15, 23, 42, 0.06) !important;
  }

  .global-logo,
  .global-avatar-link {
    display: none !important;
  }

  .global-nav {
    flex: 1;
    flex-direction: row;
    justify-content: space-around;
    gap: 0;
    padding: 0;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .global-nav::-webkit-scrollbar {
    display: none;
  }

  .global-nav a {
    width: auto;
    min-width: 54px;
    min-height: auto;
    padding: 6px 4px;
  }

  .has-global-sidebar .editor-topbar,
  .has-global-sidebar .compose-topbar {
    margin-left: 0;
  }
}

/* =====================================================================
   防污染保护：部分页面存在 body.xxx-page a { color: inherit } 之类的
   全局规则，加载顺序靠后时会覆盖顶部用户区的文字颜色与排版。
   以下规则用更高优先级把顶部用户区的视觉锁定为统一样式。
   ===================================================================== */
body .global-user-dock .global-member-pill {
  color: #ffffff !important;
  font-size: 14px !important;
  font-weight: 500 !important;
  line-height: 20px !important;
  text-decoration: none !important;
}

body .global-user-dock .global-credit-pill {
  color: #0062ff !important;
  font-size: 14px !important;
  font-weight: 500 !important;
  line-height: 20px !important;
  text-decoration: none !important;
}

body .global-user-dock .global-avatar-button,
body .global-user-dock .global-avatar-button [data-global-avatar-text] {
  color: #ffffff !important;
  font-size: 14px !important;
  font-weight: 800 !important;
  line-height: 1 !important;
  letter-spacing: 0 !important;
  text-align: center !important;
  white-space: nowrap !important;
}

body .global-user-dock .global-bell-button {
  color: #6b7280 !important;
}

body .global-user-dock .global-recharge-button {
  color: #ffffff !important;
  text-decoration: none !important;
}

body .global-user-dock .global-notice-all {
  color: #6b7280 !important;
  text-decoration: none !important;
}

body .global-user-dock .global-user-popover,
body .global-user-dock .global-user-popover a {
  text-decoration: none !important;
}
