/* ==========================================================================
   WIKI COMPONENTS (wiki-components.css)
   包含：Header 新增按钮 (hd-) 与 页面编辑操作 (gh-) 
   ========================================================================== */

/* --- 0. 防御性锁定：防止自定义组件在加载瞬间回退到白色 --- */
:root[data-md-color-scheme="slate"] {
  --md-default-bg-color: #1e2129 !important;
  --md-default-fg-color: rgba(255, 255, 255, 0.82) !important;
}

/* --- 1. 基础布局与复用容器 --- */
.hd-action-wrapper, .action-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

/* 页面内操作按钮 (gh-) 的特殊定位 */
.action-wrapper {
  float: right;
  z-index: 1;
  line-height: normal;
}

/* 页面内按钮图标行 */
.action-icons-row {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 6px;
}

/* --- 2. 统一触发按钮与图标渲染 --- */
.icon-btn-trigger {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--md-default-fg-color) !important;
  opacity: 0.7;
  cursor: pointer;
  transition: 0.2s;
}

.icon-btn-trigger:hover {
  opacity: 1;
}

.icon-btn-trigger svg {
  width: 100%;
  height: 100%;
  fill: currentColor;
}

/* 调整悬停菜单换行 */
[data-md-component="header"] .md-tooltip {
  width: auto !important;
  min-width: max-content !important;
}

[data-md-component="header"] .md-tooltip .md-tooltip__inner {
  min-width: fit-content !important;
  white-space: normal !important; 
  max-width: 200px !important;
  text-align: center;
}


/* --- 3. 核心弹出菜单逻辑与状态控制 --- */
.hd-popup-menu, .gh-popup-menu {
  display: none;
  position: absolute;
  top: 100%;
  width: 260px;
  z-index: 101;
  filter: drop-shadow(0 12px 30px rgba(0, 0, 0, 0.15));
  animation: popup-anim-desktop 0.2s ease-out;
}

/* 细节：根据不同位置调整弹窗偏移 */
.hd-popup-menu { right: -12px; margin-top: 8px; }
.gh-popup-menu { right: 0; margin-top: 10px; }

/* 状态控制：Checkbox 联动逻辑 */
#hd-action-toggle:checked ~ .hd-action-container .hd-popup-menu,
#action-menu-toggle:checked ~ .action-container .gh-popup-menu,
#hd-action-toggle:checked ~ .hd-overlay-mask,
#action-menu-toggle:checked ~ .action-overlay-mask {
  display: block;
}

/* --- 4. 遮罩层与装饰三角形 --- */
.hd-overlay-mask, .action-overlay-mask {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 100;
  background: transparent;
}

.hd-popup-arrow, .gh-popup-arrow {
  position: absolute;
  top: -6px;
  width: 12px;
  height: 12px;
  background: var(--md-default-bg-color);
  border-top: 1px solid var(--md-divider-color);
  border-left: 1px solid var(--md-divider-color);
  transform: rotate(45deg);
  z-index: 102;
}

/* 细节：区分三角形的水平位置 */
.hd-popup-arrow { right: 30px; }
.gh-popup-arrow { right: 48px; }

/* 深色模式下的三角形与背景色强制适配 */
[data-md-color-scheme="slate"] :is(.hd-popup-arrow, .gh-popup-arrow, .hd-popup-box, .gh-popup-box) {
  background-color: #2e323e !important;
}

/* --- 5. 弹出框内部内容样式 --- */
.hd-popup-box, .gh-popup-box {
  background: var(--md-default-bg-color);
  border: 1px solid var(--md-divider-color);
  border-radius: 12px;
  overflow: hidden;
  position: relative;
  z-index: 103;
  padding: 18px;
  line-height: normal;
}

.hd-popup-header strong, .gh-popup-header strong {
  display: block;
  font-size: 0.8rem;
  text-align: center;
  color: var(--md-default-fg-color);
}

.hd-popup-header p, .gh-popup-header p {
  margin: 6px 0 0;
  font-size: 0.65rem;
  color: var(--md-default-fg-color--light);
  line-height: 1.4;
  text-align: center;
}

/* GitHub 风格操作按钮 */
.hd-btn-github, .gh-btn-github {
  display: block;
  text-align: center;
  padding: 10px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  text-decoration: none;
  margin-top: 20px;
  background-color: #1f883d;
  color: #fff !important;
  transition: background-color 0.1s;
}

.hd-btn-github:hover, .gh-btn-github:hover { background-color: #1c8139; }
.hd-btn-github:active, .gh-btn-github:active { background-color: #197935; }

/* 深色模式下 GitHub 按钮色值微调 */
[data-md-color-scheme="slate"] :is(.hd-btn-github, .gh-btn-github) { background-color: #238636; }
[data-md-color-scheme="slate"] :is(.hd-btn-github, .gh-btn-github):hover { background-color: #29903b; }
[data-md-color-scheme="slate"] :is(.hd-btn-github, .gh-btn-github):active { background-color: #2e9a40; }

/* --- 6. 导航链接组 --- */
.hd-links-nav, .gh-links-nav {
  margin-top: 6px;
  padding-top: 12px;
  border-top: 1px solid var(--md-divider-color);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

:is(.hd-links-nav, .gh-links-nav) a {
  display: block;
  padding: 4px 0;
  font-size: 0.75rem;
  text-align: center;
  color: var(--md-default-fg-color);
  text-decoration: none;
}

:is(.hd-links-nav, .gh-links-nav) a:hover {
  color: var(--md-accent-fg-color);
  background-color: var(--md-default-bg-color--lightest);
  border-radius: 4px;
}

/* --- 7. 响应式布局调整与动画 --- */
@media screen and (max-width: 480px) {
  :is(.hd-overlay-mask, .action-overlay-mask) { background: rgba(0, 0, 0, 0.4); }

  :is(.hd-popup-menu, .gh-popup-menu) {
    position: fixed;
    top: 50%;
    left: 50%;
    right: auto;
    width: 85vw;
    max-width: 320px;
    margin: 0;
    transform: translate(-50%, -50%);
    /* 保持更弹的曲线 */
    animation: popup-anim-mobile 0.25s cubic-bezier(0.1, 0.7, 0.1, 1);
  }

  :is(.hd-popup-arrow, .gh-popup-arrow) { display: none; }
}

/* 桌面端入场动画 */
@keyframes popup-anim-desktop {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* 移动端入场动画 */
@keyframes popup-anim-mobile {
  from { 
    opacity: 0; 
    transform: translate(-50%, -45%) scale(0.95); 
  }
  to { 
    opacity: 1; 
    transform: translate(-50%, -50%) scale(1); 
  }
}
