/* =====================================================================
   toast-styles.css — 消息提示样式（毛玻璃 / iOS 弹窗 / 经典胶囊）
   ---------------------------------------------------------------------
   切换方式：html[data-toaststyle="glass|ios|classic"]，缺省 = glass

   ▍iOS 弹窗 = UIAlertController 双按钮形态（对齐系统警告框）：
     圆角卡片
       ├─ .cm-alert-body      正文区
       │    ├─ .cm-alert-title  粗体标题 17px/600
       │    └─ .cm-alert-msg    小字正文 13px（有标题时）
       └─ .cm-alert-actions   按钮区
            └─ .cm-alert-btn × N（横排，竖线分隔，蓝色）

   ⚠ 四个踩过的坑，改动前务必理解：
   1. chat.css:146 的 .tg-toast 是 pointer-events:none（原本纯展示）。
      iOS 档必须恢复 auto，否则按钮点不动且触摸穿透。
   2. chat.css 的 .tg-toast 有 transition:.22s（等于 all），会让
      background / backdrop-filter 一起渐变，切档时卡住旧值。
      → 本文件把 transition 限定为 opacity/transform。
   3. transform 会为 position:fixed 后代创建包含块。
      遮罩若用 .tg-toast::before + inset:0，只覆盖弹窗自身而非视口。
      → 遮罩用独立元素 .cm-toast-veil。
   4. filter 非 none 会让元素成为 backdrop root，使 backdrop-filter
      采样自身 → 必须保持 filter:none。

   加载顺序：必须在 chat.css / chat-motion.css 之后。
   ===================================================================== */

/* ---------- 通用 ---------- */
.tg-toast {
  font-weight: 500;
  letter-spacing: .1px;
  filter: none !important;
  will-change: opacity, transform;
  transition: opacity .22s cubic-bezier(.32, .72, 0, 1),
              transform .22s cubic-bezier(.32, .72, 0, 1) !important;
  transition-property: opacity, transform !important;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}

/* =====================================================================
   独立遮罩层（iOS 弹窗专用）
   ===================================================================== */
.cm-toast-veil {
  position: fixed;
  inset: 0;
  z-index: 129;
  background: rgba(0, 0, 0, .18);
  -webkit-backdrop-filter: blur(1px);
  backdrop-filter: blur(1px);
  opacity: 0;
  /* 显示时才拦截触摸，避免点穿到背后页面 */
  pointer-events: none;
  transition: opacity .24s cubic-bezier(.32, .72, 0, 1);
}
.cm-toast-veil.show {
  opacity: 1;
  pointer-events: auto;
}

/* =====================================================================
   一、毛玻璃（默认）
   ===================================================================== */
html[data-toaststyle="glass"] .tg-toast,
html:not([data-toaststyle]) .tg-toast {
  background: rgba(255, 255, 255, .58) !important;
  color: #1c1c1e !important;
  border: 1px solid rgba(255, 255, 255, .72);
  -webkit-backdrop-filter: blur(22px) saturate(180%) brightness(1.06);
  backdrop-filter: blur(22px) saturate(180%) brightness(1.06);
  box-shadow:
    0 8px 32px rgba(0, 0, 0, .16),
    0 1px 2px rgba(0, 0, 0, .06),
    inset 0 1px 0 rgba(255, 255, 255, .85),
    inset 0 -1px 0 rgba(255, 255, 255, .28);
}

@media (prefers-color-scheme: dark) {
  html[data-toaststyle="glass"] .tg-toast,
  html:not([data-toaststyle]) .tg-toast {
    background: rgba(48, 48, 52, .52) !important;
    color: #f2f2f7 !important;
    border-color: rgba(255, 255, 255, .14);
    -webkit-backdrop-filter: blur(22px) saturate(160%) brightness(.92);
    backdrop-filter: blur(22px) saturate(160%) brightness(.92);
    box-shadow:
      0 8px 32px rgba(0, 0, 0, .46),
      0 1px 2px rgba(0, 0, 0, .3),
      inset 0 1px 0 rgba(255, 255, 255, .16),
      inset 0 -1px 0 rgba(255, 255, 255, .05);
  }
}

/* =====================================================================
   二、iOS 弹窗（UIAlertController 双按钮）
   ===================================================================== */
html[data-toaststyle="ios"] .tg-toast {
  /* chat.css 的 pointer-events:none 必须解除，否则按钮不可点 */
  pointer-events: auto !important;
  /* 居中：left/top 50% + transform 回拉。
     不用 inset:0+margin:auto —— chat.css 的 left:50% 会干扰。 */
  top: 50% !important;
  left: 50% !important;
  right: auto !important;
  bottom: auto !important;
  margin: 0 !important;
  width: 270px;
  max-width: calc(100vw - 64px);
  height: -moz-fit-content;
  height: fit-content;
  /* 重置 chat.css 的胶囊样式 */
  padding: 0 !important;
  border: 0;
  border-radius: 22px;
  overflow: hidden;
  text-align: center;
  font-size: 17px;
  line-height: 1.38;
  /* 微毛玻璃：低不透明度 + 小半径模糊，背景真的能透上来 */
  background: rgba(252, 252, 253, .58) !important;
  color: #000 !important;
  -webkit-backdrop-filter: blur(15px) saturate(170%) brightness(1.04);
  backdrop-filter: blur(15px) saturate(170%) brightness(1.04);
  box-shadow:
    0 12px 40px rgba(0, 0, 0, .22),
    0 1px 2px rgba(0, 0, 0, .05);
  /* 收起态 */
  opacity: 0;
  transform: translate(-50%, -50%) scale(.88);
  transition: opacity .16s cubic-bezier(.32, .72, 0, 1),
              transform .3s cubic-bezier(.34, 1.56, .64, 1) !important;
  transition-property: opacity, transform !important;
}

html[data-toaststyle="ios"] .tg-toast.show {
  opacity: 1 !important;
  transform: translate(-50%, -50%) scale(1) !important;
  animation: none !important;
  transition-property: opacity, transform !important;
}

/* ---------- 正文区 ---------- */
html[data-toaststyle="ios"] .cm-alert-body {
  padding: 19px 16px 15px;
  text-align: center;
}

/* 有标题时正文区下边距收紧，贴近 iOS 观感 */
html[data-toaststyle="ios"] .cm-alert-body.has-title {
  padding: 19px 16px 17px;
}

/* 粗体标题 */
html[data-toaststyle="ios"] .cm-alert-title {
  font-size: 17px;
  font-weight: 600;
  line-height: 1.29;
  letter-spacing: -.4px;
  color: #000;
  margin: 0 0 5px;
  word-break: break-word;
}

/* 正文：有标题时 13px；无标题单独成句时 17px */
html[data-toaststyle="ios"] .cm-alert-msg {
  font-size: 13px;
  line-height: 1.38;
  font-weight: 400;
  letter-spacing: -.08px;
  color: #000;
  padding: 0;
  margin: 0;
  word-break: break-word;
  /* 长文可滚动，避免弹窗超出屏幕 */
  max-height: 260px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  white-space: pre-wrap;
}

/* 无标题时正文放大到 17px，更像单句提示 */
html[data-toaststyle="ios"] .cm-alert-body:not(.has-title) .cm-alert-msg {
  font-size: 16px;
  letter-spacing: -.2px;
}

/* ---------- 按钮区 ---------- */
html[data-toaststyle="ios"] .cm-alert-actions {
  position: relative;
  display: flex;
  pointer-events: auto !important;
  border-top: .5px solid rgba(60, 60, 67, .29);
}

/* 横排按钮之间的竖线分隔 */
html[data-toaststyle="ios"] .cm-alert-actions .cm-alert-btn + .cm-alert-btn {
  border-left: .5px solid rgba(60, 60, 67, .29);
}

html[data-toaststyle="ios"] .cm-alert-btn {
  flex: 1 1 0;
  min-width: 0;
  height: 44px;
  border: 0;
  background: transparent;
  pointer-events: auto !important;
  touch-action: manipulation;
  font-family: inherit;
  font-size: 17px;
  font-weight: 400;
  letter-spacing: -.2px;
  color: #007aff;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color .12s ease;
  /* 长文案不换行，超出省略 */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 10px;
}
html[data-toaststyle="ios"] .cm-alert-btn:active {
  background: rgba(0, 0, 0, .06);
}
/* 主按钮加粗（对应 iOS preferredAction） */
html[data-toaststyle="ios"] .cm-alert-btn.primary {
  font-weight: 600;
}

/* 深色模式 */
@media (prefers-color-scheme: dark) {
  .cm-toast-veil { background: rgba(0, 0, 0, .42); }

  html[data-toaststyle="ios"] .tg-toast {
    background: rgba(44, 44, 46, .6) !important;
    color: #fff !important;
    -webkit-backdrop-filter: blur(15px) saturate(150%) brightness(.92);
    backdrop-filter: blur(15px) saturate(150%) brightness(.92);
    box-shadow: 0 12px 40px rgba(0, 0, 0, .5);
  }
  html[data-toaststyle="ios"] .cm-alert-title,
  html[data-toaststyle="ios"] .cm-alert-msg {
    color: #fff;
  }
  html[data-toaststyle="ios"] .cm-alert-actions {
    border-top-color: rgba(84, 84, 88, .65);
  }
  html[data-toaststyle="ios"] .cm-alert-actions .cm-alert-btn + .cm-alert-btn {
    border-left-color: rgba(84, 84, 88, .65);
  }
  html[data-toaststyle="ios"] .cm-alert-btn {
    color: #0a84ff;
  }
  html[data-toaststyle="ios"] .cm-alert-btn:active {
    background: rgba(255, 255, 255, .08);
  }
}

/* =====================================================================
   三、经典胶囊
   ===================================================================== */
html[data-toaststyle="classic"] .tg-toast {
  background: rgba(28, 28, 30, .92) !important;
  color: #fff !important;
  border: 1px solid rgba(255, 255, 255, .08);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  box-shadow: 0 6px 22px rgba(0, 0, 0, .3);
  font-weight: 400;
}

/* 非 iOS 模式下，注入的 alert 结构退化为纯文本 */
html:not([data-toaststyle="ios"]) .cm-alert-actions {
  display: none !important;
}
html:not([data-toaststyle="ios"]) .cm-alert-body {
  padding: 0;
}
html:not([data-toaststyle="ios"]) .cm-alert-title {
  display: none;
}
html:not([data-toaststyle="ios"]) .cm-alert-msg {
  font-size: inherit;
  line-height: inherit;
  color: inherit;
  font-weight: inherit;
  max-height: none;
  overflow: visible;
  white-space: pre-wrap;
}

/* =====================================================================
   兼容与降级
   ===================================================================== */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  html[data-toaststyle="glass"] .tg-toast,
  html:not([data-toaststyle]) .tg-toast {
    background: rgba(28, 28, 30, .93) !important;
    color: #fff !important;
    border-color: rgba(255, 255, 255, .16);
  }
  html[data-toaststyle="ios"] .tg-toast {
    background: rgba(249, 249, 249, .99) !important;
  }
  @media (prefers-color-scheme: dark) {
    html[data-toaststyle="ios"] .tg-toast {
      background: rgba(44, 44, 46, .99) !important;
    }
  }
}

@media (prefers-reduced-motion: reduce) {
  .tg-toast,
  .cm-toast-veil { transition-duration: .001ms !important; }
  html[data-toaststyle="ios"] .tg-toast {
    transform: translate(-50%, -50%) !important;
  }
}
