/* ============================================
   tw-modal.css — 轻量弹窗组件样式
   零依赖，PC + H5 兼容
   ============================================ */

:root {
  --tw-bg-page: #f5f4f2;
  --tw-bg-card: #ffffff;
  --tw-bg-overlay: rgba(0, 0, 0, 0.45);
  --tw-text-primary: #1a1a1e;
  --tw-text-secondary: #6b6b6f;
  --tw-text-tertiary: #9d9d9f;
  --tw-border-light: #e8e7e4;
  --tw-border-input: #d9d8d5;
  --tw-accent: #1f1f23;
  --tw-accent-hover: #3a3a40;
  --tw-accent-subtle: #e9e8e6;
  --tw-shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --tw-shadow-md: 0 4px 16px rgba(0,0,0,0.07);
  --tw-shadow-lg: 0 8px 40px rgba(0,0,0,0.10);
  --tw-radius: 12px;
  --tw-radius-sm: 8px;
  --tw-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
}

/* ===== 遮罩层 ===== */
.tw-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  justify-content: center;
  align-items: flex-start;
  padding: 5vh 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.tw-overlay.active {
  display: flex;
}

/* ===== 弹窗容器 ===== */
.tw-modal {
  background: var(--tw-bg-card);
  border-radius: var(--tw-radius);
  box-shadow: var(--tw-shadow-lg);
  width: 420px;
  max-width: 100%;
  max-height: 90vh;
  position: relative;
  display: flex;
  flex-direction: column;
  margin: auto;
  text-align: left;
  font-family: var(--tw-font);
  color: var(--tw-text-primary);
  font-size: 14px;
  line-height: 1.5;
  /* 动画基础状态由 JS 通过 data-anim 控制 */
}
.tw-overlay[data-position="center"] .tw-modal {
  margin: auto;
}

/* ===== 尺寸预设 ===== */
.tw-modal[data-size="small"] { width: 320px; }
.tw-modal[data-size="medium"] { width: 420px; }
.tw-modal[data-size="large"] { width: 520px; }
.tw-modal[data-size="full"] {
  width: 92vw;
  max-width: 600px;
}
.tw-modal[data-size="auto"] {
  width: auto;
  min-width: 260px;
  max-width: 600px;
}

/* ===== 关闭按钮 ===== */
.tw-close-btn {
  position: absolute;
  top: 18px;
  right: 12px;
  z-index: 10;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 18px;
  color: var(--tw-text-tertiary);
  border-radius: 50%;
  transition: background 0.15s, color 0.15s;
  line-height: 1;
  padding: 0;
  font-family: inherit;
}
.tw-close-btn:hover {
  background: var(--tw-accent-subtle);
  color: var(--tw-text-primary);
}
.tw-close-btn:focus-visible {
  outline: 2px solid var(--tw-accent);
  outline-offset: 2px;
}

/* ===== 头部 ===== */
.tw-modal-head {
  padding: 20px 24px 16px;
  text-align: center;
  flex-shrink: 0;
  border-radius: var(--tw-radius) var(--tw-radius) 0 0;
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
}
.tw-modal-head h2 {
  font-size: 16px;
  font-weight: 700;
  color: var(--tw-text-primary);
  letter-spacing: -0.2px;
  margin: 0;
  text-wrap: balance;
}
.tw-modal-head .tw-sub {
  font-size: 12px;
  color: var(--tw-text-secondary);
  margin-top: 4px;
  font-weight: 400;
}

/* ===== 主体 ===== */
.tw-modal-body {
  padding: 0 24px 20px;
  font-size: 14px;
  color: var(--tw-text-secondary);
  line-height: 1.6;
  overflow-y: auto;
  flex: 1;
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
}
.tw-modal-body.tw-scrollable {
  max-height: 50vh;
}
.tw-modal-body::-webkit-scrollbar {
  width: 4px;
}
.tw-modal-body::-webkit-scrollbar-thumb {
  background: #d4d3d0;
  border-radius: 4px;
}

/* ===== 底部 ===== */
.tw-modal-foot {
  padding: 0 24px 20px;
  flex-shrink: 0;
  border-radius: 0 0 var(--tw-radius) var(--tw-radius);
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
}
.tw-modal-foot[data-btn-align="center"] {
  text-align: center;
}
.tw-modal-foot[data-btn-align="left"] {
  text-align: left;
}
.tw-modal-foot[data-btn-align="right"] {
  text-align: right;
}

/* ===== 关闭按钮位置 ===== */
.tw-close-btn[data-close-pos="top-left"] {
  right: auto;
  left: 12px;
}
.tw-close-btn[data-close-pos="bottom-center"] {
  top: 100%;
  right: auto;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
}
.tw-btn {
  display: inline-block;
  padding: 9px 24px;
  border-radius: var(--tw-radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  background: var(--tw-accent);
  color: #fff;
  transition: background 0.15s, transform 0.1s;
  letter-spacing: 0.3px;
  font-family: inherit;
  line-height: 1.4;
  margin: 0 4px;
  vertical-align: middle;
  user-select: none;
}
.tw-btn:hover {
  background: var(--tw-accent-hover);
}
.tw-btn:active {
  transform: scale(0.97);
}
.tw-btn:focus-visible {
  outline: 2px solid #666;
  outline-offset: 2px;
}
.tw-btn-secondary {
  background: transparent;
  color: var(--tw-text-primary);
  border: 1px solid var(--tw-border-input);
}
.tw-btn-secondary:hover {
  background: var(--tw-accent-subtle);
}
.tw-btn-ghost {
  background: transparent;
  color: var(--tw-text-secondary);
  border: none;
  padding: 9px 16px;
}
.tw-btn-ghost:hover {
  background: var(--tw-accent-subtle);
  color: var(--tw-text-primary);
}

/* ===== 按钮禁用 ===== */
.tw-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* ===== 按钮全宽 ===== */
.tw-btn-block {
  display: block;
  width: 100%;
  margin: 4px 0;
}
.tw-btn-block + .tw-btn-block {
  margin-top: 8px;
}

/* ===== 分割线 ===== */
.tw-divider {
  height: 1px;
  background: var(--tw-border-light);
  margin: 0;
  flex-shrink: 0;
  border: none;
}

/* ===== 加载旋转动画 ===== */
.tw-loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--tw-border-light);
  border-top-color: var(--tw-accent);
  border-radius: 50%;
  animation: tw-spin 0.7s linear infinite;
  margin: 0 auto;
}
@keyframes tw-spin {
  to { transform: rotate(360deg); }
}

/* ===== 动画：fade ===== */
.tw-overlay[data-anim="fade"] .tw-modal {
  opacity: 0;
  transition: opacity 0.25s ease;
}
.tw-overlay[data-anim="fade"].active .tw-modal {
  opacity: 1;
}

/* ===== 动画：slide-up ===== */
.tw-overlay[data-anim="slide-up"] .tw-modal {
  opacity: 0;
  transform: translateY(24px);
  transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.25s ease;
}
.tw-overlay[data-anim="slide-up"].active .tw-modal {
  opacity: 1;
  transform: translateY(0);
}

/* ===== 动画：scale ===== */
.tw-overlay[data-anim="scale"] .tw-modal {
  opacity: 0;
  transform: scale(0.9);
  transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.2s ease;
}
.tw-overlay[data-anim="scale"].active .tw-modal {
  opacity: 1;
  transform: scale(1);
}

/* ===== 动画：none ===== */
.tw-overlay[data-anim="none"].active .tw-modal {
  opacity: 1;
}

/* ===== 遮罩过度 ===== */
.tw-overlay {
  transition: background-color 0.2s ease;
}

/* ===== 遮罩毛玻璃（已在 JS 中通过 style 设置） ===== */

/* ===== 动画时长定制（已在 JS 中通过 style 设置） ===== */

/* ===== 滚动锁定 ===== */
body.tw-scroll-lock {
  overflow: hidden !important;
  padding-right: var(--tw-scrollbar-width, 0px);
}

/* ===== 响应式 ===== */
@media (max-width: 480px) {
  .tw-overlay {
    padding: 10px;
    align-items: center;
  }
  .tw-modal {
    width: 100% !important;
    max-width: 100% !important;
    border-radius: var(--tw-radius);
  }
  .tw-modal[data-size="full"] {
    width: 100% !important;
    max-width: 100% !important;
    border-radius: var(--tw-radius);
  }
  .tw-modal-head {
    padding: 16px 16px 12px;
  }
  .tw-modal-body {
    padding: 0 16px 16px;
  }
  .tw-modal-foot {
    padding: 0 16px 16px;
  }
  .tw-btn {
    padding: 10px 20px;
    font-size: 14px;
  }
  .tw-close-btn {
    top: 14px;
    right: 8px;
  }
  .tw-close-btn[data-close-pos="top-left"] {
    left: 8px;
  }
}

/* ===== 弹窗遮罩点击区域（撑满） ===== */
.tw-overlay::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
}
