.toast-stack {
  position: fixed;
  inset: auto;
  top: max(20px, env(safe-area-inset-top, 0px));
  left: 50%;
  z-index: 2147483647;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: min(360px, calc(100vw - 32px));
  height: auto;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  overflow: visible;
  transform: translate(-50%, var(--toast-dialog-offset-y, 0px));
  pointer-events: none;
}

.toast-stack[popover]:not(:popover-open) {
  display: none;
}

.toast {
  --toast-accent: var(--color-primary-500);
  --toast-accent-bg: var(--color-primary-alpha-10);
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  box-sizing: border-box;
  width: fit-content;
  min-width: 240px;
  max-width: 100%;
  min-height: 52px;
  padding: 12px 18px 12px 14px;
  border-radius: 16px;
  border: 1px solid rgba(15, 23, 42, 0.08);
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow:
    0 14px 34px rgba(15, 23, 42, 0.16),
    0 3px 10px rgba(15, 23, 42, 0.08);
  color: #172033;
  font-size: 15px;
  font-family: PingFang SC, sans-serif;
  font-weight: 500;
  line-height: 22px;
  opacity: 0;
  transform: translateY(-10px) scale(0.96);
  transition:
    opacity 0.28s cubic-bezier(0.22, 1, 0.36, 1),
    transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
  pointer-events: auto;
  overflow: hidden;
}

.toast::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--toast-accent);
}

.toast--visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.toast--leaving {
  opacity: 0;
  transform: translateY(-6px) scale(0.98);
  transition-duration: 0.2s;
}

.toast__icon {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: var(--toast-accent-bg);
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.toast__icon::before,
.toast__icon::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  box-sizing: border-box;
}

.toast__text {
  flex: 1;
  min-width: 0;
  word-break: break-word;
  color: #172033;
  line-height: 22px;
}

.toast--success {
  --toast-accent: #22c55e;
  --toast-accent-bg: #22c55e;
  border-color: rgba(34, 197, 94, 0.18);
  background:
    linear-gradient(135deg, rgba(34, 197, 94, 0.09) 0%, rgba(255, 255, 255, 0.98) 44%),
    #fff;
}

.toast--success .toast__icon {
  width: 24px;
  height: 24px;
  background: linear-gradient(145deg, #34d399 0%, #22c55e 100%);
  box-shadow: 0 2px 8px rgba(34, 197, 94, 0.28);
}

.toast--success .toast__icon::before {
  width: 6px;
  height: 10px;
  margin: 0;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: translate(-50%, -58%) rotate(45deg);
}

.toast--error {
  --toast-accent: #fd2e33;
  --toast-accent-bg: rgba(253, 46, 51, 0.12);
}

.toast--error .toast__icon::before,
.toast--error .toast__icon::after {
  width: 2px;
  height: 12px;
  border-radius: 999px;
  background: #fd2e33;
}

.toast--error .toast__icon::before {
  transform: translate(-50%, -50%) rotate(45deg);
}

.toast--error .toast__icon::after {
  transform: translate(-50%, -50%) rotate(-45deg);
}

.toast--info {
  --toast-accent: var(--color-primary-500);
  --toast-accent-bg: var(--color-primary-alpha-10);
}

.toast--info .toast__icon::before {
  width: 2px;
  height: 8px;
  border-radius: 999px;
  background: var(--color-primary-500);
  transform: translate(-50%, calc(-50% + 2px));
}

.toast--info .toast__icon::after {
  width: 2px;
  height: 2px;
  border-radius: 999px;
  background: var(--color-primary-500);
  transform: translate(-50%, -50%);
  top: calc(50% - 5px);
}

.toast--warning {
  --toast-accent: #f59e0b;
  --toast-accent-bg: rgba(245, 158, 11, 0.14);
}

.toast--warning .toast__icon::before {
  width: 2px;
  height: 10px;
  border-radius: 999px;
  background: #f59e0b;
  transform: translate(-50%, calc(-50% - 2px));
}

.toast--warning .toast__icon::after {
  width: 2px;
  height: 2px;
  border-radius: 999px;
  background: #f59e0b;
  transform: translate(-50%, -50%);
  top: calc(50% + 6px);
}

@media (max-width: 768px) {
  .toast-stack {
    top: max(14px, env(safe-area-inset-top, 0px));
    width: min(328px, calc(100vw - 32px));
    gap: 8px;
  }

  .toast {
    min-width: 220px;
    min-height: 50px;
    padding: 11px 16px 11px 13px;
    border-radius: 15px;
    font-size: 14px;
    font-weight: 500;
    line-height: 20px;
  }

  .toast__icon {
    width: 20px;
    height: 20px;
  }

  .toast__text {
    line-height: 20px;
  }

  .toast--success .toast__icon {
    width: 24px;
    height: 24px;
  }

  .toast--success .toast__icon::before {
    width: 5px;
    height: 9px;
  }
}
