/**
 * 全站 Toast 提示 - 唯一样式源
 * 分类：尺寸变量 · 容器定位 · Bootstrap Toast 皮肤 · 类型配色 · 旧版 alert 通知 · 响应式
 * 依赖：bootstrap4.css、font-awesome
 * 引入：application/index/view/layout/app.html（放在页面 CSS 之前，页面可按需覆盖定位）
 * 覆盖示例：页面 CSS 只需写 .toast-container { top: 80px; } 避开顶部导航
 *
 * ⚠ 必读（历史坑）：项目内置 bootstrap4.css 的 .toast 带了
 *     flex-basis: 350px; -ms-flex-preferred-size: 350px;
 *   本文件容器是 flex-direction: column（主轴 = 垂直），
 *   flex 会把该值当成【高度】，导致弹窗被撑成 350px 高的方块（内容只有一两行，下方大片空白）。
 *   因此 .toast 必须显式 `flex: 0 0 auto; height: auto;` 重置。
 *   —— 改这个文件时不要删掉这两行。
 */

:root {
  --toast-width: 340px;
  --toast-gap: 10px;
  --toast-radius: 10px;
  --toast-shadow: 0 8px 24px rgba(15, 23, 42, 0.16);
  --toast-primary: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --toast-success: linear-gradient(135deg, #28a745 0%, #20c997 100%);
  --toast-error: linear-gradient(135deg, #dc3545 0%, #c82333 100%);
  --toast-warning: linear-gradient(135deg, #ffc107 0%, #ff9800 100%);
}

/* ========== 容器：固定在网页右上角，多条纵向堆叠 ========== */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  /* 所有弹窗等宽，不随文案长短忽大忽小 */
  align-items: stretch;
  gap: var(--toast-gap);
  /* 定死宽度：避免 shrink-to-fit 与子元素百分比宽度互相依赖 */
  width: var(--toast-width);
  max-width: calc(100vw - 40px);
  /* 容器本身不拦截点击，只让弹窗本体可交互（关闭按钮） */
  pointer-events: none;
}

.toast-container .toast,
.toast-container .toast-notification {
  pointer-events: auto;
  /* 清掉 bootstrap 的 .toast:not(:last-child) 12px，避免与 gap 叠加成 22px */
  margin-bottom: 0;
}

/* ========== Bootstrap Toast 皮肤 ========== */
.toast {
  /* 关键：重置 bootstrap 的 flex-basis: 350px（列向 flex 下会被当成高度） */
  flex: 0 0 auto;
  height: auto;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  font-size: 14px;
  border: none;
  border-radius: var(--toast-radius);
  background-color: #fff;
  box-shadow: var(--toast-shadow);
}

.toast-header {
  display: flex;
  align-items: center;
  padding: 9px 14px;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  border-bottom: none;
  /* 清掉 bootstrap 的 border-top-*-radius，圆角交给 .toast 的 overflow 裁切 */
  border-radius: 0;
  background: var(--toast-primary);
}

.toast-header .close {
  color: #fff;
  opacity: 0.8;
  font-size: 1.15rem;
  line-height: 1;
  text-shadow: none;
}

.toast-header .close:hover {
  opacity: 1;
}

.toast-body {
  padding: 12px 14px;
  font-size: 14px;
  line-height: 1.5;
  color: #4b5563;
  /* 长链接 / 长文案不撑破弹窗 */
  word-break: break-word;
}

/* ========== 类型配色 ========== */
.toast-header.toast-success {
  background: var(--toast-success);
}

.toast-header.toast-error,
.toast-header.toast-danger {
  background: var(--toast-error);
}

.toast-header.toast-warning {
  background: var(--toast-warning);
}

/* ========== 旧版 alert 通知（layout/app.html 全局 showToast 使用） ========== */
.toast-notification {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  min-width: 300px;
  max-width: var(--toast-width);
  padding: 12px 14px;
  font-size: 14px;
  border-radius: var(--toast-radius);
  box-shadow: var(--toast-shadow);
  animation: toastSlideIn 0.3s ease-out;
}

/* 放进容器内时改回常规流：跟随容器定位，并与其他弹窗一起纵向堆叠 */
.toast-container .toast-notification {
  position: static;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  animation: none;
}

@keyframes toastSlideIn {
  from {
    transform: translateX(400px);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* ========== 响应式：窄屏铺满可用宽度 ========== */
@media (max-width: 575px) {
  .toast-container {
    top: 12px;
    right: 12px;
    left: 12px;
    width: auto;
    max-width: none;
  }

  .toast-notification {
    top: 12px;
    right: 12px;
    left: 12px;
    width: auto;
    min-width: 0;
    max-width: none;
  }
}
