/*
 * 标准弹窗 + 字段 + 开关 + 进阶折叠 (pangu-modal / field / switch / disclosure)
 * ---------------------------------------------------------------------------
 * 来源：component-spec.html 模块 6「标准弹窗规范与进阶项折叠」+ 模块 7 字段套件。
 * 结构：头部说明任务 → 主体给决策依据 → 进阶选项默认折叠（不吓退小白）→ 底部一个 primary。
 *
 * ⚠️ 分组选择部分（.console-key-create-group-*）用户明确要求保持原样，
 *    本文件不含任何分组相关规则，那套旧样式继续由 legacy.css 提供。
 *    已核对：legacy 里没有任何规则把分组类嵌在 .console-key-modal 作用域下，
 *    所以外层换成 pangu-modal-* 不会影响分组的显示。
 */

/* ==========================================================================
   弹窗骨架
   ========================================================================== */
.pangu-modal {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--pangu-space-4);
}

.pangu-modal[hidden] {
  display: none;
}

.pangu-modal-backdrop {
  position: absolute;
  inset: 0;
  padding: 0;
  border: 0;
  cursor: default;
  background: var(--pangu-overlay);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.pangu-modal-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 540px;
  max-height: calc(100vh - var(--pangu-space-6));
  background: var(--pangu-surface);
  border: 1px solid var(--pangu-border-strong);
  border-radius: var(--pangu-radius-lg);
  box-shadow: var(--pangu-shadow-h);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.pangu-modal-header {
  padding: var(--pangu-space-4) var(--pangu-space-5);
  border-bottom: 1px solid var(--pangu-border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--pangu-space-3);
}

.pangu-modal-title {
  margin: 0;
  font-size: var(--pangu-fs-lg);
  font-weight: 750;
  line-height: 1.25;
  color: var(--pangu-text);
}

.pangu-modal-subtitle {
  margin: var(--pangu-space-1) 0 0;
  font-size: var(--pangu-fs-xs);
  line-height: 1.4;
  color: var(--pangu-text-2);
}

.pangu-modal-body {
  padding: var(--pangu-space-5);
  display: flex;
  flex-direction: column;
  gap: var(--pangu-space-4);
  /* flex 列里要 min-height:0 才会真的滚动，否则内容会把卡片撑出屏幕、底部按钮被切掉 */
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

.pangu-modal-footer {
  padding: var(--pangu-space-3) var(--pangu-space-5);
  border-top: 1px solid var(--pangu-border);
  background: var(--pangu-bg-hover);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--pangu-space-3);
}

/* ==========================================================================
   字段
   ========================================================================== */
.pangu-field {
  display: flex;
  flex-direction: column;
  gap: var(--pangu-space-2);
  width: 100%;
  min-width: 0;
}

.pangu-field-label {
  font-size: var(--pangu-fs-sm);
  font-weight: 600;
  color: var(--pangu-text);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--pangu-space-2);
}

.pangu-field-label-desc {
  font-size: var(--pangu-fs-xs);
  font-weight: 400;
  color: var(--pangu-text-3);
  text-align: right;
}

.pangu-field-input,
.pangu-field-select {
  height: 38px;
  width: 100%;
  border-radius: var(--pangu-radius-sm);
  border: 1px solid var(--pangu-border);
  background: var(--pangu-surface-sunken);
  padding: 0 var(--pangu-space-3);
  font-family: inherit;
  font-size: var(--pangu-fs-sm);
  color: var(--pangu-text);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.pangu-field-textarea {
  min-height: 72px;
  width: 100%;
  border-radius: var(--pangu-radius-sm);
  border: 1px solid var(--pangu-border);
  background: var(--pangu-surface-sunken);
  padding: var(--pangu-space-2) var(--pangu-space-3);
  font-family: inherit;
  font-size: var(--pangu-fs-sm);
  line-height: 1.5;
  color: var(--pangu-text);
  outline: none;
  resize: vertical;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.pangu-field-input:focus,
.pangu-field-select:focus,
.pangu-field-textarea:focus {
  border-color: var(--pangu-brand);
  box-shadow: var(--pangu-focus-ring);
}

.pangu-field-input:disabled,
.pangu-field-select:disabled,
.pangu-field-textarea:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.pangu-field-hint {
  font-size: var(--pangu-fs-xs);
  line-height: 1.4;
  color: var(--pangu-text-2);
}

/* 字段级错误：贴在字段正下方（反馈三层的第一层） */
.pangu-field-error {
  display: flex;
  align-items: center;
  gap: var(--pangu-space-1);
  font-size: var(--pangu-fs-xs);
  font-weight: 550;
  color: var(--pangu-danger-ink);
}

.pangu-field-error[hidden] {
  display: none;
}

.pangu-field-error::before {
  content: "error";
  font-family: "Material Symbols Outlined";
  font-size: 14px;
  line-height: 1;
}

.pangu-field-input.is-invalid,
.pangu-field-select.is-invalid,
.pangu-field-textarea.is-invalid {
  border-color: var(--pangu-danger);
}

/* ==========================================================================
   反馈三层 第 1 层：字段级行内校验
   ---------------------------------------------------------------------------
   app.js 的 setFieldError() 会在字段块后面插一条 [data-auto-field-error]，
   所以老表单（兑换码、改密码、邮箱绑定…）不用改模板也能有行内错误。
   父容器可能是 flex 行也可能是 grid，两种都给足够的占位让它独占一行。
   ========================================================================== */
.pangu-field-error[data-auto-field-error] {
  flex: 1 0 100%;
  grid-column: 1 / -1;
  width: 100%;
  margin-top: var(--pangu-space-1);
}

/* 老表单里的原生输入框也要有错误态。用 .console-shell 提权重（0,2,1），
   盖过 legacy 里 .console-xxx input 那种 (0,2,0) 的规则，不用 !important。 */
.console-shell input.is-invalid,
.console-shell select.is-invalid,
.console-shell textarea.is-invalid,
.console-shell input.is-invalid:focus,
.console-shell select.is-invalid:focus,
.console-shell textarea.is-invalid:focus,
.pangu-field-input.is-invalid:focus,
.pangu-field-select.is-invalid:focus,
.pangu-field-textarea.is-invalid:focus {
  border-color: var(--pangu-danger);
  /* legacy 里给输入框的 border/box-shadow 大量带 !important，换前缀也躲不掉。
     错误态改用 outline —— 它渲染在边框外沿、legacy 基本没碰过，
     视觉上就是一圈红框，也不用去改 legacy。 */
  outline: 2px solid var(--pangu-danger);
  outline-offset: -2px;
  box-shadow: 0 0 0 3px var(--pangu-danger-soft);
}

/* 金额输入：$ 前缀 + USD 后缀 */
.pangu-field-money {
  display: flex;
  align-items: center;
  gap: var(--pangu-space-2);
  height: 38px;
  padding: 0 var(--pangu-space-3);
  border-radius: var(--pangu-radius-sm);
  border: 1px solid var(--pangu-border);
  background: var(--pangu-surface-sunken);
}

.pangu-field-money:focus-within {
  border-color: var(--pangu-brand);
  box-shadow: var(--pangu-focus-ring);
}

.pangu-field-money > span {
  flex: 0 0 auto;
  font-size: var(--pangu-fs-sm);
  color: var(--pangu-text-3);
}

.pangu-field-money > input {
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
  border: 0;
  background: transparent;
  outline: none;
  font-family: inherit;
  font-size: var(--pangu-fs-sm);
  color: var(--pangu-text);
}

/* 一行放两个 / 三个字段 */
.pangu-field-grid {
  display: grid;
  gap: var(--pangu-space-3);
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

/* 快捷填充小药丸（名称建议 / 有效期快捷） */
.pangu-field-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--pangu-space-2);
}

.pangu-field-chips > button:not(.pangu-btn){
  height: 28px;
  padding: 0 var(--pangu-space-3);
  border-radius: var(--pangu-radius-full);
  border: 1px solid var(--pangu-border);
  background: var(--pangu-bg-hover);
  font-family: inherit;
  font-size: var(--pangu-fs-xs);
  font-weight: 550;
  color: var(--pangu-text-2);
  cursor: pointer;
  transition: all 0.15s ease;
}

.pangu-field-chips > button:hover {
  color: var(--pangu-text);
  border-color: var(--pangu-brand);
}

.pangu-field-chips > button:focus-visible {
  outline: none;
  box-shadow: var(--pangu-focus-ring);
}

/* ==========================================================================
   开关行
   ========================================================================== */
.pangu-switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--pangu-space-3);
  padding: var(--pangu-space-2) 0;
  cursor: pointer;
  user-select: none;
}

.pangu-switch-label {
  font-size: var(--pangu-fs-sm);
  font-weight: 600;
  color: var(--pangu-text);
}

.pangu-switch-label small {
  display: block;
  margin-top: 2px;
  font-size: var(--pangu-fs-xs);
  font-weight: 400;
  color: var(--pangu-text-3);
}

.pangu-switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  width: 48px;
  height: 28px;
  flex: 0 0 auto;
  cursor: pointer;
}

.pangu-switch-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  margin: 0;
  cursor: pointer;
  z-index: 2;
}

.pangu-switch-track {
  position: absolute;
  inset: 0;
  background-color: var(--pangu-border-strong);
  border-radius: var(--pangu-radius-full);
  transition: background-color 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.pangu-switch-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 24px;
  height: 24px;
  background-color: #ffffff;
  border-radius: var(--pangu-radius-full);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2), 0 0 1px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.pangu-switch-input:checked + .pangu-switch-track {
  background-color: var(--pangu-brand);
}

.pangu-switch-input:checked + .pangu-switch-track .pangu-switch-thumb {
  transform: translateX(20px);
}

.pangu-switch-input:focus-visible + .pangu-switch-track {
  box-shadow: var(--pangu-focus-ring);
}

/* 开关打开后展开的那块（app.js 用 hidden 属性控制） */
.pangu-reveal {
  display: flex;
  flex-direction: column;
  gap: var(--pangu-space-3);
  padding: var(--pangu-space-3);
  border-radius: var(--pangu-radius-sm);
  background: var(--pangu-surface-sunken);
  border: 1px solid var(--pangu-border);
}

.pangu-reveal[hidden] {
  display: none;
}

/* ==========================================================================
   进阶折叠抽屉
   ========================================================================== */
.pangu-disclosure {
  width: 100%;
  border: 1px solid var(--pangu-border);
  border-radius: var(--pangu-radius-sm);
  overflow: hidden;
  background: var(--pangu-bg-hover);
}

.pangu-disclosure-trigger {
  width: 100%;
  padding: var(--pangu-space-3) var(--pangu-space-4);
  background: transparent;
  border: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--pangu-space-2);
  cursor: pointer;
  font-family: inherit;
  font-size: var(--pangu-fs-xs);
  font-weight: 600;
  color: var(--pangu-text-2);
  transition: color 0.15s ease;
  outline: none;
}

.pangu-disclosure-trigger:hover {
  color: var(--pangu-text);
}

.pangu-disclosure-trigger:focus-visible {
  box-shadow: var(--pangu-focus-ring);
}

.pangu-disclosure-trigger > span:first-child {
  display: flex;
  align-items: center;
  gap: var(--pangu-space-2);
}

.pangu-disclosure-arrow {
  font-size: 18px;
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.pangu-disclosure-trigger[aria-expanded="true"] .pangu-disclosure-arrow {
  transform: rotate(180deg);
}

.pangu-disclosure-content {
  display: none;
  flex-direction: column;
  gap: var(--pangu-space-3);
  padding: var(--pangu-space-4);
  border-top: 1px solid var(--pangu-border);
  background: var(--pangu-surface);
}

.pangu-disclosure.is-open .pangu-disclosure-content {
  display: flex;
}

@media (prefers-reduced-motion: reduce) {
  .pangu-switch-track,
  .pangu-switch-thumb,
  .pangu-disclosure-arrow {
    transition: none;
  }
}

/* ==========================================================================
   窄屏：底部导航形态下弹窗贴底（手机端布局本身不动）
   ========================================================================== */
@media (max-width: 540px) {
  /* 手机上也居中（用户定的：弹窗一律居中）。
     原来这里是底部抽屉：align-items:flex-end + 只留上面两个圆角。 */
  .pangu-modal {
    padding: var(--pangu-space-3);
    align-items: center;
  }

  .pangu-modal-card {
    width: 100%;
    max-width: none;
    max-height: min(86vh, calc(100dvh - var(--pangu-space-6)));
  }

  .pangu-modal-header,
  .pangu-modal-body,
  .pangu-modal-footer {
    padding-left: var(--pangu-space-4);
    padding-right: var(--pangu-space-4);
  }

  .pangu-modal-footer > .pangu-btn {
    flex: 1 1 auto;
  }
}

/* ==========================================================================
   公告中心 / 公告详情
   ---------------------------------------------------------------------------
   骨架直接复用上面的 .pangu-modal（本来就是居中的），这里只补两处：
   页签行要贴在 header 和 body 中间、面板要能滚动。
   语义：「通知」= 后台设为置顶的固定公告；「时间线」= 不固定的，按时间倒序。
   ========================================================================== */
.console-ann-center-card {
  max-width: 560px;
}

.console-ann-center-card .console-ann-tabs {
  flex: 0 0 auto;
  margin: 0;
  padding: var(--pangu-space-3) var(--pangu-space-5) 0;
  border: 0;
  background: transparent;
}

.console-ann-center-card .console-ann-panes {
  gap: 0;
  padding-top: var(--pangu-space-4);
}

.console-ann-center-card .console-ann-body {
  max-height: min(52vh, 460px);
  overflow-y: auto;
}

.console-ann-center-card .console-ann-body[hidden] {
  display: none;
}

.console-ann-tab [data-ann-count] {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: var(--pangu-radius-full);
  color: var(--pangu-text-2);
  background: var(--pangu-bg-hover);
  font-size: 11px;
  font-style: normal;
  font-weight: 700;
  line-height: 18px;
}

.console-ann-tab[data-ann-tab].is-active [data-ann-count] {
  color: var(--pangu-brand-ink);
  background: var(--pangu-brand-soft);
}

.console-ann-detail-card {
  max-width: 560px;
}

.console-ann-detail-tags {
  display: flex;
  align-items: center;
  gap: var(--pangu-space-2);
  flex-wrap: wrap;
  margin-bottom: var(--pangu-space-2);
}

.console-ann-detail-card .console-announcement-modal-body {
  line-height: 1.75;
}


/* ==========================================================================
   公告 —— 照 new-api 的 announcements-panel / announcement-detail-dialog
   ========================================================================== */

/* 一行公告：正文预览一行截断 */
.console-ann-tl-preview {
  display: -webkit-box;
  overflow: hidden;
  margin-top: 2px;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 1;
  line-clamp: 1;
  color: var(--pangu-text-2);
  font-size: var(--pangu-fs-xs);
  line-height: 1.5;
}

/* 时间 + hover 才出现的「点击查看详情」 */
.console-ann-tl-copy small {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--pangu-space-2);
}

.console-ann-tl-hint {
  flex: 0 0 auto;
  color: var(--pangu-text-3, #94a3b8);
  font-size: 11px;
  font-style: normal;
  opacity: 0;
  transition: opacity 160ms ease;
}

.console-ann-tl-item:hover .console-ann-tl-hint,
.console-ann-tl-item:focus-visible .console-ann-tl-hint { opacity: 1; }

@media (prefers-reduced-motion: reduce) {
  .console-ann-tl-hint { transition: none; }
}

/* 详情弹窗：正文分段 + 可滚动 */
.console-ann-detail-card .pangu-modal-body {
  max-height: min(58vh, 520px);
  overflow-y: auto;
}

.console-ann-detail-section + .console-ann-detail-section {
  margin-top: var(--pangu-space-4);
  padding-top: var(--pangu-space-4);
  border-top: 1px solid var(--pangu-border);
}

.console-ann-detail-section > h4 {
  margin: 0 0 var(--pangu-space-2);
  color: var(--pangu-text);
  font-size: var(--pangu-fs-sm);
  font-weight: 700;
}

.console-ann-detail-rich {
  color: var(--pangu-text);
  font-size: var(--pangu-fs-sm);
  line-height: 1.7;
}

.console-ann-detail-section.is-extra .console-ann-detail-rich { color: var(--pangu-text-2); }


/* ==========================================================================
   关闭按钮的「钉右上角」工具类
   --------------------------------------------------------------------------
   pangu-btn 只负责长相和尺寸，不负责待在哪儿。卡片里那种绝对定位的关闭 X，
   换成 pangu-btn 之后要额外补这个类，否则会掉进正常文档流
   （2026-09-06：抽奖结果弹窗的 X 掉到了卡片正中间、支付弹窗的 X 贴到了标题右边）。
   用在任何 position:relative 的弹窗卡片里。
   ========================================================================== */
.pangu-modal-close-abs {
  position: absolute;
  z-index: 2;
  top: var(--pangu-space-3);
  right: var(--pangu-space-3);
}
